feature-7816-v3.patch

Charlie Somerville, 02/16/2013 06:31 PM

Download (3.72 KB)

View differences:

class.c
80 80
    RCLASS_SUPER(klass) = super;
81 81
    RCLASS_M_TBL(klass) = st_init_numtable();
82 82

  
83
    FL_SET(super, RCLASS_INHERITED_FLAG);
83 84
    OBJ_INFECT(klass, super);
84 85
    return (VALUE)klass;
85 86
}
gc.c
925 925
	break;
926 926
      case T_MODULE:
927 927
      case T_CLASS:
928
	rb_clear_cache_by_class((VALUE)obj);
929 928
        if (RCLASS_M_TBL(obj)) {
930 929
            rb_free_m_table(RCLASS_M_TBL(obj));
931 930
        }
include/ruby/ruby.h
748 748
#define RMODULE_IS_OVERLAID FL_USER2
749 749
#define RMODULE_IS_REFINEMENT FL_USER3
750 750
#define RMODULE_INCLUDED_INTO_REFINEMENT FL_USER4
751
#define RCLASS_INHERITED_FLAG FL_USER5
751 752

  
752 753
struct RFloat {
753 754
    struct RBasic basic;
insns.def
975 975
		  class_iseq->local_size, 0);
976 976
    RESTORE_REGS();
977 977

  
978
    INC_VM_STATE_VERSION();
979 978
    NEXT_INSN();
980 979
}
981 980

  
vm.c
2011 2011
    if (!is_singleton && noex == NOEX_MODFUNC) {
2012 2012
	rb_add_method(rb_singleton_class(klass), id, VM_METHOD_TYPE_ISEQ, miseq, NOEX_PUBLIC);
2013 2013
    }
2014
    INC_VM_STATE_VERSION();
2015 2014
}
2016 2015

  
2017 2016
#define REWIND_CFP(expr) do { \
......
2206 2205
static VALUE usage_analysis_register_stop(VALUE self);
2207 2206
#endif
2208 2207

  
2208
/*
2209
 *  call-seq:
2210
 *     RubyVM.state_version ->	int
2211
 *
2212
 *  Returns the current VM state version. The state version is used for
2213
 *  invalidating inline method and constant caches.
2214
 *
2215
 *  The state version is not guaranteed to be monotonic and may wrap around in
2216
 *  long running processes.
2217
 */
2218
static VALUE
2219
vm_state_version()
2220
{
2221
    return INT2FIX(ruby_vm_global_state_version);
2222
}
2223

  
2209 2224
void
2210 2225
Init_VM(void)
2211 2226
{
......
2217 2232
    rb_cRubyVM = rb_define_class("RubyVM", rb_cObject);
2218 2233
    rb_undef_alloc_func(rb_cRubyVM);
2219 2234
    rb_undef_method(CLASS_OF(rb_cRubyVM), "new");
2235
    rb_define_singleton_method(rb_cRubyVM, "state_version", vm_state_version, 0);
2220 2236

  
2221 2237
    /* FrozenCore (hidden) */
2222 2238
    fcore = rb_class_new(rb_cBasicObject);
vm_method.c
220 220
    }
221 221
}
222 222

  
223
static inline rb_method_entry_t*
224
search_method(VALUE klass, ID id, VALUE *defined_class_ptr);
225

  
223 226
static rb_method_entry_t *
224 227
rb_method_entry_make(VALUE klass, ID mid, rb_method_type_t type,
225 228
		     rb_method_definition_t *def, rb_method_flag_t noex)
......
315 318

  
316 319
    me = ALLOC(rb_method_entry_t);
317 320

  
318
    rb_clear_cache_by_id(mid);
321
    if (search_method(klass, mid, NULL) /* clear cache if overriding existing method */
322
	|| FL_TEST(klass, RCLASS_INHERITED_FLAG) /* or this class has subclasses */
323
	|| RB_TYPE_P(klass, T_MODULE) /* or this is a module */)
324
    {
325
        rb_clear_cache_by_id(mid);
326
    }
319 327

  
320 328
    me->flag = NOEX_WITH_SAFE(noex);
321 329
    me->mark = 0;
......
555 563

  
556 564
    ent = cache + EXPR1(klass, id);
557 565
    if (ent->filled_version == GET_VM_STATE_VERSION() &&
558
	ent->mid == id && ent->klass == klass) {
566
	ent->mid == id && ent->klass == klass && ent->me) {
559 567
	if (defined_class_ptr)
560 568
	    *defined_class_ptr = ent->defined_class;
561 569
	return ent->me;