diff options
author | Eileen M. Uchitelle <[email protected]> | 2025-03-17 10:42:48 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2025-03-17 10:42:48 -0400 |
commit | c85dffeee2f1899e0db3bde6a4fb49bc90c90ec2 (patch) | |
tree | 5545ed4f48598c820c70b4bf709bb45273367b7c /iseq.c | |
parent | 8d6f153fba8ce48a8e31cb22a9c9222bbb1832f6 (diff) |
Avoid pinning `storage_head` in `iseq_mark_and_move` (#12880)
* Avoid pinning `storage_head` in `iseq_mark_and_move`
This refactor changes the behavior of `iseq_mark_and_move` to avoid
pinning the `storage_head`. Previously pinning was required because they
could be gc'd during `iseq_set_sequence` it would be possible to end
up with a half build array of instructions. However, in order to
implement a moving immix algorithm we can't pin these objects so this
rafactoring changes the code to mark and move. To accomplish this, it was
required to add `iseq_size`, `iseq_encoded`, and the `mark_bits` union
to the `iseq_compile_data` struct. In addition `iseq_compile_data` sets
a bool for whether there is a single or list of mark bits. While this
change is needed for moving immix, it should be better for Ruby's GC
as well.
* Don't allocate mark_offset_bits for one word
If only one word is needed, we don't need to allocate mark_offset_bits
and can instead directly write to it.
---------
Co-authored-by: Peter Zhu <[email protected]>
Notes
Notes:
Merged-By: eileencodes <[email protected]>
Diffstat (limited to 'iseq.c')
-rw-r--r-- | iseq.c | 45 |
1 files changed, 30 insertions, 15 deletions
@@ -232,7 +232,30 @@ iseq_scan_bits(unsigned int page, iseq_bits_t bits, VALUE *code, VALUE *original } static void -rb_iseq_mark_and_move_each_value(const rb_iseq_t *iseq, VALUE *original_iseq) +rb_iseq_mark_and_move_each_compile_data_value(const rb_iseq_t *iseq, VALUE *original_iseq) +{ + unsigned int size; + VALUE *code; + const struct iseq_compile_data *const compile_data = ISEQ_COMPILE_DATA(iseq); + + size = compile_data->iseq_size; + code = compile_data->iseq_encoded; + + // Embedded VALUEs + if (compile_data->mark_bits.list) { + if(compile_data->is_single_mark_bit) { + iseq_scan_bits(0, compile_data->mark_bits.single, code, original_iseq); + } + else { + for (unsigned int i = 0; i < ISEQ_MBITS_BUFLEN(size); i++) { + iseq_bits_t bits = compile_data->mark_bits.list[i]; + iseq_scan_bits(i, bits, code, original_iseq); + } + } + } +} +static void +rb_iseq_mark_and_move_each_body_value(const rb_iseq_t *iseq, VALUE *original_iseq) { unsigned int size; VALUE *code; @@ -280,11 +303,9 @@ rb_iseq_mark_and_move_each_value(const rb_iseq_t *iseq, VALUE *original_iseq) iseq_scan_bits(0, body->mark_bits.single, code, original_iseq); } else { - if (body->mark_bits.list) { - for (unsigned int i = 0; i < ISEQ_MBITS_BUFLEN(size); i++) { - iseq_bits_t bits = body->mark_bits.list[i]; - iseq_scan_bits(i, bits, code, original_iseq); - } + for (unsigned int i = 0; i < ISEQ_MBITS_BUFLEN(size); i++) { + iseq_bits_t bits = body->mark_bits.list[i]; + iseq_scan_bits(i, bits, code, original_iseq); } } } @@ -327,7 +348,7 @@ rb_iseq_mark_and_move(rb_iseq_t *iseq, bool reference_updating) if (ISEQ_BODY(iseq)) { struct rb_iseq_constant_body *body = ISEQ_BODY(iseq); - rb_iseq_mark_and_move_each_value(iseq, reference_updating ? ISEQ_ORIGINAL_ISEQ(iseq) : NULL); + rb_iseq_mark_and_move_each_body_value(iseq, reference_updating ? ISEQ_ORIGINAL_ISEQ(iseq) : NULL); rb_gc_mark_and_move(&body->variable.coverage); rb_gc_mark_and_move(&body->variable.pc2branchindex); @@ -394,14 +415,8 @@ rb_iseq_mark_and_move(rb_iseq_t *iseq, bool reference_updating) else if (FL_TEST_RAW((VALUE)iseq, ISEQ_USE_COMPILE_DATA)) { const struct iseq_compile_data *const compile_data = ISEQ_COMPILE_DATA(iseq); - if (!reference_updating) { - /* The operands in each instruction needs to be pinned because - * if auto-compaction runs in iseq_set_sequence, then the objects - * could exist on the generated_iseq buffer, which would not be - * reference updated which can lead to T_MOVED (and subsequently - * T_NONE) objects on the iseq. */ - rb_iseq_mark_and_pin_insn_storage(compile_data->insn.storage_head); - } + rb_iseq_mark_and_move_insn_storage(compile_data->insn.storage_head); + rb_iseq_mark_and_move_each_compile_data_value(iseq, reference_updating ? ISEQ_ORIGINAL_ISEQ(iseq) : NULL); rb_gc_mark_and_move((VALUE *)&compile_data->err_info); rb_gc_mark_and_move((VALUE *)&compile_data->catch_table_ary); |