Projectkk2glider/issue 4827 (#4855)

* Reverting a part of f94b4c743d that deals with the size of table hash. Fixes 4827, but uses more memory and CPU.

* New internal Lua traces
This commit is contained in:
Damjan Adamic
2017-04-26 21:45:46 +02:00
committed by Bertrand Songis
parent 3aceed62c9
commit 73f4b8f172
4 changed files with 22 additions and 11 deletions
+10
View File
@@ -70,8 +70,18 @@ extern "C" {
#if defined(TRACE_LUA_INTERNALS_ENABLED)
#define TRACE_LUA_INTERNALS(f_, ...) debugPrintf(("[LUA INT] " f_ "\r\n"), ##__VA_ARGS__)
#define TRACE_LUA_INTERNALS_WITH_LINEINFO(L, f_, ...) do { \
lua_Debug ar; \
if (lua_getstack(L, 1, &ar)) { \
lua_getinfo(L, ">Sl", &ar); \
debugPrintf("%s:%d: ", ar.short_src, ar.currentline); \
} \
debugPrintf(("[LUA INT] " f_ "\r\n"), ##__VA_ARGS__); \
} while(0)
#else
#define TRACE_LUA_INTERNALS(...)
#define TRACE_LUA_INTERNALS_WITH_LINEINFO(L, f_, ...)
#endif
#if defined(DEBUG) && !defined(SIMU)
+2 -2
View File
@@ -569,7 +569,7 @@ typedef struct Node {
typedef struct Table {
CommonHeader;
lu_byte flags; /* 1<<p means tagmethod(p) is not present */
lu_byte lsizenode; /* size of `node' array */
lu_byte lsizenode; /* log2 of size of `node' array */
struct Table *metatable;
TValue *array; /* array part */
Node *node;
@@ -588,7 +588,7 @@ typedef struct Table {
#define twoto(x) (1<<(x))
#define sizenode(t) ((t)->lsizenode)
#define sizenode(t) (twoto((t)->lsizenode))
/*
+2
View File
@@ -181,6 +181,7 @@ static void new_localvar (LexState *ls, TString *name) {
int reg = registerlocalvar(ls, name);
checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,
MAXVARS, "local variables");
TRACE_LUA_INTERNALS("new_localvar %s %d", getstr(name), dyd->actvar.n + 1 - fs->firstlocal);
luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,
dyd->actvar.size, Vardesc, MAX_INT, "local variables");
dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg);
@@ -1529,6 +1530,7 @@ static void retstat (LexState *ls) {
static void statement (LexState *ls) {
int line = ls->linenumber; /* may be needed for error messages */
enterlevel(ls);
TRACE_LUA_INTERNALS("statement %02x at line %d", ls->t.token, line);
switch (ls->t.token) {
case ';': { /* stat -> ';' (empty statement) */
luaX_next(ls); /* skip ';' */
+8 -9
View File
@@ -282,16 +282,14 @@ static void setnodevector (lua_State *L, Table *t, int size) {
int lsize;
if (size == 0) { /* no elements to hash part? */
t->node = cast(Node *, dummynode); /* use common `dummynode' */
lsize = 1;
lsize = 0;
}
else {
int i;
// lsize = luaO_ceillog2(size);
// if (lsize > MAXBITS)
// luaG_runerror(L, "table overflow");
// size = twoto(lsize);
// size += size/2;
lsize = size;
lsize = luaO_ceillog2(size);
if (lsize > MAXBITS)
luaG_runerror(L, "table overflow");
size = twoto(lsize);
t->node = luaM_newvector(L, size, Node);
for (i=0; i<size; i++) {
Node *n = gnode(t, i);
@@ -308,6 +306,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) {
int i;
int oldasize = t->sizearray;
int oldhsize = t->lsizenode;
TRACE_LUA_INTERNALS_WITH_LINEINFO(L, "luaH_resize table %p %d(%d) %d(%d)", t, nasize, oldasize, nhsize, twoto(oldhsize));
Node *nold = t->node; /* save old hash ... */
if (nasize > oldasize) /* array part must grow? */
setarrayvector(L, t, nasize);
@@ -324,7 +323,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) {
luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
}
/* re-insert elements from hash part */
for (i = oldhsize - 1; i >= 0; i--) {
for (i = twoto(oldhsize) - 1; i >= 0; i--) {
Node *old = nold+i;
if (!ttisnil(gval(old))) {
/* doesn't need barrier/invalidate cache, as entry was
@@ -333,7 +332,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) {
}
}
if (!isdummy(nold))
luaM_freearray(L, nold, cast(size_t, oldhsize)); /* free old array */
luaM_freearray(L, nold, cast(size_t, twoto(oldhsize))); /* free old array */
}