Skip to content

Commit c95c820

Browse files
committed
ZJIT: Only add single ractor patchpoint to class/module receivers
1 parent 1191458 commit c95c820

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

zjit/src/hir.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,10 +1668,18 @@ impl Function {
16681668
} else if def_type == VM_METHOD_TYPE_IVAR && args.is_empty() {
16691669
self.push_insn(block, Insn::PatchPoint { invariant: Invariant::MethodRedefined { klass, method: mid, cme }, state });
16701670
if let Some(profiled_type) = profiled_type {
1671-
self_val = self.push_insn(block, Insn::GuardType { val: self_val, guard_type: Type::from_profiled_type(profiled_type), state });
1671+
let guard_type = Type::from_profiled_type(profiled_type);
1672+
self_val = self.push_insn(block, Insn::GuardType { val: self_val, guard_type, state });
1673+
1674+
// Check if we're accessing ivars of a Class or Module object as they require single-ractor mode
1675+
if unsafe { rb_zjit_singleton_class_p(klass) } {
1676+
let attached = unsafe { rb_class_attached_object(klass) };
1677+
if unsafe { RB_TYPE_P(attached, RUBY_T_CLASS) || RB_TYPE_P(attached, RUBY_T_MODULE) } {
1678+
self.push_insn(block, Insn::PatchPoint { invariant: Invariant::SingleRactorMode, state });
1679+
}
1680+
}
16721681
}
16731682
let id = unsafe { get_cme_def_body_attr_id(cme) };
1674-
self.push_insn(block, Insn::PatchPoint { invariant: Invariant::SingleRactorMode, state });
16751683
let getivar = self.push_insn(block, Insn::GetIvar { self_val, id, state });
16761684
self.make_equal_to(insn_id, getivar);
16771685
} else {

0 commit comments

Comments
 (0)