Make ruby_global_symbols movable

The `ids` array and `dsymbol_fstr_hash` were pinned because they were
kept alive by rb_vm_register_global_object. This prevented the GC from
moving them even though there were reference updating code.

This commit changes it to be marked movable by marking it as a root object.
This commit is contained in:
Peter Zhu 2025-02-07 10:30:32 -05:00
parent 397bb7e42c
commit 8d0416ae0b
Notes: git 2025-02-10 13:48:02 +00:00
3 changed files with 13 additions and 2 deletions

3
gc.c
View File

@ -2650,6 +2650,9 @@ rb_gc_mark_roots(void *objspace, const char **categoryp)
MARK_CHECKPOINT("machine_context");
mark_current_machine_context(ec);
MARK_CHECKPOINT("global_symbols");
rb_sym_global_symbols_mark();
MARK_CHECKPOINT("finish");
#undef MARK_CHECKPOINT

View File

@ -17,6 +17,7 @@
#endif
/* symbol.c */
void rb_sym_global_symbols_mark(void);
VALUE rb_to_symbol_type(VALUE obj);
VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc);
VALUE rb_sym_intern_ascii(const char *ptr, long len);

View File

@ -95,17 +95,24 @@ Init_sym(void)
VALUE dsym_fstrs = rb_ident_hash_new();
symbols->dsymbol_fstr_hash = dsym_fstrs;
rb_vm_register_global_object(dsym_fstrs);
rb_obj_hide(dsym_fstrs);
symbols->str_sym = st_init_table_with_size(&symhash, 1000);
symbols->ids = rb_ary_hidden_new(0);
rb_vm_register_global_object(symbols->ids);
Init_op_tbl();
Init_id();
}
void
rb_sym_global_symbols_mark(void)
{
rb_symbols_t *symbols = &ruby_global_symbols;
rb_gc_mark_movable(symbols->ids);
rb_gc_mark_movable(symbols->dsymbol_fstr_hash);
}
WARN_UNUSED_RESULT(static VALUE dsymbol_alloc(rb_symbols_t *symbols, const VALUE klass, const VALUE str, rb_encoding *const enc, const ID type));
WARN_UNUSED_RESULT(static VALUE dsymbol_check(rb_symbols_t *symbols, const VALUE sym));
WARN_UNUSED_RESULT(static ID lookup_str_id(VALUE str));