jmap命令

Java版本:JDK1.8

0. jmp使用手冊(cè)

[root@localhost ~]$ jmap -help
Usage:
    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)

where <option> is one of:
    <none>               to print same info as Solaris pmap
    -heap                to print java heap summary
    -histo[:live]        to print histogram of java object heap; if the "live"
                         suboption is specified, only count live objects
    -clstats             to print class loader statistics
    -finalizerinfo       to print information on objects awaiting finalization
    -dump:<dump-options> to dump java heap in hprof binary format
                         dump-options:
                           live         dump only live objects; if not specified,
                                        all objects in the heap are dumped.
                           format=b     binary format
                           file=<file>  dump heap to <file>
                         Example: jmap -dump:live,format=b,file=heap.bin <pid>
    -F                   force. Use with -dump:<dump-options> <pid> or -histo
                         to force a heap dump or histogram when <pid> does not
                         respond. The "live" suboption is not supported
                         in this mode.
    -h | -help           to print this help message
    -J<flag>             to pass <flag> directly to the runtime system

1. jmap -heap <pid>

打印heap的概要信息

[root@localhost ~]$ sudo jmap -heap 9557
Attaching to process ID 9557, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.151-b12

using thread-local object allocation.
Parallel GC with 8 thread(s)

Heap Configuration:
   MinHeapFreeRatio         = 0
   MaxHeapFreeRatio         = 100
   MaxHeapSize              = 536870912 (512.0MB)
   NewSize                  = 178782208 (170.5MB)
   MaxNewSize               = 178782208 (170.5MB)
   OldSize                  = 358088704 (341.5MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 0 (0.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 134742016 (128.5MB)
   used     = 4202352 (4.0076751708984375MB)
   free     = 130539664 (124.49232482910156MB)
   3.1188133625668772% used
From Space:
   capacity = 22020096 (21.0MB)
   used     = 524288 (0.5MB)
   free     = 21495808 (20.5MB)
   2.380952380952381% used
To Space:
   capacity = 22020096 (21.0MB)
   used     = 0 (0.0MB)
   free     = 22020096 (21.0MB)
   0.0% used
PS Old Generation
   capacity = 358088704 (341.5MB)
   used     = 6465368 (6.165855407714844MB)
   free     = 351623336 (335.33414459228516MB)
   1.805521349257641% used

7798 interned Strings occupying 651104 bytes.

2. jmap -dump:live,format=b,file=fileName <pid>

dump堆到文件,format指定輸出格式,live指明是活著的對(duì)象,file指定文件名

[root@localhost ~]$ sudo jmap -dump:live,format=b,file=dump.hprof 9557
Dumping heap to /home/mbs/dump.hprof ...
Heap dump file created

查看 dump.hprof 文件

3. jmap -histo:live <pid>

打印堆的對(duì)象統(tǒng)計(jì),包括對(duì)象數(shù)、內(nèi)存大小等。jmap -histo:live 這個(gè)命令執(zhí)行,JVM會(huì)先觸發(fā)gc,然后再統(tǒng)計(jì)信息。

[root@localhost ~]$ sudo jmap -histo:live 9557 | more

 num     #instances         #bytes  class name
----------------------------------------------
   1:         15376        1224224  [C
   2:          4362         490456  java.lang.Class
   3:         15304         367296  java.lang.String
   4:           670         302344  [B
   5:          3548         213936  [Ljava.lang.Object;
   6:          5953         190496  java.util.concurrent.ConcurrentHashMap$Node
   7:          2832          90624  java.util.HashMap$Node
   8:          2061          84560  [I
   9:          5079          81264  java.lang.Object
  10:           369          42224  [Ljava.util.HashMap$Node;
  11:            45          42032  [Ljava.util.concurrent.ConcurrentHashMap$Node;

4. jmap -finalizerinfo <pid>

打印等待回收的對(duì)象信息

[root@localhost ~]$ sudo jmap -finalizerinfo 9557
Attaching to process ID 9557, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.151-b12
Number of objects pending for finalization: 0
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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