annotate src/lua/lgc.h @ 352:82e3ba144773

wrote skeleton for celadon purchase spree.
author Robert McIntyre <rlm@mit.edu>
date Sun, 08 Apr 2012 21:21:39 -0500
parents 27763b933818
children
rev   line source
rlm@1 1 /*
rlm@1 2 ** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $
rlm@1 3 ** Garbage Collector
rlm@1 4 ** See Copyright Notice in lua.h
rlm@1 5 */
rlm@1 6
rlm@1 7 #ifndef lgc_h
rlm@1 8 #define lgc_h
rlm@1 9
rlm@1 10
rlm@1 11 #include "lobject.h"
rlm@1 12
rlm@1 13
rlm@1 14 /*
rlm@1 15 ** Possible states of the Garbage Collector
rlm@1 16 */
rlm@1 17 #define GCSpause 0
rlm@1 18 #define GCSpropagate 1
rlm@1 19 #define GCSsweepstring 2
rlm@1 20 #define GCSsweep 3
rlm@1 21 #define GCSfinalize 4
rlm@1 22
rlm@1 23
rlm@1 24 /*
rlm@1 25 ** some userful bit tricks
rlm@1 26 */
rlm@1 27 #define resetbits(x,m) ((x) &= cast(lu_byte, ~(m)))
rlm@1 28 #define setbits(x,m) ((x) |= (m))
rlm@1 29 #define testbits(x,m) ((x) & (m))
rlm@1 30 #define bitmask(b) (1<<(b))
rlm@1 31 #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2))
rlm@1 32 #define l_setbit(x,b) setbits(x, bitmask(b))
rlm@1 33 #define resetbit(x,b) resetbits(x, bitmask(b))
rlm@1 34 #define testbit(x,b) testbits(x, bitmask(b))
rlm@1 35 #define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2)))
rlm@1 36 #define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2)))
rlm@1 37 #define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2)))
rlm@1 38
rlm@1 39
rlm@1 40
rlm@1 41 /*
rlm@1 42 ** Layout for bit use in `marked' field:
rlm@1 43 ** bit 0 - object is white (type 0)
rlm@1 44 ** bit 1 - object is white (type 1)
rlm@1 45 ** bit 2 - object is black
rlm@1 46 ** bit 3 - for userdata: has been finalized
rlm@1 47 ** bit 3 - for tables: has weak keys
rlm@1 48 ** bit 4 - for tables: has weak values
rlm@1 49 ** bit 5 - object is fixed (should not be collected)
rlm@1 50 ** bit 6 - object is "super" fixed (only the main thread)
rlm@1 51 */
rlm@1 52
rlm@1 53
rlm@1 54 #define WHITE0BIT 0
rlm@1 55 #define WHITE1BIT 1
rlm@1 56 #define BLACKBIT 2
rlm@1 57 #define FINALIZEDBIT 3
rlm@1 58 #define KEYWEAKBIT 3
rlm@1 59 #define VALUEWEAKBIT 4
rlm@1 60 #define FIXEDBIT 5
rlm@1 61 #define SFIXEDBIT 6
rlm@1 62 #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
rlm@1 63
rlm@1 64
rlm@1 65 #define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
rlm@1 66 #define isblack(x) testbit((x)->gch.marked, BLACKBIT)
rlm@1 67 #define isgray(x) (!isblack(x) && !iswhite(x))
rlm@1 68
rlm@1 69 #define otherwhite(g) (g->currentwhite ^ WHITEBITS)
rlm@1 70 #define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS)
rlm@1 71
rlm@1 72 #define changewhite(x) ((x)->gch.marked ^= WHITEBITS)
rlm@1 73 #define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT)
rlm@1 74
rlm@1 75 #define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x)))
rlm@1 76
rlm@1 77 #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS)
rlm@1 78
rlm@1 79
rlm@1 80 #define luaC_checkGC(L) { \
rlm@1 81 condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \
rlm@1 82 if (G(L)->totalbytes >= G(L)->GCthreshold) \
rlm@1 83 luaC_step(L); }
rlm@1 84
rlm@1 85
rlm@1 86 #define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \
rlm@1 87 luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
rlm@1 88
rlm@1 89 #define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \
rlm@1 90 luaC_barrierback(L,t); }
rlm@1 91
rlm@1 92 #define luaC_objbarrier(L,p,o) \
rlm@1 93 { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
rlm@1 94 luaC_barrierf(L,obj2gco(p),obj2gco(o)); }
rlm@1 95
rlm@1 96 #define luaC_objbarriert(L,t,o) \
rlm@1 97 { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }
rlm@1 98
rlm@1 99 LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all);
rlm@1 100 LUAI_FUNC void luaC_callGCTM (lua_State *L);
rlm@1 101 LUAI_FUNC void luaC_freeall (lua_State *L);
rlm@1 102 LUAI_FUNC void luaC_step (lua_State *L);
rlm@1 103 LUAI_FUNC void luaC_fullgc (lua_State *L);
rlm@1 104 LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
rlm@1 105 LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);
rlm@1 106 LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);
rlm@1 107 LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t);
rlm@1 108
rlm@1 109
rlm@1 110 #endif