Search code examples
javagarbage-collectionconcurrent-mark-sweep

What's the exact use of -XX+UseCMSCompactAtFullCollection?


I understand it tells CMS collector to do a compaction on old gen when a full GC has happened.

But I want to confirm if I understand it correctly (pieced together from various sources):

A full GC would pause the world, collect and compact the old gen (using the result from the CMS's remark phase), then collect the young gen, promote objects (if any), and resume the world.

At this point, there might be floating garbage in the old gen, and UseCMSCompactAtFullCollection is to clean up them and compact the old gen again (basically another GC on old gen). Because the world is stopped anyway, it might be worth to do a bit more compacting.

Is this description correct? Have I missed any important details? Thanks


Solution

  • This ticket is a good answer: https://bugs.openjdk.java.net/browse/JDK-8027132

    Basically, my understanding is correct. There was a foreground CMS mode that picks up from the background mode when there is an allocation failure (because the system cannot proceed until the failure is resolved).

    -XX:+UseCMSCompactAtFullCollection tells that foreground mode to run a compaction using serial old. It has no effect over a full GC.

    The foreground mode has been deprecated in Java 8 (and running a full GC is the only option now), and so was the flag.

    Conclusion

    The flag is dead and don't use it.