more sysasserts for allocator/gc
This commit is contained in:
parent
92e1a21b26
commit
e6b3f50c7f
8 changed files with 38 additions and 24 deletions
|
|
@ -478,6 +478,7 @@ proc getSmallChunk(a: var TMemRegion): PSmallChunk =
|
|||
result = cast[PSmallChunk](res)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
proc isAllocatedPtr(a: TMemRegion, p: pointer): bool
|
||||
|
||||
proc rawAlloc(a: var TMemRegion, requestedSize: int): pointer =
|
||||
sysAssert(roundup(65, 8) == 72, "rawAlloc 1")
|
||||
|
|
@ -537,7 +538,8 @@ proc rawAlloc0(a: var TMemRegion, requestedSize: int): pointer =
|
|||
result = rawAlloc(a, requestedSize)
|
||||
zeroMem(result, requestedSize)
|
||||
|
||||
proc rawDealloc(a: var TMemRegion, p: pointer) =
|
||||
proc rawDealloc(a: var TMemRegion, p: pointer) =
|
||||
sysAssert(isAllocatedPtr(a, p), "rawDealloc: no allocated pointer!")
|
||||
var c = pageAddr(p)
|
||||
if isSmallChunk(c):
|
||||
# `p` is within a small chunk:
|
||||
|
|
|
|||
|
|
@ -222,11 +222,8 @@ proc rtlAddZCT(c: PCell) {.rtl, inl.} =
|
|||
ReleaseSys(HeapLock)
|
||||
|
||||
proc decRef(c: PCell) {.inline.} =
|
||||
when stressGC:
|
||||
if c.refcount <% rcIncrement:
|
||||
writeCell("broken cell", c)
|
||||
sysAssert(isAllocatedPtr(gch.region, c), "decRef: interiorPtr")
|
||||
sysAssert(c.refcount >=% rcIncrement, "decRef")
|
||||
#if c.refcount <% rcIncrement: quit("leck mich")
|
||||
if --c.refcount:
|
||||
rtlAddZCT(c)
|
||||
elif canBeCycleRoot(c):
|
||||
|
|
@ -235,6 +232,7 @@ proc decRef(c: PCell) {.inline.} =
|
|||
rtlAddCycleRoot(c)
|
||||
|
||||
proc incRef(c: PCell) {.inline.} =
|
||||
sysAssert(isAllocatedPtr(gch.region, c), "incRef: interiorPtr")
|
||||
++c.refcount
|
||||
if canBeCycleRoot(c):
|
||||
rtlAddCycleRoot(c)
|
||||
|
|
@ -500,6 +498,7 @@ proc doOperation(p: pointer, op: TWalkOp) =
|
|||
sysAssert(c != nil, "doOperation: 1")
|
||||
case op # faster than function pointers because of easy prediction
|
||||
of waZctDecRef:
|
||||
sysAssert(isAllocatedPtr(gch.region, c), "decRef: waZctDecRef")
|
||||
sysAssert(c.refcount >=% rcIncrement, "doOperation 2")
|
||||
c.refcount = c.refcount -% rcIncrement
|
||||
when logGC: writeCell("decref (from doOperation)", c)
|
||||
|
|
@ -727,8 +726,10 @@ proc CollectZCT(gch: var TGcHeap) =
|
|||
var L = addr(gch.zct.len)
|
||||
while L[] > 0:
|
||||
var c = gch.zct.d[0]
|
||||
sysAssert(isAllocatedPtr(gch.region, c), "CollectZCT: isAllocatedPtr")
|
||||
# remove from ZCT:
|
||||
sysAssert((c.refcount and rcZct) == rcZct, "collectZCT")
|
||||
|
||||
c.refcount = c.refcount and not colorMask
|
||||
gch.zct.d[0] = gch.zct.d[L[] - 1]
|
||||
dec(L[])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue