-XX:+HeapDumpOnOutOfMemoryError not creating hprof file in OOM
Asked Answered
R

2

7

I start my java code (1.6.0_16 in Vista) with the following params (among others) -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../logs. I run the code and I can see in the logs there are two OOM.

The first one I know cause I can see in the 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, towards the end of the code I get another OOM, I capture this, but I don't get a second hprof file created. Anybody knows why is that?? Is it because I have captured the OOM exception?

Resnatron answered 5/10, 2009 at 8:31 Comment(0)
S
5

Out of memory generates only one dump-file on the first error. If you want to get more you can try jmap or keep jconsole on the jvm (version 6) then you can after everything crashed i.e in the morning create your own dump from jconsole (or your analyser tool of choice).

More on the dumping subject can be read in Eclipse MemoryAnalyser.

Stancil answered 2/3, 2011 at 10:2 Comment(0)
V
8

I wouldn't try to recover from an OutOfMemoryError as some objects might end up in an undefined state (just thinking about an ArrayList that couldn't allocate its array to store date for instance).

Regarding your question, I'd suspect that -XX:+HeapDumpOnOutOfMemoryError is only creating a single dump intentionally to prevent multiple heap dumps: just think about several threads throwing an OOME at the same time, causing a heap dump for each thrown exception.

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

Viminal answered 5/10, 2009 at 9:47 Comment(1)
well I know about the advise not to try to recover from OOM but in this case I need to, have to, and in many cases all works well. But your hipothesys sounds good, maybe only one is created on purpose... While researching this issue I found some question here in stackoverlfow that showed how to create the dump programatically, but cannot find it nowResnatron
S
5

Out of memory generates only one dump-file on the first error. If you want to get more you can try jmap or keep jconsole on the jvm (version 6) then you can after everything crashed i.e in the morning create your own dump from jconsole (or your analyser tool of choice).

More on the dumping subject can be read in Eclipse MemoryAnalyser.

Stancil answered 2/3, 2011 at 10:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.