diff options
| author | Takashi Kokubun <takashikkbn@gmail.com> | 2023-02-08 17:54:18 -0800 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2023-03-05 22:41:35 -0800 |
| commit | ac7b2f0d177312f4d2da52c00b66221802f16595 (patch) | |
| tree | 4f61a364ac66dd0a8964aa608ba2deff32964fa7 /lib/ruby_vm | |
| parent | 091c2ee1acd65bcc17801be6a08dba6b8843ac55 (diff) | |
Check interrupts on jump and branchunless
Diffstat (limited to 'lib/ruby_vm')
| -rw-r--r-- | lib/ruby_vm/mjit/insn_compiler.rb | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb index d34b7fa418..8f762ea287 100644 --- a/lib/ruby_vm/mjit/insn_compiler.rb +++ b/lib/ruby_vm/mjit/insn_compiler.rb @@ -336,9 +336,13 @@ module RubyVM::MJIT # @param ctx [RubyVM::MJIT::Context] # @param asm [RubyVM::MJIT::Assembler] def jump(jit, ctx, asm) - # TODO: check ints for backward branches + # Check for interrupts, but only on backward branches that may create loops + jump_offset = jit.operand(0) + if jump_offset < 0 + jit_check_ints(jit, ctx, asm) + end - pc = jit.pc + C.VALUE.size * (jit.insn.len + jit.operand(0)) + pc = jit.pc + C.VALUE.size * (jit.insn.len + jump_offset) stub_next_block(jit.iseq, pc, ctx, asm) EndBlock end @@ -349,7 +353,12 @@ module RubyVM::MJIT # @param ctx [RubyVM::MJIT::Context] # @param asm [RubyVM::MJIT::Assembler] def branchunless(jit, ctx, asm) - # TODO: check ints for backward branches + # Check for interrupts, but only on backward branches that may create loops + jump_offset = jit.operand(0) + if jump_offset < 0 + jit_check_ints(jit, ctx, asm) + end + # TODO: skip check for known truthy # This `test` sets ZF only for Qnil and Qfalse, which let jz jump. @@ -360,7 +369,7 @@ module RubyVM::MJIT branch_stub = BranchStub.new( iseq: jit.iseq, shape: Default, - target0: BranchTarget.new(ctx:, pc: jit.pc + C.VALUE.size * (jit.insn.len + jit.operand(0))), # branch target + target0: BranchTarget.new(ctx:, pc: jit.pc + C.VALUE.size * (jit.insn.len + jump_offset)), # branch target target1: BranchTarget.new(ctx:, pc: jit.pc + C.VALUE.size * jit.insn.len), # fallthrough ) branch_stub.target0.address = Assembler.new.then do |ocb_asm| |
