右键,Run as è Run Conigurations..中的Arguments设置VM argument为:
-XX:+HeapDumpOnOutOfMemoryError
另外一种指定生成文件存储位置:
-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=/home/xieyun/test/TestHeapDumpOnOutOfMemoryError.hprof
生成的hprof文件,就在工程目录下。
具体分析请参见后面统一说明。
10.2 Tomcat应用配置JVM参数,及生成hprof文件
首先需要添加JVM参数。修改/home/xieyun/software/apache-tomcat-6.0.32/bin/catalina.sh
if [ -z"$LOGGING_MANAGER" ]; then
JAVA_OPTS="$JAVA_OPTS-XX:+HeapDumpOnOutOfMemoryError-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
else
JAVA_OPTS="$JAVA_OPTS-XX:+HeapDumpOnOutOfMemoryError$LOGGING_MANAGER"
Fi
-XX:+HeapDumpOnOutOfMemoryError一定要放在最后,不然不会生效。
启动tomcat:
xieyun@xieyun-OptiPlex-760:~/software/apache-tomcat-6.0.32/bin$./startup.sh
UsingCATALINA_BASE: /home/xieyun/software/apache-tomcat-6.0.32
UsingCATALINA_HOME: /home/xieyun/software/apache-tomcat-6.0.32
UsingCATALINA_TMPDIR: /home/xieyun/software/apache-tomcat-6.0.32/temp
UsingJRE_HOME: /usr/ali/java
Using CLASSPATH: /home/xieyun/software/apache-tomcat-6.0.32/bin/bootstrap.jar
启动tomcat:
http://localhost:8080/testHeapDumpOnOutOfMemoryErrorWeb/HeapDumpOnOutOfMemoryErrorServlet
catalina.out输出:
2012-4-2320:41:16 org.apache.catalina.startup.Catalina start
信息: Server startup in833 ms
开始ThreadTest
开始ThreadTest
开始ThreadTest
开始ThreadTest
开始ThreadTest
开始SuccessThread
java.lang.OutOfMemoryError:Java heap space
Dumping heap tojava_pid31185.hprof ...
Heap dump filecreated [718127281 bytes in 27.183 secs]
Exception inthread "Thread-13" java.lang.OutOfMemoryError: Java heap space
atcom.yxie.test.ThreadTest.run(ThreadTest.java:15)
Exception inthread "Thread-10" java.lang.OutOfMemoryError: Java heap space
atcom.yxie.test.ThreadTest.run(ThreadTest.java:15)
Exception inthread "Thread-9" java.lang.OutOfMemoryError: Java heap space
atjava.util.Arrays.copyOf(Arrays.java:2734)
atjava.util.ArrayList.ensureCapacity(ArrayList.java:167)
atjava.util.ArrayList.add(ArrayList.java:351)
atcom.yxie.test.ThreadTest.run(ThreadTest.java:17)
Exception inthread "Thread-12" java.lang.OutOfMemoryError: Java heap space
Exception inthread "Thread-11" java.lang.OutOfMemoryError: Java heap space
生成的hprof文件在:
具体分析请参见后面统一说明。
简单的linux jboss配置,和windowsjboss配置是一样的。需要修改run.sh文件。对应windows jboss配置修改就好啦。请参见: windows 平台使用Mat Jboss应用配置JVM参数,及生成hprof文件
Alibaba的项目,用的是jboss,如果我们需要生成heapdump可以使用jmp或者添加对应的参数。
1、 配置jvm参数
我是通过定时器来测试的。需要修改: /home/xieyun/work/standalone/superdeal/deploy/autoconf/promotionProductSoldOutNapoliTimer.sh.vm
JAVA_OPTS="-Xdebug-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
$JAVA_HOME/bin/java -Xmx512m -Dwget=true $JAVA_OPTS com.alibaba.intl.standalone.wholesale.superdeal.main.PromotionProductSoldOutNapoliTimer -XX:+HeapDumpOnOutOfMemoryError
2、 启动jboss,然后通过jmap命令生成对应hprof文件
jmap-dump:format=b,file=/home/xieyun/test/matTtempFile/heapDump.hprof 30146
3、通过mat工具进行分析。
Linux web应用intl-wholesale
需要修改/alibaba.intl.wholesale.deploy-1.0-SNAPSHOT/autoconf/env.vm文件。修改的代码对应
exportPRODUCTION_MODE=dev
$PRODUCTION_MODE= "dev"模式的代码。如:
elif [ $PRODUCTION_MODE = "dev" ]; then
#we should reduce resource usage ondeveloping mode
JAVA_MEM_OPTS=" -Xms64m -Xmx1024m-XX:MaxPermSize=128m -XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=/home/xieyun/test/matTtempFile/TestHeapDumpOnOutOfMemoryError.hprof"
JAVA_OPTS=" $JAVA_MEM_OPTS$JAVA_DEBUG_OPT "
启动服务。然后访问http://www.aliexpress.com:1080/proengine/release/displayPromotionMultipriceSearchBackDoor.htm
该页面会调用多线程导致outOfMemery错误。会生成hprof文件: