jcmd VM.set_flag,哪些标志是可写的?

jcmd VM.set_flag, which flags are writable?

我正在尝试使用 jcmd VM.set_flag 选项。但是遇到一个错误 "only 'writeable' flags can be set"。什么是可写标志?

正在获取我的 pid:

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

正在尝试更改虚拟机标志:

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

编辑:它适用于可管理的标志,下面是成功的命令。

 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    

可写标志标记为 {manageable}

您可以使用 jcmd 12345 VM.flags -all 列出所有标志。然后您可以 grep 寻找可管理的(在我的 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}

VM options 上的文章指出:-

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

要找出所有此类标志,您可以使用 VM.flags 那会

Print the VM flag options and their current values

-all 作为

的选项

Prints all flags supported by the VM

使用命令:-

jcmd <pid> VM.flags -all