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 “l(fā)ive” 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 “l(fā)ive” 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)在內(nèi)存中分配的各種對象、對象類型、大小等信息。

3、hprof文件通常用于診斷Java應用程序的內(nèi)存問題,如內(nèi)存泄漏或過度分配等。

二、解析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文件

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容