Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

What paragc is

paragc is a tracing garbage collector for Rust programs that share one heap across many threads.

  • Objects live in 32 KiB blocks cut into 256-byte lines, the layout of Immix (Blackburn & McKinley, 2008).
  • Threads bump-allocate into free lines on their own.
  • A collection marks and sweeps on every core.

What sets it apart

Many mutatorsHeap::mutate(&self) runs on any number of threads at once. Each thread allocates from its own buffer (Tlab) and claims whole blocks with one atomic operation.
Exclusive by borrowingHeap::collect(&mut self) cannot overlap a mutate, because the borrow checker forbids it. That borrow is the stop-the-world: there is no safepoint protocol and no lock.
Concurrent markingHeap::mark_concurrently(&self) marks while mutators keep running. A snapshot-at-the-beginning barrier on Slot writes keeps it correct, and new objects are allocated black.
Concurrent sweepingHeap::finish_marking only finishes marking. Mutators sweep a block themselves when they need one, and sweep_concurrently sweeps the rest on the pool.
EvacuationA stop-the-world collection copies live objects out of sparse blocks while it marks (Immix defragmentation).
Young collectionscollect_young traces only objects allocated since the last collection and compacts the survivors.
Reference countingOld objects carry a small count, settled at young collections and released in the background (the LXR design). Full tracing only runs every few rounds, for cycles.
Weak referencesWeak<B> does not keep its target alive; every kind of collection clears or moves it.
References between heapsFar points straight from one private heap into another; collect_group reclaims cycles across them.
Cross-heap (Linux)A CrossHeap lives in a shared-memory file. Several processes map it and use it at once, a killed process never blocks the others, and objects can be signed and found from another process.

Where it is used

paragc is the heap of the j8 JavaScript engine. In j8:

  • every JS object, string and closure is a paragc object;
  • one isolate owns one Heap;
  • with the crossheap feature, the isolate attaches a cross-heap as its old generation. JS values that survive a turn are promoted there, so another process can read them by signature.

What it is not

  • Not a conservative collector. paragc does not scan stacks. Every object that must survive a collection is reachable from a Root. Inside a mutate, Gc handles are safe because no collection can run.
  • Not no_std. It needs threads, mmap and atomics from std.
  • Not a drop-in Rc replacement. Objects are reached through branded handles. Types implement Trace (usually with #[derive(Trace)]), and a type with Gc fields must not implement Drop.