jmap

How to capture Java heap dump?

jmap tool under <JAVA_HOME>\bin folder is an effective option. It can be invoked using the command:

Here is how you should invoke jmap:
jmap -dump:format=b,file=<file-path> <pid> 
where
pid: is the Java Process Id, whose heap dump should be captured
file-path: is the file path where heap dump will be written in to.
Example:
jmap -dump:format=b,file=/opt/tmp/heapdump.bin 37320

Note: It’s quite important to pass “live” option. If this option is passed, then only live objects in the memory are written into the heap dump file. If this option is not passed, all the objects, even the ones which are ready to be garbage collected are printed in the heap dump file. It will increase the heap dump file size significantly. It will also make the analysis tedious. To troubleshoot memory problems or optimize memory, just “live” option should suffice the need.

jmap
jmap print heap dumps into specified file location. This tool is packaged within JDK. It can be found in \bin folder.
[arthas@58205]$ heapdump arthas-output/dump.hprof
Dumping heap to arthas-output/dump.hprof ...
Heap dump file created

heapdump

一、hprof文件简介
1、hprof文件是一种Java Heap Dump文件,可以通过jmap、Eclipse Memory Analyzer或者MAT(Memory Analyzer Tool)等工具生成。

2、hprof文件记录了Java应用程序的运行时快照信息,包括Java虚拟机(JVM)在内存中分配的各种对象、对象类型、大小等信息。

3、hprof文件通常用于诊断Java应用程序的内存问题,如内存泄漏或过度分配等。

二、解析hprof文件
1、通过jmap生成hprof文件:

jmap -dump:format=b,file=heap_dump.hprof
2、通过Eclipse Memory Analyzer打开hprof文件,并进行分析:

(1)打开Eclipse Memory Analyzer,选择File -> Open Heap Dump -> 选择hprof文件。

理解和解析hprof文件

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容