I've been trying to dump the heap file when an OutOfMemoryError occurs on a given Java process using Jmap.
I have been able to dump the heap file but I want to add the HeapDumpOnOutOfMemoryError flag to Jmap but I think I'm doing something wrong. Am I doing something wrong? I've tried:
jmap -J-XX:+HeapDumpOnOutOfMemoryError -dump:live,file=/home/eduardo2/dumpfile.hprof 18763
When I run the above it just says the following -- but it doesn't wait for the OutOfMemoryError:
>> Dumping heap to /home/eduardo2/dump21file.hprof ...
>> Heap dump file created
You are mixing up two different things:
jmap
to capture a heap dump from a running process like you did. See https://docs.oracle.com/javase/7/docs/technotes/tools/share/jmap.html.-XX:+HeapDumpOnOutOfMemoryError
on the java process you are expecting to throw the OOM
. If the exception occurs, a dump will be written to the current directory. See https://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/clopts.html#gbzrr