This article mainly studies the Native Memory Tracking of HotSpot VM.
Native Memory Tracking
Java8 introduces the Native Memory Tracking (NMT) feature to HotSpot VM, which can be used to track the internal memory usage of JVM.
Use-xx: NativeMemoryTracking = summary to turn on NMT, where the value is off by default and can be set to Summary or detail to turn on; When turned on, it will increase the performance consumption by 5%-10%
/ # jcmd 1 VM.native_memory summary / # jcmd 1 VM.native_memory summary scale=MB
Use jcmd pid VM.native_memory to view, followed by summary or detail. If summary is opened, only summary can be used. Where the scale parameter can specify the displayed unit, which can be KB, MB or GB
/ # jcmd 1 VM.native_memory baseline 1: Baseline succeeded
After creating the baseline, you can compare it with summary.diff
/ # jcmd 1 VM.native_memory summary.diff
Use summary.diff to view statistics compared to baseline
Output on shutdown
Use the above command to output the overall native memory statistics when the jvm shutdown.
/ # jcmd 1 VM.native_memory shutdown 1: Native memory tracking has been turned off
Native _ memoryshutdown can be used to shut down NMT；; Note that there does not appear to be a corresponding jcmd command to open after closing using jcmd
/ # 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=1024MB, 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)
- 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. Where reserved represents the amount of memory available to the application and committed represents the amount of memory the application is using.
- Java Heap part indicates that heap memory currently occupies 463MB； ; The Class part indicates that the number of classes loaded is 8801, and its metadata takes up 50MB； ; The Thread part indicates that there are 225 threads currently, occupying 27MB； ; The Code section indicates that JIT-generated or cached instructions take up 17MB； ; The GC part indicates that 15MB of memory has been occupied to help GC; The compiler section indicates that the Compiler took up 26MB； when generating code; The Internal part indicates that command line parsing, JVMTI, etc. take up 5 MB; The Other part indicates that the unclassified ones occupy 2 MB. The Symbol part indicates that symbols such as string table and constanpool occupy 10MB； ; The Native Memory Tracking section indicates that the function itself occupies 5 MB; The Arena Chunk section indicates that arena chunk occupies 63MB.
- An arena represents a memory chunk allocated by malloc. These chunks can be used as temporary memory by other subsystems, such as the memory allocation of pre-thread. Its memory release is bulk.
- Java8 introduces the Native Memory Tracking (NMT) feature to HotSpot VM, which can be used to track the internal memory usage of JVM.
- Use-xx: NativeMemoryTracking = summary to turn on NMT, where the value is off by default, and Summary and detail can be set to turn on; If it is turned on, it will increase the performance consumption by 5%-10%. Using-xx:+unlockdiagnosticvmoptions-xx:+printnmtstatistics can output the overall native memory statistics when the jvm shutdown; Others can be viewed, diff, shutdown, etc. using jcmd pid VM.native_memory related commands.
- The whole memory mainly includes Java Heap, Class, Thread, Code, GC, Compiler, Internal, Other, Symbol, Native Memory Tracking, Arena Chunk. Where reserved represents the amount of memory available to the application and committed represents the amount of memory the application is using.