-XX:+HeapDump and _JAVA_HEAPDUMP environment variable

The -XX:+HeapDump option can be used to examine memory allocation in a running Java application by taking snapshots of the heap over time.

Another way to get heap dumps is to use the _JAVA_HEAPDUMP environment variable, setting this environment variable enables you to take memory snapshots without making any modifications to the Java command-line. To enable this functionality, either use the command-line option or set the environment variable before starting the Java application.

For example, export _JAVA_HEAPDUMP=1

With the -XX:+HeapDump option enabled, each time the process is sent a SIGQUIT signal, the JVM produces a snapshot of the Java heap in hprof ASCII format:

java_<pid>_<date>_<time>_heapDump.hprof.txt.

If you set the _JAVA_HEAPDUMP_ONLY option, heap dumps are triggered by SIGWINCH instead of SIGQUIT. Only the heap dump is produced, that is, the thread and trace dump of the application to STDOUT is suppressed. Setting the _JAVA_BINARY_HEAPDUMP environment variable along with _JAVA_HEAPDUMP_ONLY produces a binary format heap dump instead of ASCII, the SIGWINCH is sent to the process.

NOTE:

Before producing the heap dump, JVM performs a full GC.