Lines Matching refs:g
67 #define makewhite(g,x) \ argument
68 (x->marked = cast_byte((x->marked & maskcolors) | luaC_white(g)))
83 #define markvalue(g,o) { checkconsistency(o); \ argument
84 if (valiswhite(o)) reallymarkobject(g,gcvalue(o)); }
86 #define markobject(g,t) { if (iswhite(t)) reallymarkobject(g, obj2gco(t)); } argument
92 #define markobjectN(g,t) { if (t) markobject(g,t); } argument
94 static void reallymarkobject (global_State *g, GCObject *o);
139 static int iscleared (global_State *g, const TValue *o) { in iscleared() argument
142 markobject(g, tsvalue(o)); /* strings are 'values', so are never weak */ in iscleared()
156 global_State *g = G(L); in luaC_barrier_() local
157 lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); in luaC_barrier_()
158 if (keepinvariant(g)) /* must keep invariant? */ in luaC_barrier_()
159 reallymarkobject(g, v); /* restore invariant */ in luaC_barrier_()
161 lua_assert(issweepphase(g)); in luaC_barrier_()
162 makewhite(g, o); /* mark main obj. as white to avoid other barriers */ in luaC_barrier_()
172 global_State *g = G(L); in luaC_barrierback_() local
173 lua_assert(isblack(t) && !isdead(g, t)); in luaC_barrierback_()
175 linkgclist(t, g->grayagain); in luaC_barrierback_()
186 global_State *g = G(L); in luaC_upvalbarrier_() local
189 if (keepinvariant(g)) in luaC_upvalbarrier_()
190 markobject(g, o); in luaC_upvalbarrier_()
195 global_State *g = G(L); in luaC_fix() local
196 lua_assert(g->allgc == o); /* object must be 1st in 'allgc' list! */ in luaC_fix()
198 g->allgc = o->next; /* remove object from 'allgc' list */ in luaC_fix()
199 o->next = g->fixedgc; /* link it to 'fixedgc' list */ in luaC_fix()
200 g->fixedgc = o; in luaC_fix()
209 global_State *g = G(L); in luaC_newobj() local
211 o->marked = luaC_white(g); in luaC_newobj()
213 o->next = g->allgc; in luaC_newobj()
214 g->allgc = o; in luaC_newobj()
235 static void reallymarkobject (global_State *g, GCObject *o) { in reallymarkobject() argument
241 g->GCmemtrav += sizelstring(gco2ts(o)->shrlen); in reallymarkobject()
246 g->GCmemtrav += sizelstring(gco2ts(o)->u.lnglen); in reallymarkobject()
251 markobjectN(g, gco2u(o)->metatable); /* mark its metatable */ in reallymarkobject()
253 g->GCmemtrav += sizeudata(gco2u(o)); in reallymarkobject()
254 getuservalue(g->mainthread, gco2u(o), &uvalue); in reallymarkobject()
262 linkgclist(gco2lcl(o), g->gray); in reallymarkobject()
266 linkgclist(gco2ccl(o), g->gray); in reallymarkobject()
270 linkgclist(gco2t(o), g->gray); in reallymarkobject()
274 linkgclist(gco2th(o), g->gray); in reallymarkobject()
278 linkgclist(gco2p(o), g->gray); in reallymarkobject()
289 static void markmt (global_State *g) { in markmt() argument
292 markobjectN(g, g->mt[i]); in markmt()
299 static void markbeingfnz (global_State *g) { in markbeingfnz() argument
301 for (o = g->tobefnz; o != NULL; o = o->next) in markbeingfnz()
302 markobject(g, o); in markbeingfnz()
312 static void remarkupvals (global_State *g) { in remarkupvals() argument
314 lua_State **p = &g->twups; in remarkupvals()
325 markvalue(g, uv->v); /* remark upvalue's value */ in remarkupvals()
337 static void restartcollection (global_State *g) { in restartcollection() argument
338 g->gray = g->grayagain = NULL; in restartcollection()
339 g->weak = g->allweak = g->ephemeron = NULL; in restartcollection()
340 markobject(g, g->mainthread); in restartcollection()
341 markvalue(g, &g->l_registry); in restartcollection()
342 markmt(g); in restartcollection()
343 markbeingfnz(g); /* mark any finalizing object left from previous cycle */ in restartcollection()
361 static void traverseweakvalue (global_State *g, Table *h) { in traverseweakvalue() argument
372 markvalue(g, gkey(n)); /* mark key */ in traverseweakvalue()
373 if (!hasclears && iscleared(g, gval(n))) /* is there a white value? */ in traverseweakvalue()
377 if (g->gcstate == GCSpropagate) in traverseweakvalue()
378 linkgclist(h, g->grayagain); /* must retraverse it in atomic phase */ in traverseweakvalue()
380 linkgclist(h, g->weak); /* has to be cleared later */ in traverseweakvalue()
394 static int traverseephemeron (global_State *g, Table *h) { in traverseephemeron() argument
404 reallymarkobject(g, gcvalue(&h->array[i])); in traverseephemeron()
412 else if (iscleared(g, gkey(n))) { /* key is not marked (yet)? */ in traverseephemeron()
419 reallymarkobject(g, gcvalue(gval(n))); /* mark it now */ in traverseephemeron()
423 if (g->gcstate == GCSpropagate) in traverseephemeron()
424 linkgclist(h, g->grayagain); /* must retraverse it in atomic phase */ in traverseephemeron()
426 linkgclist(h, g->ephemeron); /* have to propagate again */ in traverseephemeron()
428 linkgclist(h, g->allweak); /* may have to clean white keys */ in traverseephemeron()
433 static void traversestrongtable (global_State *g, Table *h) { in traversestrongtable() argument
437 markvalue(g, &h->array[i]); in traversestrongtable()
444 markvalue(g, gkey(n)); /* mark key */ in traversestrongtable()
445 markvalue(g, gval(n)); /* mark value */ in traversestrongtable()
451 static lu_mem traversetable (global_State *g, Table *h) { in traversetable() argument
453 const TValue *mode = gfasttm(g, h->metatable, TM_MODE); in traversetable()
454 markobjectN(g, h->metatable); in traversetable()
461 traverseweakvalue(g, h); in traversetable()
463 traverseephemeron(g, h); in traversetable()
465 linkgclist(h, g->allweak); /* nothing to traverse now */ in traversetable()
468 traversestrongtable(g, h); in traversetable()
479 static int traverseproto (global_State *g, Proto *f) { in traverseproto() argument
483 markobjectN(g, f->source); in traverseproto()
485 markvalue(g, &f->k[i]); in traverseproto()
487 markobjectN(g, f->upvalues[i].name); in traverseproto()
489 markobjectN(g, f->p[i]); in traverseproto()
491 markobjectN(g, f->locvars[i].varname); in traverseproto()
501 static lu_mem traverseCclosure (global_State *g, CClosure *cl) { in traverseCclosure() argument
504 markvalue(g, &cl->upvalue[i]); in traverseCclosure()
514 static lu_mem traverseLclosure (global_State *g, LClosure *cl) { in traverseLclosure() argument
516 markobjectN(g, cl->p); /* mark its prototype */ in traverseLclosure()
520 if (upisopen(uv) && g->gcstate != GCSinsideatomic) in traverseLclosure()
523 markvalue(g, uv->v); in traverseLclosure()
530 static lu_mem traversethread (global_State *g, lua_State *th) { in traversethread() argument
534 lua_assert(g->gcstate == GCSinsideatomic || in traversethread()
537 markvalue(g, o); in traversethread()
538 if (g->gcstate == GCSinsideatomic) { /* final traversal? */ in traversethread()
544 th->twups = g->twups; /* link it back to the list */ in traversethread()
545 g->twups = th; in traversethread()
548 else if (g->gckind != KGC_EMERGENCY) in traversethread()
559 static void propagatemark (global_State *g) { in propagatemark() argument
561 GCObject *o = g->gray; in propagatemark()
567 g->gray = h->gclist; /* remove from 'gray' list */ in propagatemark()
568 size = traversetable(g, h); in propagatemark()
573 g->gray = cl->gclist; /* remove from 'gray' list */ in propagatemark()
574 size = traverseLclosure(g, cl); in propagatemark()
579 g->gray = cl->gclist; /* remove from 'gray' list */ in propagatemark()
580 size = traverseCclosure(g, cl); in propagatemark()
585 g->gray = th->gclist; /* remove from 'gray' list */ in propagatemark()
586 linkgclist(th, g->grayagain); /* insert into 'grayagain' list */ in propagatemark()
588 size = traversethread(g, th); in propagatemark()
593 g->gray = p->gclist; /* remove from 'gray' list */ in propagatemark()
594 size = traverseproto(g, p); in propagatemark()
599 g->GCmemtrav += size; in propagatemark()
603 static void propagateall (global_State *g) { in propagateall() argument
604 while (g->gray) propagatemark(g); in propagateall()
608 static void convergeephemerons (global_State *g) { in convergeephemerons() argument
612 GCObject *next = g->ephemeron; /* get ephemeron list */ in convergeephemerons()
613 g->ephemeron = NULL; /* tables may return to this list when traversed */ in convergeephemerons()
617 if (traverseephemeron(g, gco2t(w))) { /* traverse marked some value? */ in convergeephemerons()
618 propagateall(g); /* propagate changes */ in convergeephemerons()
639 static void clearkeys (global_State *g, GCObject *l, GCObject *f) { in clearkeys() argument
644 if (!ttisnil(gval(n)) && (iscleared(g, gkey(n)))) { in clearkeys()
658 static void clearvalues (global_State *g, GCObject *l, GCObject *f) { in clearvalues() argument
665 if (iscleared(g, o)) /* value was collected? */ in clearvalues()
669 if (!ttisnil(gval(n)) && iscleared(g, gval(n))) { in clearvalues()
736 global_State *g = G(L); in sweeplist() local
737 int ow = otherwhite(g); in sweeplist()
738 int white = luaC_white(g); /* current white */ in sweeplist()
778 static void checkSizes (lua_State *L, global_State *g) { in checkSizes() argument
779 if (g->gckind != KGC_EMERGENCY) { in checkSizes()
780 l_mem olddebt = g->GCdebt; in checkSizes()
781 if (g->strt.nuse < g->strt.size / 4) /* string table too big? */ in checkSizes()
782 luaS_resize(L, g->strt.size / 2); /* shrink it a little */ in checkSizes()
783 g->GCestimate += g->GCdebt - olddebt; /* update estimate */ in checkSizes()
788 static GCObject *udata2finalize (global_State *g) { in udata2finalize() argument
789 GCObject *o = g->tobefnz; /* get first element */ in udata2finalize()
791 g->tobefnz = o->next; /* remove it from 'tobefnz' list */ in udata2finalize()
792 o->next = g->allgc; /* return it to 'allgc' list */ in udata2finalize()
793 g->allgc = o; in udata2finalize()
795 if (issweepphase(g)) in udata2finalize()
796 makewhite(g, o); /* "sweep" object */ in udata2finalize()
808 global_State *g = G(L); in GCTM() local
811 setgcovalue(L, &v, udata2finalize(g)); in GCTM()
816 int running = g->gcrunning; in GCTM()
818 g->gcrunning = 0; /* avoid GC steps */ in GCTM()
826 g->gcrunning = running; /* restore state */ in GCTM()
845 global_State *g = G(L); in runafewfinalizers() local
847 lua_assert(!g->tobefnz || g->gcfinnum > 0); in runafewfinalizers()
848 for (i = 0; g->tobefnz && i < g->gcfinnum; i++) in runafewfinalizers()
850 g->gcfinnum = (!g->tobefnz) ? 0 /* nothing more to finalize? */ in runafewfinalizers()
851 : g->gcfinnum * 2; /* else call a few more next time */ in runafewfinalizers()
860 global_State *g = G(L); in callallpendingfinalizers() local
861 while (g->tobefnz) in callallpendingfinalizers()
880 static void separatetobefnz (global_State *g, int all) { in separatetobefnz() argument
882 GCObject **p = &g->finobj; in separatetobefnz()
883 GCObject **lastnext = findlast(&g->tobefnz); in separatetobefnz()
903 global_State *g = G(L); in luaC_checkfinalizer() local
905 gfasttm(g, mt, TM_GC) == NULL) /* or has no finalizer? */ in luaC_checkfinalizer()
909 if (issweepphase(g)) { in luaC_checkfinalizer()
910 makewhite(g, o); /* "sweep" object 'o' */ in luaC_checkfinalizer()
911 if (g->sweepgc == &o->next) /* should not remove 'sweepgc' object */ in luaC_checkfinalizer()
912 g->sweepgc = sweeptolive(L, g->sweepgc); /* change 'sweepgc' */ in luaC_checkfinalizer()
915 for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ } in luaC_checkfinalizer()
917 o->next = g->finobj; /* link it in 'finobj' list */ in luaC_checkfinalizer()
918 g->finobj = o; in luaC_checkfinalizer()
940 static void setpause (global_State *g) { in setpause() argument
942 l_mem estimate = g->GCestimate / PAUSEADJ; /* adjust 'estimate' */ in setpause()
944 threshold = (g->gcpause < MAX_LMEM / estimate) /* overflow? */ in setpause()
945 ? estimate * g->gcpause /* no overflow */ in setpause()
947 debt = gettotalbytes(g) - threshold; in setpause()
948 luaE_setdebt(g, debt); in setpause()
960 global_State *g = G(L); in entersweep() local
961 g->gcstate = GCSswpallgc; in entersweep()
962 lua_assert(g->sweepgc == NULL); in entersweep()
963 g->sweepgc = sweeplist(L, &g->allgc, 1); in entersweep()
968 global_State *g = G(L); in luaC_freeallobjects() local
969 separatetobefnz(g, 1); /* separate all objects with finalizers */ in luaC_freeallobjects()
970 lua_assert(g->finobj == NULL); in luaC_freeallobjects()
972 lua_assert(g->tobefnz == NULL); in luaC_freeallobjects()
973 g->currentwhite = WHITEBITS; /* this "white" makes all objects look dead */ in luaC_freeallobjects()
974 g->gckind = KGC_NORMAL; in luaC_freeallobjects()
975 sweepwholelist(L, &g->finobj); in luaC_freeallobjects()
976 sweepwholelist(L, &g->allgc); in luaC_freeallobjects()
977 sweepwholelist(L, &g->fixedgc); /* collect fixed objects */ in luaC_freeallobjects()
978 lua_assert(g->strt.nuse == 0); in luaC_freeallobjects()
983 global_State *g = G(L); in atomic() local
986 GCObject *grayagain = g->grayagain; /* save original list */ in atomic()
987 lua_assert(g->ephemeron == NULL && g->weak == NULL); in atomic()
988 lua_assert(!iswhite(g->mainthread)); in atomic()
989 g->gcstate = GCSinsideatomic; in atomic()
990 g->GCmemtrav = 0; /* start counting work */ in atomic()
991 markobject(g, L); /* mark running thread */ in atomic()
993 markvalue(g, &g->l_registry); in atomic()
994 markmt(g); /* mark global metatables */ in atomic()
996 remarkupvals(g); in atomic()
997 propagateall(g); /* propagate changes */ in atomic()
998 work = g->GCmemtrav; /* stop counting (do not recount 'grayagain') */ in atomic()
999 g->gray = grayagain; in atomic()
1000 propagateall(g); /* traverse 'grayagain' list */ in atomic()
1001 g->GCmemtrav = 0; /* restart counting */ in atomic()
1002 convergeephemerons(g); in atomic()
1005 clearvalues(g, g->weak, NULL); in atomic()
1006 clearvalues(g, g->allweak, NULL); in atomic()
1007 origweak = g->weak; origall = g->allweak; in atomic()
1008 work += g->GCmemtrav; /* stop counting (objects being finalized) */ in atomic()
1009 separatetobefnz(g, 0); /* separate objects to be finalized */ in atomic()
1010 g->gcfinnum = 1; /* there may be objects to be finalized */ in atomic()
1011 markbeingfnz(g); /* mark objects that will be finalized */ in atomic()
1012 propagateall(g); /* remark, to propagate 'resurrection' */ in atomic()
1013 g->GCmemtrav = 0; /* restart counting */ in atomic()
1014 convergeephemerons(g); in atomic()
1017 clearkeys(g, g->ephemeron, NULL); /* clear keys from all ephemeron tables */ in atomic()
1018 clearkeys(g, g->allweak, NULL); /* clear keys from all 'allweak' tables */ in atomic()
1020 clearvalues(g, g->weak, origweak); in atomic()
1021 clearvalues(g, g->allweak, origall); in atomic()
1022 luaS_clearcache(g); in atomic()
1023 g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */ in atomic()
1024 work += g->GCmemtrav; /* complete counting */ in atomic()
1029 static lu_mem sweepstep (lua_State *L, global_State *g, in sweepstep() argument
1031 if (g->sweepgc) { in sweepstep()
1032 l_mem olddebt = g->GCdebt; in sweepstep()
1033 g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); in sweepstep()
1034 g->GCestimate += g->GCdebt - olddebt; /* update estimate */ in sweepstep()
1035 if (g->sweepgc) /* is there still something to sweep? */ in sweepstep()
1039 g->gcstate = nextstate; in sweepstep()
1040 g->sweepgc = nextlist; in sweepstep()
1046 global_State *g = G(L); in singlestep() local
1047 switch (g->gcstate) { in singlestep()
1049 g->GCmemtrav = g->strt.size * sizeof(GCObject*); in singlestep()
1050 restartcollection(g); in singlestep()
1051 g->gcstate = GCSpropagate; in singlestep()
1052 return g->GCmemtrav; in singlestep()
1055 g->GCmemtrav = 0; in singlestep()
1056 lua_assert(g->gray); in singlestep()
1057 propagatemark(g); in singlestep()
1058 if (g->gray == NULL) /* no more gray objects? */ in singlestep()
1059 g->gcstate = GCSatomic; /* finish propagate phase */ in singlestep()
1060 return g->GCmemtrav; /* memory traversed in this step */ in singlestep()
1064 propagateall(g); /* make sure gray list is empty */ in singlestep()
1067 g->GCestimate = gettotalbytes(g); /* first estimate */; in singlestep()
1071 return sweepstep(L, g, GCSswpfinobj, &g->finobj); in singlestep()
1074 return sweepstep(L, g, GCSswptobefnz, &g->tobefnz); in singlestep()
1077 return sweepstep(L, g, GCSswpend, NULL); in singlestep()
1080 makewhite(g, g->mainthread); /* sweep main thread */ in singlestep()
1081 checkSizes(L, g); in singlestep()
1082 g->gcstate = GCScallfin; in singlestep()
1086 if (g->tobefnz && g->gckind != KGC_EMERGENCY) { in singlestep()
1091 g->gcstate = GCSpause; /* finish collection */ in singlestep()
1105 global_State *g = G(L); in luaC_runtilstate() local
1106 while (!testbit(statesmask, g->gcstate)) in luaC_runtilstate()
1115 static l_mem getdebt (global_State *g) { in getdebt() argument
1116 l_mem debt = g->GCdebt; in getdebt()
1117 int stepmul = g->gcstepmul; in getdebt()
1130 global_State *g = G(L); in luaC_step() local
1131 l_mem debt = getdebt(g); /* GC deficit (be paid now) */ in luaC_step()
1132 if (!g->gcrunning) { /* not running? */ in luaC_step()
1133 luaE_setdebt(g, -GCSTEPSIZE * 10); /* avoid being called too often */ in luaC_step()
1139 } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause); in luaC_step()
1140 if (g->gcstate == GCSpause) in luaC_step()
1141 setpause(g); /* pause until next cycle */ in luaC_step()
1143 debt = (debt / g->gcstepmul) * STEPMULADJ; /* convert 'work units' to Kb */ in luaC_step()
1144 luaE_setdebt(g, debt); in luaC_step()
1160 global_State *g = G(L); in luaC_fullgc() local
1161 lua_assert(g->gckind == KGC_NORMAL); in luaC_fullgc()
1162 if (isemergency) g->gckind = KGC_EMERGENCY; /* set flag */ in luaC_fullgc()
1163 if (keepinvariant(g)) { /* black objects? */ in luaC_fullgc()
1171 lua_assert(g->GCestimate == gettotalbytes(g)); in luaC_fullgc()
1173 g->gckind = KGC_NORMAL; in luaC_fullgc()
1174 setpause(g); in luaC_fullgc()