Garbage Collection Logging Options

This section describes HotSpot JVM options to generate garbage collection log messages. '-Xlog:gc', '-Xlog:gc*=debug', '-Xlog:gc*=debug:file' are very useful options.

The previous tutorial showed us how to use totalMemory() and freeMemory() methods to observe the JVM garbage collection (GC) process. Now let's use JVM logging options to do the observation.

JVM command line options related to garbage collection logging have been changed since JVM 9. Below is a list of new options. See next tutorial on old options.

-Xlog:gc - Turn on GC logging at the default INFO level. Here are examples of INFO level GC log messages:

[0.012s][info][gc] Using G1
[0.027s][info][gc] Periodic GC disabled

-Xlog:gc=debug - Turn on GC logging at the given DEBUG level. Here are examples of DEBUG level GC log messages:

[0.010s][debug][gc] ConcGCThreads: 2 offset 16
[0.010s][debug][gc] ParallelGCThreads: 8
[0.011s][debug][gc] Initialize mark stack with 4096 chunks,
   maximum 16384

-Xlog:gc+heap=debug - Turn on GC+HEAP logging at the given DEBUG level. Here are examples of DEBUG level GC+HEAP log messages:

[0.010s][info][gc,heap] Heap region size: 1M
[0.010s][debug][gc,heap] Minimum heap 8388608  Initial heap 132120576
   Maximum heap 2109734912

-Xlog:gc*=debug - Turn on all GC related logging at the given DEBUG level. Here are examples of different types of GC log messages at the DEBUG level:

[0.011s][info][gc,heap] Heap region size: 1M
[0.011s][debug][gc,heap] Minimum heap 8388608  Initial heap 132120576
   Maximum heap 2109734912
[0.012s][debug][gc     ] ConcGCThreads: 2 offset 16
[0.012s][debug][gc     ] ParallelGCThreads: 8
[0.013s][debug][gc     ] Initialize mark stack with 4096 chunks,
   maximum 16384
[0.013s][debug][gc,ergo,heap] Expand the heap. requested expansion
   amount: 132120576B expansion amount: 132120576B
[0.014s][debug][gc,ihop     ] Target occupancy update: old: 0B,
   new: 132120576B
[0.014s][debug][gc,ergo,refine] Initial Refinement Zones: green: 8,
   yellow: 24, red: 40, min yellow size: 16
[0.015s][info ][gc            ] Using G1
[0.015s][info ][gc,heap,coops ] Heap address: 0x0000000082400000,
   size: 2012 MB, Compressed Oops mode: 32-bit
[0.032s][info ][gc            ] Periodic GC disabled
...
[0.052s][debug][gc,refine     ] Stopping 0
[0.052s][info ][gc,heap,exit  ] Heap
[0.052s][info ][gc,heap,exit  ]  garbage-first heap   total 129024K,
   used 1024K [...
   [gc,heap,exit  ]   region size 1024K, 2 young (2048K), 0 survivors
[0.052s][info ][gc,heap,exit  ]  Metaspace       used 151K,
   capacity 4480K, committed 4480K, reserved 1056768K
[0.052s][info ][gc,heap,exit  ]   class space    used 3K, capacity 384K,
   committed 384K, reserved 1048576K

-Xlog:gc*:file=<file> or -Xlog:gc*:<file> - Redirect the log messages to the given file instead of the console. For example, "-Xlog:gc:gc.log" will send regular GC log messages at the INFO level to a file called gc.log.

-verbose:gc - Same as "-Xlog:gc".

Table of Contents

 About This Book

 Heap Memory Area and Size Control

JVM Garbage Collection Logging

 Garbage Collection Demo Program

Garbage Collection Logging Options

 "-Xlog:gc" - Default GC Logging Level: INFO

 "-Xlog:gc=trace" - Lowest GC Logging Level: TRACE

 "-Xlog:gc+heap=trace" - GC+HEAP Log Messages

 "-Xlog:gc*=trace" - Maximum GC Logging

 "-XX:+PrintFlagsFinal" - Print JVM Options

 Introduction of Garbage Collectors

 Serial Collector - "+XX:+UseSerialGC"

 Parallel Collector - "+XX:+UseParallelGC"

 Concurrent Mark-Sweep (CMS) Collector - "+XX:+UseConcMarkSweepGC"

 Garbage First (G1) Collector - "+XX:+UseG1GC"

 The Z Garbage Collector (ZGC) - "+XX:+UseZGC"

 Object References and Garbage Collection

 Garbage Collection Performance Test Program

 Performance Tests on Serial Collector

 Performance Tests on Parallel collector

 Performance Tests on Concurrent collector

 Performance Tests on G1 collector

 Garbage Collection Performance Test Summary

 References

 Full Version in PDF/EPUB