Skip to content

Commit eead831

Browse files
Prevent enabling yjit when zjit enabled (rubyGH-13358)
`ruby --yjit --zjit` already warns and exits, but it was still possible to enable both with `ruby --zjit -e 'RubyVM:YJIT.enable`. This commit prevents that with a warning and an early return. (We could also exit, but that seems a bit unfriendly once we're already running the program.) Co-authored-by: ywenc <[email protected]>
1 parent cc90adb commit eead831

File tree

5 files changed

+13
-0
lines changed

5 files changed

+13
-0
lines changed

common.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21737,6 +21737,7 @@ yjit.$(OBJEXT): {$(VPATH)}vm_sync.h
2173721737
yjit.$(OBJEXT): {$(VPATH)}yjit.c
2173821738
yjit.$(OBJEXT): {$(VPATH)}yjit.h
2173921739
yjit.$(OBJEXT): {$(VPATH)}yjit.rbinc
21740+
yjit.$(OBJEXT): {$(VPATH)}zjit.h
2174021741
zjit.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
2174121742
zjit.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h
2174221743
zjit.$(OBJEXT): $(CCAN_DIR)/list/list.h

test/ruby/test_yjit.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ def test_yjit_enable_with_invalid_runtime_mem_size_option
166166
end
167167
end
168168

169+
if JITSupport.zjit_supported?
170+
def test_yjit_enable_with_zjit_enabled
171+
assert_in_out_err(['--zjit'], 'puts RubyVM::YJIT.enable', ['false'], ['Only one JIT can be enabled at the same time.'])
172+
end
173+
end
169174

170175
def test_yjit_stats_and_v_no_error
171176
_stdout, stderr, _status = invoke_ruby(%w(-v --yjit-stats), '', true, true)

yjit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "iseq.h"
3030
#include "ruby/debug.h"
3131
#include "internal/cont.h"
32+
#include "zjit.h"
3233

3334
// For mmapp(), sysconf()
3435
#ifndef _WIN32

yjit.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ def self.reset_stats!
4848
def self.enable(stats: false, log: false, mem_size: nil, call_threshold: nil)
4949
return false if enabled?
5050

51+
if Primitive.cexpr! 'RBOOL(rb_zjit_enabled_p)'
52+
warn("Only one JIT can be enabled at the same time.")
53+
return false
54+
end
55+
5156
if mem_size
5257
raise ArgumentError, "mem_size must be a Integer" unless mem_size.is_a?(Integer)
5358
raise ArgumentError, "mem_size must be between 1 and 2048 MB" unless (1..2048).include?(mem_size)

zjit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ void rb_zjit_profile_enable(const rb_iseq_t *iseq);
1414
void rb_zjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop);
1515
void rb_zjit_invalidate_ep_is_bp(const rb_iseq_t *iseq);
1616
#else
17+
#define rb_zjit_enabled_p false
1718
static inline void rb_zjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception) {}
1819
static inline void rb_zjit_profile_insn(enum ruby_vminsn_type insn, rb_execution_context_t *ec) {}
1920
static inline void rb_zjit_profile_enable(const rb_iseq_t *iseq) {}

0 commit comments

Comments
 (0)