问题描述
当我想更改HeapDumpAfterFullGC
标志时,我使用jps
查找程序的pid。
41123 Jps
5957
41031 Launcher
41032 Main # this is mine
然后我执行jcmd 41032 help
41032:
The following commands are available:
JFR.stop
JFR.start
JFR.dump
JFR.check
VM.native_memory
VM.check_commercial_features
VM.unlock_commercial_features
ManagementAgent.stop
ManagementAgent.start_local
ManagementAgent.start
GC.rotate_log
Thread.print
GC.class_stats
GC.class_histogram
GC.heap_dump
GC.run_finalization
GC.run
VM.uptime
VM.flags
VM.system_properties
VM.command_line
VM.version
help
For more information about a specific command use 'help <command>'.
VM.set_flags
未列出,而jcmd 0 help
具有:
5957:
The following commands are available:
Compiler.CodeHeap_Analytics
Compiler.codecache
Compiler.codelist
Compiler.directives_add
Compiler.directives_clear
Compiler.directives_print
Compiler.directives_remove
Compiler.queue
GC.class_histogram
GC.class_stats
GC.finalizer_info
GC.heap_dump
GC.heap_info
GC.run
GC.run_finalization
JFR.check
JFR.configure
JFR.dump
JFR.start
JFR.stop
jvmti.agent_load
jvmti.data_dump
ManagementAgent.start
ManagementAgent.start_local
ManagementAgent.status
ManagementAgent.stop
Thread.print
VM.class_hierarchy
VM.classloader_stats
VM.classloaders
VM.command_line
VM.dynlibs
VM.flags
VM.info
VM.log
VM.Metaspace
VM.native_memory
VM.print_touched_methods
**VM.set_flag** # this have it
VM.stringtable
VM.symboltable
VM.system_properties
VM.systemdictionary
VM.uptime
VM.version
help
For more information about a specific command use 'help <command>'.
41031:
The following commands are available:
JFR.stop
JFR.start
JFR.dump
JFR.check
VM.native_memory
VM.check_commercial_features
VM.unlock_commercial_features
ManagementAgent.stop
ManagementAgent.start_local
ManagementAgent.start
GC.rotate_log
Thread.print
GC.class_stats
GC.class_histogram
GC.heap_dump
GC.run_finalization
GC.run
VM.uptime
VM.flags
VM.system_properties
VM.command_line
VM.version
help
For more information about a specific command use 'help <command>'.
41032:
The following commands are available:
JFR.stop
JFR.start
JFR.dump
JFR.check
VM.native_memory
VM.check_commercial_features
VM.unlock_commercial_features
ManagementAgent.stop
ManagementAgent.start_local
ManagementAgent.start
GC.rotate_log
Thread.print
GC.class_stats
GC.class_histogram
GC.heap_dump
GC.run_finalization
GC.run
VM.uptime
VM.flags
VM.system_properties
VM.command_line
VM.version
help
For more information about a specific command use 'help <command>'.
我想知道为什么会这样,以及如何使用jcmd
来更改JVM的标志。
解决方法
可用的TaskType
命令的列表取决于目标JVM的版本。
jcmd
首先在JDK 9中命令appeared。
但是,VM.set_flag
在JDK 8中也是一个manageable选项。这意味着,即使HeapDumpAfterFullGC
中未列出该标志,也可以在运行时更改该标志。最简单的方法是使用jattach
实用程序:
jcmd
设置标记的另一种方法是JMX:例如,使用$ jattach <pid> setflag HeapDumpAfterFullGC 1
。
找到jconsole
MXBean并调用com.sun.management:type=HotSpotDiagnostic
操作:
jcmd
命令列出了目标JVM支持的命令。
它取决于目标JVM支持和实现哪些命令。
较新的JVM比较旧的JVM支持更多的命令。
例如,在我的计算机上,JDK 8 JVM接受以下命令,大约20条:
2237216: (JDK 8 JVM)
The following commands are available:
VM.native_memory
ManagementAgent.stop
ManagementAgent.start_local
ManagementAgent.start
VM.classloader_stats
GC.rotate_log
Thread.print
GC.class_stats
GC.class_histogram
GC.heap_dump
GC.finalizer_info
GC.heap_info
GC.run_finalization
GC.run
VM.uptime
VM.dynlibs
VM.flags
VM.system_properties
VM.command_line
VM.version
JDK 14 JVM接受了更多的命令,大约46条:
2218174:
The following commands are available:
Compiler.CodeHeap_Analytics
Compiler.codecache
Compiler.codelist
Compiler.directives_add
Compiler.directives_clear
Compiler.directives_print
Compiler.directives_remove
Compiler.queue
GC.class_histogram
GC.class_stats
GC.finalizer_info
GC.heap_dump
GC.heap_info
GC.run
GC.run_finalization
JFR.check
JFR.configure
JFR.dump
JFR.start
JFR.stop
JVMTI.agent_load
JVMTI.data_dump
ManagementAgent.start
ManagementAgent.start_local
ManagementAgent.status
ManagementAgent.stop
Thread.print
VM.class_hierarchy
VM.classloader_stats
VM.classloaders
VM.command_line
VM.dynlibs
VM.events
VM.flags
VM.info
VM.log
VM.metaspace
VM.native_memory
VM.print_touched_methods
VM.set_flag
VM.stringtable
VM.symboltable
VM.system_properties
VM.systemdictionary
VM.uptime
VM.version
help
因此,总而言之。您没有VM.set_flags
,因为您正在运行的目标JVM不支持它。
此外,我不确定VM.set_flags
会做什么。正如@ paulsm4所提到的,我很确定在事实不会改变实际行为之后更改'HeapDumpAfterFullGC'标志。我宁愿搜索是否有直接标志或JMX选项。