Keep the remembered sets local to each thread during parallel GC
[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 bdescr *grab_todo_block      (step_workspace *ws);
21 StgPtr  todo_block_full      (nat size, step_workspace *ws);
22 StgPtr  alloc_todo_block     (step_workspace *ws, nat size);
23
24 // Returns true if a block is partially full.  This predicate is used to try
25 // to re-use partial blocks wherever possible, and to reduce wastage.
26 // We might need to tweak the actual value.
27 INLINE_HEADER rtsBool
28 isPartiallyFull(bdescr *bd)
29 {
30     return (bd->free + WORK_UNIT_WORDS < bd->start + BLOCK_SIZE_W);
31 }
32
33
34 #if DEBUG
35 void printMutableList (generation *gen);
36 #endif
37
38 // Version of recordMutableGen for use during GC.  This uses the
39 // mutable lists attached to the current gc_thread structure, which
40 // are the same as the mutable lists on the Capability.
41 INLINE_HEADER void
42 recordMutableGen_GC (StgClosure *p, nat gen_no)
43 {
44     bdescr *bd;
45
46     bd = gct->mut_lists[gen_no];
47     if (bd->free >= bd->start + BLOCK_SIZE_W) {
48         bdescr *new_bd;
49         new_bd = allocBlock_sync();
50         new_bd->link = bd;
51         bd = new_bd;
52         gct->mut_lists[gen_no] = bd;
53     }
54     *bd->free++ = (StgWord)p;
55 }