当前位置: 首页 > 知识库问答 >
问题:

为什么G1完全GC似乎被不必要地触发?

濮阳和泰
2023-03-14

我在用

java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

使用G1垃圾收集器。JVM参数是

-server -Xss4096k -XX:MaxPermSize=512m -XX:PermSize=512m -Xms30G 
-Xmx30G -Xnoclassgc -XX:+UseNUMA -XX:+UseFastAccessorMethods 
-XX:ReservedCodeCacheSize=48m -XX:+UseStringCache 
-XX:+UseGCOverheadLimit -Duser.timezone=EET 
-Xmaxf1 -XX:+UseCompressedOops -XX:+DisableExplicitGC 
-XX:+AggressiveOpts -XX:CMSInitiatingOccupancyFraction=70 
-XX:+ParallelRefProcEnabled -XX:+UseAdaptiveSizePolicy 
-XX:MaxGCPauseMillis=500 -XX:+UseG1GC 
-XX:InitiatingHeapOccupancyPercent=0 
-XX:GCPauseIntervalMillis=10000 -XX:+PrintGCDetails 
-XX:+PrintHeapAtGC -XX:+PrintGCDateStamps -Xloggc:gc.log

然而,我在没有任何明显原因的情况下经历了完整的GC扫描,如何摆脱它们?

GC日志,带有前面事件的一些尾部:

