(1)JMAP
1.作用
列印程序,core檔案,和遠端程序的共享對象存儲map或堆存儲器的詳細資訊。
2.使用
jmap [ options ] pid
jmap [ options ] executable core
jmap [ options ] [ pid ] server-id@ ] remote-hostname-or-IP
如果指定的程序是在64位Java虛拟機(JVM)上運作,那麼你可能需要指定-J-d64選項,例如:jmap -J-d64 -heap pid。
3.參數選項
3.1 <no option>
當不使用選項,該jmap指令列印共享對象映射
如
C:\Users\Administrator>jmap 9208
Attaching to process ID 9208, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.75-b04
0x00000000623c0000 8016K D:\Java\jdk1.7.0_75\jre\bin\server\jvm.dll
0x0000000062ba0000 840K D:\Java\jdk1.7.0_75\jre\bin\msvcr100.dll
0x0000000062cc0000 144K D:\Java\jdk1.7.0_75\jre\bin\sunec.dll
0x0000000062cf0000 68K D:\Java\jdk1.7.0_75\jre\bin\nio.dll
0x0000000062d10000 100K D:\Java\jdk1.7.0_75\jre\bin\net.dll
0x0000000062d30000 160K D:\Java\jdk1.7.0_75\jre\bin\java.dll
0x00000000634d0000 84K D:\Java\jdk1.7.0_75\jre\bin\zip.dll
0x0000000065950000 44K D:\Java\jdk1.7.0_75\jre\bin\sunmscapi.dll
0x0000000065960000 60K D:\Java\jdk1.7.0_75\jre\bin\verify.dll
0x0000000065970000 44K D:\Java\jdk1.7.0_75\jre\bin\management.dll
...
3.2
-dump:[live,] format=b, file=filename
轉儲Java堆hprof二進制格式。指定live,辨別轉儲active狀态的對象。生成的檔案可以由jhat指令檢視。
C:\Users\Administrator>jmap -dump:format=b,file=9208_0413.hprof 9208
Dumping heap to C:\Users\Administrator\9208_0413.hprof ...
Heap dump file created
3.3 -finalizerinfo
列印将要結束的對象的資訊
C:\Users\Administrator>jmap -finalizerinfo 9208
Attaching to process ID 9208, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.75-b04
Number of objects pending for finalization: 0
3.4 -heap
列印垃圾收集和heap摘要資訊,以及生成-wise 堆使用的堆摘要
C:\Users\Administrator>jmap -heap 9208
Attaching to process ID 9208, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.75-b04
using thread-local object allocation.
Parallel GC with 4 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 2124414976 (2026.0MB)
NewSize = 1310720 (1.25MB)
MaxNewSize = 17592186044415 MB
OldSize = 5439488 (5.1875MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 21757952 (20.75MB)
MaxPermSize = 85983232 (82.0MB)
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 68157440 (65.0MB)
used = 16646688 (15.875518798828125MB)
free = 51510752 (49.124481201171875MB)
24.423875075120193% used
From Space:
capacity = 5242880 (5.0MB)
used = 5228248 (4.986045837402344MB)
free = 14632 (0.01395416259765625MB)
99.72091674804688% used
To Space:
capacity = 15728640 (15.0MB)
used = 0 (0.0MB)
free = 15728640 (15.0MB)
0.0% used
PS Old Generation
capacity = 88080384 (84.0MB)
used = 27239848 (25.977943420410156MB)
free = 60840536 (58.022056579589844MB)
30.9261231195359% used
PS Perm Generation
capacity = 22020096 (21.0MB)
used = 15369592 (14.657585144042969MB)
free = 6650504 (6.342414855957031MB)
69.7980244954427% used
10057 interned Strings occupying 867832 bytes.
3.5 -histo[:live]
列印堆的直方圖
num #instances #bytes class name
----------------------------------------------
...
877: 1 32 [Lcom.sun.jndi.ldap.pool.Pool;
878: 2 32 com.sun.org.apache.xerces.internal.impl.dv.dtd.ENTITYDatatypeValidator
879: 2 32 java.lang.Shutdown$Lock
880: 1 32 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler
881: 2 32 com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver
882: 1 32 java.lang.reflect.WeakCache$CacheKey
883: 1 32 java.text.FieldPosition
884: 1 32 java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl
885: 2 32 sun.security.x509.CertificateVersion
886: 2 32 [Lorg.apache.catalina.deploy.ContextEnvironment;
887: 1 32 [Lorg.apache.tomcat.util.net.AbstractEndpoint$Acceptor$AcceptorState;
888: 1 32 sun.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級表示沒有調試輸出
C:\Users\Administrator>jhat -port 8000 9208_0413.hprof
Reading from 9208_0413.hprof...
Dump file created Thu Apr 13 21:18:58 CST 2017
Snapshot read, resolving...
Resolving 389761 objects...
Chasing references, expect 77 dots..........................................................................
Eliminating duplicate references............................................................................
Snapshot resolved.
Started HTTP server on port 8000
Server is ready.
接下來,就可以通過浏覽器通路檢視。http://localhost:8000/。
(3)jinfo
3.1作用
生成的配置資訊。如果指定的程序是在64位JVM上運作,那麼你可能需要指定-J-d64選項
3.2使用
jinfo [ option ] pid
jinfo [ option ] executable core
jinfo [ option ] [ servier-id ] remote-hostname-or-IP
3.3選項參數
no-option:既列印指令行标志和系統屬性鍵值對。
-flag name
列印名和指定的指令行标志的值。
-flag [+|-]name
開啟或禁止指定的布爾指令行标志。
-flag name=value
設定指定的指令行标志為指定值。
-flags
列印指令行标志傳遞給JVM。
-sysprops
列印Java系統屬性鍵值對。
列印程序的指令行參數
C:\Users\Administrator>jinfo -flags 9208
Attaching to process ID 9208, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.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中可以找到設定的地方
列印參數值
#值類型參數
C:\Users\Administrator>jinfo -flag NewSize 9208
-XX:NewSize=1310720
#開關類型參數
C:\Users\Administrator>jinfo -flag PrintGC 9208
-XX:-PrintGC
C:\Users\Administrator>jinfo -flag Xmn 9208
no such flag 'Xmn'
可以總結出:-xms,-xmn系列參數不能通過jinfo指定或列印;jinfo指令作用于-XX:***格式的參數。
設定參數值
C:\Users\Administrator>jinfo -flag PrintGC 9208
-XX:-PrintGC
C:\Users\Administrator>jinfo -flag +PrintGC 9208
C:\Users\Administrator>jinfo -flag PrintGC 9208
-XX:+PrintGC
//2 windows環境總是失敗
C:\Users\Administrator>jinfo -flag PermSize=21750000 9208
Exception in thread "main" java.io.IOException: Command failed in target VM
at sun.tools.attach.WindowsVirtualMachine.execute(WindowsVirtualMachine.java:112)
at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:217)
at sun.tools.attach.HotSpotVirtualMachine.setFlag(HotSpotVirtualMachine.java:190)
at sun.tools.jinfo.JInfo.flag(JInfo.java:123)
at sun.tools.jinfo.JInfo.main(JInfo.java:76)