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

ruby-changes:72593

From: Jemma <ko1@a...>
Date: Tue, 19 Jul 2022 04:44:16 +0900 (JST)
Subject: [ruby-changes:72593] ecff334995 (master): Extract vm_ic_entry API to mimic vm_cc behavior

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

From ecff3349953e17491630ef7b68c5ac6b095d39bf Mon Sep 17 00:00:00 2001
From: Jemma Issroff <jemmaissroff@g...>
Date: Mon, 6 Jun 2022 10:48:42 -0400
Subject: Extract vm_ic_entry API to mimic vm_cc behavior

---
 common.mk                      |  1 +
 vm_callinfo.h                  | 20 ++++++++++++++++++++
 vm_insnhelper.c                | 15 ++++++---------
 yjit/src/cruby_bindings.inc.rs | 24 ++++++++++++------------
 4 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/common.mk b/common.mk
index ddd55c55a1..2edee06520 100644
--- a/common.mk
+++ b/common.mk
@@ -3499,6 +3499,7 @@ debug.$(OBJEXT): $(CCAN_DIR)/list/list.h https://github.com/ruby/ruby/blob/trunk/common.mk#L3499
 debug.$(OBJEXT): $(CCAN_DIR)/str/str.h
 debug.$(OBJEXT): $(hdrdir)/ruby/ruby.h
 debug.$(OBJEXT): $(top_srcdir)/internal/array.h
+debug.$(OBJEXT): $(top_srcdir)/internal/class.h
 debug.$(OBJEXT): $(top_srcdir)/internal/compilers.h
 debug.$(OBJEXT): $(top_srcdir)/internal/gc.h
 debug.$(OBJEXT): $(top_srcdir)/internal/imemo.h
diff --git a/vm_callinfo.h b/vm_callinfo.h
index f17035b27f..fd2215be7d 100644
--- a/vm_callinfo.h
+++ b/vm_callinfo.h
@@ -9,6 +9,7 @@ https://github.com/ruby/ruby/blob/trunk/vm_callinfo.h#L9
  */
 
 #include "debug_counter.h"
+#include "internal/class.h"
 
 enum vm_call_flag_bits {
     VM_CALL_ARGS_SPLAT_bit,     /* m(*args) */
@@ -363,6 +364,18 @@ vm_cc_attr_index_p(const struct rb_callcache *cc) https://github.com/ruby/ruby/blob/trunk/vm_callinfo.h#L364
     return cc->aux_.attr_index > 0;
 }
 
+static inline uint32_t
+vm_ic_entry_index(const struct iseq_inline_iv_cache_entry *ic)
+{
+    return ic->entry->index;
+}
+
+static inline bool
+vm_ic_entry_p(const struct iseq_inline_iv_cache_entry *ic)
+{
+    return ic->entry;
+}
+
 static inline unsigned int
 vm_cc_cmethod_missing_reason(const struct rb_callcache *cc)
 {
@@ -416,6 +429,13 @@ vm_cc_attr_index_set(const struct rb_callcache *cc, int index) https://github.com/ruby/ruby/blob/trunk/vm_callinfo.h#L429
     *(int *)&cc->aux_.attr_index = index + 1;
 }
 
