爪哇GC:为什么两个幸存者地区? [英] Java GC: why two survivor regions?
问题描述
我相信JRockit的GC实现更像你的建议,只有一个单一的伊甸园和单个幸存者空间,但不要引用我。
HotSpot JVM的两个幸存空间的原因是为了减少处理碎片的需要。新的对象分配在伊甸园空间。一切都很好。当它满了时,你需要一个GC,所以杀掉陈旧的物体并将活的物体移动到一个幸存者空间,在那里他们可以成熟一段时间,然后被提升到老一代。迄今为止还是不错的。然而,当我们下次伊甸园空间用尽时,我们有一个难题。下一个GC会出现并清除伊甸园和我们的幸存者空间中的一些空间,但这些空间不是连续的。那么,更好的做法是试着将伊甸园中的幸存者安置到幸存者空间的空洞中,并由空位清除?
li>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
- Try to fit the survivors from eden into the holes in the survivor space that were cleared by the GC?
- Shift all the objects in the survivor space down to eliminate the fragmentation, and then move the survivors into it?
- 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屋!