{Heap before GC invocations=206 (full 8):
 garbage-first heap   total 31457280K, used 18323299K [0x00007fc6eb800000, 0x00007fce6b800000, 0x00007fce6b800000)
  region size 8192K, 768 young (6291456K), 31 survivors (253952K)
 compacting perm gen  total 524288K, used 145771K [0x00007fce6b800000, 0x00007fce8b800000, 0x00007fce8b800000)
   the space 524288K,  27% used [0x00007fce6b800000, 0x00007fce7465af18, 0x00007fce7465b000, 0x00007fce8b800000)
No shared spaces configured.
2013-01-16T11:45:31.290+0200: 20430.451: [GC pause (young), 0.54738500 secs]
   [Parallel Time: 510.7 ms]
      [GC Worker Start (ms):  20430451.7  20430451.8  20430451.8  20430451.8
       Avg: 20430451.8, Min: 20430451.7, Max: 20430451.8, Diff:   0.1]
      [Ext Root Scanning (ms):  22.3  68.3  21.8  20.8
       Avg:  33.3, Min:  20.8, Max:  68.3, Diff:  47.5]
      [Update RS (ms):  21.6  0.0  23.6  23.7
       Avg:  17.3, Min:   0.0, Max:  23.7, Diff:  23.7]
         [Processed Buffers : 77 0 18 55
          Sum: 150, Avg: 37, Min: 0, Max: 77, Diff: 77]
      [Scan RS (ms):  19.6  0.1  19.3  19.6
       Avg:  14.7, Min:   0.1, Max:  19.6, Diff:  19.5]
      [Object Copy (ms):  439.1  434.2  437.8  438.4
       Avg: 437.4, Min: 434.2, Max: 439.1, Diff:   4.9]
      [Termination (ms):  0.0  0.0  0.0  0.0
       Avg:   0.0, Min:   0.0, Max:   0.0, Diff:   0.0]
         [Termination Attempts : 1 1 1 1
          Sum: 4, Avg: 1, Min: 1, Max: 1, Diff: 0]
      [GC Worker End (ms):  20430954.5  20430954.6  20430954.5  20430954.4
       Avg: 20430954.5, Min: 20430954.4, Max: 20430954.6, Diff:   0.1]
      [GC Worker (ms):  502.7  502.8  502.7  502.6
       Avg: 502.7, Min: 502.6, Max: 502.8, Diff:   0.2]
      [GC Worker Other (ms):  8.0  8.0  8.0  8.1
       Avg:   8.0, Min:   8.0, Max:   8.1, Diff:   0.1]
   [Clear CT:   2.6 ms]
   [Other:  34.1 ms]
      [Choose CSet:   0.1 ms]
      [Ref Proc:  27.4 ms]
      [Ref Enq:   0.2 ms]
      [Free CSet:   5.4 ms]
   [Eden: 5896M(5896M)->0B(5688M) Survivors: 248M->456M Heap: 17893M(30720M)->12208M(30720M)]
 [Times: user=2.12 sys=0.02, real=0.55 secs]
Heap after GC invocations=207 (full 8):
 garbage-first heap   total 31457280K, used 12501684K [0x00007fc6eb800000, 0x00007fce6b800000, 0x00007fce6b800000)
  region size 8192K, 57 young (466944K), 57 survivors (466944K)
 compacting perm gen  total 524288K, used 145771K [0x00007fce6b800000, 0x00007fce8b800000, 0x00007fce8b800000)
   the space 524288K,  27% used [0x00007fce6b800000, 0x00007fce7465af18, 0x00007fce7465b000, 0x00007fce8b800000)
No shared spaces configured.
}
{Heap before GC invocations=207 (full 8):
 garbage-first heap   total 31457280K, used 19058524K [0x00007fc6eb800000, 0x00007fce6b800000, 0x00007fce6b800000)
  region size 8192K, 727 young (5955584K), 57 survivors (466944K)
 compacting perm gen  total 524288K, used 145775K [0x00007fce6b800000, 0x00007fce8b800000, 0x00007fce8b800000)
   the space 524288K,  27% used [0x00007fce6b800000, 0x00007fce7465bdd8, 0x00007fce7465be00, 0x00007fce8b800000)
No shared spaces configured.
2013-01-16T11:46:26.619+0200: 20485.781: [GC pause (mixed), 1.42356500 secs]
   [Parallel Time: 1385.9 ms]
      [GC Worker Start (ms):  20485786.6  20485786.6  20485786.6  20485786.7
       Avg: 20485786.6, Min: 20485786.6, Max: 20485786.7, Diff:   0.1]
      [Ext Root Scanning (ms):  22.1  70.0  22.2  21.3
       Avg:  33.9, Min:  21.3, Max:  70.0, Diff:  48.7]
      [Update RS (ms):  9.9  0.0  10.9  11.2
       Avg:   8.0, Min:   0.0, Max:  11.2, Diff:  11.2]
         [Processed Buffers : 13 0 25 17
          Sum: 55, Avg: 13, Min: 0, Max: 25, Diff: 25]
      [Scan RS (ms):  324.6  276.4  324.6  324.6
       Avg: 312.5, Min: 276.4, Max: 324.6, Diff:  48.2]
      [Object Copy (ms):  1021.1  1031.2  1019.8  1020.5
       Avg: 1023.1, Min: 1019.8, Max: 1031.2, Diff:  11.4]
      [Termination (ms):  0.0  0.0  0.0  0.0
       Avg:   0.0, Min:   0.0, Max:   0.0, Diff:   0.0]
         [Termination Attempts : 6 5 5 1
          Sum: 17, Avg: 4, Min: 1, Max: 6, Diff: 5]
      [GC Worker End (ms):  20487164.3  20487164.3  20487164.3  20487164.3
       Avg: 20487164.3, Min: 20487164.3, Max: 20487164.3, Diff:   0.0]
      [GC Worker (ms):  1377.7  1377.6  1377.6  1377.6
       Avg: 1377.7, Min: 1377.6, Max: 1377.7, Diff:   0.1]
      [GC Worker Other (ms):  8.2  8.3  8.3  8.3
       Avg:   8.3, Min:   8.2, Max:   8.3, Diff:   0.1]
   [Clear CT:   4.4 ms]
   [Other:  33.3 ms]
      [Choose CSet:   5.5 ms]
      [Ref Proc:   5.0 ms]
      [Ref Enq:   0.2 ms]
      [Free CSet:   9.1 ms]
   [Eden: 5360M(5688M)->0B(5784M) Survivors: 456M->360M Heap: 18616M(30720M)->11359M(30720M)]
 [Times: user=5.56 sys=0.01, real=1.42 secs]
Heap after GC invocations=208 (full 8):
 garbage-first heap   total 31457280K, used 11632594K [0x00007fc6eb800000, 0x00007fce6b800000, 0x00007fce6b800000)
  region size 8192K, 45 young (368640K), 45 survivors (368640K)
 compacting perm gen  total 524288K, used 145775K [0x00007fce6b800000, 0x00007fce8b800000, 0x00007fce8b800000)
   the space 524288K,  27% used [0x00007fce6b800000, 0x00007fce7465bdd8, 0x00007fce7465be00, 0x00007fce8b800000)
No shared spaces configured.
}
{Heap before GC invocations=208 (full 8):
 garbage-first heap   total 31457280K, used 11632594K [0x00007fc6eb800000, 0x00007fce6b800000, 0x00007fce6b800000)
  region size 8192K, 45 young (368640K), 45 survivors (368640K)
 compacting perm gen  total 524288K, used 145775K [0x00007fce6b800000, 0x00007fce8b800000, 0x00007fce8b800000)
   the space 524288K,  27% used [0x00007fce6b800000, 0x00007fce7465bdd8, 0x00007fce7465be00, 0x00007fce8b800000)
No shared spaces configured.
2013-01-16T11:46:28.060+0200: 20487.222: [Full GC 11359M->8807M(30720M), 32.4879420 secs]
 [Times: user=45.41 sys=0.21, real=32.48 secs]
Heap after GC invocations=209 (full 9):
 garbage-first heap   total 31457280K, used 9019206K [0x00007fc6eb800000, 0x00007fce6b800000, 0x00007fce6b800000)
  region size 8192K, 0 young (0K), 0 survivors (0K)
 compacting perm gen  total 524288K, used 145775K [0x00007fce6b800000, 0x00007fce8b800000, 0x00007fce8b800000)
   the space 524288K,  27% used [0x00007fce6b800000, 0x00007fce7465bdd8, 0x00007fce7465be00, 0x00007fce8b800000)
No shared spaces configured.
}

