e71f4374fb012c9dc88fce914761312ea9c4a50f
[ghc-hetmet.git] / rts / sm / GCUtils.h
1 /* ----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team 1998-2008
4  *
5  * Generational garbage collector: utilities
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 #include "SMP.h"
15
16 bdescr *allocBlock_sync(void);
17 void    freeChain_sync(bdescr *bd);
18
19 void    push_scanned_block   (bdescr *bd, step_workspace *ws);
20 StgPtr  todo_block_full      (nat size, step_workspace *ws);
21 StgPtr  alloc_todo_block     (step_workspace *ws, nat size);
22
23 bdescr *grab_local_todo_block  (step_workspace *ws);
24 bdescr *steal_todo_block       (nat s);
25
26 // Returns true if a block is partially full.  This predicate is used to try
27 // to re-use partial blocks wherever possible, and to reduce wastage.
28 // We might need to tweak the actual value.
29 INLINE_HEADER rtsBool
30 isPartiallyFull(bdescr *bd)
31 {
32     return (bd->free + WORK_UNIT_WORDS < bd->start + BLOCK_SIZE_W);
33 }
34
35
36 #if DEBUG
37 void printMutableList (generation *gen);
38 #endif
39
40 // Version of recordMutableGen for use during GC.  This uses the
41 // mutable lists attached to the current gc_thread structure, which
42 // are the same as the mutable lists on the Capability.
43 INLINE_HEADER void
44 recordMutableGen_GC (StgClosure *p, nat gen_no)
45 {
46     bdescr *bd;
47
48     bd = gct->mut_lists[gen_no];
49     if (bd->free >= bd->start + BLOCK_SIZE_W) {
50         bdescr *new_bd;
51         new_bd = allocBlock_sync();
52         new_bd->link = bd;
53         bd = new_bd;
54         gct->mut_lists[gen_no] = bd;
55     }
56     *bd->free++ = (StgWord)p;
57 }