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

This section describes the garbage collection logging option, '-Xlog:gc', which prints out log messages from the GC channel at the INFO level.

In the first test, let's try the "-Xlog:gc" garbage collection logging option to see what we will get in the log file.

C:\herong>java -Xms2m -Xmx64m -Xlog:gc:gc.log GarbageCollection

Step/TotalMemory/FreeMemory/UsedMemory:
1   2031616   698848   1332768
2   3874816   1473392   2401424
3   3874816   425688   3449128
4   8970240   4442016   4528224
...
(Ctrl-C)

C:\herong>type gc.log
[0.013s][info][gc] Using G1
[0.028s][info][gc] Periodic GC disabled
[0.056s][info][gc] GC(0) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.118s][info][gc] GC(1) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.154s][info][gc] GC(2) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.211s][info][gc] GC(3) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.246s][info][gc] GC(4) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.296s][info][gc] GC(5) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.320s][info][gc] GC(6) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.333s][info][gc] GC(7) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.349s][info][gc] GC(8) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.356s][info][gc] GC(9) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.371s][info][gc] GC(10) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.388s][info][gc] GC(11) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.398s][info][gc] GC(12) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.412s][info][gc] GC(13) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.478s][info][gc] GC(14) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.500s][info][gc] GC(15) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.503s][info][gc] GC(16) Pause Young (Concurrent Start) (G1 Evacuati...
[0.503s][info][gc] GC(17) Concurrent Cycle
[0.505s][info][gc] GC(18) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.508s][info][gc] GC(19) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.510s][info][gc] GC(17) Pause Remark 14M->14M(27M) 0.830ms
[0.513s][info][gc] GC(20) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.515s][info][gc] GC(17) Pause Cleanup 18M->18M(27M) 0.025ms
[0.515s][info][gc] GC(17) Concurrent Cycle 12.548ms
[0.519s][info][gc] GC(21) Pause Young (Prepare Mixed) (G1 Evacuation ...
[0.522s][info][gc] GC(22) Pause Young (Mixed) (G1 Evacuation Pause)  ...
[0.523s][info][gc] GC(23) Pause Young (Concurrent Start) (G1 Evacuat ...
[0.524s][info][gc] GC(24) Concurrent Cycle
[0.528s][info][gc] GC(25) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.533s][info][gc] GC(26) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.536s][info][gc] GC(27) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.538s][info][gc] GC(24) Pause Remark 34M->34M(59M) 0.934ms         ...
[0.540s][info][gc] GC(28) Pause Young (Normal) (G1 Evacuation Pause) ...
[0.543s][info][gc] GC(24) Pause Cleanup 38M->38M(61M) 0.050ms
[0.545s][info][gc] GC(24) Concurrent Cycle 21.163ms
...

The output shows that the JVM is using the G1 as the default garbage collector. The default logging level is INFO.

JVM supports multiple garbage collectors and each garbage collector uses different log message format. I will explain how to read log messages later when we have better understandings on how each garbage collector works.

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