Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lgc.h File Reference
#include "lobject.h"
#include "lstate.h"

Go to the source code of this file.

Macros

#define GCSTEPSIZE   (cast_int(100 * sizeof(TString)))
 
#define GCSpropagate   0
 
#define GCSatomic   1
 
#define GCSswpallgc   2
 
#define GCSswpfinobj   3
 
#define GCSswptobefnz   4
 
#define GCSswpend   5
 
#define GCScallfin   6
 
#define GCSpause   7
 
#define issweepphase(g)    (GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend)
 
#define keepinvariant(g)   ((g)->gcstate <= GCSatomic)
 
#define resetbits(x, m)   ((x) &= cast(lu_byte, ~(m)))
 
#define setbits(x, m)   ((x) |= (m))
 
#define testbits(x, m)   ((x) & (m))
 
#define bitmask(b)   (1<<(b))
 
#define bit2mask(b1, b2)   (bitmask(b1) | bitmask(b2))
 
#define l_setbit(x, b)   setbits(x, bitmask(b))
 
#define resetbit(x, b)   resetbits(x, bitmask(b))
 
#define testbit(x, b)   testbits(x, bitmask(b))
 
#define WHITE0BIT   0 /* object is white (type 0) */
 
#define WHITE1BIT   1 /* object is white (type 1) */
 
#define BLACKBIT   2 /* object is black */
 
#define FINALIZEDBIT   3 /* object has been marked for finalization */
 
#define WHITEBITS   bit2mask(WHITE0BIT, WHITE1BIT)
 
#define iswhite(x)   testbits((x)->marked, WHITEBITS)
 
#define isblack(x)   testbit((x)->marked, BLACKBIT)
 
#define isgray(x)
 
#define tofinalize(x)   testbit((x)->marked, FINALIZEDBIT)
 
#define otherwhite(g)   ((g)->currentwhite ^ WHITEBITS)
 
#define isdeadm(ow, m)   (!(((m) ^ WHITEBITS) & (ow)))
 
#define isdead(g, v)   isdeadm(otherwhite(g), (v)->marked)
 
#define changewhite(x)   ((x)->marked ^= WHITEBITS)
 
#define gray2black(x)   l_setbit((x)->marked, BLACKBIT)
 
#define luaC_white(g)   cast(lu_byte, (g)->currentwhite & WHITEBITS)
 
#define luaC_condGC(L, pre, pos)
 
#define luaC_checkGC(L)   luaC_condGC(L,(void)0,(void)0)
 
#define luaC_barrier(L, p, v)
 
#define luaC_barrierback(L, p, v)
 
#define luaC_objbarrier(L, p, o)
 
#define luaC_upvalbarrier(L, uv)
 

Functions

LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o)
 
LUAI_FUNC void luaC_freeallobjects (lua_State *L)
 
LUAI_FUNC void luaC_step (lua_State *L)
 
LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask)
 
LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency)
 
LUAI_FUNC GCObjectluaC_newobj (lua_State *L, int tt, size_t sz)
 
LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v)
 
LUAI_FUNC void luaC_barrierback_ (lua_State *L, Table *o)
 
LUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv)
 
LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt)
 
LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv)
 

Macro Definition Documentation

◆ bit2mask

#define bit2mask ( b1,
b2 )   (bitmask(b1) | bitmask(b2))

Definition at line 71 of file lua-5.3.6/src/lgc.h.

◆ bitmask

#define bitmask ( b)    (1<<(b))

Definition at line 70 of file lua-5.3.6/src/lgc.h.

◆ BLACKBIT

#define BLACKBIT   2 /* object is black */

Definition at line 80 of file lua-5.3.6/src/lgc.h.

◆ changewhite

#define changewhite ( x)    ((x)->marked ^= WHITEBITS)

Definition at line 98 of file lua-5.3.6/src/lgc.h.

◆ FINALIZEDBIT

#define FINALIZEDBIT   3 /* object has been marked for finalization */

Definition at line 81 of file lua-5.3.6/src/lgc.h.

◆ GCSatomic

#define GCSatomic   1

Definition at line 40 of file lua-5.3.6/src/lgc.h.

◆ GCScallfin

#define GCScallfin   6

Definition at line 45 of file lua-5.3.6/src/lgc.h.

