diff options
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r-- | vm_insnhelper.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 3f09991ba2..8c01a62d92 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -976,12 +976,20 @@ vm_getivar(VALUE obj, ID id, IC ic, struct rb_call_cache *cc, int is_attr) if (index < ROBJECT_NUMIV(obj)) { val = ROBJECT_IVPTR(obj)[index]; } - if (!is_attr) { - ic->ic_value.index = index; - ic->ic_serial = RCLASS_SERIAL(RBASIC(obj)->klass); - } - else { /* call_info */ - cc->aux.index = (int)index + 1; + if (is_attr) { /* call_info */ + cc->aux.index = (int)index + 1; + } + else { /* getinstancevariable */ + if (ic->ic_serial == RUBY_VM_CLASS_SERIAL_UNSET) { + /* set ic_serial only for the first time */ + ic->ic_value.index = index; + ic->ic_serial = RCLASS_SERIAL(RBASIC(obj)->klass); + } + else if (ic->ic_serial != RUBY_VM_CLASS_SERIAL_INVALID) { + /* never use cache for another class, to avoid race condition with MJIT worker + and to reduce the number of JIT cancellations by code generated for IC hit. */ + ic->ic_serial = RUBY_VM_CLASS_SERIAL_INVALID; + } } } } |