本文主要研究一下HotSpot VM的Native Memory Trackinghtml
java8給HotSpot VM引入了Native Memory Tracking (NMT)特性,能夠用於追蹤JVM的內部內存使用java
-XX:NativeMemoryTracking=summary
使用-XX:NativeMemoryTracking=summary能夠用於開啓NMT,其中該值默認爲off,能夠設置爲summary或者detail來開啓;開啓的話,大概會增長5%-10%的性能消耗spring
/ # jcmd 1 VM.native_memory summary / # jcmd 1 VM.native_memory summary scale=MB
使用jcmd pid VM.native_memory能夠查看,後面能夠加summary或者detail,若是是開啓summary的,就只能使用summary;其中scale參數能夠指定展現的單位,能夠爲KB或者MB或者GB緩存
/ # jcmd 1 VM.native_memory baseline 1: Baseline succeeded
建立baseline以後能夠用summary.diff來對比oracle
/ # jcmd 1 VM.native_memory summary.diff
使用summary.diff來查看跟baseline對比的統計信息jvm
-XX:+UnlockDiagnosticVMOptions -XX:+PrintNMTStatistics
使用上述命令能夠在jvm shutdown的時候輸出總體的native memory統計性能
/ # jcmd 1 VM.native_memory shutdown 1: Native memory tracking has been turned off
使用jcmd pid VM.native_memory shutdown能夠用於關閉NMT;注意使用jcmd關閉以後貌似沒有對應jcmd命令來開啓spa
/ # jcmd 1 VM.native_memory summary scale=MB 1: Native Memory Tracking: Total: reserved=2175MB, committed=682MB - Java Heap (reserved=501MB, committed=463MB) (mmap: reserved=501MB, committed=463MB) - Class (reserved=1070MB, committed=50MB) (classes #8801) ( instance classes #8204, array classes #597) (malloc=2MB #24660) (mmap: reserved=1068MB, committed=49MB) ( Metadata: ) ( reserved=44MB, committed=43MB) ( used=42MB) ( free=1MB) ( waste=0MB =0.00%) ( Class space:) ( reserved=1024MB, committed=6MB) ( used=5MB) ( free=0MB) ( waste=0MB =0.00%) - Thread (reserved=228MB, committed=27MB) (thread #226) (stack: reserved=227MB, committed=26MB) (malloc=1MB #1139) - Code (reserved=243MB, committed=17MB) (malloc=1MB #5509) (mmap: reserved=242MB, committed=16MB) - GC (reserved=23MB, committed=15MB) (malloc=8MB #11446) (mmap: reserved=16MB, committed=7MB) - Compiler (reserved=26MB, committed=26MB) (malloc=2MB #1951) (arena=24MB #13) - Internal (reserved=5MB, committed=5MB) (malloc=3MB #9745) (mmap: reserved=2MB, committed=2MB) - Other (reserved=2MB, committed=2MB) (malloc=2MB #202) - Symbol (reserved=10MB, committed=10MB) (malloc=8MB #233939) (arena=3MB #1) - Native Memory Tracking (reserved=5MB, committed=5MB) (tracking overhead=5MB) - Arena Chunk (reserved=63MB, committed=63MB) (malloc=63MB)