diff --git a/vm_core.h b/vm_core.h index a0d2b1ed2df4e5..119a0fd3b249c1 100644 --- a/vm_core.h +++ b/vm_core.h @@ -305,6 +305,20 @@ vm_icc_has_entry(const struct iseq_inline_constant_cache *cc) return vm_icc_flags(cc) & IMEMO_CONST_CACHE_HAS_ENTRY; } +static inline bool +vm_icc_is_set(const struct iseq_inline_constant_cache *cc) +{ + return !UNDEF_P(cc->value); +} + +static inline void +vm_icc_reset(struct iseq_inline_constant_cache *cc) +{ + if (!UNDEF_P(cc->value)) { + cc->value = Qundef; + } +} + static inline void vm_icc_init(struct iseq_inline_constant_cache *cc, const ID *segments) { diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 68eec7edbe675c..f5a2d67119434a 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -6388,7 +6388,6 @@ vm_inlined_ic_hit_p(VALUE flags, VALUE value, const rb_cref_t *ic_cref, const VA static bool vm_ic_hit_p(const struct iseq_inline_constant_cache *ic, const VALUE *reg_ep) { - VM_ASSERT(IMEMO_TYPE_P(ice, imemo_constcache)); return vm_inlined_ic_hit_p(vm_icc_flags(ic), vm_icc_value(ic), vm_icc_cref(ic), reg_ep); } @@ -6396,7 +6395,7 @@ vm_ic_hit_p(const struct iseq_inline_constant_cache *ic, const VALUE *reg_ep) bool rb_vm_ic_hit_p(IC ic, const VALUE *reg_ep) { - return ic->entry && vm_ic_hit_p(ic, reg_ep); + return vm_icc_is_set(ic) && vm_ic_hit_p(ic, reg_ep); } static void @@ -6404,7 +6403,7 @@ vm_ic_update(const rb_iseq_t *iseq, IC ic, VALUE val, const VALUE *reg_ep, const { if (ruby_vm_const_missing_count > 0) { ruby_vm_const_missing_count = 0; - ic->entry = NULL; + vm_icc_reset(ic); return; } @@ -6433,7 +6432,7 @@ rb_vm_opt_getconstant_path(rb_execution_context_t *ec, rb_control_frame_t *const { VALUE val; const ID *segments = vm_icc_segments(ic); - if (!UNDEF_P(ic->value) && vm_ic_hit_p(ic, GET_EP())) { + if (vm_icc_is_set(ic) && vm_ic_hit_p(ic, GET_EP())) { val = vm_icc_value(ic); VM_ASSERT(val == vm_get_ev_const_chain(ec, segments)); diff --git a/vm_method.c b/vm_method.c index e4f71648acb3aa..fb43cb8d242d97 100644 --- a/vm_method.c +++ b/vm_method.c @@ -129,7 +129,7 @@ vm_cme_invalidate(rb_callable_method_entry_t *cme) static int rb_clear_constant_cache_for_id_i(st_data_t ic, st_data_t idx, st_data_t arg) { - ((IC) ic)->entry = NULL; + vm_icc_reset((IC) ic); return ST_CONTINUE; }