diff --git a/compile.c b/compile.c index c0cc0be873ef05..7c51a4f134b745 100644 --- a/compile.c +++ b/compile.c @@ -2018,6 +2018,7 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) rb_hash_rehash(map); freeze_hide_obj(map); generated_iseq[code_index + 1 + j] = map; + FL_SET(iseq, ISEQ_MARKABLE_ISEQ); break; } case TS_LINDEX: @@ -2028,6 +2029,9 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) { VALUE v = operands[j]; generated_iseq[code_index + 1 + j] = v; + if (!SPECIAL_CONST_P(v)) { + FL_SET(iseq, ISEQ_MARKABLE_ISEQ); + } break; } case TS_VALUE: /* VALUE */ @@ -2035,6 +2039,9 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) VALUE v = operands[j]; generated_iseq[code_index + 1 + j] = v; /* to mark ruby object */ + if (!SPECIAL_CONST_P(v)) { + FL_SET(iseq, ISEQ_MARKABLE_ISEQ); + } break; } case TS_IC: /* inline cache */ @@ -2045,6 +2052,9 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) rb_bug("iseq_set_sequence: ic_index overflow: index: %d, size: %d", ic_index, iseq->body->is_size); } generated_iseq[code_index + 1 + j] = (VALUE)ic; + if (BIN(once) == insn || BIN(trace_once) == insn) { + FL_SET(iseq, ISEQ_MARKABLE_ISEQ); + } break; } case TS_CALLINFO: /* call info */ diff --git a/iseq.c b/iseq.c index e59a612de8d635..7743cd3e8a1f58 100644 --- a/iseq.c +++ b/iseq.c @@ -215,7 +215,10 @@ rb_iseq_mark(const rb_iseq_t *iseq) if (iseq->body) { const struct rb_iseq_constant_body *body = iseq->body; - rb_iseq_each_value(iseq, each_insn_value, NULL); + if(FL_TEST(iseq, ISEQ_MARKABLE_ISEQ)) { + rb_iseq_each_value(iseq, each_insn_value, NULL); + } + rb_gc_mark(body->variable.coverage); rb_gc_mark(body->variable.original_iseq); rb_gc_mark(body->location.label); diff --git a/iseq.h b/iseq.h index d238a55fe4d5f8..31a3232e3be1f7 100644 --- a/iseq.h +++ b/iseq.h @@ -84,6 +84,7 @@ ISEQ_ORIGINAL_ISEQ_ALLOC(const rb_iseq_t *iseq, long size) #define ISEQ_NOT_LOADED_YET IMEMO_FL_USER1 #define ISEQ_USE_COMPILE_DATA IMEMO_FL_USER2 #define ISEQ_TRANSLATED IMEMO_FL_USER3 +#define ISEQ_MARKABLE_ISEQ IMEMO_FL_USER4 struct iseq_compile_data { /* GC is needed */