1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2009
5 * External Storage Manger Interface
7 * ---------------------------------------------------------------------------*/
12 #include "Capability.h"
14 #include "BeginPrivate.h"
16 /* -----------------------------------------------------------------------------
17 Initialisation / De-initialisation
18 -------------------------------------------------------------------------- */
20 void initStorage(void);
21 void exitStorage(void);
22 void freeStorage(rtsBool free_heap);
24 /* -----------------------------------------------------------------------------
26 -------------------------------------------------------------------------- */
29 doYouWantToGC( Capability *cap )
31 return (cap->r.rCurrentNursery->link == NULL ||
32 g0->n_large_blocks >= alloc_blocks_lim);
35 /* for splitting blocks groups in two */
36 bdescr * splitLargeBlock (bdescr *bd, nat blocks);
38 /* -----------------------------------------------------------------------------
39 Generational garbage collection support
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.
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.
51 updateWithPermIndirection(p1,p2) As above but uses a permanent indir.
53 -------------------------------------------------------------------------- */
56 * Storage manager mutex
58 #if defined(THREADED_RTS)
59 extern Mutex sm_mutex;
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);
67 #define ACQUIRE_SM_LOCK
68 #define RELEASE_SM_LOCK
69 #define ASSERT_SM_LOCK()
73 recordMutableGen(StgClosure *p, nat gen_no)
77 bd = generations[gen_no].mut_list;
78 if (bd->free >= bd->start + BLOCK_SIZE_W) {
80 new_bd = allocBlock();
83 generations[gen_no].mut_list = bd;
85 *bd->free++ = (StgWord)p;
90 recordMutableGenLock(StgClosure *p, nat gen_no)
93 recordMutableGen(p,gen_no);
98 recordMutable(StgClosure *p)
101 ASSERT(closure_MUTABLE(p));
103 if (bd->gen_no > 0) recordMutableGen(p, bd->gen_no);
107 recordMutableLock(StgClosure *p)
114 /* -----------------------------------------------------------------------------
115 The write barrier for MVARs
116 -------------------------------------------------------------------------- */
118 void dirty_MVAR(StgRegTable *reg, StgClosure *p);
120 /* -----------------------------------------------------------------------------
122 -------------------------------------------------------------------------- */
124 extern nursery *nurseries;
126 void resetNurseries ( void );
127 void resizeNurseries ( nat blocks );
128 void resizeNurseriesFixed ( nat blocks );
129 lnat countNurseryBlocks ( void );
131 /* -----------------------------------------------------------------------------
132 Stats 'n' DEBUG stuff
133 -------------------------------------------------------------------------- */
135 lnat calcAllocated (void);
136 lnat calcLiveBlocks (void);
137 lnat calcLiveWords (void);
138 lnat countOccupied (bdescr *bd);
139 lnat calcNeeded (void);
141 /* ----------------------------------------------------------------------------
142 Storage manager internal APIs and globals
143 ------------------------------------------------------------------------- */
145 extern bdescr *exec_block;
147 #define END_OF_STATIC_LIST ((StgClosure*)1)
149 void move_TSO (StgTSO *src, StgTSO *dest);
151 extern StgClosure * caf_list;
152 extern StgClosure * revertible_caf_list;
154 #include "EndPrivate.h"
156 #endif /* SM_STORAGE_H */