The Battle for Wesnoth  1.15.0+dev
Macros | Functions
lgc.cpp File Reference
#include "lprefix.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 GCSinsideatomic   (GCSpause + 1)
 
#define GCSWEEPCOST   ((sizeof(TString) + 4) / 4)
 
#define GCSWEEPMAX   (cast_int((GCSTEPSIZE / GCSWEEPCOST) / 4))
 
#define GCFINALIZECOST   GCSWEEPCOST
 
#define STEPMULADJ   200
 
#define PAUSEADJ   100
 
#define maskcolors   (~(bitmask(BLACKBIT) | WHITEBITS))
 
#define makewhite(g, x)   (x->marked = cast_byte((x->marked & maskcolors) | luaC_white(g)))
 
#define white2gray(x)   resetbits(x->marked, WHITEBITS)
 
#define black2gray(x)   resetbit(x->marked, BLACKBIT)
 
#define valiswhite(x)   (iscollectable(x) && iswhite(gcvalue(x)))
 
#define checkdeadkey(n)   lua_assert(!ttisdeadkey(gkey(n)) || ttisnil(gval(n)))
 
#define checkconsistency(obj)   lua_longassert(!iscollectable(obj) || righttt(obj))
 
#define markvalue(g, o)
 
#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(size_t, sizenode(h)))
 
#define linkgclist(o, p)   ((o)->gclist = (p), (p) = obj2gco(o))
 
#define sweepwholelist(L, p)   sweeplist(L,p,MAX_LUMEM)
 

Functions

static void reallymarkobject (global_State *g, GCObject *o)
 
static void removeentry (Node *n)
 
static int iscleared (global_State *g, const TValue *o)
 
void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v)
 
void luaC_barrierback_ (lua_State *L, Table *t)
 
void luaC_upvalbarrier_ (lua_State *L, UpVal *uv)
 
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 void markbeingfnz (global_State *g)
 
static void remarkupvals (global_State *g)
 
static void restartcollection (global_State *g)
 
static void traverseweakvalue (global_State *g, Table *h)
 
static int traverseephemeron (global_State *g, Table *h)
 
static void traversestrongtable (global_State *g, Table *h)
 
static lu_mem traversetable (global_State *g, Table *h)
 
static int traverseproto (global_State *g, Proto *f)
 
static lu_mem traverseCclosure (global_State *g, CClosure *cl)
 
static lu_mem traverseLclosure (global_State *g, LClosure *cl)
 
static lu_mem traversethread (global_State *g, lua_State *th)
 
static void propagatemark (global_State *g)
 
static void propagateall (global_State *g)
 
static void convergeephemerons (global_State *g)
 
static void clearkeys (global_State *g, GCObject *l, GCObject *f)
 
static void clearvalues (global_State *g, GCObject *l, GCObject *f)
 
void luaC_upvdeccount (lua_State *L, UpVal *uv)
 
static void freeLclosure (lua_State *L, LClosure *cl)
 
static void freeobj (lua_State *L, GCObject *o)
 
static GCObject ** sweeplist (lua_State *L, GCObject **p, lu_mem count)
 
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, int propagateerrors)
 
static int runafewfinalizers (lua_State *L)
 
static void callallpendingfinalizers (lua_State *L)
 
static GCObject ** findlast (GCObject **p)
 
static void separatetobefnz (global_State *g, int all)
 
void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt)
 
static void setpause (global_State *g)
 
static void entersweep (lua_State *L)
 
void luaC_freeallobjects (lua_State *L)
 
static l_mem atomic (lua_State *L)
 
static lu_mem 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 l_mem getdebt (global_State *g)
 
void luaC_step (lua_State *L)
 
void luaC_fullgc (lua_State *L, int isemergency)
 

Macro Definition Documentation

◆ black2gray

#define black2gray (   x)    resetbit(x->marked, BLACKBIT)

Definition at line 71 of file lgc.cpp.

Referenced by luaC_barrierback_(), propagatemark(), and traversetable().

◆ checkconsistency

#define checkconsistency (   obj)    lua_longassert(!iscollectable(obj) || righttt(obj))

Definition at line 79 of file lgc.cpp.

◆ checkdeadkey

#define checkdeadkey (   n)    lua_assert(!ttisdeadkey(gkey(n)) || ttisnil(gval(n)))

Definition at line 76 of file lgc.cpp.

Referenced by traverseephemeron(), traversestrongtable(), and traverseweakvalue().

◆ GCFINALIZECOST

#define GCFINALIZECOST   GCSWEEPCOST

Definition at line 45 of file lgc.cpp.

Referenced by singlestep().

◆ GCSinsideatomic

#define GCSinsideatomic   (GCSpause + 1)

Definition at line 33 of file lgc.cpp.

