emilly
emilly

Reputation: 10530

Why CMS is stop the world for Initial mark but not for sweeping phase?

There are 4 high level phases CMS works for full GC

  1. Initial mark :- Stop the world(STW)
  2. Concurrent marking :- Run concurrently
  3. Remark :- STW
  4. Concurrent sweeping:- Run concurrently

I have got high level understanding of CMS after reading

http://www.tikalk.com/java/garbage-collection-serial-vs-parallel-vs-concurrent-mark-sweep/ and https://plumbr.eu/handbook/garbage-collection-algorithms-implementations/concurrent-mark-and-sweep

My question is why initial mark stage is STW for Initial Mark phase ? Can't we have just Remark phase as STW as this is the final stage for reconciliation.

Similarly why Sweeping phase is not STW as it will require compaction which means change ofphsical location of object. So if object is referred by app and concurrent thread changes the phsical location, won't it be issue ?

I know i a missing something here but what's that ?

Upvotes: 3

Views: 1762

Answers (1)

Alexey Ragozin
Alexey Ragozin

Reputation: 8379

I assume you are referring Concurrent Mark Sweep implementation in Oracle's HotSpot JVM.

Initial mark phase include scanning young space (any young to old reference is root for concurrent mark). Remark phase includes very same operation.

In theory, you could omit STW for initial mark as scan it concurrent with risk of missing few root (which will be recovered during final remark any way). Though there are draw backs here

  • Scanning of memory may be inaccurate as young collection is moving objects. Synchronization between old collector and young collector would become even more complicated.
  • If some root would be missed during inaccurate initial mark, remark may become significantly longer as it would involve traversing objects reachable from newly found roots.

Sweeping does not require STW because it does not compact. CMS does not compact old space in concurrent cycles.

Here is my article explaining nature and asymptotics of CMS GC pauses

Upvotes: 1

Related Questions