XX:+HeapDumpOnOutOfMemoryError 最大文件大小限制

XX:+HeapDumpOnOutOfMemoryError Max file size limit

我是 运行 一个带有 XX:+HeapDumpOnOutOfMemoryError JVM 标志的 Java 进程并看到以下输出:

java.lang.OutOfMemoryError: Java heap space
Dumping heap to /local/disk2/heaps/heapdump.hprof ...
Dump file is incomplete: file size limit

有办法解决这个问题吗?

-XX:+HeapDumpOnOutOfMemoryError 命令行选项告诉 HotSpot VM 在无法满足 Java 堆或永久代的分配时生成堆转储。 运行 此选项没有开销,因此它对于 OutOfMemoryError 需要很长时间才能浮出水面的生产系统很有用。

为了解决您面临的具体问题,您可以使用以下纠正措施之一:

措施 1: XX:HeapDumpSegmentSize

The -XX:HeapDumpSegmentSize option specifies an appropriate segment size when generating a segmented HPROF heap dump.

格式

-XX:HeapDumpSegmentSize=尺码[k|K][m|M][g|G]

示例

java -XX:+HeapDumpOnOutOfMemory -XX:HeapDumpSegmentSize=512M myApp

默认值
1 GB

测量 2 -XX:SegmentedHeapDumpThreshold

The -XX:SegmentedHeapDumpThreshold option generates a segmented heap dump (.hprof file, 1.0.2 format) when the heap usage is larger than the specified size.

需要分段 HPROF 转储格式才能正确生成包含超过 4 GB 数据的堆转储。如果 -XX:SegmentedHeapDumpThreshold 选项的值设置超过 4 GB,堆转储可能无法正确生成。

格式
-XX:SegmentedHeapDumpThreshold=大小

示例

java -XX:SegmentedHeapDumpThreshold=512M myApp

默认值
2GB

该确切失败消息的一个简单原因可能是:
转储目录中 space 不足。

如果未通过 JVM 参数 -XX:HeapDumpPath 更改转储目录,则转储目录为当前工作目录(参见 documentation)。