JVM configuration details
jcmd VM.command_line
jcmd VM.version
jcmd VM.system_properties
jinfo -sysprops
or
jcmd VM.flags
jinfo -flags
or
On fly JMX port configuration
Start listening to JMX on specified port
jcmd ManagementAgent.start
jmxremote.authenticate=false
jmxremote.host= jmxremote.port=
jmxremote.rmi.port= jmxremote.ssl=false
See more details on https://docs.oracle.com/javase/8/docs/
technotes/guides/management/agent.html
Stop listening to JMX
jcmd ManagementAgent.stop
-Djava.rmi.server.hostname=
If port is not working with remote connection or SSH port
forwarding, you may need to add following options to JVM
startup (cannot be applied on running JMV).
Use 127.0.0.1 as host if you plan to use SSH port forwarding
On fly modify -XX JVM options
Only sub set of options could be changed at runtime.
You can use command below to list them.
jcmd VM.set_flag PrintGC true
jinfo -flag PrintGC=1
or
jcmd VM.flags -all | grep manageable
GC Runtime control
jcmd GC.rotate_log
jcmd GC.run System.gc()
jcmd GC.run_finalization
System.runFinalization()
jmap -histo:live FullGC as side effect
JVM heap information
jmap -heap
jstat -gc
-gc[meta|new|old]capacity
-gccapacity -gccause -gcutil
Alternative gc related options
jstat aberations
E* – Eden
S0* – Survivor 0
O*|OG* – Old space
CCS* – Compressed class space
M*|MC* – Metaspace
YGC|FGC – Youg|Full GC count
YGCT|FGCT – Youg|Full GC cumulative time
Java Flight Recorder control
jcmd VM.unlock_commercial_features
or use -XX:+UnlockCommercialFeatures on start
jcmd JFR.start
jcmd JFR.start settings=profile
jcmd JFR.start settings=/path_to/jfr.xml
jcmd JFR.check Show active recordings
jcmd JFR.dump recording=1 filename=dump.jfr
jcmd JFR.stop recording=1
Use absolute path. Relative path is calcurated from JRE/lib/jfr
Dump is created relative to target JVM working directory
jcmd help JFR.start
See more options available for Flight Recorder via help
Thread dump
jcmd Thread.print
jstack
jcmd Thread.print -l
or
jstack -l
or
Display lock information in stack trace
jstack -m
Display both native and Java stack frames
Buggy, requires JVM debug symbols
Heap dump / Class histogram
jcmd GC.class_histogram [-all]
jmap -histo[:live]
or
“live” option is forcing Full GC before heap inspection, “-all” does opposite
Class histogram
jcmd GC.heap_dump filename=dump.hprof [-all]
jmap -dump:file=dump.hprof[,live]
or
Heap dump
Class / compiler statistic
jstat -printcompilation
jstat -compiler
jstat -class
Native memory tracking
-XX:NativeMemoryTracking=[summary|detail]
Native memory tracking should be enabled on startup
jcmd VM.native_memory [detail=true]
Native memory tracking may not track memory
allocated via C runtime (e.g. zlib)
-XX:+PreserveFramePointer
Better use with
Command can be used with JVM core dump. These command also have -F option to deal with unresponsive JVM.
Alexey Ragozin – http://blog.ragozin.info
JDK command line tools cheatsheet Java 8
[email protected]
https://training.ragozin.info/collateral/JDK_tools_cheatsheet.pdf