From 86bf97a73001b3ffc856755a80097ee303d0492b Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Sun, 20 Jan 2013 21:19:49 +0200 Subject: cleaned up some debugging code --- lib/system/gc.nim | 99 ++++++++++++++++----------------------------------- lib/system/mmdisp.nim | 6 ++-- lib/system/sysstr.nim | 1 - 3 files changed, 33 insertions(+), 73 deletions(-) (limited to 'lib/system') diff --git a/lib/system/gc.nim b/lib/system/gc.nim index b870e9f8e..a5cd9a2b0 100755 --- a/lib/system/gc.nim +++ b/lib/system/gc.nim @@ -96,6 +96,8 @@ const # XXX: still has problems in release mode in the compiler itself. # investigate how it affects growObj + CollectCyclesStats = false + type TWalkOp = enum waPush @@ -203,8 +205,6 @@ proc addZCT(zct: var TCellSeq, c: PCell) {.noinline.} = if c.isBitDown(rcZct): c.setBit rcZct zct.add c - # writecell("adding to ZCT 1", c) - # cprintf ("called from %d\n", framePtr.prev.line) template setStackTop(gch) = # This must be called immediately after we enter the GC code @@ -257,7 +257,6 @@ proc forAllChildrenAux(dest: Pointer, mt: PNimType, op: TWalkOp) # we need the prototype here for debugging purposes proc prepareDealloc(cell: PCell) = - # writecell("finalizers", cell) if cell.typ.finalizer != nil: # the finalizer could invoke something that # allocates memory; this could trigger a garbage @@ -397,7 +396,6 @@ template doDecRef(cc: PCell, # this is the last reference from the heap # add to a zero-count-table that will be matched against stack pointers rtlAddZCT(c) - # writeCell("decref to 0", c) else: when cycleFlag != Acyclic: if cycleFlag == Cyclic or canBeCycleRoot(c): @@ -559,7 +557,6 @@ proc addNewObjToZCT(res: PCell, gch: var TGcHeap) {.inline.} = # all slots 68% var L = gch.zct.len var d = gch.zct.d - #writecell("ZCT ADDING 2", res) when true: # loop unrolled for performance: template replaceZctEntry(i: expr) = @@ -622,7 +619,6 @@ proc rawNewObj(typ: PNimType, size: int, gch: var TGcHeap, rc1: bool): pointer = addNewObjToZCT(res, gch) if NewObjectsAreCycleRoots and canBeCycleRoot(res): - # writeCell("cyclic allocation", res) res.setBit(rcInCycleRoots) res.setColor rcCycleCandidate gch.cycleRoots.add res @@ -647,7 +643,6 @@ proc freeCell(gch: var TGcHeap, c: PCell) = else: sysAssert(c.typ != nil, "collectCycles") zeroMem(c, sizeof(TCell)) - # writecell("nuked cell", c) template eraseAt(cells: var TCellSeq, at: int): stmt = cells.d[at] = cells.d[cells.len - 1] @@ -706,16 +701,13 @@ proc growObj(old: pointer, newsize: int, gch: var TGcHeap): pointer = var d = gch.zct.d while j >= 0: if d[j] == ol: - #writecell("replaced old", ol) d[j] = res - #writecell("replaced new", res) break dec(j) if ol.isBitUp(rcInCycleRoots): for i in 0 .. 0: repeat - # quit 1 - var gcDebugging* = false -var vis*: proc (a: pointer, b: PNimType) - -proc debugNode(n: ptr TNimNode) = - c_fprintf(c_stdout, "node %s\n", n.name) - for i in 0..n.len-1: - debugNode(n.sons[i]) - -proc debugTyp(x: PNimType) = - c_fprintf(c_stdout, "type %d\n", x.kind) - if x.node != nil: - debugNode(x.node) var seqdbg* : proc (s: PGenericSeq) {.cdecl.} @@ -992,7 +973,7 @@ proc gcMark(gch: var TGcHeap, p: pointer) {.inline.} = # mark the cell: if objStart.isBitDown(rcReallyDead): if gcDebugging: - writeCell("marking ", objStart) + # writeCell("marking ", objStart) else: inc objStart.refcount, rcIncrement gch.decStack.add objStart @@ -1174,18 +1155,14 @@ proc releaseCell(gch: var TGcHeap, cell: PCell) = prepareDealloc(cell) cell.setColor rcReallyDead - #writecell("RELEASING ", cell) - let l1 = gch.tempStack.len cell.forAllChildren waPush let l2 = gch.tempStack.len for i in l1 .. 0: var c = gch.zct.d[0] - if c.isBitDown(rcZct): - writecell("BAD ZCT", c) - quit 1 - # writecell("ZCT PROCESS", c) + sysAssert c.isBitUp(rcZct), "CollectZCT: rcZct missing!" sysAssert(isAllocatedPtr(gch.region, c), "CollectZCT: isAllocatedPtr") - # remove from ZCT: - sysAssert((c.refcount and rcZct) == rcZct, "collectZCT") + # remove from ZCT: c.clearBit(rcZct) gch.zct.d[0] = gch.zct.d[L[] - 1] dec(L[]) @@ -1238,13 +1207,9 @@ proc CollectZCT(gch: var TGcHeap): bool = # freed. **KEEP THIS IN MIND WHEN MAKING THIS INCREMENTAL!** if c.color == rcRetiredBuffer: if c.isBitDown(rcInCycleRoots): - # writecell("retired buffer", c) freeCell(gch, c) else: - if c.color == rcReallyDead: - # writeCell("ReallyDead in ZCT?", c) - - # writecell("bad cell in zct", c) + # if c.color == rcReallyDead: writeCell("ReallyDead in ZCT?", c) releaseCell(gch, c) when withRealtime: if steps == 0: @@ -1270,7 +1235,6 @@ proc unmarkStackAndRegisters(gch: var TGcHeap) = sysAssert c.typ != nil, "unmarkStackAndRegisters 2" if c.color == rcRetiredBuffer: - # writecell("unmark retired", c) continue # XXX no need for an atomic dec here: @@ -1284,11 +1248,8 @@ proc unmarkStackAndRegisters(gch: var TGcHeap) = # a leak if it's orphaned through the stack reference # that's because the write-barrier won't be executed for stack # locations - #writeCell("restoring balance cycle roots", c) addCycleRoot(gch.cycleRoots, c) - #writecell("unmark stack cell", c) - gch.decStack.len = 0 proc collectCTBody(gch: var TGcHeap) = diff --git a/lib/system/mmdisp.nim b/lib/system/mmdisp.nim index 28ef67781..9bf9c1e67 100755 --- a/lib/system/mmdisp.nim +++ b/lib/system/mmdisp.nim @@ -14,14 +14,14 @@ {.push checks:off.} const - debugGC = true # we wish to debug the GC... + debugGC = false # we wish to debug the GC... logGC = false - traceGC = true # extensive debugging + traceGC = false # extensive debugging alwaysCycleGC = false alwaysGC = false # collect after every memory allocation (for debugging) leakDetector = false overwriteFree = false - trackAllocationSource = true or leakDetector + trackAllocationSource = leakDetector cycleGC = true # (de)activate the cycle GC reallyDealloc = true # for debugging purposes this can be set to false diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim index 8314362f3..bd830d213 100755 --- a/lib/system/sysstr.nim +++ b/lib/system/sysstr.nim @@ -213,7 +213,6 @@ proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {. doDecRef(gch.tempStack.d[i], LocalHeap, MaybeCyclic) gch.tempStack.len = len0 - # XXX add a proper addCycleRoot barrier here! # and set the memory to nil: zeroMem(cast[pointer](cast[TAddress](result) +% GenericSeqSize +% (newLen*%elemSize)), (result.len-%newLen) *% elemSize) -- cgit 1.4.1-2-gfad0