Java Garbage Collector and Log Levels
Currently, Parallel Scavenge (PS), Concurrent Mark Sweep (CMS), Garbage-First (G1), and ZGC garbage collector logs can be parsed. Java 8 supports PS, CMS, and G1; Java 9 and later versions support only G1; Java 17 and later versions support ZGC only.
If no data is obtained on the garbage collection (GC) log page, check whether the corresponding log level is enabled. That is, add parameters when starting the Java process. After the log level is enabled, you can view the log data. For details about log levels, see Table 1.
- Java 8 is used together with PS by default if no garbage collectors are specified when starting the process.
G1 garbage collector: -XX:+UseG1GC; CMS garbage collector: -XX:+UseConcMarkSweepGC; PS garbage collector: -XX:+UseParallelGC.
- When starting Java 8, add the log printing parameter -verbose:gc -XX:+PrintHeapAtGC -Xloggc:/filepath/filename.log or -XX:+PrintGCDetails -XX:+PrintHeapAtGC -Xloggc:/filepath/filename.log.
filepath indicates the log storage path, and filename indicates the log name. The log name supports dynamic parameters %p (PID) and %t (system timestamp).
- For details about the log printing parameter format in Java 9 and later, visit JEP 158: Unified JVM Logging.
- ZGC (JDK 15 and later): -XX:+UseZGC; generational ZGC (JDK 21 and later): -XX:+UseZGC -XX:+ZGenerational.
Java Version |
Garbage Collector |
Log Level |
Data Available |
|---|---|---|---|
Java 8 |
G1 |
-verbose:gc |
No data is available in the linearity, GC phases, eden space, survivor space, and metaspace. |
-XX:+PrintGCDetails |
All data can be displayed. Full GC events are recorded only when they exist in the metaspace. |
||
(Optional) -XX:+PrintHeapAtGC |
All data about memory usage changes can be displayed. |
||
CMS |
-verbose:gc |
No data is available in the linearity, GC phases, old generation, young generation, eden space, survivor space, and metaspace. |
|
-XX:+PrintGCDetails |
All data except that in the eden and survivor spaces can be displayed. Full GC events are recorded only when they exist in the metaspace. |
||
(Optional) -XX:+PrintHeapAtGC |
All data about memory usage changes can be displayed. |
||
PS |
-verbose:gc |
No data is available in the linearity, GC phases, old generation, young generation, eden space, survivor space, and metaspace. |
|
-XX:+PrintGCDetails |
All data except that in the eden and survivor spaces can be displayed. Full GC events are recorded only when they exist in the metaspace. |
||
(Optional) -XX:+PrintHeapAtGC |
All data about memory usage changes can be displayed. |
||
Java 9 and later |
G1 |
-Xlog:gc*=info |
The [gc] tag displays GC pause and heap change information. |
The [gc,cpu] tag displays the linearity information. |
|||
The [gc,marking] tag displays the parallel phase information. |
|||
-Xlog:gc*=debug |
The [gc,heap] tag displays the memory changes of the eden space, survivor space, and metaspace. |
||
The [gc,phases] tag displays details about the GC pauses. |
|||
Java 17 and later |
ZGC |
-Xlog:gc*=info |
The [gc,start] tag displays the GC cause, GC pause time, and heap change information. The [gc,phases] tag displays details about the GC pauses. |
-Xlog:gc*=debug |
The [gc,heap] tag displays the memory changes of the metaspace. |
||
Java 21 |
Generational ZGC |
-XX:+ZGenerational -Xlog:gc*=info |
The [gc,start] tag displays the GC cause, GC pause time, and heap change information. The [gc,phases tag displays the details of the GC pause and the memory changes of the young generation and generations. |
-XX:+ZGenerational -Xlog:gc*=debug |
The [gc,heap] tag displays the memory changes of the metaspace. |