爪哇GC:为什么两个幸存者地区? [英] Java GC: why two survivor regions?

查看:276
本文介绍了爪哇GC:为什么两个幸存者地区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Sun / Oracle的JVM,我已经读过GC算法将新一代划分为一个Eden地区和两个幸存者地区。我想知道的是,为什么两个幸存者地区,而不是一个?算法可以在伊甸园和只有一个幸存者地区之间保持乒乓球(目前在两个幸存者地区之间的方式);或者是否存在这种方法的缺点?

解决方案

我相信JRockit的GC实现更像你的建议,只有一个单一的伊甸园和单个幸存者空间,但不要引用我。



HotSpot JVM的两个幸存空间的原因是为了减少处理碎片的需要。新的对象分配在伊甸园空间。一切都很好。当它满了时,你需要一个GC,所以杀掉陈旧的物体并将活的物体移动到一个幸存者空间,在那里他们可以成熟一段时间,然后被提升到老一代。迄今为止还是不错的。然而,当我们下次伊甸园空间用尽时,我们有一个难题。下一个GC会出现并清除伊甸园和我们的幸存者空间中的一些空间,但这些空间不是连续的。那么,更好的做法是试着将伊甸园中的幸存者安置到幸存者空间的空洞中,并由空位清除?

li>
  • 移动幸存空间中的所有对象以消除碎片,然后然后将幸存者移入其中?

  • 只需说:拧它,我们正在移动所有东西,并将两个空间中的所有幸存者复制到一个完全独立的空间 - 第二个幸存者空间 - 从而为您留下一个干净的伊甸园和幸存者空间,您可以在那里重复在下一个GC的序列?

  • Sun对问题的回答显而易见。


    For Sun/Oracle's JVM, I've read that the GC algo divides new generation into one Eden region and two survivor regions. What I'm wondering about is, why two survivor regions and not just one? The algo can keep ping-ponging between Eden and just one survivor region (the way it currently does between two survivor regions); or are there any shortcomings to this approach?

    解决方案

    I believe JRockit's GC implementation works more like you suggest, with just a single eden and single survivor space, but don't quote me on that.

    The reason for the HotSpot JVM's two survivor spaces is to reduce the need to deal with fragmentation. New objects are allocated in eden space. All well and good. When that's full, you need a GC, so kill stale objects and move live ones to a survivor space, where they can mature for a while before being promoted to the old generation. Still good so far. The next time we run out of eden space, though, we have a conundrum. The next GC comes along and clears out some space in both eden and our survivor space, but the spaces aren't contiguous. So is it better to

    1. Try to fit the survivors from eden into the holes in the survivor space that were cleared by the GC?
    2. Shift all the objects in the survivor space down to eliminate the fragmentation, and then move the survivors into it?
    3. Just say "screw it, we're moving everything around anyway," and copy all of the survivors from both spaces into a completely separate space--the second survivor space--thus leaving you with a clean eden and survivor space where you can repeat the sequence on the next GC?

    Sun's answer to the question is obvious.

    这篇关于爪哇GC:为什么两个幸存者地区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