mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
Cleanup and fix trace flush logic.
This commit is contained in:
parent
f385af7084
commit
751eff9f97
@ -709,8 +709,7 @@ void lj_gdbjit_addtrace(jit_State *J, GCtrace *T)
|
|||||||
GDBJITctx ctx;
|
GDBJITctx ctx;
|
||||||
GCproto *pt = &gcref(T->startpt)->pt;
|
GCproto *pt = &gcref(T->startpt)->pt;
|
||||||
TraceNo parent = T->ir[REF_BASE].op1;
|
TraceNo parent = T->ir[REF_BASE].op1;
|
||||||
uintptr_t pcofs = (uintptr_t)(T->snap[0].mapofs+T->snap[0].nent);
|
const BCIns *startpc = mref(T->startpc, const BCIns);
|
||||||
const BCIns *startpc = snap_pc(T->snapmap[pcofs]);
|
|
||||||
ctx.T = T;
|
ctx.T = T;
|
||||||
ctx.mcaddr = (uintptr_t)T->mcode;
|
ctx.mcaddr = (uintptr_t)T->mcode;
|
||||||
ctx.szmcode = T->szmcode;
|
ctx.szmcode = T->szmcode;
|
||||||
|
@ -172,9 +172,10 @@ typedef struct GCtrace {
|
|||||||
SnapShot *snap; /* Snapshot array. */
|
SnapShot *snap; /* Snapshot array. */
|
||||||
SnapEntry *snapmap; /* Snapshot map. */
|
SnapEntry *snapmap; /* Snapshot map. */
|
||||||
GCRef startpt; /* Starting prototype. */
|
GCRef startpt; /* Starting prototype. */
|
||||||
|
MRef startpc; /* Bytecode PC of starting instruction. */
|
||||||
BCIns startins; /* Original bytecode of starting instruction. */
|
BCIns startins; /* Original bytecode of starting instruction. */
|
||||||
MCode *mcode; /* Start of machine code. */
|
|
||||||
MSize szmcode; /* Size of machine code. */
|
MSize szmcode; /* Size of machine code. */
|
||||||
|
MCode *mcode; /* Start of machine code. */
|
||||||
MSize mcloop; /* Offset of loop start in machine code. */
|
MSize mcloop; /* Offset of loop start in machine code. */
|
||||||
uint16_t nchild; /* Number of child traces (root trace only). */
|
uint16_t nchild; /* Number of child traces (root trace only). */
|
||||||
uint16_t spadjust; /* Stack pointer adjustment (offset in bytes). */
|
uint16_t spadjust; /* Stack pointer adjustment (offset in bytes). */
|
||||||
|
@ -1996,6 +1996,7 @@ void lj_record_setup(jit_State *J)
|
|||||||
J->cur.nk = REF_TRUE;
|
J->cur.nk = REF_TRUE;
|
||||||
|
|
||||||
J->startpc = J->pc;
|
J->startpc = J->pc;
|
||||||
|
setmref(J->cur.startpc, J->pc);
|
||||||
if (J->parent) { /* Side trace. */
|
if (J->parent) { /* Side trace. */
|
||||||
GCtrace *T = traceref(J, J->parent);
|
GCtrace *T = traceref(J, J->parent);
|
||||||
TraceNo root = T->root ? T->root : J->parent;
|
TraceNo root = T->root ? T->root : J->parent;
|
||||||
|
@ -96,8 +96,7 @@ static void perftools_addtrace(GCtrace *T)
|
|||||||
{
|
{
|
||||||
static FILE *fp;
|
static FILE *fp;
|
||||||
GCproto *pt = &gcref(T->startpt)->pt;
|
GCproto *pt = &gcref(T->startpt)->pt;
|
||||||
uintptr_t pcofs = (uintptr_t)(T->snap[0].mapofs+T->snap[0].nent);
|
const BCIns *startpc = mref(T->startpc, const BCIns);
|
||||||
const BCIns *startpc = snap_pc(T->snapmap[pcofs]);
|
|
||||||
const char *name = strdata(proto_chunkname(pt));
|
const char *name = strdata(proto_chunkname(pt));
|
||||||
BCLine lineno;
|
BCLine lineno;
|
||||||
if (name[0] == '@' || name[0] == '=')
|
if (name[0] == '@' || name[0] == '=')
|
||||||
@ -183,34 +182,35 @@ void lj_trace_reenableproto(GCproto *pt)
|
|||||||
static void trace_unpatch(jit_State *J, GCtrace *T)
|
static void trace_unpatch(jit_State *J, GCtrace *T)
|
||||||
{
|
{
|
||||||
BCOp op = bc_op(T->startins);
|
BCOp op = bc_op(T->startins);
|
||||||
MSize pcofs = T->snap[0].mapofs + T->snap[0].nent;
|
BCIns *pc = mref(T->startpc, BCIns);
|
||||||
BCIns *pc = ((BCIns *)snap_pc(T->snapmap[pcofs])) - 1;
|
|
||||||
UNUSED(J);
|
UNUSED(J);
|
||||||
switch (op) {
|
if (op == BC_JMP)
|
||||||
case BC_FORL:
|
return; /* No need to unpatch branches in parent traces (yet). */
|
||||||
lua_assert(bc_op(*pc) == BC_JFORI);
|
switch (bc_op(*pc)) {
|
||||||
setbc_op(pc, BC_FORI); /* Unpatch JFORI, too. */
|
case BC_JFORI:
|
||||||
|
lua_assert(op == BC_FORL);
|
||||||
|
setbc_op(pc, BC_FORI);
|
||||||
pc += bc_j(*pc);
|
pc += bc_j(*pc);
|
||||||
lua_assert(bc_op(*pc) == BC_JFORL && traceref(J, bc_d(*pc)) == T);
|
lua_assert(bc_op(*pc) == BC_JFORL && traceref(J, bc_d(*pc)) == T);
|
||||||
*pc = T->startins;
|
*pc = T->startins;
|
||||||
break;
|
break;
|
||||||
case BC_LOOP:
|
case BC_JLOOP:
|
||||||
lua_assert(bc_op(*pc) == BC_JLOOP && traceref(J, bc_d(*pc)) == T);
|
lua_assert(op == BC_LOOP || bc_isret(op));
|
||||||
*pc = T->startins;
|
*pc = T->startins;
|
||||||
break;
|
break;
|
||||||
case BC_ITERL:
|
case BC_JMP:
|
||||||
lua_assert(bc_op(*pc) == BC_JMP);
|
lua_assert(op == BC_ITERL);
|
||||||
pc += bc_j(*pc)+2;
|
pc += bc_j(*pc)+2;
|
||||||
lua_assert(bc_op(*pc) == BC_JITERL && traceref(J, bc_d(*pc)) == T);
|
if (bc_op(*pc) == BC_JITERL) {
|
||||||
|
lua_assert(traceref(J, bc_d(*pc)) == T);
|
||||||
|
*pc = T->startins;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BC_JFUNCF:
|
||||||
|
lua_assert(op == BC_FUNCF);
|
||||||
*pc = T->startins;
|
*pc = T->startins;
|
||||||
break;
|
break;
|
||||||
case BC_FUNCF:
|
default: /* Already unpatched. */
|
||||||
lua_assert(bc_op(*pc) == BC_JFUNCF && traceref(J, bc_d(*pc)) == T);
|
|
||||||
*pc = T->startins;
|
|
||||||
break;
|
|
||||||
case BC_JMP: /* No need to unpatch branches in parent traces (yet). */
|
|
||||||
default:
|
|
||||||
lua_assert(0);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -227,11 +227,11 @@ static void trace_flushroot(jit_State *J, GCtrace *T)
|
|||||||
pt->trace = T->nextroot;
|
pt->trace = T->nextroot;
|
||||||
} else { /* Otherwise search in chain of root traces. */
|
} else { /* Otherwise search in chain of root traces. */
|
||||||
GCtrace *T2 = traceref(J, pt->trace);
|
GCtrace *T2 = traceref(J, pt->trace);
|
||||||
while (T2->nextroot != T->traceno) {
|
for (; T2->nextroot; T2 = traceref(J, T2->nextroot))
|
||||||
lua_assert(T2->nextroot != 0);
|
if (T2->nextroot == T->traceno) {
|
||||||
T2 = traceref(J, T2->nextroot);
|
|
||||||
}
|
|
||||||
T2->nextroot = T->nextroot; /* Unlink from chain. */
|
T2->nextroot = T->nextroot; /* Unlink from chain. */
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,7 +408,7 @@ static void trace_start(jit_State *J)
|
|||||||
/* Stop tracing. */
|
/* Stop tracing. */
|
||||||
static void trace_stop(jit_State *J)
|
static void trace_stop(jit_State *J)
|
||||||
{
|
{
|
||||||
BCIns *pc = (BCIns *)J->startpc; /* Not const here. */
|
BCIns *pc = mref(J->cur.startpc, BCIns);
|
||||||
BCOp op = bc_op(J->cur.startins);
|
BCOp op = bc_op(J->cur.startins);
|
||||||
GCproto *pt = &gcref(J->cur.startpt)->pt;
|
GCproto *pt = &gcref(J->cur.startpt)->pt;
|
||||||
TraceNo traceno = J->cur.traceno;
|
TraceNo traceno = J->cur.traceno;
|
||||||
|
Loading…
Reference in New Issue
Block a user