Skip to content

Commit 24a1b09

Browse files
committed
Don't use obj_id in Box classext_cow_classes
Using obj_id in classext_cow_classes is slow and also is a problem when freeing classes because the lookup requires the EC, which is not available if it is running on a GC thread. This will cause it to crash on MMTk. We don't need to use the obj_id as the key in the classext_cow_classes st_table because the class itself is pinned and won't move so we can use it as the key instead.
1 parent da9e384 commit 24a1b09

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

box.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ rb_box_entry_mark(void *ptr)
234234
rb_gc_mark(box->ruby_dln_libmap);
235235
rb_gc_mark(box->gvar_tbl);
236236
if (box->classext_cow_classes) {
237-
rb_mark_tbl(box->classext_cow_classes);
237+
rb_mark_set(box->classext_cow_classes);
238238
}
239239
}
240240

@@ -271,10 +271,10 @@ free_box_st_tables(void *ptr)
271271
}
272272

273273
static int
274-
free_classext_for_box(st_data_t _key, st_data_t obj_value, st_data_t box_arg)
274+
free_classext_for_box(st_data_t key, st_data_t _value, st_data_t box_arg)
275275
{
276276
rb_classext_t *ext;
277-
VALUE obj = (VALUE)obj_value;
277+
VALUE obj = (VALUE)key;
278278
const rb_box_t *box = (const rb_box_t *)box_arg;
279279

280280
if (RB_TYPE_P(obj, T_CLASS) || RB_TYPE_P(obj, T_MODULE)) {

class.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ rb_class_unlink_classext(VALUE klass, const rb_box_t *box)
8989
{
9090
st_data_t ext;
9191
st_data_t key = (st_data_t)box->box_object;
92-
VALUE obj_id = rb_obj_id(klass);
93-
st_delete(box->classext_cow_classes, &obj_id, 0);
92+
st_delete(box->classext_cow_classes, &klass, 0);
9493
st_delete(RCLASS_CLASSEXT_TBL(klass), &key, &ext);
9594
return (rb_classext_t *)ext;
9695
}
@@ -203,7 +202,7 @@ rb_class_set_box_classext(VALUE obj, const rb_box_t *box, rb_classext_t *ext)
203202
// (e.g. st_insert below) that could trigger GC.
204203
rb_gc_writebarrier_remember(obj);
205204

206-
st_insert(box->classext_cow_classes, (st_data_t)rb_obj_id(obj), obj);
205+
st_insert(box->classext_cow_classes, (st_data_t)obj, 0);
207206
}
208207

209208
RUBY_EXTERN rb_serial_t ruby_vm_global_cvar_state;

0 commit comments

Comments
 (0)