一、命令说明
jmap(Java Memory Map)用于用于生成堆转储快照,有时候也用于查看内存内存使用情况。
二、参数说明
C:\Users\Administrator>jmap
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 : 打印Java内存使用统计信息
C:\Users\Administrator>jmap -heap 7364
Attaching to process ID 7364, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.77-b03
using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 4294967296 (4096.0MB
NewSize = 1073741824 (1024.0MB
MaxNewSize = 1073741824 (1024.0MB
OldSize = 1073741824 (1024.0MB
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875M
CompressedClassSpaceSize = 1073741824 (1024.0MB
MaxMetaspaceSize = 2147483648 (2048.0MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
New Generation (Eden + 1 Survivor Space): //---------------新生代
capacity = 966393856 (921.625MB)
used = 360977320 (344.25479888916016MB)
free = 605416536 (577.3702011108398MB)
37.35302307219966% used
Eden Space: //-----------------伊甸区
capacity = 859045888 (819.25MB)
used = 360977320 (344.25479888916016MB)
free = 498068568 (474.99520111083984MB)
42.02072613843883% used
From Space: //----------------第一幸存区
capacity = 107347968 (102.375MB)
used = 0 (0.0MB)
free = 107347968 (102.375MB)
0.0% used
To Space: //-----------------第二幸存区
capacity = 107347968 (102.375MB)
used = 0 (0.0MB)
free = 107347968 (102.375MB)
0.0% used
concurrent mark-sweep generation:
capacity = 1073741824 (1024.0MB)
used = 590955568 (563.5791473388672MB)
free = 482786256 (460.4208526611328MB)
55.03702610731125% used
156040 interned Strings occupying 14738896 bytes.
2 . jmap -histo[:live] : 打印每个类的实例数以及所占空间的统计信息
jmap -histo 7364 > c:\Users\Administrator\Desktop\2.txt
num #instances #bytes class name
----------------------------------------------
1: 3393365 348565536 [C
2: 631117 100897704 [B
3: 117043 68459672 [I
4: 2724434 65386416 java.lang.String
5: 538821 47416248 java.lang.reflect.Method
6: 371571 18602096 [Ljava.lang.Object;
7: 426426 17057040 java.util.TreeMap$Entry
8: 2070 16797336 [J
9: 473146 15140672 java.util.concurrent.ConcurrentHashMap$Node
10: 465948 14910336 java.util.HashMap$Node
11: 439728 14071296 java.lang.ref.WeakReference
12: 417987 10968376 [Ljava.lang.String;
13: 122936 10818368 com.seeyon.ctp.common.i18n.domain.ResourceInfo
//只打印出存活对象
jmap -histo:live 7364 > c:\Users\Administrator\Desktop\2.txt
num #instances #bytes class name
----------------------------------------------
1: 1991718 197879544 [C
2: 1984202 47620848 java.lang.String
3: 527284 46400992 java.lang.reflect.Method
4: 1201 16776160 [J
5: 339593 16602976 [Ljava.lang.Object;
6: 18450 15985840 [B
7: 466136 14916352 java.util.concurrent.ConcurrentHashMap$Node
8: 440931 14109792 java.util.HashMap$Node
9: 437902 14012864 java.lang.ref.WeakReference
10: 84851 12626640 [I
附 - jmap输出中class name非自定义类的说明:
BaseType Character | Type |
---|---|
B | byte |
C | char |
D | double |
F | float |
I | int |
J | long |
L | 引用对象 |
S | short |
Z | boolean |
[ | 数组引用对象 |
3 .jmap -finalizerinfo : 打印等待回收的对象信息
C:\Users\Administrator>jmap -finalizerinfo 7364
Attaching to process ID 7364, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.77-b03
Number of objects pending for finalization: 0