開啟NMT
NMT目前只能在啟動的時候開啟,不支持動態開關NMT功能。開啟NMT功能,會帶來5%到10%的額外開銷
通過-XX:NativeMemoryTracking=[off | summary | detail]來開啟NMT功能。
- off 關閉NMT功能,默認關閉
- summary 僅收集子系統聚合的內存使用情況
- detail 收集各個調用點的內存使用情況。
使用jcmd功能獲取NMT數據
可以使用jcmd收集數據,或者是與基線進行對比
jcmd <pid> VM.native_memory [summary | detail | baseline | summary.diff | detail.diff | shutdown] [scale= KB | MB | GB]
jcmd NMT選項 |
描述 |
summary |
打印summary |
detail |
打印按分類聚合的內存使用、打印按調用聚合的內存使用、打印虛擬內存映射 |
baseline |
建立內存使用基線 |
summary.diff |
打印summary和基線的對比 |
detail.diff |
打印detail和基線的對比 |
shutdown |
停止NMT |
實戰演示
jcmd 27 VM.native_memory summary scale=MB
Native Memory Tracking:
(Omitting categories weighting less than 1MB)
Total: reserved=2830MB, committed=1288MB
- JAVA Heap (reserved=1024MB, committed=1024MB)
(mmap: reserved=1024MB, committed=1024MB)
- Class (reserved=1025MB, committed=6MB)
(classes #8980)
( instance classes #8430, array classes #550)
(malloc=1MB #20044)
(mmap: reserved=1024MB, committed=5MB)
( Metadata: )
( reserved=40MB, committed=38MB)
( used=38MB)
( waste=0MB =0.34%)
( Class space:)
( reserved=1024MB, committed=5MB)
( used=5MB)
( waste=0MB =2.88%)
- Thread (reserved=312MB, committed=16MB)
(thread #156)
(stack: reserved=312MB, committed=16MB)
- Code (reserved=243MB, committed=18MB)
(malloc=1MB #6733)
(mmap: reserved=242MB, committed=17MB)
- GC (reserved=83MB, committed=83MB)
(malloc=13MB #7985)
(mmap: reserved=70MB, committed=70MB)
- Internal (reserved=14MB, committed=14MB)
(malloc=14MB #10083)
- Other (reserved=61MB, committed=61MB)
(malloc=61MB #126)
- Symbol (reserved=9MB, committed=9MB)
(malloc=8MB #224838)
(arena=1MB #1)
- Native Memory Tracking (reserved=5MB, committed=5MB)
(tracking overhead=4MB)
- Shared class space (reserved=12MB, committed=12MB)
(mmap: reserved=12MB, committed=12MB)
- Metaspace (reserved=40MB, committed=38MB)
(mmap: reserved=40MB, committed=38MB)