JMC 之 内存篇

前言

在之前的《Java Mission Control(JMC)介绍》中已经介绍了如何使用JMC工具监控JVM的状态,最近在做项目的过程中遇到了内存偏高的情况,这时我想起了JMC工具。

内存监控

连接JVM之后,点击“内存”页签,我们可以看到动态的内存使用详情。

JMC 之 内存篇_第1张图片

图中各个参数意义:

参数 类型 描述
Code Cache 非堆内存 代码
Mataspace 非堆内存 Java 8之后取代PermGen永久代对内存,存储class类元数据
Eden Gen 堆内存 新生代初始区,new的对象最先放到该区
Survivor Space 堆内存 新生代中转区,平均分成2份From/To,保持一份是空的,GC时会从Eden转到该区
Tenured Gen 堆内存 老年代,GC达到一定次数还存活的对象转到该区

通过在shell中执行jcmd命令可以得到更详细信息

shell>jcmd <PID> VM.native_memory [baseline|detail[.diff]] [scale=kb|mb|gb]

运行结果

Native Memory Tracking:

Total: reserved=172804KB, committed=94236KB
                 Java Heap (reserved=102400KB, committed=53736KB)
                        堆  (mmap: reserved=102400KB, committed=53736KB) 

                     Class (reserved=18221KB, committed=18173KB)
                     元数据  (classes #5094)
                            (malloc=509KB #5180) 
                            (mmap: reserved=17712KB, committed=17664KB) 

                    Thread (reserved=10745KB, committed=10745KB)
                     线程栈  (thread #32)
                            (stack: reserved=10620KB, committed=10620KB)
                            (malloc=56KB #157) 
                            (arena=70KB #62)

                      Code (reserved=33661KB, committed=3957KB)
                 编译后的代码 (malloc=381KB #1185) 
                            (mmap: reserved=33280KB, committed=3576KB) 

                        GC (reserved=364KB, committed=212KB)
                            (malloc=24KB #309) 
                            (mmap: reserved=340KB, committed=188KB) 

                  Compiler (reserved=70KB, committed=70KB)
                            (malloc=4KB #143) 
                            (arena=66KB #2)

                  Internal (reserved=1105KB, committed=1105KB)
                            (malloc=1073KB #6876) 
                            (mmap: reserved=32KB, committed=32KB) 

                    Symbol (reserved=5679KB, committed=5679KB)
                    符号引用 (malloc=2536KB #29771) 
                            (arena=3142KB #1)

    Native Memory Tracking (reserved=389KB, committed=389KB)
                            (malloc=38KB #1172) 
                            (tracking overhead=351KB)

               Arena Chunk (reserved=166KB, committed=166KB)
                            (malloc=166KB) 

                   Unknown (reserved=4KB, committed=4KB)
                            (mmap: reserved=4KB, committed=4KB)

通过执行jmap命令,可以将java heap再细分

shell>jmap -heap <PID>

运行结果

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 104857600 (100.0MB)
   NewSize                  = 11141120 (10.625MB)
   MaxNewSize               = 34930688 (33.3125MB)
   OldSize                  = 22413312 (21.375MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 12582912 (12.0MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 4294963200 (4095.99609375MB)
   G1HeapRegionSize         = 0 (0.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space):
   capacity = 17367040 (16.5625MB)
   used     = 3141976 (2.9964218139648438MB)
   free     = 14225064 (13.566078186035156MB)
   18.091603405070753% used
Eden Space:
   capacity = 15466496 (14.75MB)
   used     = 2136808 (2.0378189086914062MB)
   free     = 13329688 (12.712181091308594MB)
   13.815721414856991% used
From Space:
   capacity = 1900544 (1.8125MB)
   used     = 1005168 (0.9586029052734375MB)
   free     = 895376 (0.8538970947265625MB)
   52.88843615301724% used
To Space:
   capacity = 1900544 (1.8125MB)
   used     = 0 (0.0MB)
   free     = 1900544 (1.8125MB)
   0.0% used
tenured generation:
   capacity = 38498304 (36.71484375MB)
   used     = 28349152 (27.035858154296875MB)
   free     = 10149152 (9.678985595703125MB)
   73.63740491009682% used

14161 interned Strings occupying 1720696 bytes.

你可能感兴趣的:(java)