mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
32/64 bit memory ref cleanup, part 3: GCproto ->lineinfo.
This commit is contained in:
parent
d778982120
commit
8dcc4364cf
@ -184,8 +184,9 @@ LJLIB_CF(jit_util_funcinfo)
|
|||||||
setintfield(L, t, "gcconsts", (int32_t)pt->sizekgc);
|
setintfield(L, t, "gcconsts", (int32_t)pt->sizekgc);
|
||||||
setintfield(L, t, "nconsts", (int32_t)pt->sizekn);
|
setintfield(L, t, "nconsts", (int32_t)pt->sizekn);
|
||||||
setintfield(L, t, "upvalues", (int32_t)pt->sizeuv);
|
setintfield(L, t, "upvalues", (int32_t)pt->sizeuv);
|
||||||
if (pc > 0)
|
if (pc-1 < pt->sizebc)
|
||||||
setintfield(L, t, "currentline", pt->lineinfo ? pt->lineinfo[pc-1] : 0);
|
setintfield(L, t, "currentline",
|
||||||
|
proto_lineinfo(pt) ? proto_line(pt, pc-1) : 0);
|
||||||
lua_pushboolean(L, (pt->flags & PROTO_IS_VARARG));
|
lua_pushboolean(L, (pt->flags & PROTO_IS_VARARG));
|
||||||
lua_setfield(L, -2, "isvararg");
|
lua_setfield(L, -2, "isvararg");
|
||||||
setstrV(L, L->top++, proto_chunkname(pt));
|
setstrV(L, L->top++, proto_chunkname(pt));
|
||||||
|
@ -301,12 +301,12 @@ void LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc)
|
|||||||
g->hookcount = g->hookcstart;
|
g->hookcount = g->hookcstart;
|
||||||
callhook(L, LUA_HOOKCOUNT, -1);
|
callhook(L, LUA_HOOKCOUNT, -1);
|
||||||
}
|
}
|
||||||
if ((g->hookmask & LUA_MASKLINE) && pt->lineinfo) {
|
if ((g->hookmask & LUA_MASKLINE) && proto_lineinfo(pt)) {
|
||||||
BCPos npc = proto_bcpos(pt, pc) - 1;
|
BCPos npc = proto_bcpos(pt, pc) - 1;
|
||||||
BCPos opc = proto_bcpos(pt, oldpc) - 1;
|
BCPos opc = proto_bcpos(pt, oldpc) - 1;
|
||||||
BCLine line = pt->lineinfo[npc];
|
BCLine line = proto_line(pt, npc);
|
||||||
if (npc == 0 || pc <= oldpc ||
|
if (npc == 0 || pc <= oldpc ||
|
||||||
opc >= pt->sizebc || line != pt->lineinfo[opc]) {
|
opc >= pt->sizebc || line != proto_line(pt, opc)) {
|
||||||
L->top = L->base + slots; /* Fix top again after instruction hook. */
|
L->top = L->base + slots; /* Fix top again after instruction hook. */
|
||||||
callhook(L, LUA_HOOKLINE, line);
|
callhook(L, LUA_HOOKLINE, line);
|
||||||
}
|
}
|
||||||
|
14
src/lj_err.c
14
src/lj_err.c
@ -129,7 +129,7 @@ static BCLine currentline(lua_State *L, GCfunc *fn, cTValue *nextframe)
|
|||||||
if (pc != ~(BCPos)0) {
|
if (pc != ~(BCPos)0) {
|
||||||
GCproto *pt = funcproto(fn);
|
GCproto *pt = funcproto(fn);
|
||||||
lua_assert(pc < pt->sizebc);
|
lua_assert(pc < pt->sizebc);
|
||||||
return pt->lineinfo ? pt->lineinfo[pc] : 0;
|
return proto_lineinfo(pt) ? proto_line(pt, pc) : 0;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -224,7 +224,7 @@ void lj_err_pushloc(lua_State *L, GCproto *pt, BCPos pc)
|
|||||||
MSize i, len = name->len;
|
MSize i, len = name->len;
|
||||||
BCLine line;
|
BCLine line;
|
||||||
if (pc)
|
if (pc)
|
||||||
line = pt->lineinfo ? pt->lineinfo[pc-1] : 0;
|
line = proto_lineinfo(pt) ? proto_line(pt, pc-1) : 0;
|
||||||
else
|
else
|
||||||
line = pt->linedefined;
|
line = pt->linedefined;
|
||||||
if (*s == '@') {
|
if (*s == '@') {
|
||||||
@ -377,10 +377,12 @@ LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)
|
|||||||
case 'L':
|
case 'L':
|
||||||
if (isluafunc(fn)) {
|
if (isluafunc(fn)) {
|
||||||
GCtab *t = lj_tab_new(L, 0, 0);
|
GCtab *t = lj_tab_new(L, 0, 0);
|
||||||
BCLine *lineinfo = funcproto(fn)->lineinfo;
|
BCLine *lineinfo = proto_lineinfo(funcproto(fn));
|
||||||
uint32_t i, szl = funcproto(fn)->sizelineinfo;
|
if (lineinfo) {
|
||||||
for (i = 0; i < szl; i++)
|
uint32_t i, szl = funcproto(fn)->sizelineinfo;
|
||||||
setboolV(lj_tab_setint(L, t, lineinfo[i]), 1);
|
for (i = 0; i < szl; i++)
|
||||||
|
setboolV(lj_tab_setint(L, t, lineinfo[i]), 1);
|
||||||
|
}
|
||||||
settabV(L, L->top, t);
|
settabV(L, L->top, t);
|
||||||
} else {
|
} else {
|
||||||
setnilV(L->top);
|
setnilV(L->top);
|
||||||
|
@ -37,7 +37,7 @@ GCproto *lj_func_newproto(lua_State *L)
|
|||||||
pt->sizeuvname = 0;
|
pt->sizeuvname = 0;
|
||||||
pt->linedefined = 0;
|
pt->linedefined = 0;
|
||||||
pt->lastlinedefined = 0;
|
pt->lastlinedefined = 0;
|
||||||
pt->lineinfo = NULL;
|
setmref(pt->lineinfo, NULL);
|
||||||
pt->varinfo = NULL;
|
pt->varinfo = NULL;
|
||||||
setmref(pt->uvname, NULL);
|
setmref(pt->uvname, NULL);
|
||||||
setgcrefnull(pt->chunkname);
|
setgcrefnull(pt->chunkname);
|
||||||
@ -52,7 +52,7 @@ void LJ_FASTCALL lj_func_freeproto(global_State *g, GCproto *pt)
|
|||||||
lj_mem_free(g, mref(pt->k, GCRef) - nkgc, sizek);
|
lj_mem_free(g, mref(pt->k, GCRef) - nkgc, sizek);
|
||||||
lj_mem_freevec(g, proto_bc(pt), pt->sizebc, BCIns);
|
lj_mem_freevec(g, proto_bc(pt), pt->sizebc, BCIns);
|
||||||
lj_mem_freevec(g, proto_uv(pt), pt->sizeuv, uint16_t);
|
lj_mem_freevec(g, proto_uv(pt), pt->sizeuv, uint16_t);
|
||||||
lj_mem_freevec(g, pt->lineinfo, pt->sizelineinfo, int32_t);
|
lj_mem_freevec(g, proto_lineinfo(pt), pt->sizelineinfo, BCLine);
|
||||||
lj_mem_freevec(g, pt->varinfo, pt->sizevarinfo, struct VarInfo);
|
lj_mem_freevec(g, pt->varinfo, pt->sizevarinfo, struct VarInfo);
|
||||||
lj_mem_freevec(g, mref(pt->uvname, GCRef), pt->sizeuvname, GCRef);
|
lj_mem_freevec(g, mref(pt->uvname, GCRef), pt->sizeuvname, GCRef);
|
||||||
lj_trace_freeproto(g, pt);
|
lj_trace_freeproto(g, pt);
|
||||||
|
@ -330,7 +330,7 @@ static size_t propagatemark(global_State *g)
|
|||||||
sizeof(GCRef) * pt->sizekgc +
|
sizeof(GCRef) * pt->sizekgc +
|
||||||
sizeof(lua_Number) * pt->sizekn +
|
sizeof(lua_Number) * pt->sizekn +
|
||||||
sizeof(uint16_t) * pt->sizeuv +
|
sizeof(uint16_t) * pt->sizeuv +
|
||||||
sizeof(int32_t) * pt->sizelineinfo +
|
sizeof(BCLine) * pt->sizelineinfo +
|
||||||
sizeof(VarInfo) * pt->sizevarinfo +
|
sizeof(VarInfo) * pt->sizevarinfo +
|
||||||
sizeof(GCRef) * pt->sizeuvname;
|
sizeof(GCRef) * pt->sizeuvname;
|
||||||
} else {
|
} else {
|
||||||
|
@ -706,7 +706,7 @@ void lj_gdbjit_addtrace(jit_State *J, Trace *T, TraceNo traceno)
|
|||||||
ctx.spadjp = CFRAME_SIZE + (MSize)(parent ? J->trace[parent]->spadjust : 0);
|
ctx.spadjp = CFRAME_SIZE + (MSize)(parent ? J->trace[parent]->spadjust : 0);
|
||||||
ctx.spadj = CFRAME_SIZE + T->spadjust;
|
ctx.spadj = CFRAME_SIZE + T->spadjust;
|
||||||
if (startpc >= proto_bc(pt))
|
if (startpc >= proto_bc(pt))
|
||||||
ctx.lineno = pt->lineinfo ? pt->lineinfo[proto_bcpos(pt, startpc)] : 0;
|
ctx.lineno = proto_lineinfo(pt) ? proto_line(pt,proto_bcpos(pt,startpc)): 0;
|
||||||
else
|
else
|
||||||
ctx.lineno = pt->linedefined;
|
ctx.lineno = pt->linedefined;
|
||||||
ctx.filename = strdata(proto_chunkname(pt));
|
ctx.filename = strdata(proto_chunkname(pt));
|
||||||
|
@ -364,7 +364,7 @@ typedef struct GCproto {
|
|||||||
MSize sizeuvname; /* Size of upvalue names array (may be 0). */
|
MSize sizeuvname; /* Size of upvalue names array (may be 0). */
|
||||||
BCLine linedefined; /* First line of the function definition. */
|
BCLine linedefined; /* First line of the function definition. */
|
||||||
BCLine lastlinedefined; /* Last line of the function definition. */
|
BCLine lastlinedefined; /* Last line of the function definition. */
|
||||||
BCLine *lineinfo; /* Map from bytecode instructions to source lines. */
|
MRef lineinfo; /* Map from bytecode instructions to source lines. */
|
||||||
struct VarInfo *varinfo; /* Names and extents of local variables. */
|
struct VarInfo *varinfo; /* Names and extents of local variables. */
|
||||||
MRef uvname; /* Array of upvalue names (GCRef of GCstr). */
|
MRef uvname; /* Array of upvalue names (GCRef of GCstr). */
|
||||||
GCRef chunkname; /* Name of the chunk this function was defined in. */
|
GCRef chunkname; /* Name of the chunk this function was defined in. */
|
||||||
@ -393,6 +393,9 @@ typedef struct GCproto {
|
|||||||
check_exp((uintptr_t)(idx) < (pt)->sizeuvname, \
|
check_exp((uintptr_t)(idx) < (pt)->sizeuvname, \
|
||||||
gcref(mref((pt)->uvname, GCRef)[(idx)]))
|
gcref(mref((pt)->uvname, GCRef)[(idx)]))
|
||||||
#define proto_chunkname(pt) (gco2str(gcref((pt)->chunkname)))
|
#define proto_chunkname(pt) (gco2str(gcref((pt)->chunkname)))
|
||||||
|
#define proto_lineinfo(pt) (mref((pt)->lineinfo, BCLine))
|
||||||
|
#define proto_line(pt, pos) \
|
||||||
|
check_exp((uintptr_t)(pos) < (pt)->sizebc, proto_lineinfo(pt)[(pos)])
|
||||||
|
|
||||||
/* -- Upvalue object ------------------------------------------------------ */
|
/* -- Upvalue object ------------------------------------------------------ */
|
||||||
|
|
||||||
|
@ -247,19 +247,22 @@ static void patchlist(FuncState *fs, BCPos list, BCPos target)
|
|||||||
static BCPos emitINS(FuncState *fs, BCIns i)
|
static BCPos emitINS(FuncState *fs, BCIns i)
|
||||||
{
|
{
|
||||||
GCproto *pt;
|
GCproto *pt;
|
||||||
|
BCIns *bc;
|
||||||
|
BCLine *lineinfo;
|
||||||
patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);
|
patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);
|
||||||
fs->jpc = NO_JMP;
|
fs->jpc = NO_JMP;
|
||||||
pt = fs->pt;
|
pt = fs->pt;
|
||||||
|
bc = proto_bc(pt);
|
||||||
|
lineinfo = proto_lineinfo(pt);
|
||||||
if (LJ_UNLIKELY(fs->pc >= pt->sizebc)) {
|
if (LJ_UNLIKELY(fs->pc >= pt->sizebc)) {
|
||||||
BCIns *bc;
|
|
||||||
checklimit(fs, fs->pc, LJ_MAX_BCINS, "bytecode instructions");
|
checklimit(fs, fs->pc, LJ_MAX_BCINS, "bytecode instructions");
|
||||||
bc = proto_bc(pt);
|
|
||||||
lj_mem_growvec(fs->L, bc, pt->sizebc, LJ_MAX_BCINS, BCIns);
|
lj_mem_growvec(fs->L, bc, pt->sizebc, LJ_MAX_BCINS, BCIns);
|
||||||
setmref(pt->bc, bc);
|
setmref(pt->bc, bc);
|
||||||
lj_mem_growvec(fs->L, pt->lineinfo, pt->sizelineinfo, LJ_MAX_BCINS, BCLine);
|
lj_mem_growvec(fs->L, lineinfo, pt->sizelineinfo, LJ_MAX_BCINS, BCLine);
|
||||||
|
setmref(pt->lineinfo, lineinfo);
|
||||||
}
|
}
|
||||||
*proto_insptr(pt, fs->pc) = i;
|
bc[fs->pc] = i;
|
||||||
pt->lineinfo[fs->pc] = fs->ls->lastline;
|
lineinfo[fs->pc] = fs->ls->lastline;
|
||||||
return fs->pc++;
|
return fs->pc++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1233,6 +1236,7 @@ static void close_func(LexState *ls)
|
|||||||
GCproto *pt = fs->pt;
|
GCproto *pt = fs->pt;
|
||||||
BCIns *bc;
|
BCIns *bc;
|
||||||
GCRef *uvname;
|
GCRef *uvname;
|
||||||
|
BCLine *lineinfo;
|
||||||
removevars(ls, 0);
|
removevars(ls, 0);
|
||||||
finalret(fs, pt);
|
finalret(fs, pt);
|
||||||
bc = proto_bc(pt);
|
bc = proto_bc(pt);
|
||||||
@ -1241,7 +1245,9 @@ static void close_func(LexState *ls)
|
|||||||
pt->sizebc = fs->pc;
|
pt->sizebc = fs->pc;
|
||||||
collectk(fs, pt);
|
collectk(fs, pt);
|
||||||
collectuv(fs, pt);
|
collectuv(fs, pt);
|
||||||
lj_mem_reallocvec(L, pt->lineinfo, pt->sizelineinfo, fs->pc, BCLine);
|
lineinfo = proto_lineinfo(pt);
|
||||||
|
lj_mem_reallocvec(L, lineinfo, pt->sizelineinfo, fs->pc, BCLine);
|
||||||
|
setmref(pt->lineinfo, lineinfo);
|
||||||
pt->sizelineinfo = fs->pc;
|
pt->sizelineinfo = fs->pc;
|
||||||
lj_mem_reallocvec(L, pt->varinfo, pt->sizevarinfo, fs->nlocvars, VarInfo);
|
lj_mem_reallocvec(L, pt->varinfo, pt->sizevarinfo, fs->nlocvars, VarInfo);
|
||||||
pt->sizevarinfo = fs->nlocvars;
|
pt->sizevarinfo = fs->nlocvars;
|
||||||
@ -1509,7 +1515,7 @@ static void funcargs(LexState *ls, ExpDesc *e)
|
|||||||
}
|
}
|
||||||
init_exp(e, VCALL, emitINS(fs, ins));
|
init_exp(e, VCALL, emitINS(fs, ins));
|
||||||
e->u.s.aux = base;
|
e->u.s.aux = base;
|
||||||
fs->pt->lineinfo[fs->pc - 1] = line;
|
proto_lineinfo(fs->pt)[fs->pc - 1] = line;
|
||||||
fs->freereg = base+1; /* call removes function and arguments and leaves
|
fs->freereg = base+1; /* call removes function and arguments and leaves
|
||||||
(unless changed) one result */
|
(unless changed) one result */
|
||||||
}
|
}
|
||||||
@ -1929,9 +1935,9 @@ static void forbody(LexState *ls, BCReg base, BCLine line, BCReg nvars,
|
|||||||
fixjump(fs, loop, fs->pc);
|
fixjump(fs, loop, fs->pc);
|
||||||
emitABC(fs, BC_ITERC, base+3, nvars+1, 2+1);
|
emitABC(fs, BC_ITERC, base+3, nvars+1, 2+1);
|
||||||
loopend = emitAJ(fs, BC_ITERL, base+3, NO_JMP);
|
loopend = emitAJ(fs, BC_ITERL, base+3, NO_JMP);
|
||||||
fs->pt->lineinfo[loopend-1] = line;
|
proto_lineinfo(fs->pt)[loopend-1] = line;
|
||||||
}
|
}
|
||||||
fs->pt->lineinfo[loopend] = line; /* pretend last op starts the loop */
|
proto_lineinfo(fs->pt)[loopend] = line; /* pretend last op starts the loop */
|
||||||
fixjump(fs, loopend, loop+1);
|
fixjump(fs, loopend, loop+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2091,7 +2097,7 @@ static void funcstat(LexState *ls, BCLine line)
|
|||||||
body(ls, &b, needself, line);
|
body(ls, &b, needself, line);
|
||||||
fs = ls->fs;
|
fs = ls->fs;
|
||||||
storevar(fs, &v, &b);
|
storevar(fs, &v, &b);
|
||||||
fs->pt->lineinfo[fs->pc - 1] = line;
|
proto_lineinfo(fs->pt)[fs->pc - 1] = line;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void exprstat(LexState *ls)
|
static void exprstat(LexState *ls)
|
||||||
|
Loading…
Reference in New Issue
Block a user