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:

C:\>\progra~1\java\jdk1.8.0\bin\java -Xms105m -Xmx105m 
   -XX:NewSize=102m -XX:SurvivorRatio=1
   -XX:TargetSurvivorRatio=99
   -XX:InitialTenuringThreshold=3 -XX:MaxTenuringThreshold=3
   -XX:+UseSerialGC -XX:+PrintGCDetails -XX:+PrintHeapAtGC
   -XX:+PrintTenuringDistribution GarbageCollection2

...   
{Heap before GC invocations=3 (full 0):
 def new generation   total 69632K, used 65443K [...
  eden space 34816K,  99% used [...
  from space 34816K,  88% used [...
  to   space 34816K,   0% used [...
 tenured generation   total 4096K, used 0K [...
   the space 4096K,   0% used [...
 Metaspace used 1567K, capacity 2242K, committed 2368K, reserved 4480K

[GC (Allocation Failure) [DefNew
Desired survivor size 35295068 bytes, new threshold 3 (max 3)
- age   1:   22020432 bytes,   22020432 total
- age   2:    7340144 bytes,   29360576 total
- age   3:    1048592 bytes,   30409168 total
: 65443K->29696K(69632K), 0.0114630 secs] 
   65443K->31990K(73728K), 0.0114985 secs] 

Heap after GC invocations=4 (full 0):
 def new generation   total 69632K, used 29696K [...
  eden space 34816K,   0% used [...
  from space 34816K,  85% used [...
  to   space 34816K,   0% used [...
 tenured generation   total 4096K, used 2294K [...
   the space 4096K,  56% used [...
 Metaspace used 1567K, capacity 2242K, committed 2368K, reserved 4480K
}

As you can see from the output, Minor GC #4 promoted 2294K 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.

Last update: 2018.

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 - 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" not 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"

 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

 Outdated Tutorials

 References

 Full Version in PDF/EPUB