next steps for the GC
This commit is contained in:
parent
9ed635d5c0
commit
10530add48
2 changed files with 23 additions and 6 deletions
|
|
@ -39,9 +39,9 @@ iterToProc(allObjects, ptr ObjectSpaceIter, allObjectsAsProc)
|
||||||
|
|
||||||
const
|
const
|
||||||
rcIncrement = 0b1000 # so that lowest 3 bits are not touched
|
rcIncrement = 0b1000 # so that lowest 3 bits are not touched
|
||||||
rcWhite = 0b000 # cell is colored white
|
rcBlack = 0b000
|
||||||
rcGrey = 0b001 # traditional color for incremental mark&sweep
|
rcGrey = 0b001 # traditional color for incremental mark&sweep
|
||||||
rcBlack = 0b010 # marked as alive; direct children also have been processed
|
rcWhite = 0b010
|
||||||
rcUnused = 0b011
|
rcUnused = 0b011
|
||||||
ZctFlag = 0b100 # in ZCT
|
ZctFlag = 0b100 # in ZCT
|
||||||
rcShift = 3 # shift by rcShift to get the reference counter
|
rcShift = 3 # shift by rcShift to get the reference counter
|
||||||
|
|
@ -153,7 +153,7 @@ when BitsPerPage mod (sizeof(int)*8) != 0:
|
||||||
|
|
||||||
template color(c): expr = c.refCount and colorMask
|
template color(c): expr = c.refCount and colorMask
|
||||||
template setColor(c, col) =
|
template setColor(c, col) =
|
||||||
when col == rcWhite:
|
when col == rcBlack:
|
||||||
c.refcount = c.refcount and not colorMask
|
c.refcount = c.refcount and not colorMask
|
||||||
else:
|
else:
|
||||||
c.refcount = c.refcount and not colorMask or col
|
c.refcount = c.refcount and not colorMask or col
|
||||||
|
|
@ -584,6 +584,12 @@ template checkTime {.dirty.} =
|
||||||
# ---------------- cycle collector -------------------------------------------
|
# ---------------- cycle collector -------------------------------------------
|
||||||
|
|
||||||
proc freeCyclicCell(gch: var GcHeap, c: PCell) =
|
proc freeCyclicCell(gch: var GcHeap, c: PCell) =
|
||||||
|
gcAssert(isAllocatedPtr(gch.region, c), "freeCyclicCell: freed pointer?")
|
||||||
|
|
||||||
|
var d = gch.decStack.d
|
||||||
|
for i in 0..gch.decStack.len-1:
|
||||||
|
gcAssert d[i] != c, "wtf man, freeing obviously alive stuff?!!"
|
||||||
|
|
||||||
prepareDealloc(c)
|
prepareDealloc(c)
|
||||||
gcTrace(c, csCycFreed)
|
gcTrace(c, csCycFreed)
|
||||||
when logGC: writeCell("cycle collector dealloc cell", c)
|
when logGC: writeCell("cycle collector dealloc cell", c)
|
||||||
|
|
@ -606,7 +612,7 @@ proc sweep(gch: var GcHeap): bool =
|
||||||
var c = cast[PCell](x)
|
var c = cast[PCell](x)
|
||||||
gcAssert c.color != rcGrey, "cell is still grey?"
|
gcAssert c.color != rcGrey, "cell is still grey?"
|
||||||
if c.color == rcWhite: freeCyclicCell(gch, c)
|
if c.color == rcWhite: freeCyclicCell(gch, c)
|
||||||
else: c.setColor(rcWhite)
|
#else: c.setColor(rcWhite)
|
||||||
checkTime()
|
checkTime()
|
||||||
# prepare for next iteration:
|
# prepare for next iteration:
|
||||||
echo "loop end"
|
echo "loop end"
|
||||||
|
|
@ -614,9 +620,20 @@ proc sweep(gch: var GcHeap): bool =
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
proc markS(gch: var GcHeap, c: PCell) =
|
proc markS(gch: var GcHeap, c: PCell) =
|
||||||
|
# since we start with 'black' cells, we need to mark them here too:
|
||||||
|
if c.color != rcGrey:
|
||||||
|
c.setColor(rcGrey)
|
||||||
|
add(gch.greyStack, c)
|
||||||
|
when false:
|
||||||
|
# since we start with 'black' cells, we need to mark them unconditionally
|
||||||
|
# here. But this means that we mark too much. Duplicate roots (which can
|
||||||
|
# often happen for stack slots) lead to somewhat duplicate marking.
|
||||||
|
# XXX We could maybe prevent this somehow?
|
||||||
if c.color == rcWhite:
|
if c.color == rcWhite:
|
||||||
c.setColor(rcGrey)
|
c.setColor(rcGrey)
|
||||||
add(gch.greyStack, c)
|
add(gch.greyStack, c)
|
||||||
|
#elif c.color == rcBlack:
|
||||||
|
# echo "cell is black?!"
|
||||||
#forAllChildren(c, waMarkGrey)
|
#forAllChildren(c, waMarkGrey)
|
||||||
#x.setColor(rcBlack)
|
#x.setColor(rcBlack)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ const
|
||||||
debugGC = false # we wish to debug the GC...
|
debugGC = false # we wish to debug the GC...
|
||||||
logGC = false
|
logGC = false
|
||||||
traceGC = false # extensive debugging
|
traceGC = false # extensive debugging
|
||||||
alwaysCycleGC = false
|
alwaysCycleGC = true
|
||||||
alwaysGC = defined(fulldebug) # collect after every memory
|
alwaysGC = defined(fulldebug) # collect after every memory
|
||||||
# allocation (for debugging)
|
# allocation (for debugging)
|
||||||
leakDetector = false
|
leakDetector = false
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue