jmap命令詳解----查看JVM內存使用詳情

linux獲取java進程PID:

https://www.cnblogs.com/sxdcgaq8080/p/10734752.html 

 

如果命令使用過程中報錯,可能解決你問題的方案:

 

https://www.cnblogs.com/sxdcgaq8080/p/11089179.html

https://www.cnblogs.com/sxdcgaq8080/p/10675966.html

==========================================

 

1、jmap命令基本概述

  jmap命令是一個可以輸出所有內存中對象的工具,甚至可以將VM 中的heap,以二進制輸出成文本。

  打印出某個java進程(使用pid)內存內的,所有‘對象’的情況(如:產生那些對象,及其數量)。

 

64位機上使用需要使用如下方式:

jmap -J-d64 -heap pid

 

2、命令格式

    jmap [option] <pid>
        (to connect to running process) 連接到正在運行的進程

    jmap [option] <executable <core>
        (to connect to a core file)     連接到核心文件

    jmap [option] [server_id@]<remote server IP or hostname>
        (to connect to remote debug server) 連接到遠程調試服務

 

3.參數說明

1) options: 

>    pid:    目標進程的PID,進程編號,可以採用ps -ef | grep java 查看java進程的PID;
>    executable:     產生core dump的java可執行程序;
>    core:     將被打印信息的core dump文件;
>    remote-hostname-or-IP:     遠程debug服務的主機名或ip;
>    server-id:     唯一id,假如一臺主機上多個遠程debug服務;

 

2)基本參數:

[就是替換[option]位置的參數]

1>  -dump:[live,]format=b,file=<filename> 使用hprof二進制形式,輸出jvm的heap內容到文件=.  live子選項是可選的,假如指定live選項,那麼只輸出活的對象到文件. 

命令:

jmap -dump:live,format=b,file=myjmapfile.txt 19570

結果:

 

即可在/root目錄打開myjmapfile.txt文件。

當然,file=後面也可以指定文件存放的目錄,就可以在指定目錄查看文件了。

 

 

2>  -finalizerinfo 打印正等候回收的對象的信息

命令:

jmap -finalizerinfo 3772

結果:

Attaching to process ID 19570, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.80-b11
Number of objects pending for finalization: 0 (等候回收的對象爲0個)

 

 

3>  -heap 打印heap的概要信息,GC使用的算法,heap(堆)的配置及JVM堆內存的使用情況.

命令:

jmap -heap 19570

 

結果:

解析:

using parallel threads in the new generation.  ##新生代採用的是並行線程處理方式

using thread-local object allocation.   

Concurrent Mark-Sweep GC   ##同步並行垃圾回收

 

Heap Configuration:  ##堆配置情況,也就是JVM參數配置的結果[平常說的tomcat配置JVM參數,就是在配置這些]

   MinHeapFreeRatio = 40 ##最小堆使用比例

   MaxHeapFreeRatio = 70 ##最大堆可用比例

   MaxHeapSize      = 2147483648 (2048.0MB) ##最大堆空間大小

   NewSize          = 268435456 (256.0MB) ##新生代分配大小

   MaxNewSize       = 268435456 (256.0MB) ##最大可新生代分配大小

   OldSize          = 5439488 (5.1875MB) ##老年代大小

   NewRatio         = 2  ##新生代比例

   SurvivorRatio    = 8 ##新生代與suvivor的比例

   PermSize         = 134217728 (128.0MB) ##perm區 永久代大小

   MaxPermSize      = 134217728 (128.0MB) ##最大可分配perm區 也就是永久代大小

 

Heap Usage: ##堆使用情況【堆內存實際的使用情況】

New Generation (Eden + 1 Survivor Space):  ##新生代(伊甸區Eden區 + 倖存區survior(1+2)空間)

   capacity = 241631232 (230.4375MB)  ##伊甸區容量

   used     = 77776272 (74.17323303222656MB) ##已經使用大小

   free     = 163854960 (156.26426696777344MB) ##剩餘容量

   32.188004570534986% used ##使用比例

Eden Space:  ##伊甸區

   capacity = 214827008 (204.875MB) ##伊甸區容量

   used     = 74442288 (70.99369812011719MB) ##伊甸區使用

   free     = 140384720 (133.8813018798828MB) ##伊甸區當前剩餘容量

   34.65220164496263% used ##伊甸區使用情況

From Space: ##survior1區

   capacity = 26804224 (25.5625MB) ##survior1區容量

   used     = 3333984 (3.179534912109375MB) ##surviror1區已使用情況

   free     = 23470240 (22.382965087890625MB) ##surviror1區剩餘容量

   12.43827838477995% used ##survior1區使用比例

To Space: ##survior2 區

   capacity = 26804224 (25.5625MB) ##survior2區容量

   used     = 0 (0.0MB) ##survior2區已使用情況

   free     = 26804224 (25.5625MB) ##survior2區剩餘容量

   0.0% used ## survior2區使用比例

PS Old  Generation: ##老年代使用情況

   capacity = 1879048192 (1792.0MB) ##老年代容量

   used     = 30847928 (29.41887664794922MB) ##老年代已使用容量

   free     = 1848200264 (1762.5811233520508MB) ##老年代剩餘容量

   1.6416783843721663% used ##老年代使用比例

