copyright updates and add Commentary links
[ghc.git] / rts / sm / Compact.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team 1998-2005
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 GCCOMPACT_H
15 #define GCCOMPACT_H
16
17 INLINE_HEADER rtsBool
18 mark_stack_empty(void)
19 {
20 return mark_sp == mark_stack;
21 }
22
23 INLINE_HEADER rtsBool
24 mark_stack_full(void)
25 {
26 return mark_sp >= mark_splim;
27 }
28
29 INLINE_HEADER void
30 reset_mark_stack(void)
31 {
32 mark_sp = mark_stack;
33 }
34
35 INLINE_HEADER void
36 push_mark_stack(StgPtr p)
37 {
38 *mark_sp++ = p;
39 }
40
41 INLINE_HEADER StgPtr
42 pop_mark_stack(void)
43 {
44 return *--mark_sp;
45 }
46
47 INLINE_HEADER void
48 mark(StgPtr p, bdescr *bd)
49 {
50 nat offset_within_block = p - bd->start; // in words
51 StgPtr bitmap_word = (StgPtr)bd->u.bitmap +
52 (offset_within_block / (sizeof(W_)*BITS_PER_BYTE));
53 StgWord bit_mask = (StgWord)1 << (offset_within_block & (sizeof(W_)*BITS_PER_BYTE - 1));
54 *bitmap_word |= bit_mask;
55 }
56
57 INLINE_HEADER void
58 unmark(StgPtr p, bdescr *bd)
59 {
60 nat offset_within_block = p - bd->start; // in words
61 StgPtr bitmap_word = (StgPtr)bd->u.bitmap +
62 (offset_within_block / (sizeof(W_)*BITS_PER_BYTE));
63 StgWord bit_mask = (StgWord)1 << (offset_within_block & (sizeof(W_)*BITS_PER_BYTE - 1));
64 *bitmap_word &= ~bit_mask;
65 }
66
67 INLINE_HEADER StgWord
68 is_marked(StgPtr p, bdescr *bd)
69 {
70 nat offset_within_block = p - bd->start; // in words
71 StgPtr bitmap_word = (StgPtr)bd->u.bitmap +
72 (offset_within_block / (sizeof(W_)*BITS_PER_BYTE));
73 StgWord bit_mask = (StgWord)1 << (offset_within_block & (sizeof(W_)*BITS_PER_BYTE - 1));
74 return (*bitmap_word & bit_mask);
75 }
76
77 void compact(void);
78
79 #endif /* GCCOMPACT_H */