Flags
-XX:+HeapDumpOnOutOfMemoryError writes an HPROF heap dump when Java heap is
exhausted. -XX:ErrorFile controls where the VM writes fatal error logs such as
hs_err_pid files.
Flag details
- -XX:+HeapDumpOnOutOfMemoryError
- Writes a heap dump when the JVM throws an
OutOfMemoryErrordue to Java heap exhaustion. The dump captures object graphs for offline leak analysis. - -XX:HeapDumpPath=/var/log/myapp/dumps
- Chooses the output directory or file for heap dumps. The JVM process must have write permission and enough disk space.
- -XX:ErrorFile=/var/log/myapp/hs_err_pid%p.log
- Chooses where fatal JVM error logs are written.
%pexpands to the process ID, which prevents multiple crashes from overwriting the same file.
When to use it
Use this in production services, batch jobs, and staging systems where a failure should leave enough evidence for later analysis with tools such as Eclipse MAT, JDK Mission Control, or VisualVM.
Java version support
-XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath, and
-XX:ErrorFile are longstanding HotSpot diagnostic options and apply across the
cataloged Java versions.
Related JEPs
- These crash and heap-dump flags predate the modern JEP process and do not have a dedicated feature JEP.
Examples
java -XX:+HeapDumpOnOutOfMemoryError \
-XX:HeapDumpPath=/var/log/myapp/dumps \
-XX:ErrorFile=/var/log/myapp/hs_err_pid%p.log \
-jar app.jar
Use absolute paths in production so dumps land on a volume with known retention and capacity.
Verify
Confirm write permissions and retention policy for dump directories before relying on the flags during an incident.