Skip to content

Commit

Permalink
Merge snabbco#101 branch 'long-running-stable' into integrate
Browse files Browse the repository at this point in the history
  • Loading branch information
lukego committed Dec 11, 2017
2 parents 4fafb32 + ce6fbb4 commit 0a33b43
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/lj_jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@ static LJ_AINLINE MSize snap_nextofs(GCtrace *T, SnapShot *snap)
/* Round-robin penalty cache for bytecodes leading to aborted traces. */
typedef struct HotPenalty {
MRef pc; /* Starting bytecode PC. */
uint16_t val; /* Penalty value, i.e. hotcount start. */
uint32_t val; /* Penalty value, i.e. hotcount start. */
uint16_t reason; /* Abort reason (really TraceErr). */
} HotPenalty;

#define PENALTY_SLOTS 64 /* Penalty cache slot. Must be a power of 2. */
#define PENALTY_MIN (36*2) /* Minimum penalty value. */
#define PENALTY_MAX 60000 /* Maximum penalty value. */
#define PENALTY_MAX 6000000 /* Maximum penalty value. */
#define PENALTY_RNDBITS 4 /* # of random bits to add to penalty value. */

/* Round-robin backpropagation cache for narrowing conversions. */
Expand Down
3 changes: 2 additions & 1 deletion src/lj_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ static void rec_loop_interp(jit_State *J, const BCIns *pc, LoopEvent ev)
/* Handle the case when an already compiled loop op is hit. */
static void rec_loop_jit(jit_State *J, TraceNo lnk, LoopEvent ev)
{
if (J->parent == 0 && J->exitno == 0) { /* Root trace hit an inner loop. */
/* Root trace hit an inner loop. */
if (J->parent == 0 && J->exitno == 0 && !innerloopleft(J, J->startpc)) {
/* Better let the inner loop spawn a side trace back here. */
lj_trace_err(J, LJ_TRERR_LINNER);
} else if (ev != LOOPEV_LEAVE) { /* Side trace enters a compiled loop. */
Expand Down
10 changes: 9 additions & 1 deletion src/lj_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ int lj_trace_flushall(lua_State *L)
}
/* Clear penalty cache. */
memset(J->penalty, 0, sizeof(J->penalty));
/* Reset hotcounts. */
lj_dispatch_init_hotcount(J2G(J));
/* Free the whole machine code and invalidate all exit stub groups. */
lj_mcode_free(J);
memset(J->exitstubgroup, 0, sizeof(J->exitstubgroup));
Expand Down Expand Up @@ -335,7 +337,7 @@ static void penalty_pc(jit_State *J, GCproto *pt, BCIns *pc, TraceError e)
J->penaltyslot = (J->penaltyslot + 1) & (PENALTY_SLOTS-1);
setmref(J->penalty[i].pc, pc);
setpenalty:
J->penalty[i].val = (uint16_t)val;
J->penalty[i].val = val;
J->penalty[i].reason = e;
hotcount_set(J2GG(J), pc+1, val);
}
Expand Down Expand Up @@ -401,6 +403,7 @@ static void trace_stop(jit_State *J)
TraceNo traceno = J->cur.traceno;
GCtrace *T = J->curfinal;
lua_State *L;
int i;

switch (op) {
case BC_FORL:
Expand Down Expand Up @@ -452,6 +455,11 @@ static void trace_stop(jit_State *J)
J->postproc = LJ_POST_NONE;
trace_save(J, T);

/* Clear any penalty after successful recording. */
for (i = 0; i < PENALTY_SLOTS; i++)
if (mref(J->penalty[i].pc, const BCIns) == pc)
J->penalty[i].val = PENALTY_MIN;

L = J->L;
}

Expand Down

0 comments on commit 0a33b43

Please sign in to comment.