Usage:
This flag allows you to enable scavenging attempts before the Concurrent Mark Sweep (CMS) remark step.
Since:
Starting from JDK 6.
Deprecated:
Obsoleted in JDK 14.
Expired in JDK 15.
Examples:
To enable scavenging in your application, you can add the argument as the following:
java -XX:+CMSScavengeBeforeRemark 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.
JDK introduced since its version 6 many arguments to manage and control CMS, one of them is our main topic, “CMSScavengeBeforeRemark”. This flag allows the JVM to perform a minor GC on the young generation before re-marking, so that the number of objects remaining to be marked in the young gen will be much lower than before the GC (only the surviving objects remain, and a large number of dead objects will be killed by the GC), the number of remaining objects regarded as "GC ROOTS" has plummeted, so the workload of remarking is much less, and the time overhead of remarking will also be reduced.
Default Value:
By default, this flag is disabled.
Arguments related:
CMSInitiatingOccupancyFraction, CMSScavengeBeforeRemark, CMSClassUnloadingEnabled, CMSScavengeBeforeRemark, CMSIncrementalSafetyFactor, UseCMSInitiatingOccupancyOnly, CMSPermGenSweepingEnabled, UseConcMarkSweepGC, CMSIncrementalMode, CMSIncrementalDutyCycle, CMSIncrementalDutySafetyFactor, CMSIncrementalOffset, CMSIncrementalPacing, CMSTriggerRatio and CMSIncrementalDutyCycleMin
Related Posts:
Edit your Comment