What do you know about CMS?
Concurrent mark sweep CMS(concurrent mark sweep) has been used in jdk1.5, which was released on September 30,2004. The goal of CMS design is to obtain the minimum stop the world pause time, which is based on the mark-clear algorithm. A common scenario is an Internet web site (with high service response requirements), which is an old garbage collector that can be used in conjunction with the Serial collector and the Parallel New collector. The CMS degrades to Serial Old when concurrent mode failure occurs.
What is the workflow (steps) of the CMS collector?
Four main stages
- Initial tag: only tag objects that can be directly connected to GC Roots, fast, stop the world
- Concurrency flag: Execute concurrently with the application thread, traversal
Initial tag
Phase marked objects, marking the reachable objects of these objects. - Re-mark: due to
Concurrent tags
Is executed concurrently with the application thread, so some marked objects have changed. This process ratioInitial tag
For longer, but less thanConcurrent tags
Phases are short. Stop the world - Concurrent cleanup: Runs with application threads. Clean objects directly based on tag objects.
Disadvantages of CMS?
Debris problem
- Reason: Because CMS uses
Mark-clear
Algorithm, so inevitably there will be memory fragmentation. - Solution: Use
-XX:+CMSFullGCsBeforeCompaction=n
It means last timeCMS
concurrentGC
After implementation, how much more to doFull GC
Just do the compression. The default is 0, which means every timeCMS GC
Can’t hold up the turnFull GC
All the time.
Concurrent mode failure
- Cause: THE CMS garbage cleanup thread and the application thread execute concurrently, if the old age space is insufficient to accommodate the new object during the cleanup process.
- Solution: Use
-XX:+UseCMSInitiatingOccupancyOnly
and-XX:CMSInitiatingOccupancyFraction=60
To specify that GC starts when the CMS memory usage reaches 60%.
The re-marking phase takes too long
- Solution: Use
-XX:+CMSScavengeBeforeRemark
, in theTo mark
Before you do it, do it onceYoung GC
The purpose is to reduce the invalid reference of the young generation to the old generationTo mark
Overhead.
Why is it configuredCMS GC
“But it was triggeredFull GC
?
- When allocating large objects, the young generation can not put down, directly go to the old age, the result of the old age can not put down.
- Memory fragmentation issues (using
Mark-clear
Disadvantages of algorithm) CMS GC
Failure (caused by concurrent mode failure)- Jmap-histo executed the command manually