diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb index 0905b68218..9b26e6c37f 100644 --- a/test/ruby/test_yjit.rb +++ b/test/ruby/test_yjit.rb @@ -3,7 +3,7 @@ require 'test/unit' require 'envutil' require 'tmpdir' -return unless YJIT.enabled? +return unless defined?(YJIT) && YJIT.enabled? # Tests for YJIT with assertions on compilation and side exits # insipired by the MJIT tests in test/ruby/test_jit.rb diff --git a/yjit.c b/yjit.c index bfe79822f0..a0ac959d4f 100644 --- a/yjit.c +++ b/yjit.c @@ -10,8 +10,6 @@ #include "vm_sync.h" #include "yjit.h" -#include "yjit_asm.c" - #ifndef YJIT_CHECK_MODE # define YJIT_CHECK_MODE 0 #endif @@ -31,6 +29,11 @@ // USE_MJIT comes from configure options #define JIT_ENABLED USE_MJIT +// Check if we need to include YJIT in the build +#if JIT_ENABLED && PLATFORM_SUPPORTED_P + +#include "yjit_asm.c" + // Code block into which we write machine code static codeblock_t block; static codeblock_t *cb = NULL; @@ -154,3 +157,31 @@ static uint32_t yjit_codepage_frozen_bytes = 0; #include "yjit_core.c" #include "yjit_iface.c" #include "yjit_codegen.c" + +#else +// !JIT_ENABLED || !PLATFORM_SUPPORTED_P +// In these builds, YJIT could never be turned on. Provide dummy +// implementations for YJIT functions exposed to the rest of the code base. +// See yjit.h. + +void Init_builtin_yjit(void) {} +bool rb_yjit_enabled_p(void) { return false; } +unsigned rb_yjit_call_threshold(void) { return UINT_MAX; } +void rb_yjit_invalidate_all_method_lookup_assumptions(void) {}; +void rb_yjit_method_lookup_change(VALUE klass, ID mid) {}; +void rb_yjit_cme_invalidate(VALUE cme) {} +void rb_yjit_collect_vm_usage_insn(int insn) {} +void rb_yjit_collect_binding_alloc(void) {} +void rb_yjit_collect_binding_set(void) {} +bool rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec) { return false; } +void rb_yjit_init(struct rb_yjit_options *options) {} +void rb_yjit_bop_redefined(VALUE klass, const rb_method_entry_t *me, enum ruby_basic_operators bop) {} +void rb_yjit_constant_state_changed(void) {} +void rb_yjit_iseq_mark(const struct rb_iseq_constant_body *body) {} +void rb_yjit_iseq_update_references(const struct rb_iseq_constant_body *body) {} +void rb_yjit_iseq_free(const struct rb_iseq_constant_body *body) {} +void rb_yjit_before_ractor_spawn(void) {} +void rb_yjit_constant_ic_update(const rb_iseq_t *iseq, IC ic) {} +void rb_yjit_tracing_invalidate_all(void) {} + +#endif // if JIT_ENABLED && PLATFORM_SUPPORTED_P diff --git a/yjit.rb b/yjit.rb index 79511685d1..cbd2ea1e44 100644 --- a/yjit.rb +++ b/yjit.rb @@ -1,3 +1,10 @@ +# This module allows for introspection on YJIT, CRuby's experimental in-process +# just-in-time compiler. This module is for development purposes only; +# everything in this module is highly implementation specific and comes with no +# API stability guarantee whatsoever. +# +# This module is only defined when YJIT has support for the particular platform +# on which CRuby is built. module YJIT if defined?(Disasm) def self.disasm(iseq, tty: $stdout && $stdout.tty?)