其他类似的:

{Heap before GC invocations=105 (full 4):
 garbage-first heap   total 31457280K, used 12638024K [0x00007fcb22800000, 0x00007fd2a2800000, 0x00007fd2a2800000)
  region size 8192K, 56 young (458752K), 56 survivors (458752K)
 compacting perm gen  total 524288K, used 147352K [0x00007fd2a2800000, 0x00007fd2c2800000, 0x00007fd2c2800000)
   the space 524288K,  28% used [0x00007fd2a2800000, 0x00007fd2ab7e61f8, 0x00007fd2ab7e6200, 0x00007fd2c2800000)
No shared spaces configured.
2013-01-14T10:31:31.240+0200: 14185.812: [Full GC 12341M->7092M(30720M), 25.3417840 secs]
 [Times: user=35.12 sys=0.21, real=25.33 secs]
Heap after GC invocations=106 (full 5):
 garbage-first heap   total 31457280K, used 7262578K [0x00007fcb22800000, 0x00007fd2a2800000, 0x00007fd2a2800000)
  region size 8192K, 0 young (0K), 0 survivors (0K)
 compacting perm gen  total 524288K, used 147352K [0x00007fd2a2800000, 0x00007fd2c2800000, 0x00007fd2c2800000)
   the space 524288K,  28% used [0x00007fd2a2800000, 0x00007fd2ab7e61f8, 0x00007fd2ab7e6200, 0x00007fd2c2800000)
No shared spaces configured.
}

{Heap before GC invocations=248 (full 11):
 garbage-first heap   total 31457280K, used 12262418K [0x00007fcb22800000, 0x00007fd2a2800000, 0x00007fd2a2800000)
  region size 8192K, 37 young (303104K), 37 survivors (303104K)
 compacting perm gen  total 524288K, used 152608K [0x00007fd2a2800000, 0x00007fd2c2800000, 0x00007fd2c2800000)
   the space 524288K,  29% used [0x00007fd2a2800000, 0x00007fd2abd082e8, 0x00007fd2abd08400, 0x00007fd2c2800000)
No shared spaces configured.
2013-01-14T13:01:39.869+0200: 23194.441: [Full GC 11975M->7331M(30720M), 28.6147390 secs]
 [Times: user=40.31 sys=0.03, real=28.62 secs]
Heap after GC invocations=249 (full 12):
 garbage-first heap   total 31457280K, used 7507920K [0x00007fcb22800000, 0x00007fd2a2800000, 0x00007fd2a2800000)
  region size 8192K, 0 young (0K), 0 survivors (0K)
 compacting perm gen  total 524288K, used 152608K [0x00007fd2a2800000, 0x00007fd2c2800000, 0x00007fd2c2800000)
   the space 524288K,  29% used [0x00007fd2a2800000, 0x00007fd2abd082e8, 0x00007fd2abd08400, 0x00007fd2c2800000)
No shared spaces configured.
}

