From 30086a1e1526c4fd50e49eaaf9f27e2bd923605e Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 17 Feb 2021 13:59:46 -0500 Subject: [PATCH 1/5] uJIT: don't compile tailcalls --- ujit_codegen.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ujit_codegen.c b/ujit_codegen.c index a092081081049e..a065d15ace3119 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 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 From 023e7270d11d5bd1594ff8d97f11c49559cb7639 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 17 Feb 2021 14:28:27 -0500 Subject: [PATCH 2/5] 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. --- ujit_codegen.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ujit_codegen.c b/ujit_codegen.c index a065d15ace3119..d7637d952cb7b5 100644 --- a/ujit_codegen.c +++ b/ujit_codegen.c @@ -1454,6 +1454,11 @@ gen_opt_send_without_block(jitstate_t* jit, ctx_t* ctx) 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) { From 3e9e3e23036d5b4af572ca586cf2217eb97e02e7 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 17 Feb 2021 15:51:57 -0500 Subject: [PATCH 3/5] Fix copy pasta --- ujit_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ujit_core.c b/ujit_core.c index efaa33c09a3812..31bd530dba9ea5 100644 --- a/ujit_core.c +++ b/ujit_core.c @@ -539,7 +539,7 @@ void gen_direct_jump( 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; } From 6f0f61881a71c0d540ec4adab7c4f308698b4bc0 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 17 Feb 2021 16:36:41 -0500 Subject: [PATCH 4/5] Update blockids in branches --- ujit_core.c | 9 +++++++++ ujit_core.h | 1 + ujit_iface.c | 2 ++ 3 files changed, 12 insertions(+) diff --git a/ujit_core.c b/ujit_core.c index 31bd530dba9ea5..1313cfcfabcc41 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) 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) { diff --git a/ujit_core.h b/ujit_core.h index 76b8325cbb8054..c537c5e7b96201 100644 --- a/ujit_core.h +++ b/ujit_core.h @@ -148,6 +148,7 @@ block_t* find_block_version(blockid_t blockid, const ctx_t* ctx); 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 675cadd7984e9d..15a484fb8e1672 100644 --- a/ujit_iface.c +++ b/ujit_iface.c @@ -206,6 +206,8 @@ ujit_root_update_references(void *ptr) RUBY_ASSERT(false); } } + + ujit_branches_update_references(); } // GC callback during mark phase From 5681af2c9f87926265705d4472c42e39d810f7a9 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 17 Feb 2021 16:58:36 -0500 Subject: [PATCH 5/5] Update dependencies --- common.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/common.mk b/common.mk index 35fdd7cb4d8b55..0aab54a319c862 100644 --- a/common.mk +++ b/common.mk @@ -6626,6 +6626,7 @@ io.$(OBJEXT): {$(VPATH)}backward/2/stdarg.h 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