Skip to content

Fix race condition when concurrently moving objects

Yorick Peterse requested to merge gc-bug-issue-148 into master

This fixes the race condition described in #148 (closed). From the last commit in this MR:

When promoting or evacuating an object, ObjectPointer::status() would only return Promote/Evacuate for the first caller, returning OK for all following calls. This could lead to a race condition where multiple threads try to process a pointer to the same object that has to be moved. In this case, one thread would win, and the other one(s) would lose. All threads that lose would then simply mark the object and move on, without resolving a forwarding pointer produced by the winning thread. This could then lead to pointers being used that still point to moved objects.

To resolve this, ObjectPointer::status() now returns a "PendingMove" status whenever a thread witnesses an object that has to be moved but is already being moved by another thread. As long as this status is observed, the pointer is rescheduled for marking. This allows the thread to continue marking other objects, instead of having to spin for an undetermined amount of time.

Merge request reports