{Heap before GC invocations=399 (full 19):
 garbage-first heap   total 31457280K, used 13016093K [0x00007fcb22800000, 0x00007fd2a2800000, 0x00007fd2a2800000)
  region size 8192K, 54 young (442368K), 54 survivors (442368K)
 compacting perm gen  total 524288K, used 155475K [0x00007fd2a2800000, 0x00007fd2c2800000, 0x00007fd2c2800000)
   the space 524288K,  29% used [0x00007fd2a2800000, 0x00007fd2abfd4c70, 0x00007fd2abfd4e00, 0x00007fd2c2800000)
No shared spaces configured.
2013-01-14T15:31:36.484+0200: 32191.056: [Full GC 12711M->7543M(30720M), 29.5013210 secs]
 [Times: user=41.39 sys=0.06, real=29.50 secs]
Heap after GC invocations=400 (full 20):
 garbage-first heap   total 31457280K, used 7724994K [0x00007fcb22800000, 0x00007fd2a2800000, 0x00007fd2a2800000)
  region size 8192K, 0 young (0K), 0 survivors (0K)
 compacting perm gen  total 524288K, used 155475K [0x00007fd2a2800000, 0x00007fd2c2800000, 0x00007fd2c2800000)
   the space 524288K,  29% used [0x00007fd2a2800000, 0x00007fd2abfd4c70, 0x00007fd2abfd4e00, 0x00007fd2c2800000)
No shared spaces configured.
}

{Heap before GC invocations=476 (full 26):
 garbage-first heap   total 31457280K, used 14622246K [0x00007fcb22800000, 0x00007fd2a2800000, 0x00007fd2a2800000)
  region size 8192K, 27 young (221184K), 27 survivors (221184K)
 compacting perm gen  total 524288K, used 156716K [0x00007fd2a2800000, 0x00007fd2c2800000, 0x00007fd2c2800000)
   the space 524288K,  29% used [0x00007fd2a2800000, 0x00007fd2ac10b2b0, 0x00007fd2ac10b400, 0x00007fd2c2800000)
No shared spaces configured.
2013-01-14T18:46:41.545+0200: 43896.117: [Full GC 14279M->8107M(30720M), 31.6936770 secs]
 [Times: user=44.40 sys=0.18, real=31.69 secs]
Heap after GC invocations=477 (full 27):
 garbage-first heap   total 31457280K, used 8302054K [0x00007fcb22800000, 0x00007fd2a2800000, 0x00007fd2a2800000)
  region size 8192K, 0 young (0K), 0 survivors (0K)
 compacting perm gen  total 524288K, used 156551K [0x00007fd2a2800000, 0x00007fd2c2800000, 0x00007fd2c2800000)
   the space 524288K,  29% used [0x00007fd2a2800000, 0x00007fd2ac0e1fa0, 0x00007fd2ac0e2000, 0x00007fd2c2800000)
No shared spaces configured.
}

{Heap before GC invocations=522 (full 34):
 garbage-first heap   total 31457280K, used 16096219K [0x00007fcb22800000, 0x00007fd2a2800000, 0x00007fd2a2800000)
  region size 8192K, 30 young (245760K), 30 survivors (245760K)
 compacting perm gen  total 524288K, used 156869K [0x00007fd2a2800000, 0x00007fd2c2800000, 0x00007fd2c2800000)
   the space 524288K,  29% used [0x00007fd2a2800000, 0x00007fd2ac1315d8, 0x00007fd2ac131600, 0x00007fd2c2800000)
No shared spaces configured.
2013-01-14T22:31:40.711+0200: 57395.283: [Full GC 15718M->11933M(30720M), 42.0857250 secs]
 [Times: user=60.13 sys=0.07, real=42.08 secs]
Heap after GC invocations=523 (full 35):
 garbage-first heap   total 31457280K, used 12219927K [0x00007fcb22800000, 0x00007fd2a2800000, 0x00007fd2a2800000)
  region size 8192K, 0 young (0K), 0 survivors (0K)
 compacting perm gen  total 524288K, used 156869K [0x00007fd2a2800000, 0x00007fd2c2800000, 0x00007fd2c2800000)
   the space 524288K,  29% used [0x00007fd2a2800000, 0x00007fd2ac1315d8, 0x00007fd2ac131600, 0x00007fd2c2800000)
No shared spaces configured.
}

其他类似问题报告:

http://grokbase.com/t/openjdk/hotspot-gc-use/1192sy84j5/g1c-strange-full-gc-behaviorhttp://grokbase.com/p/openjdk/hotspot-gc-use/123ydf9c92/puzzling-why-is-a-full-gc-triggered-herehttp://mail.openjdk.java.net/pipermail/hotspot-gc-use/2013-February/001484.html

我一直在使用appdynamics profiler分析这个问题,我发现每次发生完全GC时,代码缓存(配置为最大值)都已满。这似乎是GC中的一个错误。

