ruby-changes:68777
From: Alan <ko1@a...>
Date: Thu, 21 Oct 2021 08:13:31 +0900 (JST)
Subject: [ruby-changes:68777] faabe2b0ad (master): Ujit bug fixes
https://git.ruby-lang.org/ruby.git/commit/?id=faabe2b0ad From faabe2b0ad0917ac5cf88c2683c22c533ad6ddb9 Mon Sep 17 00:00:00 2001 From: Alan Wu <XrXr@u...> Date: Thu, 18 Feb 2021 11:54:37 -0500 Subject: Ujit bug fixes * uJIT: don't compile tailcalls * Don't compile calls to protected methods We need to generate extra code to check whether the call goes through if we want to support these. * Fix copy pasta * Update blockids in branches * Update dependencies --- common.mk | 1 + ujit_codegen.c | 10 ++++++++++ ujit_core.c | 11 ++++++++++- ujit_core.h | 1 + ujit_iface.c | 2 ++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/common.mk b/common.mk index 4de1d833b7..abe03d487e 100644 --- a/common.mk +++ b/common.mk @@ -6627,6 +6627,7 @@ io.$(OBJEXT): {$(VPATH)}backward/2/stdarg.h https://github.com/ruby/ruby/blob/trunk/common.mk#L6627 io.$(OBJEXT): {$(VPATH)}builtin.h io.$(OBJEXT): {$(VPATH)}config.h io.$(OBJEXT): {$(VPATH)}constant.h +io.$(OBJEXT): {$(VPATH)}darray.h io.$(OBJEXT): {$(VPATH)}defines.h io.$(OBJEXT): {$(VPATH)}dln.h io.$(OBJEXT): {$(VPATH)}encindex.h diff --git a/ujit_codegen.c b/ujit_codegen.c index 6ab1ee1c9b..b6d5f5fbce 100644 --- a/ujit_codegen.c +++ b/ujit_codegen.c @@ -1277,6 +1277,11 @@ gen_opt_swb_iseq(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb https://github.com/ruby/ruby/blob/trunk/ujit_codegen.c#L1277 return false; } + if (vm_ci_flag(cd->ci) & VM_CALL_TAILCALL) { + // We can't handle tailcalls + return false; + } + rb_gc_register_mark_object((VALUE)iseq); // FIXME: intentional LEAK! // Create a size-exit to fall back to the interpreter @@ -1464,6 +1469,11 @@ gen_opt_send_without_block(jitstate_t* jit, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/ujit_codegen.c#L1469 return false; } + // We don't generate code to check protected method calls + if (METHOD_ENTRY_VISI(cme) == METHOD_VISI_PROTECTED) { + return false; + } + // If this is a C call if (cme->def->type == VM_METHOD_TYPE_CFUNC) { diff --git a/ujit_core.c b/ujit_core.c index 7b135dc89b..e642b67544 100644 --- a/ujit_core.c +++ b/ujit_core.c @@ -256,6 +256,15 @@ block_t* find_block_version(blockid_t blockid, const ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L256 return best_version; } +void +ujit_branches_update_references(void) +{ + for (uint32_t i = 0; i < num_branches; i++) { + branch_entries[i].targets[0].iseq = (const void *)rb_gc_location((VALUE)branch_entries[i].targets[0].iseq); + branch_entries[i].targets[1].iseq = (const void *)rb_gc_location((VALUE)branch_entries[i].targets[1].iseq); + } +} + // Compile a new block version immediately block_t* gen_block_version(blockid_t blockid, const ctx_t* start_ctx) { @@ -539,7 +548,7 @@ void gen_direct_jump( https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L548 generic_ctx.sp_offset = ctx->sp_offset; if (count_block_versions(target0) >= MAX_VERSIONS - 1) { - fprintf(stderr, "version limit hit in branch_stub_hit\n"); + fprintf(stderr, "version limit hit in gen_direct_jump\n"); ctx = &generic_ctx; } diff --git a/ujit_core.h b/ujit_core.h index 6e863f08bf..051fadb4a3 100644 --- a/ujit_core.h +++ b/ujit_core.h @@ -145,6 +145,7 @@ block_t* find_block_version(blockid_t blockid, const ctx_t* ctx); https://github.com/ruby/ruby/blob/trunk/ujit_core.h#L145 block_t* gen_block_version(blockid_t blockid, const ctx_t* ctx); uint8_t* gen_entry_point(const rb_iseq_t *iseq, uint32_t insn_idx); void ujit_free_block(block_t *block); +void ujit_branches_update_references(void); void gen_branch( const ctx_t* src_ctx, diff --git a/ujit_iface.c b/ujit_iface.c index 675cadd798..15a484fb8e 100644 --- a/ujit_iface.c +++ b/ujit_iface.c @@ -206,6 +206,8 @@ ujit_root_update_references(void *ptr) https://github.com/ruby/ruby/blob/trunk/ujit_iface.c#L206 RUBY_ASSERT(false); } } + + ujit_branches_update_references(); } // GC callback during mark phase -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/