简体   繁体   English

在抛出OutOfMemoryError时将JVM设置为转储堆

[英]Set a JVM to dump heap when OutOfMemoryError is thrown

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. 我正在尝试设置我正在处理的服务器的JVM,因此它会在发生OOME时将堆转储到文件中。

I know I have to add this option -XX:-HeapDumpOnOutOfMemoryError to the JVM arguments somewhere, but I can't figure how to do this. 我知道我必须在某处将这个选项-XX:-HeapDumpOnOutOfMemoryError添加到JVM参数中,但我无法知道如何执行此操作。

FYI, I can access the server through PuTTY, so I am looking for a command line way of doing this. 仅供参考,我可以通过PuTTY访问服务器,所以我正在寻找一种命令行方式。

The JVM I am using is OpenJDK64-Bit Server VM. 我使用的JVM是OpenJDK64-Bit Server VM。

I don't know if that's relevant, but the application is a war file. 我不知道这是否相关,但应用程序是一个war文件。

PS : ps -ef|grep java

tomcat   23837     1  0 Mar25 ?        00:03:46 /usr/lib/jvm/jre/bin/java -classpath :/usr/share/tomcat6/bin/bootstrap.jar:/usr/share/tomcat6/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar -Dcatalina.base=/usr/share/tomcat6 -Dcatalina.home=/usr/share/tomcat6 -Djava.endorsed.dirs= -Djava.io.tmpdir=/var/cache/tomcat6/temp -Djava.util.logging.config.file=/usr/share/tomcat6/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager org.apache.catalina.startup.Bootstrap start

EDIT : 编辑:

I found something, correct me if I'm wrong : since I am using Tomcat, I decided to add these lines in the tomcat.conf file: 我找到了一些东西,如果我错了就纠正我:因为我使用的是Tomcat,所以我决定在tomcat.conf文件中添加这些行:

JAVA_OPTS=-XX:-HeapDumpOnOutOfMemoryError JAVA_OPTS = -XX:-HeapDumpOnOutOfMemoryError

JAVA_OPTS=-XX:HeapDumpPath=/root/dump JAVA_OPTS = -XX:HeapDumpPath = /根/转储

JAVA_OPTS=-Xmx20m JAVA_OPTS = -Xmx20m

What do you think ? 你怎么看 ?

This option from the HotSpot VM options . HotSpot VM 选项中的此选项。 I would think it'd be the same in the OpenJDK VM but let me know if it's not. 我认为它在OpenJDK VM中是相同的,但如果不是,请告诉我。

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

You can also manually generate a memory map using jmap if you know the process id: 如果您知道进程ID,也可以使用jmap手动生成内存映射:

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

You can use JHat to analyze the dump. 您可以使用JHat来分析转储。

jhat <path to dump file>

As mentioned by @CoolBeans, the JVM options to use are: 正如@CoolBeans所提到的,要使用的JVM选项是:

-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 要在tomcat中进行设置,请在TOMCAT_HOME / bin目录下创建名为setenv.sh(setenv.bat for windows)的文件并添加以下行

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. CATALINA_OPTS是这类选项的首选,因为它们不需要应用于关闭过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM