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