+ performCollection = performCollection'
+
+
+performCollection' :: (RefObj a) => [a] -> StateT TwoSpace IO ()
+performCollection' roots = do oldState <- get
+ modify switchSpaces
+ newState <- get
+ lift (performCollectionIO newState roots)
+ -- [todo hs]: patch gc roots
+
+-- [todo hs] this is slow. merge phases to eliminate list with refs
+performCollectionIO :: (AllocationManager b, RefObj a) => b -> [a] -> IO ()
+performCollectionIO manager refs = do lifeRefs <- liftM concat $ mapM (markTree'' marked mark []) refs
+ evacuateList lifeRefs manager
+ patchAllRefs lifeRefs
+
+switchSpaces :: TwoSpace -> TwoSpace
+switchSpaces old = old { fromHeap = toHeap old,
+ toHeap = fromBase old,
+ fromBase = toBase old,
+ toBase = fromBase old,
+ fromExtreme = toExtreme old,
+ toExtreme = fromExtreme old }
+