Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-XX:+HeapDumpOnOutOfMemoryError not creating hprof file in OOM

Tags:

java

hprof

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?

like image 640
Persimmonium Avatar asked Oct 05 '09 08:10

Persimmonium


People also ask

Where are Hprof files generated?

The only heap dump format generated by the -XX:+HeapDumpOnOutOfMemoryError option is the hprof binary format. The file will be generated in the home directory of the application (i.e. where the application is started) and the file owner will be the name of the application user.

How do you resolve an oom issue?

Use the server. xml file with Oracle JREs. For any OOM problem on an IBM JRE, we need at least a heapdump, javacore, and the verboseGC output. The running process that causes an OOM error to be thrown will probably keep throwing OOM errors, and by default, every OOM error will generate a javacore and heapdump.

What is Hprof file in cloudera?

hprof files in /tmp directory leading to 100% disk usage on / mount. The owner of these files are hdfs:hadoop. I know hprof is created when we have a heap dump of the process at the time of the failure. This is typically seen in scenarios with "java. lang.

How do I fix out of memory heap space in Java?

OutOfMemoryError: Java heap space. 1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.


1 Answers

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).

like image 64
sfussenegger Avatar answered Sep 20 '22 10:09

sfussenegger