Skip to content

Commit

Permalink
Merge branch 'raptorjit/master' into fix-alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
lukego committed Dec 1, 2017
2 parents d371db6 + 14120c1 commit ad02215
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 50 deletions.
16 changes: 5 additions & 11 deletions src/lj_bcread.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,12 @@ static uint32_t bcread_uleb128_33(LexState *ls)
/* Read debug info of a prototype. */
static void bcread_dbg(LexState *ls, GCproto *pt, MSize sizedbg)
{
void *lineinfo = (void *)proto_lineinfo(pt);
uint32_t *lineinfo = (uint32_t*)proto_lineinfo(pt);
bcread_block(ls, lineinfo, sizedbg);
/* Swap lineinfo if the endianess differs. */
if (bcread_swap(ls) && pt->numline >= 256) {
MSize i, n = pt->sizebc-1;
if (pt->numline < 65536) {
uint16_t *p = (uint16_t *)lineinfo;
for (i = 0; i < n; i++) p[i] = (uint16_t)((p[i] >> 8)|(p[i] << 8));
} else {
uint32_t *p = (uint32_t *)lineinfo;
for (i = 0; i < n; i++) p[i] = lj_bswap(p[i]);
}
if (bcread_swap(ls)) {
int i;
for (i = 0; i < pt->sizebc-1; i++) lineinfo[i] = lj_bswap(lineinfo[i]);
}
}

Expand Down Expand Up @@ -367,7 +361,7 @@ GCproto *lj_bcread_proto(LexState *ls)
pt->firstline = firstline;
pt->numline = numline;
if (sizedbg) {
MSize sizeli = (sizebc-1) << (numline < 256 ? 0 : numline < 65536 ? 1 : 2);
MSize sizeli = (sizebc-1) * sizeof(BCLine);
setmref(pt->lineinfo, (char *)pt + ofsdbg);
setmref(pt->uvinfo, (char *)pt + ofsdbg + sizeli);
bcread_dbg(ls, pt, sizedbg);
Expand Down
15 changes: 3 additions & 12 deletions src/lj_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,7 @@ BCLine lj_debug_line(GCproto *pt, BCPos pc)
BCLine first = pt->firstline;
if (pc == pt->sizebc) return first + pt->numline;
if (pc-- == 0) return first;
if (pt->numline < 256)
return first + (BCLine)((const uint8_t *)lineinfo)[pc];
else if (pt->numline < 65536)
return first + (BCLine)((const uint16_t *)lineinfo)[pc];
else
return first + (BCLine)((const uint32_t *)lineinfo)[pc];
return first + ((BCLine *)lineinfo)[pc];
}
return 0;
}
Expand Down Expand Up @@ -497,16 +492,12 @@ int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, int ext)
if (isluafunc(fn)) {
GCtab *t = lj_tab_new(L, 0, 0);
GCproto *pt = funcproto(fn);
const void *lineinfo = proto_lineinfo(pt);
const uint32_t *lineinfo = proto_lineinfo(pt);
if (lineinfo) {
BCLine first = pt->firstline;
int sz = pt->numline < 256 ? 1 : pt->numline < 65536 ? 2 : 4;
MSize i, szl = pt->sizebc-1;
for (i = 0; i < szl; i++) {
BCLine line = first +
(sz == 1 ? (BCLine)((const uint8_t *)lineinfo)[i] :
sz == 2 ? (BCLine)((const uint16_t *)lineinfo)[i] :
(BCLine)((const uint32_t *)lineinfo)[i]);
BCLine line = first + lineinfo[i];
setboolV(lj_tab_setint(L, t, line), 1);
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/lj_jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ typedef struct FoldState {
IRIns right[2]; /* Instruction referenced by right operand. */
} FoldState;

/* Log entry for a bytecode that was recorded. */
typedef struct BCRecLog {
GCproto *pt; /* Prototype of bytecode function (or NULL). */
BCPos pos; /* Position of bytecode in prototype. */
int32_t framedepth; /* Frame depth when recorded. */
} BCRecLog;

/* JIT compiler state. */
typedef struct jit_State {
GCtrace cur; /* Current trace. */
Expand Down Expand Up @@ -340,6 +347,10 @@ typedef struct jit_State {
SnapEntry *snapmapbuf; /* Temp. snapshot map buffer. */
MSize sizesnapmap; /* Size of temp. snapshot map buffer. */

BCRecLog *bclog; /* Start of of recorded bytecode log. */
uint32_t nbclog; /* Number of logged bytecodes. */
uint32_t maxbclog; /* Max entries in the bytecode log. */

PostProc postproc; /* Required post-processing after execution. */
uint8_t retryrec; /* Retry recording. */

Expand Down
4 changes: 2 additions & 2 deletions src/lj_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ typedef struct GCproto {
GCRef chunkname; /* Name of the chunk this function was defined in. */
BCLine firstline; /* First line of the function definition. */
BCLine numline; /* Number of lines for the function definition. */
MRef lineinfo; /* Compressed map from bytecode ins. to source line. */
MRef lineinfo; /* Map from bytecode ins. to source line. */
MRef uvinfo; /* Upvalue names. */
MRef varinfo; /* Names and compressed extents of local variables. */
} GCproto;
Expand Down Expand Up @@ -345,7 +345,7 @@ typedef struct GCproto {

#define proto_chunkname(pt) (strref((pt)->chunkname))
#define proto_chunknamestr(pt) (strdata(proto_chunkname((pt))))
#define proto_lineinfo(pt) (mref((pt)->lineinfo, const void))
#define proto_lineinfo(pt) (mref((pt)->lineinfo, const uint32_t))
#define proto_uvinfo(pt) (mref((pt)->uvinfo, const uint8_t))
#define proto_varinfo(pt) (mref((pt)->varinfo, const uint8_t))

Expand Down
32 changes: 8 additions & 24 deletions src/lj_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ static void fs_fixup_uv1(FuncState *fs, GCproto *pt, uint16_t *uv)
/* Prepare lineinfo for prototype. */
static size_t fs_prep_line(FuncState *fs, BCLine numline)
{
return (fs->pc-1) << (numline < 256 ? 0 : numline < 65536 ? 1 : 2);
return (fs->pc-1) * sizeof(BCLine);
}

/* Fixup lineinfo for prototype. */
Expand All @@ -1365,28 +1365,12 @@ static void fs_fixup_line(FuncState *fs, GCproto *pt,
pt->firstline = fs->linedefined;
pt->numline = numline;
setmref(pt->lineinfo, lineinfo);
if (LJ_LIKELY(numline < 256)) {
uint8_t *li = (uint8_t *)lineinfo;
do {
BCLine delta = base[i].line - first;
lua_assert(delta >= 0 && delta < 256);
li[i] = (uint8_t)delta;
} while (++i < n);
} else if (LJ_LIKELY(numline < 65536)) {
uint16_t *li = (uint16_t *)lineinfo;
do {
BCLine delta = base[i].line - first;
lua_assert(delta >= 0 && delta < 65536);
li[i] = (uint16_t)delta;
} while (++i < n);
} else {
uint32_t *li = (uint32_t *)lineinfo;
do {
BCLine delta = base[i].line - first;
lua_assert(delta >= 0);
li[i] = (uint32_t)delta;
} while (++i < n);
}
uint32_t *li = (uint32_t *)lineinfo;
do {
BCLine delta = base[i].line - first;
lua_assert(delta >= 0);
li[i] = (uint32_t)delta;
} while (++i < n);
}

/* Prepare variable info for prototype. */
Expand Down Expand Up @@ -1443,7 +1427,7 @@ static void fs_fixup_var(LexState *ls, GCproto *pt, uint8_t *p, size_t ofsvar)
/* Initialize with empty debug info, if disabled. */
#define fs_prep_line(fs, numline) (UNUSED(numline), 0)
#define fs_fixup_line(fs, pt, li, numline) \
pt->firstline = pt->numline = 0, setmref((pt)->lineinfo, NULL)
pt->firstline = pt->numline = 0, setmref((pt)->lineinfo, NULL)
#define fs_prep_var(ls, fs, ofsvar) (UNUSED(ofsvar), 0)
#define fs_fixup_var(ls, pt, p, ofsvar) \
setmref((pt)->uvinfo, NULL), setmref((pt)->varinfo, NULL)
Expand Down
9 changes: 9 additions & 0 deletions src/lj_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,13 @@ void lj_record_ins(jit_State *J)
BCOp op;
TRef ra, rb, rc;

if (J->nbclog < J->maxbclog) {
BCRecLog *log = &J->bclog[J->nbclog++];
log->pt = J->pt;
log->pos = J->pt ? proto_bcpos(J->pt, J->pc) : -1;
log->framedepth = J->framedepth;
}

/* Perform post-processing action before recording the next instruction. */
if (LJ_UNLIKELY(J->postproc != LJ_POST_NONE)) {
switch (J->postproc) {
Expand Down Expand Up @@ -2436,6 +2443,8 @@ void lj_record_setup(jit_State *J)
J->bc_min = NULL; /* Means no limit. */
J->bc_extent = ~(MSize)0;

J->nbclog = 0;

/* Emit instructions for fixed references. Also triggers initial IR alloc. */
emitir_raw(IRT(IR_BASE, IRT_PGC), J->parent, J->exitno);
for (i = 0; i <= 2; i++) {
Expand Down
7 changes: 6 additions & 1 deletion src/lj_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ static void close_state(lua_State *L)
lj_mem_freevec(g, g->strhash, g->strmask+1, GCRef);
lj_buf_free(g, &g->tmpbuf);
lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue);
lj_mem_free(g, J->bclog, sizeof(BCRecLog)*65536);
lj_mem_free(g, J->snapmapbuf, J->sizesnapmap);
lj_mem_free(g, J->snapbuf, J->sizesnap);
lj_mem_free(g, J->irbuf, 65536*sizeof(IRIns));
Expand Down Expand Up @@ -216,8 +217,12 @@ LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)
J->sizesnapmap = sizeof(SnapEntry)*65536;
J->snapbuf = (SnapShot *)lj_mem_new(L, J->sizesnap);
J->snapmapbuf = (SnapEntry *)lj_mem_new(L, J->sizesnapmap);
J->maxbclog = 65536;
J->bclog = (BCRecLog *)lj_mem_new(L, sizeof(BCRecLog)*J->maxbclog);
J->nbclog = 0;
J->irbuf = (IRIns *)lj_mem_new(L, sizeof(IRIns)*65536);
if (J->irbuf == NULL || J->snapbuf == NULL || J->snapmapbuf == NULL)
if (J->irbuf == NULL || J->snapbuf == NULL ||
J->bclog == NULL || J->snapmapbuf == NULL)
return NULL;
lj_dispatch_init((GG_State *)L);
L->status = LUA_ERRERR+1; /* Avoid touching the stack upon memory error. */
Expand Down
9 changes: 9 additions & 0 deletions src/lj_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ int lj_trace_flushall(lua_State *L)
}
J->cur.traceno = 0;
J->freetrace = 0;
/* Unpatch blacklisted byte codes. */
GCRef *p = &(G(L)->gc.root);
GCobj *o;
while ((o = gcref(*p)) != NULL) {
if (o->gch.gct == ~LJ_TPROTO) {
lj_trace_reenableproto(gco2pt(o));
}
p = &o->gch.nextgc;
}
/* Clear penalty cache. */
memset(J->penalty, 0, sizeof(J->penalty));
/* Free the whole machine code and invalidate all exit stub groups. */
Expand Down

0 comments on commit ad02215

Please sign in to comment.