Slide 1

Slide 1 text

Understanding (a bit of) G1 GC Case Study: ETS Worker Miftah Fathudin Helmi Fitria Nugroho

Slide 2

Slide 2 text

Runtime arguments

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

G1GC (Garbage First Garbage Collector) is the low latency garbage collection algorithm included in recent versions of both OpenJDK and Oracle Java G1GC

Slide 7

Slide 7 text

GC Epoch

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Heap Types

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Tenure ● Consists of Working set + Humongous objects + fragmentation (Reclaimable and Un-reclaimable heap waste) ● Garbage-collected in batches during qualifying epochs

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Humongous Objects ● Humongous object size ≥ (G1HeapRegionSize/2) ● They’re allocated in contiguous regions of Free space ● They’re instantly added to Tenured

Slide 15

Slide 15 text

Minor GC Event Lifecycle

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

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())

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Conclusion ● Don’t just copy paste configs ● Load test not only throughput