6dcb50b1aabc014624223d70faee52603009ba96
[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://ghc.haskell.org/trac/ghc/wiki/Commentary/Rts/Storage/GC
11 *
12 * ---------------------------------------------------------------------------*/
13
14 #pragma once
15
16 #include "BeginPrivate.h"
17
18 INLINE_HEADER void
19 mark(StgPtr p, bdescr *bd)
20 {
21 uint32_t offset_within_block = p - bd->start; // in words
22 StgPtr bitmap_word = (StgPtr)bd->u.bitmap +
23 (offset_within_block / (sizeof(W_)*BITS_PER_BYTE));
24 StgWord bit_mask = (StgWord)1 << (offset_within_block & (sizeof(W_)*BITS_PER_BYTE - 1));
25 *bitmap_word |= bit_mask;
26 }
27
28 INLINE_HEADER void
29 unmark(StgPtr p, bdescr *bd)
30 {
31 uint32_t offset_within_block = p - bd->start; // in words
32 StgPtr bitmap_word = (StgPtr)bd->u.bitmap +
33 (offset_within_block / (sizeof(W_)*BITS_PER_BYTE));
34 StgWord bit_mask = (StgWord)1 << (offset_within_block & (sizeof(W_)*BITS_PER_BYTE - 1));
35 *bitmap_word &= ~bit_mask;
36 }
37
38 INLINE_HEADER StgWord
39 is_marked(StgPtr p, bdescr *bd)
40 {
41 uint32_t offset_within_block = p - bd->start; // in words
42 StgPtr bitmap_word = (StgPtr)bd->u.bitmap +
43 (offset_within_block / (sizeof(W_)*BITS_PER_BYTE));
44 StgWord bit_mask = (StgWord)1 << (offset_within_block & (sizeof(W_)*BITS_PER_BYTE - 1));
45 return (*bitmap_word & bit_mask);
46 }
47
48 void compact (StgClosure *static_objects);
49
50 #include "EndPrivate.h"