aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2014-12-20 00:17:50 +0100
committerMike Pall <mike>2014-12-20 00:17:50 +0100
commit6e9145a882ea70fe438d59959ac4e65481fe5e85 (patch)
tree98e7c78e5aab6bd0360d9e00e4c82e9f1634c96d
parent82e6e5fb5f17e497b3341322998ede75ec29e554 (diff)
downloadluajit-6e9145a882ea70fe438d59959ac4e65481fe5e85.tar.gz
luajit-6e9145a882ea70fe438d59959ac4e65481fe5e85.tar.bz2
luajit-6e9145a882ea70fe438d59959ac4e65481fe5e85.zip
Cleanup of memory vs. GC sizes. No functional changes.
-rw-r--r--src/lib_package.c4
-rw-r--r--src/lj_api.c2
-rw-r--r--src/lj_bcread.c2
-rw-r--r--src/lj_buf.c6
-rw-r--r--src/lj_def.h11
-rw-r--r--src/lj_gc.c24
-rw-r--r--src/lj_gc.h10
-rw-r--r--src/lj_ir.c2
-rw-r--r--src/lj_obj.h11
-rw-r--r--src/lj_state.c2
10 files changed, 39 insertions, 35 deletions
diff --git a/src/lib_package.c b/src/lib_package.c
index d3229110..dc9f61ab 100644
--- a/src/lib_package.c
+++ b/src/lib_package.c
@@ -226,7 +226,7 @@ static int ll_loadfunc(lua_State *L, const char *path, const char *name, int r)
226 const char *bcdata = ll_bcsym(*reg, mksymname(L, name, SYMPREFIX_BC)); 226 const char *bcdata = ll_bcsym(*reg, mksymname(L, name, SYMPREFIX_BC));
227 lua_pop(L, 1); 227 lua_pop(L, 1);
228 if (bcdata) { 228 if (bcdata) {
229 if (luaL_loadbuffer(L, bcdata, LJ_MAX_MEM, name) != 0) 229 if (luaL_loadbuffer(L, bcdata, LJ_MAX_BUF, name) != 0)
230 return PACKAGE_ERR_LOAD; 230 return PACKAGE_ERR_LOAD;
231 return 0; 231 return 0;
232 } 232 }
@@ -383,7 +383,7 @@ static int lj_cf_package_loader_preload(lua_State *L)
383 if (lua_isnil(L, -1)) { /* Not found? */ 383 if (lua_isnil(L, -1)) { /* Not found? */
384 const char *bcname = mksymname(L, name, SYMPREFIX_BC); 384 const char *bcname = mksymname(L, name, SYMPREFIX_BC);
385 const char *bcdata = ll_bcsym(NULL, bcname); 385 const char *bcdata = ll_bcsym(NULL, bcname);
386 if (bcdata == NULL || luaL_loadbuffer(L, bcdata, LJ_MAX_MEM, name) != 0) 386 if (bcdata == NULL || luaL_loadbuffer(L, bcdata, LJ_MAX_BUF, name) != 0)
387 lua_pushfstring(L, "\n\tno field package.preload['%s']", name); 387 lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
388 } 388 }
389 return 1; 389 return 1;
diff --git a/src/lj_api.c b/src/lj_api.c
index 1ccd7be1..03be80f9 100644
--- a/src/lj_api.c
+++ b/src/lj_api.c
@@ -1150,7 +1150,7 @@ LUA_API int lua_gc(lua_State *L, int what, int data)
1150 res = (int)(g->gc.total & 0x3ff); 1150 res = (int)(g->gc.total & 0x3ff);
1151 break; 1151 break;
1152 case LUA_GCSTEP: { 1152 case LUA_GCSTEP: {
1153 MSize a = (MSize)data << 10; 1153 GCSize a = (GCSize)data << 10;
1154 g->gc.threshold = (a <= g->gc.total) ? (g->gc.total - a) : 0; 1154 g->gc.threshold = (a <= g->gc.total) ? (g->gc.total - a) : 0;
1155 while (g->gc.total >= g->gc.threshold) 1155 while (g->gc.total >= g->gc.threshold)
1156 if (lj_gc_step(L) > 0) { 1156 if (lj_gc_step(L) > 0) {
diff --git a/src/lj_bcread.c b/src/lj_bcread.c
index 2360bf40..519164ca 100644
--- a/src/lj_bcread.c
+++ b/src/lj_bcread.c
@@ -48,7 +48,7 @@ static LJ_NOINLINE void bcread_error(LexState *ls, ErrMsg em)
48static LJ_NOINLINE void bcread_fill(LexState *ls, MSize len, int need) 48static LJ_NOINLINE void bcread_fill(LexState *ls, MSize len, int need)
49{ 49{
50 lua_assert(len != 0); 50 lua_assert(len != 0);
51 if (len > LJ_MAX_MEM || ls->c < 0) 51 if (len > LJ_MAX_BUF || ls->c < 0)
52 bcread_error(ls, LJ_ERR_BCBAD); 52 bcread_error(ls, LJ_ERR_BCBAD);
53 do { 53 do {
54 const char *buf; 54 const char *buf;
diff --git a/src/lj_buf.c b/src/lj_buf.c
index 05ff1f51..05b35615 100644
--- a/src/lj_buf.c
+++ b/src/lj_buf.c
@@ -31,7 +31,7 @@ static void buf_grow(SBuf *sb, MSize sz)
31LJ_NOINLINE char *LJ_FASTCALL lj_buf_need2(SBuf *sb, MSize sz) 31LJ_NOINLINE char *LJ_FASTCALL lj_buf_need2(SBuf *sb, MSize sz)
32{ 32{
33 lua_assert(sz > sbufsz(sb)); 33 lua_assert(sz > sbufsz(sb));
34 if (LJ_UNLIKELY(sz > LJ_MAX_MEM)) 34 if (LJ_UNLIKELY(sz > LJ_MAX_BUF))
35 lj_err_mem(sbufL(sb)); 35 lj_err_mem(sbufL(sb));
36 buf_grow(sb, sz); 36 buf_grow(sb, sz);
37 return sbufB(sb); 37 return sbufB(sb);
@@ -41,7 +41,7 @@ LJ_NOINLINE char *LJ_FASTCALL lj_buf_more2(SBuf *sb, MSize sz)
41{ 41{
42 MSize len = sbuflen(sb); 42 MSize len = sbuflen(sb);
43 lua_assert(sz > sbufleft(sb)); 43 lua_assert(sz > sbufleft(sb));
44 if (LJ_UNLIKELY(sz > LJ_MAX_MEM || len + sz > LJ_MAX_MEM)) 44 if (LJ_UNLIKELY(sz > LJ_MAX_BUF || len + sz > LJ_MAX_BUF))
45 lj_err_mem(sbufL(sb)); 45 lj_err_mem(sbufL(sb));
46 buf_grow(sb, len + sz); 46 buf_grow(sb, len + sz);
47 return sbufP(sb); 47 return sbufP(sb);
@@ -178,7 +178,7 @@ SBuf *lj_buf_puttab(SBuf *sb, GCtab *t, GCstr *sep, int32_t i, int32_t e)
178 char *p; 178 char *p;
179 if (!o) { 179 if (!o) {
180 badtype: /* Error: bad element type. */ 180 badtype: /* Error: bad element type. */
181 setsbufP(sb, (intptr_t)i); /* Store failing index. */ 181 setsbufP(sb, (void *)(intptr_t)i); /* Store failing index. */
182 return NULL; 182 return NULL;
183 } else if (tvisstr(o)) { 183 } else if (tvisstr(o)) {
184 MSize len = strV(o)->len; 184 MSize len = strV(o)->len;
diff --git a/src/lj_def.h b/src/lj_def.h
index 8624aed2..93420ba5 100644
--- a/src/lj_def.h
+++ b/src/lj_def.h
@@ -46,10 +46,12 @@ typedef unsigned int uintptr_t;
46#include <stdlib.h> 46#include <stdlib.h>
47 47
48/* Various VM limits. */ 48/* Various VM limits. */
49#define LJ_MAX_MEM 0x7fffff00 /* Max. total memory allocation. */ 49#define LJ_MAX_MEM32 0x7fffff00 /* Max. 32 bit memory allocation. */
50#define LJ_MAX_MEM LJ_MAX_MEM32 /* Max. total memory allocation. */
50#define LJ_MAX_ALLOC LJ_MAX_MEM /* Max. individual allocation length. */ 51#define LJ_MAX_ALLOC LJ_MAX_MEM /* Max. individual allocation length. */
51#define LJ_MAX_STR LJ_MAX_MEM /* Max. string length. */ 52#define LJ_MAX_STR LJ_MAX_MEM32 /* Max. string length. */
52#define LJ_MAX_UDATA LJ_MAX_MEM /* Max. userdata length. */ 53#define LJ_MAX_BUF LJ_MAX_MEM32 /* Max. buffer length. */
54#define LJ_MAX_UDATA LJ_MAX_MEM32 /* Max. userdata length. */
53 55
54#define LJ_MAX_STRTAB (1<<26) /* Max. string table size. */ 56#define LJ_MAX_STRTAB (1<<26) /* Max. string table size. */
55#define LJ_MAX_HBITS 26 /* Max. hash bits. */ 57#define LJ_MAX_HBITS 26 /* Max. hash bits. */
@@ -57,7 +59,7 @@ typedef unsigned int uintptr_t;
57#define LJ_MAX_ASIZE ((1<<(LJ_MAX_ABITS-1))+1) /* Max. array part size. */ 59#define LJ_MAX_ASIZE ((1<<(LJ_MAX_ABITS-1))+1) /* Max. array part size. */
58#define LJ_MAX_COLOSIZE 16 /* Max. elems for colocated array. */ 60#define LJ_MAX_COLOSIZE 16 /* Max. elems for colocated array. */
59 61
60#define LJ_MAX_LINE LJ_MAX_MEM /* Max. source code line number. */ 62#define LJ_MAX_LINE LJ_MAX_MEM32 /* Max. source code line number. */
61#define LJ_MAX_XLEVEL 200 /* Max. syntactic nesting level. */ 63#define LJ_MAX_XLEVEL 200 /* Max. syntactic nesting level. */
62#define LJ_MAX_BCINS (1<<26) /* Max. # of bytecode instructions. */ 64#define LJ_MAX_BCINS (1<<26) /* Max. # of bytecode instructions. */
63#define LJ_MAX_SLOTS 250 /* Max. # of slots in a Lua func. */ 65#define LJ_MAX_SLOTS 250 /* Max. # of slots in a Lua func. */
@@ -99,6 +101,7 @@ typedef unsigned int uintptr_t;
99#define checki32(x) ((x) == (int32_t)(x)) 101#define checki32(x) ((x) == (int32_t)(x))
100#define checku32(x) ((x) == (uint32_t)(x)) 102#define checku32(x) ((x) == (uint32_t)(x))
101#define checkptr32(x) ((uintptr_t)(x) == (uint32_t)(uintptr_t)(x)) 103#define checkptr32(x) ((uintptr_t)(x) == (uint32_t)(uintptr_t)(x))
104#define checkptrGC(x) (checkptr32(x))
102 105
103/* Every half-decent C compiler transforms this into a rotate instruction. */ 106/* Every half-decent C compiler transforms this into a rotate instruction. */
104#define lj_rol(x, n) (((x)<<(n)) | ((x)>>(-(int)(n)&(8*sizeof(x)-1)))) 107#define lj_rol(x, n) (((x)<<(n)) | ((x)>>(-(int)(n)&(8*sizeof(x)-1))))
diff --git a/src/lj_gc.c b/src/lj_gc.c
index 376c9d09..5a7127c2 100644
--- a/src/lj_gc.c
+++ b/src/lj_gc.c
@@ -374,7 +374,7 @@ static const GCFreeFunc gc_freefunc[] = {
374}; 374};
375 375
376/* Full sweep of a GC list. */ 376/* Full sweep of a GC list. */
377#define gc_fullsweep(g, p) gc_sweep(g, (p), LJ_MAX_MEM) 377#define gc_fullsweep(g, p) gc_sweep(g, (p), ~(uint32_t)0)
378 378
379/* Partial sweep of a GC list. */ 379/* Partial sweep of a GC list. */
380static GCRef *gc_sweep(global_State *g, GCRef *p, uint32_t lim) 380static GCRef *gc_sweep(global_State *g, GCRef *p, uint32_t lim)
@@ -452,7 +452,7 @@ static void gc_call_finalizer(global_State *g, lua_State *L,
452{ 452{
453 /* Save and restore lots of state around the __gc callback. */ 453 /* Save and restore lots of state around the __gc callback. */
454 uint8_t oldh = hook_save(g); 454 uint8_t oldh = hook_save(g);
455 MSize oldt = g->gc.threshold; 455 GCSize oldt = g->gc.threshold;
456 int errcode; 456 int errcode;
457 TValue *top; 457 TValue *top;
458 lj_trace_abort(g); 458 lj_trace_abort(g);
@@ -590,7 +590,7 @@ static void atomic(global_State *g, lua_State *L)
590 g->gc.currentwhite = (uint8_t)otherwhite(g); /* Flip current white. */ 590 g->gc.currentwhite = (uint8_t)otherwhite(g); /* Flip current white. */
591 g->strempty.marked = g->gc.currentwhite; 591 g->strempty.marked = g->gc.currentwhite;
592 setmref(g->gc.sweep, &g->gc.root); 592 setmref(g->gc.sweep, &g->gc.root);
593 g->gc.estimate = g->gc.total - (MSize)udsize; /* Initial estimate. */ 593 g->gc.estimate = g->gc.total - (GCSize)udsize; /* Initial estimate. */
594} 594}
595 595
596/* GC state machine. Returns a cost estimate for each step performed. */ 596/* GC state machine. Returns a cost estimate for each step performed. */
@@ -614,7 +614,7 @@ static size_t gc_onestep(lua_State *L)
614 g->gc.sweepstr = 0; 614 g->gc.sweepstr = 0;
615 return 0; 615 return 0;
616 case GCSsweepstring: { 616 case GCSsweepstring: {
617 MSize old = g->gc.total; 617 GCSize old = g->gc.total;
618 gc_fullsweep(g, &g->strhash[g->gc.sweepstr++]); /* Sweep one chain. */ 618 gc_fullsweep(g, &g->strhash[g->gc.sweepstr++]); /* Sweep one chain. */
619 if (g->gc.sweepstr > g->strmask) 619 if (g->gc.sweepstr > g->strmask)
620 g->gc.state = GCSsweep; /* All string hash chains sweeped. */ 620 g->gc.state = GCSsweep; /* All string hash chains sweeped. */
@@ -623,7 +623,7 @@ static size_t gc_onestep(lua_State *L)
623 return GCSWEEPCOST; 623 return GCSWEEPCOST;
624 } 624 }
625 case GCSsweep: { 625 case GCSsweep: {
626 MSize old = g->gc.total; 626 GCSize old = g->gc.total;
627 setmref(g->gc.sweep, gc_sweep(g, mref(g->gc.sweep, GCRef), GCSWEEPMAX)); 627 setmref(g->gc.sweep, gc_sweep(g, mref(g->gc.sweep, GCRef), GCSWEEPMAX));
628 lua_assert(old >= g->gc.total); 628 lua_assert(old >= g->gc.total);
629 g->gc.estimate -= old - g->gc.total; 629 g->gc.estimate -= old - g->gc.total;
@@ -667,7 +667,7 @@ static size_t gc_onestep(lua_State *L)
667int LJ_FASTCALL lj_gc_step(lua_State *L) 667int LJ_FASTCALL lj_gc_step(lua_State *L)
668{ 668{
669 global_State *g = G(L); 669 global_State *g = G(L);
670 MSize lim; 670 GCSize lim;
671 int32_t ostate = g->vmstate; 671 int32_t ostate = g->vmstate;
672 setvmstate(g, GC); 672 setvmstate(g, GC);
673 lim = (GCSTEPSIZE/100) * g->gc.stepmul; 673 lim = (GCSTEPSIZE/100) * g->gc.stepmul;
@@ -676,13 +676,13 @@ int LJ_FASTCALL lj_gc_step(lua_State *L)
676 if (g->gc.total > g->gc.threshold) 676 if (g->gc.total > g->gc.threshold)
677 g->gc.debt += g->gc.total - g->gc.threshold; 677 g->gc.debt += g->gc.total - g->gc.threshold;
678 do { 678 do {
679 lim -= (MSize)gc_onestep(L); 679 lim -= (GCSize)gc_onestep(L);
680 if (g->gc.state == GCSpause) { 680 if (g->gc.state == GCSpause) {
681 g->gc.threshold = (g->gc.estimate/100) * g->gc.pause; 681 g->gc.threshold = (g->gc.estimate/100) * g->gc.pause;
682 g->vmstate = ostate; 682 g->vmstate = ostate;
683 return 1; /* Finished a GC cycle. */ 683 return 1; /* Finished a GC cycle. */
684 } 684 }
685 } while ((int32_t)lim > 0); 685 } while (sizeof(lim) == 8 ? ((int64_t)lim > 0) : ((int32_t)lim > 0));
686 if (g->gc.debt < GCSTEPSIZE) { 686 if (g->gc.debt < GCSTEPSIZE) {
687 g->gc.threshold = g->gc.total + GCSTEPSIZE; 687 g->gc.threshold = g->gc.total + GCSTEPSIZE;
688 g->vmstate = ostate; 688 g->vmstate = ostate;
@@ -801,7 +801,7 @@ void lj_gc_barriertrace(global_State *g, uint32_t traceno)
801/* -- Allocator ----------------------------------------------------------- */ 801/* -- Allocator ----------------------------------------------------------- */
802 802
803/* Call pluggable memory allocator to allocate or resize a fragment. */ 803/* Call pluggable memory allocator to allocate or resize a fragment. */
804void *lj_mem_realloc(lua_State *L, void *p, MSize osz, MSize nsz) 804void *lj_mem_realloc(lua_State *L, void *p, GCSize osz, GCSize nsz)
805{ 805{
806 global_State *g = G(L); 806 global_State *g = G(L);
807 lua_assert((osz == 0) == (p == NULL)); 807 lua_assert((osz == 0) == (p == NULL));
@@ -809,19 +809,19 @@ void *lj_mem_realloc(lua_State *L, void *p, MSize osz, MSize nsz)
809 if (p == NULL && nsz > 0) 809 if (p == NULL && nsz > 0)
810 lj_err_mem(L); 810 lj_err_mem(L);
811 lua_assert((nsz == 0) == (p == NULL)); 811 lua_assert((nsz == 0) == (p == NULL));
812 lua_assert(checkptr32(p)); 812 lua_assert(checkptrGC(p));
813 g->gc.total = (g->gc.total - osz) + nsz; 813 g->gc.total = (g->gc.total - osz) + nsz;
814 return p; 814 return p;
815} 815}
816 816
817/* Allocate new GC object and link it to the root set. */ 817/* Allocate new GC object and link it to the root set. */
818void * LJ_FASTCALL lj_mem_newgco(lua_State *L, MSize size) 818void * LJ_FASTCALL lj_mem_newgco(lua_State *L, GCSize size)
819{ 819{
820 global_State *g = G(L); 820 global_State *g = G(L);
821 GCobj *o = (GCobj *)g->allocf(g->allocd, NULL, 0, size); 821 GCobj *o = (GCobj *)g->allocf(g->allocd, NULL, 0, size);
822 if (o == NULL) 822 if (o == NULL)
823 lj_err_mem(L); 823 lj_err_mem(L);
824 lua_assert(checkptr32(o)); 824 lua_assert(checkptrGC(o));
825 g->gc.total += size; 825 g->gc.total += size;
826 setgcrefr(o->gch.nextgc, g->gc.root); 826 setgcrefr(o->gch.nextgc, g->gc.root);
827 setgcref(g->gc.root, o); 827 setgcref(g->gc.root, o);
diff --git a/src/lj_gc.h b/src/lj_gc.h
index c85d0756..fa415a21 100644
--- a/src/lj_gc.h
+++ b/src/lj_gc.h
@@ -107,8 +107,8 @@ static LJ_AINLINE void lj_gc_barrierback(global_State *g, GCtab *t)
107 lj_gc_barrierf(G(L), obj2gco(p), obj2gco(o)); } 107 lj_gc_barrierf(G(L), obj2gco(p), obj2gco(o)); }
108 108
109/* Allocator. */ 109/* Allocator. */
110LJ_FUNC void *lj_mem_realloc(lua_State *L, void *p, MSize osz, MSize nsz); 110LJ_FUNC void *lj_mem_realloc(lua_State *L, void *p, GCSize osz, GCSize nsz);
111LJ_FUNC void * LJ_FASTCALL lj_mem_newgco(lua_State *L, MSize size); 111LJ_FUNC void * LJ_FASTCALL lj_mem_newgco(lua_State *L, GCSize size);
112LJ_FUNC void *lj_mem_grow(lua_State *L, void *p, 112LJ_FUNC void *lj_mem_grow(lua_State *L, void *p,
113 MSize *szp, MSize lim, MSize esz); 113 MSize *szp, MSize lim, MSize esz);
114 114
@@ -116,13 +116,13 @@ LJ_FUNC void *lj_mem_grow(lua_State *L, void *p,
116 116
117static LJ_AINLINE void lj_mem_free(global_State *g, void *p, size_t osize) 117static LJ_AINLINE void lj_mem_free(global_State *g, void *p, size_t osize)
118{ 118{
119 g->gc.total -= (MSize)osize; 119 g->gc.total -= (GCSize)osize;
120 g->allocf(g->allocd, p, osize, 0); 120 g->allocf(g->allocd, p, osize, 0);
121} 121}
122 122
123#define lj_mem_newvec(L, n, t) ((t *)lj_mem_new(L, (MSize)((n)*sizeof(t)))) 123#define lj_mem_newvec(L, n, t) ((t *)lj_mem_new(L, (GCSize)((n)*sizeof(t))))
124#define lj_mem_reallocvec(L, p, on, n, t) \ 124#define lj_mem_reallocvec(L, p, on, n, t) \
125 ((p) = (t *)lj_mem_realloc(L, p, (on)*sizeof(t), (MSize)((n)*sizeof(t)))) 125 ((p) = (t *)lj_mem_realloc(L, p, (on)*sizeof(t), (GCSize)((n)*sizeof(t))))
126#define lj_mem_growvec(L, p, n, m, t) \ 126#define lj_mem_growvec(L, p, n, m, t) \
127 ((p) = (t *)lj_mem_grow(L, (p), &(n), (m), (MSize)sizeof(t))) 127 ((p) = (t *)lj_mem_grow(L, (p), &(n), (m), (MSize)sizeof(t)))
128#define lj_mem_freevec(g, p, n, t) lj_mem_free(g, (p), (n)*sizeof(t)) 128#define lj_mem_freevec(g, p, n, t) lj_mem_free(g, (p), (n)*sizeof(t))
diff --git a/src/lj_ir.c b/src/lj_ir.c
index 460cd307..2eabdb4b 100644
--- a/src/lj_ir.c
+++ b/src/lj_ir.c
@@ -253,7 +253,7 @@ TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv)
253 goto found; 253 goto found;
254 ref = ir_nextk(J); 254 ref = ir_nextk(J);
255 ir = IR(ref); 255 ir = IR(ref);
256 lua_assert(checkptr32(tv)); 256 lua_assert(checkptrGC(tv));
257 setmref(ir->ptr, tv); 257 setmref(ir->ptr, tv);
258 ir->t.irt = t; 258 ir->t.irt = t;
259 ir->o = op; 259 ir->o = op;
diff --git a/src/lj_obj.h b/src/lj_obj.h
index daa62e34..99e2d819 100644
--- a/src/lj_obj.h
+++ b/src/lj_obj.h
@@ -15,8 +15,9 @@
15 15
16/* -- Memory references (32 bit address space) ---------------------------- */ 16/* -- Memory references (32 bit address space) ---------------------------- */
17 17
18/* Memory size. */ 18/* Memory and GC object sizes. */
19typedef uint32_t MSize; 19typedef uint32_t MSize;
20typedef uint32_t GCSize;
20 21
21/* Memory reference */ 22/* Memory reference */
22typedef struct MRef { 23typedef struct MRef {
@@ -490,8 +491,8 @@ typedef enum {
490#define mmname_str(g, mm) (strref((g)->gcroot[GCROOT_MMNAME+(mm)])) 491#define mmname_str(g, mm) (strref((g)->gcroot[GCROOT_MMNAME+(mm)]))
491 492
492typedef struct GCState { 493typedef struct GCState {
493 MSize total; /* Memory currently allocated. */ 494 GCSize total; /* Memory currently allocated. */
494 MSize threshold; /* Memory threshold. */ 495 GCSize threshold; /* Memory threshold. */
495 uint8_t currentwhite; /* Current white color. */ 496 uint8_t currentwhite; /* Current white color. */
496 uint8_t state; /* GC state. */ 497 uint8_t state; /* GC state. */
497 uint8_t nocdatafin; /* No cdata finalizer called. */ 498 uint8_t nocdatafin; /* No cdata finalizer called. */
@@ -503,9 +504,9 @@ typedef struct GCState {
503 GCRef grayagain; /* List of objects for atomic traversal. */ 504 GCRef grayagain; /* List of objects for atomic traversal. */
504 GCRef weak; /* List of weak tables (to be cleared). */ 505 GCRef weak; /* List of weak tables (to be cleared). */
505 GCRef mmudata; /* List of userdata (to be finalized). */ 506 GCRef mmudata; /* List of userdata (to be finalized). */
507 GCSize debt; /* Debt (how much GC is behind schedule). */
508 GCSize estimate; /* Estimate of memory actually in use. */
506 MSize stepmul; /* Incremental GC step granularity. */ 509 MSize stepmul; /* Incremental GC step granularity. */
507 MSize debt; /* Debt (how much GC is behind schedule). */
508 MSize estimate; /* Estimate of memory actually in use. */
509 MSize pause; /* Pause between successive GC cycles. */ 510 MSize pause; /* Pause between successive GC cycles. */
510} GCState; 511} GCState;
511 512
diff --git a/src/lj_state.c b/src/lj_state.c
index 444f269d..344f8fe1 100644
--- a/src/lj_state.c
+++ b/src/lj_state.c
@@ -187,7 +187,7 @@ LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)
187 GG_State *GG = (GG_State *)f(ud, NULL, 0, sizeof(GG_State)); 187 GG_State *GG = (GG_State *)f(ud, NULL, 0, sizeof(GG_State));
188 lua_State *L = &GG->L; 188 lua_State *L = &GG->L;
189 global_State *g = &GG->g; 189 global_State *g = &GG->g;
190 if (GG == NULL || !checkptr32(GG)) return NULL; 190 if (GG == NULL || !checkptrGC(GG)) return NULL;
191 memset(GG, 0, sizeof(GG_State)); 191 memset(GG, 0, sizeof(GG_State));
192 L->gct = ~LJ_TTHREAD; 192 L->gct = ~LJ_TTHREAD;
193 L->marked = LJ_GC_WHITE0 | LJ_GC_FIXED | LJ_GC_SFIXED; /* Prevent free. */ 193 L->marked = LJ_GC_WHITE0 | LJ_GC_FIXED | LJ_GC_SFIXED; /* Prevent free. */