Skip to content
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

Merged
merged 5 commits into from
Aug 12, 2021

Conversation

osa1
Copy link
Contributor

@osa1 osa1 commented Aug 12, 2021

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.

@osa1 osa1 requested review from ulan and crusso August 12, 2021 12:37
@dfinity-ci
Copy link

This PR does not affect the produced WebAssembly code.

Copy link
Contributor

@ulan ulan left a 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!

rts/motoko-rts/src/gc/mark_compact.rs Show resolved Hide resolved
@@ -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 {
Copy link
Contributor Author

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

Copy link
Contributor

@crusso crusso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch @ulan

@osa1 osa1 added the automerge-squash When ready, merge (using squash) label Aug 12, 2021
@mergify mergify bot merged commit 020b4e4 into master Aug 12, 2021
@mergify mergify bot deleted the osa1/compacting_gc_self_ref_bug branch August 12, 2021 13:50
@mergify mergify bot removed the automerge-squash When ready, merge (using squash) label Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants