Search code examples
javajvmjvm-argumentsheap-dump

Usage of XX:HeapDumpSegmentSize and XX:SegmentedHeapDumpThreshold


I've encountered a problem that dumping a heap fails due to the following message:

java.lang.OutOfMemoryError: Java heap space
Dumping heap to /usr/local/webapp/logs/java_pid<MY_PID>.hprof ...
Dump file is incomplete: file size limit

I've found a similar QA here: XX:+HeapDumpOnOutOfMemoryError Max file size limit, but it just refers to options we can use to solve this problem, not how to use them. Searching on the web doesn't help me either because there's little information on these. To make matters worse, I cannot easily test them because the problem seldom occurs.

I found that my application reached its max heap size(8GB) and tried to dump the heap, but failed due to the error above and the dumped file size is only 2.2GB, which seems incomplete and any tools (like jhat, jconsole, jvirtualvm) can't open it.

How can I avoid the problem by using options XX:HeapDumpSegmentSize and XX:SegmentedHeapDumpThreshold?

Environment

  • Java 1.8.0_71
  • Options that seem to be relevant:
    • -Xmx8196m
    • -XX:+HeapDumpOnOutOfMemoryError
    • -XX:HeapDumpPath=$LOG_DIR
    • -XX:OnOutOfMemoryError="kill -9 %p"

Solution

  • HeapDumpSegmentSize and SegmentedHeapDumpThreshold are developer options, they cannot be changed in production JVM. These options will not help you anyway, because they are not about splitting heap dump into multiple files, but rather about creating multiple segments inside one file.

    Make sure that ulimit -f is large enough to create 8G files.