[前][次][番号順一覧][スレッド一覧]

ruby-changes:69438

From: Alan <ko1@a...>
Date: Mon, 25 Oct 2021 23:45:51 +0900 (JST)
Subject: [ruby-changes:69438] 244c98e635 (master): Strip out YJIT at build time when unsupported or disabled (#5003)

https://git.ruby-lang.org/ruby.git/commit/?id=244c98e635

From 244c98e635a01cc7cfde9e24ed4b44413e6c3e75 Mon Sep 17 00:00:00 2001
From: Alan Wu <XrXr@u...>
Date: Mon, 25 Oct 2021 10:45:22 -0400
Subject: Strip out YJIT at build time when unsupported or disabled (#5003)

In an effort to minimize build issues on non x64 platforms, we can
decide at build time to not build the bulk of YJIT. This should fix
obscure build errors like this one on riscv64:

    yjit_asm.c:137:(.text+0x3fa): relocation truncated to fit: R_RISCV_PCREL_HI20 against `alloc_exec_mem'

We also don't need to bulid YJIT on `--disable-jit-support` builds.

One wrinkle to this is that the YJIT Ruby module will not be defined
when YJIT is stripped from the build. I think that's a fair change as
it's only meant to be used for YJIT development.
---
 test/ruby/test_yjit.rb |  2 +-
 yjit.c                 | 35 +++++++++++++++++++++++++++++++++--
 yjit.rb                |  7 +++++++
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb
index 0905b682188..9b26e6c37f2 100644
--- a/test/ruby/test_yjit.rb
+++ b/test/ruby/test_yjit.rb
@@ -3,7 +3,7 @@ require 'test/unit' https://github.com/ruby/ruby/blob/trunk/test/ruby/test_yjit.rb#L3
 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 bfe79822f00..a0ac959d4f4 100644
--- a/yjit.c
+++ b/yjit.c
@@ -10,8 +10,6 @@ https://github.com/ruby/ruby/blob/trunk/yjit.c#L10
 #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 @@ https://github.com/ruby/ruby/blob/trunk/yjit.c#L29
 // 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; https://github.com/ruby/ruby/blob/trunk/yjit.c#L157
 #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 79511685d1a..cbd2ea1e441 100644
--- a/yjit.rb
+++ b/yjit.rb
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/yjit.rb#L1
+# 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?)
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]