aboutsummaryrefslogtreecommitdiff
path: root/lgc.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-04-05 13:50:51 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-04-05 13:50:51 -0300
commite4287da3a6b0b167da465fd449e5191b9ac9ef46 (patch)
tree3568d8717dea66ff815475a945cfaafc7e6d98da /lgc.h
parent1a1b2f3d7f321dd6f28118c985986940b189c635 (diff)
downloadlua-e4287da3a6b0b167da465fd449e5191b9ac9ef46.tar.gz
lua-e4287da3a6b0b167da465fd449e5191b9ac9ef46.tar.bz2
lua-e4287da3a6b0b167da465fd449e5191b9ac9ef46.zip
generational collector (still not complete)
Diffstat (limited to 'lgc.h')
-rw-r--r--lgc.h54
1 files changed, 39 insertions, 15 deletions
diff --git a/lgc.h b/lgc.h
index e75ff85c..158c0e38 100644
--- a/lgc.h
+++ b/lgc.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.h,v 2.91 2015/12/21 13:02:14 roberto Exp roberto $ 2** $Id: lgc.h,v 2.92 2017/02/23 21:07:34 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -37,13 +37,14 @@
37** Possible states of the Garbage Collector 37** Possible states of the Garbage Collector
38*/ 38*/
39#define GCSpropagate 0 39#define GCSpropagate 0
40#define GCSatomic 1 40#define GCSenteratomic 1
41#define GCSswpallgc 2 41#define GCSatomic 2
42#define GCSswpfinobj 3 42#define GCSswpallgc 3
43#define GCSswptobefnz 4 43#define GCSswpfinobj 4
44#define GCSswpend 5 44#define GCSswptobefnz 5
45#define GCScallfin 6 45#define GCSswpend 6
46#define GCSpause 7 46#define GCScallfin 7
47#define GCSpause 8
47 48
48 49
49#define issweepphase(g) \ 50#define issweepphase(g) \
@@ -74,14 +75,17 @@
74#define testbit(x,b) testbits(x, bitmask(b)) 75#define testbit(x,b) testbits(x, bitmask(b))
75 76
76 77
77/* Layout for bit use in 'marked' field: */ 78/*
78#define WHITE0BIT 0 /* object is white (type 0) */ 79** Layout for bit use in 'marked' field. First three bits are
79#define WHITE1BIT 1 /* object is white (type 1) */ 80** used for object "age" in generational mode.
80#define BLACKBIT 2 /* object is black */ 81*/
81#define FINALIZEDBIT 3 /* object has been marked for finalization */ 82#define WHITE0BIT 3 /* object is white (type 0) */
82#define OLDBIT 4 /* object is old (gen. mode) */ 83#define WHITE1BIT 4 /* object is white (type 1) */
84#define BLACKBIT 5 /* object is black */
85#define FINALIZEDBIT 6 /* object has been marked for finalization */
83#define TESTGRAYBIT 7 /* used by tests (luaL_checkmemory) */ 86#define TESTGRAYBIT 7 /* used by tests (luaL_checkmemory) */
84 87
88
85#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) 89#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
86 90
87 91
@@ -89,7 +93,6 @@
89#define isblack(x) testbit((x)->marked, BLACKBIT) 93#define isblack(x) testbit((x)->marked, BLACKBIT)
90#define isgray(x) /* neither white nor black */ \ 94#define isgray(x) /* neither white nor black */ \
91 (!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT))) 95 (!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT)))
92#define isold(x) testbit((x)->marked, OLDBIT)
93 96
94#define tofinalize(x) testbit((x)->marked, FINALIZEDBIT) 97#define tofinalize(x) testbit((x)->marked, FINALIZEDBIT)
95 98
@@ -103,6 +106,27 @@
103#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) 106#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS)
104 107
105 108
109/* object age in generational mode */
110#define G_NEW 0 /* created in current cycle */
111#define G_SURVIVAL 1 /* created in previous cycle */
112#define G_OLD1 2 /* first full cycle as old */
113#define G_OLD0 3 /* marked old by frw. barrier in this cycle */
114#define G_OLD 4 /* really old object (not to be visited) */
115#define G_TOUCHED1 5 /* old object touched this cycle */
116#define G_TOUCHED2 6 /* old object touched in previous cycle */
117
118#define AGEBITS 7 /* all age bits (111) */
119
120#define getage(o) ((o)->marked & AGEBITS)
121#define setage(o,a) ((o)->marked = cast_byte(((o)->marked & (~AGEBITS)) | a))
122#define isold(o) (getage(o) > G_SURVIVAL)
123
124#define changeage(o,f,t) \
125 check_exp(getage(o) == (f), (o)->marked ^= ((f)^(t)))
126
127#define ongraylist(o) (isgray(o) || getage(o) == G_TOUCHED2)
128
129
106/* 130/*
107** Does one step of collection when debt becomes positive. 'pre'/'pos' 131** Does one step of collection when debt becomes positive. 'pre'/'pos'
108** allows some adjustments to be done only when needed. macro 132** allows some adjustments to be done only when needed. macro