Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jcmd VM.set_flag, which flags are writable?

Tags:

java

java-9

jcmd

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    
like image 755
Vipin Avatar asked Oct 17 '17 08:10

Vipin


People also ask

How to list all writewritable flags in JVM?

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) : Show activity on this post.

What is the impact of setting the VM flag in Java?

Impact: Medium — depends on Java content. VM.set_flag [arguments] Sets the VM flag option by using the provided value. Impact: Low Permission: java.lang.management.ManagementPermission(control)

How to list all flags on a VM?

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) :

Which command sends the actual command to the JVM?

The command jcmd <process id/main class> <command> [options] sends the actual command to the JVM. Example 2-1 shows diagnostic command requests to JVM using jcmd utility. Example 2-1 Diagnostic Command Requests with jcmd Utility


2 Answers

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}
like image 158
Erwin Bolwidt Avatar answered Oct 24 '22 20:10

Erwin Bolwidt


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
like image 24
Naman Avatar answered Oct 24 '22 19:10

Naman