Skip to content

Commit 1986d77

Browse files
committed
symbol.c: use rb_gc_mark_and_move over rb_gc_location
The `p->field = rb_gc_location(p->field)` isn't ideal because it means all references are rewritten on compaction, regardless of whether the referenced object has moved. This isn't good for caches nor for Copy-on-Write. `rb_gc_mark_and_move` avoid needless writes, and most of the time allow to have a single function for both marking and updating references.
1 parent 5bcfc53 commit 1986d77

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,7 +3028,7 @@ rb_gc_mark_roots(void *objspace, const char **categoryp)
30283028
mark_current_machine_context(ec);
30293029

30303030
MARK_CHECKPOINT("global_symbols");
3031-
rb_sym_global_symbols_mark();
3031+
rb_sym_global_symbols_mark_and_move();
30323032

30333033
MARK_CHECKPOINT("finish");
30343034

@@ -4045,7 +4045,7 @@ rb_gc_update_vm_references(void *objspace)
40454045

40464046
rb_vm_update_references(vm);
40474047
rb_gc_update_global_tbl();
4048-
rb_sym_global_symbols_update_references();
4048+
rb_sym_global_symbols_mark_and_move();
40494049

40504050
#if USE_YJIT
40514051
void rb_yjit_root_update_references(void); // in Rust

internal/symbol.h

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

1919
/* symbol.c */
20-
void rb_sym_global_symbols_mark(void);
21-
void rb_sym_global_symbols_update_references(void);
20+
void rb_sym_global_symbols_mark_and_move(void);
2221
VALUE rb_to_symbol_type(VALUE obj);
2322
VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc);
2423
VALUE rb_sym_intern_ascii(const char *ptr, long len);

symbol.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -371,21 +371,12 @@ Init_sym(void)
371371
}
372372

373373
void
374-
rb_sym_global_symbols_mark(void)
374+
rb_sym_global_symbols_mark_and_move(void)
375375
{
376376
rb_symbols_t *symbols = &ruby_global_symbols;
377377

378-
rb_gc_mark_movable(symbols->sym_set);
379-
rb_gc_mark_movable(symbols->ids);
380-
}
381-
382-
void
383-
rb_sym_global_symbols_update_references(void)
384-
{
385-
rb_symbols_t *symbols = &ruby_global_symbols;
386-
387-
symbols->sym_set = rb_gc_location(symbols->sym_set);
388-
symbols->ids = rb_gc_location(symbols->ids);
378+
rb_gc_mark_and_move(&symbols->sym_set);
379+
rb_gc_mark_and_move(&symbols->ids);
389380
}
390381

391382
static int

0 commit comments

Comments
 (0)