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

ruby-changes:68735

From: Alan <ko1@a...>
Date: Thu, 21 Oct 2021 08:12:30 +0900 (JST)
Subject: [ruby-changes:68735] 5f9beb9b1b (master): Include disassembly in MicroJIT scraper output

https://git.ruby-lang.org/ruby.git/commit/?id=5f9beb9b1b

From 5f9beb9b1b931a90b314f6adcf9ca5b7447471aa Mon Sep 17 00:00:00 2001
From: Alan Wu <XrXr@u...>
Date: Thu, 29 Oct 2020 17:37:40 -0400
Subject: Include disassembly in MicroJIT scraper output

---
 tool/ruby_vm/models/micro_jit.rb         | 29 ++++++++++++++++++-----------
 tool/ruby_vm/views/ujit_examples.inc.erb |  9 +++++++--
 ujit_compile.c                           |  8 ++++----
 3 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/tool/ruby_vm/models/micro_jit.rb b/tool/ruby_vm/models/micro_jit.rb
index 63815a85a0..54f2144503 100644
--- a/tool/ruby_vm/models/micro_jit.rb
+++ b/tool/ruby_vm/models/micro_jit.rb
@@ -11,6 +11,8 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/models/micro_jit.rb#L11
 # details.
 
 module RubyVM::MicroJIT
+  ScrapeResult = Struct.new(:pre_call_bytes, :post_call_bytes, :disassembly_lines)
+
   class << self
     def target_platform
       # Note, checking RUBY_PLATRFORM doesn't work when cross compiling
@@ -117,8 +119,9 @@ module RubyVM::MicroJIT https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/models/micro_jit.rb#L119
       raise 'generated code for example too long' unless jmp_idx < 10
       handler_instructions = instructions[(0..jmp_idx)]
 
+      disassembly_lines = handler_instructions.map {|_, _, line| line}
       puts "Disassembly for the example handler:"
-      puts handler_instructions.map {|_, _, line| line}
+      puts disassembly_lines
 
 
       raise 'rip reference in example makes copying unsafe' if handler_instructions.any? { |_, _, full_line| full_line.downcase.include?('rip') }
@@ -144,7 +147,11 @@ module RubyVM::MicroJIT https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/models/micro_jit.rb#L147
         post_call_bytes += bytes.split
       end
 
-      [pre_call_bytes, post_call_bytes]
+      ScrapeResult.new(
+        comma_separated_hex_string(pre_call_bytes),
+        comma_separated_hex_string(post_call_bytes),
+        disassembly_lines
+      )
     end
 
     def darwin_scrape(instruction_id)
@@ -169,13 +176,11 @@ module RubyVM::MicroJIT https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/models/micro_jit.rb#L176
       disassemble(handler_offset)
     end
 
-    def make_result(success, pre_call, post_call, pre_call_with_ec, post_call_with_ec)
+    def make_result(success, without_pc, with_pc)
       [success ? 1 : 0,
        [
-         ['ujit_pre_call_bytes', comma_separated_hex_string(pre_call)],
-         ['ujit_post_call_bytes', comma_separated_hex_string(post_call)],
-         ['ujit_pre_call_with_ec_bytes', comma_separated_hex_string(pre_call_with_ec)],
-         ['ujit_post_call_with_ec_bytes', comma_separated_hex_string(post_call_with_ec)]
+         ['ujit_without_ec', without_pc],
+         ['ujit_with_ec', with_pc],
        ]
       ]
     end
@@ -193,12 +198,14 @@ module RubyVM::MicroJIT https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/models/micro_jit.rb#L198
     end
 
     def scrape
-      pre, post = scrape_instruction(RubyVM::Instructions.find_index { |insn| insn.name == 'ujit_call_example' })
-      pre_with_ec, post_with_ec = scrape_instruction(RubyVM::Instructions.find_index { |insn| insn.name == 'ujit_call_example_with_ec' })
-      make_result(true, pre, post, pre_with_ec, post_with_ec)
+      without_ec = scrape_instruction(RubyVM::Instructions.find_index { |insn| insn.name == 'ujit_call_example' })
+      with_ec = scrape_instruction(RubyVM::Instructions.find_index { |insn| insn.name == 'ujit_call_example_with_ec' })
+      make_result(true, without_ec, with_ec)
     rescue => e
       print_warning("scrape failed: #{e.message}")
-      make_result(false, ['cc'], ['cc'], ['cc'], ['cc'])
+      int3 = '0xcc'
+      failure_result = ScrapeResult.new(int3, int3, ['int3'])
+      make_result(false, failure_result, failure_result)
     end
 
     def print_warning(text)
diff --git a/tool/ruby_vm/views/ujit_examples.inc.erb b/tool/ruby_vm/views/ujit_examples.inc.erb
index af0561f852..9409c996b1 100644
--- a/tool/ruby_vm/views/ujit_examples.inc.erb
+++ b/tool/ruby_vm/views/ujit_examples.inc.erb
@@ -14,6 +14,11 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/ujit_examples.inc.erb#L14
 
 % success, byte_arrays = RubyVM::MicroJIT.scrape
 static const uint8_t ujit_scrape_successful = <%= success %>;
-% byte_arrays.each do |(name, bytes)|
-static const uint8_t <%= name %>[] = { <%= bytes %> };
+% byte_arrays.each do |(prefix, scrape_result)|
+// Disassembly:
+%   scrape_result.disassembly_lines.each do |line|
+// <%= line %>
+%   end
+static const uint8_t <%= prefix %>_pre_call_bytes[] = { <%= scrape_result.pre_call_bytes %> };
+static const uint8_t <%= prefix %>_post_call_bytes[] = { <%= scrape_result.post_call_bytes  %> };
 % end
diff --git a/ujit_compile.c b/ujit_compile.c
index 7a8e809879..4d5224e61f 100644
--- a/ujit_compile.c
+++ b/ujit_compile.c
@@ -304,8 +304,8 @@ x86opnd_t ctx_stack_opnd(ctx_t* ctx, int32_t idx) https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L304
 static void
 ujit_gen_entry(codeblock_t* cb)
 {
-    for (size_t i = 0; i < sizeof(ujit_pre_call_with_ec_bytes); ++i)
-        cb_write_byte(cb, ujit_pre_call_with_ec_bytes[i]);
+    for (size_t i = 0; i < sizeof(ujit_with_ec_pre_call_bytes); ++i)
+        cb_write_byte(cb, ujit_with_ec_pre_call_bytes[i]);
 }
 
 /**
@@ -327,8 +327,8 @@ ujit_gen_exit(codeblock_t* cb, ctx_t* ctx, VALUE* exit_pc) https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L327
     mov(cb, member_opnd(REG_CFP, rb_control_frame_t, pc), RAX);
 
     // Write the post call bytes
-    for (size_t i = 0; i < sizeof(ujit_post_call_with_ec_bytes); ++i)
-        cb_write_byte(cb, ujit_post_call_with_ec_bytes[i]);
+    for (size_t i = 0; i < sizeof(ujit_with_ec_post_call_bytes); ++i)
+        cb_write_byte(cb, ujit_with_ec_post_call_bytes[i]);
 }
 
 /**
-- 
cgit v1.2.1


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

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