+static inline void
+vm_ic_entry_set(struct iseq_inline_iv_cache_entry *ic, struct rb_iv_index_tbl_entry *entry, const rb_iseq_t *iseq)
+{
+    ic->entry = entry;
+    RB_OBJ_WRITTEN(iseq, Qundef, entry->class_value);
+}
+
 static inline void
 vm_cc_attr_index_initialize(const struct rb_callcache *cc)
 {
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 8db11be5e5..5a77484b74 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1104,8 +1104,7 @@ fill_ivar_cache(const rb_iseq_t *iseq, IVC ic, const struct rb_callcache *cc, in https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1104
 {
     // fill cache
     if (!is_attr) {
-        ic->entry = ent;
-        RB_OBJ_WRITTEN(iseq, Qundef, ent->class_value);
+        vm_ic_entry_set(ic, ent, iseq);
     }
     else {
         vm_cc_attr_index_set(cc, ent->index);
@@ -1124,9 +1123,8 @@ vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_call https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1123
     }
     else if (LIKELY(is_attr ?
                     RB_DEBUG_COUNTER_INC_UNLESS(ivar_get_ic_miss_unset, vm_cc_attr_index_p(cc)) :
-                    RB_DEBUG_COUNTER_INC_UNLESS(ivar_get_ic_miss_serial,
-                                                ic->entry && ic->entry->class_serial == RCLASS_SERIAL(RBASIC(obj)->klass)))) {
-        uint32_t index = !is_attr ? ic->entry->index: (vm_cc_attr_index(cc));
+                    RB_DEBUG_COUNTER_INC_UNLESS(ivar_get_ic_miss_serial, vm_ic_entry_p(ic) && ic->entry->class_serial == RCLASS_SERIAL(RBASIC(obj)->klass)))) {
+        uint32_t index = !is_attr ? vm_ic_entry_index(ic): (vm_cc_attr_index(cc));
 
         RB_DEBUG_COUNTER_INC(ivar_get_ic_hit);
 
@@ -1208,8 +1206,7 @@ vm_setivar_slowpath(VALUE obj, ID id, VALUE val, const rb_iseq_t *iseq, IVC ic, https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1206
 
         if (iv_index_tbl_lookup(iv_index_tbl, id, &ent)) {
             if (!is_attr) {
-                ic->entry = ent;
-                RB_OBJ_WRITTEN(iseq, Qundef, ent->class_value);
+                vm_ic_entry_set(ic, ent, iseq);
             }
             else if (ent->index >= INT_MAX) {
                 rb_raise(rb_eArgError, "too many instance variables");
@@ -1257,9 +1254,9 @@ vm_setivar(VALUE obj, ID id, VALUE val, const rb_iseq_t *iseq, IVC ic, const str https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1254
         VM_ASSERT(!rb_ractor_shareable_p(obj));
 
 	if (LIKELY(
-	    (!is_attr && RB_DEBUG_COUNTER_INC_UNLESS(ivar_set_ic_miss_serial, ic->entry && ic->entry->class_serial  == RCLASS_SERIAL(RBASIC(obj)->klass))) ||
+	    (!is_attr && RB_DEBUG_COUNTER_INC_UNLESS(ivar_set_ic_miss_serial, vm_ic_entry_p(ic) && ic->entry->class_serial == RCLASS_SERIAL(RBASIC(obj)->klass))) ||
             ( is_attr && RB_DEBUG_COUNTER_INC_UNLESS(ivar_set_ic_miss_unset, vm_cc_attr_index_p(cc))))) {
-            uint32_t index = !is_attr ? ic->entry->index : vm_cc_attr_index(cc);
+            uint32_t index = !is_attr ? vm_ic_entry_index(ic) : vm_cc_attr_index(cc);
 
             if (UNLIKELY(index >= ROBJECT_NUMIV(obj))) {
                 rb_init_iv_list(obj);
diff --git a/yjit/src/cruby_bindings.inc.rs b/yjit/src/cruby_bindings.inc.rs
index b9c239cd23..fed132588c 100644
--- a/yjit/src/cruby_bindings.inc.rs
+++ b/yjit/src/cruby_bindings.inc.rs
@@ -657,6 +657,18 @@ extern "C" { https://github.com/ruby/ruby/blob/trunk/yjit/src/cruby_bindings.inc.rs#L657
         cfp: *const rb_control_frame_t,
     ) -> *const rb_callable_method_entry_t;
 }
+#[repr(C)]
+pub struct rb_iv_index_tbl_entry {
+    pub index: u32,
+    pub class_serial: rb_serial_t,
+    pub class_value: VALUE,
+}
+#[repr(C)]
+pub struct rb_cvar_class_tbl_entry {
+    pub index: u32,
+    pub global_cvar_state: rb_serial_t,
+    pub class_value: VALUE,
+}
 pub const VM_CALL_ARGS_SPLAT_bit: vm_call_flag_bits = 0;
 pub const VM_CALL_ARGS_BLOCKARG_bit: vm_call_flag_bits = 1;
 pub const VM_CALL_FCALL_bit: vm_call_flag_bits = 2;
@@ -714,18 +726,6 @@ extern "C" { https://github.com/ruby/ruby/blob/trunk/yjit/src/cruby_bindings.inc.rs#L726
     pub fn rb_vm_insn_decode(encoded: VALUE) -> ::std::os::raw::c_int;
 }
 #[repr(C)]
-pub struct rb_iv_index_tbl_entry {
-    pub index: u32,
-    pub class_serial: rb_serial_t,
-    pub class_value: VALUE,
-}
-#[repr(C)]
-pub struct rb_cvar_class_tbl_entry {
-    pub index: u32,
-    pub global_cvar_state: rb_serial_t,
-    pub class_value: VALUE,
-}
-#[repr(C)]
 #[derive(Debug, Copy, Clone)]
 pub struct rb_builtin_function {
     pub func_ptr: *const ::std::os::raw::c_void,
-- 
cgit v1.2.1


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

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