`

常用JVM配置参数

    博客分类:
  • Java
 
阅读更多

详细信息参考:Oracle官方文档

环境信息:Windows10

JDK:1.8

 

Trace跟踪参数

 

public class Test {
    public static void main(String[] args) {
        byte[] bytes = null;
        for (int i = 0; i < 10; i++) {
            bytes = new byte[1 * 1024 * 1024];
        }
    }
}

 

 

 以上述代码为例,展示各个参数结果。

 

  • -verbose:gc 或 -XX:+printGC

作用:打印GC的简要信息

参数:

 

-Xmx10m -Xms5m -verbose:gc
-Xmx10m -Xms5m -XX:+printGC

 

 

......
[GC (Allocation Failure)  7362K->7217K(8704K), 0.0006685 secs]
[GC (Allocation Failure)  7217K->7257K(9728K), 0.0006430 secs]
[Full GC (Allocation Failure)  7257K->1828K(6656K), 0.0065725 secs]

 

  •  -XX:+PrintGCDetails

作用:打印GC详细信息

参数:

-Xmx10m -Xms5m -XX:+PrintGCDetails

 

[GC (Allocation Failure) [PSYoungGen: 504K->504K(2560K)] 7133K->7133K(9728K), 0.0005841 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[Full GC (Allocation Failure) [PSYoungGen: 504K->0K(2560K)] [ParOldGen: 6629K->1868K(4096K)] 7133K->1868K(6656K), [Metaspace: 3448K->3448K(1056768K)], 0.0046903 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 PSYoungGen      total 2560K, used 1044K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
  eden space 2048K, 51% used [0x00000000ffd00000,0x00000000ffe05370,0x00000000fff00000)
  from space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
  to   space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
 ParOldGen       total 5632K, used 4940K [0x00000000ff600000, 0x00000000ffb80000, 0x00000000ffd00000)
  object space 5632K, 87% used [0x00000000ff600000,0x00000000ffad31a8,0x00000000ffb80000)
 Metaspace       used 3454K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 376K, capacity 388K, committed 512K, reserved 1048576K
  •  -XX:+PrintGCDateStamps 

作用:打印GC发生的时间戳

参数:

-Xmx10m -Xms5m -XX:+PrintGCDetails -XX:+PrintGCDateStamps
......
2018-08-14T10:23:15.832+0800: [GC (Allocation Failure) [PSYoungGen: 496K->480K(2560K)] 7158K->7166K(9728K), 0.0004435 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2018-08-14T10:23:15.832+0800: [Full GC (Allocation Failure) [PSYoungGen: 480K->0K(2560K)] [ParOldGen: 6686K->1828K(4096K)] 7166K->1828K(6656K), [Metaspace: 3448K->3448K(1056768K)], 0.0043986 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 PSYoungGen      total 2560K, used 1085K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
  eden space 2048K, 53% used [0x00000000ffd00000,0x00000000ffe0f758,0x00000000fff00000)
  from space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
  to   space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
 ParOldGen       total 5632K, used 4900K [0x00000000ff600000, 0x00000000ffb80000, 0x00000000ffd00000)
  object space 5632K, 87% used [0x00000000ff600000,0x00000000ffac9050,0x00000000ffb80000)
 Metaspace       used 3454K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 376K, capacity 388K, committed 512K, reserved 1048576K
  •  -Xloggc:log/gc.log

作用:指定GC log的输出位置,以文件输出(目录需要手动创建,文件会自动创建)

参数:

-Xmx10m -Xms5m -XX:+PrintGCDetails -Xloggc:d:/log/gc.log


  •  -XX:+PrintHeapAtGC

作用:每一次GC前后,都打印堆的信息

参数:

-Xmx10m -Xms5m -XX:+PrintHeapAtGC
......
{Heap before GC invocations=4 (full 0):
 PSYoungGen      total 1536K, used 504K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
  eden space 1024K, 0% used [0x00000000ffd00000,0x00000000ffd00000,0x00000000ffe00000)
  from space 512K, 98% used [0x00000000ffe00000,0x00000000ffe7e010,0x00000000ffe80000)
  to   space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
 ParOldGen       total 7168K, used 6617K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
  object space 7168K, 92% used [0x00000000ff600000,0x00000000ffc76760,0x00000000ffd00000)
 Metaspace       used 3447K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 375K, capacity 388K, committed 512K, reserved 1048576K
Heap after GC invocations=4 (full 0):
 PSYoungGen      total 2560K, used 480K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
  eden space 2048K, 0% used [0x00000000ffd00000,0x00000000ffd00000,0x00000000fff00000)
  from space 512K, 93% used [0x00000000fff80000,0x00000000ffff8030,0x0000000100000000)
  to   space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
 ParOldGen       total 7168K, used 6697K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
  object space 7168K, 93% used [0x00000000ff600000,0x00000000ffc8a770,0x00000000ffd00000)
 Metaspace       used 3447K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 375K, capacity 388K, committed 512K, reserved 1048576K
}
{Heap before GC invocations=5 (full 1):
 PSYoungGen      total 2560K, used 480K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
  eden space 2048K, 0% used [0x00000000ffd00000,0x00000000ffd00000,0x00000000fff00000)
  from space 512K, 93% used [0x00000000fff80000,0x00000000ffff8030,0x0000000100000000)
  to   space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
 ParOldGen       total 7168K, used 6697K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
  object space 7168K, 93% used [0x00000000ff600000,0x00000000ffc8a770,0x00000000ffd00000)
 Metaspace       used 3447K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 375K, capacity 388K, committed 512K, reserved 1048576K
Heap after GC invocations=5 (full 1):
 PSYoungGen      total 2560K, used 0K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
  eden space 2048K, 0% used [0x00000000ffd00000,0x00000000ffd00000,0x00000000fff00000)
  from space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
  to   space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
 ParOldGen       total 4096K, used 1828K [0x00000000ff600000, 0x00000000ffa00000, 0x00000000ffd00000)
  object space 4096K, 44% used [0x00000000ff600000,0x00000000ff7c9020,0x00000000ffa00000)
 Metaspace       used 3447K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 375K, capacity 388K, committed 512K, reserved 1048576K
}
  •  -Xmx10m -Xms5m -XX:+TraceClassLoading

作用:监控类的加载

参数:

-Xmx10m -Xms5m -XX:+TraceClassLoading
[Opened D:\Dev_Tools\Java\jdk1.8.0_161\jre\lib\rt.jar]
[Loaded java.lang.Object from D:\Dev_Tools\Java\jdk1.8.0_161\jre\lib\rt.jar]
[Loaded java.io.Serializable from D:\Dev_Tools\Java\jdk1.8.0_161\jre\lib\rt.jar]
......
[Loaded java.lang.Shutdown from D:\Dev_Tools\Java\jdk1.8.0_161\jre\lib\rt.jar]
[Loaded java.lang.Shutdown$Lock from D:\Dev_Tools\Java\jdk1.8.0_161\jre\lib\rt.jar]
  •  -XX:+PrintClassHistogram

作用:打印类的信息,包含实例数量、总大小、类型等

参数:

-Xmx10m -Xms5m -XX:+PrintClassHistogram

 按下Ctrl+Break后,打印类的信息

 num     #instances         #bytes  class name
----------------------------------------------
   1:            46        1082640  [B
   2:          3013         416608  [C
   3:           639          72976  java.lang.Class
   4:          2863          68712  java.lang.String
   5:           624          36816  [Ljava.lang.Object;
   6:           791          31640  java.util.TreeMap$Entry
   7:           782          18768  java.util.LinkedList$Node
   8:           485          15520  java.util.HashMap$Node
   9:           394          12608  java.util.LinkedList
   ......

 

堆分配参数

  • -Xmx –Xms

作用:指定最大堆和最小堆。在分配堆空间时,最好保持-Xmx –Xms数值一致,以免

参数:-Xmx20m -Xms5m

 

        byte[] bytes = new byte[1 * 1024 * 1024];
        // 堆总大小
        System.out.print("Xmx=");
        System.out.println(Runtime.getRuntime().maxMemory()/1024.0/1024+"M");
        // 当前剩余可用空间
        System.out.print("free mem=");
        System.out.println(Runtime.getRuntime().freeMemory()/1024.0/1024+"M");
        // 当前总共分配空间
        System.out.print("total mem=");
        System.out.println(Runtime.getRuntime().totalMemory()/1024.0/1024+"M");

 

分配1M空间给数组
Xmx=18.0M
free mem=4.182762145996094M
total mem=6.5M

 由于Java会尽可能维持在最小堆运行,所以total mem会尽可能保持较小的值。

 

 

        byte[] bytes = new byte[6 * 1024 * 1024];
        // 堆总大小
        System.out.print("Xmx=");
        System.out.println(Runtime.getRuntime().maxMemory()/1024.0/1024+"M");
        // 当前剩余可用空间
        System.out.print("free mem=");
        System.out.println(Runtime.getRuntime().freeMemory()/1024.0/1024+"M");
        // 当前总共分配空间
        System.out.print("total mem=");
        System.out.println(Runtime.getRuntime().totalMemory()/1024.0/1024+"M");

 

分配6M空间给数组
Xmx=18.0M
free mem=4.718879699707031M
total mem=12.0M
  •  -Xmn

作用:设置新生代大小。官方推荐新生代占堆的3/8。

 

  • -XX:NewRatio

作用:设置新生代(eden+2*s)和老年代(不包含永久区)的比值。比如-XX:NewRatio=4表示: 新生代:老年代 = 1:4,即新生代占1/5

 

  • -XX:SurvivorRatio

作用:设置两个Survivor区和eden的比。比如-XX:SurvivorRatio=8表示:两个Survivor:eden=2:8,即一个Survivor占新生代的1/10。官方推荐Survivor占新生代的1/10。

 

  • -XX:+HeapDumpOnOutOfMemoryError

作用:OOM时将堆信息导出到文件中

 

  • -XX:+HeapDumpPath

作用:指定OOM时导出的文件路径

参数:-Xmx20m -Xms5m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=d:/a.dump 

 

 

public class Test {
    public static void main(String[] args) {
        Vector vector = new Vector();
        for (int index = 0; index < 25; index++) {
            vector.add(new byte[1 * 1024 * 1024]);
        }
    }
}

 

java.lang.OutOfMemoryError: Java heap space
Dumping heap to d:/a.dump ...
Heap dump file created [15379974 bytes in 0.049 secs]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at com.example.demo.test.Test.main(Test.java:14)

 

 

  • -XX:OnOutOfMemoryError

作用:在OOM时,执行一个脚本。可以在OOM时发送邮件告警、甚至重启程序。

 

  • -XX:PermSize  -XX:MaxPermSize

作用:设置永久区的初始空间和最大空间,与-Xmx –Xms类似。

 

堆分配实例

 

public class Test {
    public static void main(String[] args) {
        byte[] bytes = null;
        for (int index = 0; index < 10; index++) {
            bytes = new byte[1 * 1024 * 1024];
        }
    }
}

 

  •  -Xmx20m -Xms20m -Xmn1m -XX:+PrintGCDetails

解释说明:堆大小为20M,新生代大小为1M。

 

[GC (Allocation Failure) [PSYoungGen: 512K->504K(1024K)] 512K->512K(19968K), 0.0008422 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 1016K->504K(1024K)] 1024K->672K(19968K), 0.0009345 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 1016K->504K(1024K)] 1184K->847K(19968K), 0.0007328 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 1016K->504K(1024K)] 1359K->927K(19968K), 0.0005718 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 PSYoungGen      total 1024K, used 830K [0x00000000ffe80000, 0x0000000100000000, 0x0000000100000000)
  eden space 512K, 63% used [0x00000000ffe80000,0x00000000ffed1888,0x00000000fff00000)
  from space 512K, 98% used [0x00000000fff80000,0x00000000ffffe010,0x0000000100000000)
  to   space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
 ParOldGen       total 18944K, used 10663K [0x00000000fec00000, 0x00000000ffe80000, 0x00000000ffe80000)
  object space 18944K, 56% used [0x00000000fec00000,0x00000000ff669f88,0x00000000ffe80000)
 Metaspace       used 3454K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 376K, capacity 388K, committed 512K, reserved 1048576K
Java HotSpot(TM) 64-Bit Server VM warning: NewSize (1536k) is greater than the MaxNewSize (1024k). A new max generation size of 1536k will be used.

 新生代无法分配(Eden和两个Survivor总大小为1M),对象直接在老年代分配。总共分配对象大小为10M,并未触发Full GC,所以老年代空间使用在10M左右,并没有回收。

 

 

注意最后一行,虚拟机提示新生代大小最好设置为1536K。

 

  • -Xmx20m -Xms20m -Xmn1536K -XX:+PrintGCDetails

 

[GC (Allocation Failure) [PSYoungGen: 512K->504K(1024K)] 512K->544K(19968K), 0.0006121 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 1016K->504K(1024K)] 1056K->672K(19968K), 0.0008765 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 1016K->504K(1024K)] 1184K->819K(19968K), 0.0007404 secs] [Times: user=0.09 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 1016K->504K(1024K)] 1331K->963K(19968K), 0.0007809 secs] [Times: user=0.02 sys=0.00, real=0.00 secs] 
Heap
 PSYoungGen      total 1024K, used 823K [0x00000000ffe80000, 0x0000000100000000, 0x0000000100000000)
  eden space 512K, 62% used [0x00000000ffe80000,0x00000000ffecfc58,0x00000000fff00000)
  from space 512K, 98% used [0x00000000fff80000,0x00000000ffffe010,0x0000000100000000)
  to   space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
 ParOldGen       total 18944K, used 10699K [0x00000000fec00000, 0x00000000ffe80000, 0x00000000ffe80000)
  object space 18944K, 56% used [0x00000000fec00000,0x00000000ff672d50,0x00000000ffe80000)
 Metaspace       used 3454K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 376K, capacity 388K, committed 512K, reserved 1048576K

 貌似没啥效果!

 

 

  • -Xmx20m -Xms20m -Xmn15m -XX:+PrintGCDetails

解释说明:堆大小为20M,新生代大小为15M。

 

[GC (Allocation Failure) [PSYoungGen: 12249K->1520K(13824K)] 12249K->1969K(18944K), 0.0011009 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 PSYoungGen      total 13824K, used 2667K [0x00000000ff100000, 0x0000000100000000, 0x0000000100000000)
  eden space 12288K, 9% used [0x00000000ff100000,0x00000000ff21ed08,0x00000000ffd00000)
  from space 1536K, 98% used [0x00000000ffd00000,0x00000000ffe7c020,0x00000000ffe80000)
  to   space 1536K, 0% used [0x00000000ffe80000,0x00000000ffe80000,0x0000000100000000)
 ParOldGen       total 5120K, used 449K [0x00000000fec00000, 0x00000000ff100000, 0x00000000ff100000)
  object space 5120K, 8% used [0x00000000fec00000,0x00000000fec706d0,0x00000000ff100000)
 Metaspace       used 3454K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 376K, capacity 388K, committed 512K, reserved 1048576K

 对象全部分配在新生代中,老年代基本没有使用。新生代触发GC并回收了一部分内存(Survivor大小为1536K,因此GC时不需要老年代进行担保,即对象不会进入老年代),只有部分对象依然存在于内存中,大部分对象已被回收。

 

 

  • -Xmx20m -Xms20m -Xmn7m -XX:+PrintGCDetails

解释说明:堆大小为20M,新生代大小为7M。

 

[GC (Allocation Failure) [PSYoungGen: 5557K->488K(6656K)] 5557K->1909K(19968K), 0.0010793 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 5724K->488K(6656K)] 7146K->2969K(19968K), 0.0012265 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 PSYoungGen      total 6656K, used 2708K [0x00000000ff900000, 0x0000000100000000, 0x0000000100000000)
  eden space 6144K, 36% used [0x00000000ff900000,0x00000000ffb2b110,0x00000000fff00000)
  from space 512K, 95% used [0x00000000fff80000,0x00000000ffffa040,0x0000000100000000)
  to   space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
 ParOldGen       total 13312K, used 2481K [0x00000000fec00000, 0x00000000ff900000, 0x00000000ff900000)
  object space 13312K, 18% used [0x00000000fec00000,0x00000000fee6c6e0,0x00000000ff900000)
 Metaspace       used 3454K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 376K, capacity 388K, committed 512K, reserved 1048576K

 对象全部分配在新生代,但是新生代GC时Survivor大小不足1M,部分对象进入老年代,还有一部分对象在GC时被回收。

 

 

  • -Xmx20m -Xms20m -Xmn7m   -XX:SurvivorRatio=2 -XX:+PrintGCDetails

解释说明:堆大小为20M,新生代大小为7M,但是增大Survivor大小为新生代的1/4。

 

[GC (Allocation Failure) [PSYoungGen: 3457K->1000K(5632K)] 3457K->2032K(18944K), 0.0015567 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 4148K->1528K(5632K)] 5180K->2947K(18944K), 0.0010745 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 4669K->1520K(5632K)] 6088K->3019K(18944K), 0.0006911 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 PSYoungGen      total 5632K, used 4747K [0x00000000ff900000, 0x0000000100000000, 0x0000000100000000)
  eden space 4096K, 78% used [0x00000000ff900000,0x00000000ffc26cd8,0x00000000ffd00000)
  from space 1536K, 98% used [0x00000000ffd00000,0x00000000ffe7c050,0x00000000ffe80000)
  to   space 1536K, 0% used [0x00000000ffe80000,0x00000000ffe80000,0x0000000100000000)
 ParOldGen       total 13312K, used 1499K [0x00000000fec00000, 0x00000000ff900000, 0x00000000ff900000)
  object space 13312K, 11% used [0x00000000fec00000,0x00000000fed76c80,0x00000000ff900000)
 Metaspace       used 3454K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 376K, capacity 388K, committed 512K, reserved 1048576K

 由于扩大了Survivor大小,进入老年代的对象减少。

 

 

  • -Xmx20m -Xms20m -Xmn7m   -XX:SurvivorRatio=1 -XX:+PrintGCDetails

解释说明:堆大小为20M,新生代大小为7M,但是增大Survivor大小为新生代的1/3。

 

[GC (Allocation Failure) [PSYoungGen: 2441K->904K(5120K)] 2441K->912K(18432K), 0.0018878 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 3007K->1976K(5120K)] 3015K->1984K(18432K), 0.0009336 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 4132K->1960K(5120K)] 4140K->1968K(18432K), 0.0008194 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 4059K->1960K(5120K)] 4067K->1968K(18432K), 0.0006821 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 4062K->1960K(5120K)] 4070K->1968K(18432K), 0.0006000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 PSYoungGen      total 5120K, used 4126K [0x00000000ff900000, 0x0000000100000000, 0x0000000100000000)
  eden space 3072K, 70% used [0x00000000ff900000,0x00000000ffb1d810,0x00000000ffc00000)
  from space 2048K, 95% used [0x00000000ffc00000,0x00000000ffdea030,0x00000000ffe00000)
  to   space 2048K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x0000000100000000)
 ParOldGen       total 13312K, used 8K [0x00000000fec00000, 0x00000000ff900000, 0x00000000ff900000)
  object space 13312K, 0% used [0x00000000fec00000,0x00000000fec02000,0x00000000ff900000)
 Metaspace       used 3454K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 376K, capacity 388K, committed 512K, reserved 1048576K

 继续扩大Survivor大小,没有进入老年代的对象。

 

 

  • -Xmx20m -Xms20m -XX:NewRatio=1 -XX:SurvivorRatio=2 -XX:+PrintGCDetails 

解释说明:堆大小为20M,新生代与老年代比例为1:1,即新生代占一半内存空间(10M),并且新生代中两个Survivor:Eden比值为2:2,即每个Survivor占新生代1/4空间(2.5M)。

 

[GC (Allocation Failure) [PSYoungGen: 4564K->2056K(7680K)] 4564K->2064K(17920K), 0.0012851 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 6248K->1976K(7680K)] 6256K->1984K(17920K), 0.0010730 secs] [Times: user=0.03 sys=0.00, real=0.00 secs] 
Heap
 PSYoungGen      total 7680K, used 6315K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
  eden space 5120K, 84% used [0x00000000ff600000,0x00000000ffa3ce18,0x00000000ffb00000)
  from space 2560K, 77% used [0x00000000ffd80000,0x00000000fff6e040,0x0000000100000000)
  to   space 2560K, 0% used [0x00000000ffb00000,0x00000000ffb00000,0x00000000ffd80000)
 ParOldGen       total 10240K, used 8K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
  object space 10240K, 0% used [0x00000000fec00000,0x00000000fec02000,0x00000000ff600000)
 Metaspace       used 3454K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 376K, capacity 388K, committed 512K, reserved 1048576K

 对象全部在新生代分配,且没有对象进入老年代。

 

 

栈分配参数

  • -Xss

作用:指定栈大小,通常只有几百K,决定了函数调用的深度。

 

垃圾收集器相关参数

  • -XX:+UseSerialGC:在新生代和老年代使用串行收集器
  • -XX:+UseParNewGC:在新生代使用并行收集器
  • -XX:+UseParallelGC :在新生代使用并行收集器,吞吐量优先
  • -XX:+UseParallelOldGC:在老年代使用并行收集器,吞吐量优先
  • -XX:ParallelGCThreads:设置用于并行垃圾回收的线程数,以CPU核数为依据进行设置
  • -XX:+UseConcMarkSweepGC:新生代使用并行收集器,老年代使用CMS+串行收集器(CMS为并发收集器,进行回收时程序依然在运行。程序可能在内存使用将满进行垃圾回收时,继续申请内存从而导致回收失败,此时使用备用的串行收集器进行垃圾回收)
  • -XX:MaxGCPauseMills:最大停顿时间(毫秒),GC尽力保证每次回收时间不超过设定值
  • -XX:GCTimeRatio:垃圾收集时间占总时间的比值。默认为99,即最大允许1%的时间做GC。
  • -XX:ParallelCMSThreads:设定CMS的线程数量
  • -XX:CMSInitiatingOccupancyFraction:设置CMS收集器在老年代空间被使用多少后触发(防止CMS回收失败)
  • -XX:+UseCMSCompactAtFullCollection:设置CMS收集器在完成垃圾收集后是否要进行一次内存碎片的整理(CMS使用标记-清除算法,可能会有碎片存在)
  • -XX:CMSFullGCsBeforeCompaction:设定进行多少次CMS垃圾回收后,进行一次内存压缩(即碎片整理)
  • -XX:+CMSClassUnloadingEnabled:允许对类元数据进行回收
  • -XX:CMSInitiatingPermOccupancyFraction:当永久区占用率达到这一百分比时,启动CMS回收
  • -XX:UseCMSInitiatingOccupancyOnly:表示只在到达阀值的时候,才进行CMS回收
 
-XX:MaxGCPauseMills和-XX:GCTimeRatio两个参数是互相矛盾的,因为停顿时间和吞吐量不可能同时调优。

垃圾回收的工作总量基本不变,如果停顿时间设置较小,势必需要频繁GC(每次GC都需要先标记再回收)才能完成全部回收工作,那么GC所占用的时间会更多(用于响应请求的时间会相对较少,吞吐量相对较低);如果想要吞吐量较高,则GC占用时间相应较少,势必需要减少GC次数,那么每次GC的停顿时间相对较长。

 

  • 大小: 9.8 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics