1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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]
This commit is contained in:
Koichi Sasada 2021-02-19 14:57:59 +09:00
parent d260cbe295
commit 9c769575bf
Notes: git 2021-02-19 16:54:53 +09:00
2 changed files with 16 additions and 7 deletions

View file

@ -61,5 +61,16 @@ class TestMethodCache < Test::Unit::TestCase
assert_equal :c2, c3.new.foo assert_equal :c2, c3.new.foo
end 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 end

View file

@ -129,17 +129,15 @@ rb_clear_constant_cache(void)
} }
static void static void
invalidate_negative_cache(ID mid, bool invalidate_cme) invalidate_negative_cache(ID mid)
{ {
const rb_callable_method_entry_t *cme; const rb_callable_method_entry_t *cme;
rb_vm_t *vm = GET_VM(); rb_vm_t *vm = GET_VM();
if (rb_id_table_lookup(vm->negative_cme_table, mid, (VALUE *)&cme)) { if (rb_id_table_lookup(vm->negative_cme_table, mid, (VALUE *)&cme)) {
rb_id_table_delete(vm->negative_cme_table, mid); rb_id_table_delete(vm->negative_cme_table, mid);
if (invalidate_cme) { vm_cme_invalidate((rb_callable_method_entry_t *)cme);
vm_cme_invalidate((rb_callable_method_entry_t *)cme); RB_DEBUG_COUNTER_INC(cc_invalidate_negative);
RB_DEBUG_COUNTER_INC(cc_invalidate_negative);
}
} }
} }
@ -162,7 +160,7 @@ clear_method_cache_by_id_in_class(VALUE klass, ID mid)
// invalidate CCs // invalidate CCs
if (cc_tbl && rb_id_table_lookup(cc_tbl, mid, (VALUE *)&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_vm_ccs_free(ccs);
rb_id_table_delete(cc_tbl, mid); rb_id_table_delete(cc_tbl, mid);
RB_DEBUG_COUNTER_INC(cc_invalidate_leaf_ccs); RB_DEBUG_COUNTER_INC(cc_invalidate_leaf_ccs);
@ -211,7 +209,7 @@ clear_method_cache_by_id_in_class(VALUE klass, ID mid)
RB_DEBUG_COUNTER_INC(cc_invalidate_tree); RB_DEBUG_COUNTER_INC(cc_invalidate_tree);
} }
else { else {
invalidate_negative_cache(mid, true); invalidate_negative_cache(mid);
} }
} }
} }