1 /* ----------------------------------------------------------------------------
2 * $Id: InfoTables.h,v 1.32 2003/11/14 14:28:08 stolz Exp $
4 * (c) The GHC Team, 1998-2002
8 * -------------------------------------------------------------------------- */
13 /* -----------------------------------------------------------------------------
15 -------------------------------------------------------------------------- */
22 /* -----------------------------------------------------------------------------
24 -------------------------------------------------------------------------- */
26 #if 0 && (defined(PAR) || defined(GRAN))
29 // ToDo: use this in StgInfoTable (mutually recursive) -- HWL
32 StgInfoTable *rbh_infoptr; /* infoptr to the RBH */
38 Copied from ghc-0.29; ToDo: check this code -- HWL
40 In the parallel system, all updatable closures have corresponding
41 revertible black holes. When we are assembly-mangling, we guarantee
42 that the revertible black hole code precedes the normal entry code, so
43 that the RBH info table resides at a fixed offset from the normal info
44 table. Otherwise, we add the RBH info table pointer to the end of the
45 normal info table and vice versa.
47 Currently has to use a !RBH_MAGIC_OFFSET setting.
48 Still todo: init of par.infoptr field in all infotables!!
51 #if defined(PAR) || defined(GRAN)
53 # ifdef RBH_MAGIC_OFFSET
55 # error magic offset not yet implemented
57 # define RBH_INFO_WORDS 0
58 # define INCLUDE_RBH_INFO(infoptr)
60 # define RBH_INFOPTR(infoptr) (((P_)infoptr) - RBH_MAGIC_OFFSET)
61 # define REVERT_INFOPTR(infoptr) (((P_)infoptr) + RBH_MAGIC_OFFSET)
65 # define RBH_INFO_WORDS 1
66 # define INCLUDE_RBH_INFO(info) rbh_infoptr : &(info)
68 # define RBH_INFOPTR(infoptr) (((StgInfoTable *)(infoptr))->rbh_infoptr)
69 # define REVERT_INFOPTR(infoptr) (((StgInfoTable *)(infoptr))->rbh_infoptr)
73 /* see ParallelRts.h */
75 //StgClosure *convertToRBH(StgClosure *closure);
77 //void convertFromRBH(StgClosure *closure);
79 //void convertToFetchMe(StgPtr closure, globalAddr *ga);
84 /* -----------------------------------------------------------------------------
86 -------------------------------------------------------------------------- */
88 #if defined(SUPPORTS_EMPTY_STRUCTS)
94 /* -----------------------------------------------------------------------------
96 -------------------------------------------------------------------------- */
104 #else /* !DEBUG_CLOSURE */
106 # if defined(SUPPORTS_EMPTY_STRUCTS)
107 typedef struct StgDebugInfo {
112 #endif /* DEBUG_CLOSURE */
114 /* -----------------------------------------------------------------------------
116 -------------------------------------------------------------------------- */
118 /* The type flags provide quick access to certain properties of a closure. */
120 #define _HNF (1<<0) /* head normal form? */
121 #define _BTM (1<<1) /* bitmap-style layout? */
122 #define _NS (1<<2) /* non-sparkable */
123 #define _STA (1<<3) /* static? */
124 #define _THU (1<<4) /* thunk? */
125 #define _MUT (1<<5) /* mutable? */
126 #define _UPT (1<<6) /* unpointed? */
127 #define _SRT (1<<7) /* has an SRT? */
128 #define _IND (1<<8) /* is an indirection? */
130 #define isSTATIC(flags) ((flags) &_STA)
131 #define isMUTABLE(flags) ((flags) &_MUT)
132 #define isBITMAP(flags) ((flags) &_BTM)
133 #define isTHUNK(flags) ((flags) &_THU)
134 #define isUNPOINTED(flags) ((flags) &_UPT)
135 #define hasSRT(flags) ((flags) &_SRT)
137 extern StgWord16 closure_flags[];
139 #define closureFlags(c) (closure_flags[get_itbl(c)->type])
141 #define closure_HNF(c) ( closureFlags(c) & _HNF)
142 #define closure_BITMAP(c) ( closureFlags(c) & _BTM)
143 #define closure_NON_SPARK(c) ( (closureFlags(c) & _NS))
144 #define closure_SHOULD_SPARK(c) (!(closureFlags(c) & _NS))
145 #define closure_STATIC(c) ( closureFlags(c) & _STA)
146 #define closure_THUNK(c) ( closureFlags(c) & _THU)
147 #define closure_MUTABLE(c) ( closureFlags(c) & _MUT)
148 #define closure_UNPOINTED(c) ( closureFlags(c) & _UPT)
149 #define closure_SRT(c) ( closureFlags(c) & _SRT)
150 #define closure_IND(c) ( closureFlags(c) & _IND)
152 /* same as above but for info-ptr rather than closure */
153 #define ipFlags(ip) (closure_flags[ip->type])
155 #define ip_HNF(ip) ( ipFlags(ip) & _HNF)
156 #define ip_BITMAP(ip) ( ipFlags(ip) & _BTM)
157 #define ip_SHOULD_SPARK(ip) (!(ipFlags(ip) & _NS))
158 #define ip_STATIC(ip) ( ipFlags(ip) & _STA)
159 #define ip_THUNK(ip) ( ipFlags(ip) & _THU)
160 #define ip_MUTABLE(ip) ( ipFlags(ip) & _MUT)
161 #define ip_UNPOINTED(ip) ( ipFlags(ip) & _UPT)
162 #define ip_SRT(ip) ( ipFlags(ip) & _SRT)
163 #define ip_IND(ip) ( ipFlags(ip) & _IND)
165 /* -----------------------------------------------------------------------------
168 These are used to describe the pointerhood of a sequence of words
169 (usually on the stack) to the garbage collector. The two primary
170 uses are for stack frames, and functions (where we need to describe
171 the layout of a PAP to the GC).
172 -------------------------------------------------------------------------- */
175 // Small bitmaps: for a small bitmap, we store the size and bitmap in
176 // the same word, using the following macros. If the bitmap doesn't
177 // fit in a single word, we use a pointer to an StgLargeBitmap below.
179 #define MK_SMALL_BITMAP(size,bits) (((bits)<<BITMAP_BITS_SHIFT) | (size))
181 #define BITMAP_SIZE(bitmap) ((bitmap) & BITMAP_SIZE_MASK)
182 #define BITMAP_BITS(bitmap) ((bitmap) >> BITMAP_BITS_SHIFT)
189 StgWord bitmap[FLEXIBLE_ARRAY];
192 /* -----------------------------------------------------------------------------
193 SRTs (Static Reference Tables)
195 These tables are used to keep track of the static objects referred
196 to by the code for a closure or stack frame, so that we can follow
197 static data references from code and thus accurately
198 garbage-collect CAFs.
199 -------------------------------------------------------------------------- */
201 // An SRT is just an array of closure pointers:
202 typedef StgClosure* StgSRT[];
204 // Each info table refers to some subset of the closure pointers in an
205 // SRT. It does this using a pair of an StgSRT pointer and a
206 // half-word bitmap. If the half-word bitmap isn't large enough, then
207 // we fall back to a large SRT, including an unbounded bitmap. If the
208 // half-word bitmap is set to all ones (0xffff), then the StgSRT
209 // pointer instead points to an StgLargeSRT:
210 typedef struct StgLargeSRT_ {
215 /* ----------------------------------------------------------------------------
217 ------------------------------------------------------------------------- */
220 // Stuff describing the closure layout. Well, actually, it might
221 // contain the selector index for a THUNK_SELECTOR. This union is one
225 struct { // Heap closure payload layout:
226 StgHalfWord ptrs; // number of pointers
227 StgHalfWord nptrs; // number of non-pointers
230 StgWord bitmap; // word-sized bit pattern describing
231 // a stack frame: see below
233 StgLargeBitmap* large_bitmap; // pointer to large bitmap structure
235 StgWord selector_offset; // used in THUNK_SELECTORs
241 // The "standard" part of an info table. Every info table has this bit.
243 typedef struct _StgInfoTable {
245 #ifndef TABLES_NEXT_TO_CODE
246 StgFunPtr entry; // pointer to the entry code
249 #if defined(PAR) || defined(GRAN)
250 struct _StgInfoTable *rbh_infoptr;
256 MAYBE_EMPTY_STRUCT(StgTickyInfo,ticky)
259 MAYBE_EMPTY_STRUCT(StgDebugInfo,debug)
262 StgClosureInfo layout; // closure layout info (one word)
264 StgHalfWord type; // closure type
265 StgHalfWord srt_bitmap; // number of entries in SRT (or constructor tag)
267 #ifdef TABLES_NEXT_TO_CODE
268 StgCode code[FLEXIBLE_ARRAY];
273 /* -----------------------------------------------------------------------------
276 This is the general form of function info tables. The compiler
277 will omit some of the fields in common cases:
279 - If fun_type is not ARG_GEN or ARG_GEN_BIG, then the slow_apply
280 and bitmap fields may be left out (they are at the end, so omitting
281 them doesn't affect the layout).
283 - If srt_bitmap (in the std info table part) is zero, then the srt
284 field may be omitted. This only applies if the slow_apply and
285 bitmap fields have also been omitted.
286 -------------------------------------------------------------------------- */
288 typedef struct _StgFunInfoTable {
289 #if defined(TABLES_NEXT_TO_CODE)
290 StgFun *slow_apply; // apply to args on the stack
291 StgWord bitmap; // arg ptr/nonptr bitmap
292 StgSRT *srt; // pointer to the SRT table
293 StgHalfWord fun_type; // function type
294 StgHalfWord arity; // function arity
298 StgHalfWord fun_type; // function type
299 StgHalfWord arity; // function arity
300 StgSRT *srt; // pointer to the SRT table
301 StgWord bitmap; // arg ptr/nonptr bitmap
302 StgFun *slow_apply; // apply to args on the stack
306 /* -----------------------------------------------------------------------------
308 -------------------------------------------------------------------------- */
310 // When info tables are laid out backwards, we can omit the SRT
311 // pointer iff srt_bitmap is zero.
313 typedef struct _StgRetInfoTable {
314 #if !defined(TABLES_NEXT_TO_CODE)
317 StgSRT *srt; // pointer to the SRT table
318 #if defined(TABLES_NEXT_TO_CODE)
321 #if !defined(TABLES_NEXT_TO_CODE)
322 StgFunPtr vector[FLEXIBLE_ARRAY];
326 /* -----------------------------------------------------------------------------
328 -------------------------------------------------------------------------- */
330 // When info tables are laid out backwards, we can omit the SRT
331 // pointer iff srt_bitmap is zero.
333 typedef struct _StgThunkInfoTable {
334 #if !defined(TABLES_NEXT_TO_CODE)
337 StgSRT *srt; // pointer to the SRT table
338 #if defined(TABLES_NEXT_TO_CODE)
343 #endif /* INFOTABLES_H */