Java 8 GC Tutorials - Herong's Tutorial Examples - v1.03, by Dr. Herong Yang
"-XX:+NeverTenure" and "-XX:+AlwaysTenure" not Working
This section provides a tutorial showing '-XX:+NeverTenure' and '-XX:+AlwaysTenure' JVM options are not working with the Serial collector.
HotSpot JVM also support two hidden options you can use to control tenuring behavior:
First, let's try "-XX:+NeverTenure" with our test program GarbageCollection2.java:
herong> \progra~1\java\jdk1.8.0\bin\java -Xms130m -Xmx130m \ -XX:NewSize=120m -XX:SurvivorRatio=1 \ -XX:+NeverTenure -Xloggc:gc.log \ -XX:+UseSerialGC -XX:+PrintGCDetails -XX:+PrintHeapAtGC \ -XX:+PrintTenuringDistribution GarbageCollection2 {Heap before GC invocations=15 (full 0): def new generation total 81920K, used 72729K [... eden space 40960K, 99% used [... from space 40960K, 78% used [... to space 40960K, 0% used [... tenured generation total 10240K, used 0K [... the space 10240K, 0% used [... Metaspace used 1567K, capacity 2242K, committed 2368K, reserved 4480K [GC (Allocation Failure) [DefNew Desired survivor size 41523608 bytes, new threshold 15 (max 15) - age 1: 25166208 bytes, 25166208 total - age 2: 5242960 bytes, 30409168 total - age 3: 2097184 bytes, 32506352 total - age 4: 72 bytes, 32506424 total - age 7: 56 bytes, 32506480 total : 72729K->31744K(81920K), 0.0084429 secs] 72729K->31991K(92160K), 0.0084774 secs] Heap after GC invocations=16 (full 0): def new generation total 81920K, used 31744K [... eden space 40960K, 0% used [... from space 40960K, 77% used [... to space 40960K, 0% used [... tenured generation total 10240K, used 246K [... the space 10240K, 2% used [... Metaspace used 1567K, capacity 2242K, committed 2368K, reserved 4480K }
The log message shows that some old objects were promoted to Tenured generation at Minor GC #16, even there were still some memory available in survivor space. The usage was 77%, lower than 99% given in "-XX:TargetSurvivorRatio=99" option.
So the "-XX:+NeverTenure" option is not working for Serial collector.
Now, let's try "-XX:+AlwaysTenure" with our test program GarbageCollection2.java:
herong> \progra~1\java\jdk1.8.0\bin\java -Xms130m -Xmx130m \ -XX:NewSize=120m -XX:SurvivorRatio=1 \ -XX:+AlwaysTenure -Xloggc:gc.log \ -XX:+UseSerialGC -XX:+PrintGCDetails -XX:+PrintHeapAtGC \ -XX:+PrintTenuringDistribution GarbageCollection2 ... {Heap before GC invocations=0 (full 0): def new generation total 81920K, used 40551K [... eden space 40960K, 99% used [... from space 40960K, 0% used [... to space 40960K, 0% used [... tenured generation total 10240K, used 0K [... the space 10240K, 0% used [... Metaspace used 1567K, capacity 2242K, committed 2368K, reserved 4480K [GC (Allocation Failure) [DefNew Desired survivor size 41523608 bytes, new threshold 15 (max 15) - age 1: 22273272 bytes, 22273272 total : 40551K->21751K(81920K), 0.0172061 secs] 40551K->21751K(92160K), 0.0172543 secs] Heap after GC invocations=1 (full 0): def new generation total 81920K, used 21751K [... eden space 40960K, 0% used [... from space 40960K, 53% used [... to space 40960K, 0% used [... tenured generation total 10240K, used 0K [... the space 10240K, 0% used [... Metaspace used 1567K, capacity 2242K, committed 2368K, reserved 4480K }
The "-XX:+AlwaysTenure" option is also not working for Serial collector. The first Minor GC listed above showing 22273272B objects stayed in the survivor space. Not promoted to the Tenured generation.
Conclusion:
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 - 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