Skip to content

Commit

Permalink
try gccct if cc misses
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Apr 25, 2024
1 parent 0fa795a commit bb5fdce
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
29 changes: 18 additions & 11 deletions vm_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,18 +440,8 @@ scope_to_ci(call_type scope, ID mid, int argc, struct rb_callinfo *ci)
}

static inline const struct rb_callcache *
gccct_method_search(rb_execution_context_t *ec, VALUE recv, ID mid, const struct rb_callinfo *ci)
gccct_method_search_klass(rb_execution_context_t *ec, VALUE klass, ID mid, const struct rb_callinfo *ci)
{
VALUE klass;

if (!SPECIAL_CONST_P(recv)) {
klass = RBASIC_CLASS(recv);
if (UNLIKELY(!klass)) uncallable_object(recv, mid);
}
else {
klass = CLASS_OF(recv);
}

// search global method cache
unsigned int index = (unsigned int)(gccct_hash(klass, mid) % VM_GLOBAL_CC_CACHE_TABLE_SIZE);
rb_vm_t *vm = rb_ec_vm_ptr(ec);
Expand All @@ -475,9 +465,26 @@ gccct_method_search(rb_execution_context_t *ec, VALUE recv, ID mid, const struct
}

RB_DEBUG_COUNTER_INC(gccct_miss);

return gccct_method_search_slowpath(vm, klass, index, ci);
}

static inline const struct rb_callcache *
gccct_method_search(rb_execution_context_t *ec, VALUE recv, ID mid, const struct rb_callinfo *ci)
{
VALUE klass;

if (!SPECIAL_CONST_P(recv)) {
klass = RBASIC_CLASS(recv);
if (UNLIKELY(!klass)) uncallable_object(recv, mid);
}
else {
klass = CLASS_OF(recv);
}

return gccct_method_search_klass(ec, klass, mid, ci);
}

/**
* @internal
* calls the specified method.
Expand Down
5 changes: 5 additions & 0 deletions vm_insnhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,7 @@ vm_search_method_slowpath0(VALUE cd_owner, struct rb_call_data *cd, VALUE klass)
return cc;
}

static inline const struct rb_callcache * gccct_method_search_klass(rb_execution_context_t *ec, VALUE klass, ID mid, const struct rb_callinfo *ci); // vm_eval.c
ALWAYS_INLINE(static const struct rb_callcache *vm_search_method_fastpath(VALUE cd_owner, struct rb_call_data *cd, VALUE klass));
static const struct rb_callcache *
vm_search_method_fastpath(VALUE cd_owner, struct rb_call_data *cd, VALUE klass)
Expand All @@ -2256,6 +2257,10 @@ vm_search_method_fastpath(VALUE cd_owner, struct rb_call_data *cd, VALUE klass)
}
else {
RB_DEBUG_COUNTER_INC(mc_inline_miss_klass);

if (vm_ci_mid(cd->ci) == idInitialize) {
return gccct_method_search_klass(GET_EC(), klass, idInitialize, cd->ci);
}
}
#endif

Expand Down

0 comments on commit bb5fdce

Please sign in to comment.