Java GC Tutorials - Herong's Tutorial Examples - v1.12, by Herong Yang
Serial GC Tracing - Tenuring Threshold Controlled
This section provides a tutorial showing how to control Serial collector Tenuring threshold with InitialTenuringThreshold and MaxTenuringThreshold JVM options.
In previous tutorials, we learned that the Serial collector controls objects tenuring using the tenuring threshold (default is 15 age old). When a live object reaches the tenuring threshold age, it is considered as matured to be promoted to tenured generation.
But if the survivor space usage reaches the TargetSurvivorRatio (default is 50% used), all remaining live objects will be promoted to tenured generation regardless of their ages.
The Serial collector also dynamically adjust the tenuring threshold based on current survivor space usage.
If we give enough survivor space, live objects may stay in Young generation for a long time surviving up to 15 times of Minor GCs. This may have performance impact on your application. An object of age 15 means that it has been copied 15 times between the two survivor spaces ("from" and "to" spaces).
If we want to change the default behavior, we can use InitialTenuringThreshold and MaxTenuringThreshold JVM options:
Let's try it with our test program GarbageCollection2.java with fixed new generation size option of "-XX:NewSize=102m":
herong> java -Xms105m -Xmx105m -XX:+UseSerialGC \ -XX:NewSize=102m -XX:SurvivorRatio=1v -XX:TargetSurvivorRatio=99 \ -XX:InitialTenuringThreshold=3 -XX:MaxTenuringThreshold=3 \ -Xlog:gc=info,gc+heap=debug,gc+age=trace GarbageCollection2 ... 108 75956224 7997424 67958800 [debug][gc,heap] GC(3) Heap before GC invocations=3 (full 0): def new generation total 68864K, used 66366K ... [debug][gc,heap] GC(3) eden space 34496K, 97% used [... [debug][gc,heap] GC(3) from space 34368K, 94% used [... [debug][gc,heap] GC(3) to space 34368K, 0% used [... [debug][gc,heap] GC(3) tenured generation total 5312K, used 0K ... [debug][gc,heap] GC(3) the space 5312K, 0% used [... [debug][gc,age ] GC(3) Desired survivor size 34840896 bytes, new threshold 3 (max threshold 3) [trace][gc,age ] GC(3) Age table with threshold 3 (max threshold 3) [trace][gc,age ] GC(3) - age 1: 24117752 bytes, 24117752 total [trace][gc,age ] GC(3) - age 2: 4195104 bytes, 28312856 total [trace][gc,age ] GC(3) - age 3: 3145776 bytes, 31458632 total [info ][gc,heap] GC(3) DefNew: 66366K->30721K(68864K) [info ][gc,heap] GC(3) Tenured: 0K->2876K(5312K) [info ][gc ] GC(3) Pause Young (Allocation Failure) 64M->32M(72M) 12.245ms [debug][gc,heap] GC(3) Heap after GC invocations=4 (full 0): def new generation total 68864K, used 30721K ... [debug][gc,heap] GC(3) eden space 34496K, 0% used [... [debug][gc,heap] GC(3) from space 34368K, 89% used [... [debug][gc,heap] GC(3) to space 34368K, 0% used [... [debug][gc,heap] GC(3) tenured generation total 5312K, used 2876K ... [debug][gc,heap] GC(3) the space 5312K, 54% used [...
As you can see from the output, Minor GC #4 promoted 2876K objects to tenured generation, because the maximum tenuring threshold was set to 3. Those objects would grow to age 4, if left in the survivor space.
Table of Contents
Heap Memory Area and Size Control
JVM Garbage Collection Logging
Introduction of Garbage Collectors
►Serial Collector - "+XX:+UseSerialGC"
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