Skip to content

Instantly share code, notes, and snippets.

@shugo
Created November 11, 2012 02:04
Show Gist options
  • Save shugo/4053359 to your computer and use it in GitHub Desktop.
Save shugo/4053359 to your computer and use it in GitHub Desktop.
fix inline method cache for refinements
diff --git a/compile.c b/compile.c
index 16bfcef..eb824ca 100644
--- a/compile.c
+++ b/compile.c
@@ -954,6 +954,7 @@ new_callinfo(rb_iseq_t *iseq, ID mid, int argc, VALUE block, unsigned long flag)
}
}
ci->vmstat = 0;
+ ci->refinements = Qundef;
ci->blockptr = 0;
ci->recv = Qundef;
ci->call = 0; /* TODO: should set default function? */
diff --git a/vm_core.h b/vm_core.h
index dd9e387..82400a3 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -153,6 +153,7 @@ typedef struct rb_call_info_struct {
/* inline cache: keys */
VALUE vmstat;
VALUE klass;
+ VALUE refinements;
/* inline cache: values */
const rb_method_entry_t *me;
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 554aad4..cf64c14 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -843,19 +843,30 @@ static void
vm_search_method(rb_call_info_t *ci, VALUE recv)
{
VALUE klass = CLASS_OF(recv);
+ NODE *cref = rb_vm_cref();
+ VALUE refinements = Qnil;
+
+ if (cref && !NIL_P(cref->nd_refinements)) {
+ refinements = cref->nd_refinements;
+ }
#if OPT_INLINE_METHOD_CACHE
- if (LIKELY(GET_VM_STATE_VERSION() == ci->vmstat && klass == ci->klass)) {
+ if (LIKELY(GET_VM_STATE_VERSION() == ci->vmstat && klass == ci->klass &&
+ refinements == ci->refinements)) {
/* cache hit! */
}
else {
- ci->me = rb_method_entry(klass, ci->mid, &ci->defined_class);
+ ci->me = rb_method_entry_get_with_refinements(refinements, klass,
+ ci->mid,
+ &ci->defined_class);
ci->klass = klass;
+ ci->refinements = refinements;
ci->vmstat = GET_VM_STATE_VERSION();
ci->call = vm_call_general;
}
#else
- ci->me = rb_method_entry(klass, ci->mid, &ci->defined_class);
+ ci->me = rb_method_entry_get_with_refinements(refinements, klass, ci->mid,
+ &ci->defined_class);
ci->call = vm_call_general;
ci->klass = klass;
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment