New generation Java garbage collection tool: ZGC

JavaZGCZGC ZGCThe Z Garbage CollectorTBZGC JDK 11 JDK 15 Production ReadyZGC"Z"ZZGC ZFSZFSZFS Zettabyte File SystemJeff Bonwick Oracle ZGCZGC2018Oracle ZGC TB GC 10ms G1 15%202211Oracle ZGClive-set root-set TB 8MB-16TB ZGCZGC 10ms 2018 ZGCConcurrentTracing: CompactingSingle generation: Region-basedRegionNUMA-awareNUMANon-Uniform Memory AccessLoad barriersColored pointers2022 ZGCConcurrentRegion-basedRegionCompactingNUMA-awareNUMANon-Uniform Memory AccessUsing colored pointersUsing load barriers 2018 2022 ZGC Single generation G1G1 Region-based RegionRegionZGC G1ZGC Region-basedRegion-basedZGC G1ZGC Region :Small Region Region 2M 256KMedium Region Region 32M 256K 4MLarge Region Region: 2M 4MBCompactingCompacting ZGC CMSG1"-"NUMANUMANon-Uniform Memory Access CPU CPU CPUUniform Memory Access UMA CPU CPUNUMAUMANUMA ZGC NUMAColored pointersColored pointersJVMGC CMSG1 GC ZGC GC 64 JDK zGlobals_x86.cpp ZGC 31[0 ~ 41] 42-bits 4TB Java[42-45] 4-bits Metadata Bits Marked0Marked1RemappedFinalizable [46-63] 18-bits02[0 ~ 42] 43-bits 8TB Java[43-46] 4-bits Metadata Bits Marked0Marked1RemappedFinalizable [47-63] 17-bits03[0 ~ 43] 44-bits 16TB Java[44-47] 4-bits Metadata Bits Marked0Marked1RemappedFinalizable [48-63] 16-bits0 3 4-bits Marked0Marked1RemappedFinalizable 4Marked01-bitMarked11-bitRemapped1-bitFinalizable1-bitfinalizer Marked0Marked1RemappedZGC Marked0Marked1 RemappedZGC""GCGCLoad barriersLoad barriers JIT just-in-time compilation JVMjavaString n = person

JavaZGC

ZGC

ZGCThe Z Garbage CollectorTB
ZGC JDK 11 JDK 15 Production Ready

ZGC"Z"

ZZGC ZFSZFSZFS Zettabyte File SystemJeff Bonwick

Oracle ZGC

ZGC

2018Oracle ZGC

  1. TB
  2. GC 10ms
  3. G1 15%

202211Oracle ZGC

  1. live-set root-set
  2. TB 8MB-16TB

ZGCZGC 10ms

2018 ZGC

  • Concurrent
  • Tracing:
  • Compacting
  • Single generation:
  • Region-basedRegion
  • NUMA-awareNUMANon-Uniform Memory Access
  • Load barriers
  • Colored pointers

2022 ZGC

  • Concurrent
  • Region-basedRegion
  • Compacting
  • NUMA-awareNUMANon-Uniform Memory Access
  • Using colored pointers
  • Using load barriers

2018 2022 ZGC Single generation G1G1 Region-based RegionRegionZGC G1

ZGC

Region-based

Region-based

ZGC G1

ZGC Region :

  • Small Region Region 2M 256K
  • Medium Region Region 32M 256K 4M
  • Large Region Region: 2M 4MB

Compacting

Compacting

ZGC CMSG1"-"

NUMA

NUMANon-Uniform Memory Access

CPU CPU CPUUniform Memory Access UMA CPU CPU

NUMAUMA

NUMA ZGC NUMA

Colored pointers

Colored pointersJVMGC
CMSG1 GC ZGC GC 64 JDK zGlobals_x86.cpp ZGC 3

1

  • [0 ~ 41] 42-bits 4TB Java
  • [42-45] 4-bits Metadata Bits Marked0Marked1RemappedFinalizable
  • [46-63] 18-bits0

2

  • [0 ~ 42] 43-bits 8TB Java
  • [43-46] 4-bits Metadata Bits Marked0Marked1RemappedFinalizable
  • [47-63] 17-bits0

3

  • [0 ~ 43] 44-bits 16TB Java
  • [44-47] 4-bits Metadata Bits Marked0Marked1RemappedFinalizable
  • [48-63] 16-bits0

3 4-bits Marked0Marked1RemappedFinalizable 4

  • Marked01-bit
  • Marked11-bit
  • Remapped1-bit
  • Finalizable1-bitfinalizer

Marked0Marked1RemappedZGC Marked0Marked1 Remapped

ZGC""GCGC

Load barriers

Load barriers JIT just-in-time compilation JVM

javaString n = person.name; //     <Load barrier start>  if (n & bad_bit_mask) {  slow_path(register_for(n), address_of(person.name));  }  <Load barrier end>    String p = n ; //   n.isEmpty() ; //   int age = person.age; //   

JVM

textif (n & bad_bit_mask) {  slow_path(register_for(n), address_of(person.name));  }  

javamov 0x10(%rax), %rbx // String n = person.name;  test %rbx, 0x20(%r15) // Bad color?  jnz slow_path // Yes -> Enter slow path and  // mark/relocate/remap, adjust  // 0x10(%rax) and %rbx  

person n person.name n n good bad color n n person.name

""

""ZGC Page

Concurrent

Concurrent GC

MCSG1ZGC-ZGC-ZGC

  • ZGC Remapped
  • Marked0 Marked1
  • Remapped

obj1obj2obj3

ZGC

ZGC 6

ZGC 3 STWStop The World 3 STW ZGC STW 1ms

  • STW GC Root
  • GC region

  • STWJVMTIJFR
  • GC Root Set
  • GCGC

Marked0 Marked1

GC Marked GC
GC1 Marked0 GC Marked0 0101 = 0GC2 Marked11 Marked 1010 = 1

3

ZGC 8MB-16TB ZGC 16TB Java bit3

CMSG1GC ZGC GCGC ZGC

Supported Platforms

ZGC

ZGC 64


ZGC

shell-XX:+UseZGC -Xmx<size> -Xlog:gc  #   -XX:+UseZGC -Xmx<size> -Xlog:gc*  

ZGC JVM

  • -Xms -Xmx
  • -XX:ReservedCodeCacheSize -XX:InitialCodeCacheSizeCodeCache JITCodeCache64m128m
  • -XX:+UnlockExperimentalVMOptions -XX:+UseZGCZGC
  • -XX:ConcGCThreads12.5%8CPU1GCCPU
  • -XX:ParallelGCThreadsSTW60% -XX:ZCollectionIntervalZGC
  • -XX:ZAllocationSpikeToleranceZGC2ZGC
  • -XX:+UnlockDiagnosticVMOptions -XX:-ZProactive
  • -XlogGC

ZGC

ZGC JDK 11 JDK 15 Production Ready

JDK 16

......

ZGC JDK

ZGCGCGC

  • ZGCTB
  • ZGC STW
  • ZGCCMSG1
  • ZGC ShenandoahG1 Region
  • ZGC
  • ZGC
  • , jdk 8jdk 11 ParNew + CMS G1


Disclaimer: The content of this article is sourced from the internet. The copyright of the text, images, and other materials belongs to the original author. The platform reprints the materials for the purpose of conveying more information. The content of the article is for reference and learning only, and should not be used for commercial purposes. If it infringes on your legitimate rights and interests, please contact us promptly and we will handle it as soon as possible! We respect copyright and are committed to protecting it. Thank you for sharing.(Email:[email protected])