Usage:
The option “-XX:+UseCMSInitiatingOccupancyOnly” use occupancy as a criterion for starting a Concurrent Mark Sweep (CMS) collector.
Since:
Starting from JDK 6.
Deprecated:
- Obsoleted in JDK14
- Expired in JDK15.
Syntax:
java -XX:+UseCMSInitiatingOccupancyOnly MainClass
Examples:
To turn on the detailed logs for Garbage Collector: java -XX:+UseCMSInitiatingOccupancyOnly MainClass
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.
Thus, this option is used to instruct the JVM not to base its decision when to start a Concurrent Mark Sweep (CMS) cycle on run time statistics. Instead, when this flag is enabled, the JVM uses the value of “CMSInitiatingOccupancyFraction” for every CMS cycle, not just for the first one. However, keep in mind that in the majority of cases the JVM does a better job of making GC decisions than us humans. Therefore, we should use this flag only if we have good reason (i.e., measurements) as well as really good knowledge of the lifecycle of objects generated by the application.
Default Value:
By default, this option is disabled and other criteria may be used.
Errors
None.
Related arguments:
CMSInitiatingOccupancyFraction, CMSScavengeBeforeRemark, CMSClassUnloadingEnabled, CMSScavengeBeforeRemark, CMSIncrementalSafetyFactor, CMSPermGenSweepingEnabled, CMSIncrementalMode and UseConcMarkSweepGC
Related Posts:
Edit your Comment