6

我正在尝试使用 jcmd VM.set_flag 选项。但是遇到了一个错误,说“只能设置'可写'标志”。什么是可写标志?

获取我的 pid:

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

尝试更改 vm 标志:

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    
4

2 回答 2

4

可写标志标记为{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}
于 2017-10-17T08:10:34.413 回答
2

关于VM 选项的文章指出:-

标记为可管理的标志可通过 JDK 管理接口 ( API) 和 JConsole动态写入。com.sun.management.HotSpotDiagnosticMXBean

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

打印 VM 标志选项及其当前值

作为-all选项

打印 VM 支持的所有标志

使用命令:-

jcmd <pid> VM.flags -all
于 2017-10-17T08:13:42.620 回答