[前][次][番号順一覧][スレッド一覧]

ruby-changes:66016

From: nagachika <ko1@a...>
Date: Thu, 29 Apr 2021 17:50:31 +0900 (JST)
Subject: [ruby-changes:66016] cc4e602634 (ruby_3_0): merge revision(s) 87c546b5fa97e6e226cce4daf417617a1143f642,7a3322a0fd660d676f1918bd7c4a37676b44e1c2:

https://git.ruby-lang.org/ruby.git/commit/?id=cc4e602634

From cc4e602634e894c831a4103a5803a3de566c1856 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@r...>
Date: Thu, 29 Apr 2021 17:49:55 +0900
Subject: merge revision(s)
 87c546b5fa97e6e226cce4daf417617a1143f642,7a3322a0fd660d676f1918bd7c4a37676b44e1c2:

	Avoid using inconsistent coding style

	Other `_mjit_compile_*.erb` files don't use goto. These files'd better
	be consistent for readability.
	---
	 tool/ruby_vm/views/_mjit_compile_getinlinecache.erb | 14 +++-----------
	 1 file changed, 3 insertions(+), 11 deletions(-)

	Fix broken JIT of getinlinecache

	e7fc353f04 reverted vm_ic_hit_p's signature change made in 53babf35ef,
	which broke JIT compilation of getinlinecache.

	To make sure it doesn't happen again, I separated vm_inlined_ic_hit_p to
	make the intention clear.
	---
	 test/ruby/test_jit.rb                              | 12 +++++++++++
	 .../ruby_vm/views/_mjit_compile_getinlinecache.erb |  2 +-
	 vm_insnhelper.c                                    | 25 ++++++++++++++--------
	 3 files changed, 29 insertions(+), 10 deletions(-)
---
 test/ruby/test_jit.rb                              | 12 +++++++++++
 .../ruby_vm/views/_mjit_compile_getinlinecache.erb | 14 +++---------
 version.h                                          |  2 +-
 vm_insnhelper.c                                    | 25 ++++++++++++++--------
 4 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/test/ruby/test_jit.rb b/test/ruby/test_jit.rb
index 3a38b1a..be35500 100644
--- a/test/ruby/test_jit.rb
+++ b/test/ruby/test_jit.rb
@@ -857,6 +857,18 @@ class TestJIT < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_jit.rb#L857
     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 1b636bc..1acfdb7 100644
--- a/tool/ruby_vm/views/_mjit_compile_getinlinecache.erb
+++ b/tool/ruby_vm/views/_mjit_compile_getinlinecache.erb
@@ -13,17 +13,10 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_mjit_compile_getinlinecache.erb#L13
 
 % # 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 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_mjit_compile_getinlinecache.erb#L29
         b->stack_size += <%= insn.call_attribute('sp_inc') %>;
         break;
     }
-    getinlinecache_cancel:;
diff --git a/version.h b/version.h
index 49bbef7..9a0663c 100644
--- a/version.h
+++ b/version.h
@@ -12,7 +12,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L12
 # 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 8a87685..74ab6ac 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -4640,19 +4640,26 @@ vm_opt_newarray_min(rb_num_t num, const VALUE *ptr) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L4640
 
 #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
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]