另请参阅分析器图像,两个不必要的Full GC: s位于24/5和25/5之间。更重要的是,它们会扼杀服务器可用性,因为它们每个持续60秒:

Profiler日志图像http://eisler.vps.kotisivut.com/logs/g1gc-code-cache-full-gc-bug-illustration.png

另见关于Azul的无停顿GC的讨论,他们似乎已经解决了这类问题http://www.artima.com/lejava/articles/azul_pauseless_gc.html

共有2个答案

宋宏毅
2023-03-14

我们在1.7._u06上记录了这个错误,并升级到1.7.0_21-b11就在几天前,自升级以来,我们还没有看到任何Full GC,所以似乎这个错误在JVM中得到了修复。代码缓存内存配置文件现在看起来好多了在分析器中也是如此。在过去,这个问题曾经是一个日常问题,每天一到多次。

如果情况发生变化,我会向你汇报。在那之前,我认为升级解决了这个问题。

广昊昊
2023-03-14

请参阅我在G1GC中的回复,带有初始标记的长暂停

你的每一个环境都应该有一个坚实的理由来这里。。。不幸的是,其中一些没有,例如,-XX:UseBiasedLocking(用于长期和年轻一代GCs的组合,但G1GC能够处理这两种情况)-XX:DisableExplicitGC(根据我的经验,它是不可预测的,从不限制显式gc调用

请相应地使用/调整下面提到的设置以获得最佳结果,我将为您提供前进的基线,希望这些设置对您有用:生产中的Java G1垃圾收集

 类似资料:
  • 问题内容: 如果您在Python 3.7中执行以下语句,它将(根据我的测试)打印: 但是,计算结果为。 当然,计算结果为,并计算结果为。 我最初是在测试函数的返回值时发现此问题的,但是在第二种情况下却未返回任何内容-因此,该函数返回了。 这里发生了什么? 问题答案: 这是一个很好的例子,说明为什么不应该直接使用这些方法,因为它们通常不是等效操作符的适当替代;您应该使用运算符来代替相等性比较,或者在

  • 本文向大家介绍GC是什么? 为什么要有GC?相关面试题,主要包含被问及GC是什么? 为什么要有GC?时的应答技巧和注意事项,需要的朋友参考一下 答 GC(Garbage Collection) GC是垃圾收集器。程序员不用担心内存管理,因为垃圾收集器会自动进行管理。要请求垃圾收集,可以调用下面的方法之一: 当程序需要更多的堆空间时,GC需要进行垃圾清理工作,暂停所有线程,找出所有无被引用的对象,进

  • JRockit(1.6)有一个名为gcTrigger的选项。默认情况下,当旧发电机充满时,会触发完全gc。gc触发器选项允许您在完全gc填充之前(或者在触发完全gc时)触发它。 我想知道Sun JDK(1.6)是否有类似的选项。到目前为止,我还没有找到一个。 更新:我不是指手动gc!我指的是一个模仿JRockit中gcTrigger行为的选项

  • 问题内容: 我的活动课在这里: 和相机预览类在这里: 但是,当我测试该类时,似乎首先调用onResume(),然后在1或2秒后再次调用。因此,相机必须再次刷新。如果我根本没有onResume(),则摄像头预览稳定,但是如果我从主屏幕或其他某个应用再次切换到该应用,则会崩溃。我发现onPause()不会影响任何一个。我的代码正确吗?我应该添加/删除哪些内容以使其不会再次刷新并且在应用切换后仍然不会崩

  • 我在JDK8中设置了-XX: LaunatingHeap占领百分比=70(没有自适应IHOP功能),但是我发现当Heap占领百分比远小于70%时,JVM开始时有两个初始标记阶段,是否有其他因素会触发G1 GC初始标记阶段?提前谢谢! GC日志摘录: 2020-01-22T03:58:14.227 0000: 3.158:[GC暂停(元数据GC阈值)(年轻)(初始标记),0.1583711 ses]

  • 问题内容: 我正在使用JDBC连接到MySQL服务器(我认为没有连接池)。在连接网址中,我有 但是我的连接仍然超时。我什至检查了它的错误。但是,当我尝试使用连接时,出现以下异常。 我知道在Java 1.6中可以使用它来检查连接,但是我正在使用Java 1.5 有没有办法确保它不会超时?还是我必须升级到Java 1.6? 问题答案: 我有同样的问题,这绝对令人发疯。这是文档在MySQL网站上的内容(