当java应用程序出现OOM(内存溢出)异常时,jmap是我们常用的排错指令,此指令能让我们看到jvm heap内存信息,java进程中每个对象有多少个实例,占用多少内存等信息
例一:查看jvm heap(堆内存)信息
[www@iZbp1j3zm4hugfnv44puytZ ~]$ jmap -heap 2493
Attaching to process ID 2493, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.73-b02
using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 1258291200 (1200.0MB)
NewSize = 1073741824 (1024.0MB)
MaxNewSize = 1073741824 (1024.0MB)
OldSize = 184549376 (176.0MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
New Generation (Eden + 1 Survivor Space):
capacity = 966393856 (921.625MB)
used = 966393848 (921.6249923706055MB)
free = 8 (7.62939453125E-6MB)
99.99999917218017% used
Eden Space:
capacity = 859045888 (819.25MB)
used = 859045880 (819.2499923706055MB)
free = 8 (7.62939453125E-6MB)
99.99999906873427% used
From Space:
capacity = 107347968 (102.375MB)
used = 107347968 (102.375MB)
free = 0 (0.0MB)
100.0% used
To Space:
capacity = 107347968 (102.375MB)
used = 0 (0.0MB)
free = 107347968 (102.375MB)
0.0% used
concurrent mark-sweep generation:
capacity = 184549376 (176.0MB)
used = 184549344 (175.99996948242188MB)
free = 32 (3.0517578125E-5MB)
99.99998266046697% used
20905 interned Strings occupying 2220488 bytes.
[www@iZbp1j3zm4hugfnv44puytZ ~]$
上面2493为进程号:
jvm heap(堆)内存主要分为:
新生代(Young Generation)又分为:Eden区和Survivor区,Survivor区有分为From Space和To Space。Eden区是对象最初分配到的地方;默认情况下,From Space和To Space的区域大小相等。
老年代(Old Generation)
永久代(Permanent Generation)
例二:java进程中每个对象有多少个实例,占用多少内存信息
[root@localhost ~]# jmap -histo 25453 | head -n 20
num #instances #bytes class name
----------------------------------------------
1: 220855 27984664 [C
2: 19802 18777128 [B
3: 8735 11026312 [I
4: 211785 5082840 java.lang.String
5: 52714 5060544 java.util.jar.JarFile$JarFileEntry
6: 94705 3030560 java.util.HashMap$Node
7: 11058 1554912 [Ljava.util.HashMap$Node;
8: 10760 1207792 java.lang.Class
9: 21710 1136096 [Ljava.lang.Object;
10: 32501 1040032 java.util.concurrent.ConcurrentHashMap$Node
11: 11019 969672 java.lang.reflect.Method
12: 15147 969408 java.net.URL
13: 17583 703320 java.util.LinkedHashMap$Entry
14: 9742 545552 java.util.LinkedHashMap
15: 11037 529776 java.util.HashMap
16: 9381 525336 java.util.concurrent.ConcurrentHashMap$ValueIterator
17: 9147 439056 org.apache.catalina.loader.ResourceEntry
Total 1089836 92194448
上面25453为进程号,因为输出太多只取前20行:
第一列,序号,无实际意义
第二列,对象实例数量
第三列,对象实例占用总内存数,单位:字节
第四列,对象实例名称
最后一行,总实例数量与总内存占用数
另,部分示例说明(还没弄明白,后续补充):
[C,
[B,
[I,
[J,
[L,
参考:
http://www.importnew.com/15671.html
https://blog.csdn.net/zlzlei/article/details/46472729