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

Go to the source code of this file.

Macros

#define GCSpause   0
 
#define GCSpropagate   1
 
#define GCSsweepstring   2
 
#define GCSsweep   3
 
#define GCSfinalize   4
 
#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 set2bits(x, b1, b2)   setbits(x, (bit2mask(b1, b2)))
 
#define reset2bits(x, b1, b2)   resetbits(x, (bit2mask(b1, b2)))
 
#define test2bits(x, b1, b2)   testbits(x, (bit2mask(b1, b2)))
 
#define WHITE0BIT   0
 
#define WHITE1BIT   1
 
#define BLACKBIT   2
 
#define FINALIZEDBIT   3
 
#define KEYWEAKBIT   3
 
#define VALUEWEAKBIT   4
 
#define FIXEDBIT   5
 
#define SFIXEDBIT   6
 
#define WHITEBITS   bit2mask(WHITE0BIT, WHITE1BIT)
 
#define iswhite(x)   test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
 
#define isblack(x)   testbit((x)->gch.marked, BLACKBIT)
 
#define isgray(x)   (!isblack(x) && !iswhite(x))
 
#define otherwhite(g)   (g->currentwhite ^ WHITEBITS)
 
#define isdead(g, v)   ((v)->gch.marked & otherwhite(g) & WHITEBITS)
 
#define changewhite(x)   ((x)->gch.marked ^= WHITEBITS)
 
#define gray2black(x)   l_setbit((x)->gch.marked, BLACKBIT)
 
#define valiswhite(x)   (iscollectable(x) && iswhite(gcvalue(x)))
 
#define luaC_white(g)   cast(lu_byte, (g)->currentwhite & WHITEBITS)
 
#define luaC_checkGC(L)
 
#define luaC_barrier(L, p, v)
 
#define luaC_barriert(L, t, v)
 
#define luaC_objbarrier(L, p, o)
 
#define luaC_objbarriert(L, t, o)    { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }
 

Functions

LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all)
 
LUAI_FUNC void luaC_callGCTM (lua_State *L)
 
LUAI_FUNC void luaC_freeall (lua_State *L)
 
LUAI_FUNC void luaC_step (lua_State *L)
 
LUAI_FUNC void luaC_fullgc (lua_State *L)
 
LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt)
 
LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv)
 
LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v)
 
LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t)
 

Macro Definition Documentation

◆ bit2mask

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

Definition at line 31 of file lua-5.1.5/src/lgc.h.

Referenced by lua_newstate().

◆ bitmask

◆ BLACKBIT

#define BLACKBIT   2

Definition at line 56 of file lua-5.1.5/src/lgc.h.

◆ changewhite

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

◆ FINALIZEDBIT

#define FINALIZEDBIT   3

◆ FIXEDBIT

#define FIXEDBIT   5

Definition at line 60 of file lua-5.1.5/src/lgc.h.

Referenced by lua_newstate(), and sweeplist().

◆ GCSfinalize

#define GCSfinalize   4

◆ GCSpause

◆ GCSpropagate

◆ GCSsweep

#define GCSsweep   3

Definition at line 20 of file lua-5.1.5/src/lgc.h.

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

◆ GCSsweepstring

#define GCSsweepstring   2

Definition at line 19 of file lua-5.1.5/src/lgc.h.

Referenced by atomic(), entersweep(), luaC_fullgc(), luaS_resize(), singlestep(), and singlestep().

◆ gray2black

◆ isblack

◆ isdead

◆ isgray

◆ iswhite

◆ KEYWEAKBIT

#define KEYWEAKBIT   3

Definition at line 58 of file lua-5.1.5/src/lgc.h.

Referenced by cleartable(), and traversetable().

◆ l_setbit

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

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

Referenced by luaC_checkfinalizer(), and separatetobefnz().

◆ luaC_barrier

