码迷,mamicode.com
首页 > 其他好文 > 详细

G1 gabage collector notes

时间:2017-08-15 22:59:18      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:java   gabage collection   

Traditional: Eden Survivor 0 Survior 1   Old generation
G1:   Various size regions   (Free/Occupied)
Each region:  young(Eden or survivor)/old/humongous

Humongous object:
Object < 50% region size (normal allocation into eden)
Object >= 50% region size (humongous object, allocation into old generation directly)
Object > region size (allocation into contiguous regions into old generation, humongous region)

Collection set (candidate regions for GC)
Young collection set -> all young regions
Mix collection set -> all youn regions + a few candidate old regions based on "most garbage first" principle
Incremental compaction in G1 VS monolithic stop world for normal full GC

Remembered set:
tracking incoming reference
5% memory footprint overhead
tracking old-to-young references +  old-to-old references
more popular objects in remember set, it gets denser -> performance issue
Each old region has associated remember set, no need for young regions

Phases:
Young collection (stop the world)
Initial mark (stop the world)  triggered when initiating heap occupancy percent is reached
  -XX:InitiatingHeapOccupancyPercent (default 45%)
  -XX:ConcGCThreads=<n>

Root object scanning

Concurrent marking can be interrupted by young collection

Remark (stop the world)
Cleanup (stop the world)
Mixed collection

1.8.40  ClassUnloadingWithConcurrentMark  enabled by default
before 1.8.40 humongous objects are only collected during cleanup phase,  
after 1.8.40 humongous objects can be collected in young collection

Tuning options:
Mixed GC happens too frequently
Mixed GC pause too long  -> divide expensive collection further into smaller inexpensive collections


Strategy:
min number of old regions to include in the mixed collection set (-XX:G1MixedGcCountTarget=<n>)
max number of old regions to include in the mixed collection set (-XX:G1OldCSetRegionThresholdPercent=<p>)

Remove the expensive regions from mixed collection set
eliminate based on the liveness per old region    -XX:G1MixedGCLiveThresholdPercent = <p>  (default 85%)
eliminate expensive old regions towards the end of sorted array   -XX:G1HeapWastePercent = <p>  (default 5%)

Major contributor to GC pause:
ideally: copying live objects

others:

update remember set (problemetic)
other time (reference processing etc)

lots of long-lived humongous objects can cause evacuation failure
each humongous region can have 1 humongous object (wasted space)
promotion/evacuation failure can cause by fragmentation -> full GC


Prevent evacuation failure:

  • increase heap size

  • lower InitiatingHeapOccupancyPercent

  • increase marking threads

  • increase G1ReservePercent (make sure enough to space)


Always watch allocation rate/promotion rate and be aware of allocation spikes


https://www.youtube.com/watch?v=Io8hEdm6haw&list=PLy7t4z5SYNaRN2IDmjq_SSCrb9Sph4zAC&index=29



G1 gabage collector notes

标签:java   gabage collection   

原文地址:http://shadowisper.blog.51cto.com/3189863/1956415

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!