tomoya yokota
May 26, 2018
2.8k

# introduction-to-modern-gc

Shenandoah GC・ZGC・Epsilon GCをざっくり理解したい！

JJUG CCC 2018 Spring での発表資料です

May 26, 2018

## Transcript

GC

4. ### GCͱΞϓϦఀࢭ(STW) Compaction GC Parallel GC young gc old gc GC

= ΞϓϦέʔγϣϯεϨουఀࢭ ϝϞϦ͕ϑϥάϝϯτ͠ͳ͍ CPUෛՙ͸খ͍͞ Stop The world = ΞϓϦέʔγϣϯεϨουͷఀࢭ Mark Compaction GC Noop
5. ### GCͱΞϓϦఀࢭ(STW) CMS GC Compaction GC young gc marking sweep GC

old gc initial-mark ﬁnal-remark young gc͸ΞϓϦέʔγϣϯεϨουఀࢭ major gc͸΄΅ฒྻ ϝϞϦͷϑϥάϝϯτ͕ܽ఺ Stop The world = ΞϓϦέʔγϣϯεϨουͷఀࢭ Concurrent = ΞϓϦέʔγϣϯεϨουͱฒྻ
6. ### GCͱΞϓϦఀࢭ(STW) G1GC Compaction GC young gc Marking old gc initial-mark

ﬁnal-remark young gc͸ΞϓϦέʔγϣϯεϨουఀࢭ major gc͸໨ඪఀࢭ࣌ؒΛݩʹGCΛߦ͏ ϝϞϦ͕ϑϥάϝϯτ͠ͳ͍ Stop The world = ΞϓϦέʔγϣϯεϨουͷఀࢭ Compaction GC Concurrent = ΞϓϦέʔγϣϯεϨουͱฒྻ
7. ### GCͱΞϓϦఀࢭ(STW) Parallel GC CMS GC G1GC young gc Concurrent mark

Concurrent sweep Mark Concurrent mark old gc Compaction GC Compaction GC Compaction GC Compaction GC Compaction GC Noop

10. ### ৽͍͠GCͷඞཁੑ • ڊେώʔϓΛ࢖͏ΞϓϦέʔγϣϯͷ୆಄  ElasticsearchͳͲ • ίϯύΫγϣϯܕGCͷఀࢭΛ΍Ί͍ͨ  Young GC / G1GCͷίϯύΫγϣϯ

• ώʔϓྖҬͷେ͖͞ͱGCͰͷఀࢭ͕࣌ؒൺྫ

14. ### ฒྻίϯύΫγϣϯͷ໰୊఺ Pointer x = 1 y = 2 z= 3

Pointer x = 1 y= 2 z= 3 GCεϨου͕Ҡಈத • GCεϨου͕ΦϒδΣΫτͷҠಈதʹ  ϦϑΝϨϯεͷॻ͖׵͕͑ى͖ΔՄೳੑ Ͳ͕ͬͪຊ෺ʁ
15. ### ΦϒδΣΫτͷϔομ͕ΩϞ Pointer Header ͜ΕΛղܾ͢ΔͨΊʹBrooks pointerΛಋೖ  ϙΠϯλ͕ࣗ෼Ҏ֎ͷϔομΛࢦ͍ͯ͠Δ৔߹  ͦͷઌͷΦϒδΣΫτΛࢀর͢Δ x = 1

y = 2 z = 3 Pointer Header x = 1 y= 2 z= 3 ຊ෺ ผͷ৔ॴʹ଴ආ
16. ### Brooks pointer Pointer Header x = 1 y = 2

z= 3 Pointer Header x = 1 y= 2 z= 3 ࢀরઌ͕ίϯύΫγϣϯ͞Εͨݹ͍ΦϒδΣΫτͳΒ ϔομʔΛͨͲͬͯɺ৽͍͠ΦϒδΣΫτΛࢀর͢Δ

࡟আ͞Εͨࢀর

world

ۭʹͳͬͨʂ
25. ### GCશମΛͳ͕ΊͯΈΔ Initial Mark Final Remark Concurrent Mark Concurrent Compaction update

