sequence
This paper mainly studies the Native Memory Tracking of HotSpot VM
Native Memory Tracking
Java8 introduces Native Memory Tracking (NMT) to HotSpot VM, which can be used to track internal Memory usage of the JVM
use
open
-XX:NativeMemoryTracking=summary
Copy the code
-xx :NativeMemoryTracking=summary can be used to enable NMT, where the value is off by default and can be set to summary or detail. When enabled, the performance cost increases by about 5-10%
To view
/ # jcmd 1 VM.native_memory summary
/ # jcmd 1 VM.native_memory summary scale=MB
Copy the code
Native_memory (JCMD PID VM. Native_memory), which can be followed by summary or detail. If summary is enabled, only summary can be used. The scale parameter can specify the display unit, which can be KB, MB, or GB
Create a baseline
/ # jcmd 1 VM.native_memory baseline
1:
Baseline succeeded
Copy the code
Once the baseline is created, you can compare it with summary.diff
See the diff
/ # jcmd 1 VM.native_memory summary.diff
Copy the code
Use summary.diff to view statistics against baseline
When shutdown output
-XX:+UnlockDiagnosticVMOptions -XX:+PrintNMTStatistics
Copy the code
Using the above commands, you can output the overall native memory statistics when the JVM is shutdown
Shut down
/ # jcmd 1 VM.native_memory shutdown
1:
Native memory tracking has been turned off
Copy the code
Use JCMD pid VM. Native_memory shutdown to shutdown NMT; Note that there seems to be no corresponding JCMD command to enable it after using JCMD
The instance
/ # 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=44MB, committed=43MB) (used=42MB) (free=1MB) (waste=0MB =0.00%) 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)
Copy the code
- It can be seen that the whole memory mainly includes Java Heap, Class, Thread, Code, GC, Compiler, Internal, Other, Symbol, Native Memory Tracking, Arena Chunk. Reserved indicates the available memory size of an application, while COMMITTED indicates the memory size that an application is using
- The Java Heap section indicates that the Heap memory currently occupies 463MB; The Class section represents 8801 classes loaded, and the metadata is 50MB. The Thread section indicates that there are currently 225 threads, occupying 27MB. The Code part indicates that the JIT-generated or cached instructions occupy 17MB; The GC section indicates that 15MB of memory is currently used to help GC; The Code part indicates that compiler takes 26MB when generating Code. The Internal part indicates that command line parsing and JVMTI occupy 5MB. The Other field indicates that uncategorized items occupy 2MB. The Symbol part indicates that symbols such as String table and constant pool occupy 10MB; Native Memory Tracking indicates that the feature itself takes up 5MB; Arena Chunk indicates that Arena Chunk occupies 63MB
- An arena represents a chunk of memory allocated using MALLOc. These chunks can be used by other SUBSYSTEMS as temporary memory, such as the allocation of pre-threads, whose memory is freed as bulk
summary
- Java8 introduces Native Memory Tracking (NMT) to HotSpot VM, which can be used to track internal Memory usage of the JVM
- -xx :NativeMemoryTracking=summary can be used to enable NMT. The default value is off. You can set summary and detail to enable NMT. If enabled, the performance cost increases by about 5%-10%. Use – XX: + UnlockDiagnosticVMOptions – XX: + PrintNMTStatistics can the JVM when shutdown of the output of the whole native memory statistics; You can run the JCMD pid VM. Native_memory commands to view, diff, and shutdown other commands
- The whole memory mainly includes Java Heap, Class, Thread, Code, GC, Compiler, Internal, Other, Symbol, Native Memory Tracking, Arena Chunk. Reserved indicates the available memory size of an application, while COMMITTED indicates the memory size that an application is using
doc
- Native Memory Tracking
- Native Memory Tracking diagnostic-tools
- NMT Memory Categories
- Memory footprint of the JVM
- Native Memory Tracking in JVM