• Home
  • Raw
  • Download

Lines Matching refs:g

59 #define makewhite(g,x)	\  argument
60 (gch(x)->marked = cast_byte((gch(x)->marked & maskcolors) | luaC_white(g)))
75 #define markvalue(g,o) { checkconsistency(o); \ argument
76 if (valiswhite(o)) reallymarkobject(g,gcvalue(o)); }
78 #define markobject(g,t) { if ((t) && iswhite(obj2gco(t))) \ argument
79 reallymarkobject(g, obj2gco(t)); }
81 static void reallymarkobject (global_State *g, GCObject *o);
121 static int iscleared (global_State *g, const TValue *o) { in iscleared() argument
124 markobject(g, rawtsvalue(o)); /* strings are `values', so are never weak */ in iscleared()
136 global_State *g = G(L); in luaC_barrier_() local
137 lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); in luaC_barrier_()
138 lua_assert(g->gcstate != GCSpause); in luaC_barrier_()
140 if (keepinvariantout(g)) /* must keep invariant? */ in luaC_barrier_()
141 reallymarkobject(g, v); /* restore invariant */ in luaC_barrier_()
143 lua_assert(issweepphase(g)); in luaC_barrier_()
144 makewhite(g, o); /* mark main obj. as white to avoid other barriers */ in luaC_barrier_()
156 global_State *g = G(L); in luaC_barrierback_() local
157 lua_assert(isblack(o) && !isdead(g, o) && gch(o)->tt == LUA_TTABLE); in luaC_barrierback_()
159 gco2t(o)->gclist = g->grayagain; in luaC_barrierback_()
160 g->grayagain = o; in luaC_barrierback_()
173 global_State *g = G(L); in luaC_barrierproto_() local
180 p->gclist = g->grayagain; in luaC_barrierproto_()
181 g->grayagain = obj2gco(p); in luaC_barrierproto_()
190 void luaC_checkupvalcolor (global_State *g, UpVal *uv) { in luaC_checkupvalcolor() argument
194 if (keepinvariant(g)) { in luaC_checkupvalcolor()
197 markvalue(g, uv->v); in luaC_checkupvalcolor()
200 lua_assert(issweepphase(g)); in luaC_checkupvalcolor()
201 makewhite(g, o); in luaC_checkupvalcolor()
214 global_State *g = G(L); in luaC_newobj() local
218 list = &g->allgc; /* standard list for collectable objects */ in luaC_newobj()
219 gch(o)->marked = luaC_white(g); in luaC_newobj()
243 static void reallymarkobject (global_State *g, GCObject *o) { in reallymarkobject() argument
254 markobject(g, mt); in reallymarkobject()
255 markobject(g, gco2u(o)->env); in reallymarkobject()
261 markvalue(g, uv->v); in reallymarkobject()
268 gco2lcl(o)->gclist = g->gray; in reallymarkobject()
269 g->gray = o; in reallymarkobject()
273 gco2ccl(o)->gclist = g->gray; in reallymarkobject()
274 g->gray = o; in reallymarkobject()
278 linktable(gco2t(o), &g->gray); in reallymarkobject()
282 gco2th(o)->gclist = g->gray; in reallymarkobject()
283 g->gray = o; in reallymarkobject()
287 gco2p(o)->gclist = g->gray; in reallymarkobject()
288 g->gray = o; in reallymarkobject()
294 g->GCmemtrav += size; in reallymarkobject()
301 static void markmt (global_State *g) { in markmt() argument
304 markobject(g, g->mt[i]); in markmt()
311 static void markbeingfnz (global_State *g) { in markbeingfnz() argument
313 for (o = g->tobefnz; o != NULL; o = gch(o)->next) { in markbeingfnz()
314 makewhite(g, o); in markbeingfnz()
315 reallymarkobject(g, o); in markbeingfnz()
324 static void remarkupvals (global_State *g) { in remarkupvals() argument
326 for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) { in remarkupvals()
328 markvalue(g, uv->v); 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()
355 static void traverseweakvalue (global_State *g, Table *h) { in traverseweakvalue() argument
366 markvalue(g, gkey(n)); /* mark key */ in traverseweakvalue()
367 if (!hasclears && iscleared(g, gval(n))) /* is there a white value? */ in traverseweakvalue()
372 linktable(h, &g->weak); /* has to be cleared later */ in traverseweakvalue()
374 linktable(h, &g->grayagain); /* no need to clean */ in traverseweakvalue()
378 static int traverseephemeron (global_State *g, Table *h) { in traverseephemeron() argument
388 reallymarkobject(g, gcvalue(&h->array[i])); in traverseephemeron()
396 else if (iscleared(g, gkey(n))) { /* key is not marked (yet)? */ in traverseephemeron()
403 reallymarkobject(g, gcvalue(gval(n))); /* mark it now */ in traverseephemeron()
407 linktable(h, &g->ephemeron); /* have to propagate again */ in traverseephemeron()
409 linktable(h, &g->allweak); /* may have to clean white keys */ in traverseephemeron()
411 linktable(h, &g->grayagain); /* no need to clean */ in traverseephemeron()
416 static void traversestrongtable (global_State *g, Table *h) { in traversestrongtable() argument
420 markvalue(g, &h->array[i]); in traversestrongtable()
427 markvalue(g, gkey(n)); /* mark key */ in traversestrongtable()
428 markvalue(g, gval(n)); /* mark value */ in traversestrongtable()
434 static lu_mem traversetable (global_State *g, Table *h) { in traversetable() argument
436 const TValue *mode = gfasttm(g, h->metatable, TM_MODE); in traversetable()
437 markobject(g, h->metatable); in traversetable()
444 traverseweakvalue(g, h); in traversetable()
446 traverseephemeron(g, h); in traversetable()
448 linktable(h, &g->allweak); /* nothing to traverse now */ in traversetable()
451 traversestrongtable(g, h); in traversetable()
457 static int traverseproto (global_State *g, Proto *f) { in traverseproto() argument
461 markobject(g, f->source); in traverseproto()
463 markvalue(g, &f->k[i]); in traverseproto()
465 markobject(g, f->upvalues[i].name); in traverseproto()
467 markobject(g, f->p[i]); in traverseproto()
469 markobject(g, f->locvars[i].varname); in traverseproto()
479 static lu_mem traverseCclosure (global_State *g, CClosure *cl) { in traverseCclosure() argument
482 markvalue(g, &cl->upvalue[i]); in traverseCclosure()
486 static lu_mem traverseLclosure (global_State *g, LClosure *cl) { in traverseLclosure() argument
488 markobject(g, cl->p); /* mark its prototype */ in traverseLclosure()
490 markobject(g, cl->upvals[i]); in traverseLclosure()
495 static lu_mem traversestack (global_State *g, lua_State *th) { in traversestack() argument
501 markvalue(g, o); in traversestack()
502 if (g->gcstate == GCSatomic) { /* final traversal? */ in traversestack()
521 static void propagatemark (global_State *g) { in propagatemark() argument
523 GCObject *o = g->gray; in propagatemark()
529 g->gray = h->gclist; /* remove from 'gray' list */ in propagatemark()
530 size = traversetable(g, h); in propagatemark()
535 g->gray = cl->gclist; /* remove from 'gray' list */ in propagatemark()
536 size = traverseLclosure(g, cl); in propagatemark()
541 g->gray = cl->gclist; /* remove from 'gray' list */ in propagatemark()
542 size = traverseCclosure(g, cl); in propagatemark()
547 g->gray = th->gclist; /* remove from 'gray' list */ in propagatemark()
548 th->gclist = g->grayagain; in propagatemark()
549 g->grayagain = o; /* insert into 'grayagain' list */ in propagatemark()
551 size = traversestack(g, th); in propagatemark()
556 g->gray = p->gclist; /* remove from 'gray' list */ in propagatemark()
557 size = traverseproto(g, p); in propagatemark()
562 g->GCmemtrav += size; in propagatemark()
566 static void propagateall (global_State *g) { in propagateall() argument
567 while (g->gray) propagatemark(g); in propagateall()
571 static void propagatelist (global_State *g, GCObject *l) { in propagatelist() argument
572 lua_assert(g->gray == NULL); /* no grays left */ in propagatelist()
573 g->gray = l; in propagatelist()
574 propagateall(g); /* traverse all elements from 'l' */ in propagatelist()
582 static void retraversegrays (global_State *g) { in retraversegrays() argument
583 GCObject *weak = g->weak; /* save original lists */ in retraversegrays()
584 GCObject *grayagain = g->grayagain; in retraversegrays()
585 GCObject *ephemeron = g->ephemeron; in retraversegrays()
586 g->weak = g->grayagain = g->ephemeron = NULL; in retraversegrays()
587 propagateall(g); /* traverse main gray list */ in retraversegrays()
588 propagatelist(g, grayagain); in retraversegrays()
589 propagatelist(g, weak); in retraversegrays()
590 propagatelist(g, ephemeron); in retraversegrays()
594 static void convergeephemerons (global_State *g) { in convergeephemerons() argument
598 GCObject *next = g->ephemeron; /* get ephemeron list */ in convergeephemerons()
599 g->ephemeron = NULL; /* tables will return to this list when traversed */ in convergeephemerons()
603 if (traverseephemeron(g, gco2t(w))) { /* traverse marked some value? */ in convergeephemerons()
604 propagateall(g); /* propagate changes */ in convergeephemerons()
625 static void clearkeys (global_State *g, GCObject *l, GCObject *f) { in clearkeys() argument
630 if (!ttisnil(gval(n)) && (iscleared(g, gkey(n)))) { in clearkeys()
643 static void clearvalues (global_State *g, GCObject *l, GCObject *f) { in clearvalues() argument
650 if (iscleared(g, o)) /* value was collected? */ in clearvalues()
654 if (!ttisnil(gval(n)) && iscleared(g, gval(n))) { in clearvalues()
720 global_State *g = G(L); in sweeplist() local
721 int ow = otherwhite(g); in sweeplist()
724 if (isgenerational(g)) { /* generational mode? */ in sweeplist()
731 toset = luaC_white(g); /* make object white */ in sweeplist()
779 global_State *g = G(L); in checkSizes() local
780 if (g->gckind != KGC_EMERGENCY) { /* do not change sizes in emergency */ in checkSizes()
781 int hs = g->strt.size / 2; /* half the size of the string table */ in checkSizes()
782 if (g->strt.nuse < cast(lu_int32, hs)) /* using less than that half? */ in checkSizes()
784 luaZ_freebuffer(L, &g->buff); /* free concatenation buffer */ in checkSizes()
789 static GCObject *udata2finalize (global_State *g) { in udata2finalize() argument
790 GCObject *o = g->tobefnz; /* get first element */ in udata2finalize()
792 g->tobefnz = gch(o)->next; /* remove it from 'tobefnz' list */ in udata2finalize()
793 gch(o)->next = g->allgc; /* return it to 'allgc' list */ in udata2finalize()
794 g->allgc = o; in udata2finalize()
797 if (!keepinvariantout(g)) /* not keeping invariant? */ in udata2finalize()
798 makewhite(g, o); /* "sweep" object */ in udata2finalize()
810 global_State *g = G(L); in GCTM() local
813 setgcovalue(L, &v, udata2finalize(g)); in GCTM()
818 int running = g->gcrunning; in GCTM()
820 g->gcrunning = 0; /* avoid GC steps */ in GCTM()
826 g->gcrunning = running; /* restore state */ in GCTM()
846 global_State *g = G(L); in separatetobefnz() local
847 GCObject **p = &g->finobj; in separatetobefnz()
849 GCObject **lastnext = &g->tobefnz; in separatetobefnz()
874 global_State *g = G(L); in luaC_checkfinalizer() local
877 gfasttm(g, mt, TM_GC) == NULL) /* or has no finalizer? */ in luaC_checkfinalizer()
882 if (g->sweepgc == &ho->next) { /* avoid removing current sweep object */ in luaC_checkfinalizer()
883 lua_assert(issweepphase(g)); in luaC_checkfinalizer()
884 g->sweepgc = sweeptolive(L, g->sweepgc, NULL); in luaC_checkfinalizer()
887 for (p = &g->allgc; *p != o; p = &gch(*p)->next) { /* empty */ } in luaC_checkfinalizer()
889 ho->next = g->finobj; /* link it in list 'finobj' */ in luaC_checkfinalizer()
890 g->finobj = o; in luaC_checkfinalizer()
892 if (!keepinvariantout(g)) /* not keeping invariant? */ in luaC_checkfinalizer()
893 makewhite(g, o); /* "sweep" object */ in luaC_checkfinalizer()
913 static void setpause (global_State *g, l_mem estimate) { in setpause() argument
916 threshold = (g->gcpause < MAX_LMEM / estimate) /* overflow? */ in setpause()
917 ? estimate * g->gcpause /* no overflow */ in setpause()
919 debt = -cast(l_mem, threshold - gettotalbytes(g)); in setpause()
920 luaE_setdebt(g, debt); in setpause()
937 global_State *g = G(L); in entersweep() local
939 g->gcstate = GCSsweepstring; in entersweep()
940 lua_assert(g->sweepgc == NULL && g->sweepfin == NULL); in entersweep()
942 g->sweepstrgc = 0; in entersweep()
943 g->sweepfin = sweeptolive(L, &g->finobj, &n); in entersweep()
944 g->sweepgc = sweeptolive(L, &g->allgc, &n); in entersweep()
953 global_State *g = G(L); in luaC_changemode() local
954 if (mode == g->gckind) return; /* nothing to change */ in luaC_changemode()
958 g->GCestimate = gettotalbytes(g); in luaC_changemode()
959 g->gckind = KGC_GEN; in luaC_changemode()
964 g->gckind = KGC_NORMAL; in luaC_changemode()
975 global_State *g = G(L); in callallpendingfinalizers() local
976 while (g->tobefnz) { in callallpendingfinalizers()
977 resetoldbit(g->tobefnz); in callallpendingfinalizers()
984 global_State *g = G(L); in luaC_freeallobjects() local
987 lua_assert(g->finobj == NULL); in luaC_freeallobjects()
989 g->currentwhite = WHITEBITS; /* this "white" makes all objects look dead */ in luaC_freeallobjects()
990 g->gckind = KGC_NORMAL; in luaC_freeallobjects()
991 sweepwholelist(L, &g->finobj); /* finalizers can create objs. in 'finobj' */ in luaC_freeallobjects()
992 sweepwholelist(L, &g->allgc); in luaC_freeallobjects()
993 for (i = 0; i < g->strt.size; i++) /* free all string lists */ in luaC_freeallobjects()
994 sweepwholelist(L, &g->strt.hash[i]); in luaC_freeallobjects()
995 lua_assert(g->strt.nuse == 0); in luaC_freeallobjects()
1000 global_State *g = G(L); in atomic() local
1001 l_mem work = -cast(l_mem, g->GCmemtrav); /* start counting work */ in atomic()
1003 lua_assert(!iswhite(obj2gco(g->mainthread))); in atomic()
1004 markobject(g, L); /* mark running thread */ in atomic()
1006 markvalue(g, &g->l_registry); in atomic()
1007 markmt(g); /* mark basic metatables */ in atomic()
1009 remarkupvals(g); in atomic()
1010 propagateall(g); /* propagate changes */ in atomic()
1011 work += g->GCmemtrav; /* stop counting (do not (re)count grays) */ in atomic()
1013 retraversegrays(g); in atomic()
1014 work -= g->GCmemtrav; /* restart counting */ in atomic()
1015 convergeephemerons(g); in atomic()
1018 clearvalues(g, g->weak, NULL); in atomic()
1019 clearvalues(g, g->allweak, NULL); in atomic()
1020 origweak = g->weak; origall = g->allweak; in atomic()
1021 work += g->GCmemtrav; /* stop counting (objects being finalized) */ in atomic()
1023 markbeingfnz(g); /* mark objects that will be finalized */ in atomic()
1024 propagateall(g); /* remark, to propagate `preserveness' */ in atomic()
1025 work -= g->GCmemtrav; /* restart counting */ in atomic()
1026 convergeephemerons(g); in atomic()
1029 clearkeys(g, g->ephemeron, NULL); /* clear keys from all ephemeron tables */ in atomic()
1030 clearkeys(g, g->allweak, NULL); /* clear keys from all allweak tables */ in atomic()
1032 clearvalues(g, g->weak, origweak); in atomic()
1033 clearvalues(g, g->allweak, origall); in atomic()
1034 g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */ in atomic()
1035 work += g->GCmemtrav; /* complete counting */ in atomic()
1041 global_State *g = G(L); in singlestep() local
1042 switch (g->gcstate) { in singlestep()
1045 g->GCmemtrav = g->strt.size * sizeof(GCObject*); in singlestep()
1046 lua_assert(!isgenerational(g)); in singlestep()
1047 restartcollection(g); in singlestep()
1048 g->gcstate = GCSpropagate; in singlestep()
1049 return g->GCmemtrav; in singlestep()
1052 if (g->gray) { in singlestep()
1053 lu_mem oldtrav = g->GCmemtrav; in singlestep()
1054 propagatemark(g); in singlestep()
1055 return g->GCmemtrav - oldtrav; /* memory traversed in this step */ in singlestep()
1060 g->gcstate = GCSatomic; /* finish mark phase */ in singlestep()
1061 g->GCestimate = g->GCmemtrav; /* save what was counted */; in singlestep()
1063 g->GCestimate += work; /* estimate of total memory traversed */ in singlestep()
1070 for (i = 0; i < GCSWEEPMAX && g->sweepstrgc + i < g->strt.size; i++) in singlestep()
1071 sweepwholelist(L, &g->strt.hash[g->sweepstrgc + i]); in singlestep()
1072 g->sweepstrgc += i; in singlestep()
1073 if (g->sweepstrgc >= g->strt.size) /* no more strings to sweep? */ in singlestep()
1074 g->gcstate = GCSsweepudata; in singlestep()
1078 if (g->sweepfin) { in singlestep()
1079 g->sweepfin = sweeplist(L, g->sweepfin, GCSWEEPMAX); in singlestep()
1083 g->gcstate = GCSsweep; in singlestep()
1088 if (g->sweepgc) { in singlestep()
1089 g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); in singlestep()
1094 GCObject *mt = obj2gco(g->mainthread); in singlestep()
1097 g->gcstate = GCSpause; /* finish collection */ in singlestep()
1111 global_State *g = G(L); in luaC_runtilstate() local
1112 while (!testbit(statesmask, g->gcstate)) in luaC_runtilstate()
1118 global_State *g = G(L); in generationalcollection() local
1119 lua_assert(g->gcstate == GCSpropagate); in generationalcollection()
1120 if (g->GCestimate == 0) { /* signal for another major collection? */ in generationalcollection()
1122 g->GCestimate = gettotalbytes(g); /* update control */ in generationalcollection()
1125 lu_mem estimate = g->GCestimate; in generationalcollection()
1127 g->gcstate = GCSpropagate; /* skip restart */ in generationalcollection()
1128 if (gettotalbytes(g) > (estimate / 100) * g->gcmajorinc) in generationalcollection()
1129 g->GCestimate = 0; /* signal for a major collection */ in generationalcollection()
1131 g->GCestimate = estimate; /* keep estimate from last major coll. */ in generationalcollection()
1134 setpause(g, gettotalbytes(g)); in generationalcollection()
1135 lua_assert(g->gcstate == GCSpropagate); in generationalcollection()
1140 global_State *g = G(L); in incstep() local
1141 l_mem debt = g->GCdebt; in incstep()
1142 int stepmul = g->gcstepmul; in incstep()
1150 } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause); in incstep()
1151 if (g->gcstate == GCSpause) in incstep()
1152 setpause(g, g->GCestimate); /* pause until next cycle */ in incstep()
1155 luaE_setdebt(g, debt); in incstep()
1164 global_State *g = G(L); in luaC_forcestep() local
1166 if (isgenerational(g)) generationalcollection(L); in luaC_forcestep()
1169 for (i = 0; g->tobefnz && (i < GCFINALIZENUM || g->gcstate == GCSpause); i++) in luaC_forcestep()
1178 global_State *g = G(L); in luaC_step() local
1179 if (g->gcrunning) luaC_forcestep(L); in luaC_step()
1180 else luaE_setdebt(g, -GCSTEPSIZE); /* avoid being called too often */ in luaC_step()
1190 global_State *g = G(L); in luaC_fullgc() local
1191 int origkind = g->gckind; in luaC_fullgc()
1194 g->gckind = KGC_EMERGENCY; in luaC_fullgc()
1196 g->gckind = KGC_NORMAL; in luaC_fullgc()
1199 if (keepinvariant(g)) { /* may there be some black objects? */ in luaC_fullgc()
1212 g->gckind = origkind; in luaC_fullgc()
1213 setpause(g, gettotalbytes(g)); in luaC_fullgc()