Skip to content

Commit

Permalink
Add log of recorded bytecodes (BCLogRec) to jit_State
Browse files Browse the repository at this point in the history
  • Loading branch information
lukego committed Nov 28, 2017
1 parent 783cf2d commit 7a4e25b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
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;
BCPos pos;
int32_t framedepth;
} 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. */
BCRecLog *bclognext; /* Next entry in the bytecode log. */
BCRecLog *bcloglast; /* Last entry in the bytecode log. */

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

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->bclognext < J->bcloglast) {
BCRecLog *log = J->bclognext++;
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->bclognext = J->bclog;

/* 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
3 changes: 3 additions & 0 deletions 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-REF_BIAS, 65536*sizeof(IRIns));
Expand Down Expand Up @@ -216,6 +217,8 @@ 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->bclognext = J->bclog = (BCRecLog *)lj_mem_new(L, sizeof(BCRecLog)*65536);
J->bcloglast = J->bclog + 65535;
IRIns *irbufmem = (IRIns *)lj_mem_new(L, sizeof(IRIns)*65536);
if (irbufmem == NULL || J->snapbuf == NULL || J->snapmapbuf == NULL)
return NULL;
Expand Down

0 comments on commit 7a4e25b

Please sign in to comment.