summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-11-30 07:44:32 +0100
committerAraq <rumpf_a@web.de>2015-12-01 00:53:30 +0100
commit9ed635d5c092afdcbd9a6313ccf1dcd37c5344db (patch)
treef98e87e4191637942d74fe7e17b2d2926e5e159a
parent070403ca5eb9e7c1c9cdea5f930022408fca5000 (diff)
downloadNim-9ed635d5c092afdcbd9a6313ccf1dcd37c5344db.tar.gz
only mark roots when marking
-rw-r--r--lib/system/gc2.nim9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/system/gc2.nim b/lib/system/gc2.nim
index 89f299436..1a51284f0 100644
--- a/lib/system/gc2.nim
+++ b/lib/system/gc2.nim
@@ -604,6 +604,7 @@ proc sweep(gch: var GcHeap): bool =
     if isCell(x):
       # cast to PCell is correct here:
       var c = cast[PCell](x)
+      gcAssert c.color != rcGrey, "cell is still grey?"
       if c.color == rcWhite: freeCyclicCell(gch, c)
       else: c.setColor(rcWhite)
     checkTime()
@@ -613,7 +614,7 @@ proc sweep(gch: var GcHeap): bool =
   result = true
 
 proc markS(gch: var GcHeap, c: PCell) =
-  if c.color != rcGrey:
+  if c.color == rcWhite:
     c.setColor(rcGrey)
     add(gch.greyStack, c)
   #forAllChildren(c, waMarkGrey)
@@ -690,7 +691,7 @@ proc doOperation(p: pointer, op: WalkOp) =
     else:
       markS(gch, c)
   of waMarkGrey:
-    if c.color != rcBlack:
+    if c.color == rcWhite:
       c.setColor(rcGrey)
       add(gch.greyStack, c)
   #of waDebug: debugGraph(c)
@@ -703,10 +704,10 @@ proc collectZCT(gch: var GcHeap): bool {.benign.}
 proc collectCycles(gch: var GcHeap): bool =
   # ensure the ZCT 'color' is not used:
   while gch.zct.len > 0: discard collectZCT(gch)
-  markGlobals(gch)
-  markLocals(gch)
   case gch.phase
   of Phase.None, Phase.Marking:
+    markGlobals(gch)
+    markLocals(gch)
     gch.phase = Phase.Marking
     if markIncremental(gch):
       gch.phase = Phase.Sweeping