1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2009
5 * External Storage Manger Interface
7 * ---------------------------------------------------------------------------*/
12 #pragma GCC visibility push(hidden)
14 /* -----------------------------------------------------------------------------
15 Initialisation / De-initialisation
16 -------------------------------------------------------------------------- */
18 void initStorage(void);
19 void exitStorage(void);
20 void freeStorage(void);
22 /* -----------------------------------------------------------------------------
24 -------------------------------------------------------------------------- */
26 extern bdescr * pinned_object_block;
28 extern nat alloc_blocks;
29 extern nat alloc_blocks_lim;
34 return (alloc_blocks >= alloc_blocks_lim);
37 /* for splitting blocks groups in two */
38 bdescr * splitLargeBlock (bdescr *bd, nat blocks);
40 /* -----------------------------------------------------------------------------
41 Generational garbage collection support
43 recordMutable(StgPtr p) Informs the garbage collector that a
44 previously immutable object has
45 become (permanently) mutable. Used
46 by thawArray and similar.
48 updateWithIndirection(p1,p2) Updates the object at p1 with an
49 indirection pointing to p2. This is
50 normally called for objects in an old
51 generation (>0) when they are updated.
53 updateWithPermIndirection(p1,p2) As above but uses a permanent indir.
55 -------------------------------------------------------------------------- */
58 * Storage manager mutex
60 #if defined(THREADED_RTS)
61 extern Mutex sm_mutex;
64 #if defined(THREADED_RTS)
65 #define ACQUIRE_SM_LOCK ACQUIRE_LOCK(&sm_mutex);
66 #define RELEASE_SM_LOCK RELEASE_LOCK(&sm_mutex);
67 #define ASSERT_SM_LOCK() ASSERT_LOCK_HELD(&sm_mutex);
69 #define ACQUIRE_SM_LOCK
70 #define RELEASE_SM_LOCK
71 #define ASSERT_SM_LOCK()
75 recordMutableGen(StgClosure *p, nat gen_no)
79 bd = generations[gen_no].mut_list;
80 if (bd->free >= bd->start + BLOCK_SIZE_W) {
82 new_bd = allocBlock();
85 generations[gen_no].mut_list = bd;
87 *bd->free++ = (StgWord)p;
92 recordMutableGenLock(StgClosure *p, nat gen_no)
95 recordMutableGen(p,gen_no);
100 recordMutable(StgClosure *p)
103 ASSERT(closure_MUTABLE(p));
105 if (bd->gen_no > 0) recordMutableGen(p, bd->gen_no);
109 recordMutableLock(StgClosure *p)
116 /* -----------------------------------------------------------------------------
117 This is the write barrier for MUT_VARs, a.k.a. IORefs. A
118 MUT_VAR_CLEAN object is not on the mutable list; a MUT_VAR_DIRTY
119 is. When written to, a MUT_VAR_CLEAN turns into a MUT_VAR_DIRTY
120 and is put on the mutable list.
121 -------------------------------------------------------------------------- */
123 void dirty_MUT_VAR(StgRegTable *reg, StgClosure *p);
125 /* -----------------------------------------------------------------------------
126 Similarly, the write barrier for MVARs
127 -------------------------------------------------------------------------- */
129 void dirty_MVAR(StgRegTable *reg, StgClosure *p);
131 /* -----------------------------------------------------------------------------
133 -------------------------------------------------------------------------- */
135 void resetNurseries ( void );
136 void resizeNurseries ( nat blocks );
137 void resizeNurseriesFixed ( nat blocks );
138 lnat countNurseryBlocks ( void );
140 /* -----------------------------------------------------------------------------
141 Stats 'n' DEBUG stuff
142 -------------------------------------------------------------------------- */
144 extern ullong total_allocated;
146 lnat calcAllocated (void);
147 lnat calcLiveBlocks (void);
148 lnat calcLiveWords (void);
149 lnat countOccupied (bdescr *bd);
150 lnat calcNeeded (void);
151 HsInt64 getAllocations (void);
154 void memInventory (rtsBool show);
155 void checkSanity (void);
156 nat countBlocks (bdescr *);
157 void checkNurserySanity (step *stp);
160 /* ----------------------------------------------------------------------------
161 Storage manager internal APIs and globals
162 ------------------------------------------------------------------------- */
164 #define END_OF_STATIC_LIST ((StgClosure*)1)
166 void move_TSO (StgTSO *src, StgTSO *dest);
168 extern StgClosure * caf_list;
169 extern StgClosure * revertible_caf_list;
171 #pragma GCC visibility pop
173 #endif /* SM_STORAGE_H */