Mark/compact: use a dynamically-sized mark stack, and don't do linear scan
[ghc.git] / rts / sm / Compact.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team 1998-2008
4 *
5 * Compacting garbage collector
6 *
7 * Documentation on the architecture of the Garbage Collector can be
8 * found in the online commentary:
9 *
10 * http://hackage.haskell.org/trac/ghc/wiki/Commentary/Rts/Storage/GC
11 *
12 * ---------------------------------------------------------------------------*/
13
14 #ifndef SM_COMPACT_H
15 #define SM_COMPACT_H
16
17 BEGIN_RTS_PRIVATE
18
19 INLINE_HEADER void
20 mark(StgPtr p, bdescr *bd)
21 {
22 nat offset_within_block = p - bd->start; // in words
23 StgPtr bitmap_word = (StgPtr)bd->u.bitmap +
24 (offset_within_block / (sizeof(W_)*BITS_PER_BYTE));
25 StgWord bit_mask = (StgWord)1 << (offset_within_block & (sizeof(W_)*BITS_PER_BYTE - 1));
26 *bitmap_word |= bit_mask;
27 }
28
29 INLINE_HEADER void
30 unmark(StgPtr p, bdescr *bd)
31 {
32 nat offset_within_block = p - bd->start; // in words
33 StgPtr bitmap_word = (StgPtr)bd->u.bitmap +
34 (offset_within_block / (sizeof(W_)*BITS_PER_BYTE));
35 StgWord bit_mask = (StgWord)1 << (offset_within_block & (sizeof(W_)*BITS_PER_BYTE - 1));
36 *bitmap_word &= ~bit_mask;
37 }
38
39 INLINE_HEADER StgWord
40 is_marked(StgPtr p, bdescr *bd)
41 {
42 nat offset_within_block = p - bd->start; // in words
43 StgPtr bitmap_word = (StgPtr)bd->u.bitmap +
44 (offset_within_block / (sizeof(W_)*BITS_PER_BYTE));
45 StgWord bit_mask = (StgWord)1 << (offset_within_block & (sizeof(W_)*BITS_PER_BYTE - 1));
46 return (*bitmap_word & bit_mask);
47 }
48
49 void compact (StgClosure *static_objects);
50
51 END_RTS_PRIVATE
52
53 #endif /* SM_COMPACT_H */