The Battle for Wesnoth  1.17.0-dev
Macros | Functions
lgc.cpp File Reference
#include "lprefix.h"
#include <stdio.h>
#include <string.h>
#include "lua.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lgc.h"
#include "lmem.h"
#include "lobject.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
Include dependency graph for lgc.cpp:

Go to the source code of this file.

Macros

#define lgc_c
 
#define LUA_CORE
 
#define GCSWEEPMAX   100
 
#define GCFINMAX   10
 
#define GCFINALIZECOST   50
 
#define WORK2MEM   sizeof(TValue)
 
#define PAUSEADJ   100
 
#define maskcolors   (bitmask(BLACKBIT) | WHITEBITS)
 
#define maskgcbits   (maskcolors | AGEBITS)
 
#define makewhite(g, x)   (x->marked = cast_byte((x->marked & ~maskcolors) | luaC_white(g)))
 
#define set2gray(x)   resetbits(x->marked, maskcolors)
 
#define set2black(x)   (x->marked = cast_byte((x->marked & ~WHITEBITS) | bitmask(BLACKBIT)))
 
#define valiswhite(x)   (iscollectable(x) && iswhite(gcvalue(x)))
 
#define keyiswhite(n)   (keyiscollectable(n) && iswhite(gckey(n)))
 
#define gcvalueN(o)   (iscollectable(o) ? gcvalue(o) : NULL)
 
#define markvalue(g, o)
 
#define markkey(g, n)   { if keyiswhite(n) reallymarkobject(g,gckey(n)); }
 
#define markobject(g, t)   { if (iswhite(t)) reallymarkobject(g, obj2gco(t)); }
 
#define markobjectN(g, t)   { if (t) markobject(g,t); }
 
#define gnodelast(h)   gnode(h, cast_sizet(sizenode(h)))
 
#define linkgclist(o, p)   linkgclist_(obj2gco(o), &(o)->gclist, &(p))
 
#define linkobjgclist(o, p)   linkgclist_(obj2gco(o), getgclist(o), &(p))
 

Functions

static void reallymarkobject (global_State *g, GCObject *o)
 
static lu_mem atomic (lua_State *L)
 
static void entersweep (lua_State *L)
 
static GCObject ** getgclist (GCObject *o)
 
static void linkgclist_ (GCObject *o, GCObject **pnext, GCObject **list)
 
static void clearkey (Node *n)
 
static int iscleared (global_State *g, const GCObject *o)
 
void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v)
 
void luaC_barrierback_ (lua_State *L, GCObject *o)
 
void luaC_fix (lua_State *L, GCObject *o)
 
GCObjectluaC_newobj (lua_State *L, int tt, size_t sz)
 
static void markmt (global_State *g)
 
static lu_mem markbeingfnz (global_State *g)
 
static int remarkupvals (global_State *g)
 
static void cleargraylists (global_State *g)
 
static void restartcollection (global_State *g)
 
static void genlink (global_State *g, GCObject *o)
 
static void traverseweakvalue (global_State *g, Table *h)
 
static int traverseephemeron (global_State *g, Table *h, int inv)
 
static void traversestrongtable (global_State *g, Table *h)
 
static lu_mem traversetable (global_State *g, Table *h)
 
static int traverseudata (global_State *g, Udata *u)
 
static int traverseproto (global_State *g, Proto *f)
 
static int traverseCclosure (global_State *g, CClosure *cl)
 
static int traverseLclosure (global_State *g, LClosure *cl)
 
static int traversethread (global_State *g, lua_State *th)
 
static lu_mem propagatemark (global_State *g)
 
static lu_mem propagateall (global_State *g)
 
static void convergeephemerons (global_State *g)
 
static void clearbykeys (global_State *g, GCObject *l)
 
static void clearbyvalues (global_State *g, GCObject *l, GCObject *f)
 
static void freeupval (lua_State *L, UpVal *uv)
 
static void freeobj (lua_State *L, GCObject *o)
 
static GCObject ** sweeplist (lua_State *L, GCObject **p, int countin, int *countout)
 
static GCObject ** sweeptolive (lua_State *L, GCObject **p)
 
static void checkSizes (lua_State *L, global_State *g)
 
static GCObjectudata2finalize (global_State *g)
 
static void dothecall (lua_State *L, void *ud)
 
static void GCTM (lua_State *L)
 
static int runafewfinalizers (lua_State *L, int n)
 
static void callallpendingfinalizers (lua_State *L)
 
static GCObject ** findlast (GCObject **p)
 
