Add a write barrier to the TSO link field (#1589)
[ghc.git] / includes / Constants.h
1 /* ----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1998-2002
4 *
5 * Constants
6 *
7 * NOTE: this information is used by both the compiler and the RTS.
8 * Some of it is tweakable, and some of it must be kept up to date
9 * with various other parts of the system.
10 *
11 * Constants which are derived automatically from other definitions in
12 * the system (eg. structure sizes) are generated into the file
13 * DerivedConstants.h by a C program (mkDerivedConstantsHdr).
14 *
15 * -------------------------------------------------------------------------- */
16
17 #ifndef CONSTANTS_H
18 #define CONSTANTS_H
19
20 /* -----------------------------------------------------------------------------
21 Minimum closure sizes
22
23 This is the minimum number of words in the payload of a
24 heap-allocated closure, so that the closure has enough room to be
25 overwritten with a forwarding pointer during garbage collection.
26 -------------------------------------------------------------------------- */
27
28 #define MIN_PAYLOAD_SIZE 1
29
30 /* -----------------------------------------------------------------------------
31 Constants to do with specialised closure types.
32 -------------------------------------------------------------------------- */
33
34 /* We have some pre-compiled selector thunks defined in rts/StgStdThunks.hc.
35 * This constant defines the highest selectee index that we can replace with a
36 * reference to the pre-compiled code.
37 */
38
39 #define MAX_SPEC_SELECTEE_SIZE 15
40
41 /* Vector-apply thunks. These thunks just push their free variables
42 * on the stack and enter the first one. They're a bit like PAPs, but
43 * don't have a dynamic size. We've pre-compiled a few to save
44 * space.
45 */
46
47 #define MAX_SPEC_AP_SIZE 7
48
49 /* Specialised FUN/THUNK/CONSTR closure types */
50
51 #define MAX_SPEC_THUNK_SIZE 2
52 #define MAX_SPEC_FUN_SIZE 2
53 #define MAX_SPEC_CONSTR_SIZE 2
54
55 /* Range of built-in table of static small int-like and char-like closures.
56 *
57 * NB. This corresponds with the number of actual INTLIKE/CHARLIKE
58 * closures defined in rts/StgMiscClosures.cmm.
59 */
60 #define MAX_INTLIKE 16
61 #define MIN_INTLIKE (-16)
62
63 #define MAX_CHARLIKE 255
64 #define MIN_CHARLIKE 0
65
66 /* -----------------------------------------------------------------------------
67 STG Registers.
68
69 Note that in MachRegs.h we define how many of these registers are
70 *real* machine registers, and not just offsets in the Register Table.
71 -------------------------------------------------------------------------- */
72
73 #define MAX_VANILLA_REG 8
74 #define MAX_FLOAT_REG 4
75 #define MAX_DOUBLE_REG 2
76 #define MAX_LONG_REG 1
77
78 /* -----------------------------------------------------------------------------
79 Semi-Tagging constants
80
81 Old Comments about this stuff:
82
83 Tags for indirection nodes and ``other'' (probably unevaluated) nodes;
84 normal-form values of algebraic data types will have tags 0, 1, ...
85
86 @INFO_IND_TAG@ is different from @INFO_OTHER_TAG@ just so we can count
87 how often we bang into indirection nodes; that's all. (WDP 95/11)
88
89 ToDo: find out if we need any of this.
90 -------------------------------------------------------------------------- */
91
92 #define INFO_OTHER_TAG (-1)
93 #define INFO_IND_TAG (-2)
94 #define INFO_FIRST_TAG 0
95
96 /* -----------------------------------------------------------------------------
97 How much C stack to reserve for local temporaries when in the STG
98 world. Used in StgCRun.c.
99 -------------------------------------------------------------------------- */
100
101 #define RESERVED_C_STACK_BYTES (2048 * SIZEOF_LONG)
102
103 /* -----------------------------------------------------------------------------
104 How much Haskell stack space to reserve for the saving of registers
105 etc. in the case of a stack/heap overflow.
106
107 This must be large enough to accomodate the largest stack frame
108 pushed in one of the heap check fragments in HeapStackCheck.hc
109 (ie. currently the generic heap checks - 3 words for StgRetDyn,
110 18 words for the saved registers, see StgMacros.h).
111
112 In the event of an unboxed tuple or let-no-escape stack/heap check
113 failure, there will be other words on the stack which are covered
114 by the RET_DYN frame. These will have been accounted for by stack
115 checks however, so we don't need to allow for them here.
116 -------------------------------------------------------------------------- */
117
118 #define RESERVED_STACK_WORDS 21
119
120 /* -----------------------------------------------------------------------------
121 The limit on the size of the stack check performed when we enter an
122 AP_STACK, in words. See raiseAsync() and bug #1466.
123 -------------------------------------------------------------------------- */
124
125 #define AP_STACK_SPLIM 1024
126
127 /* -----------------------------------------------------------------------------
128 Storage manager constants
129 -------------------------------------------------------------------------- */
130
131 /* The size of a block (2^BLOCK_SHIFT bytes) */
132 #define BLOCK_SHIFT 12
133
134 /* The size of a megablock (2^MBLOCK_SHIFT bytes) */
135 #define MBLOCK_SHIFT 20
136
137 /* -----------------------------------------------------------------------------
138 Bitmap/size fields (used in info tables)
139 -------------------------------------------------------------------------- */
140
141 /* In a 32-bit bitmap field, we use 5 bits for the size, and 27 bits
142 * for the bitmap. If the bitmap requires more than 27 bits, then we
143 * store it in a separate array, and leave a pointer in the bitmap
144 * field. On a 64-bit machine, the sizes are extended accordingly.
145 */
146 #if SIZEOF_VOID_P == 4
147 #define BITMAP_SIZE_MASK 0x1f
148 #define BITMAP_BITS_SHIFT 5
149 #elif SIZEOF_VOID_P == 8
150 #define BITMAP_SIZE_MASK 0x3f
151 #define BITMAP_BITS_SHIFT 6
152 #else
153 #error unknown SIZEOF_VOID_P
154 #endif
155
156 /* -----------------------------------------------------------------------------
157 Lag/Drag/Void constants
158 -------------------------------------------------------------------------- */
159
160 /*
161 An LDV word is divided into 3 parts: state bits (LDV_STATE_MASK), creation
162 time bits (LDV_CREATE_MASK), and last use time bits (LDV_LAST_MASK).
163 */
164 #if SIZEOF_VOID_P == 8
165 #define LDV_SHIFT 30
166 #define LDV_STATE_MASK 0x1000000000000000
167 #define LDV_CREATE_MASK 0x0FFFFFFFC0000000
168 #define LDV_LAST_MASK 0x000000003FFFFFFF
169 #define LDV_STATE_CREATE 0x0000000000000000
170 #define LDV_STATE_USE 0x1000000000000000
171 #else
172 #define LDV_SHIFT 15
173 #define LDV_STATE_MASK 0x40000000
174 #define LDV_CREATE_MASK 0x3FFF8000
175 #define LDV_LAST_MASK 0x00007FFF
176 #define LDV_STATE_CREATE 0x00000000
177 #define LDV_STATE_USE 0x40000000
178 #endif /* SIZEOF_VOID_P */
179
180 /* -----------------------------------------------------------------------------
181 TSO related constants
182 -------------------------------------------------------------------------- */
183
184 /*
185 * Constants for the what_next field of a TSO, which indicates how it
186 * is to be run.
187 */
188 #define ThreadRunGHC 1 /* return to address on top of stack */
189 #define ThreadInterpret 2 /* interpret this thread */
190 #define ThreadKilled 3 /* thread has died, don't run it */
191 #define ThreadRelocated 4 /* thread has moved, link points to new locn */
192 #define ThreadComplete 5 /* thread has finished */
193
194 /*
195 * Constants for the why_blocked field of a TSO
196 */
197 #define NotBlocked 0
198 #define BlockedOnMVar 1
199 #define BlockedOnBlackHole 2
200 #define BlockedOnException 3
201 #define BlockedOnRead 4
202 #define BlockedOnWrite 5
203 #define BlockedOnDelay 6
204 #define BlockedOnSTM 7
205
206 /* Win32 only: */
207 #define BlockedOnDoProc 8
208
209 /* Only relevant for PAR: */
210 /* blocked on a remote closure represented by a Global Address: */
211 #define BlockedOnGA 9
212 /* same as above but without sending a Fetch message */
213 #define BlockedOnGA_NoSend 10
214 /* Only relevant for THREADED_RTS: */
215 #define BlockedOnCCall 11
216 #define BlockedOnCCall_NoUnblockExc 12
217 /* same as above but don't unblock async exceptions in resumeThread() */
218
219 /*
220 * These constants are returned to the scheduler by a thread that has
221 * stopped for one reason or another. See typedef StgThreadReturnCode
222 * in TSO.h.
223 */
224 #define HeapOverflow 1 /* might also be StackOverflow */
225 #define StackOverflow 2
226 #define ThreadYielding 3
227 #define ThreadBlocked 4
228 #define ThreadFinished 5
229
230 /*
231 * Flags for the tso->flags field.
232 *
233 * The TSO_DIRTY flag indicates that this TSO's stack should be
234 * scanned during garbage collection. The link field of a TSO is
235 * always scanned, so we don't have to dirty a TSO just for linking
236 * it on a different list.
237 *
238 * TSO_DIRTY is set by
239 * - schedule(), just before running a thread,
240 * - raiseAsync(), because it modifies a thread's stack
241 * - resumeThread(), just before running the thread again
242 * and unset by the garbage collector (only).
243 */
244 #define TSO_DIRTY 1
245
246 /*
247 * TSO_LOCKED is set when a TSO is locked to a particular Capability.
248 */
249 #define TSO_LOCKED 2
250
251 /*
252 * TSO_BLOCKEX: the TSO is blocking exceptions
253 *
254 * TSO_INTERRUPTIBLE: the TSO can be interrupted if it blocks
255 * interruptibly (eg. with BlockedOnMVar).
256 *
257 * TSO_STOPPED_ON_BREAKPOINT: the thread is currently stopped in a breakpoint
258 */
259 #define TSO_BLOCKEX 4
260 #define TSO_INTERRUPTIBLE 8
261 #define TSO_STOPPED_ON_BREAKPOINT 16
262
263 /*
264 * TSO_LINK_DIRTY is set when a TSO's link field is modified
265 */
266 #define TSO_LINK_DIRTY 32
267
268 /* -----------------------------------------------------------------------------
269 RET_DYN stack frames
270 -------------------------------------------------------------------------- */
271
272 /* VERY MAGIC CONSTANTS!
273 * must agree with code in HeapStackCheck.c, stg_gen_chk, and
274 * RESERVED_STACK_WORDS in Constants.h.
275 */
276 #define RET_DYN_BITMAP_SIZE 8
277 #define RET_DYN_NONPTR_REGS_SIZE 10
278
279 /* Sanity check that RESERVED_STACK_WORDS is reasonable. We can't
280 * just derive RESERVED_STACK_WORDS because it's used in Haskell code
281 * too.
282 */
283 #if RESERVED_STACK_WORDS != (3 + RET_DYN_BITMAP_SIZE + RET_DYN_NONPTR_REGS_SIZE)
284 #error RESERVED_STACK_WORDS may be wrong!
285 #endif
286
287 #endif /* CONSTANTS_H */