aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2010-03-22 15:59:50 +0100
committerMike Pall <mike>2010-03-22 15:59:50 +0100
commit097db7317b0fad3a63093370593c772eb1cca189 (patch)
tree7e4a3d5c981aeb023f12211405bb821ce38e4806 /src
parent361266518c1500f25f7d83464ad4b2e2bd81db51 (diff)
downloadluajit-097db7317b0fad3a63093370593c772eb1cca189.tar.gz
luajit-097db7317b0fad3a63093370593c772eb1cca189.tar.bz2
luajit-097db7317b0fad3a63093370593c772eb1cca189.zip
Move colocated array part after GCtab (now properly aligned).
Diffstat (limited to 'src')
-rw-r--r--src/lj_asm.c2
-rw-r--r--src/lj_gc.h8
-rw-r--r--src/lj_tab.c32
3 files changed, 17 insertions, 25 deletions
diff --git a/src/lj_asm.c b/src/lj_asm.c
index aa42d677..e2fddbe9 100644
--- a/src/lj_asm.c
+++ b/src/lj_asm.c
@@ -1122,7 +1122,7 @@ static void asm_fusearef(ASMState *as, IRIns *ir, RegSet allow)
1122 noconflict(as, irb->op1, IR_NEWREF)) { 1122 noconflict(as, irb->op1, IR_NEWREF)) {
1123 /* We can avoid the FLOAD of t->array for colocated arrays. */ 1123 /* We can avoid the FLOAD of t->array for colocated arrays. */
1124 as->mrm.base = (uint8_t)ra_alloc1(as, irb->op1, allow); /* Table obj. */ 1124 as->mrm.base = (uint8_t)ra_alloc1(as, irb->op1, allow); /* Table obj. */
1125 as->mrm.ofs = -(int32_t)(ira->op1*sizeof(TValue)); /* Ofs to colo array. */ 1125 as->mrm.ofs = (int32_t)sizeof(GCtab); /* Ofs to colocated array. */
1126 } else { 1126 } else {
1127 as->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow); /* Array base. */ 1127 as->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow); /* Array base. */
1128 as->mrm.ofs = 0; 1128 as->mrm.ofs = 0;
diff --git a/src/lj_gc.h b/src/lj_gc.h
index 3c4f2d24..228835ac 100644
--- a/src/lj_gc.h
+++ b/src/lj_gc.h
@@ -91,8 +91,12 @@ LJ_FUNC void *lj_mem_grow(lua_State *L, void *p,
91 MSize *szp, MSize lim, MSize esz); 91 MSize *szp, MSize lim, MSize esz);
92 92
93#define lj_mem_new(L, s) lj_mem_realloc(L, NULL, 0, (s)) 93#define lj_mem_new(L, s) lj_mem_realloc(L, NULL, 0, (s))
94#define lj_mem_free(g, p, osize) \ 94
95 (g->gc.total -= (MSize)(osize), g->allocf(g->allocd, (p), (osize), 0)) 95static LJ_AINLINE void lj_mem_free(global_State *g, void *p, size_t osize)
96{
97 g->gc.total -= (MSize)osize;
98 g->allocf(g->allocd, p, osize, 0);
99}
96 100
97#define lj_mem_newvec(L, n, t) ((t *)lj_mem_new(L, (MSize)((n)*sizeof(t)))) 101#define lj_mem_newvec(L, n, t) ((t *)lj_mem_new(L, (MSize)((n)*sizeof(t))))
98#define lj_mem_reallocvec(L, p, on, n, t) \ 102#define lj_mem_reallocvec(L, p, on, n, t) \
diff --git a/src/lj_tab.c b/src/lj_tab.c
index be26bdda..d77aa05a 100644
--- a/src/lj_tab.c
+++ b/src/lj_tab.c
@@ -98,24 +98,18 @@ static LJ_AINLINE void clearapart(GCtab *t)
98static GCtab *newtab(lua_State *L, uint32_t asize, uint32_t hbits) 98static GCtab *newtab(lua_State *L, uint32_t asize, uint32_t hbits)
99{ 99{
100 GCtab *t; 100 GCtab *t;
101 global_State *g;
102 /* First try to colocate the array part. */ 101 /* First try to colocate the array part. */
103 if (LJ_MAX_COLOSIZE && asize > 0 && asize <= LJ_MAX_COLOSIZE) { 102 if (LJ_MAX_COLOSIZE && asize > 0 && asize <= LJ_MAX_COLOSIZE) {
104 /* This is ugly. (sizeof(GCtab)&7) != 0. So prepend the colocated array. */ 103 lua_assert((sizeof(GCtab) & 7) == 0);
105 TValue *array = lj_mem_newt(L, sizetabcolo(asize), TValue); 104 t = (GCtab *)lj_mem_newgco(L, sizetabcolo(asize));
106 t = cast(GCtab *, array + asize);
107 g = G(L);
108 setgcrefr(t->nextgc, g->gc.root);
109 setgcref(g->gc.root, obj2gco(t));
110 newwhite(g, t);
111 t->gct = ~LJ_TTAB; 105 t->gct = ~LJ_TTAB;
112 t->nomm = cast_byte(~0); 106 t->nomm = cast_byte(~0);
113 t->colo = (int8_t)asize; 107 t->colo = (int8_t)asize;
114 setmref(t->array, array); 108 setmref(t->array, (TValue *)((char *)t + sizeof(GCtab)));
115 setgcrefnull(t->metatable); 109 setgcrefnull(t->metatable);
116 t->asize = asize; 110 t->asize = asize;
117 t->hmask = 0; 111 t->hmask = 0;
118 setmref(t->node, &g->nilnode); 112 setmref(t->node, &G(L)->nilnode);
119 } else { /* Otherwise separately allocate the array part. */ 113 } else { /* Otherwise separately allocate the array part. */
120 t = lj_mem_newobj(L, GCtab); 114 t = lj_mem_newobj(L, GCtab);
121 t->gct = ~LJ_TTAB; 115 t->gct = ~LJ_TTAB;
@@ -125,8 +119,7 @@ static GCtab *newtab(lua_State *L, uint32_t asize, uint32_t hbits)
125 setgcrefnull(t->metatable); 119 setgcrefnull(t->metatable);
126 t->asize = 0; /* In case the array allocation fails. */ 120 t->asize = 0; /* In case the array allocation fails. */
127 t->hmask = 0; 121 t->hmask = 0;
128 g = G(L); 122 setmref(t->node, &G(L)->nilnode);
129 setmref(t->node, &g->nilnode);
130 if (asize > 0) { 123 if (asize > 0) {
131 if (asize > LJ_MAX_ASIZE) 124 if (asize > LJ_MAX_ASIZE)
132 lj_err_msg(L, LJ_ERR_TABOV); 125 lj_err_msg(L, LJ_ERR_TABOV);
@@ -212,17 +205,12 @@ void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t)
212{ 205{
213 if (t->hmask > 0) 206 if (t->hmask > 0)
214 lj_mem_freevec(g, noderef(t->node), t->hmask+1, Node); 207 lj_mem_freevec(g, noderef(t->node), t->hmask+1, Node);
215 if (LJ_MAX_COLOSIZE && t->colo) { 208 if (t->asize > 0 && LJ_MAX_COLOSIZE && t->colo <= 0)
216 ptrdiff_t n; 209 lj_mem_freevec(g, tvref(t->array), t->asize, TValue);
217 if (t->colo < 0 && t->asize > 0) /* Array part was separated. */ 210 if (LJ_MAX_COLOSIZE && t->colo)
218 lj_mem_freevec(g, tvref(t->array), t->asize, TValue); 211 lj_mem_free(g, t, sizetabcolo((uint32_t)t->colo & 0x7f));
219 n = t->colo & 0x7f; 212 else
220 lj_mem_free(g, (TValue *)t - n, sizetabcolo((uint32_t)n));
221 } else {
222 if (t->asize > 0)
223 lj_mem_freevec(g, tvref(t->array), t->asize, TValue);
224 lj_mem_freet(g, t); 213 lj_mem_freet(g, t);
225 }
226} 214}
227 215
228/* -- Table resizing ------------------------------------------------------ */ 216/* -- Table resizing ------------------------------------------------------ */