Extract vm_ic_entry API to mimic vm_cc behavior

This commit is contained in:
Jemma Issroff 2022-06-06 10:48:42 -04:00 коммит произвёл Aaron Patterson
Родитель f240e28dfe
Коммит ecff334995
4 изменённых файлов: 39 добавлений и 21 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -9,6 +9,7 @@
*/
#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)
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)
*(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)
{

Просмотреть файл

@ -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);
@ -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);
@ -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");
@ -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);

Просмотреть файл

@ -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;
@ -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,