Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Sun JDK generate core/heap dump files when JVM crashes?

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.

like image 728
cheng Avatar asked Jun 08 '12 06:06

cheng


People also ask

What happens when JVM crashes?

When the JRockit JVM crashes, it generates a binary crash file ( . core or . mdmp ). By default, the binary crash file contains a copy of the entire JVM process.

Why does the JVM crash with a core dump?

JVM crash is one of the toughest problem professional Java developers face. In case of a JVM crash, the operating system creates a core dump file which is a memory snapshot of a running process. A core dump is created by the operating system when a fatal or unhandled error like signal or system exception occurs.

Why heap dump is generated?

We generate java memory heap dump to identify issues like memory leaks and to optimize memory usage in our application.


1 Answers

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

like image 185
Tomasz Nurkiewicz Avatar answered Oct 26 '22 04:10

Tomasz Nurkiewicz