Is there anyway to generate core/heap dump file when JVM crashes? Since these files are usually very helpful to find out bugs in code.
Asked
Active
Viewed 2.2k times
10
-
3Exiting due to an edception is nok a crash. – Thorbjørn Ravn Andersen Jun 08 '12 at 06:51
-
Can "throw new OutOfMemoryError()" generate a dump file? I tried, but failed. If not, can you provide a situation under which core/heap dump file can be generated. Thanks very much. – cheng Jun 08 '12 at 10:55
-
The IBM JVM can programatically be told to generate these dumps which you can then do just before System.exit(0). I do not know of a vendor independent way to do so. – Thorbjørn Ravn Andersen Jun 08 '12 at 10:56
-
1OK. I tried just a minute ago. throw new OutOfMemoryError() can not generate a dump file. Using -Xmx to limit memory space and define a large array in the code can generate a heap dump. Thank you for your help. – cheng Jun 08 '12 at 11:03
-
It would be OK if jvm crash with a OutOfMemoryError throwing. – Chao Jun 05 '15 at 06:56
2 Answers
18
With the following JVM options:
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath="/tmp"
JVM will dump the content of heap to a file in specified directory. Note that this only happens when OutOfMemoryError
is thrown since dump isn't really needed if JVM crashed due to a different reason.
Edit: "Boolean options are turned on with -XX:+ and turned off with -XX:-." docs

Joe23
- 5,683
- 3
- 25
- 23

Tomasz Nurkiewicz
- 334,321
- 69
- 703
- 674
-
4Should be -XX:+HeapDumpOnOutOfMemoryError (with plus symbol) because minus actually turns it off – gerrytan Jun 08 '15 at 23:58