1 /* ----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2009
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.
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).
15 * To understand the structure of the RTS headers, see the wiki:
16 * http://hackage.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
18 * -------------------------------------------------------------------------- */
20 #ifndef RTS_CONSTANTS_H
21 #define RTS_CONSTANTS_H
23 /* -----------------------------------------------------------------------------
26 This is the minimum number of words in the payload of a
27 heap-allocated closure, so that the closure has enough room to be
28 overwritten with a forwarding pointer during garbage collection.
29 -------------------------------------------------------------------------- */
31 #define MIN_PAYLOAD_SIZE 1
33 /* -----------------------------------------------------------------------------
34 Constants to do with specialised closure types.
35 -------------------------------------------------------------------------- */
37 /* We have some pre-compiled selector thunks defined in rts/StgStdThunks.hc.
38 * This constant defines the highest selectee index that we can replace with a
39 * reference to the pre-compiled code.
42 #define MAX_SPEC_SELECTEE_SIZE 15
44 /* Vector-apply thunks. These thunks just push their free variables
45 * on the stack and enter the first one. They're a bit like PAPs, but
46 * don't have a dynamic size. We've pre-compiled a few to save
50 #define MAX_SPEC_AP_SIZE 7
52 /* Specialised FUN/THUNK/CONSTR closure types */
54 #define MAX_SPEC_THUNK_SIZE 2
55 #define MAX_SPEC_FUN_SIZE 2
56 #define MAX_SPEC_CONSTR_SIZE 2
58 /* Range of built-in table of static small int-like and char-like closures.
60 * NB. This corresponds with the number of actual INTLIKE/CHARLIKE
61 * closures defined in rts/StgMiscClosures.cmm.
63 #define MAX_INTLIKE 16
64 #define MIN_INTLIKE (-16)
66 #define MAX_CHARLIKE 255
67 #define MIN_CHARLIKE 0
69 /* -----------------------------------------------------------------------------
72 Note that in MachRegs.h we define how many of these registers are
73 *real* machine registers, and not just offsets in the Register Table.
74 -------------------------------------------------------------------------- */
76 #define MAX_VANILLA_REG 8
77 #define MAX_FLOAT_REG 4
78 #define MAX_DOUBLE_REG 2
79 #define MAX_LONG_REG 1
81 /* -----------------------------------------------------------------------------
82 Semi-Tagging constants
84 Old Comments about this stuff:
86 Tags for indirection nodes and ``other'' (probably unevaluated) nodes;
87 normal-form values of algebraic data types will have tags 0, 1, ...
89 @INFO_IND_TAG@ is different from @INFO_OTHER_TAG@ just so we can count
90 how often we bang into indirection nodes; that's all. (WDP 95/11)
92 ToDo: find out if we need any of this.
93 -------------------------------------------------------------------------- */
95 #define INFO_OTHER_TAG (-1)
96 #define INFO_IND_TAG (-2)
97 #define INFO_FIRST_TAG 0
99 /* -----------------------------------------------------------------------------
100 How much C stack to reserve for local temporaries when in the STG
101 world. Used in StgCRun.c.
102 -------------------------------------------------------------------------- */
104 #define RESERVED_C_STACK_BYTES (2048 * SIZEOF_LONG)
106 /* -----------------------------------------------------------------------------
107 How much Haskell stack space to reserve for the saving of registers
108 etc. in the case of a stack/heap overflow.
110 This must be large enough to accomodate the largest stack frame
111 pushed in one of the heap check fragments in HeapStackCheck.hc
112 (ie. currently the generic heap checks - 3 words for StgRetDyn,
113 18 words for the saved registers, see StgMacros.h).
115 In the event of an unboxed tuple or let-no-escape stack/heap check
116 failure, there will be other words on the stack which are covered
117 by the RET_DYN frame. These will have been accounted for by stack
118 checks however, so we don't need to allow for them here.
119 -------------------------------------------------------------------------- */
121 #define RESERVED_STACK_WORDS 21
123 /* -----------------------------------------------------------------------------
124 The limit on the size of the stack check performed when we enter an
125 AP_STACK, in words. See raiseAsync() and bug #1466.
126 -------------------------------------------------------------------------- */
128 #define AP_STACK_SPLIM 1024
130 /* -----------------------------------------------------------------------------
131 Storage manager constants
132 -------------------------------------------------------------------------- */
134 /* The size of a block (2^BLOCK_SHIFT bytes) */
135 #define BLOCK_SHIFT 12
137 /* The size of a megablock (2^MBLOCK_SHIFT bytes) */
138 #define MBLOCK_SHIFT 20
140 /* -----------------------------------------------------------------------------
141 Bitmap/size fields (used in info tables)
142 -------------------------------------------------------------------------- */
144 /* In a 32-bit bitmap field, we use 5 bits for the size, and 27 bits
145 * for the bitmap. If the bitmap requires more than 27 bits, then we
146 * store it in a separate array, and leave a pointer in the bitmap
147 * field. On a 64-bit machine, the sizes are extended accordingly.
149 #if SIZEOF_VOID_P == 4
150 #define BITMAP_SIZE_MASK 0x1f
151 #define BITMAP_BITS_SHIFT 5
152 #elif SIZEOF_VOID_P == 8
153 #define BITMAP_SIZE_MASK 0x3f
154 #define BITMAP_BITS_SHIFT 6
156 #error unknown SIZEOF_VOID_P
159 /* -----------------------------------------------------------------------------
160 Lag/Drag/Void constants
161 -------------------------------------------------------------------------- */
164 An LDV word is divided into 3 parts: state bits (LDV_STATE_MASK), creation
165 time bits (LDV_CREATE_MASK), and last use time bits (LDV_LAST_MASK).
167 #if SIZEOF_VOID_P == 8
169 #define LDV_STATE_MASK 0x1000000000000000
170 #define LDV_CREATE_MASK 0x0FFFFFFFC0000000
171 #define LDV_LAST_MASK 0x000000003FFFFFFF
172 #define LDV_STATE_CREATE 0x0000000000000000
173 #define LDV_STATE_USE 0x1000000000000000
176 #define LDV_STATE_MASK 0x40000000
177 #define LDV_CREATE_MASK 0x3FFF8000
178 #define LDV_LAST_MASK 0x00007FFF
179 #define LDV_STATE_CREATE 0x00000000
180 #define LDV_STATE_USE 0x40000000
181 #endif /* SIZEOF_VOID_P */
183 /* -----------------------------------------------------------------------------
184 TSO related constants
185 -------------------------------------------------------------------------- */
188 * Constants for the what_next field of a TSO, which indicates how it
191 #define ThreadRunGHC 1 /* return to address on top of stack */
192 #define ThreadInterpret 2 /* interpret this thread */
193 #define ThreadKilled 3 /* thread has died, don't run it */
194 #define ThreadRelocated 4 /* thread has moved, link points to new locn */
195 #define ThreadComplete 5 /* thread has finished */
198 * Constants for the why_blocked field of a TSO
199 * NB. keep these in sync with GHC/Conc.lhs: threadStatus
202 #define BlockedOnMVar 1
203 #define BlockedOnBlackHole 2
204 #define BlockedOnException 3
205 #define BlockedOnRead 4
206 #define BlockedOnWrite 5
207 #define BlockedOnDelay 6
208 #define BlockedOnSTM 7
211 #define BlockedOnDoProc 8
213 /* Only relevant for PAR: */
214 /* blocked on a remote closure represented by a Global Address: */
215 #define BlockedOnGA 9
216 /* same as above but without sending a Fetch message */
217 #define BlockedOnGA_NoSend 10
218 /* Only relevant for THREADED_RTS: */
219 #define BlockedOnCCall 11
220 #define BlockedOnCCall_NoUnblockExc 12
221 /* same as above but don't unblock async exceptions in resumeThread() */
224 * These constants are returned to the scheduler by a thread that has
225 * stopped for one reason or another. See typedef StgThreadReturnCode
228 #define HeapOverflow 1 /* might also be StackOverflow */
229 #define StackOverflow 2
230 #define ThreadYielding 3
231 #define ThreadBlocked 4
232 #define ThreadFinished 5
235 * Flags for the tso->flags field.
239 * TSO_LOCKED is set when a TSO is locked to a particular Capability.
244 * TSO_BLOCKEX: the TSO is blocking exceptions
246 * TSO_INTERRUPTIBLE: the TSO can be interrupted if it blocks
247 * interruptibly (eg. with BlockedOnMVar).
249 * TSO_STOPPED_ON_BREAKPOINT: the thread is currently stopped in a breakpoint
251 #define TSO_BLOCKEX 4
252 #define TSO_INTERRUPTIBLE 8
253 #define TSO_STOPPED_ON_BREAKPOINT 16
256 * TSO_LINK_DIRTY is set when a TSO's link field is modified
258 #define TSO_LINK_DIRTY 32
260 #define TSO_MARKED 64
262 /* -----------------------------------------------------------------------------
264 -------------------------------------------------------------------------- */
266 /* VERY MAGIC CONSTANTS!
267 * must agree with code in HeapStackCheck.c, stg_gen_chk, and
268 * RESERVED_STACK_WORDS in Constants.h.
270 #define RET_DYN_BITMAP_SIZE 8
271 #define RET_DYN_NONPTR_REGS_SIZE 10
273 /* Sanity check that RESERVED_STACK_WORDS is reasonable. We can't
274 * just derive RESERVED_STACK_WORDS because it's used in Haskell code
277 #if RESERVED_STACK_WORDS != (3 + RET_DYN_BITMAP_SIZE + RET_DYN_NONPTR_REGS_SIZE)
278 #error RESERVED_STACK_WORDS may be wrong!
281 #endif /* RTS_CONSTANTS_H */