summaryrefslogtreecommitdiff
path: root/mjit.c
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-01-07 13:21:14 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2023-03-05 22:11:20 -0800
commit62d36dd1277bdfeac609f89bc64589e8856421b8 (patch)
tree4c90de46486efd2c8912ef970449f4744630a5ba /mjit.c
parenteddec7bc209d721e99a8cd5ceaafd0f2ab270cc3 (diff)
Implement branch stub
Diffstat (limited to 'mjit.c')
-rw-r--r--mjit.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/mjit.c b/mjit.c
index c490b0e8a4..a63e09d385 100644
--- a/mjit.c
+++ b/mjit.c
@@ -345,7 +345,7 @@ rb_mjit_compile(const rb_iseq_t *iseq)
}
void *
-rb_mjit_stub_hit(VALUE branch_stub, int sp_offset)
+rb_mjit_block_stub_hit(VALUE block_stub, int sp_offset)
{
VALUE result;
@@ -359,7 +359,33 @@ rb_mjit_stub_hit(VALUE branch_stub, int sp_offset)
cfp->sp += sp_offset; // preserve stack values, also using the actual sp_offset to make jit.peek_at_stack work
VALUE cfp_ptr = rb_funcall(rb_cMJITCfpPtr, rb_intern("new"), 1, SIZET2NUM((size_t)cfp));
- result = rb_funcall(rb_MJITCompiler, rb_intern("stub_hit"), 2, branch_stub, cfp_ptr);
+ result = rb_funcall(rb_MJITCompiler, rb_intern("block_stub_hit"), 2, block_stub, cfp_ptr);
+
+ cfp->sp -= sp_offset; // reset for consistency with the code without the stub
+
+ mjit_stats_p = mjit_opts.stats;
+ mjit_call_p = original_call_p;
+ RB_VM_LOCK_LEAVE();
+
+ return (void *)NUM2SIZET(result);
+}
+
+void *
+rb_mjit_branch_stub_hit(VALUE branch_stub, int sp_offset, int branch_target_p)
+{
+ VALUE result;
+
+ RB_VM_LOCK_ENTER();
+ rb_vm_barrier();
+ bool original_call_p = mjit_call_p;
+ mjit_call_p = false; // Avoid impacting JIT metrics by itself
+ mjit_stats_p = false; // Avoid impacting JIT stats by itself
+
+ rb_control_frame_t *cfp = GET_EC()->cfp;
+ cfp->sp += sp_offset; // preserve stack values, also using the actual sp_offset to make jit.peek_at_stack work
+
+ VALUE cfp_ptr = rb_funcall(rb_cMJITCfpPtr, rb_intern("new"), 1, SIZET2NUM((size_t)cfp));
+ result = rb_funcall(rb_MJITCompiler, rb_intern("branch_stub_hit"), 3, branch_stub, cfp_ptr, RBOOL(branch_target_p));
cfp->sp -= sp_offset; // reset for consistency with the code without the stub