How to configure the HeapDumpOnOutOfMemoryError parameter on JBoss EAP or WildFly ? It’s pretty simple.
The -XX:+HeapDumpOnOutOfMemoryError command-line option tells the HotSpot VM to generate a heap dump when an allocation from the Java heap or the permanent generation cannot be satisfied.
Just like any other JVM parameters, it can be added in the standalone.conf for standalone applications:
JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError"
Check this tutorial to learn how to set this parameter for Domain Mode: Configuring JVM Settings in a WildFly / JBoss Domain
Out of the box, the HeapDump is generated in the current working directory of the Java process, that is in the $JBOSS_HOME/bin folder. If you want to place it on a different folder, you need to include also the parameter HeapDumpPath as in this example:
JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/dumps"
It is worth mentioning that there is no overhead in running with this option, and so it can be useful for production systems where OutOfMemoryError takes a long time to surface.
The heap dump is in HPROF binary format, and so it can be analyzed using any tools that can import this format. For example, the jhat tool can be used to do rudimentary analysis of the dump.