ruby-changes:72177
From: Takashi <ko1@a...>
Date: Thu, 16 Jun 2022 07:57:52 +0900 (JST)
Subject: [ruby-changes:72177] 5310147bb8 (master): MJIT: Handle JIT failure properly
https://git.ruby-lang.org/ruby.git/commit/?id=5310147bb8 From 5310147bb826424059f258b76b37bebdc0abbc63 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun <takashikkbn@g...> Date: Wed, 15 Jun 2022 15:57:27 -0700 Subject: MJIT: Handle JIT failure properly --- mjit.c | 10 +++++++++- test/ruby/test_mjit.rb | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/mjit.c b/mjit.c index c94a2cfc86..3bceccfb4c 100644 --- a/mjit.c +++ b/mjit.c @@ -244,7 +244,15 @@ check_unit_queue(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L244 current_cc_ms = real_ms_time(); current_cc_unit = unit; current_cc_pid = start_mjit_compile(unit); - // TODO: handle -1 + + // JIT failure + if (current_cc_pid == -1) { + current_cc_pid = 0; + current_cc_unit->iseq->body->jit_func = (mjit_func_t)NOT_COMPILED_JIT_ISEQ_FUNC; + current_cc_unit = NULL; + return; + } + if (mjit_opts.wait) { mjit_wait(unit->iseq->body); } diff --git a/test/ruby/test_mjit.rb b/test/ruby/test_mjit.rb index 09503456e1..7fb984a024 100644 --- a/test/ruby/test_mjit.rb +++ b/test/ruby/test_mjit.rb @@ -1198,6 +1198,18 @@ class TestMJIT < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_mjit.rb#L1198 end end if defined?(fork) + def test_jit_failure + _, err = eval_with_jit("#{<<~"begin;"}\n#{<<~"end;"}", min_calls: 1, verbose: 1) + begin; + 1.times do + class A + end + end + end; + assert_match(/^MJIT warning: .+ unsupported instruction: defineclass/, err) + assert_match(/^JIT failure: block in <main>/, err) + end + private # The shortest way to test one proc -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/