ruby/lib/ruby_vm/rjit
Alan Wu f302e725e1
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`:

     patched:   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
9121e57a5f.

Closes ruby/ruby#6428
2023-07-17 13:57:58 -04:00
..
assembler.rb Update an Intel SDM link [ci skip] 2023-04-28 10:09:52 -07:00
block.rb
branch_stub.rb
c_pointer.rb
c_type.rb
code_block.rb RJIT: Simplify how Capstone is used in tests 2023-03-13 20:42:19 -07:00
compiler.rb RJIT: Add --rjit-verify-ctx option 2023-04-04 00:35:29 -07:00
context.rb RJIT: Upgrade type on jit_guard_known_class 2023-04-03 00:39:29 -07:00
entry_stub.rb RJIT: Support entry with different PCs 2023-04-02 15:27:40 -07:00
exit_compiler.rb RJIT: Support entry with different PCs 2023-04-02 15:27:40 -07:00
hooks.rb s/mjit/rjit/ 2023-03-06 23:44:01 -08:00
insn_compiler.rb Remove __bp__ and speed-up bmethod calls (#8060) 2023-07-17 13:57:58 -04:00
invariants.rb RJIT: Optimize Kernel#respond_to? 2023-03-19 14:04:58 -07:00
jit_state.rb RJIT: Add --rjit-verify-ctx option 2023-04-04 00:35:29 -07:00
stats.rb RJIT: Support entry with different PCs 2023-04-02 15:27:40 -07:00
type.rb RJIT: Eliminate known-result branches 2023-04-04 23:30:26 -07:00