From 22d944c8b76be04dc437100c46626db5fe9dd7f0 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sun, 5 Mar 2023 22:09:57 -0800 Subject: Avoid crashing at a random ISEQ access [Feature #19420] --- lib/ruby_vm/mjit/exit_compiler.rb | 2 +- mjit.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ruby_vm/mjit/exit_compiler.rb b/lib/ruby_vm/mjit/exit_compiler.rb index b664d795b0..1d704a8dca 100644 --- a/lib/ruby_vm/mjit/exit_compiler.rb +++ b/lib/ruby_vm/mjit/exit_compiler.rb @@ -83,7 +83,7 @@ module RubyVM::MJIT def compile_branch_stub(ctx, asm, branch_stub, target0_p) # Call rb_mjit_branch_stub_hit iseq = branch_stub.iseq - if C.imemo_type(iseq) != C.imemo_iseq # Guard against ISEQ GC at random moments + if C.mjit_opts.dump_disasm && C.imemo_type(iseq) == C.imemo_iseq # Guard against ISEQ GC at random moments asm.comment("branch stub hit: #{iseq.body.location.label}@#{C.rb_iseq_path(iseq)}:#{iseq_lineno(iseq, target0_p ? branch_stub.target0.pc : branch_stub.target1.pc)}") end asm.mov(:rdi, to_value(branch_stub)) diff --git a/mjit.c b/mjit.c index b34ae461ef..fcf644c303 100644 --- a/mjit.c +++ b/mjit.c @@ -310,7 +310,11 @@ rb_mjit_collect_vm_usage_insn(int insn) #endif // YJIT_STATS +extern VALUE rb_gc_enable(void); +extern VALUE rb_gc_disable(void); + #define WITH_MJIT_ISOLATED(stmt) do { \ + VALUE was_disabled = rb_gc_disable(); \ rb_hook_list_t *global_hooks = rb_ec_ractor_hooks(GET_EC()); \ rb_mjit_global_events = global_hooks->events; \ global_hooks->events = 0; \ @@ -321,6 +325,7 @@ rb_mjit_collect_vm_usage_insn(int insn) mjit_call_p = (mjit_cancel_p ? false : original_call_p); \ mjit_stats_p = mjit_opts.stats; \ global_hooks->events = rb_mjit_global_events; \ + if (!was_disabled) rb_gc_enable(); \ } while (0); void -- cgit v1.2.3