Serial GC Tracing - Tight Heap

This section provides a tutorial on tracing how Serial GC works with a tight heap size.

We know that our test program GarbageCollection.java works on an array of 32 MB data. Let's run with a tight heap size of 40 MB and watch how the Serial GC does garbage collections.

"gc=info", "gc+heap=debug" and "-Xlog:gc+age=trace" options are used to print GC tracing information:

herong> java -Xms40m -Xmx40m -XX:+UseSerialGC \
   -Xlog:gc=info,gc+heap=debug,gc+age=trace GarbageCollection

The first Young GC happened during the JVM startup process, because the "eden" space was full with 10944K new objects:

[debug][gc,heap] GC(0) Heap before GC invocations=0 (full 0):
                        def new generation   total 12288K, used 10944K [...
[debug][gc,heap] GC(0)   eden space 10944K, 100% used [...
[debug][gc,heap] GC(0)   from space 1344K,   0% used [...
[debug][gc,heap] GC(0)   to   space 1344K,   0% used [...
[debug][gc,heap] GC(0)  tenured generation   total 27328K, used 0K [...
[debug][gc,heap] GC(0)    the space 27328K,   0% used [...

[debug][gc,age] GC(0) Desired survivor size 688128 bytes,
                       new threshold 1 (max threshold 15)
[trace][gc,age] GC(0) Age table with threshold 1 (max threshold 15)
[trace][gc,age] GC(0) - age   1:    1376256 bytes,    1376256 total

[info][gc,heap] GC(0) DefNew: 10944K->1344K(12288K)
[info][gc,heap] GC(0) Tenured: 0K->2024K(27328K)
[info][gc] GC(0) Pause Young (Allocation Failure) 10M->3M(38M) 7.485ms

[debug][gc,heap] GC(0) Heap after GC invocations=1 (full 0):
                        def new generation   total 12288K, used 1344K [...
[debug][gc,heap] GC(0)   eden space 10944K,   0% used [...
[debug][gc,heap] GC(0)   from space 1344K, 100% used [...
[debug][gc,heap] GC(0)   to   space 1344K,   0% used [...
[debug][gc,heap] GC(0)  tenured generation   total 27328K, used 2024K [...
[debug][gc,heap] GC(0)    the space 27328K,   7% used [...

Notes on the above GC:

The second Young GC happened after another 3 iterations, because the "eden" space was 99% full again with new objects.

Step/TotalMemory/FreeMemory/UsedMemory:
1   40566784   29467528   11099256
2   40566784   27789568   12777216
3   40566784   26699544   13867240
[debug][gc,heap] GC(1) Heap before GC invocations=1 (full 0):
                        def new generation   total 12288K, used 12285K [...
[debug][gc,heap] GC(1)   eden space 10944K,  99% used [...
[debug][gc,heap] GC(1)   from space 1344K, 100% used [...
[debug][gc,heap] GC(1)   to   space 1344K,   0% used [...
[debug][gc,heap] GC(1)  tenured generation   total 27328K, used 2025K [...
[debug][gc,heap] GC(1)    the space 27328K,   7% used [...

[trace][gc,age ] GC(1) Age table with threshold 1 (max threshold 15)
[trace][gc,age ] GC(1) - age   1:    1376248 bytes,    1376248 total

[info ][gc,heap] GC(1) DefNew: 12285K->1343K(12288K)
[info ][gc,heap] GC(1) Tenured: 2025K->7255K(27328K)
[info ][gc     ] GC(1) Pause Young (Allocation Failure) 13M->8M(38M) 9.055ms

[debug][gc,heap] GC(1) Heap after GC invocations=2 (full 0):
                        def new generation   total 12288K, used 1343K [...
[debug][gc,heap] GC(1)   eden space 10944K,   0% used [...
[debug][gc,heap] GC(1)   from space 1344K,  99% used [...
[debug][gc,heap] GC(1)   to   space 1344K,   0% used [...
[debug][gc,heap] GC(1)  tenured generation   total 27328K, used 7255K [...
[debug][gc,heap] GC(1)    the space 27328K,  26% used [...

Notes on the above GC:

Table of Contents

 About This Book

 Heap Memory Area and Size Control

 JVM Garbage Collection Logging

 Introduction of Garbage Collectors

Serial Collector - "+XX:+UseSerialGC"

 What Is Serial Collector

 GC Log Message Format for Serial Collector

 GC Log Message Examples of Serial Collector

 Log Message Types from Serial Collector

 Serial Collector Stops Application for Minor/Major GC

 Usage Report on Heap Memory Areas

 Default NewRatio - Old vs. New Generation

 "-XX:NewRatio" - Ratio of Tenured and "new" Generation

 "-XX:SurvivorRatio" - Ratio of Eden and Survivor Space

Serial GC Tracing - Tight Heap

 Serial GC Tracing - Tight Heap (Part 2)

 Serial GC Tracing - Tight Heap (Part 3)

 Serial GC Tracing - Plenty of Heap

 Serial GC Tracing - Aged Live Objects

 Serial GC Tracing - Tenuring Threshold

 "-XX:TargetSurvivorRatio" - Second Tenuring Condition

 Serial GC Tracing - Tenuring Threshold Controlled

 "-XX:+NeverTenure" and "-XX:+AlwaysTenure" Working

 Minor GC Triggering Condition of Serial Collector

 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