summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <[email protected]>2023-11-24 10:25:06 -0500
committerPeter Zhu <[email protected]>2023-11-24 13:29:04 -0500
commit269c705f93c4db631f4cad89991bc5d69a7dcd03 ()
treeab71fb98e0a7465aae04ff3a2338222c58a51104
parente201b81f79828c30500947fe8c8ea3c515e3d112 (diff)
Fix compaction for generic ivars
When generic instance variable has a shape, it is marked movable. If it it transitions to too complex, it needs to update references otherwise it may have incorrect references.
-rw-r--r--gc.c10
-rw-r--r--internal/gc.h2
-rw-r--r--internal/variable.h3
-rw-r--r--variable.c23
4 files changed, 32 insertions, 6 deletions
@@ -7255,7 +7255,7 @@ gc_mark_children(rb_objspace_t *objspace, VALUE obj)
gc_mark_set_parent(objspace, obj);
if (FL_TEST(obj, FL_EXIVAR)) {
- rb_mark_and_update_generic_ivar(obj);
}
switch (BUILTIN_TYPE(obj)) {
@@ -10249,6 +10249,12 @@ gc_ref_update_table_values_only(rb_objspace_t *objspace, st_table *tbl)
}
}
static void
gc_update_table_refs(rb_objspace_t * objspace, st_table *tbl)
{
@@ -10623,7 +10629,7 @@ gc_update_object_references(rb_objspace_t *objspace, VALUE obj)
gc_report(4, objspace, "update-refs: %p ->\n", (void *)obj);
if (FL_TEST(obj, FL_EXIVAR)) {
- rb_mark_and_update_generic_ivar(obj);
}
switch (BUILTIN_TYPE(obj)) {
@@ -250,6 +250,8 @@ void rb_gc_mark_and_move(VALUE *ptr);
void rb_gc_mark_weak(VALUE *ptr);
void rb_gc_remove_weak(VALUE parent_obj, VALUE *ptr);
#define rb_gc_mark_and_move_ptr(ptr) do { \
VALUE _obj = (VALUE)*(ptr); \
rb_gc_mark_and_move(&_obj); \
@@ -53,7 +53,8 @@ void rb_evict_ivars_to_hash(VALUE obj);
RUBY_SYMBOL_EXPORT_BEGIN
/* variable.c (export) */
-void rb_mark_and_update_generic_ivar(VALUE);
void rb_mv_generic_ivar(VALUE src, VALUE dst);
VALUE rb_const_missing(VALUE klass, VALUE name);
int rb_class_ivar_set(VALUE klass, ID vid, VALUE value);
@@ -1066,17 +1066,34 @@ gen_ivtbl_resize(struct gen_ivtbl *old, uint32_t n)
}
void
-rb_mark_and_update_generic_ivar(VALUE obj)
{
struct gen_ivtbl *ivtbl;
if (rb_gen_ivtbl_get(obj, 0, &ivtbl)) {
if (rb_shape_obj_too_complex(obj)) {
- rb_mark_tbl(ivtbl->as.complex.table);
}
else {
for (uint32_t i = 0; i < ivtbl->as.shape.numiv; i++) {
- rb_gc_mark_and_move(&ivtbl->as.shape.ivptr[i]);
}
}
}