static void separatetobefnz (global_State *g, int all)
 
static void checkpointer (GCObject **p, GCObject *o)
 
static void correctpointers (global_State *g, GCObject *o)
 
void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt)
 
static void setpause (global_State *g)
 
static void sweep2old (lua_State *L, GCObject **p)
 
static GCObject ** sweepgen (lua_State *L, global_State *g, GCObject **p, GCObject *limit, GCObject **pfirstold1)
 
static void whitelist (global_State *g, GCObject *p)
 
static GCObject ** correctgraylist (GCObject **p)
 
static void correctgraylists (global_State *g)
 
static void markold (global_State *g, GCObject *from, GCObject *to)
 
static void finishgencycle (lua_State *L, global_State *g)
 
static void youngcollection (lua_State *L, global_State *g)
 
static void atomic2gen (lua_State *L, global_State *g)
 
static lu_mem entergen (lua_State *L, global_State *g)
 
static void enterinc (global_State *g)
 
void luaC_changemode (lua_State *L, int newmode)
 
static lu_mem fullgen (lua_State *L, global_State *g)
 
static void setminordebt (global_State *g)
 
static void stepgenfull (lua_State *L, global_State *g)
 
static void genstep (lua_State *L, global_State *g)
 
static void deletelist (lua_State *L, GCObject *p, GCObject *limit)
 
void luaC_freeallobjects (lua_State *L)
 
static int sweepstep (lua_State *L, global_State *g, int nextstate, GCObject **nextlist)
 
static lu_mem singlestep (lua_State *L)
 
void luaC_runtilstate (lua_State *L, int statesmask)
 
static void incstep (lua_State *L, global_State *g)
 
void luaC_step (lua_State *L)
 
static void fullinc (lua_State *L, global_State *g)
 
void luaC_fullgc (lua_State *L, int isemergency)
 

Macro Definition Documentation

◆ GCFINALIZECOST

#define GCFINALIZECOST   50

Definition at line 46 of file lgc.cpp.

Referenced by singlestep().

◆ GCFINMAX

#define GCFINMAX   10

Definition at line 40 of file lgc.cpp.

Referenced by singlestep().

◆ GCSWEEPMAX

#define GCSWEEPMAX   100

Definition at line 35 of file lgc.cpp.

Referenced by sweepstep().

◆ gcvalueN

#define gcvalueN (   o)    (iscollectable(o) ? gcvalue(o) : NULL)

Definition at line 91 of file lgc.cpp.

Referenced by clearbyvalues(), and traverseweakvalue().

◆ gnodelast

#define gnodelast (   h)    gnode(h, cast_sizet(sizenode(h)))

Definition at line 122 of file lgc.cpp.

Referenced by clearbykeys(), clearbyvalues(), traversestrongtable(), and traverseweakvalue().

◆ keyiswhite

#define keyiswhite (   n)    (keyiscollectable(n) && iswhite(gckey(n)))

Definition at line 85 of file lgc.cpp.

◆ lgc_c

#define lgc_c

Definition at line 7 of file lgc.cpp.

◆ linkgclist

#define linkgclist (   o,
  p 
)    linkgclist_(obj2gco(o), &(o)->gclist, &(p))

◆ linkobjgclist

#define linkobjgclist (   o,
  p 
)    linkgclist_(obj2gco(o), getgclist(o), &(p))

Definition at line 159 of file lgc.cpp.

Referenced by genlink(), luaC_barrierback_(), and reallymarkobject().

◆ LUA_CORE

#define LUA_CORE

Definition at line 8 of file lgc.cpp.

◆ makewhite

#define makewhite (   g,
 
)    (x->marked = cast_byte((x->marked & ~maskcolors) | luaC_white(g)))

Definition at line 71 of file lgc.cpp.

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

◆ markkey

#define markkey (   g,
  n 
)    { if keyiswhite(n) reallymarkobject(g,gckey(n)); }

Definition at line 97 of file lgc.cpp.

Referenced by traversestrongtable(), and traverseweakvalue().

◆ markobject

#define markobject (   g,
  t 
)    { if (iswhite(t)) reallymarkobject(g, obj2gco(t)); }

Definition at line 99 of file lgc.cpp.

Referenced by atomic(), iscleared(), markbeingfnz(), restartcollection(), and traversethread().

◆ markobjectN

#define markobjectN (   g,
  t 
)    { if (t) markobject(g,t); }

◆ markvalue

