some progress on GC v2
This commit is contained in:
parent
ec1abdef97
commit
19677a11b0
3 changed files with 15 additions and 8 deletions
|
|
@ -104,8 +104,6 @@ when not defined(useNimRtl):
|
||||||
|
|
||||||
proc initGC() =
|
proc initGC() =
|
||||||
when not defined(useNimRtl):
|
when not defined(useNimRtl):
|
||||||
when traceGC:
|
|
||||||
for i in low(CellState)..high(CellState): init(states[i])
|
|
||||||
gch.cycleThreshold = InitialCycleThreshold
|
gch.cycleThreshold = InitialCycleThreshold
|
||||||
gch.stat.stackScans = 0
|
gch.stat.stackScans = 0
|
||||||
gch.stat.cycleCollections = 0
|
gch.stat.cycleCollections = 0
|
||||||
|
|
@ -168,8 +166,10 @@ proc writeCell(msg: cstring, c: PCell) =
|
||||||
c_fprintf(c_stdout, "[GC] %s: %p %d rc=%ld; color=%ld\n",
|
c_fprintf(c_stdout, "[GC] %s: %p %d rc=%ld; color=%ld\n",
|
||||||
msg, c, kind, c.refcount shr rcShift, c.color)
|
msg, c, kind, c.refcount shr rcShift, c.color)
|
||||||
|
|
||||||
|
proc myastToStr[T](x: T): string {.magic: "AstToStr", noSideEffect.}
|
||||||
|
|
||||||
template gcTrace(cell, state: expr): stmt {.immediate.} =
|
template gcTrace(cell, state: expr): stmt {.immediate.} =
|
||||||
when traceGC: traceCell(cell, state)
|
when traceGC: writeCell(myastToStr(state), cell)
|
||||||
|
|
||||||
# forward declarations:
|
# forward declarations:
|
||||||
proc collectCT(gch: var GcHeap) {.benign.}
|
proc collectCT(gch: var GcHeap) {.benign.}
|
||||||
|
|
@ -568,7 +568,7 @@ template takeTime {.dirty.} =
|
||||||
|
|
||||||
template checkTime {.dirty.} =
|
template checkTime {.dirty.} =
|
||||||
if debugticker <= 0:
|
if debugticker <= 0:
|
||||||
echo "in loop"
|
#echo "in loop"
|
||||||
debugticker = 1000
|
debugticker = 1000
|
||||||
when withRealTime:
|
when withRealTime:
|
||||||
if steps == 0:
|
if steps == 0:
|
||||||
|
|
@ -602,8 +602,9 @@ proc freeCyclicCell(gch: var GcHeap, c: PCell) =
|
||||||
|
|
||||||
proc sweep(gch: var GcHeap): bool =
|
proc sweep(gch: var GcHeap): bool =
|
||||||
takeStartTime(100)
|
takeStartTime(100)
|
||||||
echo "loop start"
|
#echo "loop start"
|
||||||
let black = gch.black
|
let black = gch.black
|
||||||
|
cfprintf(cstdout, "black is %d\n", black)
|
||||||
while true:
|
while true:
|
||||||
let x = allObjectsAsProc(gch.region, addr gch.spaceIter)
|
let x = allObjectsAsProc(gch.region, addr gch.spaceIter)
|
||||||
if gch.spaceIter.state < 0: break
|
if gch.spaceIter.state < 0: break
|
||||||
|
|
@ -619,7 +620,7 @@ proc sweep(gch: var GcHeap): bool =
|
||||||
# traversal over the heap!
|
# traversal over the heap!
|
||||||
checkTime()
|
checkTime()
|
||||||
# prepare for next iteration:
|
# prepare for next iteration:
|
||||||
echo "loop end"
|
#echo "loop end"
|
||||||
gch.spaceIter = ObjectSpaceIter()
|
gch.spaceIter = ObjectSpaceIter()
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
|
|
@ -634,6 +635,9 @@ proc markIncremental(gch: var GcHeap): bool =
|
||||||
takeStartTime(100)
|
takeStartTime(100)
|
||||||
while L[] > 0:
|
while L[] > 0:
|
||||||
var c = gch.greyStack.d[0]
|
var c = gch.greyStack.d[0]
|
||||||
|
if not isAllocatedPtr(gch.region, c):
|
||||||
|
c_fprintf(c_stdout, "[GC] not allocated anymore: %p\n", c)
|
||||||
|
|
||||||
sysAssert(isAllocatedPtr(gch.region, c), "markIncremental: isAllocatedPtr")
|
sysAssert(isAllocatedPtr(gch.region, c), "markIncremental: isAllocatedPtr")
|
||||||
gch.greyStack.d[0] = gch.greyStack.d[L[] - 1]
|
gch.greyStack.d[0] = gch.greyStack.d[L[] - 1]
|
||||||
dec(L[])
|
dec(L[])
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@
|
||||||
const
|
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 = defined(smokeCycles) # extensive debugging
|
||||||
alwaysCycleGC = false
|
alwaysCycleGC = defined(smokeCycles)
|
||||||
alwaysGC = defined(fulldebug) # collect after every memory
|
alwaysGC = defined(fulldebug) # collect after every memory
|
||||||
# allocation (for debugging)
|
# allocation (for debugging)
|
||||||
leakDetector = false
|
leakDetector = false
|
||||||
|
|
|
||||||
3
todo.txt
3
todo.txt
|
|
@ -1,3 +1,6 @@
|
||||||
|
|
||||||
|
nim c --gc:v2 -r -d:useSysAssert -d:useGcAssert -d:smokeCycles -d:useRealtimeGc tests/gc/gcbench
|
||||||
|
|
||||||
essential for 1.0
|
essential for 1.0
|
||||||
=================
|
=================
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue