mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 05:29:10 +02:00
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.
This commit is contained in:
parent
5bcfc53d6f
commit
1986d775cd
3 changed files with 6 additions and 16 deletions
4
gc.c
4
gc.c
|
@ -3028,7 +3028,7 @@ rb_gc_mark_roots(void *objspace, const char **categoryp)
|
|||
mark_current_machine_context(ec);
|
||||
|
||||
MARK_CHECKPOINT("global_symbols");
|
||||
rb_sym_global_symbols_mark();
|
||||
rb_sym_global_symbols_mark_and_move();
|
||||
|
||||
MARK_CHECKPOINT("finish");
|
||||
|
||||
|
@ -4045,7 +4045,7 @@ rb_gc_update_vm_references(void *objspace)
|
|||
|
||||
rb_vm_update_references(vm);
|
||||
rb_gc_update_global_tbl();
|
||||
rb_sym_global_symbols_update_references();
|
||||
rb_sym_global_symbols_mark_and_move();
|
||||
|
||||
#if USE_YJIT
|
||||
void rb_yjit_root_update_references(void); // in Rust
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
#endif
|
||||
|
||||
/* symbol.c */
|
||||
void rb_sym_global_symbols_mark(void);
|
||||
void rb_sym_global_symbols_update_references(void);
|
||||
void rb_sym_global_symbols_mark_and_move(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);
|
||||
|
|
15
symbol.c
15
symbol.c
|
@ -371,21 +371,12 @@ Init_sym(void)
|
|||
}
|
||||
|
||||
void
|
||||
rb_sym_global_symbols_mark(void)
|
||||
rb_sym_global_symbols_mark_and_move(void)
|
||||
{
|
||||
rb_symbols_t *symbols = &ruby_global_symbols;
|
||||
|
||||
rb_gc_mark_movable(symbols->sym_set);
|
||||
rb_gc_mark_movable(symbols->ids);
|
||||
}
|
||||
|
||||
void
|
||||
rb_sym_global_symbols_update_references(void)
|
||||
{
|
||||
rb_symbols_t *symbols = &ruby_global_symbols;
|
||||
|
||||
symbols->sym_set = rb_gc_location(symbols->sym_set);
|
||||
symbols->ids = rb_gc_location(symbols->ids);
|
||||
rb_gc_mark_and_move(&symbols->sym_set);
|
||||
rb_gc_mark_and_move(&symbols->ids);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue