Concurrent Mark and Sweep algorithm details

2020-02-08 08:23发布

问题:

I am struggling to understand and get more details on the steps involved in CMS tenured collection cycles.

  1. Initial Mark
  2. Concurrent Mark
  3. Concurrent pre-clean
  4. Re-mark
  5. Concurrent Sweep
  6. Concurrent Reset

These steps are explained in lot of places in very short. But if I have to describe them in a class with diagrams and psuedo-examples where can I get that information from?

PS - I have searched extensively on Google, it throws up with a lot of textual stuff and jargon which I understand. But I am looking for a more animated explanation so that I can teach my audience.

These are some of the links which are popular, the 3rd one was very promising but it failed to explain the CMS in particular

  1. http://www.infoq.com/articles/Java_Garbage_Collection_Distilled
  2. http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html
  3. http://www.cubrid.org/blog/dev-platform/understanding-java-garbage-collection/

Dear all, thanks for commenting and pointing me to some resources. I have tried to create a visual representation of the CMS steps, can you please let me know if this matches your understanding ?

Also I seem to be missing the Compacting step, which step does it belong to ?

Answer : Ok so compacting is not handled by CMS, instead it is delegated to full GC.

回答1:

For me

http://insightfullogic.com/blog/2013/may/7/garbage-collection-java-3

with its predecessors

http://insightfullogic.com/blog/2013/feb/20/garbage-collection-java-1
http://insightfullogic.com/blog/2013/mar/6/garbage-collection-java-2

made it clear. I'd forgotten that I'd also read the links mentioned by @gap_j above, which are very good too.

You asked where the Compacting step is, but CMS does not have one. This can lead to its own issues, particularly it can increase the cost of allocating memory (because the JVM has to use list to keep track of which memory is free, and can't just allocate memory from the end of the occupied space) and it can sometimes mean a fragmented heap.



回答2:

Starting java 1.5, there is another phase that is missed out is the "concurrent abortable preclean". It aims to delay the remark until there is a desired occupancy is achieved in the Eden space.

Other than that you are pretty much on track.

I suggest you look at this old oracle gc whitepaper and this step by step description of the CMS gc logs . It confirms the steps you have put in the images.

This blog post summarizes things well.