Referenced by fullinc(), luaC_fullgc(), singlestep(), and singlestep().

◆ GCSpause

#define GCSpause   7

Definition at line 46 of file lua-5.3.6/src/lgc.h.

◆ GCSpropagate

#define GCSpropagate   0

Definition at line 39 of file lua-5.3.6/src/lgc.h.

◆ GCSswpallgc

#define GCSswpallgc   2

◆ GCSswpend

#define GCSswpend   5

Definition at line 44 of file lua-5.3.6/src/lgc.h.

Referenced by singlestep(), and singlestep().

◆ GCSswpfinobj

#define GCSswpfinobj   3

Definition at line 42 of file lua-5.3.6/src/lgc.h.

Referenced by singlestep(), and singlestep().

◆ GCSswptobefnz

#define GCSswptobefnz   4

Definition at line 43 of file lua-5.3.6/src/lgc.h.

Referenced by singlestep(), and singlestep().

◆ GCSTEPSIZE

#define GCSTEPSIZE   (cast_int(100 * sizeof(TString)))

Definition at line 32 of file lua-5.3.6/src/lgc.h.

◆ gray2black

#define gray2black ( x)    l_setbit((x)->marked, BLACKBIT)

Definition at line 99 of file lua-5.3.6/src/lgc.h.

◆ isblack

#define isblack ( x)    testbit((x)->marked, BLACKBIT)

Definition at line 88 of file lua-5.3.6/src/lgc.h.

◆ isdead

#define isdead ( g,
v )   isdeadm(otherwhite(g), (v)->marked)

Definition at line 96 of file lua-5.3.6/src/lgc.h.

◆ isdeadm

#define isdeadm ( ow,
m )   (!(((m) ^ WHITEBITS) & (ow)))

Definition at line 95 of file lua-5.3.6/src/lgc.h.

◆ isgray

#define isgray ( x)
Value:
/* neither white nor black */ \
(!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT)))
#define WHITEBITS
#define testbits(x, m)
#define BLACKBIT
#define bitmask(b)

Definition at line 89 of file lua-5.3.6/src/lgc.h.

89#define isgray(x) /* neither white nor black */ \
90 (!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT)))

◆ issweepphase

#define issweepphase ( g)     (GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend)

Definition at line 49 of file lua-5.3.6/src/lgc.h.

49#define issweepphase(g) \
50 (GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend)

◆ iswhite

#define iswhite ( x)    testbits((x)->marked, WHITEBITS)

Definition at line 87 of file lua-5.3.6/src/lgc.h.

◆ keepinvariant

#define keepinvariant ( g)    ((g)->gcstate <= GCSatomic)

Definition at line 61 of file lua-5.3.6/src/lgc.h.

◆ l_setbit

#define l_setbit ( x,
b )   setbits(x, bitmask(b))

Definition at line 72 of file lua-5.3.6/src/lgc.h.

◆ luaC_barrier

#define luaC_barrier ( L,
p,
v )
Value:
( \
(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \
#define gcvalue(o)
#define iscollectable(o)
#define obj2gco(v)
#define iswhite(x)
#define isblack(x)
LUAI_FUNC void luaC_barrier_(lua_State *L, GCObject *o, GCObject *v)
#define cast_void(i)

Definition at line 118 of file lua-5.3.6/src/lgc.h.

118#define luaC_barrier(L,p,v) ( \
119 (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \
120 luaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0))

◆ luaC_barrierback

#define luaC_barrierback ( L,
p,
v )
Value:
( \
(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \
LUAI_FUNC void luaC_barrierback_(lua_State *L, Table *o)

Definition at line 122 of file lua-5.3.6/src/lgc.h.

122#define luaC_barrierback(L,p,v) ( \
123 (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \
124 luaC_barrierback_(L,p) : cast_void(0))

◆ luaC_checkGC

#define luaC_checkGC ( L)    luaC_condGC(L,(void)0,(void)0)

Definition at line 115 of file lua-5.3.6/src/lgc.h.

◆ luaC_condGC

#define luaC_condGC ( L,
pre,
pos )
Value:
{ if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \
condchangemem(L,pre,pos); }
#define G(L)
LUAI_FUNC void luaC_step(lua_State *L)

Definition at line 110 of file lua-5.3.6/src/lgc.h.

110#define luaC_condGC(L,pre,pos) \
111 { if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \
112 condchangemem(L,pre,pos); }

◆ luaC_objbarrier

#define luaC_objbarrier ( L,
p,
o )
Value:
( \
(isblack(p) && iswhite(o)) ? \

Definition at line 126 of file lua-5.3.6/src/lgc.h.

126#define luaC_objbarrier(L,p,o) ( \
127 (isblack(p) && iswhite(o)) ? \
128 luaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0))

◆ luaC_upvalbarrier

#define luaC_upvalbarrier ( L,
uv )
Value:
( \
(iscollectable((uv)->v) && !upisopen(uv)) ? \
#define upisopen(up)
LUAI_FUNC void luaC_upvalbarrier_(lua_State *L, UpVal *uv)

Definition at line 130 of file lua-5.3.6/src/lgc.h.

130#define luaC_upvalbarrier(L,uv) ( \
131 (iscollectable((uv)->v) && !upisopen(uv)) ? \
132 luaC_upvalbarrier_(L,uv) : cast_void(0))

Referenced by lua_load(), lua_setupvalue(), lua_upvaluejoin(), luaF_close(), and luaV_execute().

◆ luaC_white

#define luaC_white ( g)    cast(lu_byte, (g)->currentwhite & WHITEBITS)

Definition at line 101 of file lua-5.3.6/src/lgc.h.

◆ otherwhite

#define otherwhite ( g)    ((g)->currentwhite ^ WHITEBITS)

Definition at line 94 of file lua-5.3.6/src/lgc.h.

◆ resetbit

#define resetbit ( x,
b )   resetbits(x, bitmask(b))

Definition at line 73 of file lua-5.3.6/src/lgc.h.

◆ resetbits

#define resetbits ( x,
m )   ((x) &= cast(lu_byte, ~(m)))

Definition at line 67 of file lua-5.3.6/src/lgc.h.

◆ setbits

#define setbits ( x,
m )   ((x) |= (m))

Definition at line 68 of file lua-5.3.6/src/lgc.h.

◆ testbit

#define testbit ( x,
b )   testbits(x, bitmask(b))

Definition at line 74 of file lua-5.3.6/src/lgc.h.

◆ testbits

#define testbits ( x,
m )   ((x) & (m))

Definition at line 69 of file lua-5.3.6/src/lgc.h.

◆ tofinalize

#define tofinalize ( x)    testbit((x)->marked, FINALIZEDBIT)

◆ WHITE0BIT

#define WHITE0BIT   0 /* object is white (type 0) */

Definition at line 78 of file lua-5.3.6/src/lgc.h.

◆ WHITE1BIT

#define WHITE1BIT   1 /* object is white (type 1) */

Definition at line 79 of file lua-5.3.6/src/lgc.h.

◆ WHITEBITS

#define WHITEBITS   bit2mask(WHITE0BIT, WHITE1BIT)

Definition at line 84 of file lua-5.3.6/src/lgc.h.

Function Documentation

◆ luaC_barrier_()

LUAI_FUNC void luaC_barrier_ ( lua_State * L,
GCObject * o,
GCObject * v )

Definition at line 135 of file lua-5.2.4/src/lgc.c.

135 {
136 global_State *g = G(L);
137 lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
139 lua_assert(gch(o)->tt != LUA_TTABLE);
140 if (keepinvariantout(g)) /* must keep invariant? */
141 reallymarkobject(g, v); /* restore invariant */
142 else { /* sweep phase */
144 makewhite(g, o); /* mark main obj. as white to avoid other barriers */
145 }
146}
#define iswhite(x)
#define GCSpause
#define isblack(x)
#define isdead(g, v)
#define lua_assert(c)
#define LUA_TTABLE
static void reallymarkobject(global_State *g, GCObject *o)
#define makewhite(g, x)
#define issweepphase(g)
#define keepinvariantout(g)
#define gch(o)

◆ luaC_barrierback_()

LUAI_FUNC void luaC_barrierback_ ( lua_State * L,
Table * o )

Definition at line 171 of file lua-5.3.6/src/lgc.c.

