Set a JVM to dump heap when OutOfMemoryError is thrown

前端 未结 2 725
执笔经年
执笔经年 2020-12-03 08:39

I am trying to set the JVM of the server I am working on, so it dumps a heap to file when an OOME occurs.

I know I have to add this option -XX:-HeapDumpOnOutOf

相关标签:
2条回答
  • 2020-12-03 09:20

    This option from the HotSpot VM options. I would think it'd be the same in the OpenJDK VM but let me know if it's not.

    -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=<path to dump file>

    You can also manually generate a memory map using jmap if you know the process id:

    jmap -J-d64 -dump:format=b,file=<path to dump file> <jvm pid>

    You can use JHat to analyze the dump.

    jhat <path to dump file>

    0 讨论(0)
  • 2020-12-03 09:33

    As mentioned by @CoolBeans, the JVM options to use are:

    -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=<path to dump file>
    

    For setting this in tomcat, create a file named setenv.sh (setenv.bat for windows) under TOMCAT_HOME/bin directory & add the following line

    export CATALINA_OPTS="$CATALINA_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=<path to dump file>"
    

    CATALINA_OPTS is preferred for these kind of options as they need not be applied to the shutdown process.

    0 讨论(0)
提交回复
热议问题