Skip to content

Commit 8d0416a

Browse files
committed
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.
1 parent 397bb7e commit 8d0416a

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

gc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,6 +2650,9 @@ rb_gc_mark_roots(void *objspace, const char **categoryp)
26502650
MARK_CHECKPOINT("machine_context");
26512651
mark_current_machine_context(ec);
26522652

2653+
MARK_CHECKPOINT("global_symbols");
2654+
rb_sym_global_symbols_mark();
2655+
26532656
MARK_CHECKPOINT("finish");
26542657

26552658
#undef MARK_CHECKPOINT

internal/symbol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#endif
1818

1919
/* symbol.c */
20+
void rb_sym_global_symbols_mark(void);
2021
VALUE rb_to_symbol_type(VALUE obj);
2122
VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc);
2223
VALUE rb_sym_intern_ascii(const char *ptr, long len);

symbol.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,24 @@ Init_sym(void)
9595

9696
VALUE dsym_fstrs = rb_ident_hash_new();
9797
symbols->dsymbol_fstr_hash = dsym_fstrs;
98-
rb_vm_register_global_object(dsym_fstrs);
9998
rb_obj_hide(dsym_fstrs);
10099

101100
symbols->str_sym = st_init_table_with_size(&symhash, 1000);
102101
symbols->ids = rb_ary_hidden_new(0);
103-
rb_vm_register_global_object(symbols->ids);
104102

105103
Init_op_tbl();
106104
Init_id();
107105
}
108106

107+
void
108+
rb_sym_global_symbols_mark(void)
109+
{
110+
rb_symbols_t *symbols = &ruby_global_symbols;
111+
112+
rb_gc_mark_movable(symbols->ids);
113+
rb_gc_mark_movable(symbols->dsymbol_fstr_hash);
114+
}
115+
109116
WARN_UNUSED_RESULT(static VALUE dsymbol_alloc(rb_symbols_t *symbols, const VALUE klass, const VALUE str, rb_encoding *const enc, const ID type));
110117
WARN_UNUSED_RESULT(static VALUE dsymbol_check(rb_symbols_t *symbols, const VALUE sym));
111118
WARN_UNUSED_RESULT(static ID lookup_str_id(VALUE str));

0 commit comments

Comments
 (0)