#define luaC_barrier ( L,
p,
v )
Value:
{ if (valiswhite(v) && isblack(obj2gco(p))) \
luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
#define valiswhite(x)
#define isblack(x)
#define gcvalue(o)
#define obj2gco(v)

Definition at line 86 of file lua-5.1.5/src/lgc.h.

86#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \
87 luaC_barrierf(L,obj2gco(p),gcvalue(v)); }

Referenced by addk(), addk(), addk(), addk(), lua_copy(), lua_load(), lua_replace(), lua_setupvalue(), lua_setuservalue(), luaC_linkupval(), luaF_closeupval(), luaV_execute(), luaV_execute(), luaV_execute(), and moveto().

◆ luaC_barriert

#define luaC_barriert ( L,
t,
v )
Value:
{ if (valiswhite(v) && isblack(obj2gco(t))) \
luaC_barrierback(L,t); }

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

89#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \
90 luaC_barrierback(L,t); }

Referenced by lua_rawset(), lua_rawseti(), luaV_execute(), luaV_settable(), and newkey().

◆ luaC_checkGC

#define luaC_checkGC ( L)
Value:
{ \
condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \
if (G(L)->totalbytes >= G(L)->GCthreshold) \
luaC_step(L); }
void luaD_reallocstack(lua_State *L, int newsize)
#define G(L)
#define EXTRA_STACK

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

80#define luaC_checkGC(L) { \
81 condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \
82 if (G(L)->totalbytes >= G(L)->GCthreshold) \
83 luaC_step(L); }

Referenced by adjust_varargs(), close_func(), close_func(), close_func(), f_parser(), lua_concat(), lua_createtable(), lua_gc(), lua_gc(), lua_newthread(), lua_newuserdata(), lua_newuserdatauv(), lua_pushcclosure(), lua_pushfstring(), lua_pushlstring(), lua_pushstring(), lua_pushvfstring(), lua_tolstring(), luaD_call(), luaD_precall(), luaG_runerror(), luaV_execute(), and luaX_newstring().

◆ luaC_objbarrier

#define luaC_objbarrier ( L,
p,
o )

◆ luaC_objbarriert

#define luaC_objbarriert ( L,
t,
o )    { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }

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

96#define luaC_objbarriert(L,t,o) \
97 { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }

Referenced by lua_setmetatable().

◆ luaC_white

◆ otherwhite

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

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

Referenced by atomic(), atomic(), atomic(), atomic(), sweeplist(), sweeplist(), sweeplist(), and sweeplist().

◆ reset2bits

#define reset2bits ( x,
b1,
b2 )   resetbits(x, (bit2mask(b1, b2)))

Definition at line 36 of file lua-5.1.5/src/lgc.h.

◆ resetbit

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

Definition at line 33 of file lua-5.1.5/src/lgc.h.

Referenced by udata2finalize(), udata2finalize(), and udata2finalize().

◆ resetbits

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

Definition at line 27 of file lua-5.1.5/src/lgc.h.

◆ set2bits

#define set2bits ( x,
b1,
b2 )   setbits(x, (bit2mask(b1, b2)))

Definition at line 35 of file lua-5.1.5/src/lgc.h.

Referenced by lua_newstate().

◆ setbits

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

Definition at line 28 of file lua-5.1.5/src/lgc.h.

◆ SFIXEDBIT

#define SFIXEDBIT   6

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

Referenced by lua_newstate(), luaC_freeall(), and sweeplist().

◆ test2bits

#define test2bits ( x,
b1,
b2 )   testbits(x, (bit2mask(b1, b2)))

Definition at line 37 of file lua-5.1.5/src/lgc.h.

◆ testbit

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

◆ testbits

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

Definition at line 29 of file lua-5.1.5/src/lgc.h.

Referenced by sweeplist().

◆ valiswhite

#define valiswhite ( x)    (iscollectable(x) && iswhite(gcvalue(x)))

Definition at line 75 of file lua-5.1.5/src/lgc.h.

Referenced by removeentry(), and traverseephemeron().

◆ VALUEWEAKBIT

#define VALUEWEAKBIT   4