#define markvalue (   g,
 
)
Value:
{ checkliveness(g->mainthread,o); \
#define gcvalue(o)
Definition: lobject.h:283
#define valiswhite(x)
Definition: lgc.cpp:83
static void reallymarkobject(global_State *g, GCObject *o)
Definition: lgc.cpp:291
double g
Definition: astarsearch.cpp:64
#define checkliveness(L, obj)
Definition: lobject.h:104

Definition at line 94 of file lgc.cpp.

Referenced by atomic(), reallymarkobject(), remarkupvals(), restartcollection(), traverseCclosure(), traverseproto(), traversestrongtable(), traversethread(), and traverseudata().

◆ maskcolors

#define maskcolors   (bitmask(BLACKBIT) | WHITEBITS)

Definition at line 64 of file lgc.cpp.

◆ maskgcbits

#define maskgcbits   (maskcolors | AGEBITS)

Definition at line 67 of file lgc.cpp.

Referenced by sweepgen(), sweeplist(), and whitelist().

◆ PAUSEADJ

#define PAUSEADJ   100

Definition at line 60 of file lgc.cpp.

Referenced by setpause().

◆ set2black

#define set2black (   x)    (x->marked = cast_byte((x->marked & ~WHITEBITS) | bitmask(BLACKBIT)))

Definition at line 79 of file lgc.cpp.

Referenced by reallymarkobject().

◆ set2gray

#define set2gray (   x)    resetbits(x->marked, maskcolors)

Definition at line 75 of file lgc.cpp.

Referenced by linkgclist_(), luaC_barrierback_(), luaC_fix(), reallymarkobject(), and sweep2old().

◆ valiswhite

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

Definition at line 83 of file lgc.cpp.

Referenced by traverseephemeron().

◆ WORK2MEM

#define WORK2MEM   sizeof(TValue)

Definition at line 53 of file lgc.cpp.

Referenced by incstep().

Function Documentation

◆ atomic()

static lu_mem atomic ( lua_State L)
static

◆ atomic2gen()

static void atomic2gen ( lua_State L,
global_State g 
)
static

◆ callallpendingfinalizers()

static void callallpendingfinalizers ( lua_State L)
static

Definition at line 942 of file lgc.cpp.

References g, G, GCTM(), and global_State::tobefnz.

Referenced by finishgencycle(), and luaC_freeallobjects().

◆ checkpointer()

static void checkpointer ( GCObject **  p,
GCObject o 
)
static

Definition at line 989 of file lgc.cpp.

Referenced by correctpointers().

◆ checkSizes()

static void checkSizes ( lua_State L,
global_State g 
)
static

◆ clearbykeys()

static void clearbykeys ( global_State g,
GCObject l 
)
static

Definition at line 717 of file lgc.cpp.

References clearkey(), gckeyN, gco2t, gnode, gnodelast, gval, h, iscleared(), isempty, n, and setempty.

Referenced by atomic().

◆ clearbyvalues()

static void clearbyvalues ( global_State g,
GCObject l,
GCObject f 
)
static

Definition at line 736 of file lgc.cpp.

References Table::array, clearkey(), f, gco2t, gcvalueN, gnode, gnodelast, gval, h, i, iscleared(), isempty, luaH_realasize(), n, and setempty.

Referenced by atomic().

◆ cleargraylists()

static void cleargraylists ( global_State g)
static

◆ clearkey()

static void clearkey ( Node n)
static

◆ convergeephemerons()

static void convergeephemerons ( global_State g)
static

Definition at line 683 of file lgc.cpp.

References global_State::ephemeron, Table::gclist, gco2t, h, next, nw2black, propagateall(), traverseephemeron(), and w.

Referenced by atomic().

◆ correctgraylist()

static GCObject** correctgraylist ( GCObject **  p)
static

Definition at line 1145 of file lgc.cpp.

References changeage, curr, G_OLD, G_TOUCHED1, G_TOUCHED2, getage, getgclist(), isgray, isold, iswhite, lua_assert, LUA_VTHREAD, next, nw2black, and p.

Referenced by correctgraylists().

◆ correctgraylists()

static void correctgraylists ( global_State g)
static

◆ correctpointers()

static void correctpointers ( global_State g,
GCObject o 
)
static

◆ deletelist()

static void deletelist ( lua_State L,
GCObject p,
GCObject limit 
)
static

Definition at line 1490 of file lgc.cpp.

References freeobj(), and next.

Referenced by luaC_freeallobjects().

◆ dothecall()

static void dothecall ( lua_State L,
void *  ud 
)
static

Definition at line 893 of file lgc.cpp.

References luaD_callnoyield(), lua_State::top, and UNUSED.

Referenced by GCTM().

◆ entergen()

static lu_mem entergen ( lua_State L,
global_State g 
)
static

Definition at line 1293 of file lgc.cpp.

References atomic(), atomic2gen(), bitmask, GCSpause, GCSpropagate, and luaC_runtilstate().

Referenced by fullgen(), and luaC_changemode().

◆ enterinc()

static void enterinc ( global_State g)
static

◆ entersweep()

static void entersweep ( lua_State L)
static

◆ findlast()

static GCObject** findlast ( GCObject **  p)
static

Definition at line 952 of file lgc.cpp.

References p.

Referenced by separatetobefnz().

◆ finishgencycle()

static void finishgencycle ( lua_State L,
global_State g 
)
static

◆ freeobj()

static void freeobj ( lua_State L,
GCObject o 
)
static

◆ freeupval()

static void freeupval ( lua_State L,
UpVal uv 
)
static

Definition at line 757 of file lgc.cpp.

References luaF_unlinkupval(), luaM_free, and upisopen.

Referenced by freeobj().

◆ fullgen()

static lu_mem fullgen ( lua_State L,
global_State g 
)
static

Definition at line 1338 of file lgc.cpp.

References entergen(), and enterinc().

Referenced by genstep(), and luaC_fullgc().

◆ fullinc()

static void fullinc ( lua_State L,
global_State g 
)
static

◆ GCTM()

static void GCTM ( lua_State L)
static

◆ genlink()

static void genlink ( global_State g,
GCObject o 
)
static

◆ genstep()

static void genstep ( lua_State L,
global_State g 
)
static

◆ getgclist()

static GCObject** getgclist ( GCObject o)
static

◆ incstep()

static void incstep ( lua_State L,
global_State g 
)
static

◆ iscleared()

static int iscleared ( global_State g,
const GCObject o 
)
static

Definition at line 185 of file lgc.cpp.

References iswhite, LUA_TSTRING, markobject, and novariant.

Referenced by clearbykeys(), clearbyvalues(), traverseephemeron(), and traverseweakvalue().

◆ linkgclist_()

static void linkgclist_ ( GCObject o,
GCObject **  pnext,
GCObject **  list 
)
static

Definition at line 148 of file lgc.cpp.

References isgray, lua_assert, and set2gray.

◆ luaC_barrier_()

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

◆ luaC_barrierback_()

void luaC_barrierback_ ( lua_State L,
GCObject o 
)

◆ luaC_changemode()

void luaC_changemode ( lua_State L,
int  newmode 
)

Definition at line 1323 of file lgc.cpp.

References entergen(), enterinc(), G, global_State::gckind, KGC_GEN, and global_State::lastatomic.

Referenced by lua_gc(), and luaC_freeallobjects().

◆ luaC_checkfinalizer()

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

◆ luaC_fix()

void luaC_fix ( lua_State L,
GCObject o 
)

Definition at line 243 of file lgc.cpp.

References global_State::allgc, global_State::fixedgc, g, G, G_OLD, lua_assert, set2gray, and setage.

Referenced by luaS_init(), luaT_init(), and luaX_init().

◆ luaC_freeallobjects()

void luaC_freeallobjects ( lua_State L)

◆ luaC_fullgc()

void luaC_fullgc ( lua_State L,
int  isemergency 
)

Definition at line 1703 of file lgc.cpp.

References fullgen(), fullinc(), G, global_State::gcemergency, global_State::gckind, KGC_INC, and lua_assert.

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

◆ luaC_newobj()

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

◆ luaC_runtilstate()

void luaC_runtilstate ( lua_State L,
int  statesmask 
)

Definition at line 1631 of file lgc.cpp.

References G, global_State::gcstate, singlestep(), and testbit.

Referenced by entergen(), fullinc(), and stepgenfull().

◆ luaC_step()

void luaC_step ( lua_State L)

Definition at line 1666 of file lgc.cpp.

References G, global_State::gcemergency, global_State::gcrunning, genstep(), incstep(), isdecGCmodegen, and lua_assert.

Referenced by lua_gc().

◆ markbeingfnz()

static lu_mem markbeingfnz ( global_State g)
static

Definition at line 339 of file lgc.cpp.

References markobject, and global_State::tobefnz.

Referenced by atomic(), and restartcollection().

◆ markmt()

static void markmt ( global_State g)
static

Definition at line 329 of file lgc.cpp.

References i, LUA_NUMTAGS, markobjectN, and global_State::mt.

Referenced by atomic(), and restartcollection().

◆ markold()

static void markold ( global_State g,
GCObject from,
GCObject to 
)
static

Definition at line 1194 of file lgc.cpp.

References changeage, G_OLD, G_OLD1, getage, isblack, iswhite, lua_assert, p, and reallymarkobject().

Referenced by youngcollection().

◆ propagateall()

static lu_mem propagateall ( global_State g)
static

Definition at line 668 of file lgc.cpp.

References global_State::gray, and propagatemark().

Referenced by atomic(), and convergeephemerons().

◆ propagatemark()

static lu_mem propagatemark ( global_State g)
static

◆ reallymarkobject()

static void reallymarkobject ( global_State g,
GCObject o 
)
static

◆ remarkupvals()

static int remarkupvals ( global_State g)
static

◆ restartcollection()

static void restartcollection ( global_State g)
static

◆ runafewfinalizers()

static int runafewfinalizers ( lua_State L,
int  n 
)
static

Definition at line 930 of file lgc.cpp.

References g, G, GCTM(), i, and global_State::tobefnz.

Referenced by singlestep().

◆ separatetobefnz()

static void separatetobefnz ( global_State g,
int  all 
)
static

◆ setminordebt()

static void setminordebt ( global_State g)
static

Definition at line 1348 of file lgc.cpp.

References cast, global_State::genminormul, gettotalbytes, and luaE_setdebt().

Referenced by genstep(), and stepgenfull().

◆ setpause()

static void setpause ( global_State g)
static

◆ singlestep()

static lu_mem singlestep ( lua_State L)
static

◆ stepgenfull()

static void stepgenfull ( lua_State L,
global_State g 
)
static

◆ sweep2old()

static void sweep2old ( lua_State L,
GCObject **  p 
)
static

◆ sweepgen()

static GCObject** sweepgen ( lua_State L,
global_State g,
GCObject **  p,
GCObject limit,
GCObject **  pfirstold1 
)
static

◆ sweeplist()

static GCObject** sweeplist ( lua_State L,
GCObject **  p,
int  countin,
int *  countout 
)
static

Definition at line 816 of file lgc.cpp.

References cast_byte, curr, freeobj(), g, G, i, isdeadm, luaC_white, maskgcbits, otherwhite, and p.

Referenced by sweepstep(), and sweeptolive().

◆ sweepstep()

static int sweepstep ( lua_State L,
global_State g,
int  nextstate,
GCObject **  nextlist 
)
static

◆ sweeptolive()

static GCObject** sweeptolive ( lua_State L,
GCObject **  p 
)
static

Definition at line 843 of file lgc.cpp.

References p, and sweeplist().

Referenced by entersweep(), and luaC_checkfinalizer().

◆ traverseCclosure()

static int traverseCclosure ( global_State g,
CClosure cl 
)
static

Definition at line 587 of file lgc.cpp.

References i, markvalue, and CClosure::upvalue.

Referenced by propagatemark().

◆ traverseephemeron()

static int traverseephemeron ( global_State g,
Table h,
int  inv 
)
static

◆ traverseLclosure()

static int traverseLclosure ( global_State g,
LClosure cl 
)
static

Definition at line 598 of file lgc.cpp.

References i, markobjectN, LClosure::p, and LClosure::upvals.

Referenced by propagatemark().

◆ traverseproto()

static int traverseproto ( global_State g,
Proto f 
)
static

◆ traversestrongtable()

static void traversestrongtable ( global_State g,
Table h 
)
static

◆ traversetable()

static lu_mem traversetable ( global_State g,
Table h 
)
static

◆ traversethread()

static int traversethread ( global_State g,
lua_State th 
)
static

◆ traverseudata()

static int traverseudata ( global_State g,
Udata u 
)
static

Definition at line 557 of file lgc.cpp.

References genlink(), i, markobjectN, markvalue, Udata::metatable, Udata::nuvalue, obj2gco, UValue::uv, and Udata::uv.

Referenced by propagatemark().

◆ traverseweakvalue()

static void traverseweakvalue ( global_State g,
Table h 
)
static

◆ udata2finalize()

static GCObject* udata2finalize ( global_State g)
static

◆ whitelist()

static void whitelist ( global_State g,
GCObject p 
)
static

Definition at line 1129 of file lgc.cpp.

References cast_byte, luaC_white, and maskgcbits.

Referenced by enterinc().

◆ youngcollection()

static void youngcollection ( lua_State L,
global_State g 
)
static