ruby-changes:65291
From: Koichi <ko1@a...>
Date: Fri, 19 Feb 2021 16:54:47 +0900 (JST)
Subject: [ruby-changes:65291] 9c769575bf (master): invalidate negative cache any time.
https://git.ruby-lang.org/ruby.git/commit/?id=9c769575bf From 9c769575bfa2a5c9e7078eb2840bba640dc46077 Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Fri, 19 Feb 2021 14:57:59 +0900 Subject: invalidate negative cache any time. negative cache on a class which does not have subclasses was not invalidated, but it should be invalidated because other classes can cache this negative cache. [Bug #17553] --- test/ruby/test_method_cache.rb | 11 +++++++++++ vm_method.c | 12 +++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/test/ruby/test_method_cache.rb b/test/ruby/test_method_cache.rb index a8e7e22..2ed89e4 100644 --- a/test/ruby/test_method_cache.rb +++ b/test/ruby/test_method_cache.rb @@ -61,5 +61,16 @@ class TestMethodCache < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method_cache.rb#L61 assert_equal :c2, c3.new.foo end + + def test_negative_cache_with_and_without_subclasses + c0 = Class.new{} + c1 = Class.new(c0){} + c0.new.foo rescue nil + c1.new.foo rescue nil + c1.module_eval{ def foo = :c1 } + c0.module_eval{ def foo = :c0 } + + assert_equal :c0, c0.new.foo + end end diff --git a/vm_method.c b/vm_method.c index a3bebae..2573e70 100644 --- a/vm_method.c +++ b/vm_method.c @@ -129,17 +129,15 @@ rb_clear_constant_cache(void) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L129 } static void -invalidate_negative_cache(ID mid, bool invalidate_cme) +invalidate_negative_cache(ID mid) { const rb_callable_method_entry_t *cme; rb_vm_t *vm = GET_VM(); if (rb_id_table_lookup(vm->negative_cme_table, mid, (VALUE *)&cme)) { rb_id_table_delete(vm->negative_cme_table, mid); - if (invalidate_cme) { - vm_cme_invalidate((rb_callable_method_entry_t *)cme); - RB_DEBUG_COUNTER_INC(cc_invalidate_negative); - } + vm_cme_invalidate((rb_callable_method_entry_t *)cme); + RB_DEBUG_COUNTER_INC(cc_invalidate_negative); } } @@ -162,7 +160,7 @@ clear_method_cache_by_id_in_class(VALUE klass, ID mid) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L160 // invalidate CCs if (cc_tbl && rb_id_table_lookup(cc_tbl, mid, (VALUE *)&ccs)) { - if (NIL_P(ccs->cme->owner)) invalidate_negative_cache(mid, false); + if (NIL_P(ccs->cme->owner)) invalidate_negative_cache(mid); rb_vm_ccs_free(ccs); rb_id_table_delete(cc_tbl, mid); RB_DEBUG_COUNTER_INC(cc_invalidate_leaf_ccs); @@ -211,7 +209,7 @@ clear_method_cache_by_id_in_class(VALUE klass, ID mid) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L209 RB_DEBUG_COUNTER_INC(cc_invalidate_tree); } else { - invalidate_negative_cache(mid, true); + invalidate_negative_cache(mid); } } } -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/