summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/ruby/test_jit.rb12
-rw-r--r--tool/ruby_vm/views/_mjit_compile_getinlinecache.erb14
-rw-r--r--version.h2
-rw-r--r--vm_insnhelper.c25
4 files changed, 32 insertions, 21 deletions
diff --git a/test/ruby/test_jit.rb b/test/ruby/test_jit.rb
index 3a38b1a998..be3550033d 100644
--- a/test/ruby/test_jit.rb
+++ b/test/ruby/test_jit.rb
@@ -857,6 +857,18 @@ class TestJIT < Test::Unit::TestCase
end;
end
+ def test_inlined_getconstant
+ assert_eval_with_jit("#{<<~"begin;"}\n#{<<~"end;"}", stdout: '11', success_count: 1, min_calls: 2)
+ begin;
+ FOO = 1
+ def const
+ FOO
+ end
+ print const
+ print const
+ end;
+ end
+
def test_attr_reader
assert_eval_with_jit("#{<<~"begin;"}\n#{<<~"end;"}", stdout: "4nil\nnil\n6", success_count: 2, min_calls: 2)
begin;
diff --git a/tool/ruby_vm/views/_mjit_compile_getinlinecache.erb b/tool/ruby_vm/views/_mjit_compile_getinlinecache.erb
index 1b636bceb6..1acfdb7f0b 100644
--- a/tool/ruby_vm/views/_mjit_compile_getinlinecache.erb
+++ b/tool/ruby_vm/views/_mjit_compile_getinlinecache.erb
@@ -13,17 +13,10 @@
% # 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) {
+ if (ice != NULL && ice->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, " if (vm_inlined_ic_hit_p(0x%"PRIxVALUE", 0x%"PRIxVALUE", (const rb_cref_t *)0x%"PRIxVALUE", %"PRI_SERIALT_PREFIX"u, reg_cfp->ep)) {", ice->flags, ice->value, (VALUE)ice->ic_cref, ice->ic_serial);
+ fprintf(f, " stack[%d] = 0x%"PRIxVALUE";\n", b->stack_size, ice->value);
fprintf(f, " goto label_%d;\n", pos + insn_len(insn) + (int)dst);
fprintf(f, " }");
fprintf(f, " else {");
@@ -36,4 +29,3 @@
b->stack_size += <%= insn.call_attribute('sp_inc') %>;
break;
}
- getinlinecache_cancel:;
diff --git a/version.h b/version.h
index 49bbef749c..9a0663c459 100644
--- a/version.h
+++ b/version.h
@@ -12,7 +12,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 2
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 73
+#define RUBY_PATCHLEVEL 74
#define RUBY_RELEASE_YEAR 2021
#define RUBY_RELEASE_MONTH 4
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 8a876851b9..74ab6ac1c6 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -4640,19 +4640,26 @@ vm_opt_newarray_min(rb_num_t num, const VALUE *ptr)
#define IMEMO_CONST_CACHE_SHAREABLE IMEMO_FL_USER0
-static int
-vm_ic_hit_p(const struct iseq_inline_constant_cache_entry *ice, const VALUE *reg_ep)
+// For MJIT inlining
+static inline bool
+vm_inlined_ic_hit_p(VALUE flags, VALUE value, const rb_cref_t *ic_cref, rb_serial_t ic_serial, const VALUE *reg_ep)
{
- VM_ASSERT(IMEMO_TYPE_P(ice, imemo_constcache));
- if (ice->ic_serial == GET_GLOBAL_CONSTANT_STATE() &&
- (FL_TEST_RAW((VALUE)ice, IMEMO_CONST_CACHE_SHAREABLE) || rb_ractor_main_p())) {
+ if (ic_serial == GET_GLOBAL_CONSTANT_STATE() &&
+ ((flags & IMEMO_CONST_CACHE_SHAREABLE) || rb_ractor_main_p())) {
- VM_ASSERT(FL_TEST_RAW((VALUE)ice, IMEMO_CONST_CACHE_SHAREABLE) ? rb_ractor_shareable_p(ice->value) : true);
+ VM_ASSERT((flags & IMEMO_CONST_CACHE_SHAREABLE) ? rb_ractor_shareable_p(value) : true);
- return (ice->ic_cref == NULL || // no need to check CREF
- ice->ic_cref == vm_get_cref(reg_ep));
+ return (ic_cref == NULL || // no need to check CREF
+ ic_cref == vm_get_cref(reg_ep));
}
- return FALSE;
+ return false;
+}
+
+static bool
+vm_ic_hit_p(const struct iseq_inline_constant_cache_entry *ice, const VALUE *reg_ep)
+{
+ VM_ASSERT(IMEMO_TYPE_P(ice, imemo_constcache));
+ return vm_inlined_ic_hit_p(ice->flags, ice->value, ice->ic_cref, ice->ic_serial, reg_ep);
}
static void