diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2021-07-07 11:15:40 -0700 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-20 18:19:37 -0400 |
commit | d0174d99c6fcbeae2d5cdaa34908b9ac117bb9c3 (patch) | |
tree | b36938eeb96470dcdf339a59a872fd37687badc8 /yjit_iface.c | |
parent | b70383fbea8d4acc49eceed24c83d87637412ff4 (diff) |
Always use `ret` to return to the interpreter
Always using `ret` to return to the interpreter means that we never have
to check the VM_FRAME_FLAG_FINISH flag.
In the case that we return `Qundef`, the interpreter will execute the
cfp. We can take advantage of this by setting the PC to the instruction
we can't handle, and let the interpreter pick up the ball from there.
If we return a value other than Qundef, the interpreter will take that
value as the "return value" from the JIT and push that to the SP of the
caller
The leave instruction puts the return value on the top of the calling
frame's stack. YJIT does the same thing for leave instructions.
However, when we're returning back to the interpreter, the leave
instruction _should not_ put the return value on the top of the stack,
but put it in RAX and use RET. This commit pops the last value from the
stack pointer and puts it in RAX so that the interpreter is happy with
SP.
Diffstat (limited to 'yjit_iface.c')
-rw-r--r-- | yjit_iface.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/yjit_iface.c b/yjit_iface.c index d347cbd5ef..c6fdb7124e 100644 --- a/yjit_iface.c +++ b/yjit_iface.c @@ -465,9 +465,10 @@ yjit_block_assumptions_free(block_t *block) } } -void +bool rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec) { + bool success = true; #if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE RB_VM_LOCK_ENTER(); // TODO: I think we need to stop all other ractors here @@ -478,14 +479,16 @@ rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec) if (code_ptr) { - // Map the code address to the corresponding opcode - int first_opcode = yjit_opcode_at_pc(iseq, &encoded[0]); - map_addr2insn(code_ptr, first_opcode); - encoded[0] = (VALUE)code_ptr; + iseq->body->jit_func = code_ptr; + } + else { + iseq->body->jit_func = 0; + success = false; } RB_VM_LOCK_LEAVE(); #endif + return success; } struct yjit_block_itr { |