-
給eclipse 安裝mat插件:
點擊help ---install new software------add 然后添加新地址,路徑為:http://download.eclipse.org/mat/1.3/update-site/
-
導出對應進程的堆內存文件
jmap:Prints shared object memory maps or heap memory details for a process
如果什么參數都沒有 :jamp 3161,則: the jmap
command prints shared object mappings.
如果-dump:[live,] format=b, file=filename則:Dumps the Java heap in hprof
binary format to filename
. The live
suboption is optional, but when specified, only the active objects in the heap are dumped(會觸發full gc )
如果 -heap 則:Prints a heap summary of the garbage collection used, the head configuration, and generation-wise heap usage
-histo[:live] 則:Prints a histogram of the heap. For each Java class, the number of objects, memory size in bytes, and the fully qualified class names are printed. 統計堆中對象
-clstats:Prints class loader wise statistics of Java heap. For each class loader, its name, how active it is, address, parent class loader, and the number and size of classes it has loaded are printed.
可以通過命令先看下一下內存映射 : jmap -histo:live 3514 | head -5
導出命令: jmap -dump:live,format=b,file=heap.hprof 3161
-
將文件導入map中:
-
文件分析
使用第一種histogram 模式:
-
選擇對象,右鍵 list Object -- with incoming reference
-
選中對應的類,右鍵 open resource file 即可打開對應的類文件
- 分析同樣一個dump快照,MAT需要的額外內存比jhat要小的多的多,所以建議使用MAT來進行分析,當然也看個人偏好