"-XX:CMSInitiatingOccupancyFraction=20" - Initiate CMS

This section demonstrates that the '-XX:+UseCMSInitiatingOccupancyOnly' and '-XX:CMSInitiatingOccupancyFraction=20' JVM options can initiate CMS collector when Tenured generation occupancy reaches 20%.

In the last tutorial, we saw that the CMS collector was triggered when memory usage in the Tenured generation reached 60%.

If we want to start the CMS collector earlier, we can use "-XX:+UseCMSInitiatingOccupancyOnly" and "-XX:CMSInitiatingOccupancyFraction=20" JVM options to use the given 20% Tenured generation occupancy only to initiate CMS collector:

C:\herong>java -XX:+UseConcMarkSweepGC
   -Xms80m -Xmx80m -XX:NewRatio=3 -XX:SurvivorRatio=18
   -XX:MaxTenuringThreshold=0
   -XX:CMSInitiatingOccupancyFraction=20
   -XX:+UseCMSInitiatingOccupancyOnly
   -Xlog:gc,gc+heap=debug,gc+age=trace
   GarbageCollection2 > output.txt

C:\herong>type output.txt
...
16   82837504   64172304   18665200
GC(0) ParNew: 18227K->0K(19456K)
GC(0) CMS: 0K->13130K(61440K)
GC(0) Pause Young (Allocation Failure) 17M->12M(79M) 10.905ms
GC(1) Pause Initial Mark 13M->13M(79M) 0.328ms
GC(1) Concurrent Mark
   -- GC #0 (Young GC) moved 13130K objects to Tenured generation
   -- Tenured generation occupancy reached: 13130K/61440K = 21% > 20%
   -- This triggered GC #1 (Old GC) as expected

32   82837504   52244608   30592896
GC(1) Concurrent Mark 2.207ms
GC(1) Concurrent Preclean
33   82837504   51196016   31641488
GC(2) ParNew: 17769K->0K(19456K)
GC(2) CMS: 13130K->25418K(61440K)
GC(2) Pause Young (Allocation Failure) 30M->24M(79M) 6.030ms
   -- GC #2 (Young GC) performed while GC #1 (Old GC) was still running

GC(1) Concurrent Sweep
35   82837504   54340368   28497136
36   82837504   53298320   29539184
GC(1) Concurrent Sweep 0.548ms
37   82837504   52235568   30601936
GC(1) Concurrent Reset
38   82837504   53298408   29539096
39   82837504   52249816   30587688
40   82837504   51201224   31636280
GC(1) Concurrent Reset 0.326ms
GC(1) Old: 13130K->23364K(61440K)
   -- GC #1 (Old GC) - reached the end!

...
50   82837504   40715304   42122200
GC(3) ParNew: 17770K->0K(19456K)
GC(3) CMS: 23364K->36676K(61440K)
GC(3) Pause Young (Allocation Failure) 40M->35M(79M) 5.675ms
GC(4) Pause Initial Mark 36M->36M(79M) 0.077ms
GC(4) Concurrent Mark
   -- GC #3 (Young GC) moved more objects to Tenured generation
   -- Tenured generation occupancy reached: 36676K/61440K = 60% > 20%
   -- This triggered GC #4 (Old GC) as expected
...
61   82837504   33375656   49461848
GC(4) Concurrent Mark 1.417ms
GC(4) Concurrent Preclean
62   82837504   32327064   50510440
GC(4) Concurrent Preclean 0.136ms
GC(4) Concurrent Abortable Preclean
   -- GC #2 (Old GC) - continued concurrently

GC(5) ParNew: 17770K->0K(19456K)
GC(5) CMS: 36676K->46916K(61440K)
GC(5) Pause Young (Allocation Failure) 53M->45M(79M) 5.194ms
   -- GC #5 (Young GC) performed while GC #4 (Old GC) was still running

GC(4) Concurrent Abortable Preclean 16.344ms
GC(7) Pause Full (Allocation Failure) 76M->28M(79M) 8.291ms
GC(6) ParNew: 17954K->0K(19456K)
GC(6) CMS: 46916K->29414K(61440K)
GC(6) Pause Young (Allocation Failure) 63M->28M(79M) 16.381ms
   -- GC #4 (Old GC) was cancelled - Old generation was full
   -- GC #7 (Full GC) was performed
   -- GC #6 (Young GC) was also performed
...

Conclusion: "-XX:+UseCMSInitiatingOccupancyOnly" and "-XX:CMSInitiatingOccupancyFraction=20" JVM options can force CMS collector to initiate Tenured generation GC when Tenured generation occupancy reaches 20%.

Note that both "-XX:+UseCMSInitiatingOccupancyOnly" and "-XX:CMSInitiatingOccupancyFraction=20" JVM options must be used together.

Table of Contents

 About This Book

 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

 Maximium 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

 Maximium Logging of All Phases on Old GC

 Maximium 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

 Garbage Collection Performance Test Summary

 References

 Full Version in PDF/EPUB