18

When using -XX:+HeapDumpOnOutOfMemoryError the JVM will not overwrite the heap dump if there is already a dump file under the specified path. I want to be able to have multiple heap dumps in a non-default location, and was planning on using the pid in the heap dump path in order to allow that.

However, when I tried to specify the argument like so:

-XX:HeapDumpPath=some/heapdump/path/heapdump-%p.hprof

And then created a heap dump, I got %p and not the actual pid in the file name. However, the use of %p seems to work with the -XX:OnOutOfMemoryError option. Is there some other syntax that I'm supposed to use for -XX:HeapDumpPath=?

djikay
  • 10,450
  • 8
  • 41
  • 52
Nina
  • 181
  • 1
  • 2
  • 3

2 Answers2

20

That can be a path to a file OR directory. If you have a path to a directory, the generated file name will have pid in it by default.

http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

Brett Okken
  • 6,210
  • 1
  • 19
  • 25
  • 1
    I am trying to do "some stuff" ONLY if there is a directory /path/to/heapdump present/exists. What happens when the path provided in /path/to/heapdump does not exist but is set in HeapDumpPath? On OOME, does jvm create the path and then create the heapdump at that path? – Prathamesh dhanawade Mar 12 '19 at 17:56
2

You should add which Java you use. These options depends on the JVM vendor (IBM, Oracle, etc.)

OnOutOfMemoryError says WHEN to perform the dump. HeapDumpPath says WHERE to put the dump. I think the use of HeapDumpPath turns on the first, but I advice to use both for clarity.

About the original question, use the pid in the dump file name is a good practice. It can help in particular to corolate and analyse what happens after multiple issues/restarts.

The exact syntax is explained here.

mcoolive
  • 3,805
  • 1
  • 27
  • 32