A young-generation collector can miss a live object when an older object points to it. A remembered set preserves that cross-generation path without scanning the entire old generation. section 9.2.4
During V8's minor collection, the mechanism works as follows:
- A write barrier observes property assignments and checks whether the stored reference crosses from an old object to a young object. section 9.2.4
- The barrier records each relevant old-to-young reference in the remembered set. section 9.2.4
- The Scavenger traces from ordinary roots and the remembered set, then copies surviving young objects into to-space. section 9.2.2 section 9.2.4
- The bookkeeping makes assignments to long-lived objects slightly more expensive, with accumulated cost in mutation-heavy code. section 9.2.4
The hidden edge
Suppose an old-generation cache receives a newly allocated young object. Without a remembered set, the Scavenger ignores the cache and could classify that object as garbage. The write barrier records the cache-to-object edge, allowing the next scavenge to retain it. section 9.2.4
Figure 9.4 During a scavenge, V8 traces live objects in from-space and copies them into to-space. Dead objects are never visited. Once copying is complete, the semi-space labels swap: the old from-space is abandoned and the old to-space becomes the new from-space for future allocations.
Visualizes the Scavenger's copying process and shows where remembered-set references supplement ordinary roots. section 9.2.2
