Jmap 查看Heap信息

准备代码:

public class GarbageRecycle {

    public static void main(String[] args) throws InterruptedException {
        System.out.println("1.................");
        Thread.sleep(30000);
        byte[] array = new byte[20 * 1024 * 1024];
        System.out.println("2.................");
        Thread.sleep(30000);
        array = null;
        System.gc();
        System.out.println("3.................");
        Thread.sleep(3000000);
    }
}

jps查看进程信息

Jmap 查看Heap信息_第1张图片

查看pid:23280 堆使用信息:jhsdb jmap --heap --pid 23280
注:jdk8之前的命令是(jmap -heap 23280)

此时 G1 Heap used 为26m

Attaching to process ID 23280, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 11.0.11+9-LTS-194

using thread-local object allocation.
Garbage-First (G1) GC with 13 thread(s)

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 8533311488 (8138.0MB)
   NewSize                  = 1363144 (1.2999954223632812MB)
   MaxNewSize               = 5119148032 (4882.0MB)
   OldSize                  = 5452592 (5.1999969482421875MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 2097152 (2.0MB)

Heap Usage:
G1 Heap:
   regions  = 4069
   capacity = 8533311488 (8138.0MB)
   used     = 27262976 (26.0MB)
   free     = 8506048512 (8112.0MB)
   0.3194888178913738% used
G1 Young Generation:
Eden Space:
   regions  = 3
   capacity = 27262976 (26.0MB)
   used     = 6291456 (6.0MB)
   free     = 20971520 (20.0MB)
   23.076923076923077% used
Survivor Space:
   regions  = 0
   capacity = 0 (0.0MB)
   used     = 0 (0.0MB)
   free     = 0 (0.0MB)
   0.0% used
G1 Old Generation:
   regions  = 11
   capacity = 507510784 (484.0MB)
   used     = 20971520 (20.0MB)
   free     = 486539264 (464.0MB)
   4.132231404958677% used


程序打印3.................之后再次查询:G1 Heap used 仅为1m

F:\project\javaBase>jhsdb jmap --heap --pid 23280
Attaching to process ID 23280, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 11.0.11+9-LTS-194

using thread-local object allocation.
Garbage-First (G1) GC with 13 thread(s)

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 8533311488 (8138.0MB)
   NewSize                  = 1363144 (1.2999954223632812MB)
   MaxNewSize               = 5119148032 (4882.0MB)
   OldSize                  = 5452592 (5.1999969482421875MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 2097152 (2.0MB)

Heap Usage:
G1 Heap:
   regions  = 4069
   capacity = 8533311488 (8138.0MB)
   used     = 1470520 (1.4023971557617188MB)
   free     = 8531840968 (8136.597602844238MB)
   0.017232700365712936% used
G1 Young Generation:
Eden Space:
   regions  = 0
   capacity = 8388608 (8.0MB)
   used     = 0 (0.0MB)
   free     = 8388608 (8.0MB)
   0.0% used
Survivor Space:
   regions  = 0
   capacity = 0 (0.0MB)
   used     = 0 (0.0MB)
   free     = 0 (0.0MB)
   0.0% used
G1 Old Generation:
   regions  = 3
   capacity = 12582912 (12.0MB)
   used     = 1470520 (1.4023971557617188MB)
   free     = 11112392 (10.597602844238281MB)
   11.68664296468099% used

你可能感兴趣的:(java,jvm)