对于 Sun/Oracle 的 JVM,我读到 GC 算法将新一代划分为一个 Eden 区域和两个幸存者区域.我想知道的是,为什么有两个幸存者区域而不仅仅是一个?该算法可以在伊甸园和一个幸存者区域之间保持乒乓球(就像它目前在两个幸存者区域之间所做的那样);或者这种方法有什么缺点吗?
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?
我相信 JRockit 的 GC 实现更像你建议的那样,只有一个伊甸园和一个幸存者空间,但不要引用我的话.
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.
HotSpot JVM 有两个幸存者空间的原因是为了减少处理碎片的需要.新对象分配在伊甸园空间中.一切都很好.当它满了时,你需要一个 GC,所以杀死陈旧的对象并将活的对象移动到幸存者空间,在那里它们可以成熟一段时间,然后再被提升到老年代.到目前为止还是不错的.但是,下次我们用完伊甸园空间时,我们遇到了一个难题.下一次 GC 出现并清除了 eden 和我们的幸存者空间中的一些空间,但这些空间并不连续.那么是不是更好
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
孙对这个问题的回答是显而易见的.
Sun's answer to the question is obvious.
这篇关于Java GC:为什么有两个幸存者区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!