Referenced by atomic(), traverseLclosure(), and traversethread().

◆ GCSWEEPCOST

#define GCSWEEPCOST   ((sizeof(TString) + 4) / 4)

Definition at line 39 of file lgc.cpp.

Referenced by sweepstep().

◆ GCSWEEPMAX

#define GCSWEEPMAX   (cast_int((GCSTEPSIZE / GCSWEEPCOST) / 4))

Definition at line 42 of file lgc.cpp.

Referenced by sweepstep().

◆ gnodelast

#define gnodelast (   h)    gnode(h, cast(size_t, sizenode(h)))

◆ lgc_c

#define lgc_c

Definition at line 7 of file lgc.cpp.

◆ linkgclist

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

◆ 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 67 of file lgc.cpp.

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

◆ markobject

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

Definition at line 86 of file lgc.cpp.

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

◆ markobjectN

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

Definition at line 92 of file lgc.cpp.

Referenced by markmt(), reallymarkobject(), traverseLclosure(), traverseproto(), and traversetable().

◆ markvalue

#define markvalue (   g,
 
)
Value:
#define gcvalue(o)
Definition: lobject.h:167
#define checkconsistency(obj)
Definition: lgc.cpp:79
#define valiswhite(x)
Definition: lgc.cpp:74
static void reallymarkobject(global_State *g, GCObject *o)
Definition: lgc.cpp:235
double g
Definition: astarsearch.cpp:64

Definition at line 83 of file lgc.cpp.

Referenced by atomic(), remarkupvals(), restartcollection(), traverseCclosure(), traverseLclosure(), traverseproto(), traversestrongtable(), traversethread(), and traverseweakvalue().

◆ maskcolors

#define maskcolors   (~(bitmask(BLACKBIT) | WHITEBITS))

Definition at line 66 of file lgc.cpp.

Referenced by sweeplist().

◆ PAUSEADJ

#define PAUSEADJ   100

Definition at line 59 of file lgc.cpp.

Referenced by setpause().

◆ STEPMULADJ

#define STEPMULADJ   200

Definition at line 52 of file lgc.cpp.

Referenced by getdebt(), and luaC_step().

◆ sweepwholelist

#define sweepwholelist (   L,
  p 
)    sweeplist(L,p,MAX_LUMEM)

Definition at line 724 of file lgc.cpp.

Referenced by luaC_freeallobjects().

◆ valiswhite

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

Definition at line 74 of file lgc.cpp.

Referenced by reallymarkobject(), removeentry(), and traverseephemeron().

◆ white2gray

#define white2gray (   x)    resetbits(x->marked, WHITEBITS)

Definition at line 70 of file lgc.cpp.

Referenced by luaC_fix(), and reallymarkobject().

Function Documentation

◆ atomic()

static l_mem atomic ( lua_State L)
static

◆ callallpendingfinalizers()

static void callallpendingfinalizers ( lua_State L)
static

Definition at line 859 of file lgc.cpp.

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

Referenced by luaC_freeallobjects().

◆ checkSizes()

static void checkSizes ( lua_State L,
global_State g 
)
static

◆ clearkeys()

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

Definition at line 639 of file lgc.cpp.

References f, gco2t, gkey, gnode, gnodelast, gval, h, iscleared(), n, removeentry(), setnilvalue, and ttisnil.

Referenced by atomic().

◆ clearvalues()

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

Definition at line 658 of file lgc.cpp.

References Table::array, f, gco2t, gnode, gnodelast, gval, h, i, iscleared(), n, removeentry(), setnilvalue, Table::sizearray, and ttisnil.

Referenced by atomic().

◆ convergeephemerons()

static void convergeephemerons ( global_State g)
static

Definition at line 608 of file lgc.cpp.

References global_State::ephemeron, gco2t, next, propagateall(), traverseephemeron(), and w.

Referenced by atomic().

◆ dothecall()

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

Definition at line 801 of file lgc.cpp.

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

Referenced by GCTM().

◆ entersweep()

static void entersweep ( lua_State L)
static

◆ findlast()

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

Definition at line 869 of file lgc.cpp.

References p.

Referenced by separatetobefnz().

◆ freeLclosure()

static void freeLclosure ( lua_State L,
LClosure cl 
)
static

Definition at line 686 of file lgc.cpp.

References i, luaC_upvdeccount(), luaM_freemem, sizeLclosure, and LClosure::upvals.

Referenced by freeobj().

◆ freeobj()

static void freeobj ( lua_State L,
GCObject o 
)
static

◆ GCTM()

static void GCTM ( lua_State L,
int  propagateerrors 
)
static

◆ getdebt()

static l_mem getdebt ( global_State g)
static

Definition at line 1115 of file lgc.cpp.