Reference Concurrent update Reference ﬁnal update Reference Application work Application work Application work ฒྻίϯύΫγϣϯͷ͓͔͛Ͱ  ίϯύΫγϣϯ࣌ͷSTWΛͳͭͭ͘͠  ϑϥάϝϯτΛ๷͙͜ͱ͕Ͱ͖ΔΑ͏ʹͳͬͨ Stop the world

64bit ͷΈಈ࡞
28. ### Shenandoah GCͱࣅ͍ͯΔ • ίϯηϓτ͸ Shenandoah GCͱಉ͡  ੈ୅؅ཧͳ͠ɾϦʔδϣϯܕͷϝϞϦ؅ཧ  ฒྻίϯύΫγϣϯ • Linux

64 bit OSͰ͔͠ར༻Ͱ͖ͳ͍

30. ### ΧϥʔɾϙΠϯλ • ΦϒδΣΫτͷঢ়ଶΛΧϥʔͱͯ͠දݱ • ϚʔΫࡁ 0(marked0) ϚʔΫϑΣʔζʹ࢖͏ • ϚʔΫࡁ 1(marked1)

ޙͰৄ͘͠ • ΦϒδΣΫτ଴ආࡁ (remapped)
31. ### ΦϒδΣΫτͷΞυϨεදݱ 42 bit ࠷େ4TBͷΞυϨεΛදݱͰ͖Δ 4 1 17 bit ະ࢖༻ ΧϥʔϙΠϯλΛදݱ

1. 64bitͷΞυϨεۭؒશ෦࢖͏ 2. ώʔϓΞυϨε͸ԼҐ42bitΛར༻ 3. 4bitͰΧϥʔϙΠϯλͷ৭Λදݱ
32. ### 64bitΞυϨεΛ࠷େݶར༻ Heap(4TB) marked0 marked1 remapped 0x0000040000000000 0x0000000000000000 0x0000080000000000 0x00000C0000000000 0x0000100000000000

0x0000140000000000 0x000010001234abcdef 1. ΦϒδΣΫτ͸଴ආࡁΈ 2. 001234abcdefʹ࣮ମ ZGCͰ͸64bitͷΞυϨεΛ࢖͏.ϝϞϦ͕128TBඞཁ

world

࡟আ͞Εͨࢀর

world

Concurrent

42. ### GCશମΛͳ͕ΊͯΈΔ Initial Mark Final Remark Concurrent Mark Concurrent Compaction Application

work Application work
43. ### GCશମΛͳ͕ΊͯΈΔ ark Final Remark oncurrent Mark Concurrent Compaction pplication work

Application work Initial Mark Final Remark Concurrent Mark/Remap Concurrent Compaction Application work Application work GC1प໨ GC2प໨

45. ### Concurrent-Mark/Remap Root Region Region Region Region Concurrent ৽͘͠௥Ճ͞Εͨࢀর͸ΧϥʔϙΠϯλͷ ϑϥά͕ҧ͏ͷͰɺ ͰϚʔΫ͠ͳ͓͠

ϑΥϫʔσΟϯάɾςʔϒϧ ࢀর͕௥Ճ͞ΕͨͷͰ  ϚʔΫ͠௚͠

଴ආ

52. ### Epsilon GC • JVM։ൃ༻ͷGC • ύϑΥʔϚϯεଌఆ࣌ʹGCͰͷੑೳྼԽΛ  ഉআ͢ΔͨΊ • ώʔϓ͕ຒ·Δͱ OutOfMemoryError

• ຊ൪؀ڥͰ͸࢖Θͳ͍ͰͶ
53. ### ·ͱΊ • ڊେώʔϓɾଟίΞલఏΞϓϦέʔγϣϯ༻GC  ఀࢭ͕࣌ؒ໰୊ͳΒݕ౼ͷՁ஋͋Γ • Linux 64 bit OSͳΒ ZGC

• ͦΕҎ֎ͳΒ Shenandoah GC • Epsilon GC͸Կ΋͠ͳ͍GC