move sanity checking code from Storage.c to Sanity.c
[ghc-hetmet.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 BEGIN_RTS_PRIVATE
15
16 /* -----------------------------------------------------------------------------
17    Initialisation / De-initialisation
18    -------------------------------------------------------------------------- */
19
20 void initStorage(void);
21 void exitStorage(void);
22 void freeStorage(void);
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           cap->r.rNursery->n_large_blocks >= alloc_blocks_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    recordMutable(StgPtr p)       Informs the garbage collector that a
42                                  previously immutable object has
43                                  become (permanently) mutable.  Used
44                                  by thawArray and similar.
45
46    updateWithIndirection(p1,p2)  Updates the object at p1 with an
47                                  indirection pointing to p2.  This is
48                                  normally called for objects in an old
49                                  generation (>0) when they are updated.
50
51    updateWithPermIndirection(p1,p2)  As above but uses a permanent indir.
52
53    -------------------------------------------------------------------------- */
54
55 /*
56  * Storage manager mutex
57  */
58 #if defined(THREADED_RTS)
59 extern Mutex sm_mutex;
60 #endif
61
62 #if defined(THREADED_RTS)
63 #define ACQUIRE_SM_LOCK   ACQUIRE_LOCK(&sm_mutex);
64 #define RELEASE_SM_LOCK   RELEASE_LOCK(&sm_mutex);
65 #define ASSERT_SM_LOCK()  ASSERT_LOCK_HELD(&sm_mutex);
66 #else
67 #define ACQUIRE_SM_LOCK
68 #define RELEASE_SM_LOCK
69 #define ASSERT_SM_LOCK()
70 #endif
71
72 INLINE_HEADER void
73 recordMutableGen(StgClosure *p, nat gen_no)
74 {
75     bdescr *bd;
76
77     bd = generations[gen_no].mut_list;
78     if (bd->free >= bd->start + BLOCK_SIZE_W) {
79         bdescr *new_bd;
80         new_bd = allocBlock();
81         new_bd->link = bd;
82         bd = new_bd;
83         generations[gen_no].mut_list = bd;
84     }
85     *bd->free++ = (StgWord)p;
86
87 }
88
89 INLINE_HEADER void
90 recordMutableGenLock(StgClosure *p, nat gen_no)
91 {
92     ACQUIRE_SM_LOCK;
93     recordMutableGen(p,gen_no);
94     RELEASE_SM_LOCK;
95 }
96
97 INLINE_HEADER void
98 recordMutable(StgClosure *p)
99 {
100     bdescr *bd;
101     ASSERT(closure_MUTABLE(p));
102     bd = Bdescr((P_)p);
103     if (bd->gen_no > 0) recordMutableGen(p, bd->gen_no);
104 }
105
106 INLINE_HEADER void
107 recordMutableLock(StgClosure *p)
108 {
109     ACQUIRE_SM_LOCK;
110     recordMutable(p);
111     RELEASE_SM_LOCK;
112 }
113
114 /* -----------------------------------------------------------------------------
115    The write barrier for MVARs
116    -------------------------------------------------------------------------- */
117
118 void dirty_MVAR(StgRegTable *reg, StgClosure *p);
119
120 /* -----------------------------------------------------------------------------
121    Nursery manipulation
122    -------------------------------------------------------------------------- */
123
124 extern step *nurseries;
125
126 void     resetNurseries       ( void );
127 void     resizeNurseries      ( nat blocks );
128 void     resizeNurseriesFixed ( nat blocks );
129 lnat     countNurseryBlocks   ( void );
130
131 /* -----------------------------------------------------------------------------
132    Stats 'n' DEBUG stuff
133    -------------------------------------------------------------------------- */
134
135 extern ullong total_allocated;
136
137 lnat    calcAllocated  (void);
138 lnat    calcLiveBlocks (void);
139 lnat    calcLiveWords  (void);
140 lnat    countOccupied  (bdescr *bd);
141 lnat    calcNeeded     (void);
142 HsInt64 getAllocations (void);
143
144 #if defined(DEBUG)
145 void    memInventory       (rtsBool show);
146 nat     countBlocks        (bdescr *);
147 #endif
148
149 /* ----------------------------------------------------------------------------
150    Storage manager internal APIs and globals
151    ------------------------------------------------------------------------- */
152
153 #define END_OF_STATIC_LIST ((StgClosure*)1)
154
155 void move_TSO  (StgTSO *src, StgTSO *dest);
156
157 extern StgClosure * caf_list;
158 extern StgClosure * revertible_caf_list;
159
160 END_RTS_PRIVATE
161
162 #endif /* SM_STORAGE_H */