Skip to content

ZJIT: Add RubyVM::ZJIT.enabled? #14159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions test/ruby/test_zjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
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
Expand Down Expand Up @@ -1547,14 +1556,23 @@ def assert_runs(expected, test_script, insns: [], assert_compiles: false, **opts
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
Expand Down
9 changes: 7 additions & 2 deletions zjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -26,7 +31,7 @@ def stats
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
Expand Down
Loading