mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-08 07:34:07 +00:00
Move colocated array part after GCtab (now properly aligned).
This commit is contained in:
parent
361266518c
commit
097db7317b
@ -1122,7 +1122,7 @@ static void asm_fusearef(ASMState *as, IRIns *ir, RegSet allow)
|
|||||||
noconflict(as, irb->op1, IR_NEWREF)) {
|
noconflict(as, irb->op1, IR_NEWREF)) {
|
||||||
/* We can avoid the FLOAD of t->array for colocated arrays. */
|
/* We can avoid the FLOAD of t->array for colocated arrays. */
|
||||||
as->mrm.base = (uint8_t)ra_alloc1(as, irb->op1, allow); /* Table obj. */
|
as->mrm.base = (uint8_t)ra_alloc1(as, irb->op1, allow); /* Table obj. */
|
||||||
as->mrm.ofs = -(int32_t)(ira->op1*sizeof(TValue)); /* Ofs to colo array. */
|
as->mrm.ofs = (int32_t)sizeof(GCtab); /* Ofs to colocated array. */
|
||||||
} else {
|
} else {
|
||||||
as->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow); /* Array base. */
|
as->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow); /* Array base. */
|
||||||
as->mrm.ofs = 0;
|
as->mrm.ofs = 0;
|
||||||
|
@ -91,8 +91,12 @@ LJ_FUNC void *lj_mem_grow(lua_State *L, void *p,
|
|||||||
MSize *szp, MSize lim, MSize esz);
|
MSize *szp, MSize lim, MSize esz);
|
||||||
|
|
||||||
#define lj_mem_new(L, s) lj_mem_realloc(L, NULL, 0, (s))
|
#define lj_mem_new(L, s) lj_mem_realloc(L, NULL, 0, (s))
|
||||||
#define lj_mem_free(g, p, osize) \
|
|
||||||
(g->gc.total -= (MSize)(osize), g->allocf(g->allocd, (p), (osize), 0))
|
static LJ_AINLINE void lj_mem_free(global_State *g, void *p, size_t osize)
|
||||||
|
{
|
||||||
|
g->gc.total -= (MSize)osize;
|
||||||
|
g->allocf(g->allocd, p, osize, 0);
|
||||||
|
}
|
||||||
|
|
||||||
#define lj_mem_newvec(L, n, t) ((t *)lj_mem_new(L, (MSize)((n)*sizeof(t))))
|
#define lj_mem_newvec(L, n, t) ((t *)lj_mem_new(L, (MSize)((n)*sizeof(t))))
|
||||||
#define lj_mem_reallocvec(L, p, on, n, t) \
|
#define lj_mem_reallocvec(L, p, on, n, t) \
|
||||||
|
30
src/lj_tab.c
30
src/lj_tab.c
@ -98,24 +98,18 @@ static LJ_AINLINE void clearapart(GCtab *t)
|
|||||||
static GCtab *newtab(lua_State *L, uint32_t asize, uint32_t hbits)
|
static GCtab *newtab(lua_State *L, uint32_t asize, uint32_t hbits)
|
||||||
{
|
{
|
||||||
GCtab *t;
|
GCtab *t;
|
||||||
global_State *g;
|
|
||||||
/* First try to colocate the array part. */
|
/* First try to colocate the array part. */
|
||||||
if (LJ_MAX_COLOSIZE && asize > 0 && asize <= LJ_MAX_COLOSIZE) {
|
if (LJ_MAX_COLOSIZE && asize > 0 && asize <= LJ_MAX_COLOSIZE) {
|
||||||
/* This is ugly. (sizeof(GCtab)&7) != 0. So prepend the colocated array. */
|
lua_assert((sizeof(GCtab) & 7) == 0);
|
||||||
TValue *array = lj_mem_newt(L, sizetabcolo(asize), TValue);
|
t = (GCtab *)lj_mem_newgco(L, sizetabcolo(asize));
|
||||||
t = cast(GCtab *, array + asize);
|
|
||||||
g = G(L);
|
|
||||||
setgcrefr(t->nextgc, g->gc.root);
|
|
||||||
setgcref(g->gc.root, obj2gco(t));
|
|
||||||
newwhite(g, t);
|
|
||||||
t->gct = ~LJ_TTAB;
|
t->gct = ~LJ_TTAB;
|
||||||
t->nomm = cast_byte(~0);
|
t->nomm = cast_byte(~0);
|
||||||
t->colo = (int8_t)asize;
|
t->colo = (int8_t)asize;
|
||||||
setmref(t->array, array);
|
setmref(t->array, (TValue *)((char *)t + sizeof(GCtab)));
|
||||||
setgcrefnull(t->metatable);
|
setgcrefnull(t->metatable);
|
||||||
t->asize = asize;
|
t->asize = asize;
|
||||||
t->hmask = 0;
|
t->hmask = 0;
|
||||||
setmref(t->node, &g->nilnode);
|
setmref(t->node, &G(L)->nilnode);
|
||||||
} else { /* Otherwise separately allocate the array part. */
|
} else { /* Otherwise separately allocate the array part. */
|
||||||
t = lj_mem_newobj(L, GCtab);
|
t = lj_mem_newobj(L, GCtab);
|
||||||
t->gct = ~LJ_TTAB;
|
t->gct = ~LJ_TTAB;
|
||||||
@ -125,8 +119,7 @@ static GCtab *newtab(lua_State *L, uint32_t asize, uint32_t hbits)
|
|||||||
setgcrefnull(t->metatable);
|
setgcrefnull(t->metatable);
|
||||||
t->asize = 0; /* In case the array allocation fails. */
|
t->asize = 0; /* In case the array allocation fails. */
|
||||||
t->hmask = 0;
|
t->hmask = 0;
|
||||||
g = G(L);
|
setmref(t->node, &G(L)->nilnode);
|
||||||
setmref(t->node, &g->nilnode);
|
|
||||||
if (asize > 0) {
|
if (asize > 0) {
|
||||||
if (asize > LJ_MAX_ASIZE)
|
if (asize > LJ_MAX_ASIZE)
|
||||||
lj_err_msg(L, LJ_ERR_TABOV);
|
lj_err_msg(L, LJ_ERR_TABOV);
|
||||||
@ -212,18 +205,13 @@ void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t)
|
|||||||
{
|
{
|
||||||
if (t->hmask > 0)
|
if (t->hmask > 0)
|
||||||
lj_mem_freevec(g, noderef(t->node), t->hmask+1, Node);
|
lj_mem_freevec(g, noderef(t->node), t->hmask+1, Node);
|
||||||
if (LJ_MAX_COLOSIZE && t->colo) {
|
if (t->asize > 0 && LJ_MAX_COLOSIZE && t->colo <= 0)
|
||||||
ptrdiff_t n;
|
|
||||||
if (t->colo < 0 && t->asize > 0) /* Array part was separated. */
|
|
||||||
lj_mem_freevec(g, tvref(t->array), t->asize, TValue);
|
|
||||||
n = t->colo & 0x7f;
|
|
||||||
lj_mem_free(g, (TValue *)t - n, sizetabcolo((uint32_t)n));
|
|
||||||
} else {
|
|
||||||
if (t->asize > 0)
|
|
||||||
lj_mem_freevec(g, tvref(t->array), t->asize, TValue);
|
lj_mem_freevec(g, tvref(t->array), t->asize, TValue);
|
||||||
|
if (LJ_MAX_COLOSIZE && t->colo)
|
||||||
|
lj_mem_free(g, t, sizetabcolo((uint32_t)t->colo & 0x7f));
|
||||||
|
else
|
||||||
lj_mem_freet(g, t);
|
lj_mem_freet(g, t);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* -- Table resizing ------------------------------------------------------ */
|
/* -- Table resizing ------------------------------------------------------ */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user