205

I was told I can add the -XX:+HeapDumpOnOutOfMemoryError parameter to my JVM start up options to my JBoss start up script to get a heap dump when we get an out of memory error in our application. I was wondering where this data gets dumped? Is it just to the console, or to some log file? If it's just to the console, what if I'm not logged into the Unix server through the console?

trincot
  • 317,000
  • 35
  • 244
  • 286

5 Answers5

272

Here's what Oracle's documentation has to say:

By default the heap dump is created in a file called java_pid.hprof in the working directory of the VM, as in the example above. You can specify an alternative file name or directory with the -XX:HeapDumpPath= option. For example -XX:HeapDumpPath=/disk2/dumps will cause the heap dump to be generated in the /disk2/dumps directory.

Matt Solnit
  • 32,152
  • 8
  • 53
  • 57
  • 18
    This also lists out all VM performance related options: http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp#PerformanceTuning – Ravi Gupta Jan 07 '10 at 11:00
  • 4
    Important! The HeapDump flags are available only from Java 1.5.0_07. – rustyx Sep 17 '12 at 15:53
  • 16
    Also it's important to recognize that the JVM will NOT overwrite an existing heap dump in the `HeapDumpPath`, you'll see something similar to `"Unable to create /tmp/java_pidpid.hprof: File exists"` in your standard out. Be sure to move your dump file out of the dump path to clear the way for any future dump files; and make use of the `` placeholder in the file name to increase entropy in the file name. – Ben Nov 16 '13 at 01:41
  • 1
    It was extremely useful. It took just minutes to find the leak with Eclipse Memory Analyzer. – Aron Lorincz Jun 09 '15 at 14:03
  • What happens if we give path to folder which does not exists in the system? Will it create folder and push the hump dump within that folder? – Vinit89 May 30 '18 at 13:33
  • What are "-mn256m -mx512m" options (I believe floor-ceiling) ?? Why am I getting unknown option error for "-mn256m" ??! – Prathamesh dhanawade Mar 25 '19 at 21:37
  • @Vinit89 No. It will not create a new path. You have to make sure the path exists. – Prathamesh dhanawade Mar 28 '19 at 16:47
  • @Ben can you share the any reference where it's mentioned that JVM will not overwrite the existing dump file. I was trying to find out but couldn't get it although I am seeing opposite view on https://dzone.com/articles/finding-java-memory-leaks-from-a-heap-dump#:~:text=The%20%2DXX%3AHeapDumpPath%20can%20specify,exists%2C%20it%20will%20be%20overwritten. – Manish Jan 13 '23 at 12:31
  • 1
    Hi @Manish, that recommendation was written for Java 7 in the year 2013. Support for heap dumps appears to have matured since then. I'm unfortunately unable to edit my comment now. – Ben Jan 19 '23 at 01:46
  • @Ben yeah I tried to generate heapdump on my machine and found that it will not overwrite the same dump file name if it's exist already. – Manish Jan 19 '23 at 05:03
52

You can view this dump from the UNIX console.

The path for the heap dump will be provided as a variable right after where you have placed the mentioned variable.

E.g.:

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${DOMAIN_HOME}/logs/mps"

You can view the dump from the console on the mentioned path.

Mark van Lent
  • 12,641
  • 4
  • 30
  • 52
6

I found it hard to decipher what is meant by "working directory of the VM". In my example, I was using the Java Service Wrapper program to execute a jar - the dump files were created in the directory where I had placed the wrapper program, e.g. c:\myapp\bin. The reason I discovered this is because the files can be quite large and they filled up the hard drive before I discovered their location.

B5A7
  • 863
  • 12
  • 20
  • Your working directory can be found via the pwdx command. First do a ps -ef| grep java, find your PID for your java app, then run pwdx . It'll tell you the working directory. – RCG Dec 05 '18 at 16:55
3

If you are not using "-XX:HeapDumpPath" option then in case of JBoss EAP/As by default the heap dump file will be generated in "JBOSS_HOME/bin" directory.

1

If you only configure -XX:+HeapDumpOnOutOfMemoryError parameter then heapdump will be generated in JBOSS_HOME/bin directory for OpenJDK/Oracle JDK. If you are using IBM JDK then heapdump will be created under /tmp directory as phd file. -XX:HeapDumpPath option gives us more feasibility for configuring our custom headpump path location (-XX:HeapDumpPath=/my-custom-jboss-server-path/). It's recommended to have this parameters configured in your environment as it will collect heapdump on OutOfMemory error for analyzing the issue with memory leak of the application or checking any large object retention in the application.