Project

General

Profile

Feature #7816 » dont-invalidate-method-cache-when-defining-new-singleton-methods.patch

Anonymous, 02/10/2013 02:13 AM

View differences:

.gitignore
inst
*-*-*.def
*.a
*.bak
class.c
RCLASS_SUPER(klass) = super;
RCLASS_M_TBL(klass) = st_init_numtable();
FL_SET(super, RCLASS_INHERITED_FLAG);
OBJ_INFECT(klass, super);
return (VALUE)klass;
}
include/ruby/ruby.h
#define RMODULE_IS_OVERLAID FL_USER2
#define RMODULE_IS_REFINEMENT FL_USER3
#define RMODULE_INCLUDED_INTO_REFINEMENT FL_USER4
#define RCLASS_INHERITED_FLAG FL_USER5
struct RFloat {
struct RBasic basic;
insns.def
class_iseq->local_size, 0);
RESTORE_REGS();
INC_VM_STATE_VERSION();
NEXT_INSN();
}
object.c
/*
* call-seq:
* Class#has_subclass? -> bool
*
* Returns true if the class has ever been subclassed.
*
* Object.has_subclass? #=> true
* Class.new.has_subclass? #=> false
*/
VALUE
rb_class_has_subclass_p(VALUE klass)
{
return FL_TEST(klass, RCLASS_INHERITED_FLAG) ? Qtrue : Qfalse;
}
/*
* call-seq:
* Hash(arg) -> hash
*
* Converts <i>arg</i> to a <code>Hash</code> by calling
......
rb_define_method(rb_cClass, "allocate", rb_obj_alloc, 0);
rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
rb_define_method(rb_cClass, "has_subclass?", rb_class_has_subclass_p, 0);
rb_define_method(rb_cClass, "initialize", rb_class_initialize, -1);
rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0);
rb_define_alloc_func(rb_cClass, rb_class_s_alloc);
vm.c
if (!is_singleton && noex == NOEX_MODFUNC) {
rb_add_method(rb_singleton_class(klass), id, VM_METHOD_TYPE_ISEQ, miseq, NOEX_PUBLIC);
}
INC_VM_STATE_VERSION();
}
#define REWIND_CFP(expr) do { \
......
static VALUE usage_analysis_register_stop(VALUE self);
#endif
/*
* call-seq:
* RubyVM.state_version -> int
*
* Returns the current VM state version. The state version is used for
* invalidating inline method and constant caches.
*
* The state version is not guaranteed to be monotonic and may wrap around in
* long running processes.
*/
static VALUE
vm_state_version()
{
return INT2FIX(ruby_vm_global_state_version);
}
void
Init_VM(void)
{
......
rb_cRubyVM = rb_define_class("RubyVM", rb_cObject);
rb_undef_alloc_func(rb_cRubyVM);
rb_undef_method(CLASS_OF(rb_cRubyVM), "new");
rb_define_singleton_method(rb_cRubyVM, "state_version", vm_state_version, 0);
/* FrozenCore (hidden) */
fcore = rb_class_new(rb_cBasicObject);
vm_method.c
}
}
static inline rb_method_entry_t*
search_method(VALUE klass, ID id, VALUE *defined_class_ptr);
static rb_method_entry_t *
rb_method_entry_make(VALUE klass, ID mid, rb_method_type_t type,
rb_method_definition_t *def, rb_method_flag_t noex)
......
me = ALLOC(rb_method_entry_t);
rb_clear_cache_by_id(mid);
if (search_method(klass, mid, NULL) /* clear cache if overriding existing method */
|| FL_TEST(klass, RCLASS_INHERITED_FLAG) /* or this class has subclasses */
|| (RB_TYPE_P(klass, T_MODULE)) /* or this is a module */)
{
rb_clear_cache_by_id(mid);
}
me->flag = NOEX_WITH_SAFE(noex);
me->mark = 0;
......
ent = cache + EXPR1(klass, id);
if (ent->filled_version == GET_VM_STATE_VERSION() &&
ent->mid == id && ent->klass == klass) {
ent->mid == id && ent->klass == klass && ent->me) {
if (defined_class_ptr)
*defined_class_ptr = ent->defined_class;
return ent->me;
(1-1/3)