summaryrefslogtreecommitdiff
path: root/lib/ruby_vm/mjit/compiler.rb
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2023-02-19 23:35:48 -0800
committerTakashi Kokubun <[email protected]>2023-03-05 23:28:59 -0800
commit993c43e4294cf445e0422f56f1b2d3ac53aa5e84 (patch)
treeb4303a3855c48817a882c3cc4576dbf4f90ebce1 /lib/ruby_vm/mjit/compiler.rb
parentbef63f445b85bcfea5e76a724ee3b03be35a82cf (diff)
Change a branch stub shape only when needed
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7448
Diffstat (limited to 'lib/ruby_vm/mjit/compiler.rb')
-rw-r--r--lib/ruby_vm/mjit/compiler.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/ruby_vm/mjit/compiler.rb b/lib/ruby_vm/mjit/compiler.rb
index f19e1bd6fb..710c3fd23d 100644
--- a/lib/ruby_vm/mjit/compiler.rb
+++ b/lib/ruby_vm/mjit/compiler.rb
@@ -248,13 +248,18 @@ module RubyVM::MJIT
next if target.nil?
# TODO: Could target.address be a stub address? Is invalidation not needed in that case?
+ # If the target being re-generated is currently a fallthrough block,
+ # the fallthrough code must be rewritten with a jump to the stub.
+ if target.address == branch_stub.end_addr
+ branch_stub.shape = Default
+ end
+
target.address = Assembler.new.then do |ocb_asm|
@exit_compiler.compile_branch_stub(block.ctx, ocb_asm, branch_stub, target == branch_stub.target0)
@ocb.write(ocb_asm)
end
@cb.with_write_addr(branch_stub.start_addr) do
branch_asm = Assembler.new
- branch_stub.shape = Default # cancel fallthrough. TODO: It seems fine for defer_compilation, but is this always safe?
branch_stub.compile.call(branch_asm)
@cb.write(branch_asm)
end