Java GC Tutorials - Herong's Tutorial Examples - v1.11, by Dr. Herong Yang
"-XX:MaxTenuringThreshold=0" - Tenuring Objects Immediately
This section provides a tutorial on how to use '-XX:MaxTenuringThreshold=0' to force objects being promoted immediately to Tenured generation. This will result more Major GCs.
Earlier, we learned how to give a large Young generation to limit the GC in the Young generation using the ParNew collector only.
In this tutorial, let's try to use the "-XX:MaxTenuringThreshold=0" JVM option to perform Tenured generation GC and Young generation GC:
herong> java -XX:+UseConcMarkSweepGC \ -Xms80m -Xmx80m -XX:NewRatio=3 -XX:SurvivorRatio=18 \ -XX:MaxTenuringThreshold=0 \ -Xlog:gc,gc+heap=debug,gc+age=trace \ GarbageCollection2 > output.txt herong> more output.txt Using Concurrent Mark Sweep Step/TotalMemory/FreeMemory/UsedMemory: 1 82837504 80656320 2181184 ... 16 82837504 64172304 18665200 GC(0) Desired survivor size 524288 bytes, new threshold 0 (max threshold 0) GC(0) Age table with threshold 0 (max threshold 0) GC(0) ParNew: 18227K->0K(19456K) GC(0) CMS: 0K->12104K(61440K) GC(0) Pause Young (Allocation Failure) 17M->11M(79M) 10.493ms -- GC #0 - Young generation only -- All live objects were promoted directly -- from "eden" space to "tenured" generation -- because of -XX:MaxTenuringThreshold=0 ... 33 82837504 52246896 30590608 GC(1) ParNew: 17769K->0K(19456K) GC(1) CMS: 12104K->24392K(61440K) GC(1) Pause Young (Allocation Failure) 29M->23M(79M) 6.775ms -- GC #1 - Young generation only -- More live objects were promoted directly to the Tenured generation ... 50 82837504 39662368 43175136 GC(2) ParNew: 17770K->0K(19456K) GC(2) CMS: 24392K->36680K(61440K) GC(2) Pause Young (Allocation Failure) 41M->35M(79M) 6.169ms -- GC #2 - Young generation only -- Old generation usage went to 36680K out of 61440K, about 60% GC(3) Pause Initial Mark 37M->37M(79M) 0.414ms -- Old generation usage of 60% triggered GC #3, which is a CMS GC ... GC(3) Concurrent Mark 65 82837504 29176944 53660560 GC(3) Concurrent Mark 2.348ms -- GC #3 step ran concurrently GC(3) Concurrent Preclean 66 82837504 28128352 54709152 67 82837504 27079760 55757744 GC(3) Concurrent Preclean 0.139ms -- GC #3 step ran concurrently GC(3) Concurrent Abortable Preclean GC(4) ParNew: 17954K->0K(19456K) GC(4) CMS: 36680K->47944K(61440K) GC(4) Pause Young (Allocation Failure) 53M->46M(79M) 5.878ms 68 82837504 32693472 50144032 -- GC #4 (Young GC) performed while GC #3 (Old GC) was still running ... 84 82837504 15546832 67290672 GC(3) Concurrent Abortable Preclean 14.492ms GC(6) Pause Full (Allocation Failure) 76M->27M(79M) 7.637ms GC(5) ParNew: 17768K->0K(19456K) GC(5) CMS: 47944K->28389K(61440K) GC(5) Pause Young (Allocation Failure) 64M->27M(79M) 14.113ms -- GC #3 (Old GC) did not reach the end - cancelled by Full GC #11 -- GC #6 (Full GC) performed, because heap full -- But no details printed for GC #6 -- GC #5 (Young GC) performed - may be part of GC #6 -- Not sure why GC #6 printed before GC #5.
... 101 82837504 35448056 47389448 GC(7) ParNew: 17888K->0K(19456K) GC(7) CMS: 28389K->38632K(61440K) GC(7) Pause Young (Allocation Failure) 45M->37M(79M) 2.114ms GC(8) Pause Initial Mark 39M->39M(79M) 0.115ms GC(8) Concurrent Mark -- GC #7 (Young GC) moved more objects to Old generation -- That triggered GC #8 (Old GC) 112 82837504 31374912 51462592 GC(8) Concurrent Mark 1.271ms GC(8) Concurrent Preclean 113 82837504 30326320 52511184 GC(8) Concurrent Preclean 0.115ms GC(8) Concurrent Abortable Preclean ... 118 82837504 25083360 57754144 GC(9) ParNew: 17768K->0K(19456K) GC(9) CMS: 38632K->52968K(61440K) GC(9) Pause Young (Allocation Failure) 55M->51M(79M) 3.210ms -- GC #9 (Young GC) performed while GC #8 (Old GC) was still running GC(8) Concurrent Abortable Preclean 6.264ms GC(11) Pause Full (Allocation Failure) 69M->29M(79M) 7.138ms GC(10) ParNew: 17768K->0K(19456K) GC(10) CMS: 52968K->30437K(61440K) GC(10) Pause Young (Allocation Failure) 69M->29M(79M) 7.227ms -- GC #9 (Old GC) did not reach the end - cancelled by Full GC #11 -- GC #11 (Full GC) performed, because heap full -- But no details printed for GC #11 -- GC #10 (Young GC) performed - may be part of GC #11 ... -- Many Old GC started and cancelled by Full GC ... 254 82837504 31376064 51461440 GC(22) ParNew: 17769K->0K(19456K) GC(22) CMS: 32486K->46824K(61440K) GC(22) Pause Young (Allocation Failure) 49M->45M(79M) 2.816ms GC(23) Pause Initial Mark 46M->46M(79M) 0.106ms GC(23) Concurrent Mark -- GC #22 (Young GC) moved more objects to Old generation -- That triggered GC #23 (Old GC) ... 266 82837504 21884688 60952816 GC(23) Concurrent Mark 1.429ms GC(23) Concurrent Preclean 267 82837504 20836096 62001408 GC(23) Concurrent Preclean 0.128ms GC(23) Concurrent Abortable Preclean GC(23) Concurrent Abortable Preclean 0.076ms 268 82837504 19787504 63050000 GC(23) Pause Remark 60M->60M(79M) 0.578ms GC(23) Concurrent Sweep 269 82837504 18738912 64098592 270 82837504 17690320 65147184 GC(23) Concurrent Sweep 0.317ms GC(23) Concurrent Reset GC(23) Concurrent Reset 0.097ms GC(23) Old: 46824K->32488K(61440K) -- GC #23 (Old GC) - the first Old GC reached the end! ...
Conclusion:
Table of Contents
Heap Memory Area and Size Control
JVM Garbage Collection Logging
Introduction of Garbage Collectors
Serial Collector - "+XX:+UseSerialGC"
Parallel Collector - "+XX:+UseParallelGC"
►Concurrent Mark-Sweep (CMS) Collector - "+XX:+UseConcMarkSweepGC"
What Is Concurrent Mark-Sweep (CMS) Collector
Concurrent Mark-Sweep Collector GC Log Message Format
Reduce Stop-The-World with Concurrent Mark and Sweep
Parallel New (ParNew) Collector for Minor GC
ParNew Collector - Tenuring Age Distribution
Maximum Logging of All Phases on Young GC
"-XX:ParallelGCThreads=6" - Young GC Parallel Threads
►"-XX:MaxTenuringThreshold=0" - Tenuring Objects Immediately
"-XX:CMSInitiatingOccupancyFraction=20" - Initiate CMS
Maximum Logging of All Phases on Old GC
Maximum Logging of All Phases on Full GC
"-XX:ParallelGCThreads=6" - Old GC Parallel Threads
"-XX:ConcGCThreads=3" - Old GC Concurrent Threads
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