jcmd VM.set_flag, which flags are writable?
Asked Answered
V

2

6

I was trying to experiment with jcmd VM.set_flag option. But came across one error saying "only 'writeable' flags can be set". What are writable flags ?

Getting my pid:

XXX@XXX-Air:~/javacode$ jcmd -l
6294 Test
6295 jdk.jcmd/sun.tools.jcmd.JCmd -l

Trying to change vm flags:

XXX@XXX-Air:~/javacode$ jcmd 6294 VM.set_flag ConcGCThreads 4
6294:
only 'writeable' flags can be set
XXX@XXX-Air:~/javacode$ jcmd 6294 VM.set_flag MaxNewSize 1G
6294:
only 'writeable' flags can be set

Edit: It worked for manageable flags, below are successful commands.

 XXXX@XXX-Air:~/javacode$ jcmd 11441 VM.flags -all | grep MinHeapFreeRatio
    uintx MinHeapFreeRatio                         = 40                                    {manageable} {default}
XXXX@XXX-Air:~/javacode$ jcmd 11441 VM.set_flag MinHeapFreeRatio 45
11441:
Command executed successfully
XXXX@XXX-Air:~/javacode$ jcmd 11441 VM.flags -all | grep MinHeapFreeRatio
    uintx MinHeapFreeRatio                         = 45    
Valaria answered 17/10, 2017 at 8:1 Comment(1)
VM.set_flag is available in java 9 via openjdk.java.net/jeps/228, it is jdk9 specific option. isnt it ?Valaria
T
6

Writable flags are labeled as {manageable}.

You can list all flags with jcmd 12345 VM.flags -all. You can then grep for manageable ones (the is on my Oracle jdk8 VM) :

$ jcmd 12345 VM.flags -all | grep manageable
     intx CMSAbortablePrecleanWaitMillis            = 100                                 {manageable}
     intx CMSTriggerInterval                        = -1                                  {manageable}
     intx CMSWaitDuration                           = 2000                                {manageable}
     bool HeapDumpAfterFullGC                       = false                               {manageable}
     bool HeapDumpBeforeFullGC                      = false                               {manageable}
     bool HeapDumpOnOutOfMemoryError                = false                               {manageable}
    ccstr HeapDumpPath                              =                                     {manageable}
    uintx MaxHeapFreeRatio                          = 100                                 {manageable}
    uintx MinHeapFreeRatio                          = 0                                   {manageable}
     bool PrintClassHistogram                       = false                               {manageable}
     bool PrintClassHistogramAfterFullGC            = false                               {manageable}
     bool PrintClassHistogramBeforeFullGC           = false                               {manageable}
     bool PrintConcurrentLocks                      = false                               {manageable}
     bool PrintGC                                   = false                               {manageable}
     bool PrintGCDateStamps                         = false                               {manageable}
     bool PrintGCDetails                            = false                               {manageable}
     bool PrintGCID                                 = false                               {manageable}
     bool PrintGCTimeStamps                         = false                               {manageable}
Tildy answered 17/10, 2017 at 8:10 Comment(0)
Y
3

The article over the VM options states this :-

Flags marked as manageable are dynamically writeable through the JDK management interface (com.sun.management.HotSpotDiagnosticMXBean API) and also through JConsole.

To find out all such flags you can use VM.flags that would

Print the VM flag options and their current values

with the -all as the option to

Prints all flags supported by the VM

using the command :-

jcmd <pid> VM.flags -all
Yevetteyew answered 17/10, 2017 at 8:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.