Fil-C on Nix

Filnix wiki

mbrock/filnix/nanofil

FUGC

Fil-C also garbage collector, collector, soft handshake, store barrier, free singleton

Upstream FUGC, safepoints, soft handshakes, fugc.c

FUGC, Fil's Unbelievable Garbage Collector, is what reclaims memory in Fil-C. It marks and sweeps on its own threads, in parallel, while the program runs, and never moves an object. It never stops the world: it asks each thread for work, such as scanning its stack, by a soft handshake, which the thread answers at its next pollcheck. While it marks, a store barrier marks the target of every pointer stored to the heap. It finds pointers exactly: on stacks through the roots the compiler keeps, and in objects only in their aux allocation.

  • free does not wait for it. Free empties the object's bounds and raises its free flag at once, so every later access through any pointer to it panics. FUGC then repoints every lower of the freed object at one shared free singleton and reclaims the memory. Use after free and double free are caught even after the memory is reused, and an object never freed is still reclaimed.

  • The model has one thread and no collector. What FUGC may do at a safepoint is stated as runtime axioms: no region changes (collector_live), so nothing the program can name is reclaimed (rooting, a lemma from it); no object moves (non_moving); and a free changes no byte (retention).