summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shape.h1
-rw-r--r--vm_callinfo.h33
-rw-r--r--vm_insnhelper.c2
3 files changed, 22 insertions, 14 deletions
diff --git a/shape.h b/shape.h
index b58eebd4d3..e14f1576a0 100644
--- a/shape.h
+++ b/shape.h
@@ -30,6 +30,7 @@ typedef uint32_t redblack_id_t;
# define SHAPE_MAX_VARIATIONS 8
# define INVALID_SHAPE_ID (((uintptr_t)1 << SHAPE_ID_NUM_BITS) - 1)
+#define ATTR_INDEX_NOT_SET (attr_index_t)-1
#define ROOT_SHAPE_ID 0x0
#define SPECIAL_CONST_SHAPE_ID 0x1
diff --git a/vm_callinfo.h b/vm_callinfo.h
index d2160a9ff9..6813c1cc94 100644
--- a/vm_callinfo.h
+++ b/vm_callinfo.h
@@ -416,21 +416,24 @@ vm_cc_call(const struct rb_callcache *cc)
}
static inline void
-vm_cc_atomic_shape_and_index(const struct rb_callcache *cc, shape_id_t * shape_id, attr_index_t * index)
+vm_unpack_shape_and_index(uintptr_t cache_value, shape_id_t *shape_id, attr_index_t *index)
{
- uintptr_t cache_value = cc->aux_.attr.value; // Atomically read 64 bits
*shape_id = (shape_id_t)(cache_value >> SHAPE_FLAG_SHIFT);
*index = (attr_index_t)(cache_value & SHAPE_FLAG_MASK) - 1;
- return;
}
static inline void
-vm_ic_atomic_shape_and_index(const struct iseq_inline_iv_cache_entry *ic, shape_id_t * shape_id, attr_index_t * index)
+vm_cc_atomic_shape_and_index(const struct rb_callcache *cc, shape_id_t *shape_id, attr_index_t *index)
{
- uintptr_t cache_value = ic->value; // Atomically read 64 bits
- *shape_id = (shape_id_t)(cache_value >> SHAPE_FLAG_SHIFT);
- *index = (attr_index_t)(cache_value & SHAPE_FLAG_MASK) - 1;
- return;
+ // Atomically read uintptr_t
+ vm_unpack_shape_and_index(cc->aux_.attr.value, shape_id, index);
+}
+
+static inline void
+vm_ic_atomic_shape_and_index(const struct iseq_inline_iv_cache_entry *ic, shape_id_t *shape_id, attr_index_t *index)
+{
+ // Atomically read uintptr_t
+ vm_unpack_shape_and_index(ic->value, shape_id, index);
}
static inline unsigned int
@@ -467,17 +470,23 @@ set_vm_cc_ivar(const struct rb_callcache *cc)
*(VALUE *)&cc->flags |= VM_CALLCACHE_IVAR;
}
+static inline uintptr_t
+vm_pack_shape_and_index(shape_id_t shape_id, attr_index_t index)
+{
+ return (attr_index_t)(index + 1) | ((uintptr_t)(shape_id) << SHAPE_FLAG_SHIFT);
+}
+
static inline void
vm_cc_attr_index_set(const struct rb_callcache *cc, attr_index_t index, shape_id_t dest_shape_id)
{
uintptr_t *attr_value = (uintptr_t *)&cc->aux_.attr.value;
if (!vm_cc_markable(cc)) {
- *attr_value = (uintptr_t)INVALID_SHAPE_ID << SHAPE_FLAG_SHIFT;
+ *attr_value = vm_pack_shape_and_index(INVALID_SHAPE_ID, ATTR_INDEX_NOT_SET);
return;
}
VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
VM_ASSERT(cc != vm_cc_empty());
- *attr_value = (attr_index_t)(index + 1) | ((uintptr_t)(dest_shape_id) << SHAPE_FLAG_SHIFT);
+ *attr_value = vm_pack_shape_and_index(dest_shape_id, index);
set_vm_cc_ivar(cc);
}
@@ -490,13 +499,13 @@ vm_cc_ivar_p(const struct rb_callcache *cc)
static inline void
vm_ic_attr_index_set(const rb_iseq_t *iseq, const struct iseq_inline_iv_cache_entry *ic, attr_index_t index, shape_id_t dest_shape_id)
{
- *(uintptr_t *)&ic->value = ((uintptr_t)dest_shape_id << SHAPE_FLAG_SHIFT) | (attr_index_t)(index + 1);
+ *(uintptr_t *)&ic->value = vm_pack_shape_and_index(dest_shape_id, index);
}
static inline void
vm_ic_attr_index_initialize(const struct iseq_inline_iv_cache_entry *ic, shape_id_t shape_id)
{
- *(uintptr_t *)&ic->value = (uintptr_t)shape_id << SHAPE_FLAG_SHIFT;
+ *(uintptr_t *)&ic->value = vm_pack_shape_and_index(shape_id, ATTR_INDEX_NOT_SET);
}
static inline void
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index cf7e554dd9..519455282b 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1209,8 +1209,6 @@ fill_ivar_cache(const rb_iseq_t *iseq, IVC ic, const struct rb_callcache *cc, in
#define ractor_object_incidental_shareable_p(obj, val) \
ractor_incidental_shareable_p(rb_ractor_shareable_p(obj), val)
-#define ATTR_INDEX_NOT_SET (attr_index_t)-1
-
ALWAYS_INLINE(static VALUE vm_getivar(VALUE, ID, const rb_iseq_t *, IVC, const struct rb_callcache *, int, VALUE));
static inline VALUE
vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_callcache *cc, int is_attr, VALUE default_value)