From 60d75a5665e808e7491ea6bca9c02245852ea495 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sun, 30 Apr 2023 00:38:10 -0700 Subject: [PATCH] MJIT: Check if self is T_OBJECT before opt_pc jump --- lib/ruby_vm/mjit/compiler.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/ruby_vm/mjit/compiler.rb b/lib/ruby_vm/mjit/compiler.rb index a9f2aeda8d..81022cd0a8 100644 --- a/lib/ruby_vm/mjit/compiler.rb +++ b/lib/ruby_vm/mjit/compiler.rb @@ -75,6 +75,13 @@ class RubyVM::MJIT::Compiler # :nodoc: all src << "#undef GET_SELF\n" src << "#define GET_SELF() cfp_self\n" + # Generate merged ivar guards first if needed + if !status.compile_info.disable_ivar_cache && using_ivar?(iseq.body) + src << " if (UNLIKELY(!RB_TYPE_P(GET_SELF(), T_OBJECT))) {" + src << " goto ivar_cancel;\n" + src << " }\n" + end + # Simulate `opt_pc` in setup_parameters_complex. Other PCs which may be passed by catch tables # are not considered since vm_exec doesn't call jit_exec for catch tables. if iseq.body.param.flags.has_opt @@ -88,13 +95,6 @@ class RubyVM::MJIT::Compiler # :nodoc: all src << " }\n" end - # Generate merged ivar guards first if needed - if !status.compile_info.disable_ivar_cache && using_ivar?(iseq.body) - src << " if (UNLIKELY(!RB_TYPE_P(GET_SELF(), T_OBJECT))) {" - src << " goto ivar_cancel;\n" - src << " }\n" - end - compile_insns(0, 0, status, iseq.body, src) compile_cancel_handler(src, iseq.body, status) src << "#undef GET_SELF\n"