简体   繁体   English

为什么我的Java堆转储仅显示一半的堆?

[英]Why does my Java heap dump show only half the heap?

I'm intentionally adding items to a data structure until Java throws an OutOfMemoryError , and grabbing a heap dump using -XX:+HeapDumpOnOutOfMemoryError . 我故意在数据结构中添加项目,直到Java抛出OutOfMemoryError ,然后使用-XX:+HeapDumpOnOutOfMemoryError抓取堆转储。 I'm using -Xmx100M , so I expected the heap dump would show nearly 100MB of live objects, but instead it shows only 46MB. 我正在使用-Xmx100M ,所以我希望堆转储将显示将近100MB的活动对象,但它只会显示46MB。

Why would Java throw OOM with a 100MB heap if there are only 46MB of live objects? 如果只有46MB的活动对象,为什么Java会用100MB的堆抛出OOM?

(I realize there's a good chance I haven't given enough information to answer this question, but I'm not sure what's relevant. Happy to add more info as needed.) (我意识到我很可能没有提供足够的信息来回答这个问题,但是我不确定有什么意义。很高兴根据需要添加更多信息。)

EDIT: The end of the -verbose:gc output: 编辑: -verbose:gc输出的结尾:

 [Full GC (Ergonomics) [PSYoungGen: 1056K->64K(2560K)] [ParOldGen: 7116K->7116K(7168K)] 8173K->7180K(9728K), [Metaspace: 5981K->5981K(1056768K)], 0.0071141 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
 [Full GC (Allocation Failure) [PSYoungGen: 64K->0K(2560K)] [ParOldGen: 7116K->7075K(7168K)] 7180K->7075K(9728K), [Metaspace: 5981K->5974K(1056768K)], 0.0190392 secs] [Times: user=0.02 sys=0.00, real=0.02 secs] 
 java.lang.OutOfMemoryError: Java heap space

Heap is split into two sections young generation and old generation. 堆分为年轻一代和老一代两个部分。 You get OOM when eg the old generation is full or fragmented in such way that it is impossible to promote object from young generation to the old (and probably others). 当例如老一代人已满或支离破碎时,您将获得OOM,从而不可能将对象从年轻一代提升到老一代(可能还有其他)。

If you log GC usage using eg -verbose:gc -XX:+PrintGCDetails -Xloggc:gc.log then you will see each generation sizes. 如果使用-verbose:gc -XX:+PrintGCDetails -Xloggc:gc.log记录GC使用情况,那么您将看到每个世代的大小。

You can see how to tune generation sizes here https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/sizing.html 您可以在此处查看如何调整世代大小:https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/sizing.html

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

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