Definition at line 59 of file lua-5.1.5/src/lgc.h.

Referenced by cleartable(), and traversetable().

◆ WHITE0BIT

#define WHITE0BIT   0

Definition at line 54 of file lua-5.1.5/src/lgc.h.

Referenced by lua_newstate().

◆ WHITE1BIT

#define WHITE1BIT   1

Definition at line 55 of file lua-5.1.5/src/lgc.h.

◆ WHITEBITS

#define WHITEBITS   bit2mask(WHITE0BIT, WHITE1BIT)

Definition at line 62 of file lua-5.1.5/src/lgc.h.

Referenced by luaC_freeall(), luaC_freeallobjects(), and sweeplist().

Function Documentation

◆ luaC_barrierback()

LUAI_FUNC void luaC_barrierback ( lua_State * L,
Table * t )

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

674 {
675 global_State *g = G(L);
676 GCObject *o = obj2gco(t);
677 lua_assert(isblack(o) && !isdead(g, o));
679 black2gray(o); /* make table gray (again) */
680 t->gclist = g->grayagain;
681 g->grayagain = o;
682}
#define black2gray(x)
#define GCSpause
#define GCSfinalize
#define isdead(g, v)
#define lua_assert(c)
GCObject * gclist

References black2gray, G, Table::gclist, GCSfinalize, GCSpause, global_State::gcstate, global_State::grayagain, isblack, isdead, lua_assert, and obj2gco.

◆ luaC_barrierf()

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

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

661 {
662 global_State *g = G(L);
663 lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
666 /* must keep invariant? */
667 if (g->gcstate == GCSpropagate)
668 reallymarkobject(g, v); /* restore invariant */
669 else /* don't mind */
670 makewhite(g, o); /* mark as white just to avoid other barriers */
671}
static void reallymarkobject(global_State *g, GCObject *o)
#define makewhite(g, x)
#define GCSpropagate
#define ttype(o)
#define LUA_TTABLE

References G, GCObject::gch, GCSfinalize, GCSpause, GCSpropagate, global_State::gcstate, isblack, isdead, iswhite, lua_assert, LUA_TTABLE, makewhite, reallymarkobject(), and ttype.

◆ luaC_callGCTM()

LUAI_FUNC void luaC_callGCTM ( lua_State * L)

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

477 {
478 while (G(L)->tmudata)
479 GCTM(L);
480}
static void GCTM(lua_State *L)

References G, and GCTM().

Referenced by callallgcTM().

◆ luaC_freeall()

LUAI_FUNC void luaC_freeall ( lua_State * L)

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

483 {
484 global_State *g = G(L);
485 int i;
486 g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT); /* mask to collect all elements */
487 sweepwholelist(L, &g->rootgc);
488 for (i = 0; i < g->strt.size; i++) /* free all string lists */
489 sweepwholelist(L, &g->strt.hash[i]);
490}
#define sweepwholelist(L, p)
#define WHITEBITS
#define SFIXEDBIT
#define bitmask(b)

References bitmask, global_State::currentwhite, G, stringtable::hash, global_State::rootgc, SFIXEDBIT, stringtable::size, global_State::strt, sweepwholelist, and WHITEBITS.

Referenced by close_state().

◆ luaC_fullgc()

LUAI_FUNC void luaC_fullgc ( lua_State * L)

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

635 {
636 global_State *g = G(L);
637 if (g->gcstate <= GCSpropagate) {
638 /* reset sweep marks to sweep all elements (returning them to white) */
639 g->sweepstrgc = 0;
640 g->sweepgc = &g->rootgc;
641 /* reset other collector lists */
642 g->gray = NULL;
643 g->grayagain = NULL;
644 g->weak = NULL;
646 }
648 /* finish any pending sweep phase */
649 while (g->gcstate != GCSfinalize) {
651 singlestep(L);
652 }
653 markroot(L);
654 while (g->gcstate != GCSpause) {
655 singlestep(L);
656 }
657 setthreshold(g);
658}
#define NULL
Definition gmacros.h:924
static void markroot(lua_State *L)
static l_mem singlestep(lua_State *L)
#define setthreshold(g)
#define GCSsweep
#define GCSsweepstring

