diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2025-08-07 14:43:18 +0200 |
|---|---|---|
| committer | Jean Boussier <jean.boussier@gmail.com> | 2025-08-07 21:00:00 +0200 |
| commit | 559d9e1f67cb6c19630b20b609af315ed7fdafca (patch) | |
| tree | 44e54eb73d50041112d7631b440c0d88bb01d6d6 /shape.c | |
| parent | bc9781c264b9e37c2482dba429b560436104a1f5 (diff) | |
Convert `VM/shape_tree` to use `rb_gc_mark_and_move`
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.
Diffstat (limited to 'shape.c')
| -rw-r--r-- | shape.c | 21 |
1 files changed, 4 insertions, 17 deletions
@@ -296,26 +296,13 @@ rb_shape_get_root_shape(void) } static void -shape_tree_mark(void *data) +shape_tree_mark_and_move(void *data) { rb_shape_t *cursor = rb_shape_get_root_shape(); rb_shape_t *end = RSHAPE(rb_shape_tree.next_shape_id - 1); while (cursor <= end) { if (cursor->edges && !SINGLE_CHILD_P(cursor->edges)) { - rb_gc_mark_movable(cursor->edges); - } - cursor++; - } -} - -static void -shape_tree_compact(void *data) -{ - rb_shape_t *cursor = rb_shape_get_root_shape(); - rb_shape_t *end = RSHAPE(rb_shape_tree.next_shape_id - 1); - while (cursor <= end) { - if (cursor->edges && !SINGLE_CHILD_P(cursor->edges)) { - cursor->edges = rb_gc_location(cursor->edges); + rb_gc_mark_and_move(&cursor->edges); } cursor++; } @@ -330,10 +317,10 @@ shape_tree_memsize(const void *data) static const rb_data_type_t shape_tree_type = { .wrap_struct_name = "VM/shape_tree", .function = { - .dmark = shape_tree_mark, + .dmark = shape_tree_mark_and_move, .dfree = NULL, // Nothing to free, done at VM exit in rb_shape_free_all, .dsize = shape_tree_memsize, - .dcompact = shape_tree_compact, + .dcompact = shape_tree_mark_and_move, }, .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED, }; |
