mirror of
https://github.com/ruby/ruby.git
synced 2025-09-18 10:03:59 +02:00

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.
39 lines
1.7 KiB
Text
39 lines
1.7 KiB
Text
% # -*- C -*-
|
|
% # Copyright (c) 2020 Takashi Kokubun. All rights reserved.
|
|
% #
|
|
% # This file is a part of the programming language Ruby. Permission is hereby
|
|
% # granted, to either redistribute and/or modify this file, provided that the
|
|
% # conditions mentioned in the file COPYING are met. Consult the file for
|
|
% # details.
|
|
%
|
|
% # compiler: Declare dst and ic
|
|
% insn.opes.each_with_index do |ope, i|
|
|
<%= ope.fetch(:decl) %> = (<%= ope.fetch(:type) %>)operands[<%= i %>];
|
|
% end
|
|
|
|
% # compiler: Capture IC values, locking getinlinecache
|
|
struct iseq_inline_constant_cache_entry *ice = ic->entry;
|
|
if (ice == NULL) {
|
|
goto getinlinecache_cancel;
|
|
}
|
|
rb_serial_t ic_serial = ice->ic_serial;
|
|
const rb_cref_t *ic_cref = ice->ic_cref;
|
|
VALUE ic_value = ice->value;
|
|
|
|
if (ic_serial && !status->compile_info->disable_const_cache) {
|
|
% # JIT: Inline everything in IC, and cancel the slow path
|
|
fprintf(f, " if (vm_ic_hit_p((rb_serial_t)%"PRI_SERIALT_PREFIX"u, (const rb_cref_t *)0x%"PRIxVALUE", reg_cfp->ep)) {", ic_serial, (VALUE)ic_cref);
|
|
fprintf(f, " stack[%d] = 0x%"PRIxVALUE";\n", b->stack_size, ic_value);
|
|
fprintf(f, " goto label_%d;\n", pos + insn_len(insn) + (int)dst);
|
|
fprintf(f, " }");
|
|
fprintf(f, " else {");
|
|
fprintf(f, " reg_cfp->sp = vm_base_ptr(reg_cfp) + %d;\n", b->stack_size);
|
|
fprintf(f, " reg_cfp->pc = original_body_iseq + %d;\n", pos);
|
|
fprintf(f, " goto const_cancel;\n");
|
|
fprintf(f, " }");
|
|
|
|
% # compiler: Move JIT compiler's internal stack pointer
|
|
b->stack_size += <%= insn.call_attribute('sp_inc') %>;
|
|
break;
|
|
}
|
|
getinlinecache_cancel:;
|