调整 GC Overhead Exceeded 参数
我需要我的 Oracle Hotspot 比使用 UseGCOverheadLimit
的默认参数更快地抛出异常 java.lang.OutOfMemoryError: GC 开销限制
.
I need my Oracle Hotspot to throw an exception java.lang.OutOfMemoryError: GC overhead limit exceeded
much sooner than with the default parameters of UseGCOverheadLimit
.
默认情况下,OOME 发生在 98% 以上的时间用于 GC 且堆回收不到 2% 时(描述 http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#par_gc.oom).
By default, OOME occurs when more than 98% of the time is spent in GC and less than 2% of the heap is recovered (described http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#par_gc.oom).
例如,当超过 20% 的时间用于 GC 时,我需要我的 JVM 抛出 OOME.不幸的是,-XX:GCTimeRatio=nn
似乎没有什么不同.
For instance, I need my JVM to throw OOME when more than 20% of the time is spent in GC.
Unfortunately, the -XX:GCTimeRatio=nn
doesn't seem to make a difference.
我需要以这种方式调整我的 JVM 的原因是我正在测试我的应用程序是否包含内存泄漏(准确地说,我有一个内存泄漏检测基础设施,我想每天测试我们的应用程序)而且我不需要我的 JVM 尽可能努力地释放堆.
The reason I need to adjust my JVM in this way is that I'm testing my application whether it contains a memory leak (precisely, I have a memory leak detection infrastructure where I want to test our app on a daily basis) and I don't need my JVM to try as hard as possible to free the heap.
推荐答案
默认情况下,当超过 98% 的时间花费在 GC 上且不到 2% 的堆被回收时,就会发生 OOME
By default, OOME occurs when more than 98% of the time is spent in GC and less than 2% of the heap is recovered
这两个值是通过GCHeapFreeLimit
和GCTimeLimit
GCTimeRatio
仅定义了 GC 启发式算法将优化的软目标.
GCTimeRatio
only defines a soft goal for which the GC heuristics will optimize.
相关文章