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