summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2020-10-29 17:37:40 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2021-10-20 18:19:26 -0400
commit5f9beb9b1b931a90b314f6adcf9ca5b7447471aa (patch)
treef49fbfbe9b829ea5bba6171ae2c207b2b41144de
parent188c54428c46c1098cda0e366ee8c974f25ac07b (diff)
downloadruby-5f9beb9b1b931a90b314f6adcf9ca5b7447471aa.tar.gz
Include disassembly in MicroJIT scraper output
-rw-r--r--tool/ruby_vm/models/micro_jit.rb29
-rw-r--r--tool/ruby_vm/views/ujit_examples.inc.erb9
-rw-r--r--ujit_compile.c8
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 @@
# 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
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
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
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
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 @@
% 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)
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)
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]);
}
/**