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 * ---------------------------------------------------------------------------*/
14 #include "PosixSource.h"
24 bdescr *bd, *prev, *next;
26 nat freed, resid, fragd, blocks, live;
28 ASSERT(countBlocks(step->old_blocks) == step->n_old_blocks);
30 live = 0; // estimate of live data in this gen
35 for (bd = step->old_blocks; bd != NULL; bd = next)
39 if (!(bd->flags & BF_MARKED)) {
46 for (i = 0; i < BLOCK_SIZE_W / BITS_IN(W_); i++)
48 if (bd->u.bitmap[i] != 0) resid++;
50 live += resid * BITS_IN(W_);
57 step->old_blocks = next;
66 if (resid < (BLOCK_SIZE_W * 3) / (BITS_IN(W_) * 4)) {
68 bd->flags |= BF_FRAGMENTED;
73 step->live_estimate = live;
75 debugTrace(DEBUG_gc, "sweeping: %d blocks, %d were copied, %d freed (%d%%), %d are fragmented, live estimate: %ld%%",
76 step->n_old_blocks + freed,
77 step->n_old_blocks - blocks + freed,
79 blocks == 0 ? 0 : (freed * 100) / blocks,
81 (unsigned long)((blocks - freed) == 0 ? 0 : ((live / BLOCK_SIZE_W) * 100) / (blocks - freed)));
83 ASSERT(countBlocks(step->old_blocks) == step->n_old_blocks);