Declare RTS-private prototypes with __attribute__((visibility("hidden")))
[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 #pragma GCC visibility push(hidden)
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 extern nat alloc_blocks;
29 extern nat alloc_blocks_lim;
30
31 INLINE_HEADER rtsBool
32 doYouWantToGC( void )
33 {
34   return (alloc_blocks >= alloc_blocks_lim);
35 }
36
37 /* for splitting blocks groups in two */
38 bdescr * splitLargeBlock (bdescr *bd, nat blocks);
39
40 /* -----------------------------------------------------------------------------
41    Generational garbage collection support
42
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.
47
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.
52
53    updateWithPermIndirection(p1,p2)  As above but uses a permanent indir.
54
55    -------------------------------------------------------------------------- */
56
57 /*
58  * Storage manager mutex
59  */
60 #if defined(THREADED_RTS)
61 extern Mutex sm_mutex;
62 #endif
63
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);
68 #else
69 #define ACQUIRE_SM_LOCK
70 #define RELEASE_SM_LOCK
71 #define ASSERT_SM_LOCK()
72 #endif
73
74 INLINE_HEADER void
75 recordMutableGen(StgClosure *p, nat gen_no)
76 {
77     bdescr *bd;
78
79     bd = generations[gen_no].mut_list;
80     if (bd->free >= bd->start + BLOCK_SIZE_W) {
81         bdescr *new_bd;
82         new_bd = allocBlock();
83         new_bd->link = bd;
84         bd = new_bd;
85         generations[gen_no].mut_list = bd;
86     }
87     *bd->free++ = (StgWord)p;
88
89 }
90
91 INLINE_HEADER void
92 recordMutableGenLock(StgClosure *p, nat gen_no)
93 {
94     ACQUIRE_SM_LOCK;
95     recordMutableGen(p,gen_no);
96     RELEASE_SM_LOCK;
97 }
98
99 INLINE_HEADER void
100 recordMutable(StgClosure *p)
101 {
102     bdescr *bd;
103     ASSERT(closure_MUTABLE(p));
104     bd = Bdescr((P_)p);
105     if (bd->gen_no > 0) recordMutableGen(p, bd->gen_no);
106 }
107
108 INLINE_HEADER void
109 recordMutableLock(StgClosure *p)
110 {
111     ACQUIRE_SM_LOCK;
112     recordMutable(p);
113     RELEASE_SM_LOCK;
114 }
115
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    -------------------------------------------------------------------------- */
122
123 void dirty_MUT_VAR(StgRegTable *reg, StgClosure *p);
124
125 /* -----------------------------------------------------------------------------
126    Similarly, the write barrier for MVARs
127    -------------------------------------------------------------------------- */
128
129 void dirty_MVAR(StgRegTable *reg, StgClosure *p);
130
131 /* -----------------------------------------------------------------------------
132    Nursery manipulation
133    -------------------------------------------------------------------------- */
134
135 void     resetNurseries       ( void );
136 void     resizeNurseries      ( nat blocks );
137 void     resizeNurseriesFixed ( nat blocks );
138 lnat     countNurseryBlocks   ( void );
139
140 /* -----------------------------------------------------------------------------
141    Stats 'n' DEBUG stuff
142    -------------------------------------------------------------------------- */
143
144 extern ullong total_allocated;
145
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);
152
153 #if defined(DEBUG)
154 void    memInventory       (rtsBool show);
155 void    checkSanity        (void);
156 nat     countBlocks        (bdescr *);
157 void    checkNurserySanity (step *stp);
158 #endif
159
160 /* ----------------------------------------------------------------------------
161    Storage manager internal APIs and globals
162    ------------------------------------------------------------------------- */
163
164 #define END_OF_STATIC_LIST ((StgClosure*)1)
165
166 void move_TSO  (StgTSO *src, StgTSO *dest);
167
168 extern StgClosure * caf_list;
169 extern StgClosure * revertible_caf_list;
170
171 #pragma GCC visibility pop
172
173 #endif /* SM_STORAGE_H */