代码之家  ›  专栏  ›  技术社区  ›  Bokambo

GC(分配失败)

  •  0
  • Bokambo  · 技术社区  · 5 年前

    为什么总是“GC(分配失败)”?

    适用于linux-amd64 JRE的Java HotSpot(TM)64位服务器虚拟机(25.25-b02)( 1.8.0_25 -b17),

    CommandLine flags: 
    -XX:CMSInitiatingOccupancyFraction=60 
    -XX:GCLogFileSize=10485760 
    -XX:+HeapDumpOnOutOfMemoryError 
    -XX:InitialHeapSize=32212254720 
    -XX:MaxHeapSize=32212254720 
    -XX:NewRatio=10 
    -XX:OldPLABSize=16 
    -XX:ParallelGCThreads=4 
    -XX:+PrintGC 
    -XX:+PrintGCDetails 
    -XX:+PrintGCTimeStamps 
    -XX:+PrintStringTableStatistics 
    -XX:+PrintTenuringDistribution 
    -XX:StringTableSize=1000003 
    -XX:SurvivorRatio=4 
    -XX:TargetSurvivorRatio=50 
    -XX:+UseCompressedClassPointers 
    -XX:+UseCompressedOops
    -XX:+UseParNewGC 
    -XX:+UseConcMarkSweepGC
    
    27.329: [GC (Allocation Failure) 27.329: [ParNew
    Desired survivor size 44728320 bytes, new threshold 15 (max 15)
    - age   1:   16885304 bytes,   16885304 total
    : 349568K->16618K(436928K), 0.2069129 secs] 349568K->16618K(31369920K), 0.2070712 secs] [Times: user=0.78 sys=0.04, real=0.21 secs]
    
    
    28.210: [GC (Allocation Failure) 28.210: [ParNew
    Desired survivor size 44728320 bytes, new threshold 15 (max 15)
    - age   1:   28866504 bytes,   28866504 total
    - age   2:   12582536 bytes,   41449040 total
    : 366186K->47987K(436928K), 0.2144807 secs] 366186K->47987K(31369920K), 0.2146024 secs] [Times: user=0.84 sys=0.01, real=0.22 secs]
    
    
    29.037: [GC (Allocation Failure) 29.038: [ParNew
    Desired survivor size 44728320 bytes, new threshold 2 (max 15)
    - age   1:   28443488 bytes,   28443488 total
    - age   2:   28386624 bytes,   56830112 total
    - age   3:   12579928 bytes,   69410040 total
    : 397555K->76018K(436928K), 0.2357352 secs] 397555K->76018K(31369920K), 0.2358535 secs] [Times: user=0.93 sys=0.01, real=0.23 secs]
    
    0 回复  |  直到 6 年前
        1
  •  230
  •   Hearen    6 年前

    “分配失败”是GC周期开始的一个原因。

    “分配失败”意味着伊甸园中没有更多的空间来分配对象。所以,这是年轻GC的正常原因。

    较旧的JVM没有打印GC,这是因为GC周期较小。

    “分配失败”几乎是次要GC的唯一可能原因。次要GC启动的另一个原因可能是CMS备注阶段(如果 +XX:+ScavengeBeforeRemark 已启用)。

        2
  •  10
  •   Kamal Rathod    6 年前

    “分配失败”是GC不正确的原因。 这是GC操作的结果。

    当没有空间分配时(取决于执行的区域次要或主要GC),GC启动。 一旦执行GC,如果释放的空间足够好,但如果没有足够的大小,它就会失败。 分配失败就是这样一种失败。 下面的文件有很好的解释 https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/g1_gc.html

        3
  •  -6
  •   Hatter Bush    7 年前

    在jdk1中使用CMS GC时。如果出现此错误,我将更改G1 Gc以解决此问题。

     -Xss512k -Xms6g -Xmx6g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:InitiatingHeapOccupancyPercent=70 -XX:NewRatio=1 -XX:SurvivorRatio=6 -XX:G1ReservePercent=10 -XX:G1HeapRegionSize=32m -XX:ConcGCThreads=6 -Xloggc:gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps