1 /* ----------------------------------------------------------------------------
2 * $Id: Closures.h,v 1.35 2003/11/14 14:28:07 stolz Exp $
4 * (c) The GHC Team, 1998-1999
8 * -------------------------------------------------------------------------- */
14 * The Layout of a closure header depends on which kind of system we're
15 * compiling for: profiling, parallel, ticky, etc.
18 /* -----------------------------------------------------------------------------
20 -------------------------------------------------------------------------- */
25 struct _RetainerSet *rs; // Retainer Set
26 StgWord ldvw; // Lag/Drag/Void Word
30 /* -----------------------------------------------------------------------------
32 -------------------------------------------------------------------------- */
35 StgWord procs; /* bitmask indicating on which PEs this closure resides */
38 /* -----------------------------------------------------------------------------
39 The full fixed-size closure header
41 The size of the fixed header is the sum of the optional parts plus a single
42 word for the entry code pointer.
43 -------------------------------------------------------------------------- */
46 const struct _StgInfoTable* info;
55 #define FIXED_HS (sizeof(StgHeader))
57 /* -----------------------------------------------------------------------------
60 For any given closure type (defined in InfoTables.h), there is a
61 corresponding structure defined below. The name of the structure
62 is obtained by concatenating the closure type with '_closure'
63 -------------------------------------------------------------------------- */
65 /* All closures follow the generic format */
69 struct StgClosure_ *payload[FLEXIBLE_ARRAY];
72 /* What a stroke of luck - all our mutable closures follow the same
73 * basic layout, with the mutable link field as the second field after
74 * the header. This means the following structure is the supertype of
78 typedef struct StgMutClosure_ {
81 struct StgMutClosure_ *mut_link;
82 struct StgClosure_ *payload[FLEXIBLE_ARRAY];
92 StgHalfWord arity; /* zero if it is an AP */
94 StgClosure *fun; /* really points to a fun */
95 StgClosure *payload[FLEXIBLE_ARRAY];
98 // AP closures have the same layout, for convenience
103 StgWord size; // number of words in payload
105 StgClosure *payload[FLEXIBLE_ARRAY]; // contains a chunk of *stack*
110 StgClosure *indirectee;
115 StgClosure *indirectee;
116 StgMutClosure *mut_link;
121 StgClosure *indirectee;
122 StgClosure *static_link;
123 struct _StgInfoTable *saved_info;
129 StgWord payload[FLEXIBLE_ARRAY];
135 StgMutClosure *mut_link; /* mutable list */
136 StgClosure *payload[FLEXIBLE_ARRAY];
142 StgMutClosure *mut_link;
145 typedef struct _StgUpdateFrame {
152 StgInt exceptions_blocked;
168 } StgIntCharlikeClosure;
170 /* statically allocated */
175 typedef struct _StgForeignObj {
177 StgAddr data; /* pointer to data in non-haskell-land */
180 typedef struct _StgStableName {
185 typedef struct _StgWeak { /* Weak v */
188 StgClosure *value; /* v */
189 StgClosure *finalizer;
190 struct _StgWeak *link;
193 typedef struct _StgDeadWeak { /* Weak v */
195 struct _StgWeak *link;
198 /* Byte code objects. These are fixed size objects with pointers to
199 * four arrays, designed so that a BCO can be easily "re-linked" to
200 * other BCOs, to facilitate GHC's intelligent recompilation. The
201 * array of instructions is static and not re-generated when the BCO
202 * is re-linked, but the other 3 arrays will be regenerated.
204 * A BCO represents either a function or a stack frame. In each case,
205 * it needs a bitmap to describe to the garbage collector the
206 * pointerhood of its arguments/free variables respectively, and in
207 * the case of a function it also needs an arity. These are stored
208 * directly in the BCO, rather than in the instrs array, for two
210 * (a) speed: we need to get at the bitmap info quickly when
211 * the GC is examining APs and PAPs that point to this BCO
212 * (b) a subtle interaction with the compacting GC. In compacting
213 * GC, the info that describes the size/layout of a closure
214 * cannot be in an object more than one level of indirection
215 * away from the current object, because of the order in
216 * which pointers are updated to point to their new locations.
221 StgArrWords *instrs; // a pointer to an ArrWords
222 StgArrWords *literals; // a pointer to an ArrWords
223 StgMutArrPtrs *ptrs; // a pointer to a MutArrPtrs
224 StgArrWords *itbls; // a pointer to an ArrWords
225 StgHalfWord arity; // arity of this BCO
226 StgHalfWord size; // size of this BCO (in words)
227 StgWord bitmap[FLEXIBLE_ARRAY]; // an StgLargeBitmap
230 #define BCO_BITMAP(bco) ((StgLargeBitmap *)((StgBCO *)(bco))->bitmap)
231 #define BCO_BITMAP_SIZE(bco) (BCO_BITMAP(bco)->size)
232 #define BCO_BITMAP_BITS(bco) (BCO_BITMAP(bco)->bitmap)
233 #define BCO_BITMAP_SIZEW(bco) ((BCO_BITMAP_SIZE(bco) + BITS_IN(StgWord) - 1) \
236 /* Dynamic stack frames - these have a liveness mask in the object
237 * itself, rather than in the info table. Useful for generic heap
238 * check code. See StgMacros.h, HEAP_CHK_GEN().
242 const struct _StgInfoTable* info;
245 StgClosure * payload[FLEXIBLE_ARRAY];
248 /* A function return stack frame: used when saving the state for a
249 * garbage collection at a function entry point. The function
250 * arguments are on the stack, and we also save the function (its
251 * info table describes the pointerhood of the arguments).
253 * The stack frame size is also cached in the frame for convenience.
256 const struct _StgInfoTable* info;
259 StgClosure * payload[FLEXIBLE_ARRAY];
262 /* Concurrent communication objects */
266 struct StgTSO_ *head;
267 StgMutClosure *mut_link;
268 struct StgTSO_ *tail;
272 #if defined(PAR) || defined(GRAN)
274 StgBlockingQueueElement is a ``collective type'' representing the types
275 of closures that can be found on a blocking queue: StgTSO, StgRBHSave,
276 StgBlockedFetch. (StgRBHSave can only appear at the end of a blocking
277 queue). Logically, this is a union type, but defining another struct
278 with a common layout is easier to handle in the code (same as for
280 Note that in the standard setup only StgTSOs can be on a blocking queue.
281 This is one of the main reasons for slightly different code in files
284 typedef struct StgBlockingQueueElement_ {
286 struct StgBlockingQueueElement_ *link; /* next elem in BQ */
287 StgMutClosure *mut_link; /* next elem in mutable list */
288 struct StgClosure_ *payload[FLEXIBLE_ARRAY];/* contents of the closure */
289 } StgBlockingQueueElement;
291 /* only difference to std code is type of the elem in the BQ */
292 typedef struct StgBlockingQueue_ {
294 struct StgBlockingQueueElement_ *blocking_queue; /* start of the BQ */
295 StgMutClosure *mut_link; /* next elem in mutable list */
298 /* this closure is hanging at the end of a blocking queue in (see RBH.c) */
299 typedef struct StgRBHSave_ {
301 StgClosure *payload[FLEXIBLE_ARRAY]; /* 2 words ripped out of the guts of the */
302 } StgRBHSave; /* closure holding the blocking queue */
304 typedef struct StgRBH_ {
306 struct StgBlockingQueueElement_ *blocking_queue; /* start of the BQ */
307 StgMutClosure *mut_link; /* next elem in mutable list */
312 typedef struct StgBlockingQueue_ {
314 struct StgTSO_ *blocking_queue;
315 StgMutClosure *mut_link;
321 /* global indirections aka FETCH_ME closures */
322 typedef struct StgFetchMe_ {
324 globalAddr *ga; /* ptr to unique id for a closure */
325 StgMutClosure *mut_link; /* next elem in mutable list */
328 /* same contents as an ordinary StgBlockingQueue */
329 typedef struct StgFetchMeBlockingQueue_ {
331 struct StgBlockingQueueElement_ *blocking_queue; /* start of the BQ */
332 StgMutClosure *mut_link; /* next elem in mutable list */
333 } StgFetchMeBlockingQueue;
335 /* This is an entry in a blocking queue. It indicates a fetch request from a
336 TSO on another PE demanding the value of this closur. Note that a
337 StgBlockedFetch can only occur in a BQ. Once the node is evaluated and
338 updated with the result, the result will be sent back (the PE is encoded
339 in the globalAddr) and the StgBlockedFetch closure will be nuked.
341 typedef struct StgBlockedFetch_ {
343 struct StgBlockingQueueElement_ *link; /* next elem in the BQ */
344 StgMutClosure *mut_link; /* next elem in mutable list */
345 StgClosure *node; /* node to fetch */
346 globalAddr ga; /* where to send the result to */
347 } StgBlockedFetch; /* NB: not just a ptr to a GA */
350 #endif /* CLOSURES_H */