GCUtils.h 1.76 KB
Newer Older
1 2
/* ----------------------------------------------------------------------------
 *
3
 * (c) The GHC Team 1998-2008
4 5 6
 *
 * Generational garbage collector: utilities
 *
7 8 9 10 11
 * Documentation on the architecture of the Garbage Collector can be
 * found in the online commentary:
 * 
 *   http://hackage.haskell.org/trac/ghc/wiki/Commentary/Rts/Storage/GC
 *
12 13
 * --------------------------------------------------------------------------*/

Simon Marlow's avatar
Simon Marlow committed
14 15
#ifndef SM_GCUTILS_H
#define SM_GCUTILS_H
16

17
#include "BeginPrivate.h"
18

19
bdescr *allocBlock_sync(void);
20
void    freeChain_sync(bdescr *bd);
21

22 23 24
void    push_scanned_block   (bdescr *bd, gen_workspace *ws);
StgPtr  todo_block_full      (nat size, gen_workspace *ws);
StgPtr  alloc_todo_block     (gen_workspace *ws, nat size);
25

26
bdescr *grab_local_todo_block  (gen_workspace *ws);
Simon Marlow's avatar
Simon Marlow committed
27
#if defined(THREADED_RTS)
28
bdescr *steal_todo_block       (nat s);
Simon Marlow's avatar
Simon Marlow committed
29
#endif
30

31
// Returns true if a block is partially full.  This predicate is used to try
32 33 34 35 36
// to re-use partial blocks wherever possible, and to reduce wastage.
// We might need to tweak the actual value.
INLINE_HEADER rtsBool
isPartiallyFull(bdescr *bd)
{
37
    return (bd->free + WORK_UNIT_WORDS < bd->start + BLOCK_SIZE_W);
38 39 40 41
}


#if DEBUG
42
void printMutableList (bdescr *bd);
43
#endif
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

// Version of recordMutableGen for use during GC.  This uses the
// mutable lists attached to the current gc_thread structure, which
// are the same as the mutable lists on the Capability.
INLINE_HEADER void
recordMutableGen_GC (StgClosure *p, nat gen_no)
{
    bdescr *bd;

    bd = gct->mut_lists[gen_no];
    if (bd->free >= bd->start + BLOCK_SIZE_W) {
	bdescr *new_bd;
	new_bd = allocBlock_sync();
	new_bd->link = bd;
	bd = new_bd;
	gct->mut_lists[gen_no] = bd;
    }
    *bd->free++ = (StgWord)p;
}
Simon Marlow's avatar
Simon Marlow committed
63

64
#include "EndPrivate.h"
65

Simon Marlow's avatar
Simon Marlow committed
66
#endif /* SM_GCUTILS_H */