-XX: + HeapDumpOnOutOfMemoryError does not create the hprof file in OOM

I run my Java code (1.6.0_16 in Vista) with the following parameters (among others) -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../logs . I run the code and I see that there are two OOMs in the logs.

The first thing I know, because I can see in stdout that the hprof file is being created:

 java.lang.OutOfMemoryError: Java heap space Dumping heap to ../logs\java_pid4604.hprof ... Heap dump file created [37351818 bytes in 1.635 secs] 

And then, at the end of the code, I get another OOM, I commit it, but I don’t have a second hprof file. Does anyone know why this is? Is it because I caught the OOM exception?

+4
source share
2 answers

Out of memory generates only one dump file on the first error. If you want to get more, you can try jmap or save JConsole on the JVM (version 6), then after everything crashes, that is, in the morning create your own dump from JConsole (or your analyzer is a selection tool).

Read more about dumping in Eclipse MemoryAnalyser .

+2
source

I would not try to recover from OutOfMemoryError as some objects may end up in an undefined state (only thinks of an ArrayList, which could not allocate its own array for today, for example).

As for your question, I suspect that -XX: + HeapDumpOnOutOfMemoryError is only intentionally creating a single dump to prevent multiple dump heaps: just thinking about multiple OOME throwing threads at the same time, causing a heap dump for each exception to throw an exception.

As a summary: don't try to recover with OOME and don't expect the JVM to write more than one heap pile. However, if you still feel the need to create a heap dump, you can try to manually handle the OOME exception and call jmap to dump or use "-XX: + HeapDumpOnCtrlBreak" (not sure though, how to simulate CtrlBreak programmatically).

+4
source

All Articles