GC refactoring and cleanup
[ghc.git] / rts / sm / Storage.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1998-2009
4 *
5 * External Storage Manger Interface
6 *
7 * ---------------------------------------------------------------------------*/
8
9 #ifndef SM_STORAGE_H
10 #define SM_STORAGE_H
11
12 #include "Capability.h"
13
14 #include "BeginPrivate.h"
15
16 /* -----------------------------------------------------------------------------
17 Initialisation / De-initialisation
18 -------------------------------------------------------------------------- */
19
20 void initStorage(void);
21 void exitStorage(void);
22 void freeStorage(rtsBool free_heap);
23
24 /* -----------------------------------------------------------------------------
25 Storage manager state
26 -------------------------------------------------------------------------- */
27
28 INLINE_HEADER rtsBool
29 doYouWantToGC( Capability *cap )
30 {
31 return (cap->r.rCurrentNursery->link == NULL ||
32 g0->n_new_large_words >= large_alloc_lim);
33 }
34
35 /* for splitting blocks groups in two */
36 bdescr * splitLargeBlock (bdescr *bd, nat blocks);
37
38 /* -----------------------------------------------------------------------------
39 Generational garbage collection support
40
41 updateWithIndirection(p1,p2) Updates the object at p1 with an
42 indirection pointing to p2. This is
43 normally called for objects in an old
44 generation (>0) when they are updated.
45
46 updateWithPermIndirection(p1,p2) As above but uses a permanent indir.
47
48 -------------------------------------------------------------------------- */
49
50 /*
51 * Storage manager mutex
52 */
53 #if defined(THREADED_RTS)
54 extern Mutex sm_mutex;
55 #endif
56
57 #if defined(THREADED_RTS)
58 #define ACQUIRE_SM_LOCK ACQUIRE_LOCK(&sm_mutex);
59 #define RELEASE_SM_LOCK RELEASE_LOCK(&sm_mutex);
60 #define ASSERT_SM_LOCK() ASSERT_LOCK_HELD(&sm_mutex);
61 #else
62 #define ACQUIRE_SM_LOCK
63 #define RELEASE_SM_LOCK
64 #define ASSERT_SM_LOCK()
65 #endif
66
67 /* -----------------------------------------------------------------------------
68 The write barrier for MVARs
69 -------------------------------------------------------------------------- */
70
71 void dirty_MVAR(StgRegTable *reg, StgClosure *p);
72
73 /* -----------------------------------------------------------------------------
74 Nursery manipulation
75 -------------------------------------------------------------------------- */
76
77 extern nursery *nurseries;
78
79 void resetNurseries ( void );
80 lnat clearNurseries ( void );
81 void resizeNurseries ( nat blocks );
82 void resizeNurseriesFixed ( nat blocks );
83 lnat countNurseryBlocks ( void );
84
85 /* -----------------------------------------------------------------------------
86 Stats 'n' DEBUG stuff
87 -------------------------------------------------------------------------- */
88
89 lnat calcAllocated (rtsBool count_nurseries);
90 lnat countOccupied (bdescr *bd);
91 lnat calcNeeded (void);
92
93 lnat gcThreadLiveWords (nat i, nat g);
94 lnat gcThreadLiveBlocks (nat i, nat g);
95
96 lnat genLiveWords (generation *gen);
97 lnat genLiveBlocks (generation *gen);
98
99 lnat calcLiveBlocks (void);
100 lnat calcLiveWords (void);
101
102 /* ----------------------------------------------------------------------------
103 Storage manager internal APIs and globals
104 ------------------------------------------------------------------------- */
105
106 extern bdescr *exec_block;
107
108 #define END_OF_STATIC_LIST ((StgClosure*)1)
109
110 void move_STACK (StgStack *src, StgStack *dest);
111
112 extern StgClosure * caf_list;
113 extern StgClosure * revertible_caf_list;
114
115 #include "EndPrivate.h"
116
117 #endif /* SM_STORAGE_H */