Skip to content

Beskid GC specification (Go-style)

Beskid adopts a Go-style garbage collector:

  • Concurrent, precise, tri-color mark-and-sweep
  • Write barriers on pointer writes
  • Short STW pauses only for root scanning and phase transitions
  • Pacing similar to Go’s GOGC (heap growth vs CPU tradeoff)

This decision supersedes earlier alternatives (reference counting, conservative GC, region allocation).

  • Low latency with bounded STW pauses.
  • Precise pointer tracing (no conservative scanning).
  • Works with both JIT and AOT builds.
  • Heap objects carry type descriptors with pointer layout.
  • All allocations use runtime allocators that register metadata.
  • Stack frames have stack maps describing live pointer locations.
  • Stacks: precise stack maps emitted by compiler.
  • Globals: static roots registered at module init.
  • Registers: captured at safepoints.
  • White: unvisited
  • Gray: discovered, not scanned
  • Black: scanned

Mutator runs concurrently with GC. Write barriers prevent black objects from pointing to white ones during marking.

  • Insertion barrier (Dijkstra-style):
    • On pointer write, ensure the target is marked or gray.
  • Applied to:
    • pointer field stores
    • array element stores
    • captured pointer updates
  1. Sweep (concurrent)
    • Reclaim free spans.
  2. Off
    • Normal allocation.
  3. Mark (concurrent)
    • Root scan (short STW)
    • Concurrent marking
    • Mark termination (short STW)
  • Implicit at function calls and loop backedges.
  • Optional explicit safepoint calls inserted by lowering.
  • Default target similar to Go’s GOGC=100 (heap growth 100%).
  • Expose configuration via runtime env/flags.
  • Stack maps for each function.
  • Heap object descriptors for each type.
  • Write barrier insertion during CLIF lowering.

Previous runtime spec proposed multiple alternatives:

  • Reference counting: rejected (cycles + not Go-like).
  • Conservative GC: rejected (not precise, diverges from Go behavior).
  • Region allocator: rejected (no automatic memory reclaim).

All runtime docs must follow this GC decision.