Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding (a bit of) G1 GC

Understanding (a bit of) G1 GC

KMKLabs

July 09, 2019
Tweet

More Decks by KMKLabs

Other Decks in Programming

Transcript

  1. Understanding (a bit of) G1 GC Case Study: ETS Worker

    Miftah Fathudin Helmi Fitria Nugroho
  2. G1GC (Garbage First Garbage Collector) is the low latency garbage

    collection algorithm included in recent versions of both OpenJDK and Oracle Java G1GC
  3. Generational collectors are based on the following statements both being

    mostly true: • Data that is very young will not survive long • Data that is old will continue to exist Generational Collector
  4. Eden • Consists of objects allocated since the current epoch

    started • Resized for each epoch to be between -XX:G1NewSizePercent (default 5) and -XX:G1MaxNewSizePercent (default 60) • All new objects are allocated in Eden, except Humongous objects • Empty at the beginning of each epoch
  5. Survivor • Survivor From consists of objects that have survived

    at least one epoch • Survivor To is allocated but empty during the epoch • Each object in survivor has a counter for the number of epochs survived • Objects surviving long enough get promoted to Tenured • Survivor To space is resized as a ratio (-XX:SurvivorRatio, default 8) of the current Eden size
  6. Tenure • Consists of Working set + Humongous objects +

    fragmentation (Reclaimable and Un-reclaimable heap waste) • Garbage-collected in batches during qualifying epochs
  7. Region • Region sizes are not changeable and must be

    a power of two between 1MB - 32MB, inclusive • If not explicitly set on the command line via -XX:G1HeapRegionSize=#m, the region size will be set such that there are the optimal 2k or more regions on startup
  8. Humongous Objects • Humongous object size ≥ (G1HeapRegionSize/2) • They’re

    allocated in contiguous regions of Free space • They’re instantly added to Tenured
  9. Triggers of GC Events • Eden full • Free space

    cannot accommodate a Humongous object • Humongous object allocated successfully and GC event conditions met • Externally initiated (jcmd, jmap, Runtime.gc())
  10. GC Event Types • Minor: Eden + Survivor From ->

    Survivor To • Mixed: Minor + (# reclaimable Tenured regions / -XX:G1MixedGCCountTarget) regions of Tenured • Full GC: All regions evacuated • Minor/Mixed + To-space exhaustion: Minor/Mixed + rollback + Full GC