8 Native Memory Tracking

This chapter describes the Native Memory Tracking (NMT) feature. NMT is a Java Hotspot VM feature that tracks internal memory usage for a HotSpot VM. You can access NMT data by using the jcmd utility. NMT does not track memory allocations for third-party native code and Oracle Java Development Kit (JDK) class libraries. NMT does not include NMT MBean in HotSpot for Java Mission Control (JMC).

Key Features

When you use Native Memory Tracking with jcmd, you can track Java Virtual Machine (JVM) or HotSpot VM memory usage at different levels. NMT tracks only the memory that the JVM or HotSpot VM uses, not the user's native memory. NMT doesn't give complete information for the memory used by the class data sharing (CDS) archive.

NMT for HotSpot VM is turned off by default. You can turn on NMT by using the JVM command-line option. See java in the Java Platform, Standard Edition Tools Reference for information about advanced runtime options.

You can access NMT using the jcmd utility. See Use jcmd to Access NMT Data. You can stop NMT by using the jcmd utility, but you can't start or restart NMT by using the jcmd utilty.

NMT supports the following features:

  • 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.

Using Native Memory Tracking

You must enable NMT and then use the jcmd utility to access the NMT data.

Enabling NMT

To enable NMT, use the following command-line options:

-XX:NativeMemoryTracking=[off | summary | detail]

Note:

Enabling NMT causes a 5% -10% performance overhead.

The following table describes the NMT command-line usage options:

Table 8-1 NMT Usage Options

NMT Options Description
off

NMT is turned off by default.

summary

Collect only memory usage aggregated by subsystem.

detail

Collect the memory usage by individual call sites.

Accessing NMT Data using jcmd

Use jcmd to dump the data that is collected and optionally compare the data to the last baseline.

jcmd <pid> VM.native_memory [summary | detail | baseline | summary.diff | detail.diff | shutdown] [scale= KB | MB | GB]

Table 8-2 jcmd NMT Options

jcmd NMT Option Description
summary

Print a summary, aggregated by category.

detail
  • Print memory usage, aggregated by category
  • Print virtual memory map
  • Print memory usage, aggregated by call site
baseline

Create a new memory usage snapshot for comparison.

summary.diff

Print a new summary report against the last baseline.

detail.diff

Print a new detail report against the last baseline.

shutdown

Stop NMT.

Obtaining NMT Data at VM Exit

To obtain data for the last memory usage at VM exit, when Native Memory Tracking is enabled, use the following VM diagnostic command-line options. The level of detail is based on tracking level.

-XX:+UnlockDiagnosticVMOptions -XX:+PrintNMTStatistics

See Native Memory Tracking in the Java Platform, Standard Edition Troubleshooting Guide for information about how to monitor VM internal memory allocations and diagnose VM memory leaks.