关于G1 GC中Mixed GC的分析

本文通过分析具体的GC日志,详细解读了G1垃圾收集器中的Mixed GC过程,指出Mixed GC不是一个单独的GC事件,而是一个从开始到满足特定条件结束的系列过程。在 Mixed GC 中,不仅年轻代会进行回收,老年代也会参与,而且在内存耗尽时可能导致长时间停顿。 Mixed GC 的触发条件包括eden区耗尽或堆内存达到阈值。分析揭示,每次GC结束后,老年代内存并不一定显著减少,且在Mixed GC运行期间,巨大对象的申请不会再次触发GC。
摘要由CSDN通过智能技术生成

关于G1的Mixed GC,网上所有的资料都千篇一律,说分为XX阶段,有的阶段STW,有的阶段并发。。。

但实际分析日志过程中,总觉得很难理解,Mixed GC到底是一个并发的过程,还是一次GC?

本文不打算总结G1的原理(这里这里这里 都有非常详细的GC原理说明),而是通过一次完整的日志分析,来宏观地理解Mixed GC的过程。

下面的例子中,堆内存20G。环境中,存在大量H-OBJ(巨大对象)的申请,用于分析Mixed GC非常合适。

【分析过程】

先看一段GC日志。

 5347275.209: [G1Ergonomics (Concurrent Cycles) request concurrent cycle initiation, reason: requested by GC cause, GC cause: G1 Humongous Allocation]
{Heap before GC invocations=15872 (full 0):
 garbage-first heap   total 20971520K, used 14601677K [0x00000002c0000000, 0x00000002c0805000, 0x00000007c0000000)
  region size 8192K, 761 young (6234112K), 16 survivors (131072K)
 Metaspace       used 317657K, capacity 368621K, committed 461500K, reserved 1443840K
  class space    used 36695K, capacity 50034K, committed 66556K, reserved 1048576K
↑↑↑↑↑↑  回收前的内存分布,总共使用了14601677K,年轻代 6234112K,老年代=14601677K-6234112K=8367565K ↑↑↑↑↑↑ 

 5347275.209: [G1Ergonomics (Concurrent Cycles) initiate concurrent cycle, reason: concurrent cycle initiation requested]
2018-06-04T21:30:42.445+0200: 5347275.210: [GC pause (G1 Humongous Allocation) (young) (initial-mark) 5347275.212: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 96649, predicted base time: 68.52 ms, remaining time: 131.48 ms, target pause time: 200.00 ms]
 5347275.212: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 745 regions, survivors: 16 regions, predicted young region time: 50.85 ms]
 5347275.212: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 745 regions, survivors: 16 regions, old: 0 regions, predicted pause time: 119.37 ms, target pause time: 200.00 ms]
, 0.4266532 secs]
   [Parallel Time: 321.3 ms, GC Workers: 23]
      [GC Worker Start (ms): Min: 5347275212.8, Avg: 5347275212.9, Max: 5347275213.0, Diff: 0.2]
      [Ext Root Scanning (ms): Min: 5.1, Avg: 5.8, Max: 14.9, Diff: 9.9, Sum: 132.6]
      [Update RS (ms): Min: 4.3, Avg: 13.7, Max: 16.1, Diff: 11.7, Sum: 315.5]
         [Processed Buffers: Min: 26, Avg: 38.7, Max: 57, Diff: 31, Sum: 889]
      [Scan RS (ms): Min: 25.4, Avg: 27.2, Max: 27.6, Diff: 2.2, Sum: 626.7]
      [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]
      [Object Copy (ms): Min: 272.3, Avg: 272.9, Max: 273.5, Diff: 1.2, Sum: 6275.8]
      [Termination (ms): Min: 0.0, Avg: 0.6, Max: 0.9, Diff: 0.9, Sum: 13.6]
         [Termination Attempts: Min: 1, Avg: 344.6, Max: 421, Diff: 420, Sum: 7925]
      [GC Worker Other (ms): Min: 0.0, Avg: 0.1, Max: 0.2, Diff: 0.2, Sum: 2.9]
      [GC Worker Total (ms): Min: 320.1, Avg: 320.3, Max: 320.5, Diff: 0.4, Sum: 7367.1]
      [GC Worker End (ms): Min: 5347275533.1, Avg: 5347275533.2, Max: 5347275533.3, Diff: 0.2]
   [Code Root Fixup: 0.0 ms]
   [Code Root Purge: 0.0 ms]
   [Clear CT: 1.1 ms]
   [Other: 104.1 ms]
      [Choose CSet: 0.0 ms]
      [Ref Proc: 95.5 ms]
      [Ref Enq: 0.2 ms]
      [Redirty Cards: 0.3 ms]
      [Humongous Register: 0.1 ms]
      [Humongous Reclaim: 3.0 ms]
      [Free CSet: 1.8 ms]
   [Eden: 5960.0M(11.9G)->0.0B(11.4G) Survivors: 128.0M->576.0M Heap: 13.9G(20.0G)->3942.4M(20.0G)]
Heap after GC invocations=15873 (full 0):
 garbage-first heap   total 20971520K, used 4037037K [0x00000002c0000000, 0x00000002c0805000, 0x00000007c0000000)
  region size 8192K, 72 young (589824K), 72 survivors (589824K)
 Metaspace       used 317657K, capacity 368621K, committed 461500K, reserved 1443840K
  class space    used 36695K, capacity 50034K, committ
  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值