Usage:
This flag allows you to set the percentage CMS generation occupancy to start a CMS collection cycle:
-XX:CMSInitiatingOccupancyFraction=percent , where percent is the desired value in % between 0 and 100 or a negative value.
Since:
Starting from JDK 6.
Deprecated:
- Obsoleted in JDK 14
- Expired in JDK 15
Examples:
This will instruct JVM to use 50% of CMS generation occupancy:
-XX:CMSInitiatingOccupancyFraction=50
Description:
Before talking about the flag, we need to introduce Garbage Collector (GC) and Concurrent Mark Sweep (CMS):
Garbage Collector is a way of the JVM to clean the memory and makes the java memory more efficient. It tracks (Mark step) and removes (sweep step) every unused object available in the JVM heap space. An object is considered unused when it’s referenced by null, assigned to another reference or by anonymous object …. There are 5 type of GC implementations:
- Serial Garbage Collector
- Parallel Garbage Collector
- CMS Garbage Collector
- G1 Garbage Collector
- Z Garbage Collector
CMS Garbage Collector, as mentioned above, is one of the implementations of GC, which uses multiple thread for garbage collection. It’s created for applications that favor shorter garbage collection pauses and that can afford to share processor resources with the garbage collector while the application is running. It achieves long pauses by two ways:
- By using free lists to manage reclaimed space instead of compacting the Old Generation.
- By doing mainly the job in Mark (marking a reference) and Sweep (removing the marked reference) process simultaneously with the application. Which means that the GC is not stopping or freezing the application’s threads to do its job. But it does take part of using the CPU time with the application. By default, GC algorithm can use number of threads up to ¼ of the number of physical cores of your machine.
Accordingly, the flag “CMSInitiatingOccupancyFraction” sets the percentage of the old generation occupancy (0 to 100) at which to start a CMS collection cycle. For example, when you set the flag to a 50 with “-XX:CMSInitiatingOccupancyFraction=50” and the Old Generation is 50% full, the GC CMS collector starts sweeping unreferenced objects.
Any negative value (including the default) implies that the option -XX:CMSTriggerRatio is used to define the value of the initiating occupancy fraction.
Default Value:
Default is 65%.
Note:
When setting this flag, the GC CMS will only start collecting after the Old Generation is occupied at the value mentioned after argument. If you want to start the GC CMS only at the value given, then you should rather use the flag “XX:+UseCMSInitiatingOccupancyOnly”
Errors:
The value should be between any negative value and 100.
Arguments related:
CMSScavengeBeforeRemark, CMSClassUnloadingEnabled, CMSScavengeBeforeRemark, CMSIncrementalSafetyFactor, UseCMSInitiatingOccupancyOnly, CMSPermGenSweepingEnabled, UseConcMarkSweepGC and CMSTriggerRatio.
Related Posts:
Edit your Comment