References G, GCSfinalize, GCSpause, GCSpropagate, GCSsweep, GCSsweepstring, global_State::gcstate, global_State::gray, global_State::grayagain, lua_assert, markroot(), NULL, global_State::rootgc, setthreshold, singlestep(), global_State::sweepgc, global_State::sweepstrgc, and global_State::weak.

Referenced by growstrtab(), lua_gc(), lua_gc(), luaM_realloc_(), and tryagain().

◆ luaC_link()

LUAI_FUNC void luaC_link ( lua_State * L,
GCObject * o,
lu_byte tt )

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

685 {
686 global_State *g = G(L);
687 o->gch.next = g->rootgc;
688 g->rootgc = o;
689 o->gch.marked = luaC_white(g);
690 o->gch.tt = tt;
691}
#define luaC_white(g)

References G, GCObject::gch, luaC_white, and global_State::rootgc.

Referenced by luaE_newthread(), luaF_newCclosure(), luaF_newLclosure(), luaF_newproto(), luaF_newupval(), and luaH_new().

◆ luaC_linkupval()

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

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

694 {
695 global_State *g = G(L);
696 GCObject *o = obj2gco(uv);
697 o->gch.next = g->rootgc; /* link upvalue into `rootgc' list */
698 g->rootgc = o;
699 if (isgray(o)) {
700 if (g->gcstate == GCSpropagate) {
701 gray2black(o); /* closed upvalues need barrier */
702 luaC_barrier(L, uv, uv->v);
703 }
704 else { /* sweep phase: sweep it (turning it into white) */
705 makewhite(g, o);
707 }
708 }
709}
#define luaC_barrier(L, p, v)
#define isgray(x)
#define gray2black(x)

References G, GCObject::gch, GCSfinalize, GCSpause, GCSpropagate, global_State::gcstate, gray2black, isgray, lua_assert, luaC_barrier, makewhite, obj2gco, global_State::rootgc, and UpVal::v.

Referenced by luaF_close().

◆ luaC_separateudata()

LUAI_FUNC size_t luaC_separateudata ( lua_State * L,
int all )

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

128 {
129 global_State *g = G(L);
130 size_t deadmem = 0;
131 GCObject **p = &g->mainthread->next;
132 GCObject *curr;
133 while ((curr = *p) != NULL) {
134 if (!(iswhite(curr) || all) || isfinalized(gco2u(curr)))
135 p = &curr->gch.next; /* don't bother with them */
136 else if (fasttm(L, gco2u(curr)->metatable, TM_GC) == NULL) {
137 markfinalized(gco2u(curr)); /* don't need finalization */
138 p = &curr->gch.next;
139 }
140 else { /* must call its gc method */
141 deadmem += sizeudata(gco2u(curr));
142 markfinalized(gco2u(curr));
143 *p = curr->gch.next;
144 /* link `curr' at the end of `tmudata' list */
145 if (g->tmudata == NULL) /* list is empty? */
146 g->tmudata = curr->gch.next = curr; /* creates a circular list */
147 else {
148 curr->gch.next = g->tmudata->gch.next;
149 g->tmudata->gch.next = curr;
150 g->tmudata = curr;
151 }
152 }
153 }
154 return deadmem;
155}
#define isfinalized(u)
#define markfinalized(u)
#define gco2u(o)
#define sizeudata(u)
#define fasttm(l, et, e)
@ TM_GC
struct lua_State * mainthread

References fasttm, G, GCObject::gch, gco2u, isfinalized, iswhite, global_State::mainthread, markfinalized, NULL, sizeudata, TM_GC, and global_State::tmudata.

Referenced by atomic(), and lua_close().

◆ 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}
#define GCSTEPSIZE
#define MAX_LUMEM
LUAI_MEM l_mem