三种颜色
(1)white:未标记
(2)grey:该对象标记,其引用未标记
(3)black:该对象及其所有引用均被标记
GC状态
GCSpropagate
调用propagatemark(),若g->grey为NULL,置状态为GCSatomic
GCSatomic
propagateall()
atomic()
entersweep()
GCSswpallgc
sweepstep()
GCSswpfinobj
sweepstep()
GCSswptobefnz
sweepstep()
GCSswpend
makewhite(g->mainthread)
GCScallfin
调用剩余的的finalizers,完成后转GCSpause
GCSpause
调用restartcollection(),状态转为GCSpropagate
内部以luaC_作为前缀
luaC_fix()
luaC_freeallobjects()
luaC_step()
luaC_runtilstate()
luaC_fullgc()
luaC_newobj()
luaC_barrier_()
luaC_barrierback_()
luaC_upvalbarrier_()
luaC_checkfinalizer()
luaC_upvdeccound()
Generic functions
Mark functions
reallymarkobject()
Userdata, strings, and closed upvalues设为black,其它对象暂设为灰并加入list,留待稍后继续访问。
markmt()
markbeingfnz()
remarkupvals()
restartcollection()
markobject(g->mainthread)
markvalue(g->l_registry)
markmt()
遍历g->mt中基本类型的metatable并标记
markbeingfnz()
遍历g->tobefnz链表中所有元素并标记(上一循环剩下的object)
Traverse functions
traverseweakvalue()
traverseephemeron()
traversestrongtable()
traversetable()
traverseproto()
traverseCclosure()
traverseLclosure()
traverseThread()
propagatemark()
propagateall()
遍历g->grey,并执行propagatemark()
convergeephemerons()
Sweep functions
Finalization
separatetobefnz()
move all unreadable objects that need finalization from list 'finobj' to list 'tobefnz'
GC control