Overview
The Native Memory Tracking (NMT) is a Java Hotspot VM feature that tracks internal memory usage for a HotSpot JVM. You can access NMT data using jcmd utility. NMT in this release does not track third party native code memory allocations and JDK class libraries. Also, this release does not include NMT MBean in HotSpot for JMC.
Key Features
-
Native Memory Tracking has the following features and when used with jcmd can track memory usage at differnet levels.
-
NMT for Hotspot VM is turned off by default. Turn this feature on using JVM command line option. See the Native Memory Tracking command man page.
-
Memory tracking data can be accessed using jcmd utility. See use jcmd to access NMT data.
-
Generate summary and detail reports.
-
Establish an early baseline for later comparison.
-
Request a memory usage report at JVM exit with the JVM command line option. See NMT at VM exit.
-
NMT can be shutdown using jcmd utility, but can not start/restart using jcmd.
How to Use Native Memory Tracking
First enable NMT and then use jcmd to access the data collected thus far.
Enable NMT
Enable NMT using the following command line. Note that enabling this will cause 5-10% performance overhead.
-XX:NativeMemoryTracking=[off | summary | detail]
off | NMT is turned off by default. |
summary | Only collect memory usage aggregated by subsystem. |
detail | Collect memory usage by individual call sites. |
Use jcmd to Access NMT Data
Use jcmd to dump the data collected and optionally compare it to the last baseline.
jcmd VM.native_memory [summary | detail | baseline | summary.diff | detail.diff | shutdown] [scale= KB | MB | GB]
summary | Print a summary aggregated by category. |
detail |
|
baseline | Create a new memory usage snapshot to diff against. |
summary.diff | Print a new summary report against the last baseline. |
detail.diff | Print a new detail report against the last baseline. |
shutdown | Shutdown NMT. |
NMT at VM Exit
Use the following VM diagnostic command line option to obtain last memory usage data at VM exit when Native Memory Tracking is enabled. The level of detail is based on tracking level.
-XX:+UnlockDiagnosticVMOptions -XX:+PrintNMTStatistics
扩展
java8给HotSpot VM引入了Native Memory Tracking (NMT)特性
例子
-XX:NativeMemoryTracking=summary
/zxjdk-8u212-linux-x64/bin # jcmd 413 VM.native_memory summary scale=MB
413:
Native Memory Tracking:
Total: reserved=1821MB, committed=496MB
- Java Heap (reserved=300MB, committed=200MB)
(mmap: reserved=300MB, committed=200MB)
- Class (reserved=1092MB, committed=76MB)
(classes #14152)
(malloc=2MB #26102)
(mmap: reserved=1090MB, committed=74MB)
- Thread (reserved=130MB, committed=130MB)
(thread #130)
(stack: reserved=129MB, committed=129MB)
- Code (reserved=251MB, committed=42MB)
(malloc=7MB #10703)
(mmap: reserved=244MB, committed=35MB)
- GC (reserved=1MB, committed=1MB)
(mmap: reserved=1MB, committed=1MB)
- Compiler (reserved=1MB, committed=1MB)
- Internal (reserved=25MB, committed=25MB)
(malloc=25MB #19980)
- Symbol (reserved=18MB, committed=18MB)
(malloc=16MB #167642)
(arena=2MB #1)
- Native Memory Tracking (reserved=3MB, committed=3MB)
(tracking overhead=3MB)
其中reserved表示应用可用的内存大小,committed表示应用正在使用的内存大小