10

We have been struggling to diagnose the cause of an OutOfMemoryError we experienced on one of our production servers. Our attempts to reproduce the issue in soak tests have so far failed, and we are considering enabling -XX:+HeapDumpOnOutOfMemoryError on our production servers, so that if it does happen again, at least we'll have some data.

Is it wise to enable this setting on production servers?

James_pic
  • 213
  • 2
  • 6

1 Answers1

12

Take a look in documentation:

B.1.2 -XX:+HeapDumpOnOutOfMemoryError Option

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. 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.

You can also specify this option at runtime with the MBeans tab in the jconsole utility.

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.

-XX:+HeapDumpOnOutOfMemoryError flag does not introduce performance or security problems in run time. The flag is checked only after OutOfMemoryError has happened.

You can specify the actual path to which the file is saved using the corresponding -XX:HeapDumpPath flag. (Regardless of where the file is saved, make sure the filesystem and/or the Java process has the necessary permission configuration to be able to write there.)

Federico Sierra
  • 3,499
  • 1
  • 18
  • 24