jmap(Java Memory Map)主要用于查看jvm内存,是jvm自带的一种内存映像工具。
jmap常用参数:
-heap:打印jvm heap的情况
-histo:打印jvm heap的直方图。其输出信息包括类名,对象数量,对象占用大小。
-histo:live :同上,但是只打印存活对象的情况。
-permstat:打印permanent generation heap情况。
-heap
执行 jmap -heap pid 可以查看进程堆内存使用情况,包括使用的GC算法、堆配置参数和各代中堆内存使用情况。导出日志文件如下:
PROCESS PATH:/export/App/...
DATETIME: 2015-08-13 10:39:10
EXECUTE COMMAND:/export/servers/jdk1.6.0_25/bin/jmap -heap 30119
using thread-local object allocation.
Parallel GC with 23 thread(s)
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 2147483648 (2048.0MB)
NewSize = 536870912 (512.0MB)
MaxNewSize = 536870912 (512.0MB)
OldSize = 5439488 (5.1875MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 67108864 (64.0MB)
MaxPermSize = 134217728 (128.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 534904832 (510.125MB)
used = 281308384 (268.2765808105469MB)
free = 253596448 (241.84841918945312MB)
52.590361344875646% used
From Space:
capacity = 983040 (0.9375MB)
used = 720896 (0.6875MB)
free = 262144 (0.25MB)
73.33333333333333% used
To Space:
capacity = 983040 (0.9375MB)
used = 0 (0.0MB)
free = 983040 (0.9375MB)
0.0% used
PS Old Generation
capacity = 1610612736 (1536.0MB)
used = 1192251304 (1137.0194473266602MB)
free = 418361432 (398.98055267333984MB)
74.02470360199611% used
PS Perm Generation
capacity = 67108864 (64.0MB)
used = 33232488 (31.692970275878906MB)
free = 33876376 (32.307029724121094MB)
49.52026605606079% used
-histo[:live]
使用jmap -histo[:live] pid查看堆内存中的对象数目、大小统计直方图,如果带上live则只统计活对象,如下:
PROCESS PATH:/export/App/...
DATETIME: 2015-08-13 10:13:12
EXECUTE COMMAND:/export/servers/jdk1.6.0_25/bin/jmap -histo 44133
num #instances #bytes class name
----------------------------------------------
1: 244046 849851696 [I
2: 417548 419858768 [B
3: 1347221 127915792 [C
4: 192112 22450864 [Ljava.lang.Object;
5: 690346 22091072 java.lang.String
6: 402121 12867872 java.util.HashMap$Entry
7: 78652 9438240 java.net.SocksSocketImpl
8: 118128 9404576 [Ljava.util.HashMap$Entry;
9: 443640 7098240 java.lang.Object
10: 48045 6960520 <constMethodKlass>
11: 48045 6542488 <methodKlass>
12: 155208 6208320 java.util.HashMap$KeyIterator
13: 128452 6165696 java.nio.HeapByteBuffer
14: 251224 6029376 java.lang.StringBuilder
15: 117438 5637024 java.util.HashMap
16: 4544 4837032 <constantPoolKlass>
17: 106570 4262800 java.util.HashMap$EntryIterator
18: 176445 4234680 java.io.FileDescriptor
19: 71513 3984000 <symbolKlass>
20: 78823 3783504 java.nio.HeapCharBuffer
21: 76481 3671088 java.net.SocketInputStream
22: 4544 3438000 <instanceKlassKlass>
23: 3940 2957856 <constantPoolCacheKlass>
24: 92203 2950496 java.io.FileInputStream
25: 52028 2913568 org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation
26: 179818 2877088 java.util.concurrent.atomic.AtomicInteger
27: 35194 2533968 java.lang.reflect.Field
28: 128507 2528336 [Ljava.lang.Class;
29: 104205 2500920 java.lang.Long
30: 76481 2447392 java.net.Socket
其中:
[C is a char[]
[S is a short[]
[I is a int[]
[B is a byte[]
[[I is a int[][]
constMethodKlass/ methodKlass/ constantPoolKlass/ constantPoolCacheKlass/ instanceKlassKlass/ methodDataKlass
与Classloader相关,常驻与Perm区。
-permstat
使用jmap -permstat pid 打印java堆perm区的classloader统计。如下:
PROCESS PATH:/export/App/...
DATETIME: 2015-08-13 12:17:44
EXECUTE COMMAND:/export/servers/jdk1.6.0_25/bin/jmap -permstat 30119
10404 intern Strings occupying 1025240 bytes.
class_loader classes bytes parent_loader alive? type
<bootstrap> 2031 11679192 null live <internal>
0x00000007b29137a8 1 3112 null dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x00000007800124a0 1 3112 0x0000000780001cf8 dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x0000000780012350 1 3120 null dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x00000007800123f8 1 3088 null dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x0000000780740080 1 3088 null dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x00000007800122a8 1 3088 null dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x0000000780012468 1 3088 0x0000000780001cf8 dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x0000000780012200 1 1960 0x0000000780001cf8 dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x00000007800122e0 1 3112 null dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x0000000780012190 1 3312 null dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x0000000780012158 1 1944 null dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x0000000780012318 1 3112 0x0000000780001cf8 dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x00000007804918b0 0 0 0x0000000780001cf8 dead java/net/URLClassLoader@0x00000007781cf940
0x0000000780012270 1 3112 null dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x0000000780012120 1 3112 0x0000000780001cf8 dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x0000000780012388 1 3112 null dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x00000007800121c8 1 1944 null dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x0000000780012430 1 3136 null dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x00000007800123c0 1 1944 null dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x00000007801efb78 0 0 0x0000000780001cf8 dead java/util/ResourceBundle$RBClassLoader@0x00000007785701c0
0x0000000780012238 1 3112 0x0000000780001cf8 dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x00000007800124d8 1 3112 0x0000000780001cf8 dead sun/reflect/DelegatingClassLoader@0x00000007780675e8
0x0000000780001cf8 2838 16981304 0x0000000780001d40 live sun/misc/Launcher$AppClassLoader@0x000000077823e940
0x0000000780001d40 8 49544 null live sun/misc/Launcher$ExtClassLoader@0x00000007781cfdd8
total = 25 4897 28767760 N/A alive=3, dead=22 N/A