下圖中22455是tomcat的進程號,這裏不重複java
----------------------------------------------------------------------------------------------------------------------------------------------------web
查看tomcat 佔用內存:ps aux | grep tomcat | grep -v grep | awk -F ' ' '{print $5,$6}'apache
第一個數字是佔用的虛擬內存大小,第二數字是佔用物理內存大小,單位byte數組
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------瀏覽器
查看具體佔用狀況: jmap -histo 進程號 | moretomcat
其中排在最上面的幾個縮寫說明jvm
[C is a char[]
[S is a short[]
[I is a int[]
[B is a byte[]
[[I is a int[][]spa
上面的輸出中[C對象佔用Heap這麼多,每每跟String有關,String其內部使用final char[]數組來保存數據的.net
constMethodKlass/ methodKlass/ constantPoolKlass/ constantPoolCacheKlass/ instanceKlassKlass/ methodDataKlass與Classloader相關,常駐於Perm區。orm
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
查看堆轉儲快照(重要,比較直接)
jmap命令用於生成堆轉儲快照;jhat命令用於啓動堆轉儲快照的web server,以便於經過界面查看。
[root@XXXXXX temp]# jmap -dump:format=b,file=dumpfile20190528 22455
Dumping heap to /opt/apache-tomcat-8.5.8/temp/dumpfile20190528 ...
Heap dump file created
則當前目錄下會生成一個dumpfile20190528文件,即堆轉儲快照文件。
2. 運行命令: jhat dumpfile20190528
[root@XXXXXXXXX temp]# jhat dumpfile20190528
Reading from dumpfile20190528...
Dump file created Tue May 28 15:59:18 CST 2019
Snapshot read, resolving...
Resolving 22266807 objects...
Chasing references, expect 4453 dots......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.
瀏覽器訪問 http://localhost:7000,展現的是堆轉儲快照信息界面:
Show heap histogram
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
jmap輸出jvm參數(java8)
使用命令:../usr/java/jdk1.8.0_111/bin/jmap -heap 22455