Skip to content

Latest commit

 

History

History
79 lines (54 loc) · 2.27 KB

gc.md

File metadata and controls

79 lines (54 loc) · 2.27 KB

Golang Realtime GC

Other GC Algorithms `⸜( ◜࿁◝ )⸝︎︎

Concurrent Mark and Sweep (CMS):

  • Performs most marking concurrently with the application
  • Uses incremental updates to track new references
  • Reduces pause times but has higher overhead
  • More complex than the current implementation

Garbage First (G1) Collector:

  • Divides heap into equal-sized regions
  • Collects regions with most garbage first
  • Provides more predictable pause times
  • Would require significant restructuring of heap layout

ZGC (by Oracle):

  • Uses colored pointers
  • Performs concurrent operations without stop-the-world pauses
  • Scales well to large heaps
  • Very complex to implement in assembly

૮₍ • ᴥ • ₎ა gARM彡 WIP coming soon

Call init_gen_gc at program start This sets up three generation spaces:

  1. Eden (4MB) new allocations
  2. Survivor space (16MB) for young surviving objects
  3. Tenured space (44MB) for long-lived objects

Allocation:

Objects are initially allocated in eden space

ALLOC_STRING 32    // Allocate 32-byte string
ALLOC_ARRAY 100, 4 // Allocate array of 100 integers
  • UseGEN_ALLOC macro for basic allocation
  • Helper macros like ALLOC_STRING and ALLOC_ARRAY for specific types.

Root registration:

bl register_thread_roots  // Register current thread roots
  • Registers thread roots (stack, registers)
  • Registers global roots
  • GC tracks them to find live objects

Collection Triggers:

  • Minor GC happens automatically when eden fills
  • Objects surviving multiple minor GCs promote to tenured space
  • Full GC triggers when tenured space fills

Advantages

  • Fast allocation in eden space
  • Much faster minor collections since most objects die young
  • Age-based promotion policy (eden -> survivor -> tenured)
  • Better cache locality in the nursery
  • Reduced pause times as full collections are less frequent
  • Reduced write barrier overhead

(go back)

(back to top)