Skip to content

Commit

Permalink
lj_trace.c: Add penalty to trace abort message
Browse files Browse the repository at this point in the history
(cherry picked from commit 47a7020)
  • Loading branch information
alexandergall committed Jan 8, 2018
1 parent 0f5068d commit 5df67e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 10 additions & 2 deletions lib/luajit/src/jit/dump.lua
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ local function fmterr(err, info)
end

-- Dump trace states.
local function dump_trace(what, tr, func, pc, otr, oex)
local function dump_trace(what, tr, func, pc, otr, oex, penalty)
if what == "stop" or (what == "abort" and dumpmode.a) then
if dumpmode.i then dump_ir(tr, dumpmode.s, dumpmode.r and what == "stop")
elseif dumpmode.s then dump_snap(tr) end
Expand All @@ -565,7 +565,15 @@ local function dump_trace(what, tr, func, pc, otr, oex)
elseif what == "stop" or what == "abort" then
out:write("---- TRACE ", tr, " ", what)
if what == "abort" then
out:write(" ", fmtfunc(func, pc), " -- ", fmterr(otr, oex), "\n")
out:write(" ", fmtfunc(func, pc), " -- ", fmterr(otr, oex))
if penalty then
if penalty == 0 then
out:write(" -- ", 'blacklisting')
else
out:write(" -- ", 'penalty '..penalty)
end
out:write("\n")
end
else
local info = traceinfo(tr)
local link, ltype = info.link, info.linktype
Expand Down
10 changes: 7 additions & 3 deletions lib/luajit/src/lj_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ static void blacklist_pc(GCproto *pt, BCIns *pc)
}

/* Penalize a bytecode instruction. */
static void penalty_pc(jit_State *J, GCproto *pt, BCIns *pc, TraceError e)
static int penalty_pc(jit_State *J, GCproto *pt, BCIns *pc, TraceError e)
{
uint32_t i, val = PENALTY_MIN;
for (i = 0; i < PENALTY_SLOTS; i++)
Expand All @@ -394,7 +394,7 @@ static void penalty_pc(jit_State *J, GCproto *pt, BCIns *pc, TraceError e)
LJ_PRNG_BITS(J, PENALTY_RNDBITS);
if (val > PENALTY_MAX) {
blacklist_pc(pt, pc); /* Blacklist it, if that didn't help. */
return;
return(0);
}
goto setpenalty;
}
Expand All @@ -406,6 +406,7 @@ static void penalty_pc(jit_State *J, GCproto *pt, BCIns *pc, TraceError e)
J->penalty[i].val = val;
J->penalty[i].reason = e;
hotcount_set(J2GG(J), pc+1, val);
return(val);
}

/* -- Trace compiler state machine ---------------------------------------- */
Expand Down Expand Up @@ -570,6 +571,7 @@ static int trace_abort(jit_State *J)
lua_State *L = J->L;
TraceError e = LJ_TRERR_RECERR;
TraceNo traceno;
int penalty = -1;

J->postproc = LJ_POST_NONE;
lj_mcode_abort(J);
Expand All @@ -591,7 +593,7 @@ static int trace_abort(jit_State *J)
if (e == LJ_TRERR_RETRY)
hotcount_set(J2GG(J), startpc+1, 1); /* Immediate retry. */
else
penalty_pc(J, &gcref(J->cur.startpt)->pt, startpc, e);
penalty = penalty_pc(J, &gcref(J->cur.startpt)->pt, startpc, e);
} else {
traceref(J, J->exitno)->link = J->exitno; /* Self-link is blacklisted. */
}
Expand Down Expand Up @@ -621,6 +623,8 @@ static int trace_abort(jit_State *J)
setintV(L->top++, proto_bcpos(funcproto(fn), pc));
copyTV(L, L->top++, restorestack(L, errobj));
copyTV(L, L->top++, &J->errinfo);
if (penalty >= 0)
setintV(L->top++, penalty);
);
/* Drop aborted trace after the vmevent (which may still access it). */
setgcrefnull(J->trace[traceno]);
Expand Down

0 comments on commit 5df67e8

Please sign in to comment.