Java GC

young generation and old generation. 1 eden and 2 survivor spaces.

minor GC, mark and copy, from eden and one survivor to the other survivor

full GC, mark, sweep and compact generations

both will stop the world.

- Serial GC, for small heap and single thread env

- Parallel GC, multiple thread to do GC, but stop application when do both minor GC and full GC. suitable for high throughput application due to the facts

  • all cores are cleaning garbage during collection
  • no cores are used for cleaning between collection cycles.

- CMS GC, low latency, but less throughput than parallel GC if it's cpu-bound application due to the fact that some CPU cores are cleaning garbage in most of time thus they are not working on application.

  • parallel mark-copy stop-the-world collection in young generation (minor GC)
  • mostly (two of phases stop the world) concurrent-mark-sweep in old generation (full GC)
  1. Initial Mark (STW), collecting all GC roots in old generation (direct GC roots or indirectly referenced from young generation)
  2. Concurrent Mark, marking all live objects (may not all of them due to application may mutate references at the same time) in old generation from the GC roots.
  3. Concurrent Preclean, accounting for references changed during previous marking phase. 
  4. Concurrent Abortable Preclean, offloading as much work as possible from the final mark phase
  5. Final remark (STW)
  6. Concurrent sweep
  7. Concurrent reset

collection in young generation may occur when concurrent collection happens in old generation.

drawbacks are fragmentation in old generation and non-predictable pause duration especially in large heap.

- G1 GC (collect regions with more garbage)

heap is divided into regions, including eden regions, survivor regions and old regions.

  • Young GC (STW, in parallel), coping to survivor regions or old regions
  • GC in old generation
  1. Initial Mark (STW), mark survivor regions (root regions), it's piggybacked on young GC
  2. Root Region Scanning, find references to old generation
  3. Concurrent Marking, find live objects over entire heap
  4. Remark (STW), complete the marking of live objects. (snapshot-at-the-beginning). empty regions are removed and reclaimed. region liveness is calculated for all regions.
  5. Cleanup/copying, selecting regions with lowest liveness to be collected at the same time as young GC.

reference: https://plumbr.io/handbook/garbage-collection-algorithms-implementations#concurrent-mark-and-sweep

http://www.oracle.com/technetwork/tutorials/tutorials-1876574.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值