开启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)