ruby-changes:68696
From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:12:26 +0900 (JST)
Subject: [ruby-changes:68696] 1cd4c8b294 (master): Deoptimize on side-exit
https://git.ruby-lang.org/ruby.git/commit/?id=1cd4c8b294 From 1cd4c8b294acd2b4d34c2c830ee2b541a87a0e6f Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...> Date: Mon, 9 Nov 2020 16:54:29 -0500 Subject: Deoptimize on side-exit --- ujit_compile.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ujit_compile.c b/ujit_compile.c index 20592ba54a..064e93152d 100644 --- a/ujit_compile.c +++ b/ujit_compile.c @@ -113,7 +113,7 @@ struct compiled_region_array { https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L113 const rb_iseq_t *iseq; size_t start_idx; uint8_t *code; - }data[]; + } data[]; }; // Add an element to a region array, or allocate a new region array. @@ -346,14 +346,25 @@ ujit_side_exit(codeblock_t* cb, ctx_t* ctx, VALUE* exit_pc) https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L346 { uint8_t* code_ptr = cb_get_ptr(cb, cb->write_pos); + // Table mapping opcodes to interpreter handlers + const void * const *table = rb_vm_get_insns_address_table(); + + // Write back the old instruction at the entry PC + // To deotimize the code block this instruction belongs to + VALUE* entry_pc = &ctx->iseq->body->iseq_encoded[ctx->start_idx]; + int entry_opcode = opcode_at_pc(ctx->iseq, entry_pc); + void* entry_instr = (void*)table[entry_opcode]; + mov(cb, RAX, const_ptr_opnd(entry_pc)); + mov(cb, RCX, const_ptr_opnd(entry_instr)); + mov(cb, mem_opnd(64, RAX, 0), RCX); + // Write back the old instruction at the exit PC // Otherwise the interpreter may jump right back to the // JITted code we're trying to exit - const void * const *table = rb_vm_get_insns_address_table(); - int opcode = opcode_at_pc(ctx->iseq, exit_pc); - void* old_instr = (void*)table[opcode]; + int exit_opcode = opcode_at_pc(ctx->iseq, exit_pc); + void* exit_instr = (void*)table[exit_opcode]; mov(cb, RAX, const_ptr_opnd(exit_pc)); - mov(cb, RCX, const_ptr_opnd(old_instr)); + mov(cb, RCX, const_ptr_opnd(exit_instr)); mov(cb, mem_opnd(64, RAX, 0), RCX); // Generate the code to exit to the interpreters -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/