java自帶命令行工具(jmap,jhat,jinfo)
(1)JMAP
1.作用
打印進程,core文件,和遠程進程的共享對象存儲map或堆存儲器的詳細信息。
2.使用
1
2
3
|
jmap[options]pid jmap[options]executablecore jmap[options][pid]server-id@]remote-hostname-or-IP |
如果指定的進程是在64位Java虛擬機(JVM)上運行,那么你可能需要指定-J-d64選項,例如:jmap -J-d64 -heap pid。
3.參數選項
3.1
當不使用選項,該jmap命令打印共享對象映射
如
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
C:\Users\Administrator>jmap9208 AttachingtoprocessID9208,pleasewait... Debuggerattachedsuccessfully. Servercompilerdetected. JVMversionis24. 75 -b04 0x00000000623c00008016KD:\Java\jdk1. 7 .0_75\jre\bin\server\jvm.dll 0x0000000062ba0000840KD:\Java\jdk1. 7 .0_75\jre\bin\msvcr100.dll 0x0000000062cc0000144KD:\Java\jdk1. 7 .0_75\jre\bin\sunec.dll 0x0000000062cf000068KD:\Java\jdk1. 7 .0_75\jre\bin\nio.dll 0x0000000062d10000100KD:\Java\jdk1. 7 .0_75\jre\bin\net.dll 0x0000000062d30000160KD:\Java\jdk1. 7 .0_75\jre\bin\java.dll 0x00000000634d000084KD:\Java\jdk1. 7 .0_75\jre\bin\zip.dll 0x000000006595000044KD:\Java\jdk1. 7 .0_75\jre\bin\sunmscapi.dll 0x000000006596000060KD:\Java\jdk1. 7 .0_75\jre\bin\verify.dll 0x000000006597000044KD:\Java\jdk1. 7 .0_75\jre\bin\management.dll ... |
3.2
-dump:[live,] format=b, file=filename
轉儲Java堆hprof二進制格式。指定live,標識轉儲active狀態的對象。生成的文件可以由jhat命令查看。
1
2
3
|
C:\Users\Administrator>jmap-dump:format=b,file=9208_0413.hprof9208 DumpingheaptoC:\Users\Administrator\9208_0413.hprof... Heapdumpfilecreated |
3.3-finalizerinfo
打印將要結束的對象的信息
1
2
3
4
5
6
|
C:\Users\Administrator>jmap-finalizerinfo9208 AttachingtoprocessID9208,pleasewait... Debuggerattachedsuccessfully. Servercompilerdetected. JVMversionis24. 75 -b04 Numberofobjectspendingforfinalization: 0 |
3.4 -heap
打印垃圾收集和heap摘要信息,以及生成-wise 堆使用的堆摘要
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
C:\Users\Administrator>jmap-heap9208 AttachingtoprocessID9208,pleasewait... Debuggerattachedsuccessfully. Servercompilerdetected. JVMversionis24. 75 -b04 usingthread-localobjectallocation. ParallelGCwith4thread(s) HeapConfiguration: MinHeapFreeRatio= 0 MaxHeapFreeRatio= 100 MaxHeapSize= 2124414976 ( 2026 .0MB) NewSize= 1310720 ( 1 .25MB) MaxNewSize=17592186044415MB OldSize= 5439488 ( 5 .1875MB) NewRatio= 2 SurvivorRatio= 8 PermSize= 21757952 ( 20 .75MB) MaxPermSize= 85983232 ( 82 .0MB) G1HeapRegionSize= 0 ( 0 .0MB) HeapUsage: PSYoungGeneration EdenSpace: capacity= 68157440 ( 65 .0MB) used= 16646688 ( 15 .875518798828125MB) free= 51510752 ( 49 .124481201171875MB) 24.423875075120193 %used FromSpace: capacity= 5242880 ( 5 .0MB) used= 5228248 ( 4 .986045837402344MB) free= 14632 ( 0 .01395416259765625MB) 99.72091674804688 %used ToSpace: capacity= 15728640 ( 15 .0MB) used= 0 ( 0 .0MB) free= 15728640 ( 15 .0MB) 0.0 %used PSOldGeneration capacity= 88080384 ( 84 .0MB) used= 27239848 ( 25 .977943420410156MB) free= 60840536 ( 58 .022056579589844MB) 30.9261231195359 %used PSPermGeneration capacity= 22020096 ( 21 .0MB) used= 15369592 ( 14 .657585144042969MB) free= 6650504 ( 6 .342414855957031MB) 69.7980244954427 %used 10057internedStringsoccupying867832bytes. |
3.5 -histo[:live]
打印堆的直方圖
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
num#instances#bytesclassname ---------------------------------------------- ... 877 : 132 [Lcom.sun.jndi.ldap.pool.Pool; 878 :232com.sun.org.apache.xerces.internal.impl.dv.dtd.ENTITYDatatypeValidator 879 :232java.lang.Shutdown$Lock 880 :132org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler 881 :232com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver 882 :132java.lang.reflect.WeakCache$CacheKey 883 :132java.text.FieldPosition 884 :132java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl 885 :232sun.security.x509.CertificateVersion 886 : 232 [Lorg.apache.catalina.deploy.ContextEnvironment; 887 : 132 [Lorg.apache.tomcat.util.net.AbstractEndpoint$Acceptor$AcceptorState; 888 :132sun.nio.cs.StandardCharsets ... |
3.6 -clstats
java 堆的wise統計。1.7.0_75不支持該項
(2)jhat
2.1作用
分析Java堆。該jhat命令解析Java堆轉儲文件并啟動Web服務器。jhat命令可以讓你瀏覽堆轉儲。支持OQL語法。
2.2使用
jhat [ options ] heap-dump-file
2.3參數說明
1.-stack false|true
關閉跟蹤對象分配調用堆棧。默認值是true。
-refs false|true
關閉對象的引用的跟蹤。默認為true。
-port port-number
設置端口的jhatHTTP服務器。默認值是7000。
-exclude exclude-file
指定列出了應當從可及的對象查詢排除數據成員的文件
-baseline exclude-file
指定基準堆轉儲。在具有相同的對象ID兩個堆轉儲對象被標記為不是新對象。這是用于比較兩個不同的堆轉儲有用。
-debug int
0級表示沒有調試輸出
1
2
3
4
5
6
7
8
9
10
|
C:\Users\Administrator>jhat-port80009208_0413.hprof Readingfrom9208_0413.hprof... DumpfilecreatedThuApr1321: 18 :58CST2017 Snapshotread,resolving... Resolving389761objects... Chasingreferences,expect77dots.......................................................................... Eliminatingduplicatereferences............................................................................ Snapshotresolved. StartedHTTPserveronport8000 Serverisready. |
接下來,就可以通過瀏覽器訪問查看。http://localhost:8000/。
(3)jinfo
3.1作用
生成的配置信息。如果指定的進程是在64位JVM上運行,那么你可能需要指定-J-d64選項
3.2使用
1
2
3
|
jinfo[option]pid jinfo[option]executablecore jinfo[option][servier-id]remote-hostname-or-IP |
3.3選項參數
no-option:既打印命令行標志和系統屬性鍵值對。
-flag name
打印名和指定的命令行標志的值。
-flag [+|-]name
開啟或禁止指定的布爾命令行標志。
-flag name=value
設置指定的命令行標志為指定值。
-flags
打印命令行標志傳遞給JVM。
-sysprops
打印Java系統屬性鍵值對。
打印進程的命令行參數
1
2
3
4
5
6
7
8
9
|
C:\Users\Administrator>jinfo-flags9208 AttachingtoprocessID9208,pleasewait... Debuggerattachedsuccessfully. Servercompilerdetected. JVMversionis24. 75 -b04 -Djava.util.logging.config.file=D:\apache-tomcat- 7.0 . 67 \conf\logging.properties-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=D:\apache-tomcat- 7.0 . 67 \endorsed-Dcatalina.base=D:\apache-tomcat- 7.0 . 67 -Dcatalina.home=D:\apache-tomcat- 7.0 . 67 -Djava.io. tmpdir=D:\apache-tomcat- 7.0 . 67 \temp #在catalina.sh中可以找到設置的地方 |
打印參數值
1
2
3
4
5
6
7
8
9
10
|
#值類型參數 C:\Users\Administrator>jinfo-flagNewSize9208 -XX:NewSize= 1310720 #開關類型參數 C:\Users\Administrator>jinfo-flagPrintGC9208 -XX:-PrintGC C:\Users\Administrator>jinfo-flagXmn9208 nosuchflag 'Xmn' |
可以總結出:-xms,-xmn系列參數不能通過jinfo指定或打?。籮info命令作用于-XX:***格式的參數。
設置參數值
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
C:\Users\Administrator>jinfo-flagPrintGC9208 -XX:-PrintGC C:\Users\Administrator>jinfo-flag+PrintGC9208 C:\Users\Administrator>jinfo-flagPrintGC9208 -XX:+PrintGC //2windows環境總是失敗 C:\Users\Administrator>jinfo-flagPermSize= 217500009208 Exceptioninthread "main" java.io.IOException:CommandfailedintargetVM atsun.tools.attach.WindowsVirtualMachine.execute(WindowsVirtualMachine.java: 112 ) atsun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java: 217 ) atsun.tools.attach.HotSpotVirtualMachine.setFlag(HotSpotVirtualMachine.java: 190 ) atsun.tools.jinfo.JInfo.flag(JInfo.java: 123 ) atsun.tools.jinfo.JInfo.main(JInfo.java: 76 ) |
希望本篇文章對您有所幫助
原文鏈接:http://www.2cto.com/kf/201704/626229.html