jmap
输出进程、核心文件或远程调试服务器的共享对象内存或者堆内存的相关信息。
语法
jmap [ options ] pid
jmap [ options ] executable core
jmap [ options ] [ pid ] server-id@ ] remote-hostname-or-IP
解释
-
executable
产生核心转储的Java可执行文件
-
core
打印内存信息的核心文件
-
remote-hostname-or-IP
远程调试服务器的
hostname
或者IP
地址。查看jsadebug -
server-id
远程服务器上有多个调试服务器时,提供的调式服务器唯一ID
-
通过``-J-d64
可以指定
jmap`运行在64位JVM上jmap -J-d64 -heap pid
Options
<no option>
没有option参数,jmap
命令输出共享对象映射信息。会输出JVM中所有共享对象的起始地址、映射大小、文件的全路径
$ jmap 5208
Attaching to process ID 5208, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.40-b25
0x0000000056140000 8716K D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\server\jvm.dll
0x00000000569d0000 840K D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\msvcr100.dll
0x0000000056e10000 52K D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\management.dll
0x0000000056e20000 68K D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\nio.dll
0x0000000056e40000 104K D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\net.dll
0x0000000056e60000 88K D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\zip.dll
-dump:[live,] format=b, file=*filename*
- 将Java堆信息存入filename指定文件名的
hprof
二进制文件中; -
live
是可选操作,指定live
表示只保存活跃对象; - 使用
jhat
命令可以读取文件;
$ jmap -dump:live,format=b,file=test 5208
Dumping heap to C:\user\username\Desktop\test ...
Heap dump file created
$ jhat C:\\Users\\username\\Desktop\\test
Reading from C:\Users\username\Desktop\test...
Dump file created Fri Dec 27 13:20:01 CST 2019
Snapshot read, resolving...
Resolving 502739 objects...
Chasing references, expect 100 dots....................................................................................................
Eliminating duplicate references....................................................................................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.
访问localhost:7000可以查看文件具体内容
![](https://img.haomeiwen.com/i8155181/551e817d749a6cbe.png)
finalizerinfo
$ jmap -finalizerinfo 10864
Attaching to process ID 10864, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.40-b25
Number of objects pending for finalization: 0
heap
输出堆垃圾回收的摘要信息,配置信息,各年代的堆使用信息以及 interned Strings的是数量和大小。
$ jmap -heap 10864
Attaching to process ID 10864, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.40-b25
using thread-local object allocation.
Garbage-First (G1) GC with 4 thread(s)
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 1073741824 (1024.0MB)
NewSize = 1363144 (1.2999954223632812MB)
MaxNewSize = 643825664 (614.0MB)
OldSize = 5452592 (5.1999969482421875MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 268435456 (256.0MB)
G1HeapRegionSize = 1048576 (1.0MB)
Heap Usage:
G1 Heap:
regions = 1024
capacity = 1073741824 (1024.0MB)
used = 402117216 (383.4888610839844MB)
free = 671624608 (640.5111389160156MB)
37.45008409023285% used
G1 Young Generation:
Eden Space:
regions = 341
capacity = 572522496 (546.0MB)
used = 357564416 (341.0MB)
free = 214958080 (205.0MB)
62.45421245421245% used
Survivor Space:
regions = 31
capacity = 32505856 (31.0MB)
used = 32505856 (31.0MB)
free = 0 (0.0MB)
100.0% used
G1 Old Generation:
regions = 15
capacity = 468713472 (447.0MB)
used = 10998368 (10.488861083984375MB)
free = 457715104 (436.5111389160156MB)
2.34650136107033% used
22533 interned Strings occupying 2048048 bytes.
histo[:live]
- 将堆信息以列表(histogram)的形式输出;
- 输出每个类的信息:对象个数、内存字节数、全路径;
- 如果指定
live
,只统计活跃对象信息(从以下输出可以看到对象数是不同的)
$ jmap -histo 10864
num #instances #bytes class name
----------------------------------------------
1: 887212 198868312 [C
2: 423381 89093320 [B
3: 46645 26477944 [I
4: 542764 13026336 java.lang.String
5: 128620 12347520 sun.util.calendar.Gregorian$Date
6: 128391 10271280 java.util.zip.ZipEntry
7: 92913 4668984 [Ljava.lang.Object;
8: 112727 2705448 java.util.Date
9: 46899 2626344 java.util.stream.ReferencePipeline$Head
10: 48749 1949960 java.security.AccessControlContext
11: 82135 1814832 [Ljava.lang.Class;
12: 14411 1632616 java.lang.Class
13: 50674 1621568 java.util.HashMap$Node
14: 46875 1500000 java.util.Spliterators$ArraySpliterator
15: 16237 1314488 [Ljava.util.HashMap$Node;
16: 14048 1236224 java.lang.reflect.Method
17: 35411 1133152 java.util.concurrent.ConcurrentHashMap$Node
18: 46864 1124736 java.util.stream.MatchOps$$Lambda$45/319558327
19: 40542 973008 java.lang.StringBuilder
20: 19482 935136 java.util.HashMap
21: 26831 870296 [Ljava.security.ProtectionDomain;
22: 33581 805944 org.apache.commons.collections.map.ListOrderedMap$ListOrderedMapEntry
23: 9684 772896 [S
24: 46864 749824 org.apache.jorphan.reflect.ClassFinder$ExtendsClassFilter$$Lambda$44/1397381784
25: 20407 653024 java.util.ArrayList$Itr
26: 10000 640000 java.awt.event.InvocationEvent
27: 18944 606208 java.util.concurrent.locks.AbstractQueuedSynchronizer$Node
28: 18127 580064 java.util.Hashtable$Entry
29: 17336 554752 java.beans.PropertyChangeEvent
30: 13686 547440 java.lang.ref.Finalizer
31: 31829 509264 java.lang.Object
32: 19459 467016 java.util.ArrayList
....................
3770: 1 16 sun.text.normalizer.NormalizerImpl$FCDTrieImpl
3771: 1 16 sun.text.normalizer.NormalizerImpl$NormTrieImpl
3772: 1 16 sun.util.CoreResourceBundleControl
3773: 1 16 sun.util.calendar.Gregorian
3774: 1 16 sun.util.locale.InternalLocaleBuilder$CaseInsensitiveChar
3775: 1 16 sun.util.locale.provider.AuxLocaleProviderAdapter$NullProvider
3776: 1 16 sun.util.locale.provider.CalendarDataUtility$CalendarFieldValueNamesMapGetter
3777: 1 16 sun.util.locale.provider.CalendarDataUtility$CalendarWeekParameterGetter
3778: 1 16 sun.util.locale.provider.CalendarNameProviderImpl$LengthBasedComparator
3779: 1 16 sun.util.locale.provider.SPILocaleProviderAdapter
3780: 1 16 sun.util.locale.provider.TimeZoneNameUtility$TimeZoneNameGetter
3781: 1 16 sun.util.resources.LocaleData
3782: 1 16 sun.util.resources.LocaleData$LocaleDataResourceBundleControl
Total 3659918 405059648
$ jmap -histo:live 10864
num #instances #bytes class name
----------------------------------------------
1: 7681 6404584 [B
2: 74426 6304912 [C
3: 13259 4714608 [I
4: 72674 1744176 java.lang.String
5: 14411 1632616 java.lang.Class
......................
3034: 1 16 sun.util.locale.provider.SPILocaleProviderAdapter
3035: 1 16 sun.util.locale.provider.TimeZoneNameUtility$TimeZoneNameGetter
3036: 1 16 sun.util.resources.LocaleData
3037: 1 16 sun.util.resources.LocaleData$LocaleDataResourceBundleControl
Total 561269 36751776
clstats
- 输出Java堆中类加载器的统计信息;
- 输出每个类加载器的信息:名称,状态,地址,父类加载器,已加载的类的数量和大小;
- 统计会比较耗费时间;
$ jmap -clstats 10864
Attaching to process ID 10864, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.40-b25
finding class loader instances ..done.
computing per loader stat ..done.
please wait.. computing liveness..........................................................liveness analysis may be inaccurate ...
class_loader classes bytes parent_loader alive? type
<bootstrap> 3835 6981748 null live <internal>
0x00000000c02ccba8 1 1471 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1aa4420 1 878 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02cd820 1 1472 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c202e190 1 878 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1c3e350 1 878 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1dbe048 1 1472 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02ccd38 1 1472 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c134d6a0 1 1471 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c03acea0 1 1471 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02cc7b0 10587 13944043 0x00000000c0300be8 live org/apache/jmeter/DynamicClassLoader@0x0000000100060218
0x00000000c1e0fe40 1 878 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c10256a0 1 1471 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02cc888 1 1481 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c19dc138 1 1471 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c19dcb38 1 1473 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c19e6fb8 1 1473 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c19aa9b0 1 1473 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1aa5000 1 878 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02cce00 1 1472 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c0fd55d0 12 37189 0x00000000c0300be8 live sun/reflect/misc/MethodUtil@0x00000001001e1028
0x00000000c0ef5fc0 1 878 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02cca18 1 1472 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c0270990 0 0 0x00000000c0300be8 live java/util/ResourceBundle$RBClassLoader@0x00000001000f2f58
0x00000000c0fd4ec0 1 878 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c0ef6450 1 1471 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1025440 1 878 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02cd8e8 1 1472 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c037f870 1 1471 0x00000000c02ccec8 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1eac520 1 878 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1fb10b0 1 878 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02ccae0 1 1472 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c03d5370 1 878 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c10a22d8 1 1471 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c23a9668 1 878 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c0300be8 37 144387 0x00000000c02ccec8 live sun/misc/Launcher$AppClassLoader@0x000000010000f668
0x00000000c02ccc70 1 1471 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c13df1e0 1 1472 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1522db0 1 1471 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c202e8e0 1 878 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02ccec8 152 345291 null live sun/misc/Launcher$ExtClassLoader@0x000000010000fa10
0x00000000c20611e0 1 1471 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c0ef6108 1 878 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c19e2e70 1 1473 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1fe6910 1 878 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c206a068 1 878 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c10a1ef8 1 878 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c0fd5088 1 889 0x00000000c0fd55d0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c13d75c8 1 1473 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1e25298 1 1471 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02cc950 1 1471 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c23c42c0 1 878 0x00000000c02cc7b0 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
total = 52 14669 21509096 N/A alive=6, dead=46 N/A
F
强制输出
- 使用
jmap -dump
或者jmap -histo
命令时,如果进程没有响应,可以使用-F
强制输出; -
live
模式下不能使用-F
强制输出;
h
help
-h
与-help
都是输出帮助信息的指令
-Jflag
将flag
信息传递给运行jamp
命令的虚拟机
其他文章列表
spring web service系列1
spring web service系列2
spring web service系列3
maven配置文件settings.xml详解
Nginx转发请求过程解析
Nginx中的负载均衡算法
Nginx upstream指令配置说明
Nginx中虚拟服务器server指令配置说明
Nginx中proxy_pass/proxy_redirect/proxy_set_header配置说明
Nginx中ngx_http_core_module相关指令配置说明
Java自带JVM监控工具jstat使用详细说明
Java自带JVM监控工具jps使用详细说明
Java自带故障分析工具jhat工具使用说明
网友评论