diff --git a/src/lj_asm.c b/src/lj_asm.c index 217aead5..30379c4b 100644 --- a/src/lj_asm.c +++ b/src/lj_asm.c @@ -1933,6 +1933,11 @@ static void asm_tail_link(ASMState *as) } emit_addptr(as, RID_BASE, 8*(int32_t)baseslot); + if (as->J->ktrace) { /* Patch ktrace slot with the final GCtrace pointer. */ + setgcref(IR(as->J->ktrace)->gcr, obj2gco(as->J->curfinal)); + IR(as->J->ktrace)->o = IR_KGC; + } + /* Sync the interpreter state with the on-trace state. */ asm_stack_restore(as, snap); diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 14fde4d9..2dc41790 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c @@ -118,9 +118,7 @@ static void recff_stitch(jit_State *J) /* Ditto for the IR. */ memmove(&J->base[1], &J->base[-1], sizeof(TRef)*(J->maxslot+1)); J->base[0] = lj_ir_kptr(J, contptr(cont)) | TREF_CONT; - J->ktracep = lj_ir_k64_reserve(J); - lua_assert(irt_toitype_(IRT_P64) == LJ_TTRACE); - J->base[-1] = emitir(IRT(IR_XLOAD, IRT_P64), lj_ir_kptr(J, &J->ktracep->gcr), 0); + J->ktrace = tref_ref((J->base[-1] = lj_ir_ktrace(J))); J->base += 2; J->baseslot += 2; J->framedepth++; diff --git a/src/lj_ir.c b/src/lj_ir.c index 3faee371..e8c54947 100644 --- a/src/lj_ir.c +++ b/src/lj_ir.c @@ -340,6 +340,18 @@ found: return TREF(ref, t); } +/* Allocate GCtrace constant placeholder (no interning). */ +TRef lj_ir_ktrace(jit_State *J) +{ + IRRef ref = ir_nextk(J); + IRIns *ir = IR(ref); + lua_assert(irt_toitype_(IRT_P64) == LJ_TTRACE); + ir->t.irt = IRT_P64; + ir->o = IR_KNULL; /* Not IR_KGC yet, but same size. */ + ir->prev = 0; + return TREF(ref, IRT_P64); +} + /* Intern 32 bit pointer constant. */ TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr) { diff --git a/src/lj_iropt.h b/src/lj_iropt.h index 3ebb5532..616f1fc9 100644 --- a/src/lj_iropt.h +++ b/src/lj_iropt.h @@ -49,6 +49,7 @@ LJ_FUNC TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t); LJ_FUNC TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr); LJ_FUNC TRef lj_ir_knull(jit_State *J, IRType t); LJ_FUNC TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot); +LJ_FUNC TRef lj_ir_ktrace(jit_State *J); #if LJ_64 #define lj_ir_kintp(J, k) lj_ir_kint64(J, (uint64_t)(k)) diff --git a/src/lj_jit.h b/src/lj_jit.h index ec52fbf2..946ad568 100644 --- a/src/lj_jit.h +++ b/src/lj_jit.h @@ -403,7 +403,7 @@ typedef struct jit_State { GCRef *trace; /* Array of traces. */ TraceNo freetrace; /* Start of scan for next free trace. */ MSize sizetrace; /* Size of trace array. */ - TValue *ktracep; /* Pointer to K64Array slot with GCtrace pointer. */ + IRRef1 ktrace; /* Reference to KGC with GCtrace. */ IRRef1 chain[IR__MAX]; /* IR instruction skip-list chain anchors. */ TRef slot[LJ_MAX_JSLOTS+LJ_STACK_EXTRA]; /* Stack slot map. */ diff --git a/src/lj_trace.c b/src/lj_trace.c index 27cae559..26c1b108 100644 --- a/src/lj_trace.c +++ b/src/lj_trace.c @@ -426,7 +426,7 @@ static void trace_start(jit_State *J) J->postproc = LJ_POST_NONE; lj_resetsplit(J); J->retryrec = 0; - J->ktracep = NULL; + J->ktrace = 0; setgcref(J->cur.startpt, obj2gco(J->pt)); L = J->L; @@ -502,9 +502,6 @@ static void trace_stop(jit_State *J) lj_mcode_commit(J, J->cur.mcode); J->postproc = LJ_POST_NONE; trace_save(J, T); - if (J->ktracep) { /* Patch K64Array slot with the final GCtrace pointer. */ - setgcV(J->L, J->ktracep, obj2gco(T), LJ_TTRACE); - } L = J->L; lj_vmevent_send(L, TRACE,