diff options
| author | Takashi Kokubun <takashi.kokubun@shopify.com> | 2025-08-11 13:18:52 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-11 13:18:52 -0700 |
| commit | 6968668570fd43065cf4b9b4a1063a6b3fe888aa (patch) | |
| tree | fb8327eb241cc12209e58e23e63a845e97d47915 | |
| parent | 6e3790b17f1b58d67616ef1f9b899bc4af91d334 (diff) | |
ZJIT: Add RubyVM::ZJIT.enabled? (#14159)
Co-authored-by: Max Bernstein <tekknolagi@gmail.com>
| -rw-r--r-- | test/ruby/test_zjit.rb | 34 | ||||
| -rw-r--r-- | zjit.rb | 9 |
2 files changed, 33 insertions, 10 deletions
diff --git a/test/ruby/test_zjit.rb b/test/ruby/test_zjit.rb index c86ac62a9f..bf43fd1324 100644 --- a/test/ruby/test_zjit.rb +++ b/test/ruby/test_zjit.rb @@ -9,6 +9,15 @@ require_relative '../lib/jit_support' return unless JITSupport.zjit_supported? class TestZJIT < Test::Unit::TestCase + def test_enabled + assert_runs 'false', <<~RUBY, zjit: false + RubyVM::ZJIT.enabled? + RUBY + assert_runs 'true', <<~RUBY, zjit: true + RubyVM::ZJIT.enabled? + RUBY + end + def test_call_itself assert_compiles '42', <<~RUBY, call_threshold: 2 def test = 42.itself @@ -1547,14 +1556,23 @@ class TestZJIT < Test::Unit::TestCase end # Run a Ruby process with ZJIT options and a pipe for writing test results - def eval_with_jit(script, call_threshold: 1, num_profiles: 1, stats: false, debug: true, timeout: 1000, pipe_fd:) - args = [ - "--disable-gems", - "--zjit-call-threshold=#{call_threshold}", - "--zjit-num-profiles=#{num_profiles}", - ] - args << "--zjit-stats" if stats - args << "--zjit-debug" if debug + def eval_with_jit( + script, + call_threshold: 1, + num_profiles: 1, + zjit: true, + stats: false, + debug: true, + timeout: 1000, + pipe_fd: + ) + args = ["--disable-gems"] + if zjit + args << "--zjit-call-threshold=#{call_threshold}" + args << "--zjit-num-profiles=#{num_profiles}" + args << "--zjit-stats" if stats + args << "--zjit-debug" if debug + end args << "-e" << script_shell_encode(script) pipe_r, pipe_w = IO.pipe # Separate thread so we don't deadlock when @@ -14,7 +14,12 @@ module RubyVM::ZJIT end class << RubyVM::ZJIT - # Return ZJIT statistics as a Hash + # Check if \ZJIT is enabled + def enabled? + Primitive.cexpr! 'RBOOL(rb_zjit_enabled_p)' + end + + # Return \ZJIT statistics as a Hash def stats stats = Primitive.rb_zjit_stats @@ -26,7 +31,7 @@ class << RubyVM::ZJIT stats end - # Get the summary of ZJIT statistics as a String + # Get the summary of \ZJIT statistics as a String def stats_string buf = +'' stats = self.stats |
