I would like to detect an OutOfMemoryError
, take a heap dump, and automatically exit the Java program. Say I have the following command-line arguments for my JVM:>
You shall use
ExitOnOutOfMemoryError or CrashOnOutOfMemoryError
and
HeapDumpOnOutOfMemoryError
OpenJDK JVM (Hotspot) at first takes the heap dump and then crashes out or exits as opted for.
To get a clearer understanding you may refer to JVM source file taking care of this particular logic.
https://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/file/8641949eb21f/src/share/vm/utilities/debug.cpp