您好,登錄后才能下訂單哦!
今天我們的系列文章要介紹的是這四個工具:
Jstat(sun.tools.jstat) 它的全稱是Java Virtual Machine Statistics Monitoring Tool,是用來監控JVM狀態的工具。
jstack(sun.tools.jstack) 它的全稱是Java Stack Trace,是用來做java棧的跟蹤工具。
jmap(sun.tools.jmap) 它的全稱是Java Memory Map,是java的內存管理工具。
jhat (com.sun.tools.hat.Main) 它的全稱是Java Heap Analyse Tool,是java的堆分析工具。
有了這四個工具,基本上JVM運行期間的方方面面都可以被覆蓋到了。下面我們將具體對每一個工具進行詳細講解。本文將會首先講解Jstat的具體使用。
jstat主要對JVM運行期間的各種參數進行收集,包括查看類的加載情況,jc中新生代老年代元數據空間的使用情況等。
先看下Jstat的命令:
jstat outputOptions [-t] [-h lines] vmid [interval [count]]
上面我們講了JStat命令的基本格式,在本節我們會詳細講解JStat的輸出選項。
使用jstat -options可以看到jstat支持的幾個options選項:
jstat -options -class-compiler-gc-gccapacity-gccause-gcmetacapacity-gcnew-gcnewcapacity-gcold-gcoldcapacity-gcutil-printcompilation
輸出class loader的統計信息,我們舉個例子:
jstat -class -t 53528 100 5Timestamp Loaded Bytes Unloaded Bytes Time 19822.8 5214 10752.5 0 0.0 2.91 19823.0 5214 10752.5 0 0.0 2.91 19823.0 5214 10752.5 0 0.0 2.91 19823.2 5214 10752.5 0 0.0 2.91 19823.2 5214 10752.5 0 0.0 2.91
上面的例子中53528是目標JVM的pid,100表示取樣的間隔時間是100ms,5表示最后只展示5條數據。
上面的Timestamp表示的JVM的啟動的時間。
compiler統計的是Java HotSpot VM Just-in-Time JIT即時編譯器的信息。
JIT即時編譯器是為了提升代碼的執行速度而產生的。JVM對于一些熱點代碼,比如多次循環和經常使用的方法。對于這些熱點代碼,JIT會將其編譯成機器代碼,從而提升執行速度。
還是舉剛剛的JVM的例子:
jstat -compiler 53528 100 5Compiled Failed Invalid Time FailedType FailedMethod 2675 0 0 5.35 0 2675 0 0 5.35 0 2675 0 0 5.35 0 2675 0 0 5.35 0 2675 0 0 5.35 0
gc統計的是gc heap信息
jstat -gc 53528 100 5 S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT CGC CGCT GCT 0.0 4096.0 0.0 3978.2 56320.0 33792.0 15360.0 15215.0 21552.0 20680.9 2688.0 2468.0 4 0.025 0 0.000 2 0.003 0.028 0.0 4096.0 0.0 3978.2 56320.0 33792.0 15360.0 15215.0 21552.0 20680.9 2688.0 2468.0 4 0.025 0 0.000 2 0.003 0.028 0.0 4096.0 0.0 3978.2 56320.0 33792.0 15360.0 15215.0 21552.0 20680.9 2688.0 2468.0 4 0.025 0 0.000 2 0.003 0.028 0.0 4096.0 0.0 3978.2 56320.0 33792.0 15360.0 15215.0 21552.0 20680.9 2688.0 2468.0 4 0.025 0 0.000 2 0.003 0.028 0.0 4096.0 0.0 3978.2 56320.0 33792.0 15360.0 15215.0 21552.0 20680.9 2688.0 2468.0 4 0.025 0 0.000 2 0.003 0.028
gc的輸出參數比較多,我們一一進行解釋,這樣大家對于gc的運行內核會有更多的理解:
Young Gen被劃分為1個Eden Space和2個Suvivor Space。當對象剛剛被創建的時候,是放在Eden space。垃圾回收的時候,會掃描Eden Space和一個Suvivor Space。如果在垃圾回收的時候發現Eden Space中的對象仍然有效,則會將其復制到另外一個Suvivor Space。
就這樣不斷的掃描,最后經過多次掃描發現任然有效的對象會被放入Old Gen表示其生命周期比較長,可以減少垃圾回收時間。
在JDK8之前,類定義、字節碼和常量等很少會變更的信息是放在持久代Perm Gen中的。不過在JDK8之后,Perm Gen已經被取消了,現在叫做Metaspace。Metaspace并不在java虛擬機中,它使用的是本地內存。Metaspace可以通過-XX:MaxMetaspaceSize來控制。
Compressed Class Space,它是和-XX:+UseCompressedOops,-XX:+UseCompressedClassesPointers有關的。實際上是一個指針的壓縮,可以使用32bits來表示之前64bits的指針。
gccapacity統計的是內存池的創建和大小等統計信息
jstat -gccapacity 53528 100 5 NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC CGC 0.0 716800.0 60416.0 0.0 4096.0 56320.0 0.0 716800.0 15360.0 15360.0 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 2 0.0 716800.0 60416.0 0.0 4096.0 56320.0 0.0 716800.0 15360.0 15360.0 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 2 0.0 716800.0 60416.0 0.0 4096.0 56320.0 0.0 716800.0 15360.0 15360.0 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 2 0.0 716800.0 60416.0 0.0 4096.0 56320.0 0.0 716800.0 15360.0 15360.0 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 2 0.0 716800.0 60416.0 0.0 4096.0 56320.0 0.0 716800.0 15360.0 15360.0 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 2
gcnew表示新生代的統計信息
jstat -gcnew 53528 100 5 S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT 0.0 4096.0 0.0 3978.2 15 15 5120.0 56320.0 33792.0 4 0.025 0.0 4096.0 0.0 3978.2 15 15 5120.0 56320.0 33792.0 4 0.025 0.0 4096.0 0.0 3978.2 15 15 5120.0 56320.0 33792.0 4 0.025 0.0 4096.0 0.0 3978.2 15 15 5120.0 56320.0 33792.0 4 0.025 0.0 4096.0 0.0 3978.2 15 15 5120.0 56320.0 33792.0 4 0.025
gcnewcapacity統計的是新生代的指標,和gccapacity的結果是很類似的:
jstat -gcnewcapacity 53528 100 5 NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC CGC 0.0 716800.0 60416.0 0.0 0.0 716800.0 4096.0 716800.0 56320.0 4 0 2 0.0 716800.0 60416.0 0.0 0.0 716800.0 4096.0 716800.0 56320.0 4 0 2 0.0 716800.0 60416.0 0.0 0.0 716800.0 4096.0 716800.0 56320.0 4 0 2 0.0 716800.0 60416.0 0.0 0.0 716800.0 4096.0 716800.0 56320.0 4 0 2 0.0 716800.0 60416.0 0.0 0.0 716800.0 4096.0 716800.0 56320.0 4 0 2
gcold統計old代的信息
jstat -gcold 53528 100 5 MC MU CCSC CCSU OC OU YGC FGC FGCT CGC CGCT GCT 21552.0 20680.9 2688.0 2468.0 15360.0 15215.0 4 0 0.000 2 0.003 0.028 21552.0 20680.9 2688.0 2468.0 15360.0 15215.0 4 0 0.000 2 0.003 0.028 21552.0 20680.9 2688.0 2468.0 15360.0 15215.0 4 0 0.000 2 0.003 0.028 21552.0 20680.9 2688.0 2468.0 15360.0 15215.0 4 0 0.000 2 0.003 0.028 21552.0 20680.9 2688.0 2468.0 15360.0 15215.0 4 0 0.000 2 0.003 0.028
結果的幾項指標前面已經介紹過了,這里就不再重復了
gcoldcapacity表示old代的容量信息
jstat -gcoldcapacity 53528 100 5 OGCMN OGCMX OGC OC YGC FGC FGCT CGC CGCT GCT 0.0 716800.0 15360.0 15360.0 4 0 0.000 2 0.003 0.028 0.0 716800.0 15360.0 15360.0 4 0 0.000 2 0.003 0.028 0.0 716800.0 15360.0 15360.0 4 0 0.000 2 0.003 0.028 0.0 716800.0 15360.0 15360.0 4 0 0.000 2 0.003 0.028 0.0 716800.0 15360.0 15360.0 4 0 0.000 2 0.003 0.028
gcmetacapacity統計的是元數據區域的容量信息
jstat -gcmetacapacity 53528 100 5 MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC FGCT CGC CGCT GCT 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 0.000 2 0.003 0.028 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 0.000 2 0.003 0.028 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 0.000 2 0.003 0.028 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 0.000 2 0.003 0.028 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 0.000 2 0.003 0.028
gcutil統計的是GC總體的情況
jstat -gcutil 53528 100 5 S0 S1 E O M CCS YGC YGCT FGC FGCT CGC CGCT GCT 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028
gccause和gcutil非常相識,只不過多了下面兩列:
jstat -gccause 53528 100 5 S0 S1 E O M CCS YGC YGCT FGC FGCT CGC CGCT GCT LGCC GCC 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 Metadata GC Threshold No GC 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 Metadata GC Threshold No GC 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 Metadata GC Threshold No GC 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 Metadata GC Threshold No GC 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 Metadata GC Threshold No GC
printcompilation是JVM編譯器的方法統計
jstat -printcompilation 53528 100 5Compiled Size Type Method 2675 23 1 jdk/internal/misc/InnocuousThread eraseThreadLocals 2675 23 1 jdk/internal/misc/InnocuousThread eraseThreadLocals 2675 23 1 jdk/internal/misc/InnocuousThread eraseThreadLocals 2675 23 1 jdk/internal/misc/InnocuousThread eraseThreadLocals 2675 23 1 jdk/internal/misc/InnocuousThread eraseThreadLocals
本文介紹了JDK14中自帶的jstat JVM分析工具,希望大家能夠在實際的工作中用到。
https://www.imdb.com/list/ls080419900/?publish=publish
https://www.imdb.com/list/ls080419956/?publish=publish
https://www.imdb.com/list/ls080419916/?publish=publish
https://www.imdb.com/list/ls080419990/?publish=publish
https://www.imdb.com/list/ls080419855/?publish=publish
https://www.imdb.com/list/ls080419867/?publish=publish
https://www.imdb.com/list/ls080418035/?publish=publish
https://www.imdb.com/list/ls080418063/?publish=publish
https://www.imdb.com/list/ls080418085/?publish=publish
https://www.imdb.com/list/ls080418713/?publish=publish
https://www.imdb.com/list/ls080418783/?publish=publish
https://www.imdb.com/list/ls080418174/?publish=publish
https://www.imdb.com/list/ls080418113/?publish=publish
https://www.imdb.com/list/ls080418138/?publish=publish
https://www.imdb.com/list/ls080418184/?publish=publish
https://www.imdb.com/list/ls080418326/?publish=publish
https://www.imdb.com/list/ls080418399/?publish=publish
https://www.imdb.com/list/ls080418659/?publish=publish
https://www.imdb.com/list/ls080418638/?publish=publish
https://www.imdb.com/list/ls080418696/?publish=publish
https://www.imdb.com/list/ls080418253/?publish=publish
https://www.imdb.com/list/ls080418274/?publish=publish
https://www.imdb.com/list/ls080418239/?publish=publish
https://www.imdb.com/list/ls080418248/?publish=publish
https://www.imdb.com/list/ls080418280/?publish=publish
https://www.imdb.com/list/ls080418459/?publish=publish
https://www.imdb.com/list/ls080418481/?publish=publish
https://www.imdb.com/list/ls080418875/?publish=publish
https://www.imdb.com/list/ls080418874/?publish=publish
https://www.imdb.com/list/ls080418834/?publish=publish
https://www.imdb.com/list/ls080418869/?publish=publish
https://www.imdb.com/list/ls080418844/?publish=publish
https://www.imdb.com/list/ls080430017/?publish=publish
https://www.imdb.com/list/ls080430045/?publish=publish
https://www.imdb.com/list/ls080430562/?publish=publish
https://www.imdb.com/list/ls080430172/?publish=publish
https://www.imdb.com/list/ls080430111/?publish=publish
https://www.imdb.com/list/ls080430167/?publish=publish
https://www.imdb.com/list/ls080430191/?publish=publish
https://www.imdb.com/list/ls080430314/?publish=publish
https://www.imdb.com/list/ls080430389/?publish=publish
https://www.imdb.com/list/ls080430652/?publish=publish
https://www.imdb.com/list/ls080430614/?publish=publish
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。