diff options
author | Alan Wu <[email protected]> | 2023-07-17 13:57:58 -0400 |
---|---|---|
committer | <[email protected]> | 2023-07-17 13:57:58 -0400 |
commit | f302e725e10ae05e613e2c24cae0741f65f2db91 () | |
tree | f539d3b5a27636dde99dfe96ab07e917b4f62740 /yjit/src | |
parent | 105bdba899fbb10aa51115c4cd074ea42eb9e3e6 (diff) |
Remove __bp__ and speed-up bmethod calls (#8060)
Remove rb_control_frame_t::__bp__ and optimize bmethod calls This commit removes the __bp__ field from rb_control_frame_t. It was introduced to help MJIT, but since MJIT was replaced by RJIT, we can use vm_base_ptr() to compute it from the SP of the previous control frame instead. Removing the field avoids needing to set it up when pushing new frames. Simply removing __bp__ would cause crashes since RJIT and YJIT used a slightly different stack layout for bmethod calls than the interpreter. At the moment of the call, the two layouts looked as follows: ┌────────────┐ ┌────────────┐ │ frame_base │ │ frame_base │ ├────────────┤ ├────────────┤ │ ... │ │ ... │ ├────────────┤ ├────────────┤ │ args │ │ args │ ├────────────┤ └────────────┘<─prev_frame_sp │ receiver │ prev_frame_sp─>└────────────┘ RJIT & YJIT interpreter Essentially, vm_base_ptr() needs to compute the address to frame_base given prev_frame_sp in the diagrams. The presence of the receiver created an off-by-one situation. Make the interpreter use the layout the JITs use for iseq-to-iseq bmethod calls. Doing so removes unnecessary argument shifting and vm_exec_core() re-entry from the interpreter, yielding a speed improvement visible through `benchmark/vm_defined_method.yml`: ed: 7578743.1 i/s master: 4796596.3 i/s - 1.58x slower C-to-iseq bmethod calls now store one more VALUE than before, but that should have negligible impact on overall performance. Note that re-entering vm_exec_core() used to be necessary for firing TracePoint events, but that's no longer the case since 9121e57a5f50bc91bae48b3b91edb283bf96cb6b. Closes ruby/ruby#6428
-rw-r--r-- | yjit/src/codegen.rs | 1 | ||||
-rw-r--r-- | yjit/src/cruby.rs | 5 |
2 files changed, 2 insertions, 4 deletions
@@ -4850,7 +4850,6 @@ fn gen_push_frame( if let Some(pc) = frame.pc { asm.mov(cfp_opnd(RUBY_OFFSET_CFP_PC), pc.into()); }; - asm.mov(cfp_opnd(RUBY_OFFSET_CFP_BP), sp); asm.mov(cfp_opnd(RUBY_OFFSET_CFP_SP), sp); let iseq: Opnd = if let Some(iseq) = frame.iseq { VALUE::from(iseq).into() @@ -718,9 +718,8 @@ mod manual_defs { pub const RUBY_OFFSET_CFP_SELF: i32 = 24; pub const RUBY_OFFSET_CFP_EP: i32 = 32; pub const RUBY_OFFSET_CFP_BLOCK_CODE: i32 = 40; - pub const RUBY_OFFSET_CFP_BP: i32 = 48; // field __bp__ - pub const RUBY_OFFSET_CFP_JIT_RETURN: i32 = 56; - pub const RUBY_SIZEOF_CONTROL_FRAME: usize = 64; // Constants from rb_execution_context_t vm_core.h pub const RUBY_OFFSET_EC_CFP: i32 = 16; |