From b93e16dc0f45069d4a5fcce20d5c4437e151f0a8 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Mon, 4 Jan 2021 18:08:25 +0900 Subject: enable constant cache on ractors constant cache `IC` is accessed by non-atomic manner and there are thread-safety issues, so Ruby 3.0 disables to use const cache on non-main ractors. This patch enables it by introducing `imemo_constcache` and allocates it by every re-fill of const cache like `imemo_callcache`. [Bug #17510] Now `IC` only has one entry `IC::entry` and it points to `iseq_inline_constant_cache_entry`, managed by T_IMEMO object. `IC` is atomic data structure so `rb_mjit_before_vm_ic_update()` and `rb_mjit_after_vm_ic_update()` is not needed. --- gc.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'gc.c') diff --git a/gc.c b/gc.c index f9ebf6a937..e363dc158a 100644 --- a/gc.c +++ b/gc.c @@ -2397,6 +2397,7 @@ rb_imemo_name(enum imemo_type type) IMEMO_NAME(parser_strterm); IMEMO_NAME(callinfo); IMEMO_NAME(callcache); + IMEMO_NAME(constcache); #undef IMEMO_NAME } return "unknown"; @@ -3102,9 +3103,9 @@ obj_free(rb_objspace_t *objspace, VALUE obj) case imemo_callcache: RB_DEBUG_COUNTER_INC(obj_imemo_callcache); break; - default: - /* unreachable */ - break; + case imemo_constcache: + RB_DEBUG_COUNTER_INC(obj_imemo_constcache); + break; } return 0; @@ -6239,6 +6240,12 @@ gc_mark_imemo(rb_objspace_t *objspace, VALUE obj) gc_mark(objspace, (VALUE)vm_cc_cme(cc)); } return; + case imemo_constcache: + { + const struct iseq_inline_constant_cache_entry *ice = (struct iseq_inline_constant_cache_entry *)obj; + gc_mark(objspace, ice->value); + } + return; #if VM_CHECK_MODE > 0 default: VM_UNREACHABLE(gc_mark_imemo); @@ -8963,6 +8970,12 @@ gc_ref_update_imemo(rb_objspace_t *objspace, VALUE obj) } } break; + case imemo_constcache: + { + const struct iseq_inline_constant_cache_entry *ice = (struct iseq_inline_constant_cache_entry *)obj; + UPDATE_IF_MOVED(objspace, ice->value); + } + break; case imemo_parser_strterm: case imemo_tmpbuf: case imemo_callinfo: -- cgit v1.2.3