How is Heap dump file created after JVM crash

3.1k views Asked by At

When JVM crashes, Heap dump file(hs_err_pidXXXX.log) is created in the working directory. I want to know who creates this file. JVM crashed means it has terminated abnormally. So it will definitely not create this file. So how is this file created?

Also can we control the information displayed in this file. If I want to have thread dump and heap dump both together in a single file (hs_err_pidXXXX.log) is it possible? If yes how? Basically my priority is to identify the function(or stacktrace) that caused JVM to crash and store it on the Heap dump file that is created.

2

There are 2 answers

2
Henry On BEST ANSWER

Many operating systems allow a process to register a handler for certain exceptional conditions. For example in UNIX there is the concept of signals.

So it is possible that the JVM itself writes the log.

0
Anurag Kapur On

You are getting a heap dump on crash already. To get a thread dump in addition, use the following JVM argument

 -XX:OnOutOfMemoryError="kill -3 %p"

Note: This will most likely create the thread dump in a different file or console though.