-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix handling of self references in mark-compact GC, imrpove tests #2721
Conversation
This PR does not affect the produced WebAssembly code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks for fixing both the bug and the test!
@@ -211,7 +211,7 @@ unsafe fn update_refs<SetHp: Fn(u32)>(set_hp: SetHp, heap_base: u32) { | |||
/// Thread forwards pointers in object | |||
unsafe fn thread_fwd_pointers(obj: *mut Obj, heap_base: u32) { | |||
visit_pointer_fields(obj, obj.tag(), heap_base as usize, |field_addr| { | |||
if (*field_addr).unskew() > field_addr as usize { | |||
if (*field_addr).unskew() > obj as usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored for consistency with the comparison above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch @ulan
One line fix to thread self references during marking in mark-compact GC.
We had a test with self references but it accidentally passed. The problem was
none of the objects below the object with self reference were dead, so the
object was not moved, and as a result the field with the self reference had the
correct value even though we didn't update it.
The test is updated to add a dead object before the object with self ref. It
fails without the fix.
Test code is also updated to use a vector for the heap description, instead of
a map. This allows specifying object order in heap. With the previous HashMap
based implementation there is no way to reason about the object orders, so for
example the test with a backward pointer might or might not have a backward
pointer, depending on the HashMap (and hasher) implementation. With the vector
representation allocation is done in the same order as the test description,
allowing testing backward and forward pointers.
Thanks to @ulan for the catching the bug.