Safepoints and Fil-C
Safepointing is an underappreciated aspect of modern multithreaded VM/GC tech. It forms the foundation of Fil-C's accurate stack scanning, safe signal handling, and safe forking. It also forms the foundation of accurate GC, debugging, and profiling in modern lots of other virtual machines (JVMs in particular). Perhaps most crucially:
Safepointing is the reason why multiple threads can race on the heap in Fil-C using non-atomic unordered instructions, under any widely used hardware memory model, without breaking the soundness guarantees of the garbage collector.
You can replace "Fil-C" with "Java" or most other GC-based languages that support threads and the same thing holds. Let's dig into what this magical technique does!
What Does Safepointing Do?
Safepointing is:
a lightweight synchronization mechanism that allows threads in a VM to make assumptions about the VM's state, and
a lightweight mechanism for threads executing in the VM to report their current state.
Let's dig into how safepointing works by considering just one of the many assumptions that we want the compiler to be able to make about how it interacts with the accurate garbage collector: we want to allow threads to assume that a pointer loaded from the heap will point to a live object even if that thread hasn't done anything to enable the GC's root scanning to find that pointer. Say that one thread does:
void* local_variable = object->field;
... continue reading