jmap
- -heap 打印堆的概要信息 命令:
1jmap -heap 7664
各部分说明如下:
1C:\Users\Administrator>jmap -heap 7664
2Attaching to process ID 7664, please wait...
3Debugger attached successfully.
4Client compiler detected.
5JVM version is 25.131-b11
6
7using thread-local object allocation.
8Mark Sweep Compact GC
9
10Heap Configuration: ##JVM堆的配置参数
11 MinHeapFreeRatio = 40
12 MaxHeapFreeRatio = 70
13 MaxHeapSize = 268435456 (256.0MB) ##堆的最大大小
14 NewSize = 5570560 (5.3125MB) ##新生代大小
15 MaxNewSize = 89456640 (85.3125MB) ##新生代最大大小
16 OldSize = 11206656 (10.6875MB) ##老年代大小
17 NewRatio = 2 ##新生代:老年代=1:2
18 SurvivorRatio = 8 ##Eden:2s = 8:2
19 MetaspaceSize = 12582912 (12.0MB) ##元空间的初始大小
20 CompressedClassSpaceSize = 1073741824 (1024.0MB)
21 MaxMetaspaceSize = 314572800 (300.0MB) ##元空间的最大大小
22 G1HeapRegionSize = 0 (0.0MB)
23
24Heap Usage: ##堆的实际使用情况
25New Generation (Eden + 1 Survivor Space): ##新生代的使用情况,约18M
26 capacity = 17170432 (16.375MB)
27 used = 15385488 (14.672744750976562MB)
28 free = 1784944 (1.7022552490234375MB)
29 89.60454809756679% used
30Eden Space: ##伊甸区
31 capacity = 15269888 (14.5625MB)
32 used = 15269888 (14.5625MB)
33 free = 0 (0.0MB)
34 100.0% used
35From Space:
36 capacity = 1900544 (1.8125MB)
37 used = 115600 (0.1102447509765625MB)
38 free = 1784944 (1.7022552490234375MB)
39 6.082469019396552% used
40To Space:
41 capacity = 1900544 (1.8125MB)
42 used = 6264 (0.00597381591796875MB)
43 free = 1894280 (1.8065261840820312MB)
44 0.32958984375% used
45tenured generation: ##老年代的使用情况,约36M
46 capacity = 38060032 (36.296875MB)
47 used = 35454608 (33.81214904785156MB)
48 free = 2605424 (2.4847259521484375MB)
49 93.15443560320706% used
50
5120829 interned Strings occupying 2643456 bytes.
- -dump 转储heap 命令:
1jmap -dump:file=D:/a.phrof 7144
jstat
jstat命令可以查看堆内存各部分的使用量,以及加载类的数量。
-gc 垃圾回收的大小
1C:\Users\Administrator>jstat -gc 7044
2 S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
31280.0 1280.0 116.9 0.0 10816.0 8653.0 26700.0 19417.7 52096.0 51394.9 0.0 0.0 2906 4.484 4 0.151 4.635
各个字段的含义如下:
- S0C:第一个幸存区的大小
- S1C:第二个幸存区的大小
- S0U:第一个幸存区的使用大小
- S1U:第二个幸存区的使用大小
- EC:伊甸园区的大小
- EU:伊甸园区的使用大小
- OC:老年代大小
- OU:老年代使用大小
- MC:方法区大小
- MU:方法区使用大小
- CCSC:压缩类空间大小
- CCSU:压缩类空间使用大小
- YGC:年轻代垃圾回收次数
- YGCT:年轻代垃圾回收消耗时间
- FGC:老年代垃圾回收次数
- FGCT:老年代垃圾回收消耗时间
- GCT:垃圾回收消耗总时间
jcmd
JDK7后新增的命令,查看JVM内存的信息,很有用。
- jcmd -l 查看所有的java进程,同jps命令。
1C:\Users\Administrator>jcmd -l
25216
37044 test.metaspace.TestMetaSpace
4740 org.jetbrains.idea.maven.server.RemoteMavenServer
5872 sun.tools.jcmd.JCmd -l
64972 org.jetbrains.jps.cmdline.Launcher C:/Program Files/JetBrains/IntelliJ IDEA 2017.3.7/lib/jgoodies-forms.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2017.3.7/lib/jps-builders-6.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2017.3.7/lib/oromatcher.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2017.3.7/lib/javac2.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2017.3.7/lib/slf4j-api-1.7.10.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2017.3.7/lib/annotations.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2017.3.7/lib/util.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2017.3.7/lib/httpclient-4.5.2.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2017.3.7/lib/snappy-in-java-0.5.1.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2017.3.7/lib/aether-dependency-resolver.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2017.3.7/lib/jdom.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2017.3.7/lib/resources_en.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2017.3.7/lib/protobuf-java-2.5.0.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2017.3.7/
- jcmd PID help 查看帮助信息
1C:\Users\Administrator>jcmd 7044 help
27044:
3The following commands are available:
4JFR.stop
5JFR.start
6JFR.dump
7JFR.check
8VM.native_memory
9VM.check_commercial_features
10VM.unlock_commercial_features
11ManagementAgent.stop
12ManagementAgent.start_local
13ManagementAgent.start
14GC.rotate_log
15Thread.print
16GC.class_stats
17GC.class_histogram
18GC.heap_dump
19GC.run_finalization
20GC.run
21VM.uptime
22VM.flags
23VM.system_properties
24VM.command_line
25VM.version
26help
- jcmd PID VM.uptime 运行时间
1C:\Users\Administrator>jcmd 4236 VM.uptime
24236:
317.314 s
- jcmd PID VM.flags 查看你JVM的启动参数
1C:\Users\Administrator>jcmd 4236 VM.flags
24236:
3-XX:InitialHeapSize=16777216 -XX:MaxHeapSize=268435456 -XX:MaxMetaspaceSize=314572800 -XX:MaxNewSize=89456640 -XX:MinHeapDeltaBytes=131072 -XX:NewSize=5570560 -XX:OldSize=11206656 -XX:+UseFastUnorderedTimeStamps -XX:-UseLargePagesIndividualAllocation
- jcmd pid PerfCounter.print 查看性能统计
1C:\Users\Administrator>jcmd 4236 PerfCounter.print
24236:
3java.ci.totalTime=2222906
4java.cls.loadedClasses=33926
5java.cls.sharedLoadedClasses=534
6java.cls.sharedUnloadedClasses=0
7java.cls.unloadedClasses=0
8java.property.java.class.path="C:\Program Files\Java\jdk1.8.0_131\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\access-bridge.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_131\j"
9java.property.java.endorsed.dirs="C:\Program Files\Java\jdk1.8.0_131\jre\lib\endorsed"
10java.property.java.ext.dirs="C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext"
11java.property.java.home="C:\Program Files\Java\jdk1.8.0_131\jre"
12java.property.java.library.path="C:\Program Files\Java\jdk1.8.0_131\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.8.0_131\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;;."
13java.property.java.version="1.8.0_131"
14java.property.java.vm.info="mixed mode, sharing"
15java.property.java.vm.name="Java HotSpot(TM) Client VM"
16java.property.java.vm.specification.name="Java Virtual Machine Specification"
17java.property.java.vm.specification.vendor="Oracle Corporation"
18java.property.java.vm.specification.version="1.8"
19java.property.java.vm.vendor="Oracle Corporation"
20java.property.java.vm.version="25.131-b11"
- jcmd PID GC.class_histogram 查看进程中类的统计信息
1C:\Users\Administrator>jcmd 4236 GC.class_histogram
24236:
3
4 num #instances #bytes class name
5----------------------------------------------
6 1: 196631 17303528 java.lang.reflect.Method
7 2: 89900 12060616 [C
8 3: 43517 6228224 java.lang.Class
9 4: 341415 5462640 net.sf.cglib.core.Signature
10 5: 170676 5461632 net.sf.cglib.proxy.MethodProxy
11 6: 170676 5461632 net.sf.cglib.proxy.MethodProxy$CreateInfo
12 7: 5128 4841296 [I
13 8: 86027 4803360 [Ljava.lang.Object;
14 9: 89749 1435984 java.lang.String
15 10: 171157 1369256 java.lang.Object
16 11: 42785 1369120 java.lang.ref.SoftReference
17 12: 42674 1365568 java.lang.ThreadLocal$ThreadLocalMap$Entry
18 13: 42994 1031856 java.util.HashMap$Node
19 14: 42675 682800 java.lang.ThreadLocal
20 15: 28446 474960 [Ljava.lang.Class;
21 16: 34 266336 [Ljava.util.HashMap$Node;
22 17: 2 262240 [Ljava.lang.ThreadLocal$ThreadLocalMap$Entry;
- jcmd PID Thread.print 查看线程的堆栈信息
1C:\Users\Administrator>jcmd 4236 Thread.print
24236:
32020-02-03 17:03:02
4Full thread dump Java HotSpot(TM) Client VM (25.131-b11 mixed mode, sharing):
5
6"Service Thread" #8 daemon prio=9 os_prio=0 tid=0x0213d400 nid=0x19cc runnable [0x00000000]
7 java.lang.Thread.State: RUNNABLE
8
9"C1 CompilerThread0" #7 daemon prio=9 os_prio=2 tid=0x02139000 nid=0x1b9c waiting on condition [0x00000000]
10 java.lang.Thread.State: RUNNABLE
11
12"Monitor Ctrl-Break" #6 daemon prio=5 os_prio=0 tid=0x14df9c00 nid=0x1d54 runnable [0x1500f000]
13 java.lang.Thread.State: RUNNABLE
14 at java.net.SocketInputStream.socketRead0(Native Method)
15 at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
16 at java.net.SocketInputStream.read(SocketInputStream.java:171)
17 at java.net.SocketInputStream.read(SocketInputStream.java:141)
18 at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
19 at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
20 at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
21 - locked <0x097afce0> (a java.io.InputStreamReader)
22 at java.io.InputStreamReader.read(InputStreamReader.java:184)
23 at java.io.BufferedReader.fill(BufferedReader.java:161)
24 at java.io.BufferedReader.readLine(BufferedReader.java:324)
25 - locked <0x097afce0> (a java.io.InputStreamReader)
26 at java.io.BufferedReader.readLine(BufferedReader.java:389)
27 at com.intellij.rt.execution.application.AppMainV2$1.run(AppMainV2.java:64)
28
29"Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x020df000 nid=0x8f8 waiting on condition [0x00000000]
30 java.lang.Thread.State: RUNNABLE
31
32"Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x020dd400 nid=0x1c04 runnable [0x00000000]
33 java.lang.Thread.State: RUNNABLE
34
35"Finalizer" #3 daemon prio=8 os_prio=1 tid=0x020c0c00 nid=0x7cc in Object.wait() [0x14cbf000]
36 java.lang.Thread.State: WAITING (on object monitor)
37 at java.lang.Object.wait(Native Method)
38 - waiting on <0x097b01b0> (a java.lang.ref.ReferenceQueue$Lock)
39 at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
40 - locked <0x097b01b0> (a java.lang.ref.ReferenceQueue$Lock)
41 at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
42 at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)
43
44"Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x02067000 nid=0x728 in Object.wait() [0x041df000]
45 java.lang.Thread.State: WAITING (on object monitor)
46 at java.lang.Object.wait(Native Method)
47 - waiting on <0x097b0350> (a java.lang.ref.Reference$Lock)
48 at java.lang.Object.wait(Object.java:502)
49 at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
50 - locked <0x097b0350> (a java.lang.ref.Reference$Lock)
51 at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
52
53"main" #1 prio=5 os_prio=0 tid=0x00adc800 nid=0x174c runnable [0x01a4f000]
54 java.lang.Thread.State: RUNNABLE
55 at java.lang.String.equals(String.java:990)
56 at java.util.HashMap.getNode(HashMap.java:571)
57 at java.util.HashMap.containsKey(HashMap.java:595)
58 at java.util.HashSet.contains(HashSet.java:203)
59 at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$1.evaluate(AbstractClassGenerator.java:78)
60 at net.sf.cglib.core.DefaultNamingPolicy.getClassName(DefaultNamingPolicy.java:51)
61 at net.sf.cglib.core.AbstractClassGenerator.generateClassName(AbstractClassGenerator.java:157)
62 at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:320)
63 - locked <0x097915f0> (a sun.misc.Launcher$AppClassLoader)
64 at net.sf.cglib.proxy.Enhancer.generate(Enhancer.java:492)
65 at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:117)
66 at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:294)
67 at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:480)
68 at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:305)
69 at test.metaspace.TestMetaSpace.main(TestMetaSpace.java:23)
70
71"VM Thread" os_prio=2 tid=0x02062c00 nid=0x1eac runnable
72
73"VM Periodic Task Thread" os_prio=2 tid=0x14e73000 nid=0x1198 waiting on condition
74
75JNI global references: 124
- jcmd PID GC.heap_dump fileName 堆的转储
1C:\Users\Administrator>jcmd 4236 GC.heap_dump d:/aa.hprof
24236:
3Heap dump file created
- jcmd PID VM.system_properties 查看JVM的系统属性
- jcmd PID VM.version 查看JVM的版本信息
1C:\Users\Administrator>jcmd 2472 VM.version
22472:
3Java HotSpot(TM) Client VM version 25.131-b11
4JDK 8.0_131
- jcmd PID VM.command_line 查看JVM的命令行参数
1C:\Users\Administrator>jcmd 2472 VM.command_line
22472:
3VM Arguments:
4jvm_args: -XX:MaxMetaspaceSize=300m -javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\lib\idea_rt.jar=53002:C:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\bin -Dfile.encoding=UTF-8
5java_command: test.metaspace.TestMetaSpace
6java_class_path (initial): C:\Program Files\Java\jdk1.8.0_131\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\access-bridge.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar;D:\develop\IdeaProjects\learning\test01\target\classes;D:\develop\maven_repo\io\netty\netty-all\4.1.0.Final\netty-all-4.1.0.Final.jar;D:\develop\maven_repo\cglib\cglib\3.2.10\cglib-3.2.10.jar;D:\develop\maven_repo\org\ow2\asm\asm\7.0\asm-7.0.jar;D:\develop\maven_repo\org\apache\ant\ant\1.10.3\ant-1.10.3.jar;D:\develop\maven_repo\org\apache\ant\ant-launcher\1.10.3\ant-launcher-1.10.3.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\lib\idea_rt.jar
7Launcher Type: SUN_STANDARD
jstack
专门查看线程堆栈信息。命令:jstack PID 同jscmd PID Thread.print
1C:\Users\Administrator>jstack 2472
22020-02-03 17:19:21
3Full thread dump Java HotSpot(TM) Client VM (25.131-b11 mixed mode):
4
5"Service Thread" #8 daemon prio=9 os_prio=0 tid=0x14d4b800 nid=0x18b0 runnable [0x00000000]
6 java.lang.Thread.State: RUNNABLE
7
8"C1 CompilerThread0" #7 daemon prio=9 os_prio=2 tid=0x14d4a800 nid=0x1de0 waiting on condition [0x00000000]
9 java.lang.Thread.State: RUNNABLE
10
11"Monitor Ctrl-Break" #6 daemon prio=5 os_prio=0 tid=0x14d4a000 nid=0x1d9c runnable [0x14faf000]
12 java.lang.Thread.State: RUNNABLE
13 at java.net.SocketInputStream.socketRead0(Native Method)
14 at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
15 at java.net.SocketInputStream.read(SocketInputStream.java:171)
16 at java.net.SocketInputStream.read(SocketInputStream.java:141)
17 at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
18 at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
19 at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
20 - locked <0x09da3e70> (a java.io.InputStreamReader)
MBC 图形化JVM工具
JVM自带的一个内存分析工具,类似Jvisualvm
jhat
jhat 转储文件路径 jhat用于解析转储文件hprof
OQL
对象查询语言