RTS: delete BlockedOnGA* + dead code
[ghc.git] / includes / rts / storage / InfoTables.h
1 /* ----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1998-2002
4 *
5 * Info Tables
6 *
7 * -------------------------------------------------------------------------- */
8
9 #ifndef RTS_STORAGE_INFOTABLES_H
10 #define RTS_STORAGE_INFOTABLES_H
11
12 /* ----------------------------------------------------------------------------
13 Relative pointers
14
15 Several pointer fields in info tables are expressed as offsets
16 relative to the info pointer, so that we can generate
17 position-independent code.
18
19 Note [x86-64-relative]
20 There is a complication on the x86_64 platform, where pointers are
21 64 bits, but the tools don't support 64-bit relative relocations.
22 However, the default memory model (small) ensures that all symbols
23 have values in the lower 2Gb of the address space, so offsets all
24 fit in 32 bits. Hence we can use 32-bit offset fields.
25
26 Somewhere between binutils-2.16.1 and binutils-2.16.91.0.6,
27 support for 64-bit PC-relative relocations was added, so maybe this
28 hackery can go away sometime.
29 ------------------------------------------------------------------------- */
30
31 #if x86_64_TARGET_ARCH
32 #define OFFSET_FIELD(n) StgHalfInt n; StgHalfWord __pad_##n
33 #else
34 #define OFFSET_FIELD(n) StgInt n
35 #endif
36
37 /* -----------------------------------------------------------------------------
38 Profiling info
39 -------------------------------------------------------------------------- */
40
41 typedef struct {
42 #ifndef TABLES_NEXT_TO_CODE
43 char *closure_type;
44 char *closure_desc;
45 #else
46 OFFSET_FIELD(closure_type_off);
47 OFFSET_FIELD(closure_desc_off);
48 #endif
49 } StgProfInfo;
50
51 /* -----------------------------------------------------------------------------
52 Closure flags
53 -------------------------------------------------------------------------- */
54
55 /* The type flags provide quick access to certain properties of a closure. */
56
57 #define _HNF (1<<0) /* head normal form? */
58 #define _BTM (1<<1) /* uses info->layout.bitmap */
59 #define _NS (1<<2) /* non-sparkable */
60 #define _STA (1<<3) /* static? */
61 #define _THU (1<<4) /* thunk? */
62 #define _MUT (1<<5) /* mutable? */
63 #define _UPT (1<<6) /* unpointed? */
64 #define _SRT (1<<7) /* has an SRT? */
65 #define _IND (1<<8) /* is an indirection? */
66
67 #define isSTATIC(flags) ((flags) &_STA)
68 #define isMUTABLE(flags) ((flags) &_MUT)
69 #define isBITMAP(flags) ((flags) &_BTM)
70 #define isTHUNK(flags) ((flags) &_THU)
71 #define isUNPOINTED(flags) ((flags) &_UPT)
72 #define hasSRT(flags) ((flags) &_SRT)
73
74 extern StgWord16 closure_flags[];
75
76 #define closureFlags(c) (closure_flags[get_itbl(UNTAG_CLOSURE(c))->type])
77
78 #define closure_HNF(c) ( closureFlags(c) & _HNF)
79 #define closure_BITMAP(c) ( closureFlags(c) & _BTM)
80 #define closure_NON_SPARK(c) ( (closureFlags(c) & _NS))
81 #define closure_SHOULD_SPARK(c) (!(closureFlags(c) & _NS))
82 #define closure_STATIC(c) ( closureFlags(c) & _STA)
83 #define closure_THUNK(c) ( closureFlags(c) & _THU)
84 #define closure_MUTABLE(c) ( closureFlags(c) & _MUT)
85 #define closure_UNPOINTED(c) ( closureFlags(c) & _UPT)
86 #define closure_SRT(c) ( closureFlags(c) & _SRT)
87 #define closure_IND(c) ( closureFlags(c) & _IND)
88
89 /* same as above but for info-ptr rather than closure */
90 #define ipFlags(ip) (closure_flags[ip->type])
91
92 #define ip_HNF(ip) ( ipFlags(ip) & _HNF)
93 #define ip_BITMAP(ip) ( ipFlags(ip) & _BTM)
94 #define ip_SHOULD_SPARK(ip) (!(ipFlags(ip) & _NS))
95 #define ip_STATIC(ip) ( ipFlags(ip) & _STA)
96 #define ip_THUNK(ip) ( ipFlags(ip) & _THU)
97 #define ip_MUTABLE(ip) ( ipFlags(ip) & _MUT)
98 #define ip_UNPOINTED(ip) ( ipFlags(ip) & _UPT)
99 #define ip_SRT(ip) ( ipFlags(ip) & _SRT)
100 #define ip_IND(ip) ( ipFlags(ip) & _IND)
101
102 /* -----------------------------------------------------------------------------
103 Bitmaps
104
105 These are used to describe the pointerhood of a sequence of words
106 (usually on the stack) to the garbage collector. The two primary
107 uses are for stack frames, and functions (where we need to describe
108 the layout of a PAP to the GC).
109
110 In these bitmaps: 0 == ptr, 1 == non-ptr.
111 -------------------------------------------------------------------------- */
112
113 /*
114 * Small bitmaps: for a small bitmap, we store the size and bitmap in
115 * the same word, using the following macros. If the bitmap doesn't
116 * fit in a single word, we use a pointer to an StgLargeBitmap below.
117 */
118 #define MK_SMALL_BITMAP(size,bits) (((bits)<<BITMAP_BITS_SHIFT) | (size))
119
120 #define BITMAP_SIZE(bitmap) ((bitmap) & BITMAP_SIZE_MASK)
121 #define BITMAP_BITS(bitmap) ((bitmap) >> BITMAP_BITS_SHIFT)
122
123 /*
124 * A large bitmap.
125 */
126 typedef struct {
127 StgWord size;
128 StgWord bitmap[];
129 } StgLargeBitmap;
130
131 /* -----------------------------------------------------------------------------
132 SRTs (Static Reference Tables)
133
134 These tables are used to keep track of the static objects referred
135 to by the code for a closure or stack frame, so that we can follow
136 static data references from code and thus accurately
137 garbage-collect CAFs.
138 -------------------------------------------------------------------------- */
139
140 /* An SRT is just an array of closure pointers: */
141 typedef StgClosure* StgSRT[];
142
143 /*
144 * Each info table refers to some subset of the closure pointers in an
145 * SRT. It does this using a pair of an StgSRT pointer and a
146 * half-word bitmap. If the half-word bitmap isn't large enough, then
147 * we fall back to a large SRT, including an unbounded bitmap. If the
148 * half-word bitmap is set to all ones (0xffff), then the StgSRT
149 * pointer instead points to an StgLargeSRT:
150 */
151 typedef struct StgLargeSRT_ {
152 StgSRT *srt;
153 StgLargeBitmap l;
154 } StgLargeSRT;
155
156 /* ----------------------------------------------------------------------------
157 Info Tables
158 ------------------------------------------------------------------------- */
159
160 /*
161 * Stuff describing the closure layout. Well, actually, it might
162 * contain the selector index for a THUNK_SELECTOR. This union is one
163 * word long.
164 */
165 typedef union {
166 struct { /* Heap closure payload layout: */
167 StgHalfWord ptrs; /* number of pointers */
168 StgHalfWord nptrs; /* number of non-pointers */
169 } payload;
170
171 StgWord bitmap; /* word-sized bit pattern describing */
172 /* a stack frame: see below */
173
174 #ifndef TABLES_NEXT_TO_CODE
175 StgLargeBitmap* large_bitmap; /* pointer to large bitmap structure */
176 #else
177 OFFSET_FIELD(large_bitmap_offset); /* offset from info table to large bitmap structure */
178 #endif
179
180 StgWord selector_offset; /* used in THUNK_SELECTORs */
181
182 } StgClosureInfo;
183
184
185 /*
186 * The "standard" part of an info table. Every info table has this bit.
187 */
188 typedef struct StgInfoTable_ {
189
190 #if !defined(TABLES_NEXT_TO_CODE)
191 StgFunPtr entry; /* pointer to the entry code */
192 #endif
193
194 #ifdef PROFILING
195 StgProfInfo prof;
196 #endif
197
198 StgClosureInfo layout; /* closure layout info (one word) */
199
200 StgHalfWord type; /* closure type */
201 StgHalfWord srt_bitmap;
202 /* In a CONSTR:
203 - the constructor tag
204 In a FUN/THUNK
205 - a bitmap of SRT entries
206 */
207
208 #ifdef TABLES_NEXT_TO_CODE
209 StgCode code[];
210 #endif
211 } *StgInfoTablePtr; // StgInfoTable defined in rts/Types.h
212
213
214 /* -----------------------------------------------------------------------------
215 Function info tables
216
217 This is the general form of function info tables. The compiler
218 will omit some of the fields in common cases:
219
220 - If fun_type is not ARG_GEN or ARG_GEN_BIG, then the slow_apply
221 and bitmap fields may be left out (they are at the end, so omitting
222 them doesn't affect the layout).
223
224 - If srt_bitmap (in the std info table part) is zero, then the srt
225 field may be omitted. This only applies if the slow_apply and
226 bitmap fields have also been omitted.
227 -------------------------------------------------------------------------- */
228
229 typedef struct StgFunInfoExtraRev_ {
230 OFFSET_FIELD(slow_apply_offset); /* apply to args on the stack */
231 union {
232 StgWord bitmap;
233 OFFSET_FIELD(bitmap_offset); /* arg ptr/nonptr bitmap */
234 } b;
235 OFFSET_FIELD(srt_offset); /* pointer to the SRT table */
236 StgHalfWord fun_type; /* function type */
237 StgHalfWord arity; /* function arity */
238 } StgFunInfoExtraRev;
239
240 typedef struct StgFunInfoExtraFwd_ {
241 StgHalfWord fun_type; /* function type */
242 StgHalfWord arity; /* function arity */
243 StgSRT *srt; /* pointer to the SRT table */
244 union { /* union for compat. with TABLES_NEXT_TO_CODE version */
245 StgWord bitmap; /* arg ptr/nonptr bitmap */
246 } b;
247 StgFun *slow_apply; /* apply to args on the stack */
248 } StgFunInfoExtraFwd;
249
250 typedef struct {
251 #if defined(TABLES_NEXT_TO_CODE)
252 StgFunInfoExtraRev f;
253 StgInfoTable i;
254 #else
255 StgInfoTable i;
256 StgFunInfoExtraFwd f;
257 #endif
258 } StgFunInfoTable;
259
260 // canned bitmap for each arg type, indexed by constants in FunTypes.h
261 extern StgWord stg_arg_bitmaps[];
262
263 /* -----------------------------------------------------------------------------
264 Return info tables
265 -------------------------------------------------------------------------- */
266
267 /*
268 * When info tables are laid out backwards, we can omit the SRT
269 * pointer iff srt_bitmap is zero.
270 */
271
272 typedef struct {
273 #if defined(TABLES_NEXT_TO_CODE)
274 OFFSET_FIELD(srt_offset); /* offset to the SRT table */
275 StgInfoTable i;
276 #else
277 StgInfoTable i;
278 StgSRT *srt; /* pointer to the SRT table */
279 #endif
280 } StgRetInfoTable;
281
282 /* -----------------------------------------------------------------------------
283 Thunk info tables
284 -------------------------------------------------------------------------- */
285
286 /*
287 * When info tables are laid out backwards, we can omit the SRT
288 * pointer iff srt_bitmap is zero.
289 */
290
291 typedef struct StgThunkInfoTable_ {
292 #if !defined(TABLES_NEXT_TO_CODE)
293 StgInfoTable i;
294 #endif
295 #if defined(TABLES_NEXT_TO_CODE)
296 OFFSET_FIELD(srt_offset); /* offset to the SRT table */
297 #else
298 StgSRT *srt; /* pointer to the SRT table */
299 #endif
300 #if defined(TABLES_NEXT_TO_CODE)
301 StgInfoTable i;
302 #endif
303 } StgThunkInfoTable;
304
305 /* -----------------------------------------------------------------------------
306 Constructor info tables
307 -------------------------------------------------------------------------- */
308
309 typedef struct StgConInfoTable_ {
310 #if !defined(TABLES_NEXT_TO_CODE)
311 StgInfoTable i;
312 #endif
313
314 #if defined(TABLES_NEXT_TO_CODE)
315 OFFSET_FIELD(con_desc); // the name of the data constructor
316 // as: Package:Module.Name
317 #else
318 char *con_desc;
319 #endif
320
321 #if defined(TABLES_NEXT_TO_CODE)
322 StgInfoTable i;
323 #endif
324 } StgConInfoTable;
325
326
327 /* -----------------------------------------------------------------------------
328 Accessor macros for fields that might be offsets (C version)
329 -------------------------------------------------------------------------- */
330
331 /*
332 * GET_SRT(info)
333 * info must be a Stg[Ret|Thunk]InfoTable* (an info table that has a SRT)
334 */
335 #ifdef TABLES_NEXT_TO_CODE
336 #define GET_SRT(info) ((StgSRT*) (((StgWord) ((info)+1)) + (info)->srt_offset))
337 #else
338 #define GET_SRT(info) ((info)->srt)
339 #endif
340
341 /*
342 * GET_CON_DESC(info)
343 * info must be a StgConInfoTable*.
344 */
345 #ifdef TABLES_NEXT_TO_CODE
346 #define GET_CON_DESC(info) ((char *)((StgWord)((info)+1) + (info->con_desc)))
347 #else
348 #define GET_CON_DESC(info) ((info)->con_desc)
349 #endif
350
351 /*
352 * GET_FUN_SRT(info)
353 * info must be a StgFunInfoTable*
354 */
355 #ifdef TABLES_NEXT_TO_CODE
356 #define GET_FUN_SRT(info) ((StgSRT*) (((StgWord) ((info)+1)) + (info)->f.srt_offset))
357 #else
358 #define GET_FUN_SRT(info) ((info)->f.srt)
359 #endif
360
361 #ifdef TABLES_NEXT_TO_CODE
362 #define GET_LARGE_BITMAP(info) ((StgLargeBitmap*) (((StgWord) ((info)+1)) \
363 + (info)->layout.large_bitmap_offset))
364 #else
365 #define GET_LARGE_BITMAP(info) ((info)->layout.large_bitmap)
366 #endif
367
368 #ifdef TABLES_NEXT_TO_CODE
369 #define GET_FUN_LARGE_BITMAP(info) ((StgLargeBitmap*) (((StgWord) ((info)+1)) \
370 + (info)->f.b.bitmap_offset))
371 #else
372 #define GET_FUN_LARGE_BITMAP(info) ((StgLargeBitmap*) ((info)->f.b.bitmap))
373 #endif
374
375 /*
376 * GET_PROF_TYPE, GET_PROF_DESC
377 */
378 #ifdef TABLES_NEXT_TO_CODE
379 #define GET_PROF_TYPE(info) ((char *)((StgWord)((info)+1) + (info->prof.closure_type_off)))
380 #else
381 #define GET_PROF_TYPE(info) ((info)->prof.closure_type)
382 #endif
383 #ifdef TABLES_NEXT_TO_CODE
384 #define GET_PROF_DESC(info) ((char *)((StgWord)((info)+1) + (info->prof.closure_desc_off)))
385 #else
386 #define GET_PROF_DESC(info) ((info)->prof.closure_desc)
387 #endif
388
389 #endif /* RTS_STORAGE_INFOTABLES_H */