gpt4 book ai didi

java - 为什么JVM CMS(concurrent mark-and-sweep) GC需要两次停顿?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:49:36 27 4
gpt4 key购买 nike

我想知道为什么 CMS 需要两个阶段(以及两个暂停)的标记:即初始标记和备注。能不能简单的做一个标记,然后扫一扫?我想这可以是一个更快的暂停。有人可以帮助解释第二个标记的主要目的是什么以及我们为什么需要它吗?谢谢!

最佳答案

这在 HotSpot 内存管理白皮书中有很好的解释:

A collection cycle for the CMS collector starts with a short pause, called the initial mark, that identifies the initial set of live objects directly reachable from the application code. Then, during the concurrent marking phase, the collector marks all live objects that are transitively reachable from this set. Because the application is running and updating reference fields while the marking phase is taking place, not all live objects are guaranteed to be marked at the end of the concurrent marking phase. To handle this, the application stops again for a second pause, called remark, which finalizes marking by revisiting any objects that were modified during the concurrent marking phase. Because the remark pause is more substantial than the initial mark, multiple threads are run in parallel to increase its efficiency. At the end of the remark phase, all live objects in the heap are guaranteed to have been marked, so the subsequent concurrent sweep phase reclaims all the garbage that has been identified.

关于java - 为什么JVM CMS(concurrent mark-and-sweep) GC需要两次停顿?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17371984/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com