关于G1的几点疑惑?

  1. young gc是不是针对所有的新生代region进行回收?我的理解是young gc会回收全部的新生代Region,并调整Eden区数量来满足软实时性要求;
  2. Oracle文档中指出在并发标记期间还可能进行额外的young gc,这不会破坏并发标记期间的内存布局么?比如现在正在进行并发标记,对于某个Eden Region A, 还未完成标记,此时若是发生young gc,A会被如何处理?
  3. 以及这位仁兄提出的关于Mixed GC的执行次数问题, mixed gc如何利用concurrent marking phase获得的CSet,每次仅回收一部分CSet中的老年代?下次mixed gc再回收一部分直到满足mixed gc退出条件?


回答:

关于第三点,mixed gc次数问题,查阅了一些文档(原文地址), 我认为问题中对 3 的理解应当是对的,即mixed gc 每次仅针对标记阶段获得的CSet一部分老年代进行回收,直到满足退出条件:

Compared to a young collection, a mixed collection will look to collect all three generations within the same pause time target. It manages this through the incremental collection of the Old regions based on the value of G1MixedGCCountTarget (defaults to 8). Meaning, it will divide the number of candidate Old regions by the G1MixedGCCountTarget and try to collect at least that many regions during each cycle. After each cycle finishes, the liveness of the Old region is re-evaluated. If the reclaimable space is still greater than the G1HeapWastePercent, mixed collections will continue.


回答:

  1. 是的,年轻代垃圾回收只会回收Eden区Survivor区
  2. 不会,会进行再次标记(Remark)修正上一次的标记结果
  3. 默认8次,混合回收并不一定要进行8次。有一个阈值-XX:G1HeapWastePercent,默认值为10%,意思是允许整个堆内存中有10%的空间被浪费,意味着如果发现可以回收的垃圾占堆内存的比例低于10%,则不再进行混合回收。因为GC会花费很多的时间但是回收到的内存却很少。

以上是 关于G1的几点疑惑? 的全部内容, 来源链接: utcz.com/p/945310.html

回到顶部