Perm Generation: ##永久代使用情況

   capacity = 134217728 (128.0MB) ##perm區容量

   used     = 47303016 (45.111671447753906MB) ##perm區已使用容量

   free     = 86914712 (82.8883285522461MB) ##perm區剩餘容量

   35.24349331855774% used ##perm區使用比例

 

 


 

4>  -histo[:live] 打印每個class的實例數目,內存佔用,類全名信息. VM的內部類名字開頭會加上前綴”*”. 如果live子參數加上後,只統計活的對象數量. 

命令:

jmap -histo:live 19570

結果:

num     #instances(實例)   #bytes(字節大小)  class name(類名)

----------------------------------------------

   1:         65220        9755240      <constMethodKlass>
   2:         65220        8880384      <methodKlass>
   3:         11721        8252112      [B
   4:          6300        6784040      <constantPoolKlass>
   5:         75224        6218208      [C
   6:         93969        5163280      <symbolKlass>
   7:          6300        4854440      <instanceKlassKlass>
   8:          5482        4203152      <constantPoolCacheKlass>
   9:         72097        2307104      java.lang.String
  10:         15102        2289912      [I
  11:          4089        2227728      <methodDataKlass>
  12:         28887        1386576      org.apache.velocity.runtime.parser.Token
  13:          6792         706368          java.lang.Class
  14:          7445         638312          [Ljava.util.HashMap$Entry;

4380:             1             16          com.sun.proxy.$Proxy208
4381:             1             16          sun.reflect.GeneratedMethodAccessor198
4382:             1             16          com.sun.proxy.$Proxy46
4383:             1             16          org.apache.ibatis.ognl.SetPropertyAccessor
4384:             1             16          oracle.jdbc.driver.OracleDriver
4385:             1             16          com.sun.proxy.$Proxy181
4386:             1             16          com.sun.proxy.$Proxy82
4387:             1             16          java.util.jar.JavaUtilJarAccessImpl
4388:             1             16          com.sun.proxy.$Proxy171
4389:             1             16          sun.reflect.GeneratedMethodAccessor136
4390:             1             16            sun.reflect.GeneratedConstructorAccessor22
4391:             1             16          org.elasticsearch.action.search.SearchAction
4392:             1             16          org.springframework.core.annotation.AnnotationAwareOrderComparator
Total       1756265      162523736

 

  採用jmap -histo pid>a.log日誌將其保存,在一段時間後,使用文本對比工具,可以對比出GC回收了哪些對象。

  jmap -dump:format=b,file=outfile 3024可以將3024進程的內存heap輸出出來到outfile文件裏,再配合MAT(內存分析工具)。

 


5> -permstat 打印classload和jvm heap長久層的信息. 包含每個classloader的名字,活潑性,地址,父classloader和加載的class數量. 另外,內部String的數量和佔用內存數也會打印出來. 

命令:

jmap -permstat 19570

結果:

 

解析:

Attaching to process ID 19570, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.80-b11
finding class loader instances ..done.
computing per loader stat ..done.
please wait.. computing liveness.liveness analysis may be inaccurate ...
class_loader    classes    bytes    parent_loader    alive?    type

<bootstrap>    2538    14654264      null      live    <internal>
0x000000070af968c8    63    399160    0x0000000707db1788    dead    org/apache/catalina/loader/WebappClassLoader@0x000000070367d2a8
0x000000070cba7b08    1    3064    0x0000000707e709a8    dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba6a38    28    221344    0x0000000707e709a8    dead    org/apache/jasperrvlet/JasperLoader@0x0000000705b11878
0x000000070baed8b8    32    297296    0x0000000707e709a8    dead    org/apache/jasperrvlet/JasperLoader@0x0000000705b11878
0x000000070919a610    1    3056    0x0000000707e709a8    dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070bdd1e18    1    3064    0x0000000707e709a8    dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x0000000707f1d480    1    3072      null      dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba7f48    1    1912    0x0000000707e709a8    dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba8508    1    3064    0x0000000707e709a8    dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba6c40    1    3064    0x0000000707e709a8    dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070bd4c6a0    1    3056      null      dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba62b0    28    235472    0x0000000707e709a8    dead    org/apache/jasperrvlet/JasperLoader@0x0000000705b11878
0x000000070cba77c8    1    3064    0x0000000707e709a8    dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba7388    1    3064    0x0000000707e709a8    dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba8148    1    3064    0x0000000707e709a8    dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070afd8b60    1    6704    0x0000000707db1788    dead    org/apache/catalina/loader/WebappClassLoader@0x000000070367d2a8
0x000000070919a410    1    1888      null      dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070bdd05b0    1    1912      null      dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070bc848b8    1    3088    0x0000000707db1788    dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba64e8    1    1888    0x0000000707e709a8    dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x0000000707f1d2c0    1    3064    0x0000000707db1788    dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070be82e38    1    1912      null      dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba7908    1    3208      null      dead    sun/reflect/DelegatingClassLoader@0x0000000702a50b98
.........

total = 273    12995    87547304        N/A        alive=1, dead=272        N/A 

 

 


6>  -F 強迫.在pid沒有相應的時候使用-dump或者-histo參數. 在這個模式下,live子參數無效. 

 

7>  -h | -help 打印輔助信息 

 

8>  -J 傳遞參數給jmap啓動的jvm. 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章