mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
The registered_globals list made every Ractor's GC scan every slot under a shared lock. This commit splits it into per-Ractor lists. We also maintain a global registry that references every Ractor that has ever registered so that unregistering from a Ractor other than the one that registered can look up the owning list. When a Ractor is joined, the dead Ractor's slots are moved to the joining Ractor's heap before the objspace merge happens. This change tightens up the requirements for values stored in a registered address. Previously, Every Ractor's local GC scanned the shared list. So if a slot held an unshareable object living in a different Ractor's heap, that object was always kept alive regardless. After this change, only the registering Ractor's GC scans its list. So if a slot holds another Ractor's unshareable object, the owning Ractor's local GC cannot see that reference, so it can collect the object while the registered slot still points at it. Storing such an object was already a Ractor containment violation. It was just hidden by the shared scan. [Feature #22277]