可以jvm gc大小自动增加?

时间:2016-10-08 06:07:07

标签: java garbage-collection jvm

我使用的是java版本:

java version "1.8.0_73"
Java(TM) SE Runtime Environment (build 1.8.0_73-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)

我写了一个简单的测试:

byte[][] bs = new byte[10000][];
for (int i = 0; i < 10000; ++i) {
   bs[i] = new byte[1024 * 1024]; // allocate 1M
}

获取gc详细信息:

[GC (Allocation Failure) [PSYoungGen: 32305K->5047K(38400K)] 32305K->26559K(125952K), 0.0182411 secs] [Times: user=0.02 sys=0.03, real=0.02 secs] 
[GC (Allocation Failure) [PSYoungGen: 37429K->4743K(71680K)] 58941K->58007K(159232K), 0.0367694 secs] [Times: user=0.03 sys=0.05, real=0.04 secs] 
[Full GC (Ergonomics) [PSYoungGen: 4743K->0K(71680K)] [ParOldGen: 53264K->57939K(130560K)] 58007K->57939K(202240K), [Metaspace: 4229K->4229K(1056768K)], 0.0320848 secs] [Times: user=0.04 sys=0.01, real=0.03 secs] 
[GC (Allocation Failure) [PSYoungGen: 65784K->4096K(71680K)] 123724K->123476K(202240K), 0.0690420 secs] [Times: user=0.05 sys=0.10, real=0.07 secs] 
[Full GC (Ergonomics) [PSYoungGen: 4096K->0K(71680K)] [ParOldGen: 119380K->123476K(233472K)] 123476K->123476K(305152K), [Metaspace: 4229K->4229K(1056768K)], 0.0111538 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 
[GC (Allocation Failure) [PSYoungGen: 65789K->4096K(129536K)] 189265K->189013K(363008K), 0.0547978 secs] [Times: user=0.04 sys=0.08, real=0.05 secs] 
[Full GC (Ergonomics) [PSYoungGen: 4096K->0K(129536K)] [ParOldGen: 184917K->189013K(315904K)] 189013K->189013K(445440K), [Metaspace: 4229K->4229K(1056768K)], 0.0166668 secs] [Times: user=0.02 sys=0.01, real=0.02 secs] 
[GC (Allocation Failure) [PSYoungGen: 124258K->4096K(130048K)] 313272K->312919K(445952K), 0.0847352 secs] [Times: user=0.05 sys=0.11, real=0.08 secs] 
[Full GC (Ergonomics) [PSYoungGen: 4096K->0K(130048K)] [ParOldGen: 308823K->312919K(489984K)] 312919K->312919K(620032K), [Metaspace: 4229K->4229K(1056768K)], 0.0097317 secs] [Times: user=0.01 sys=0.01, real=0.01 secs] 
[GC (Allocation Failure) [PSYoungGen: 124268K->5120K(232448K)] 437188K->436825K(722432K), 0.1084567 secs] [Times: user=0.08 sys=0.14, real=0.11 secs] 
[Full GC (Ergonomics) [PSYoungGen: 5120K->0K(232448K)] [ParOldGen: 431705K->436825K(640512K)] 436825K->436825K(872960K), [Metaspace: 4229K->4229K(1056768K)], 0.0105436 secs] [Times: user=0.01 sys=0.01, real=0.01 secs] 
[GC (Allocation Failure) [PSYoungGen: 226600K->5120K(232448K)] 663425K->663133K(891392K), 0.1234434 secs] [Times: user=0.09 sys=0.17, real=0.12 secs] 
[Full GC (Ergonomics) [PSYoungGen: 5120K->5120K(232448K)] [ParOldGen: 658012K->658012K(930816K)] 663133K->663133K(1163264K), [Metaspace: 4229K->4229K(1056768K)], 0.0339242 secs] [Times: user=0.02 sys=0.01, real=0.04 secs] 
[GC (Allocation Failure) [PSYoungGen: 231734K->5120K(427008K)] 889747K->889440K(1357824K), 0.2574536 secs] [Times: user=0.13 sys=0.20, real=0.26 secs] 
[Full GC (Ergonomics) [PSYoungGen: 5120K->0K(427008K)] [ParOldGen: 884320K->889440K(1209856K)] 889440K->889440K(1636864K), [Metaspace: 4229K->4229K(1056768K)], 0.0407911 secs] [Times: user=0.03 sys=0.02, real=0.04 secs] 
[GC (Allocation Failure) [PSYoungGen: 421376K->5120K(428032K)] 1310816K->1310310K(1734656K), 0.3690828 secs] [Times: user=0.24 sys=0.44, real=0.37 secs] 
[Full GC (Ergonomics) [PSYoungGen: 5120K->4096K(428032K)] [ParOldGen: 1305190K->1306214K(1398272K)] 1310310K->1310310K(1826304K), [Metaspace: 4229K->4229K(1056768K)], 0.0325402 secs] [Times: user=0.02 sys=0.01, real=0.03 secs] 
[Full GC (Ergonomics) [PSYoungGen: 425984K->331781K(428032K)] [ParOldGen: 1306214K->1397352K(1398272K)] 1732198K->1729133K(1826304K), [Metaspace: 4229K->4229K(1056768K)], 0.1704718 secs] [Times: user=0.21 sys=0.14, real=0.17 secs] 
[Full GC (Ergonomics) [PSYoungGen: 421888K->420870K(428032K)] [ParOldGen: 1397352K->1397352K(1398272K)] 1819240K->1818222K(1826304K), [Metaspace: 4229K->4229K(1056768K)], 0.0321183 secs] [Times: user=0.05 sys=0.00, real=0.03 secs] 
[Full GC (Allocation Failure) [PSYoungGen: 420870K->420870K(428032K)] [ParOldGen: 1397352K->1397315K(1398272K)] 1818222K->1818185K(1826304K), [Metaspace: 4229K->4229K(1056768K)], 2.7526882 secs] [Times: user=3.41 sys=1.22, real=2.76 secs] 

在年轻的gc空间大小为38400K之前,旧的大小为130560K,但最终年轻的gc空间大小为428032K,旧的大小为1826304K。

jvm gc大小可以自动增加吗?那么我应该配置gc大小吗?

1 个答案:

答案 0 :(得分:2)

  

jvm gc大小可以自动增加吗?

它会自动增加,这就是为什么您的初始尺寸-ms-Xms以及最大尺寸-mx-Xmx

你应该将-mx设置为你想要的大小而不是编程而不是使用更多的堆。

  

我应该配置gc大小吗?

如果你想使用10GB的堆我建议你的最大堆至少为11 GB,例如-Xmx11g但只有在检查完您的机器后才会说12 GB的可用主内存。