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

标签 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] 

之前young gc空间大小为38400K,old gen大小为130560K,但最终young gc空间大小为428032K,old gen大小为1826304K。

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

最佳答案

Can jvm gc size auto increase?

它确实会自动增加,这就是为什么你有一个初始大小 -ms-Xms 和一个最大大小 -mx-Xmx

您应该将 -mx 设置为您想要的大小,而不是程序死掉而不是使用更多堆。

So should I config the gc size ?

如果您想使用 10GB 堆,我建议您将最大堆设置为至少 11 GB,例如-Xmx11g 但仅在检查您的机器是否有 12 GB 可用主内存后。

关于java - jvm gc大小可以自动增加吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39929254/

相关文章:

java - 我的 jar 可以在 Ubuntu 上运行,但不能在 Windows 上运行

java - 默认 Java 堆大小及其可能导致的内存问题

java - 为什么 JVM 使用全 0 的巨型 int[]?

android - OpenGL ES 2.0 顶点错误垃圾收集器 (Android)

java - 加载数据时达到饱和点;我如何控制 Java GC 生成?

java - 在运行时编辑 JavaFX CSS

java - 无法使用 eager=true 将依赖项注入(inject)到 JSF bean(Websphere、Myfaces)

java - Java/GWT 中的 GUI 模式 - 一般方法

java - 如何在java中对嵌套列表进行排序

c#检测何时有太多对象