Sahil Gupta
Sahil Gupta

Reputation: 2166

Concurrent Mark and sweep algo

Below is what i read & understand about the Concurrent Mark and sweep algo

1) In the initial marking, the GC root objects are marked as alive. During this phase, all threads of the application are suspended.

2) During concurrent marking, the marked root objects are traversed and all reachable objects are marked. This phase is fully concurrent with application execution, so all application threads are active and can even allocate new objects. For this reason there might be another phase that marks objects that have been allocated during the concurrent marking. This is sometimes referred to as pre-cleaning and is still done concurrent to the application execution.

3) In the final marking, all threads are suspended and all remaining newly allocated objects are marked as alive.

Question: Since there is a final marking phase in this algorithm, during which application threads get's suspended so how does this algorithm is faster in comparison to the parallel GC ?

Upvotes: 1

Views: 419

Answers (1)

the8472
the8472

Reputation: 43052

so how does this algorithm is faster in comparison to the parallel GC ?

It's not faster in the sense of CPU cycles burned on garbage collection. It's "faster" in the sense that it achieves lower average / Nth percentile pause times compared to the parallel GC.

The price paid for that is

  • more CPU cycles burned on concurrent phases.
  • the lack of compacting, which leads to fragmentation, which may eventually lead to a so-called concurrent-mode failure, which - at the moment - is a single-threaded, stop-the-world full GC
    • the absence of compacting also makes object promotion more expensive since it can't just use bump-pointer allocation
  • more, but shorter, pauses

Edit, for your followup questions:

Initial and final marking are not equivalent to the mark phase of a STW mark-sweep collector. They are only part of the complete mark phase. Meaning that not all marking work is done during the pause. The rest is done concurrently.

So this markup uses all the cpu cores or it is single threaded in CMS ?

You can figure that out yourself by comparing CPU time to wall time.

Upvotes: 1

Related Questions