Improve assertions.
This commit is contained in:
@@ -104,7 +104,8 @@ static void perftools_addtrace(GCtrace *T)
|
||||
name++;
|
||||
else
|
||||
name = "(string)";
|
||||
lua_assert(startpc >= proto_bc(pt) && startpc < proto_bc(pt) + pt->sizebc);
|
||||
lj_assertX(startpc >= proto_bc(pt) && startpc < proto_bc(pt) + pt->sizebc,
|
||||
"trace PC out of range");
|
||||
lineno = lj_debug_line(pt, proto_bcpos(pt, startpc));
|
||||
if (!fp) {
|
||||
char fname[40];
|
||||
@@ -183,7 +184,7 @@ void lj_trace_reenableproto(GCproto *pt)
|
||||
{
|
||||
if ((pt->flags & PROTO_ILOOP)) {
|
||||
BCIns *bc = proto_bc(pt);
|
||||
BCPos i, sizebc = pt->sizebc;;
|
||||
BCPos i, sizebc = pt->sizebc;
|
||||
pt->flags &= ~PROTO_ILOOP;
|
||||
if (bc_op(bc[0]) == BC_IFUNCF)
|
||||
setbc_op(&bc[0], BC_FUNCF);
|
||||
@@ -205,27 +206,28 @@ static void trace_unpatch(jit_State *J, GCtrace *T)
|
||||
return; /* No need to unpatch branches in parent traces (yet). */
|
||||
switch (bc_op(*pc)) {
|
||||
case BC_JFORL:
|
||||
lua_assert(traceref(J, bc_d(*pc)) == T);
|
||||
lj_assertJ(traceref(J, bc_d(*pc)) == T, "JFORL references other trace");
|
||||
*pc = T->startins;
|
||||
pc += bc_j(T->startins);
|
||||
lua_assert(bc_op(*pc) == BC_JFORI);
|
||||
lj_assertJ(bc_op(*pc) == BC_JFORI, "FORL does not point to JFORI");
|
||||
setbc_op(pc, BC_FORI);
|
||||
break;
|
||||
case BC_JITERL:
|
||||
case BC_JLOOP:
|
||||
lua_assert(op == BC_ITERL || op == BC_LOOP || bc_isret(op));
|
||||
lj_assertJ(op == BC_ITERL || op == BC_LOOP || bc_isret(op),
|
||||
"bad original bytecode %d", op);
|
||||
*pc = T->startins;
|
||||
break;
|
||||
case BC_JMP:
|
||||
lua_assert(op == BC_ITERL);
|
||||
lj_assertJ(op == BC_ITERL, "bad original bytecode %d", op);
|
||||
pc += bc_j(*pc)+2;
|
||||
if (bc_op(*pc) == BC_JITERL) {
|
||||
lua_assert(traceref(J, bc_d(*pc)) == T);
|
||||
lj_assertJ(traceref(J, bc_d(*pc)) == T, "JITERL references other trace");
|
||||
*pc = T->startins;
|
||||
}
|
||||
break;
|
||||
case BC_JFUNCF:
|
||||
lua_assert(op == BC_FUNCF);
|
||||
lj_assertJ(op == BC_FUNCF, "bad original bytecode %d", op);
|
||||
*pc = T->startins;
|
||||
break;
|
||||
default: /* Already unpatched. */
|
||||
@@ -237,7 +239,8 @@ static void trace_unpatch(jit_State *J, GCtrace *T)
|
||||
static void trace_flushroot(jit_State *J, GCtrace *T)
|
||||
{
|
||||
GCproto *pt = &gcref(T->startpt)->pt;
|
||||
lua_assert(T->root == 0 && pt != NULL);
|
||||
lj_assertJ(T->root == 0, "not a root trace");
|
||||
lj_assertJ(pt != NULL, "trace has no prototype");
|
||||
/* First unpatch any modified bytecode. */
|
||||
trace_unpatch(J, T);
|
||||
/* Unlink root trace from chain anchored in prototype. */
|
||||
@@ -353,7 +356,8 @@ void lj_trace_freestate(global_State *g)
|
||||
{ /* This assumes all traces have already been freed. */
|
||||
ptrdiff_t i;
|
||||
for (i = 1; i < (ptrdiff_t)J->sizetrace; i++)
|
||||
lua_assert(i == (ptrdiff_t)J->cur.traceno || traceref(J, i) == NULL);
|
||||
lj_assertG(i == (ptrdiff_t)J->cur.traceno || traceref(J, i) == NULL,
|
||||
"trace still allocated");
|
||||
}
|
||||
#endif
|
||||
lj_mcode_free(J);
|
||||
@@ -408,8 +412,9 @@ static void trace_start(jit_State *J)
|
||||
if ((J->pt->flags & PROTO_NOJIT)) { /* JIT disabled for this proto? */
|
||||
if (J->parent == 0 && J->exitno == 0) {
|
||||
/* Lazy bytecode patching to disable hotcount events. */
|
||||
lua_assert(bc_op(*J->pc) == BC_FORL || bc_op(*J->pc) == BC_ITERL ||
|
||||
bc_op(*J->pc) == BC_LOOP || bc_op(*J->pc) == BC_FUNCF);
|
||||
lj_assertJ(bc_op(*J->pc) == BC_FORL || bc_op(*J->pc) == BC_ITERL ||
|
||||
bc_op(*J->pc) == BC_LOOP || bc_op(*J->pc) == BC_FUNCF,
|
||||
"bad hot bytecode %d", bc_op(*J->pc));
|
||||
setbc_op(J->pc, (int)bc_op(*J->pc)+(int)BC_ILOOP-(int)BC_LOOP);
|
||||
J->pt->flags |= PROTO_ILOOP;
|
||||
}
|
||||
@@ -420,7 +425,8 @@ static void trace_start(jit_State *J)
|
||||
/* Get a new trace number. */
|
||||
traceno = trace_findfree(J);
|
||||
if (LJ_UNLIKELY(traceno == 0)) { /* No free trace? */
|
||||
lua_assert((J2G(J)->hookmask & HOOK_GC) == 0);
|
||||
lj_assertJ((J2G(J)->hookmask & HOOK_GC) == 0,
|
||||
"recorder called from GC hook");
|
||||
lj_trace_flushall(J->L);
|
||||
J->state = LJ_TRACE_IDLE; /* Silently ignored. */
|
||||
return;
|
||||
@@ -496,7 +502,7 @@ static void trace_stop(jit_State *J)
|
||||
goto addroot;
|
||||
case BC_JMP:
|
||||
/* Patch exit branch in parent to side trace entry. */
|
||||
lua_assert(J->parent != 0 && J->cur.root != 0);
|
||||
lj_assertJ(J->parent != 0 && J->cur.root != 0, "not a side trace");
|
||||
lj_asm_patchexit(J, traceref(J, J->parent), J->exitno, J->cur.mcode);
|
||||
/* Avoid compiling a side trace twice (stack resizing uses parent exit). */
|
||||
traceref(J, J->parent)->snap[J->exitno].count = SNAPCOUNT_DONE;
|
||||
@@ -515,7 +521,7 @@ static void trace_stop(jit_State *J)
|
||||
traceref(J, J->exitno)->link = traceno;
|
||||
break;
|
||||
default:
|
||||
lua_assert(0);
|
||||
lj_assertJ(0, "bad stop bytecode %d", op);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -536,8 +542,8 @@ static void trace_stop(jit_State *J)
|
||||
static int trace_downrec(jit_State *J)
|
||||
{
|
||||
/* Restart recording at the return instruction. */
|
||||
lua_assert(J->pt != NULL);
|
||||
lua_assert(bc_isret(bc_op(*J->pc)));
|
||||
lj_assertJ(J->pt != NULL, "no active prototype");
|
||||
lj_assertJ(bc_isret(bc_op(*J->pc)), "not at a return bytecode");
|
||||
if (bc_op(*J->pc) == BC_RETM)
|
||||
return 0; /* NYI: down-recursion with RETM. */
|
||||
J->parent = 0;
|
||||
@@ -750,7 +756,7 @@ static void trace_hotside(jit_State *J, const BCIns *pc)
|
||||
isluafunc(curr_func(J->L)) &&
|
||||
snap->count != SNAPCOUNT_DONE &&
|
||||
++snap->count >= J->param[JIT_P_hotexit]) {
|
||||
lua_assert(J->state == LJ_TRACE_IDLE);
|
||||
lj_assertJ(J->state == LJ_TRACE_IDLE, "hot side exit while recording");
|
||||
/* J->parent is non-zero for a side trace. */
|
||||
J->state = LJ_TRACE_START;
|
||||
lj_trace_ins(J, pc);
|
||||
@@ -822,7 +828,7 @@ static TraceNo trace_exit_find(jit_State *J, MCode *pc)
|
||||
if (T && pc >= T->mcode && pc < (MCode *)((char *)T->mcode + T->szmcode))
|
||||
return traceno;
|
||||
}
|
||||
lua_assert(0);
|
||||
lj_assertJ(0, "bad exit pc");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -844,13 +850,13 @@ int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr)
|
||||
T = traceref(J, J->parent); UNUSED(T);
|
||||
#ifdef EXITSTATE_CHECKEXIT
|
||||
if (J->exitno == T->nsnap) { /* Treat stack check like a parent exit. */
|
||||
lua_assert(T->root != 0);
|
||||
lj_assertJ(T->root != 0, "stack check in root trace");
|
||||
J->exitno = T->ir[REF_BASE].op2;
|
||||
J->parent = T->ir[REF_BASE].op1;
|
||||
T = traceref(J, J->parent);
|
||||
}
|
||||
#endif
|
||||
lua_assert(T != NULL && J->exitno < T->nsnap);
|
||||
lj_assertJ(T != NULL && J->exitno < T->nsnap, "bad trace or exit number");
|
||||
exd.J = J;
|
||||
exd.exptr = exptr;
|
||||
errcode = lj_vm_cpcall(L, NULL, &exd, trace_exit_cp);
|
||||
|
||||
Reference in New Issue
Block a user