环境:MAC OS X 10.10.3 + Oracle JDK 1.7.0_80
jmap 显示运行中JVM内存的使用情况。
1. 用法
(1)jmap [option] PID
(2)jmap [option] executable core
(3)jmap [option] [server_id@] remote server IP or hostname
option 参数可以有如下值:
(1)-heap:打印heap的情况。
(2)-histo:打印heap的直方图。其输出信息包括类名,对象数量,对象占用大小。
(3)--histo:live :同上,但是只打印存活对象的情况。
(4)-permstat:打印permanent generation heap情况。
2. 使用例子
(1)jmap -heap 28218
Attaching to process ID 28218, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.80-b11
using thread-local object allocation.
Parallel GC with 8 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 1367343104 (1304.0MB)
NewSize = 1310720 (1.25MB)
MaxNewSize = 17592186044415 MB
OldSize = 5439488 (5.1875MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 21757952 (20.75MB)
MaxPermSize = 268435456 (256.0MB)
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 370147328 (353.0MB)
used = 51031488 (48.66741943359375MB)
free = 319115840 (304.33258056640625MB)
13.786804372122875% used
From Space:
capacity = 42991616 (41.0MB)
used = 1212416 (1.15625MB)
free = 41779200 (39.84375MB)
2.8201219512195124% used
To Space:
capacity = 42467328 (40.5MB)
used = 0 (0.0MB)
free = 42467328 (40.5MB)
0.0% used
PS Old Generation
capacity = 911212544 (869.0MB)
used = 25955856 (24.753433227539062MB)
free = 885256688 (844.2465667724609MB)
2.848496343790456% used
PS Perm Generation
capacity = 58720256 (56.0MB)
used = 58384392 (55.67969512939453MB)
free = 335864 (0.32030487060546875MB)
99.42802701677594% used
25588 interned Strings occupying 2864016 bytes.
(2)jmap -histo 28218
可以查看java进程中的所有实例、实例的个数,可用于查询单例对象是否真的只生成了一个实例。
num #instances #bytes class name
----------------------------------------------
1: 81575 11722720
2: 81575 10452416
3: 8570 10051584
4: 8567 6175536
5: 7317 5623328
6: 56838 5150184 [C
7: 24518 3694920 [B
8: 60535 1937120 java.util.HashMap$Entry
9: 46036 1848096 [Ljava.lang.Object;
10: 56582 1357968 java.lang.String
11: 42072 1009728 java.util.ArrayList
12: 2137 996464
13: 9142 899600 java.lang.Class
14: 6017 848736 [Ljava.util.HashMap$Entry;
15: 13074 776880 [S
16: 13477 630936 [[I
17: 576 581624 [I
18: 3 393264 [Ljava.net.Socket;
19: 558 303552
20: 7287 291480 java.util.LinkedHashMap$Entry
21: 35 265616 [J
22: 4776 229248 java.util.HashMap
(3)jmap -histo:live 28218
(4)jmap -dump:format=b,file=/path/heap.bin PID
该命令通常用来分析内存泄漏Out of Memory。
首先配置JVM启动参数,让JVM在遇到OutOfMemoryError时自动生成Dump文件: -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/path
然后使用上述命令进行分析。
(5)jmap -dump:live,format=b,file=/path/heap.bin PID
如果只dump heap中的存活对象,则加上选项-live。
使用(4)或(5)dump heap中的对象到文件后,可以使用MAT(Memory Analyzer Tool)进行离线分析。
MAT 是Eclipse上的一个插件。
参考文献:
1. http://zheng12tian.iteye.com/blog/1420508
2. http://blog.csdn.net/fenglibing/article/details/6298326
jmap 显示运行中JVM内存的使用情况。
1. 用法
(1)jmap [option] PID
(2)jmap [option] executable core
(3)jmap [option] [server_id@] remote server IP or hostname
option 参数可以有如下值:
(1)-heap:打印heap的情况。
(2)-histo:打印heap的直方图。其输出信息包括类名,对象数量,对象占用大小。
(3)--histo:live :同上,但是只打印存活对象的情况。
(4)-permstat:打印permanent generation heap情况。
2. 使用例子
(1)jmap -heap 28218
Attaching to process ID 28218, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.80-b11
using thread-local object allocation.
Parallel GC with 8 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 1367343104 (1304.0MB)
NewSize = 1310720 (1.25MB)
MaxNewSize = 17592186044415 MB
OldSize = 5439488 (5.1875MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 21757952 (20.75MB)
MaxPermSize = 268435456 (256.0MB)
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 370147328 (353.0MB)
used = 51031488 (48.66741943359375MB)
free = 319115840 (304.33258056640625MB)
13.786804372122875% used
From Space:
capacity = 42991616 (41.0MB)
used = 1212416 (1.15625MB)
free = 41779200 (39.84375MB)
2.8201219512195124% used
To Space:
capacity = 42467328 (40.5MB)
used = 0 (0.0MB)
free = 42467328 (40.5MB)
0.0% used
PS Old Generation
capacity = 911212544 (869.0MB)
used = 25955856 (24.753433227539062MB)
free = 885256688 (844.2465667724609MB)
2.848496343790456% used
PS Perm Generation
capacity = 58720256 (56.0MB)
used = 58384392 (55.67969512939453MB)
free = 335864 (0.32030487060546875MB)
99.42802701677594% used
25588 interned Strings occupying 2864016 bytes.
(2)jmap -histo 28218
可以查看java进程中的所有实例、实例的个数,可用于查询单例对象是否真的只生成了一个实例。
num #instances #bytes class name
----------------------------------------------
1: 81575 11722720
2: 81575 10452416
3: 8570 10051584
4: 8567 6175536
5: 7317 5623328
6: 56838 5150184 [C
7: 24518 3694920 [B
8: 60535 1937120 java.util.HashMap$Entry
9: 46036 1848096 [Ljava.lang.Object;
10: 56582 1357968 java.lang.String
11: 42072 1009728 java.util.ArrayList
12: 2137 996464
13: 9142 899600 java.lang.Class
14: 6017 848736 [Ljava.util.HashMap$Entry;
15: 13074 776880 [S
16: 13477 630936 [[I
17: 576 581624 [I
18: 3 393264 [Ljava.net.Socket;
19: 558 303552
20: 7287 291480 java.util.LinkedHashMap$Entry
21: 35 265616 [J
22: 4776 229248 java.util.HashMap
(3)jmap -histo:live 28218
(4)jmap -dump:format=b,file=/path/heap.bin PID
该命令通常用来分析内存泄漏Out of Memory。
首先配置JVM启动参数,让JVM在遇到OutOfMemoryError时自动生成Dump文件: -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/path
然后使用上述命令进行分析。
(5)jmap -dump:live,format=b,file=/path/heap.bin PID
如果只dump heap中的存活对象,则加上选项-live。
使用(4)或(5)dump heap中的对象到文件后,可以使用MAT(Memory Analyzer Tool)进行离线分析。
MAT 是Eclipse上的一个插件。
参考文献:
1. http://zheng12tian.iteye.com/blog/1420508
2. http://blog.csdn.net/fenglibing/article/details/6298326
没有评论:
发表评论