我注意到在我的应用程序中使用 G1 垃圾收集器偶尔会出现完整的 GC,并试图找出它们发生的原因。
从一个区域扫描开始到下一个区域的循环摘录如下。在 61807.406,记录了一个完整的 GC,然后是一个并发标记中止的条目。我想知道的是为什么 GC 觉得有必要进行一次完整的、停止世界的垃圾收集以及如何避免它。
请注意,这个问题之前似乎已经在 OpenJDK 邮件列表中提出过,但没有任何回复。
为简洁起见,我已经修剪了年轻 GC 的细节,但如果需要,我可以在某处发布完整的块。
61805.878: [GC concurrent-root-region-scan-start]
61805.882: [GC concurrent-root-region-scan-end, 0.0033586]
61805.882: [GC concurrent-mark-start]
61806.133: [GC pause (young), 0.02836202 secs]
[Eden: 498M(498M)->0B(478M) Survivors: 14M->34M Heap: 3025M(4096M)->2548M(4096M)]
[Times: user=0.19 sys=0.00, real=0.03 secs]
61806.426: [GC pause (young), 0.02766222 secs]
[Eden: 478M(478M)->0B(480M) Survivors: 34M->32M Heap: 3050M(4096M)->2576M(4096M)]
[Times: user=0.19 sys=0.00, real=0.03 secs]
61806.717: [GC pause (young), 0.02214895 secs]
[Eden: 480M(480M)->0B(502M) Survivors: 32M->10M Heap: 3056M(4096M)->2571M(4096M)]
[Times: user=0.09 sys=0.00, real=0.02 secs]
61807.000: [GC pause (young), 0.01899188 secs]
[Eden: 502M(502M)->0B(502M) Survivors: 10M->10M Heap: 3074M(4096M)->2573M(4096M)]
[Times: user=0.09 sys=0.00, real=0.02 secs]
61807.201: [GC pause (young), 0.02619259 secs]
[Eden: 162M(502M)->0B(500M) Survivors: 10M->12M Heap: 3036M(4096M)->2876M(4096M)]
[Times: user=0.11 sys=0.00, real=0.03 secs]
61807.283: [GC pause (young), 0.02068515 secs]
[Eden: 102M(500M)->0B(500M) Survivors: 12M->12M Heap: 3058M(4096M)->2957M(4096M)]
[Times: user=0.09 sys=0.00, real=0.02 secs]
61807.350: [GC pause (young), 0.01606520 secs]
[Eden: 52M(500M)->0B(498M) Survivors: 12M->14M Heap: 3020M(4096M)->2969M(4096M)]
[Times: user=0.11 sys=0.00, real=0.02 secs]
61807.389: [GC pause (young), 0.01573865 secs]
[Eden: 42M(498M)->0B(500M) Survivors: 14M->12M Heap: 3021M(4096M)->2978M(4096M)]
[Times: user=0.09 sys=0.00, real=0.02 secs]
61807.406: [Full GC 2978M->2498M(4096M), 4.8896638 secs]
[Times: user=6.37 sys=0.08, real=4.89 secs]
61812.296: [GC concurrent-mark-abort]
61812.542: [GC pause (young), 0.01526403 secs]
[Eden: 512M(500M)->0B(510M) Survivors: 0B->2048K Heap: 3018M(4096M)->2506M(4096M)]
[Times: user=0.09 sys=0.00, real=0.02 secs]
61812.793: [GC pause (young) (initial-mark), 0.01391544 secs]
[Eden: 510M(510M)->0B(508M) Survivors: 2048K->4096K Heap: 3016M(4096M)->2508M(4096M)]
[Times: user=0.09 sys=0.00, real=0.01 secs]
61812.807: [GC concurrent-root-region-scan-start]
这是使用 Java Hotspot 1.7.0_7 版本,具有以下有趣的设置:
-XX:PermSize=128m
-XX:MaxPermSize=128m
-XX:NewSize=512m
-XX:MaxNewSize=512m
-Xms4096m
-Xmx4096m
-XX:+UnlockDiagnosticVMOptions
-XX:+UnsyncloadClass
-XX:+UseTLAB
-XX:+UseG1GC
-XX:SurvivorRatio=10
-Xloggc:./workspace/gc.log
-verbose:gc
-XX:+PrintGC
-XX:+PrintGCTimeStamps
-XX:+PrintGCDetails