1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team 2008
5 * Simple mark/sweep, collecting whole blocks.
7 * Documentation on the architecture of the Garbage Collector can be
8 * found in the online commentary:
10 * http://hackage.haskell.org/trac/ghc/wiki/Commentary/Rts/Storage/GC
12 * ---------------------------------------------------------------------------*/
22 bdescr *bd, *prev, *next;
24 nat freed, resid, fragd, blocks, live;
26 ASSERT(countBlocks(step->old_blocks) == step->n_old_blocks);
28 live = 0; // estimate of live data in this gen
33 for (bd = step->old_blocks; bd != NULL; bd = next)
37 if (!(bd->flags & BF_MARKED)) {
44 for (i = 0; i < BLOCK_SIZE_W / BITS_IN(W_); i++)
46 if (bd->u.bitmap[i] != 0) resid++;
48 live += resid * BITS_IN(W_);
55 step->old_blocks = next;
64 if (resid < (BLOCK_SIZE_W * 3) / (BITS_IN(W_) * 4)) {
66 bd->flags |= BF_FRAGMENTED;
71 step->live_estimate = live;
73 trace(DEBUG_gc|TRACE_gc, "sweeping: %d blocks, %d were copied, %d freed (%d%%), %d are fragmented, live estimate: %ld%%",
74 step->n_old_blocks + freed,
75 step->n_old_blocks - blocks + freed,
77 blocks == 0 ? 0 : (freed * 100) / blocks,
79 (unsigned long)((blocks - freed) == 0 ? 0 : ((live / BLOCK_SIZE_W) * 100) / (blocks - freed)));
81 ASSERT(countBlocks(step->old_blocks) == step->n_old_blocks);