"jcmd 0 GC.*" - Running GC Diagnostic Commands

This section provides a tutorial example on how to use 'jcmd 0 GC.*' commands to get heap information, run GC or generate heap dump file, of a given JVM.

Similar to VM.* diagnostic commands, I can run GC.* diagnostic commands the LongSleep JVM:

herong> jcmd LongSleep GC.heap_info
1928:
 garbage-first heap   total 61440K, used 1024K [0x00000000c4000000, ...)
  region size 1024K, 2 young (2048K), 0 survivors (0K)
 Metaspace used 4971K, capacity 5040K, committed 5120K, reserved 1056768K
  class space used 406K, capacity 447K, committed 512K, reserved 1048576K
 
herong> jcmd LongSleep GC.finalizer_info
1928:
No instances waiting for finalization found
 
herong> jcmd LongSleep GC.class_stats
1928:
Index Super InstBytes KlassBytes Bytecodes ... ClassName
    1    -1    169552        472         0 ... [B
    2    -1     92200        472         0 ... [Ljava.lang.Object;
    3    51     90384        640      5437 ... java.lang.Class
    4    51     76736        552       149 ... java.util.HashMap$Node
    5    51     76224        584      4108 ... java.lang.String
...

herong> jcmd LongSleep GC.class_histogram
1928:
 num     #instances         #bytes  class name (module)
-------------------------------------------------------
   1:          3273         169552  [B (java.base@10.0.1)
   2:          1373          92200  [Ljava.lang.Object; (java.base@10.0.1)
   3:           739          90384  java.lang.Class (java.base@10.0.1)
   5:          3176          76224  java.lang.String (java.base@10.0.1)
   8:            16          42448  [C (java.base@10.0.1)
...
   
herong> jcmd LongSleep GC.heap_dump LongSleep.heap
1928:
Heap dump file created   

herong> jcmd LongSleep GC.run
1928:
Command executed successfully

Not too bad. GC.* diagnostic commands can let us do a number of things with the GC without using any other fancy diagnostic tools.

Table of Contents

 About This Book

 Java Tools Terminology

 Java Tools Included in JDK

 javac - The Java Program Compiler

 jar - The JAR File Tool

 jlink - The JRE Linker

 jmod - The JMOD File Tool

 jimage - The JIMAGE File Tool

 jpackage - Binary Package Builder

 java - The Java Program Launcher

 jdeps - The Java Class Dependency Analyzer

 jdeprscan - The Java Deprecated API Scanner

 jdb - The Java Debugger

jcmd - The JVM Diagnostic Tool

 jcmd - JVM Diagnostic Tool Command

 "jcmd 0 help" - Listing JVM Diagnostic Commands

 "jcmd 0 VM.*" - Running VM Diagnostic Commands

"jcmd 0 GC.*" - Running GC Diagnostic Commands

 "jcmd 0 Thread.print" - Generating Thread Dump

 jconsole - Java Monitoring and Management Console

 jstat - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jhsdb - The Java HotSpot Debugger

 jvisualvm (Java VisualVM) - JVM Visual Tool

 jmc - Java Mission Control

 javap - The Java Class File Disassembler

 keytool - Public Key Certificate Tool

 jarsigner - JAR File Signer

 jshell - Java Language Shell

 jrunscript - Script Code Shell

 serialver - serialVersionUID Generator

 native2ascii - Native-to-ASCII Encoding Converter

 Outdated Tutorials

 References

 Full Version in PDF/EPUB