From 0b58059f15d8ec7bd9dbe1638a77b4a531b0df25 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 23 Jun 2022 16:02:42 -0700 Subject: Free bitmap buffer if it's not used If the iseqs don't have any objects in them that need marking, then immediately free the bitmap buffer --- compile.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index 8ebe6f33ad..074d157bf0 100644 --- a/compile.c +++ b/compile.c @@ -2340,6 +2340,7 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) int code_size = code_index; iseq_bits_t tmp[1] = {0}; + bool needs_bitmap = false; if (ISEQ_MBITS_BUFLEN(code_index) == 1) { mark_offset_bits = tmp; @@ -2397,6 +2398,7 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) ISEQ_MBITS_SET(mark_offset_bits, code_index + 1 + j); RB_OBJ_WRITTEN(iseq, Qundef, map); FL_SET(iseqv, ISEQ_MARKABLE_ISEQ); + needs_bitmap = true; break; } case TS_LINDEX: @@ -2413,6 +2415,7 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) RB_OBJ_WRITTEN(iseq, Qundef, v); ISEQ_MBITS_SET(mark_offset_bits, code_index + 1 + j); FL_SET(iseqv, ISEQ_MARKABLE_ISEQ); + needs_bitmap = true; } break; } @@ -2542,7 +2545,13 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) body->mark_bits.single = mark_offset_bits[0]; } else { - body->mark_bits.list = mark_offset_bits; + if (needs_bitmap) { + body->mark_bits.list = mark_offset_bits; + } + else { + body->mark_bits.list = 0; + ruby_xfree(mark_offset_bits); + } } /* get rid of memory leak when REALLOC failed */ @@ -11217,6 +11226,7 @@ ibf_load_code(const struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t bytecod else { mark_offset_bits = ZALLOC_N(iseq_bits_t, ISEQ_MBITS_BUFLEN(iseq_size)); } + bool needs_bitmap = false; unsigned int min_ic_index, min_ise_index, min_ivc_index; min_ic_index = min_ise_index = min_ivc_index = UINT_MAX; @@ -11243,6 +11253,7 @@ ibf_load_code(const struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t bytecod RB_OBJ_WRITTEN(iseqv, Qundef, v); ISEQ_MBITS_SET(mark_offset_bits, code_index); FL_SET(iseqv, ISEQ_MARKABLE_ISEQ); + needs_bitmap = true; } break; } @@ -11264,6 +11275,7 @@ ibf_load_code(const struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t bytecod ISEQ_MBITS_SET(mark_offset_bits, code_index); RB_OBJ_WRITTEN(iseqv, Qundef, v); FL_SET(iseqv, ISEQ_MARKABLE_ISEQ); + needs_bitmap = true; break; } case TS_ISEQ: @@ -11275,6 +11287,7 @@ ibf_load_code(const struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t bytecod RB_OBJ_WRITTEN(iseqv, Qundef, v); ISEQ_MBITS_SET(mark_offset_bits, code_index); FL_SET(iseqv, ISEQ_MARKABLE_ISEQ); + needs_bitmap = true; } break; } @@ -11359,7 +11372,13 @@ ibf_load_code(const struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t bytecod load_body->mark_bits.single = mark_offset_bits[0]; } else { - load_body->mark_bits.list = mark_offset_bits; + if (needs_bitmap) { + load_body->mark_bits.list = mark_offset_bits; + } + else { + load_body->mark_bits.list = 0; + ruby_xfree(mark_offset_bits); + } } assert(code_index == iseq_size); -- cgit v1.2.3