mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-21 14:55:24 +00:00
make gc:v2 compile again
This commit is contained in:
@@ -69,7 +69,7 @@ type
|
||||
maxStackCells: int # max stack cells in ``decStack``
|
||||
cycleTableSize: int # max entries in cycle table
|
||||
maxPause: int64 # max measured GC pause in nanoseconds
|
||||
|
||||
|
||||
GcStack {.final, pure.} = object
|
||||
when nimCoroutines:
|
||||
prev: ptr GcStack
|
||||
@@ -220,17 +220,6 @@ else:
|
||||
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.} =
|
||||
# we MUST access gch as a global here, because this crosses DLL boundaries!
|
||||
discard
|
||||
@@ -249,6 +238,9 @@ proc incRef(c: PCell) {.inline.} =
|
||||
gcAssert(isAllocatedPtr(gch.region, c), "incRef: interiorPtr")
|
||||
c.refcount = c.refcount +% rcIncrement
|
||||
|
||||
proc nimGCunrefRC1(p: pointer) {.compilerProc, inline.} =
|
||||
decRef(usrToCell(p))
|
||||
|
||||
proc nimGCref(p: pointer) {.compilerProc.} =
|
||||
let cell = usrToCell(p)
|
||||
incRef(cell)
|
||||
@@ -665,6 +657,8 @@ proc GC_dumpHeap() =
|
||||
|
||||
# ---------------- cycle collector -------------------------------------------
|
||||
|
||||
include gc_common
|
||||
|
||||
proc freeCyclicCell(gch: var GcHeap, c: PCell) =
|
||||
gcAssert(isAllocatedPtr(gch.region, c), "freeCyclicCell: freed pointer?")
|
||||
|
||||
@@ -859,8 +853,6 @@ proc gcMark(gch: var GcHeap, p: pointer) {.inline.} =
|
||||
add(gch.decStack, objStart)
|
||||
sysAssert(allocInv(gch.region), "gcMark end")
|
||||
|
||||
include gc_common
|
||||
|
||||
proc markStackAndRegisters(gch: var GcHeap) {.noinline, cdecl.} =
|
||||
forEachStackSlot(gch, gcMark)
|
||||
|
||||
|
||||
@@ -373,12 +373,22 @@ proc deallocHeap*(runFinalizers = true; allowGcAfterwards = true) =
|
||||
## is true. If ``allowGcAfterwards`` is true, a minimal amount of allocation
|
||||
## happens to ensure the GC can continue to work after the call
|
||||
## to ``deallocHeap``.
|
||||
template deallocCell(x) =
|
||||
if isCell(x):
|
||||
# cast to PCell is correct here:
|
||||
prepareDealloc(cast[PCell](x))
|
||||
|
||||
if runFinalizers:
|
||||
for x in allObjects(gch.region):
|
||||
if isCell(x):
|
||||
# cast to PCell is correct here:
|
||||
var c = cast[PCell](x)
|
||||
prepareDealloc(c)
|
||||
when not declared(allObjectsAsProc):
|
||||
for x in allObjects(gch.region):
|
||||
deallocCell(x)
|
||||
else:
|
||||
var spaceIter: ObjectSpaceIter
|
||||
while true:
|
||||
let x = allObjectsAsProc(gch.region, addr spaceIter)
|
||||
if spaceIter.state < 0: break
|
||||
deallocCell(x)
|
||||
|
||||
deallocOsPages(gch.region)
|
||||
zeroMem(addr gch.region, sizeof(gch.region))
|
||||
if allowGcAfterwards:
|
||||
|
||||
Reference in New Issue
Block a user