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,21 +176,21 @@ module RubyVM::MicroJIT 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 print_warning(text) + text = "ujit warning: #{text}" + text = "\x1b[1m#{text}\x1b[0m" if STDOUT.tty? + STDOUT.puts(text) 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) - end - - def post_call_bytes - scrape unless @post_call_bytes - comma_separated_hex_string(@post_call_bytes) - 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 @@ 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) 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);