Copied : Graphical Representation of Concurrent Mark and Sweep(CMS) GC

Copied : Graphical Representation of Concurrent Mark and Sweep(CMS) GC

  • perf-test.com need your contributions to build up a strong repository of performance engineering resources.

Came Across Very Good Pictorial Description of CMS Garbage Collection Stages which might in theory bit hard to understand.

CMS Collector has 5 phases for doing GC of Old Generation :
  1. Initial Mark (Stop the World Event).
  2. Concurrent Marking.
  3. Remark (Stop the World Event).
  4. Concurrent Sweep.
  5. Resetting.

(Copied Selected Part from Oracle Tutorials without any modification)

CMS Collector operations step by step.

Heap Structure for CMS Collector
The heap is split into three spaces.

slide1.png

Young generation is split into Eden and two survivor spaces. Old generation is one contiguous space. Object collection is done in place. No compaction is done unless there is a full GC.

How Young GC works in CMS

The young generation is colored light green and the old generation in blue. This is what the CMS might look like if your application has been running for a while. Objects are scattered around the old generation area.

slide2.png

With CMS, old generation objects are deallocated in place. They are not moved around. The space is not compacted unless there is a full GC.

Young Generation Collection

Live objects are copied from the Eden space and survivor space to the other survivor space. Any older objects that have reached their aging threshold are promoted to old generation.

slide3.png

After Young GC

After a young GC, the Eden space is cleared and one of the survivor spaces is cleared.

slide4.png

Newly promoted objects are shown in dark blue on the diagram. The green objects are surviving young generation objects that have not yet been promoted to old generation.

Old Generation Collection with CMS

Two stop the world events take place: initial mark and remark. When the old generation reaches a certain occupancy rate, the CMS is kicked off.

slide5.png

(1) Initial mark is a short pause phase where live (reachable) objects are marked. (2) Concurrent marking finds live objects while the application continues to execute. Finally, in the (3) remark phase, objects are found that were missed during (2) concurrent marking in the previous phase.

Old Generation Collection - Concurrent Sweep

Objects that were not marked in the previous phase are deallocated in place. There is no compaction.

slide6.png

Note: Unmarked objects == Dead Objects

Old Generation Collection - After Sweeping

After the (4) Sweeping phase, you can see that a lot of memory has been freed up. You will also notice that no compaction has been done.

slide7.png

Finally, the CMS collector will move through the (5) resetting phase and wait for the next time the GC threshold is reached.

Reference : http://www.oracle.com/technetwork/tutorials/tutorials-1876574.html
Author
Vaibhav
Views
66
First release
Last update
Rating
0.00 star(s) 0 ratings