简体   繁体   English

是什么触发了Java中的完整垃圾回收?

[英]What triggers a full garbage collection in Java?

I'm wondering what are the exact situations that trigger Full Garbage Collection in Java. 我想知道在Java中触发Full Garbage Collection的确切情况是什么。

The obvious ones are: 显而易见的是:

  • Running out of old gen 用完了老根
  • Running out of perm gen 耗尽烫发
  • Calling System.gc() 调用System.gc()

What about other cases that cause full gc? 那些导致完整gc的其他病例呢? Particularly: 尤其:

  • Not having enough free space in Survivor Space to copy objects from Eden. Survivor Space中没有足够的可用空间来复制Eden中的对象。
  • Minor collections not being able to cope with allocation rate of new objects (don't know how though). 次要集合无法应对新对象的分配率(不知道如何)。

I'm running Sun Java 1.6 and using Concurrent Mark-Sweep and ParNew for new gen. 我正在运行Sun Java 1.6并使用Concurrent Mark-Sweep和ParNew作为新一代。

I've observed one more situation that triggers a full GC in Java Hotspot VM 1.6 64bit on Ubuntu, using Concurrent Mark-Sweep: 我观察到另一种情况,使用Concurrent Mark-Sweep在Ubuntu上的Java Hotspot VM 1.6 64bit中触发完整的GC:

If -XX:PermSize value does not equal to -XX:MaxPermSize (eg is smaller), an occasional Full GC happens when java needs to expand the PermGen (even though it does not need to allocate more memory than MaxPermSize). 如果-XX:PermSize值不等于-XX:MaxPermSize(例如较小),则当java需要扩展PermGen时会发生偶尔的Full GC(即使它不需要分配比MaxPermSize更多的内存)。 So setting -XX:PermSize and -XX:MaxPermSize to be the same seems like a good idea. 所以将-XX:PermSize和-XX:MaxPermSize设置为相同似乎是一个好主意。

This greatly depends on your jvm options and the jvm that you at using. 这在很大程度上取决于你的jvm选项和你使用的jvm。

For this reason, I recommend that you look at the book "Java Performance" bý John and Hunt. 出于这个原因,我建议你看看“Java性能”这本书,约翰和亨特。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM