如何获取java heap dump

 我来答
让猫飞一会儿
2015-01-19 · TA获得超过1120个赞
知道小有建树答主
回答量:540
采纳率:80%
帮助的人:279万
展开全部
C:/Program Files/Java/jdk1.6.0_20/bin>jmap
Usage:
jmap -histo <pid>
(to connect to running process and print histogram of java object heap
jmap -dump:<dump-options> <pid>
(to connect to running process and dump java heap)

dump-options:
format=b binary default
file=<file> dump heap to <file>

Example: jmap -dump:format=b,file=heap.bin <pid>

或者,运行jconsole, 选择 MBeans -> com.sun.management -> HotSpotDiagnostic -> Operations -> dumpHeap 在参数p0中填写保存dump文件的路径,如果要使用Eclipse Memory Analyzer来分析则文件的后缀要为hprof。点击dumpHeap按钮生成dump文件。

或者在Eclipse Memory Analyzer中直接生成

或者,设置jvm让其在out of memory的时候自动生成dump文件: -XX:+HeapDumpOnOutOfMemoryError 或者-XX:+HeapDumpOnCtrlBreak,更多设置见http://wiki.eclipse.org/index.php/MemoryAnalyzer#Getting_a_Heap_Dump

附带一句,dump文件可以使用Eclipse Memory Analyzer
http://dev.eclipse.org/blogs/memoryanalyzer/2008/04/21/immortal-objects-or-how-to-find-memory-leaks/
http://wiki.eclipse.org/index.php/MemoryAnalyzer#Finding_Memory_Leaks

Finding Memory Leaks
Start by running the leak report to automatically check for memory leaks.
This blog details How to Find a Leaking Workbench Window.
The Memory Analyzer grew up at SAP. Back then, Krum blogged about Finding Memory Leaks with SAP Memory Analyzer. The content is still relevant!
Analyzing Java Collection Usage
Check out Krum's blog about Analyzing Java Collections Usage with Memory Analyzer. Also, Memory for Nothing looks unused collections and the memory kept alive.
Perm Space Issus
A good starting point is the blog The Unknown Generation: Perm by Andreas.
Also, Vedran has blogged some hints how to address Perm Space Issues.
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式