sun jdk 下如何生成heapdump文件

sun jdk 下如何生成heapdump文件

 

以Tomcat为例:

 

在tomcat启动脚本中增加 HeapDumpOnOutOfMemoryError 参数

此参数需要Java SE release 5.0 update 7 或以上支持

设置示例:

set JAVA_OPTS=%JAVA_OPTS% -server -Xms512m -Xmx800m -XX:PermSize=64M -XX:MaxPermSize=128m -Djava.awt.headless=true -XX:+HeapDumpOnOutOfMemoryError

 

测试内存溢出时可以把-Xms和-Xmx等的值相应调低即可.

文件默认产生在tomcat/bin目录下

 

如增加HeapDumpOnCtrlBreak Option就可以通过ctrl+break或收到SIGQUIT生成heapdump文件

此参数需要Java SE release 5.0 update 14 或以上支持

设置示例:

set JAVA_OPTS=%JAVA_OPTS% -server -Xms512m -Xmx800m -XX:PermSize=64M -XX:MaxPermSize=128m -Djava.awt.headless=true -XX:+HeapDumpOnOutOfMemoryError -XX:+HeapDumpOnCtrlBreak

 

参数介绍:
HeapDumpOnOutOfMemoryError 参数:


The -XX:+HeapDumpOnOutOfMemoryError command-line option was introduced in Java SE release
5.0 update 7. This option tells the HotSpot VM to generate a heap dump when the first thread throws a
java.lang.OutOfMemoryError because the Java heap or the permanent generation is full. 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.
The heap dump is in HPROF binary format, and so it can be anaylzed by any tool that can import this
format, for example the Heap Analysis Tool (HAT).
By default the heap dump is created in a file called java_pid<pid>.hprof in the working directory
of the VM, where <pid> is the process ID. You can specify an alternative file name or directory with
the -XX:HeapDumpPath= option. For example, -XX:HeapDumpPath=/disk2/dumps will cause the
heap dump to be generated in the /disk2/dumps directory.

 

HeapDumpOnCtrlBreak 参数:


The -XX:+HeapDumpOnCtrlBreak command-line option was introduced in Java SE release 5.0 update 14. This option tells the HotSpot VM to generate a heap dump when a Ctrl-Break or SIGQUIT signal
is received. This provides a way to trigger a heap dump on demand.
The heap dump is in HPROF binary format, and so it can be anaylzed by any tool that can import this
format, for example the Heap Analysis Tool (HAT). The heap dump contains only live objects.
By default the heap dump is created in a file called java_pid<pid>.hprof.<yyyymmdd>.<hhmmss>
in the working directory of the VM, where <pid> is the process ID, and <yyyymmdd>.<hhmmss> is the
approximate time when the heap dump was generated.
You can specify an alternative file name or directory with the -XX:HeapDumpPath= option. For
example, -XX:HeapDumpPath=/disk2/dumps will cause the heap dump to be generated in the
/disk2/dumps directory.
If both the -XX:+HeapDumpOnCtrlBreak and -XX:+PrintClassHistogram options are enabled, the
heap dump and the heap histogram are obtained from the same heap snapshot.

 

 

详见JavaTM 2 Platform, Standard Edition 5.0 Troubleshooting and Diagnostic Guide
http://java.sun.com/j2se/1.5/pdf/jdk50_ts_guide.pdf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值