171 {
172 global_State *g = G(L);
173 lua_assert(isblack(t) && !isdead(g, t));
174 black2gray(t); /* make table gray (again) */
175 linkgclist(t, g->grayagain);
176}
#define black2gray(x)
#define linkgclist(o, p)

References black2gray, G, global_State::grayagain, isblack, isdead, linkgclist, and lua_assert.

◆ luaC_checkfinalizer()

LUAI_FUNC void luaC_checkfinalizer ( lua_State * L,
GCObject * o,
Table * mt )

Definition at line 873 of file lua-5.2.4/src/lgc.c.

873 {
874 global_State *g = G(L);
875 if (testbit(gch(o)->marked, SEPARATED) || /* obj. is already separated... */
876 isfinalized(o) || /* ... or is finalized... */
877 gfasttm(g, mt, TM_GC) == NULL) /* or has no finalizer? */
878 return; /* nothing to be done */
879 else { /* move 'o' to 'finobj' list */
880 GCObject **p;
881 GCheader *ho = gch(o);
882 if (g->sweepgc == &ho->next) { /* avoid removing current sweep object */
884 g->sweepgc = sweeptolive(L, g->sweepgc, NULL);
885 }
886 /* search for pointer pointing to 'o' */
887 for (p = &g->allgc; *p != o; p = &gch(*p)->next) { /* empty */ }
888 *p = ho->next; /* remove 'o' from root list */
889 ho->next = g->finobj; /* link it in list 'finobj' */
890 g->finobj = o;
891 l_setbit(ho->marked, SEPARATED); /* mark it as such */
892 if (!keepinvariantout(g)) /* not keeping invariant? */
893 makewhite(g, o); /* "sweep" object */
894 else
895 resetoldbit(o); /* see MOVE OLD rule */
896 }
897}
#define NULL
Definition gmacros.h:924
#define testbit(x, b)
#define l_setbit(x, b)
@ TM_GC
#define gfasttm(g, et, e)
#define isfinalized(x)
static GCObject ** sweeptolive(lua_State *L, GCObject **p, int *n)
#define resetoldbit(o)
#define SEPARATED

◆ luaC_fix()

LUAI_FUNC void luaC_fix ( lua_State * L,
GCObject * o )

Definition at line 194 of file lua-5.3.6/src/lgc.c.

194 {
195 global_State *g = G(L);
196 lua_assert(g->allgc == o); /* object must be 1st in 'allgc' list! */
197 white2gray(o); /* they will be gray forever */
198 g->allgc = o->next; /* remove object from 'allgc' list */
199 o->next = g->fixedgc; /* link it to 'fixedgc' list */
200 g->fixedgc = o;
201}
#define white2gray(x)

◆ luaC_freeallobjects()

LUAI_FUNC void luaC_freeallobjects ( lua_State * L)

Definition at line 983 of file lua-5.2.4/src/lgc.c.

983 {
984 global_State *g = G(L);
985 int i;
986 separatetobefnz(L, 1); /* separate all objects with finalizers */
987 lua_assert(g->finobj == NULL);
989 g->currentwhite = WHITEBITS; /* this "white" makes all objects look dead */
990 g->gckind = KGC_NORMAL;
991 sweepwholelist(L, &g->finobj); /* finalizers can create objs. in 'finobj' */
992 sweepwholelist(L, &g->allgc);
993 for (i = 0; i < g->strt.size; i++) /* free all string lists */
994 sweepwholelist(L, &g->strt.hash[i]);
995 lua_assert(g->strt.nuse == 0);
996}
#define WHITEBITS
#define sweepwholelist(L, p)
static void callallpendingfinalizers(lua_State *L, int propagateerrors)
static void separatetobefnz(lua_State *L, int all)
#define KGC_NORMAL

◆ luaC_fullgc()

LUAI_FUNC void luaC_fullgc ( lua_State * L,
int isemergency )

Definition at line 1189 of file lua-5.2.4/src/lgc.c.

