Safepoints and Fil-C
4 days ago
- #Garbage Collection
- #Multithreading
- #Virtual Machines
- Safepointing is a critical synchronization mechanism in multithreaded VM/GC technology, enabling accurate stack scanning, safe signal handling, and safe forking in Fil-C.
- It allows threads to race on the heap using non-atomic unordered instructions without breaking garbage collector soundness guarantees.
- Safepoints are specific points in code where threads can be safely preempted, ensuring the GC can accurately track pointers and manage memory.
- Fil-C inserts pollchecks at backward control flow edges to implement safepoints, bounding the execution between checks for GC synchronization.
- Pizderson frames are used in Fil-C to track pointers, mirroring them into frames for GC to scan during safepoints.
- The Fil-C GC uses soft handshakes for synchronization, avoiding global stop-the-world pauses and allowing threads to execute requested actions at safepoints.
- Native code handling involves explicit filc_enter and filc_exit calls to manage thread state during blocking system calls, ensuring GC progress.
- Safepoints also manage other GC-mutator races, including store barriers, weak load barriers, and thread-local caches.
- Fil-C leverages safepoints for safe signal handling, allowing signal handlers to run at well-defined points and allocate GC memory safely.
- Stop-the-world functionality via safepoints is used for fork(2) implementation and debugging, ensuring threads stop at known-good points.