References global_State::GCdebt, global_State::gcstepmul, MAX_LMEM, and STEPMULADJ.

Referenced by luaC_step().

◆ iscleared()

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

Definition at line 139 of file lgc.cpp.

References gcvalue, iscollectable, iswhite, markobject, tsvalue, and ttisstring.

Referenced by clearkeys(), clearvalues(), traverseephemeron(), and traverseweakvalue().

◆ luaC_barrier_()

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

Definition at line 155 of file lgc.cpp.

References g, G, isblack, isdead, issweepphase, iswhite, keepinvariant, lua_assert, makewhite, and reallymarkobject().

◆ luaC_barrierback_()

void luaC_barrierback_ ( lua_State L,
Table t 
)

Definition at line 171 of file lgc.cpp.

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

◆ 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 194 of file lgc.cpp.

References global_State::allgc, global_State::fixedgc, g, G, lua_assert, and white2gray.

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 
)

◆ 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 1104 of file lgc.cpp.

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

Referenced by luaC_fullgc().

◆ luaC_step()

void luaC_step ( lua_State L)

◆ luaC_upvalbarrier_()

void luaC_upvalbarrier_ ( lua_State L,
UpVal uv 
)

Definition at line 185 of file lgc.cpp.

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

◆ luaC_upvdeccount()

void luaC_upvdeccount ( lua_State L,
UpVal uv 
)

Definition at line 678 of file lgc.cpp.

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

Referenced by freeLclosure(), and lua_upvaluejoin().

◆ markbeingfnz()

static void markbeingfnz ( global_State g)
static

Definition at line 299 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 289 of file lgc.cpp.

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

Referenced by atomic(), and restartcollection().

◆ propagateall()

static void propagateall ( global_State g)
static

Definition at line 603 of file lgc.cpp.

References global_State::gray, and propagatemark().

Referenced by atomic(), convergeephemerons(), and singlestep().

◆ propagatemark()

static void propagatemark ( global_State g)
static

◆ reallymarkobject()

static void reallymarkobject ( global_State g,
GCObject o 
)
static

◆ remarkupvals()

static void remarkupvals ( global_State g)
static

◆ removeentry()

static void removeentry ( Node n)
static

◆ restartcollection()

static void restartcollection ( global_State g)
static

◆ runafewfinalizers()

static int runafewfinalizers ( lua_State L)
static

Definition at line 844 of file lgc.cpp.

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

Referenced by luaC_step(), and singlestep().

◆ separatetobefnz()

static void separatetobefnz ( global_State g,
int  all 
)
static

Definition at line 880 of file lgc.cpp.

References curr, findlast(), global_State::finobj, iswhite, lua_assert, p, global_State::tobefnz, and tofinalize.

Referenced by atomic(), and luaC_freeallobjects().

◆ setpause()

static void setpause ( global_State g)
static

◆ singlestep()

static lu_mem singlestep ( lua_State L)
static

◆ sweeplist()

static GCObject ** sweeplist ( lua_State L,
GCObject **  p,
lu_mem  count 
)
static

Definition at line 735 of file lgc.cpp.

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

Referenced by entersweep(), sweepstep(), and sweeptolive().

◆ sweepstep()

static lu_mem 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 758 of file lgc.cpp.

References p, and sweeplist().

Referenced by luaC_checkfinalizer().

◆ traverseCclosure()

static lu_mem traverseCclosure ( global_State g,
CClosure cl 
)
static

Definition at line 501 of file lgc.cpp.

References i, markvalue, sizeCclosure, and CClosure::upvalue.

Referenced by propagatemark().

◆ traverseephemeron()

static int traverseephemeron ( global_State g,
Table h 
)
static

◆ traverseLclosure()

static lu_mem traverseLclosure ( global_State g,
LClosure cl 
)
static

◆ traverseproto()

static int traverseproto ( global_State g,
Proto f 
)
static

◆ traversestrongtable()

static void traversestrongtable ( global_State g,
Table h 
)
static

Definition at line 433 of file lgc.cpp.

References Table::array, checkdeadkey, gkey, gnode, gnodelast, gval, i, lua_assert, markvalue, n, removeentry(), Table::sizearray, and ttisnil.

Referenced by traversetable().

◆ traversetable()

static lu_mem traversetable ( global_State g,
Table h 
)
static

◆ traversethread()

static lu_mem traversethread ( global_State g,
lua_State th 
)
static

◆ traverseweakvalue()

static void traverseweakvalue ( global_State g,
Table h 
)
static

◆ udata2finalize()

static GCObject* udata2finalize ( global_State g)
static

Definition at line 788 of file lgc.cpp.

References global_State::allgc, FINALIZEDBIT, issweepphase, lua_assert, makewhite, resetbit, global_State::tobefnz, and tofinalize.

Referenced by GCTM().