Java GC: why two survivor regions?

2019-01-12 15:55发布

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?

7条回答
等我变得足够好
2楼-- · 2019-01-12 16:54

Young Generation : It is place where lived for short period and divided into two spaces:

Eden space : New objects will be allocated in the memory pool. The assumption is that most object get dereferenced and become unreachable soon after their creation. Objects not being dereferenced will be copied by the new generation garbage collector into the survivor spaces. They may get copied n some special cases directly into the old generation pool.

Survivor spaces: These two small spaces keep the surviving objects of a young generation garbage collection. Surviving objects will be copied for a (small) number of times from one survivor into the other. This allows to harvest our more dereferenced objects.

Old generation: The largest memory pool which should keep the long living objects. Objects are getting copied into this pool once they leave the survivor spaces.

Permament generation: This fairly unknown pool keeps the information of all the classes. It doesn't need any attention for most applications. It may need to be adapted for some applications with many classes. It may need some attentention as well if the application permanently loads and unloads classes.

Other advantages:

  • Memory fragmentation
  • It improves GC performance

Please find the following links for more details which can help you understand more

http://www.scalingbits.com/javaprimer

http://java.sys-con.com/node/84695

查看更多
登录 后发表回答