Make clearNursery free
[ghc.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 #include "BeginPrivate.h"
15
16 /* -----------------------------------------------------------------------------
17 Initialisation / De-initialisation
18 -------------------------------------------------------------------------- */
19
20 void initStorage(void);
21 void exitStorage(void);
22 void freeStorage(rtsBool free_heap);
23
24 // Adding more Capabilities later: this function allocates nurseries
25 // and initialises other storage-related things.
26 void storageAddCapabilities (nat from, nat to);
27
28 /* -----------------------------------------------------------------------------
29 Storage manager state
30 -------------------------------------------------------------------------- */
31
32 INLINE_HEADER rtsBool
33 doYouWantToGC( Capability *cap )
34 {
35 return (cap->r.rCurrentNursery->link == NULL ||
36 g0->n_new_large_words >= large_alloc_lim);
37 }
38
39 /* for splitting blocks groups in two */
40 bdescr * splitLargeBlock (bdescr *bd, W_ blocks);
41
42 /* -----------------------------------------------------------------------------
43 Generational garbage collection support
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 /* -----------------------------------------------------------------------------
72 The write barrier for MVARs and TVARs
73 -------------------------------------------------------------------------- */
74
75 void dirty_MVAR(StgRegTable *reg, StgClosure *p);
76 void dirty_TVAR(Capability *cap, StgTVar *p);
77
78 /* -----------------------------------------------------------------------------
79 Nursery manipulation
80 -------------------------------------------------------------------------- */
81
82 extern nursery *nurseries;
83
84 void resetNurseries ( void );
85 void clearNursery ( Capability *cap );
86 void resizeNurseries ( W_ blocks );
87 void resizeNurseriesFixed ( W_ blocks );
88 W_ countNurseryBlocks ( void );
89
90 /* -----------------------------------------------------------------------------
91 Allocation accounting
92
93 See [Note allocation accounting] in Storage.c
94 -------------------------------------------------------------------------- */
95
96 //
97 // Called when we are finished allocating into a block; account for the amount
98 // allocated in cap->total_allocated.
99 //
100 INLINE_HEADER void finishedNurseryBlock (Capability *cap, bdescr *bd) {
101 cap->total_allocated += bd->free - bd->start;
102 }
103
104 INLINE_HEADER void newNurseryBlock (bdescr *bd) {
105 bd->free = bd->start;
106 }
107
108 void updateNurseriesStats (void);
109 StgWord calcTotalAllocated (void);
110
111 /* -----------------------------------------------------------------------------
112 Stats 'n' DEBUG stuff
113 -------------------------------------------------------------------------- */
114
115 W_ countLargeAllocated (void);
116 W_ countOccupied (bdescr *bd);
117 W_ calcNeeded (rtsBool force_major, W_ *blocks_needed);
118
119 W_ gcThreadLiveWords (nat i, nat g);
120 W_ gcThreadLiveBlocks (nat i, nat g);
121
122 W_ genLiveWords (generation *gen);
123 W_ genLiveBlocks (generation *gen);
124
125 W_ calcLiveBlocks (void);
126 W_ calcLiveWords (void);
127
128 /* ----------------------------------------------------------------------------
129 Storage manager internal APIs and globals
130 ------------------------------------------------------------------------- */
131
132 extern bdescr *exec_block;
133
134 #define END_OF_STATIC_LIST ((StgClosure*)1)
135
136 void move_STACK (StgStack *src, StgStack *dest);
137
138 /* -----------------------------------------------------------------------------
139 CAF lists
140
141 dyn_caf_list (CAFs chained through static_link)
142 This is a chain of all CAFs in the program, used for
143 dynamically-linked GHCi.
144 See Note [dyn_caf_list].
145
146 debug_caf_list (CAFs chained through saved_info)
147 A chain of all *live* CAFs in the program, that does not keep
148 the CAFs alive. Used for detecting when we enter a GC'd CAF,
149 and to give diagnostics with +RTS -DG.
150
151 revertible_caf_list (CAFs chained through static_link)
152 A chain of CAFs in object code loaded with the RTS linker.
153 These CAFs can be reverted to their unevaluated state using
154 revertCAFs.
155 --------------------------------------------------------------------------- */
156
157 extern StgIndStatic * dyn_caf_list;
158 extern StgIndStatic * debug_caf_list;
159 extern StgIndStatic * revertible_caf_list;
160
161 #include "EndPrivate.h"
162
163 #endif /* SM_STORAGE_H */