make gc:v2 compile again
This commit is contained in:
parent
dcfafb3289
commit
07531b41b9
2 changed files with 21 additions and 19 deletions
|
|
@ -69,7 +69,7 @@ type
|
||||||
maxStackCells: int # max stack cells in ``decStack``
|
maxStackCells: int # max stack cells in ``decStack``
|
||||||
cycleTableSize: int # max entries in cycle table
|
cycleTableSize: int # max entries in cycle table
|
||||||
maxPause: int64 # max measured GC pause in nanoseconds
|
maxPause: int64 # max measured GC pause in nanoseconds
|
||||||
|
|
||||||
GcStack {.final, pure.} = object
|
GcStack {.final, pure.} = object
|
||||||
when nimCoroutines:
|
when nimCoroutines:
|
||||||
prev: ptr GcStack
|
prev: ptr GcStack
|
||||||
|
|
@ -220,17 +220,6 @@ else:
|
||||||
x <% rcIncrement
|
x <% rcIncrement
|
||||||
template `++`(x: expr): stmt = inc(x, rcIncrement)
|
template `++`(x: expr): stmt = inc(x, rcIncrement)
|
||||||
|
|
||||||
proc prepareDealloc(cell: PCell) =
|
|
||||||
if cell.typ.finalizer != nil:
|
|
||||||
# the finalizer could invoke something that
|
|
||||||
# allocates memory; this could trigger a garbage
|
|
||||||
# collection. Since we are already collecting we
|
|
||||||
# prevend recursive entering here by a lock.
|
|
||||||
# XXX: we should set the cell's children to nil!
|
|
||||||
inc(gch.recGcLock)
|
|
||||||
(cast[Finalizer](cell.typ.finalizer))(cellToUsr(cell))
|
|
||||||
dec(gch.recGcLock)
|
|
||||||
|
|
||||||
proc rtlAddCycleRoot(c: PCell) {.rtl, inl.} =
|
proc rtlAddCycleRoot(c: PCell) {.rtl, inl.} =
|
||||||
# we MUST access gch as a global here, because this crosses DLL boundaries!
|
# we MUST access gch as a global here, because this crosses DLL boundaries!
|
||||||
discard
|
discard
|
||||||
|
|
@ -249,6 +238,9 @@ proc incRef(c: PCell) {.inline.} =
|
||||||
gcAssert(isAllocatedPtr(gch.region, c), "incRef: interiorPtr")
|
gcAssert(isAllocatedPtr(gch.region, c), "incRef: interiorPtr")
|
||||||
c.refcount = c.refcount +% rcIncrement
|
c.refcount = c.refcount +% rcIncrement
|
||||||
|
|
||||||
|
proc nimGCunrefRC1(p: pointer) {.compilerProc, inline.} =
|
||||||
|
decRef(usrToCell(p))
|
||||||
|
|
||||||
proc nimGCref(p: pointer) {.compilerProc.} =
|
proc nimGCref(p: pointer) {.compilerProc.} =
|
||||||
let cell = usrToCell(p)
|
let cell = usrToCell(p)
|
||||||
incRef(cell)
|
incRef(cell)
|
||||||
|
|
@ -665,6 +657,8 @@ proc GC_dumpHeap() =
|
||||||
|
|
||||||
# ---------------- cycle collector -------------------------------------------
|
# ---------------- cycle collector -------------------------------------------
|
||||||
|
|
||||||
|
include gc_common
|
||||||
|
|
||||||
proc freeCyclicCell(gch: var GcHeap, c: PCell) =
|
proc freeCyclicCell(gch: var GcHeap, c: PCell) =
|
||||||
gcAssert(isAllocatedPtr(gch.region, c), "freeCyclicCell: freed pointer?")
|
gcAssert(isAllocatedPtr(gch.region, c), "freeCyclicCell: freed pointer?")
|
||||||
|
|
||||||
|
|
@ -859,8 +853,6 @@ proc gcMark(gch: var GcHeap, p: pointer) {.inline.} =
|
||||||
add(gch.decStack, objStart)
|
add(gch.decStack, objStart)
|
||||||
sysAssert(allocInv(gch.region), "gcMark end")
|
sysAssert(allocInv(gch.region), "gcMark end")
|
||||||
|
|
||||||
include gc_common
|
|
||||||
|
|
||||||
proc markStackAndRegisters(gch: var GcHeap) {.noinline, cdecl.} =
|
proc markStackAndRegisters(gch: var GcHeap) {.noinline, cdecl.} =
|
||||||
forEachStackSlot(gch, gcMark)
|
forEachStackSlot(gch, gcMark)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -373,12 +373,22 @@ proc deallocHeap*(runFinalizers = true; allowGcAfterwards = true) =
|
||||||
## is true. If ``allowGcAfterwards`` is true, a minimal amount of allocation
|
## is true. If ``allowGcAfterwards`` is true, a minimal amount of allocation
|
||||||
## happens to ensure the GC can continue to work after the call
|
## happens to ensure the GC can continue to work after the call
|
||||||
## to ``deallocHeap``.
|
## to ``deallocHeap``.
|
||||||
|
template deallocCell(x) =
|
||||||
|
if isCell(x):
|
||||||
|
# cast to PCell is correct here:
|
||||||
|
prepareDealloc(cast[PCell](x))
|
||||||
|
|
||||||
if runFinalizers:
|
if runFinalizers:
|
||||||
for x in allObjects(gch.region):
|
when not declared(allObjectsAsProc):
|
||||||
if isCell(x):
|
for x in allObjects(gch.region):
|
||||||
# cast to PCell is correct here:
|
deallocCell(x)
|
||||||
var c = cast[PCell](x)
|
else:
|
||||||
prepareDealloc(c)
|
var spaceIter: ObjectSpaceIter
|
||||||
|
while true:
|
||||||
|
let x = allObjectsAsProc(gch.region, addr spaceIter)
|
||||||
|
if spaceIter.state < 0: break
|
||||||
|
deallocCell(x)
|
||||||
|
|
||||||
deallocOsPages(gch.region)
|
deallocOsPages(gch.region)
|
||||||
zeroMem(addr gch.region, sizeof(gch.region))
|
zeroMem(addr gch.region, sizeof(gch.region))
|
||||||
if allowGcAfterwards:
|
if allowGcAfterwards:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue