testsuite: Assert that testsuite ways are known
[ghc.git] / includes / rts / Constants.h
1 /* ----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1998-2009
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 * To understand the structure of the RTS headers, see the wiki:
16 * https://gitlab.haskell.org/ghc/ghc/wikis/commentary/source-tree/includes
17 *
18 * -------------------------------------------------------------------------- */
19
20 #pragma once
21
22 /* -----------------------------------------------------------------------------
23 Minimum closure sizes
24
25 This is the minimum number of words in the payload of a heap-allocated
26 closure, so that the closure has two bits in the bitmap for mark-compact
27 collection.
28
29 See Note [Mark bits in mark-compact collector] in rts/sm/Compact.h
30 -------------------------------------------------------------------------- */
31
32 #define MIN_PAYLOAD_SIZE 1
33
34 /* -----------------------------------------------------------------------------
35 Constants to do with specialised closure types.
36 -------------------------------------------------------------------------- */
37
38 /* We have some pre-compiled selector thunks defined in rts/StgStdThunks.hc.
39 * This constant defines the highest selectee index that we can replace with a
40 * reference to the pre-compiled code.
41 */
42
43 #define MAX_SPEC_SELECTEE_SIZE 15
44
45 /* Vector-apply thunks. These thunks just push their free variables
46 * on the stack and enter the first one. They're a bit like PAPs, but
47 * don't have a dynamic size. We've pre-compiled a few to save
48 * space.
49 */
50
51 #define MAX_SPEC_AP_SIZE 7
52
53 /* Specialised FUN/THUNK/CONSTR closure types */
54
55 #define MAX_SPEC_THUNK_SIZE 2
56 #define MAX_SPEC_FUN_SIZE 2
57 #define MAX_SPEC_CONSTR_SIZE 2
58
59 /* Range of built-in table of static small int-like and char-like closures.
60 *
61 * NB. This corresponds with the number of actual INTLIKE/CHARLIKE
62 * closures defined in rts/StgMiscClosures.cmm.
63 */
64 #define MAX_INTLIKE 255
65 #define MIN_INTLIKE (-16)
66
67 #define MAX_CHARLIKE 255
68 #define MIN_CHARLIKE 0
69
70 /* Each byte in the card table for an StgMutaArrPtrs covers
71 * (1<<MUT_ARR_PTRS_CARD_BITS) elements in the array. To find a good
72 * value for this, I used the benchmarks nofib/gc/hash,
73 * nofib/gc/graph, and nofib/gc/gc_bench.
74 */
75 #define MUT_ARR_PTRS_CARD_BITS 7
76
77 /* -----------------------------------------------------------------------------
78 STG Registers.
79
80 Note that in MachRegs.h we define how many of these registers are
81 *real* machine registers, and not just offsets in the Register Table.
82 -------------------------------------------------------------------------- */
83
84 #define MAX_VANILLA_REG 10
85 #define MAX_FLOAT_REG 6
86 #define MAX_DOUBLE_REG 6
87 #define MAX_LONG_REG 1
88 #define MAX_XMM_REG 6
89
90 /* -----------------------------------------------------------------------------
91 Semi-Tagging constants
92
93 Old Comments about this stuff:
94
95 Tags for indirection nodes and ``other'' (probably unevaluated) nodes;
96 normal-form values of algebraic data types will have tags 0, 1, ...
97
98 @INFO_IND_TAG@ is different from @INFO_OTHER_TAG@ just so we can count
99 how often we bang into indirection nodes; that's all. (WDP 95/11)
100
101 ToDo: find out if we need any of this.
102 -------------------------------------------------------------------------- */
103
104 #define INFO_OTHER_TAG (-1)
105 #define INFO_IND_TAG (-2)
106 #define INFO_FIRST_TAG 0
107
108 /* -----------------------------------------------------------------------------
109 How much C stack to reserve for local temporaries when in the STG
110 world. Used in StgCRun.c.
111 -------------------------------------------------------------------------- */
112
113 #define RESERVED_C_STACK_BYTES (2048 * SIZEOF_LONG)
114
115 /* -----------------------------------------------------------------------------
116 How large is the stack frame saved by StgRun?
117 world. Used in StgCRun.c.
118
119 The size has to be enough to save the registers (see StgCRun)
120 plus padding if the result is not 16 byte aligned.
121 See the Note [Stack Alignment on X86] in StgCRun.c for details.
122
123 -------------------------------------------------------------------------- */
124 #if defined(x86_64_HOST_ARCH)
125 # if defined(mingw32_HOST_OS)
126 # define STG_RUN_STACK_FRAME_SIZE 144
127 # else
128 # define STG_RUN_STACK_FRAME_SIZE 48
129 # endif
130 #endif
131
132 /* -----------------------------------------------------------------------------
133 StgRun related labels shared between StgCRun.c and StgStartup.cmm.
134 -------------------------------------------------------------------------- */
135
136 #if defined(LEADING_UNDERSCORE)
137 #define STG_RUN "_StgRun"
138 #define STG_RUN_JMP _StgRunJmp
139 #define STG_RETURN "_StgReturn"
140 #else
141 #define STG_RUN "StgRun"
142 #define STG_RUN_JMP StgRunJmp
143 #define STG_RETURN "StgReturn"
144 #endif
145
146 /* -----------------------------------------------------------------------------
147 How much Haskell stack space to reserve for the saving of registers
148 etc. in the case of a stack/heap overflow.
149
150 This must be large enough to accommodate the largest stack frame
151 pushed in one of the heap check fragments in HeapStackCheck.hc
152 (ie. currently the generic heap checks - 3 words for StgRetDyn,
153 18 words for the saved registers, see StgMacros.h).
154 -------------------------------------------------------------------------- */
155
156 #define RESERVED_STACK_WORDS 21
157
158 /* -----------------------------------------------------------------------------
159 The limit on the size of the stack check performed when we enter an
160 AP_STACK, in words. See raiseAsync() and bug #1466.
161 -------------------------------------------------------------------------- */
162
163 #define AP_STACK_SPLIM 1024
164
165 /* -----------------------------------------------------------------------------
166 Storage manager constants
167 -------------------------------------------------------------------------- */
168
169 /* The size of a block (2^BLOCK_SHIFT bytes) */
170 #define BLOCK_SHIFT 12
171
172 /* The size of a megablock (2^MBLOCK_SHIFT bytes) */
173 #define MBLOCK_SHIFT 20
174
175 /* -----------------------------------------------------------------------------
176 Bitmap/size fields (used in info tables)
177 -------------------------------------------------------------------------- */
178
179 /* In a 32-bit bitmap field, we use 5 bits for the size, and 27 bits
180 * for the bitmap. If the bitmap requires more than 27 bits, then we
181 * store it in a separate array, and leave a pointer in the bitmap
182 * field. On a 64-bit machine, the sizes are extended accordingly.
183 */
184 #if SIZEOF_VOID_P == 4
185 #define BITMAP_SIZE_MASK 0x1f
186 #define BITMAP_BITS_SHIFT 5
187 #elif SIZEOF_VOID_P == 8
188 #define BITMAP_SIZE_MASK 0x3f
189 #define BITMAP_BITS_SHIFT 6
190 #else
191 #error unknown SIZEOF_VOID_P
192 #endif
193
194 /* -----------------------------------------------------------------------------
195 Lag/Drag/Void constants
196 -------------------------------------------------------------------------- */
197
198 /*
199 An LDV word is divided into 3 parts: state bits (LDV_STATE_MASK), creation
200 time bits (LDV_CREATE_MASK), and last use time bits (LDV_LAST_MASK).
201 */
202 #if SIZEOF_VOID_P == 8
203 #define LDV_SHIFT 30
204 #define LDV_STATE_MASK 0x1000000000000000
205 #define LDV_CREATE_MASK 0x0FFFFFFFC0000000
206 #define LDV_LAST_MASK 0x000000003FFFFFFF
207 #define LDV_STATE_CREATE 0x0000000000000000
208 #define LDV_STATE_USE 0x1000000000000000
209 #else
210 #define LDV_SHIFT 15
211 #define LDV_STATE_MASK 0x40000000
212 #define LDV_CREATE_MASK 0x3FFF8000
213 #define LDV_LAST_MASK 0x00007FFF
214 #define LDV_STATE_CREATE 0x00000000
215 #define LDV_STATE_USE 0x40000000
216 #endif /* SIZEOF_VOID_P */
217
218 /* -----------------------------------------------------------------------------
219 TSO related constants
220 -------------------------------------------------------------------------- */
221
222 /*
223 * Constants for the what_next field of a TSO, which indicates how it
224 * is to be run.
225 */
226 #define ThreadRunGHC 1 /* return to address on top of stack */
227 #define ThreadInterpret 2 /* interpret this thread */
228 #define ThreadKilled 3 /* thread has died, don't run it */
229 #define ThreadComplete 4 /* thread has finished */
230
231 /*
232 * Constants for the why_blocked field of a TSO
233 * NB. keep these in sync with GHC/Conc/Sync.hs: threadStatus
234 */
235 #define NotBlocked 0
236 #define BlockedOnMVar 1
237 #define BlockedOnMVarRead 14 /* TODO: renumber me, see #9003 */
238 #define BlockedOnBlackHole 2
239 #define BlockedOnRead 3
240 #define BlockedOnWrite 4
241 #define BlockedOnDelay 5
242 #define BlockedOnSTM 6
243
244 /* Win32 only: */
245 #define BlockedOnDoProc 7
246
247 /* Only relevant for THREADED_RTS: */
248 #define BlockedOnCCall 10
249 #define BlockedOnCCall_Interruptible 11
250 /* same as above but permit killing the worker thread */
251
252 /* Involved in a message sent to tso->msg_cap */
253 #define BlockedOnMsgThrowTo 12
254
255 /* The thread is not on any run queues, but can be woken up
256 by tryWakeupThread() */
257 #define ThreadMigrating 13
258
259 /* WARNING WARNING top number is BlockedOnMVarRead 14, not 13!! */
260
261 /*
262 * These constants are returned to the scheduler by a thread that has
263 * stopped for one reason or another. See typedef StgThreadReturnCode
264 * in TSO.h.
265 */
266 #define HeapOverflow 1 /* might also be StackOverflow */
267 #define StackOverflow 2
268 #define ThreadYielding 3
269 #define ThreadBlocked 4
270 #define ThreadFinished 5
271
272 /*
273 * Flags for the tso->flags field.
274 */
275
276 /*
277 * TSO_LOCKED is set when a TSO is locked to a particular Capability.
278 */
279 #define TSO_LOCKED 2
280
281 /*
282 * TSO_BLOCKEX: the TSO is blocking exceptions
283 *
284 * TSO_INTERRUPTIBLE: the TSO can be interrupted if it blocks
285 * interruptibly (eg. with BlockedOnMVar).
286 *
287 * TSO_STOPPED_ON_BREAKPOINT: the thread is currently stopped in a breakpoint
288 */
289 #define TSO_BLOCKEX 4
290 #define TSO_INTERRUPTIBLE 8
291 #define TSO_STOPPED_ON_BREAKPOINT 16
292
293 /*
294 * Used by the sanity checker to check whether TSOs are on the correct
295 * mutable list.
296 */
297 #define TSO_MARKED 64
298
299 /*
300 * Used to communicate between stackSqueeze() and
301 * threadStackOverflow() that a thread's stack was squeezed and the
302 * stack may not need to be expanded.
303 */
304 #define TSO_SQUEEZED 128
305
306 /*
307 * Enables the AllocationLimitExceeded exception when the thread's
308 * allocation limit goes negative.
309 */
310 #define TSO_ALLOC_LIMIT 256
311
312 /*
313 * The number of times we spin in a spin lock before yielding (see
314 * #3758). To tune this value, use the benchmark in #3758: run the
315 * server with -N2 and the client both on a dual-core. Also make sure
316 * that the chosen value doesn't slow down any of the parallel
317 * benchmarks in nofib/parallel.
318 */
319 #define SPIN_COUNT 1000
320
321 /* -----------------------------------------------------------------------------
322 Spare workers per Capability in the threaded RTS
323
324 No more than MAX_SPARE_WORKERS will be kept in the thread pool
325 associated with each Capability.
326 -------------------------------------------------------------------------- */
327
328 #define MAX_SPARE_WORKERS 6
329
330 /*
331 * The maximum number of NUMA nodes we support. This is a fixed limit so that
332 * we can have static arrays of this size in the RTS for speed.
333 */
334 #define MAX_NUMA_NODES 16