ruby-changes:68619
From: Alan <ko1@a...>
Date: Thu, 21 Oct 2021 08:10:44 +0900 (JST)
Subject: [ruby-changes:68619] a3e58f4df8 (master): Compile with MicroJIT disabled when scrape fails
https://git.ruby-lang.org/ruby.git/commit/?id=a3e58f4df8 From a3e58f4df827f36681e4fdebfef8e05a6ceb5c10 Mon Sep 17 00:00:00 2001 From: Alan Wu <XrXr@u...> Date: Mon, 5 Oct 2020 07:21:45 -0400 Subject: Compile with MicroJIT disabled when scrape fails This is just so we can build successfully on -O0 and other cases that are not supported by the code scraper. --- tool/ruby_vm/models/micro_jit.rb | 20 ++++++++++---------- tool/ruby_vm/views/ujit_examples.inc.erb | 6 ++++-- ujit_compile.c | 3 +++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/tool/ruby_vm/models/micro_jit.rb b/tool/ruby_vm/models/micro_jit.rb index 4473f617fc..eb20fe7335 100644 --- a/tool/ruby_vm/models/micro_jit.rb +++ b/tool/ruby_vm/models/micro_jit.rb @@ -176,20 +176,20 @@ module RubyVM::MicroJIT https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/models/micro_jit.rb#L176 else raise 'Unkonwn platform. Only Mach-O on macOS and ELF on Linux are supported' end + [true, comma_separated_hex_string(@pre_call_bytes), comma_separated_hex_string(@post_call_bytes)] + rescue => e + print_warning("scrape failed: #{e.message}") + [false, '', ''] end - def comma_separated_hex_string(nums) - nums.map{ |byte| '0x'+byte}.join(', ') - end - - def pre_call_bytes - scrape unless @pre_call_bytes - comma_separated_hex_string(@pre_call_bytes) + def print_warning(text) + text = "ujit warning: #{text}" + text = "\x1b[1m#{text}\x1b[0m" if STDOUT.tty? + STDOUT.puts(text) end - def post_call_bytes - scrape unless @post_call_bytes - comma_separated_hex_string(@post_call_bytes) + def comma_separated_hex_string(nums) + nums.map{ |byte| '0x'+byte}.join(', ') end end end diff --git a/tool/ruby_vm/views/ujit_examples.inc.erb b/tool/ruby_vm/views/ujit_examples.inc.erb index a301c5ca74..5fefcd4674 100644 --- a/tool/ruby_vm/views/ujit_examples.inc.erb +++ b/tool/ruby_vm/views/ujit_examples.inc.erb @@ -12,5 +12,7 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/ujit_examples.inc.erb#L12 edit: __FILE__, } -%> -static const uint8_t ujit_pre_call_bytes[] = { <%= RubyVM::MicroJIT.pre_call_bytes %> }; -static const uint8_t ujit_post_call_bytes[] = { <%= RubyVM::MicroJIT.post_call_bytes %> }; +% success, pre_call_bytes, post_call_bytes = RubyVM::MicroJIT.scrape +static const uint8_t ujit_scrape_successful = <%= success %>; +static const uint8_t ujit_pre_call_bytes[] = { <%= pre_call_bytes %> }; +static const uint8_t ujit_post_call_bytes[] = { <%= post_call_bytes %> }; diff --git a/ujit_compile.c b/ujit_compile.c index 98bc545b82..cee9e383e7 100644 --- a/ujit_compile.c +++ b/ujit_compile.c @@ -505,6 +505,9 @@ rb_ujit_enabled_p(void) https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L505 void rb_ujit_init(void) { + if (!ujit_scrape_successful) { + return; + } // Initialize the code blocks size_t mem_size = 64 * 1024 * 1024; uint8_t* mem_block = alloc_exec_mem(mem_size); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/