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.
本文介绍了多种获取Java堆内存快照(heap dump)的方法,包括使用jmap命令、jconsole工具及配置JVM参数等,适用于Java应用程序内存问题的诊断。
340

被折叠的 条评论
为什么被折叠?



