Skip to content

Commit 6968668

Browse files
k0kubuntekknolagi
andauthored
ZJIT: Add RubyVM::ZJIT.enabled? (ruby#14159)
Co-authored-by: Max Bernstein <tekknolagi@gmail.com>
1 parent 6e3790b commit 6968668

2 files changed

Lines changed: 33 additions & 10 deletions

File tree

test/ruby/test_zjit.rb

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
return unless JITSupport.zjit_supported?
1010

1111
class TestZJIT < Test::Unit::TestCase
12+
def test_enabled
13+
assert_runs 'false', <<~RUBY, zjit: false
14+
RubyVM::ZJIT.enabled?
15+
RUBY
16+
assert_runs 'true', <<~RUBY, zjit: true
17+
RubyVM::ZJIT.enabled?
18+
RUBY
19+
end
20+
1221
def test_call_itself
1322
assert_compiles '42', <<~RUBY, call_threshold: 2
1423
def test = 42.itself
@@ -1547,14 +1556,23 @@ def assert_runs(expected, test_script, insns: [], assert_compiles: false, **opts
15471556
end
15481557

15491558
# Run a Ruby process with ZJIT options and a pipe for writing test results
1550-
def eval_with_jit(script, call_threshold: 1, num_profiles: 1, stats: false, debug: true, timeout: 1000, pipe_fd:)
1551-
args = [
1552-
"--disable-gems",
1553-
"--zjit-call-threshold=#{call_threshold}",
1554-
"--zjit-num-profiles=#{num_profiles}",
1555-
]
1556-
args << "--zjit-stats" if stats
1557-
args << "--zjit-debug" if debug
1559+
def eval_with_jit(
1560+
script,
1561+
call_threshold: 1,
1562+
num_profiles: 1,
1563+
zjit: true,
1564+
stats: false,
1565+
debug: true,
1566+
timeout: 1000,
1567+
pipe_fd:
1568+
)
1569+
args = ["--disable-gems"]
1570+
if zjit
1571+
args << "--zjit-call-threshold=#{call_threshold}"
1572+
args << "--zjit-num-profiles=#{num_profiles}"
1573+
args << "--zjit-stats" if stats
1574+
args << "--zjit-debug" if debug
1575+
end
15581576
args << "-e" << script_shell_encode(script)
15591577
pipe_r, pipe_w = IO.pipe
15601578
# Separate thread so we don't deadlock when

zjit.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ module RubyVM::ZJIT
1414
end
1515

1616
class << RubyVM::ZJIT
17-
# Return ZJIT statistics as a Hash
17+
# Check if \ZJIT is enabled
18+
def enabled?
19+
Primitive.cexpr! 'RBOOL(rb_zjit_enabled_p)'
20+
end
21+
22+
# Return \ZJIT statistics as a Hash
1823
def stats
1924
stats = Primitive.rb_zjit_stats
2025

@@ -26,7 +31,7 @@ def stats
2631
stats
2732
end
2833

29-
# Get the summary of ZJIT statistics as a String
34+
# Get the summary of \ZJIT statistics as a String
3035
def stats_string
3136
buf = +''
3237
stats = self.stats

0 commit comments

Comments
 (0)