refinement $B$rF3F~$9$k$H$-$N@-G=$KBP$9$k(B excuse $B$,!V(Bmethod cache
$B$KKX$I$"(B
$B$?$k$+$i!$!J(Brefinement
$B$K4X78L5$$ItJ,$N!K@-G=Dc2<$O$J$$!W$H$$$&OC$@$C$?(B
$B$H;W$&$N$G$9$,!$:#2s$N%3!<%I$r8+$k$H!$$=$l$J$j$K%a%=%C%IC5:w%3%9%H$,A}$((B
$B$=$&$J5$$,$9$k$s$G$9$,!$$$$+$,$G$7$g$&$+!%(B
$B:rF|AjCL$5$;$FD:$$$?$H$*$j!$<BAu$H$7$F$O(B refinement $B$O(B
- $B%a%=%C%IC5:w$+$i(B refinement $B4X78$N=hM}$r:o=|(B
- $BC5:w$7$?%a%=%C%I$,(B refine $B$5$l$?%a%=%C%I$@$C$?$i!$(B
$B$=$N;~E@$GE,@Z$J%a%=%C%I$r8F$S=P$9(B
$B$N$,NI$$$H;W$$$^$9!%(B
$B$A$g$C$H!$8=>u$N%3!<%I$O<u$1F~$l$i$l$^$;$s!%(B
-------- Original Message --------
Subject: [ruby-changes:25559] shugo:r37616 (trunk): * vm_core.h
(rb_call_info_t::refinements), compile.c (new_callinfo):
Date: Sun, 11 Nov 2012 11:42:16 +0900 (JST)
From: shugo [email protected]
Reply-To: [email protected]
To: [email protected]
shugo 2012-11-11 11:42:04 +0900 (Sun, 11 Nov 2012)
New Revision: 37616
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37616
Log:
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo):
add a new field for inline method cache.
* vm_insnhelper.c (vm_search_method): check
rb_call_info_t::refinements
not to confuse inline method cache when module_eval is used with
refinements.
* test/ruby/test_refinement.rb: related test.
Modified files:
trunk/ChangeLog
trunk/compile.c
trunk/test/ruby/test_refinement.rb
trunk/vm_core.h
trunk/vm_insnhelper.c
Index: ChangeLog
— ChangeLog (revision 37615)
+++ ChangeLog (revision 37616)
@@ -1,3 +1,14 @@
+Sun Nov 11 11:36:19 2012 Shugo M. [email protected]
+
-
- vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo):
- add a new field for inline method cache.
-
- vm_insnhelper.c (vm_search_method): check
rb_call_info_t::refinements
- vm_insnhelper.c (vm_search_method): check
- not to confuse inline method cache when module_eval is used with
- refinements.
-
- test/ruby/test_refinement.rb: related test.
Sun Nov 11 08:45:45 2012 Martin D. [email protected]
- ruby.c: removed a comma before “before”
Index: vm_core.h
===================================================================
— vm_core.h (revision 37615)
+++ vm_core.h (revision 37616)
@@ -153,6 +153,7 @@
/* inline cache: keys */
VALUE vmstat;
VALUE klass;
-
VALUE refinements;
/* inline cache: values */
const rb_method_entry_t *me;
Index: compile.c
===================================================================
— compile.c (revision 37615)
+++ compile.c (revision 37616)
@@ -954,6 +954,7 @@
}
}
ci->vmstat = 0; -
ci->refinements = Qundef;
ci->blockptr = 0;
ci->recv = Qundef;
ci->call = 0; /* TODO: should set default function? */
Index: vm_insnhelper.c
===================================================================
— vm_insnhelper.c (revision 37615)
+++ vm_insnhelper.c (revision 37616)
@@ -843,19 +843,30 @@
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 && -
/* cache hit! */refinements == ci->refinements)) {
}
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->klass = klass;&ci->defined_class);
- 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->call = vm_call_general;&ci->defined_class);
ci->klass = klass;
#endif
Index: test/ruby/test_refinement.rb
===================================================================
— test/ruby/test_refinement.rb (revision 37615)
+++ test/ruby/test_refinement.rb (revision 37616)
@@ -685,4 +685,28 @@
assert_equal(“#refinement:#{c.inspect}@#{m.inspect}”,
m.refinements[c].inspect)
end - module InlineMethodCache
- class C
-
def foo
-
"original"
-
end
- end
- module M
-
refine C do
-
def foo
-
"refined"
-
end
-
end
- end
- end
- def test_inline_method_cache
- c = InlineMethodCache::C.new
- f = Proc.new { c.foo }
- assert_equal(“original”, f.call)
- assert_equal(“refined”, InlineMethodCache::M.module_eval(&f))
- assert_equal(“original”, f.call)
- end
end