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

ruby-changes:74432

From: Jemma <ko1@a...>
Date: Fri, 11 Nov 2022 00:12:02 +0900 (JST)
Subject: [ruby-changes:74432] c726c48a3d (master): Remove numiv from RObject

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

From c726c48a3dacd9ca1cb0d96fee98890cb74b37d3 Mon Sep 17 00:00:00 2001
From: Jemma Issroff <jemmaissroff@g...>
Date: Tue, 8 Nov 2022 14:09:43 -0500
Subject: Remove numiv from RObject

Since object shapes store the capacity of an object, we no longer
need the numiv field on RObjects. This gives us one extra slot which
we can use to give embedded objects one more instance variable (for a
total of 3 ivs). This commit removes the concept of numiv from RObject.
---
 ext/objspace/objspace_dump.c         |  2 +-
 gc.c                                 | 22 +++-----------
 include/ruby/internal/core/robject.h | 59 +-----------------------------------
 lib/mjit/compiler.rb                 |  2 +-
 object.c                             |  1 -
 variable.c                           | 20 +++---------
 vm_core.h                            |  2 +-
 vm_insnhelper.c                      |  6 ++--
 yjit/src/codegen.rs                  |  8 -----
 9 files changed, 16 insertions(+), 106 deletions(-)

diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c
index 7c7cae3488..61fa0f04ac 100644
--- a/ext/objspace/objspace_dump.c
+++ b/ext/objspace/objspace_dump.c
@@ -515,7 +515,7 @@ dump_object(VALUE obj, struct dump_config *dc) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L515
 
       case T_OBJECT:
         dump_append(dc, ", \"ivars\":");
-        dump_append_lu(dc, ROBJECT_NUMIV(obj));
+        dump_append_lu(dc, ROBJECT_IV_CAPACITY(obj));
         break;
 
       case T_FILE:
diff --git a/gc.c b/gc.c
index 84f3b8f206..8b8f0c11f1 100644
--- a/gc.c
+++ b/gc.c
@@ -2943,14 +2943,9 @@ rb_class_instance_allocate_internal(VALUE klass, VALUE flags, bool wb_protected) https://github.com/ruby/ruby/blob/trunk/gc.c#L2943
 
     VALUE obj = newobj_of(klass, flags, 0, 0, 0, wb_protected, size);
 
-#if USE_RVARGC
-    uint32_t capa = (uint32_t)((rb_gc_obj_slot_size(obj) - offsetof(struct RObject, as.ary)) / sizeof(VALUE));
-    ROBJECT_SET_NUMIV(obj, capa);
-#endif
-
 #if RUBY_DEBUG
     VALUE *ptr = ROBJECT_IVPTR(obj);
-    for (size_t i = 0; i < ROBJECT_NUMIV(obj); i++) {
+    for (size_t i = 0; i < ROBJECT_IV_CAPACITY(obj); i++) {
         ptr[i] = Qundef;
     }
 #endif
@@ -4859,7 +4854,7 @@ obj_memsize_of(VALUE obj, int use_all_types) https://github.com/ruby/ruby/blob/trunk/gc.c#L4854
     switch (BUILTIN_TYPE(obj)) {
       case T_OBJECT:
         if (!(RBASIC(obj)->flags & ROBJECT_EMBED)) {
-            size += ROBJECT_NUMIV(obj) * sizeof(VALUE);
+            size += ROBJECT_IV_CAPACITY(obj) * sizeof(VALUE);
         }
         break;
       case T_MODULE:
@@ -8409,7 +8404,7 @@ gc_compact_destination_pool(rb_objspace_t *objspace, rb_size_pool_t *src_pool, V https://github.com/ruby/ruby/blob/trunk/gc.c#L8404
             break;
 
         case T_OBJECT:
-            obj_size = rb_obj_embedded_size(ROBJECT_NUMIV(src));
+            obj_size = rb_obj_embedded_size(ROBJECT_IV_CAPACITY(src));
             break;
 
         case T_STRING:
@@ -10019,7 +10014,7 @@ gc_ref_update_object(rb_objspace_t *objspace, VALUE v) https://github.com/ruby/ruby/blob/trunk/gc.c#L10014
     VALUE *ptr = ROBJECT_IVPTR(v);
 
 #if USE_RVARGC
-    uint32_t numiv = ROBJECT_NUMIV(v);
+    uint32_t numiv = ROBJECT_IV_CAPACITY(v);
 
     size_t slot_size = rb_gc_obj_slot_size(v);
     size_t embed_size = rb_obj_embedded_size(numiv);
@@ -10038,13 +10033,6 @@ gc_ref_update_object(rb_objspace_t *objspace, VALUE v) https://github.com/ruby/ruby/blob/trunk/gc.c#L10033
         rb_shape_t * initial_shape = rb_shape_get_shape_by_id((shape_id_t)size_pool_shape_id);
         rb_shape_t * new_shape = rb_shape_rebuild_shape(initial_shape, rb_shape_get_shape(v));
         rb_shape_set_shape(v, new_shape);
-        ROBJECT_SET_NUMIV(v, new_shape->capacity);
-#if RUBY_DEBUG
-        if(RB_TYPE_P(v, T_OBJECT) && ROBJECT_IV_CAPACITY(v) != ROBJECT_NUMIV(v)) {
-            fprintf(stderr, "shape capa: %d, v capa: %d\n", ROBJECT_IV_CAPACITY(v), ROBJECT_NUMIV(v));
-        }
-#endif
-        RUBY_ASSERT(!RB_TYPE_P(v, T_OBJECT) || ROBJECT_IV_CAPACITY(v) == ROBJECT_NUMIV(v));
     }
 #endif
 
@@ -13975,7 +13963,7 @@ rb_raw_obj_info_buitin_type(char *const buff, const size_t buff_size, const VALU https://github.com/ruby/ruby/blob/trunk/gc.c#L13963
             }
           case T_OBJECT:
             {
-                uint32_t len = ROBJECT_NUMIV(obj);
+                uint32_t len = ROBJECT_IV_CAPACITY(obj);
 
                 if (RANY(obj)->as.basic.flags & ROBJECT_EMBED) {
                     APPEND_F("(embed) len:%d", len);
diff --git a/include/ruby/internal/core/robject.h b/include/ruby/internal/core/robject.h
index e0514d7dd2..f51c524081 100644
--- a/include/ruby/internal/core/robject.h
+++ b/include/ruby/internal/core/robject.h
@@ -44,7 +44,7 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/robject.h#L44
 /** @cond INTERNAL_MACRO */
 #define ROBJECT_EMBED_LEN_MAX ROBJECT_EMBED_LEN_MAX
 #define ROBJECT_EMBED         ROBJECT_EMBED
-#define ROBJECT_NUMIV         ROBJECT_NUMIV
+#define ROBJECT_IV_CAPACITY   ROBJECT_IV_CAPACITY
 #define ROBJECT_IVPTR         ROBJECT_IVPTR
 /** @endcond */
 
@@ -96,14 +96,6 @@ struct RObject { https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/robject.h#L96
     /** Basic part, including flags and class. */
     struct RBasic basic;
 
-#if USE_RVARGC
-    /**
-    * Number of instance variables.  This is per object; objects might
-    * differ in this field even if they have the identical classes.
-    */
-    uint32_t numiv;
-#endif
-
     /** Object's specific fields. */
     union {
 
@@ -112,14 +104,6 @@ struct RObject { https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/robject.h#L104
          * this pattern.
          */
         struct {
-#if !USE_RVARGC
-            /**
-             * Number of instance variables.  This is per object; objects might
-             * differ in this field even if they have the identical classes.
-             */
-            uint32_t numiv;
-#endif
-
             /** Pointer to a C array that holds instance variables. */
             VALUE *ivptr;
 
@@ -156,52 +140,11 @@ struct RObject { https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/robject.h#L140
 
 /* Offsets for YJIT */
 #ifndef __cplusplus
-# if USE_RVARGC
-static const int32_t ROBJECT_OFFSET_NUMIV = offsetof(struct RObject, numiv);
-# else
-static const int32_t ROBJECT_OFFSET_NUMIV = offsetof(struct RObject, as.heap.numiv);
-# endif
 static const int32_t ROBJECT_OFFSET_AS_HEAP_IVPTR = offsetof(struct RObject, as.heap.ivptr);
 static const int32_t ROBJECT_OFFSET_AS_HEAP_IV_INDEX_TBL = offsetof(struct RObject, as.heap.iv_index_tbl);
 static const int32_t ROBJECT_OFFSET_AS_ARY = offsetof(struct RObject, as.ary);
 #endif
 
-RBIMPL_ATTR_PURE_UNLESS_DEBUG()
-RBIMPL_ATTR_ARTIFICIAL()
-/**
- * Queries the number of instance variables.
- *
- * @param[in]  obj  Object in question.
- * @return     Its number of instance variables.
- * @pre        `obj` must be an instance of ::RObject.
- */
-static inline uint32_t
-ROBJECT_NUMIV(VALUE obj)
-{
-    RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
-
-#if USE_RVARGC
-    return ROBJECT(obj)->numiv;
-#else
-    if (RB_FL_ANY_RAW(obj, ROBJECT_EMBED)) {
-        return ROBJECT_EMBED_LEN_MAX;
-    }
-    else {
-        return ROBJECT(obj)->as.heap.numiv;
-    }
-#endif
-}
-
-static inline void
-ROBJECT_SET_NUMIV(VALUE obj, uint32_t capacity)
-{
-#if USE_RVARGC
-    ROBJECT(obj)->numiv = capacity;
-#else
-    ROBJECT(obj)->as.heap.numiv = capacity;
-#endif
-}
-
 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
 RBIMPL_ATTR_ARTIFICIAL()
 /**
diff --git a/lib/mjit/compiler.rb b/lib/mjit/compiler.rb
index 575ae6f84c..9e6ea0a119 100644
--- a/lib/mjit/compiler.rb
+++ b/lib/mjit/compiler.rb
@@ -386,7 +386,7 @@ module RubyVM::MJIT https://github.com/ruby/ruby/blob/trunk/lib/mjit/compiler.rb#L386
           src << "        dest_shape_id != ROBJECT_SHAPE_ID(obj)) {\n"
           # Conditionally generate a capacity change if there is one
           # between the destination and the parent IV set
-          src << "        rb_ensure_iv_list_size(obj, RBOJECT_NUMIV(obj), #{capa});\n" if capa
+          src << "        rb_ensure_iv_list_size(obj, ROBJECT_IV_CAPACITY(obj), #{capa});\n" if capa
           src << "        ROBJECT_SET_SHAPE_ID(obj, dest_shape_id);\n"
           src << "        VALUE *ptr = ROBJECT_IVPTR(obj);\n"
           src << "        RB_OBJ_WRITE(obj, &ptr[index], stack[#{stack_size - 1}]);\n"
diff --git a/object.c b/object.c
index 9a06500b6b..f51bd3486b 100644
--- a/object.c
+++ b/object.c
@@ -326,7 +326,6 @@ rb_obj_copy_ivar(VALUE dest, VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L326
     }
 
     rb_shape_set_shape(dest, shape_to_set_on_dest);
-    RUBY_ASSERT(!RB_TYPE_P(obj, T_OBJECT) || ROBJECT_IV_CAPACITY(dest) == ROBJECT_NUMIV(dest));
 }
 
 static void
diff --git a/variable.c b/variable.c
index bdde4d9607..2fed1e3512 100644
--- a/variable.c
+++ b/variable.c
@@ -1346,7 +1346,7 @@ rb_obj_transient_heap_evacuate(VALUE obj, int promote) https://github.com/ruby/ruby/blob/trunk/variable.c#L1346
     if (ROBJ_TRANSIENT_P(obj)) {
         assert(!RB_FL_TEST_RAW(obj, ROBJECT_EMBED));
 
-        uint32_t len = ROBJECT_NUMIV(obj);
+        uint32_t len = ROBJECT_IV_CAPACITY(obj);
         const VALUE *old_ptr = ROBJECT_IVPTR(obj);
         VALUE *new_ptr;
 
@@ -1378,7 +1378,6 @@ rb_ensure_iv_list_size(VALUE obj, uint32_t current_capacity, uint32_t new_capaci https://github.com/ruby/ruby/blob/trunk/variable.c#L1378
     else {
         newptr = obj_ivar_heap_realloc(obj, current_capacity, new_capacity);
     }
-    ROBJECT_SET_NUMIV(obj, new_capacity);
 }
 
 struct gen_ivtbl *
@@ -1405,21 +1404,14 @@ rb_ensure_generic_iv_list_size(VALUE obj, uint32_t newsize) https://github.com/ruby/ruby/blob/trunk/variable.c#L1404
 rb_shape_t *
 rb_grow_iv_list(VALUE obj)
 {
-    uint32_t len = ROBJECT_NUMIV(obj);
+    rb_shape_t * initi (... truncated)

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

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