1189 {
1190 global_State *g = G(L);
1191 int origkind = g->gckind;
1192 lua_assert(origkind != KGC_EMERGENCY);
1193 if (isemergency) /* do not run finalizers during emergency GC */
1194 g->gckind = KGC_EMERGENCY;
1195 else {
1196 g->gckind = KGC_NORMAL;
1198 }
1199 if (keepinvariant(g)) { /* may there be some black objects? */
1200 /* must sweep all objects to turn them back to white
1201 (as white has not changed, nothing will be collected) */
1202 entersweep(L);
1203 }
1204 /* finish any pending sweep phase to start a new cycle */
1206 luaC_runtilstate(L, ~bitmask(GCSpause)); /* start new collection */
1207 luaC_runtilstate(L, bitmask(GCSpause)); /* run entire collection */
1208 if (origkind == KGC_GEN) { /* generational mode? */
1209 /* generational mode must be kept in propagate phase */
1211 }
1212 g->gckind = origkind;
1213 setpause(g, gettotalbytes(g));
1214 if (!isemergency) /* do not run finalizers during emergency GC */
1216}
#define GCSpropagate
#define bitmask(b)
static int entersweep(lua_State *L)
static void setpause(global_State *g, l_mem estimate)
void luaC_runtilstate(lua_State *L, int statesmask)
#define keepinvariant(g)
#define gettotalbytes(g)
#define KGC_EMERGENCY
#define KGC_GEN

◆ luaC_newobj()

LUAI_FUNC GCObject * luaC_newobj ( lua_State * L,
int tt,
size_t sz )

Definition at line 208 of file lua-5.3.6/src/lgc.c.

208 {
209 global_State *g = G(L);
210 GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz));
211 o->marked = luaC_white(g);
212 o->tt = tt;
213 o->next = g->allgc;
214 g->allgc = o;
215 return o;
216}
#define luaC_white(g)
#define cast(t, exp)
#define luaM_newobject(L, tag, s)
#define novariant(x)

◆ luaC_runtilstate()

LUAI_FUNC void luaC_runtilstate ( lua_State * L,
int statesmask )

Definition at line 1110 of file lua-5.2.4/src/lgc.c.

1110 {
1111 global_State *g = G(L);
1112 while (!testbit(statesmask, g->gcstate))
1113 singlestep(L);
1114}
static lu_mem singlestep(lua_State *L)

◆ luaC_step()

LUAI_FUNC void luaC_step ( lua_State * L)

Definition at line 610 of file lua-5.1.5/src/lgc.c.

610 {
611 global_State *g = G(L);
612 l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul;
613 if (lim == 0)
614 lim = (MAX_LUMEM-1)/2; /* no limit */
615 g->gcdept += g->totalbytes - g->GCthreshold;
616 do {
617 lim -= singlestep(L);
618 if (g->gcstate == GCSpause)
619 break;
620 } while (lim > 0);
621 if (g->gcstate != GCSpause) {
622 if (g->gcdept < GCSTEPSIZE)
623 g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/g->gcstepmul;*/
624 else {
625 g->gcdept -= GCSTEPSIZE;
626 g->GCthreshold = g->totalbytes;
627 }
628 }
629 else {
630 setthreshold(g);
631 }
632}
static l_mem singlestep(lua_State *L)
#define setthreshold(g)
#define GCSTEPSIZE
#define MAX_LUMEM
LUAI_MEM l_mem

◆ luaC_upvalbarrier_()

LUAI_FUNC void luaC_upvalbarrier_ ( lua_State * L,
UpVal * uv )

Definition at line 185 of file lua-5.3.6/src/lgc.c.

185 {
186 global_State *g = G(L);
187 GCObject *o = gcvalue(uv->v);
188 lua_assert(!upisopen(uv)); /* ensured by macro luaC_upvalbarrier */
189 if (keepinvariant(g))
190 markobject(g, o);
191}
#define markobject(g, t)

References G, gcvalue, keepinvariant, lua_assert, markobject, upisopen, and UpVal::v.

◆ luaC_upvdeccount()

LUAI_FUNC void luaC_upvdeccount ( lua_State * L,
UpVal * uv )

Definition at line 678 of file lua-5.3.6/src/lgc.c.

678 {
679 lua_assert(uv->refcount > 0);
680 uv->refcount--;
681 if (uv->refcount == 0 && !upisopen(uv))
682 luaM_free(L, uv);
683}
#define luaM_free(L, b)
lu_mem refcount

References lua_assert, luaM_free, UpVal::refcount, and upisopen.

Referenced by freeLclosure(), and lua_upvaluejoin().