Skip to content

Commit 746d7fe

Browse files
Fix moving old objects between Ractors
The FL_PROMOTED flag was not copied when moving objects, causing assertions to fail when an old object is moved: gc/default/default.c:834: Assertion Failed: RVALUE_AGE_SET:age <= RVALUE_OLD_AGE Co-Authored-By: Luke Gruber <luke.gruber@shopify.com>
1 parent 54bed7e commit 746d7fe

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

bootstraptest/test_ractor.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,3 +2422,18 @@ def fetch(key)
24222422
r1.take.sort
24232423
}
24242424
end
2425+
2426+
# Moving an old object
2427+
assert_equal 'ok', %q{
2428+
r = Ractor.new do
2429+
o = Ractor.receive
2430+
GC.start
2431+
o
2432+
end
2433+
2434+
o = "ok"
2435+
# Make o an old object
2436+
3.times { GC.start }
2437+
r.send(o, move: true)
2438+
r.take
2439+
}

ractor.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3678,9 +3678,11 @@ move_leave(VALUE obj, struct obj_traverse_replace_data *data)
36783678
rb_replace_generic_ivar(data->replacement, obj);
36793679
}
36803680

3681+
VALUE flags = T_OBJECT | FL_FREEZE | (RBASIC(obj)->flags & FL_PROMOTED);
3682+
36813683
// Avoid mutations using bind_call, etc.
36823684
MEMZERO((char *)obj + sizeof(struct RBasic), char, size - sizeof(struct RBasic));
3683-
RBASIC(obj)->flags = T_OBJECT | FL_FREEZE;
3685+
RBASIC(obj)->flags = flags;
36843686
RBASIC_SET_CLASS_RAW(obj, rb_cRactorMovedObject);
36853687
return traverse_cont;
36863688
}

0 commit comments

Comments
 (0)