Skip to content

Commit

Permalink
Extract vm_ic_entry API to mimic vm_cc behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jemmaissroff authored and tenderlove committed Jul 18, 2022
1 parent f240e28 commit ecff334
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
1 change: 1 addition & 0 deletions common.mk
Expand Up @@ -3499,6 +3499,7 @@ debug.$(OBJEXT): $(CCAN_DIR)/list/list.h
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
Expand Down
20 changes: 20 additions & 0 deletions vm_callinfo.h
Expand Up @@ -9,6 +9,7 @@
*/

#include "debug_counter.h"
#include "internal/class.h"

enum vm_call_flag_bits {
VM_CALL_ARGS_SPLAT_bit, /* m(*args) */
Expand Down Expand Up @@ -363,6 +364,18 @@ vm_cc_attr_index_p(const struct rb_callcache *cc)
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)
{
Expand Down Expand Up @@ -416,6 +429,13 @@ vm_cc_attr_index_set(const struct rb_callcache *cc, int index)
*(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)
{
Expand Down
15 changes: 6 additions & 9 deletions vm_insnhelper.c
Expand Up @@ -1104,8 +1104,7 @@ fill_ivar_cache(const rb_iseq_t *iseq, IVC ic, const struct rb_callcache *cc, in
{
// 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);
Expand All @@ -1124,9 +1123,8 @@ vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_call
}
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);

Expand Down Expand Up @@ -1208,8 +1206,7 @@ vm_setivar_slowpath(VALUE obj, ID id, VALUE val, const rb_iseq_t *iseq, IVC ic,

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");
Expand Down Expand Up @@ -1257,9 +1254,9 @@ vm_setivar(VALUE obj, ID id, VALUE val, const rb_iseq_t *iseq, IVC ic, const str
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);
Expand Down
24 changes: 12 additions & 12 deletions yjit/src/cruby_bindings.inc.rs
Expand Up @@ -657,6 +657,18 @@ extern "C" {
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;
Expand Down Expand Up @@ -714,18 +726,6 @@ extern "C" {
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,
Expand Down

0 comments on commit ecff334

Please sign in to comment.