Skip to content

Commit

Permalink
Disable array and string re-embedding with MMTk.
Browse files Browse the repository at this point in the history
The current array-reembedding code does not forward the references in
the out-of-object buffer, and will result in dangling references.  And
the proper place to implement array or string re-embedding is in
`ObjectModel::copy` in the Rust part of the binding.  So we disable the
code path to re-embedding for now.
  • Loading branch information
wks committed Oct 9, 2024
1 parent f38ff71 commit fdd6b4e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ ary_heap_realloc(VALUE ary, size_t new_capa)
void
rb_ary_make_embedded(VALUE ary)
{
WHEN_USING_MMTK({
rb_bug("rb_ary_make_embedded should not be called when using MMTk.");
})

RUBY_ASSERT(rb_ary_embeddable_p(ary));
if (!ARY_EMBED_P(ary)) {
const VALUE *buf = ARY_HEAP_PTR(ary);
Expand Down
11 changes: 7 additions & 4 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3026,11 +3026,14 @@ gc_ref_update_array(void *objspace, VALUE v)
#endif
}

// MMTK: We don't do array re-embedding when using MMTK.
WHEN_NOT_USING_MMTK({
if (rb_gc_obj_slot_size(v) >= rb_ary_size_as_embedded(v)) {
if (rb_ary_embeddable_p(v)) {
rb_ary_make_embedded(v);
}
}
})
}

#if USE_MMTK
Expand Down Expand Up @@ -3432,12 +3435,10 @@ rb_gc_update_object_references(void *objspace, VALUE obj)

case T_STRING:
{
#if USE_MMTK
if (rb_mmtk_enabled_p()) {
WHEN_USING_MMTK({
rb_mmtk_gc_ref_update_string(objspace, obj);
break;
}
#endif
})

if (STR_SHARED_P(obj)) {
UPDATE_IF_MOVED(objspace, RSTRING(obj)->as.heap.aux.shared);
Expand All @@ -3447,6 +3448,8 @@ rb_gc_update_object_references(void *objspace, VALUE obj)
* slot it's been placed in, then re-embed it. */
if (rb_gc_obj_slot_size(obj) >= rb_str_size_as_embedded(obj)) {
if (!STR_EMBED_P(obj) && rb_str_reembeddable_p(obj)) {
// MMTk note: We don't re-embed strings when using MMTk.
// This statement is not reachable due to the `break;` in `WHEN_USING_MMTK` above.
rb_str_make_embedded(obj);
}
}
Expand Down
4 changes: 4 additions & 0 deletions string.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ rb_str_make_independent(VALUE str)
void
rb_str_make_embedded(VALUE str)
{
WHEN_USING_MMTK({
rb_bug("rb_str_make_embedded should not be called when using MMTk.");
})

RUBY_ASSERT(rb_str_reembeddable_p(str));
RUBY_ASSERT(!STR_EMBED_P(str));

Expand Down

0 comments on commit fdd6b4e

Please sign in to comment.