summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2023-02-07 11:55:07 -0800
committerTakashi Kokubun <[email protected]>2023-03-05 22:11:20 -0800
commitd415f1e3178625fa90ab908dcc5636b7e2e21c16 (patch)
treed33bd2749690ea9de132eac7a1a4e8c72e7c0e9c
parent47e2ea3a800dae6ac4d427ad9524a7d61dd992ee (diff)
Get rid of BlockStub
-rw-r--r--lib/ruby_vm/mjit/block_stub.rb9
-rw-r--r--lib/ruby_vm/mjit/compiler.rb32
-rw-r--r--lib/ruby_vm/mjit/exit_compiler.rb14
-rw-r--r--lib/ruby_vm/mjit/insn_compiler.rb19
-rw-r--r--mjit.c26
-rw-r--r--mjit_c.rb7
6 files changed, 1 insertions, 106 deletions
diff --git a/lib/ruby_vm/mjit/block_stub.rb b/lib/ruby_vm/mjit/block_stub.rb
deleted file mode 100644
index f676374fa0..0000000000
--- a/lib/ruby_vm/mjit/block_stub.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-class RubyVM::MJIT::BlockStub < Struct.new(
- :iseq, # @param [RubyVM::MJIT::CPointer::Struct_rb_iseq_struct] Stub target ISEQ
- :ctx, # @param [RubyVM::MJIT::Context] Stub target context
- :pc, # @param [Integer] Stub target pc
- :start_addr, # @param [Integer] Stub source start address to be re-generated
- :end_addr, # @param [Integer] Stub source end address to be re-generated
- :change_block, # @param [Proc] Recompile the source address with a new block address
-)
-end
diff --git a/lib/ruby_vm/mjit/compiler.rb b/lib/ruby_vm/mjit/compiler.rb
index 0ad289c063..26e3d75d34 100644
--- a/lib/ruby_vm/mjit/compiler.rb
+++ b/lib/ruby_vm/mjit/compiler.rb
@@ -1,6 +1,5 @@
require 'ruby_vm/mjit/assembler'
require 'ruby_vm/mjit/block'
-require 'ruby_vm/mjit/block_stub'
require 'ruby_vm/mjit/branch_stub'
require 'ruby_vm/mjit/code_block'
require 'ruby_vm/mjit/context'
@@ -68,37 +67,6 @@ module RubyVM::MJIT
$stderr.puts e.full_message # TODO: check verbose
end
- # Continue compilation from a block stub.
- # @param block_stub [RubyVM::MJIT::BlockStub]
- # @param cfp `RubyVM::MJIT::CPointer::Struct_rb_control_frame_t`
- # @return [Integer] The starting address of the compiled block stub
- def block_stub_hit(block_stub, cfp)
- # Update cfp->pc for `jit.at_current_insn?`
- cfp.pc = block_stub.pc
-
- # Prepare the jump target
- jit = JITState.new(iseq: block_stub.iseq, cfp:)
- new_asm = Assembler.new.tap do |asm|
- compile_block(asm, jit:, pc: block_stub.pc, ctx: block_stub.ctx)
- end
-
- # Rewrite the block stub
- if @cb.write_addr == block_stub.end_addr
- # If the block stub's jump is the last code, overwrite the jump with the new code.
- @cb.set_write_addr(block_stub.start_addr)
- @cb.write(new_asm)
- else
- # If the block stub's jump is old code, change the jump target to the new code.
- new_addr = @cb.write(new_asm)
- @cb.with_write_addr(block_stub.start_addr) do
- asm = Assembler.new
- block_stub.change_block.call(asm, new_addr)
- @cb.write(asm)
- end
- new_addr
- end
- end
-
# Compile a branch stub.
# @param branch_stub [RubyVM::MJIT::BranchStub]
# @param cfp `RubyVM::MJIT::CPointer::Struct_rb_control_frame_t`
diff --git a/lib/ruby_vm/mjit/exit_compiler.rb b/lib/ruby_vm/mjit/exit_compiler.rb
index 8f610e91cc..0019eda7bd 100644
--- a/lib/ruby_vm/mjit/exit_compiler.rb
+++ b/lib/ruby_vm/mjit/exit_compiler.rb
@@ -59,20 +59,6 @@ module RubyVM::MJIT
# @param ctx [RubyVM::MJIT::Context]
# @param asm [RubyVM::MJIT::Assembler]
- # @param block_stub [RubyVM::MJIT::BlockStub]
- def compile_block_stub(ctx, asm, block_stub)
- # Call rb_mjit_block_stub_hit
- asm.comment("block stub hit: #{block_stub.iseq.body.location.label}@#{C.rb_iseq_path(block_stub.iseq)}:#{iseq_lineno(block_stub.iseq, block_stub.pc)}")
- asm.mov(:rdi, to_value(block_stub))
- asm.mov(:esi, ctx.sp_offset)
- asm.call(C.rb_mjit_block_stub_hit)
-
- # Jump to the address returned by rb_mjit_stub_hit
- asm.jmp(:rax)
- end
-
- # @param ctx [RubyVM::MJIT::Context]
- # @param asm [RubyVM::MJIT::Assembler]
# @param branch_stub [RubyVM::MJIT::BranchStub]
# @param target0_p [TrueClass,FalseClass]
def compile_branch_stub(ctx, asm, branch_stub, target0_p)
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb
index 1d14fcb925..0ea0020f19 100644
--- a/lib/ruby_vm/mjit/insn_compiler.rb
+++ b/lib/ruby_vm/mjit/insn_compiler.rb
@@ -812,24 +812,7 @@ module RubyVM::MJIT
# @param asm [RubyVM::MJIT::Assembler]
def defer_compilation(jit, ctx, asm)
# Make a stub to compile the current insn
- compile_block_stub(jit.iseq, jit.pc, ctx, asm, comment: 'defer_compilation: block stub')
- end
-
- def compile_block_stub(iseq, pc, ctx, asm, comment: 'block stub')
- block_stub = BlockStub.new(iseq:, pc:, ctx: ctx.dup)
-
- stub_hit = Assembler.new.then do |ocb_asm|
- @exit_compiler.compile_block_stub(ctx, ocb_asm, block_stub)
- @ocb.write(ocb_asm)
- end
-
- block_stub.change_block = proc do |jump_asm, new_addr|
- jump_asm.comment(comment)
- jump_asm.stub(block_stub) do
- jump_asm.jmp(new_addr)
- end
- end
- block_stub.change_block.call(asm, stub_hit)
+ stub_next_block(jit.iseq, jit.pc, ctx, asm, comment: 'defer_compilation')
end
def stub_next_block(iseq, pc, ctx, asm, comment: 'stub_next_block')
diff --git a/mjit.c b/mjit.c
index 8cfaffca47..6907e9fe64 100644
--- a/mjit.c
+++ b/mjit.c
@@ -375,32 +375,6 @@ rb_mjit_compile(const rb_iseq_t *iseq)
}
void *
-rb_mjit_block_stub_hit(VALUE block_stub, int sp_offset)
-{
- VALUE result;
-
- RB_VM_LOCK_ENTER();
- rb_vm_barrier();
- bool original_call_p = mjit_call_p;
- mjit_call_p = false; // Avoid impacting JIT metrics by itself
- mjit_stats_p = false; // Avoid impacting JIT stats by itself
-
- rb_control_frame_t *cfp = GET_EC()->cfp;
- cfp->sp += sp_offset; // preserve stack values, also using the actual sp_offset to make jit.peek_at_stack work
-
- VALUE cfp_ptr = rb_funcall(rb_cMJITCfpPtr, rb_intern("new"), 1, SIZET2NUM((size_t)cfp));
- result = rb_funcall(rb_MJITCompiler, rb_intern("block_stub_hit"), 2, block_stub, cfp_ptr);
-
- cfp->sp -= sp_offset; // reset for consistency with the code without the stub
-
- mjit_stats_p = mjit_opts.stats;
- mjit_call_p = original_call_p;
- RB_VM_LOCK_LEAVE();
-
- return (void *)NUM2SIZET(result);
-}
-
-void *
rb_mjit_branch_stub_hit(VALUE branch_stub, int sp_offset, int target0_p)
{
VALUE result;
diff --git a/mjit_c.rb b/mjit_c.rb
index 45e8c260ae..f487c6ddca 100644
--- a/mjit_c.rb
+++ b/mjit_c.rb
@@ -36,13 +36,6 @@ module RubyVM::MJIT # :nodoc: all
CType::Immediate.parse("size_t").new(addr)
end
- def rb_mjit_block_stub_hit
- Primitive.cstmt! %{
- extern void *rb_mjit_block_stub_hit(VALUE block_stub, int sp_offset);
- return SIZET2NUM((size_t)rb_mjit_block_stub_hit);
- }
- end
-
def rb_mjit_branch_stub_hit
Primitive.cstmt! %{
extern void *rb_mjit_branch_stub_hit(VALUE branch_stub, int sp_offset, int target0_p);