summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2021-01-04 18:08:25 +0900
committerKoichi Sasada <ko1@atdot.net>2021-01-05 02:27:58 +0900
commite7fc353f044f9280222ca41b029b1368d2bf2fe3 (patch)
tree3e3a8e464dbc3767d5b71f17675d3f0dba6ac43f /gc.c
parentbf21faec1521540f2be05df400c37600b4316a0f (diff)
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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4022
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/gc.c b/gc.c
index f8810d1af6..ad2406c98b 100644
--- a/gc.c
+++ b/gc.c
@@ -2398,6 +2398,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;
@@ -6260,6 +6261,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);
@@ -8985,6 +8992,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: