1 /* ----------------------------------------------------------------------------
2 * $Id: Closures.h,v 1.32 2002/12/11 15:36:37 simonmar 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 pieces of
208 * information are stored at the beginning of the instruction array.
213 StgArrWords *instrs; /* a pointer to an ArrWords */
214 StgArrWords *literals; /* a pointer to an ArrWords */
215 StgMutArrPtrs *ptrs; /* a pointer to a MutArrPtrs */
216 StgArrWords *itbls; /* a pointer to an ArrWords */
221 StgWord bitmap[FLEXIBLE_ARRAY]; // really an StgLargeBitmap
224 #define BCO_INFO(bco) ((StgBCOInfo *)(((StgBCO *)(bco))->instrs->payload))
225 #define BCO_ARITY(bco) (BCO_INFO(bco)->arity)
226 #define BCO_BITMAP(bco) ((StgLargeBitmap *)BCO_INFO(bco)->bitmap)
227 #define BCO_BITMAP_SIZE(bco) (BCO_BITMAP(bco)->size)
228 #define BCO_BITMAP_BITS(bco) (BCO_BITMAP(bco)->bitmap)
229 #define BCO_BITMAP_SIZEW(bco) ((BCO_BITMAP_SIZE(bco) + BITS_IN(StgWord) - 1) \
231 #define BCO_INSTRS(bco) ((StgWord16 *)(BCO_BITMAP_BITS(bco) + \
232 BCO_BITMAP_SIZEW(bco)))
234 /* Dynamic stack frames - these have a liveness mask in the object
235 * itself, rather than in the info table. Useful for generic heap
236 * check code. See StgMacros.h, HEAP_CHK_GEN().
240 const struct _StgInfoTable* info;
243 StgClosure * payload[FLEXIBLE_ARRAY];
246 /* A function return stack frame: used when saving the state for a
247 * garbage collection at a function entry point. The function
248 * arguments are on the stack, and we also save the function (its
249 * info table describes the pointerhood of the arguments).
251 * The stack frame size is also cached in the frame for convenience.
254 const struct _StgInfoTable* info;
257 StgClosure * payload[FLEXIBLE_ARRAY];
260 /* Concurrent communication objects */
264 struct StgTSO_ *head;
265 StgMutClosure *mut_link;
266 struct StgTSO_ *tail;
270 #if defined(PAR) || defined(GRAN)
272 StgBlockingQueueElement is a ``collective type'' representing the types
273 of closures that can be found on a blocking queue: StgTSO, StgRBHSave,
274 StgBlockedFetch. (StgRBHSave can only appear at the end of a blocking
275 queue). Logically, this is a union type, but defining another struct
276 with a common layout is easier to handle in the code (same as for
278 Note that in the standard setup only StgTSOs can be on a blocking queue.
279 This is one of the main reasons for slightly different code in files
282 typedef struct StgBlockingQueueElement_ {
284 struct StgBlockingQueueElement_ *link; /* next elem in BQ */
285 StgMutClosure *mut_link; /* next elem in mutable list */
286 struct StgClosure_ *payload[FLEXIBLE_ARRAY];/* contents of the closure */
287 } StgBlockingQueueElement;
289 /* only difference to std code is type of the elem in the BQ */
290 typedef struct StgBlockingQueue_ {
292 struct StgBlockingQueueElement_ *blocking_queue; /* start of the BQ */
293 StgMutClosure *mut_link; /* next elem in mutable list */
296 /* this closure is hanging at the end of a blocking queue in (see RBH.c) */
297 typedef struct StgRBHSave_ {
299 StgClosure *payload[FLEXIBLE_ARRAY]; /* 2 words ripped out of the guts of the */
300 } StgRBHSave; /* closure holding the blocking queue */
302 typedef struct StgRBH_ {
304 struct StgBlockingQueueElement_ *blocking_queue; /* start of the BQ */
305 StgMutClosure *mut_link; /* next elem in mutable list */
310 typedef struct StgBlockingQueue_ {
312 struct StgTSO_ *blocking_queue;
313 StgMutClosure *mut_link;
319 /* global indirections aka FETCH_ME closures */
320 typedef struct StgFetchMe_ {
322 globalAddr *ga; /* ptr to unique id for a closure */
323 StgMutClosure *mut_link; /* next elem in mutable list */
326 /* same contents as an ordinary StgBlockingQueue */
327 typedef struct StgFetchMeBlockingQueue_ {
329 struct StgBlockingQueueElement_ *blocking_queue; /* start of the BQ */
330 StgMutClosure *mut_link; /* next elem in mutable list */
331 } StgFetchMeBlockingQueue;
333 /* This is an entry in a blocking queue. It indicates a fetch request from a
334 TSO on another PE demanding the value of this closur. Note that a
335 StgBlockedFetch can only occur in a BQ. Once the node is evaluated and
336 updated with the result, the result will be sent back (the PE is encoded
337 in the globalAddr) and the StgBlockedFetch closure will be nuked.
339 typedef struct StgBlockedFetch_ {
341 struct StgBlockingQueueElement_ *link; /* next elem in the BQ */
342 StgMutClosure *mut_link; /* next elem in mutable list */
343 StgClosure *node; /* node to fetch */
344 globalAddr ga; /* where to send the result to */
345 } StgBlockedFetch; /* NB: not just a ptr to a GA */
348 #endif /* CLOSURES_H */