Add Note [BLACKHOLE points to IND]
[ghc.git] / rts / StgMiscClosures.cmm
1 /* ----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-2004
4  *
5  * Entry code for various built-in closure types.
6  *
7  * This file is written in a subset of C--, extended with various
8  * features specific to GHC.  It is compiled by GHC directly.  For the
9  * syntax of .cmm files, see the parser in ghc/compiler/cmm/CmmParse.y.
10  *
11  * --------------------------------------------------------------------------*/
12
13 #include "Cmm.h"
14
15 import pthread_mutex_lock;
16 import ghczmprim_GHCziTypes_Czh_info;
17 import ghczmprim_GHCziTypes_Izh_info;
18 import EnterCriticalSection;
19 import LeaveCriticalSection;
20
21 /* ----------------------------------------------------------------------------
22    Stack underflow
23    ------------------------------------------------------------------------- */
24
25 INFO_TABLE_RET (stg_stack_underflow_frame, UNDERFLOW_FRAME,
26                 W_ info_ptr, P_ unused)
27     /* no args => explicit stack */
28 {
29     unwind Sp = W_[Sp + WDS(2)];
30
31     W_ new_tso;
32     W_ ret_off;
33
34     SAVE_STGREGS
35
36     SAVE_THREAD_STATE();
37     (ret_off) = foreign "C" threadStackUnderflow(MyCapability() "ptr",
38                                                  CurrentTSO);
39     LOAD_THREAD_STATE();
40
41     RESTORE_STGREGS
42
43     jump %ENTRY_CODE(Sp(ret_off)) [*]; // NB. all registers live!
44 }
45
46 /* ----------------------------------------------------------------------------
47    Restore a saved cost centre
48    ------------------------------------------------------------------------- */
49
50 INFO_TABLE_RET (stg_restore_cccs, RET_SMALL, W_ info_ptr, W_ cccs)
51 {
52     unwind Sp = Sp + WDS(2);
53 #if defined(PROFILING)
54     CCCS = Sp(1);
55 #endif
56     Sp_adj(2);
57     jump %ENTRY_CODE(Sp(0)) [*]; // NB. all registers live!
58 }
59
60
61 INFO_TABLE_RET (stg_restore_cccs_eval, RET_SMALL, W_ info_ptr, W_ cccs)
62     return (P_ ret)
63 {
64     unwind Sp = Sp + WDS(2);
65 #if defined(PROFILING)
66     CCCS = cccs;
67 #endif
68     jump stg_ap_0_fast(ret);
69 }
70
71 /* ----------------------------------------------------------------------------
72    Support for the bytecode interpreter.
73    ------------------------------------------------------------------------- */
74
75 /* 7 bits of return code for constructors created by the interpreter. */
76 stg_interp_constr1_entry (P_ ret) { return (ret + 1); }
77 stg_interp_constr2_entry (P_ ret) { return (ret + 2); }
78 stg_interp_constr3_entry (P_ ret) { return (ret + 3); }
79 stg_interp_constr4_entry (P_ ret) { return (ret + 4); }
80 stg_interp_constr5_entry (P_ ret) { return (ret + 5); }
81 stg_interp_constr6_entry (P_ ret) { return (ret + 6); }
82 stg_interp_constr7_entry (P_ ret) { return (ret + 7); }
83
84 /* Some info tables to be used when compiled code returns a value to
85    the interpreter, i.e. the interpreter pushes one of these onto the
86    stack before entering a value.  What the code does is to
87    impedance-match the compiled return convention (in R1p/R1n/F1/D1 etc) to
88    the interpreter's convention (returned value is on top of stack),
89    and then cause the scheduler to enter the interpreter.
90
91    On entry, the stack (growing down) looks like this:
92
93       ptr to BCO holding return continuation
94       ptr to one of these info tables.
95
96    The info table code, both direct and vectored, must:
97       * push R1/F1/D1 on the stack, and its tag if necessary
98       * push the BCO (so it's now on the stack twice)
99       * Yield, ie, go to the scheduler.
100
101    Scheduler examines the t.o.s, discovers it is a BCO, and proceeds
102    directly to the bytecode interpreter.  That pops the top element
103    (the BCO, containing the return continuation), and interprets it.
104    Net result: return continuation gets interpreted, with the
105    following stack:
106
107       ptr to this BCO
108       ptr to the info table just jumped thru
109       return value
110
111    which is just what we want -- the "standard" return layout for the
112    interpreter.  Hurrah!
113
114    Don't ask me how unboxed tuple returns are supposed to work.  We
115    haven't got a good story about that yet.
116 */
117
118 INFO_TABLE_RET( stg_ctoi_R1p, RET_BCO)
119     /* explicit stack */
120 {
121     Sp_adj(-2);
122     Sp(1) = R1;
123     Sp(0) = stg_enter_info;
124     jump stg_yield_to_interpreter [];
125 }
126
127 /*
128  * When the returned value is a pointer, but unlifted, in R1 ...
129  */
130 INFO_TABLE_RET( stg_ctoi_R1unpt, RET_BCO )
131     /* explicit stack */
132 {
133     Sp_adj(-2);
134     Sp(1) = R1;
135     Sp(0) = stg_ret_p_info;
136     jump stg_yield_to_interpreter [];
137 }
138
139 /*
140  * When the returned value is a non-pointer in R1 ...
141  */
142 INFO_TABLE_RET( stg_ctoi_R1n, RET_BCO )
143     /* explicit stack */
144 {
145     Sp_adj(-2);
146     Sp(1) = R1;
147     Sp(0) = stg_ret_n_info;
148     jump stg_yield_to_interpreter [];
149 }
150
151 /*
152  * When the returned value is in F1
153  */
154 INFO_TABLE_RET( stg_ctoi_F1, RET_BCO )
155     /* explicit stack */
156 {
157     Sp_adj(-2);
158     F_[Sp + WDS(1)] = F1;
159     Sp(0) = stg_ret_f_info;
160     jump stg_yield_to_interpreter [];
161 }
162
163 /*
164  * When the returned value is in D1
165  */
166 INFO_TABLE_RET( stg_ctoi_D1, RET_BCO )
167     /* explicit stack */
168 {
169     Sp_adj(-1) - SIZEOF_DOUBLE;
170     D_[Sp + WDS(1)] = D1;
171     Sp(0) = stg_ret_d_info;
172     jump stg_yield_to_interpreter [];
173 }
174
175 /*
176  * When the returned value is in L1
177  */
178 INFO_TABLE_RET( stg_ctoi_L1, RET_BCO )
179     /* explicit stack */
180 {
181     Sp_adj(-1) - 8;
182     L_[Sp + WDS(1)] = L1;
183     Sp(0) = stg_ret_l_info;
184     jump stg_yield_to_interpreter [];
185 }
186
187 /*
188  * When the returned value is a void
189  */
190 INFO_TABLE_RET( stg_ctoi_V, RET_BCO )
191     /* explicit stack */
192 {
193     Sp_adj(-1);
194     Sp(0) = stg_ret_v_info;
195     jump stg_yield_to_interpreter [];
196 }
197
198 /*
199  * Dummy info table pushed on the top of the stack when the interpreter
200  * should apply the BCO on the stack to its arguments, also on the
201  * stack.
202  */
203 INFO_TABLE_RET( stg_apply_interp, RET_BCO )
204     /* explicit stack */
205 {
206     /* Just in case we end up in here... (we shouldn't) */
207     jump stg_yield_to_interpreter [];
208 }
209
210 /* ----------------------------------------------------------------------------
211    Entry code for a BCO
212    ------------------------------------------------------------------------- */
213
214 INFO_TABLE_FUN( stg_BCO, 4, 0, BCO, "BCO", "BCO", ARG_BCO )
215     /* explicit stack */
216 {
217   /* entering a BCO means "apply it", same as a function */
218   Sp_adj(-2);
219   // Skip the stack check; the interpreter will do one before using
220   // the stack anyway.
221   Sp(1) = R1;
222   Sp(0) = stg_apply_interp_info;
223   jump stg_yield_to_interpreter [];
224 }
225
226 /* ----------------------------------------------------------------------------
227    Info tables for indirections.
228
229    SPECIALISED INDIRECTIONS: we have a specialised indirection for direct returns,
230    so that we can avoid entering
231    the object when we know it points directly to a value.  The update
232    code (Updates.cmm) updates objects with the appropriate kind of
233    indirection.  We only do this for young-gen indirections.
234    ------------------------------------------------------------------------- */
235
236 INFO_TABLE(stg_IND,1,0,IND,"IND","IND")
237 #if 0
238 /*
239   This version in high-level cmm generates slightly less good code
240   than the low-level version below it. (ToDo)
241 */
242     (P_ node)
243 {
244     TICK_ENT_DYN_IND(); /* tick */
245     node = UNTAG(StgInd_indirectee(node));
246     TICK_ENT_VIA_NODE();
247     jump %GET_ENTRY(node) (node);
248 }
249 #else
250     /* explicit stack */
251 {
252     TICK_ENT_DYN_IND(); /* tick */
253     R1 = UNTAG(StgInd_indirectee(R1));
254     TICK_ENT_VIA_NODE();
255     jump %GET_ENTRY(R1) [R1];
256 }
257 #endif
258
259 INFO_TABLE(stg_IND_direct,1,0,IND,"IND","IND")
260     (P_ node)
261 {
262     TICK_ENT_DYN_IND(); /* tick */
263     node = StgInd_indirectee(node);
264     TICK_ENT_VIA_NODE();
265     jump %ENTRY_CODE(Sp(0)) (node);
266 }
267
268 INFO_TABLE(stg_IND_STATIC,1,0,IND_STATIC,"IND_STATIC","IND_STATIC")
269     /* explicit stack */
270 {
271     TICK_ENT_STATIC_IND(); /* tick */
272     R1 = UNTAG(StgInd_indirectee(R1));
273     TICK_ENT_VIA_NODE();
274     jump %GET_ENTRY(R1) [R1];
275 }
276
277 /* ----------------------------------------------------------------------------
278    Black holes.
279
280    Entering a black hole normally causes a cyclic data dependency, but
281    in the concurrent world, black holes are synchronization points,
282    and they are turned into blocking queues when there are threads
283    waiting for the evaluation of the closure to finish.
284    ------------------------------------------------------------------------- */
285
286 INFO_TABLE(stg_BLACKHOLE,1,0,BLACKHOLE,"BLACKHOLE","BLACKHOLE")
287     (P_ node)
288 {
289     W_ r, info, owner, bd;
290     P_ p, bq, msg;
291
292     TICK_ENT_DYN_IND(); /* tick */
293
294 retry:
295     p = StgInd_indirectee(node);
296     if (GETTAG(p) != 0) {
297         return (p);
298     }
299
300     info = StgHeader_info(p);
301     if (info == stg_IND_info) {
302         // This could happen, if e.g. we got a BLOCKING_QUEUE that has
303         // just been replaced with an IND by another thread in
304         // wakeBlockingQueue().
305         // See Note [BLACKHOLE pointing to IND] in sm/Evac.c
306         goto retry;
307     }
308
309     if (info == stg_TSO_info ||
310         info == stg_BLOCKING_QUEUE_CLEAN_info ||
311         info == stg_BLOCKING_QUEUE_DIRTY_info)
312     {
313         ("ptr" msg) = ccall allocate(MyCapability() "ptr",
314                                      BYTES_TO_WDS(SIZEOF_MessageBlackHole));
315
316         SET_HDR(msg, stg_MSG_BLACKHOLE_info, CCS_SYSTEM);
317         MessageBlackHole_tso(msg) = CurrentTSO;
318         MessageBlackHole_bh(msg) = node;
319
320         (r) = ccall messageBlackHole(MyCapability() "ptr", msg "ptr");
321
322         if (r == 0) {
323             goto retry;
324         } else {
325             StgTSO_why_blocked(CurrentTSO) = BlockedOnBlackHole::I16;
326             StgTSO_block_info(CurrentTSO) = msg;
327             jump stg_block_blackhole(node);
328         }
329     }
330     else
331     {
332         ENTER(p);
333     }
334 }
335
336 // CAF_BLACKHOLE is allocated when entering a CAF.  The reason it is
337 // distinct from BLACKHOLE is so that we can tell the difference
338 // between an update frame on the stack that points to a CAF under
339 // evaluation, and one that points to a closure that is under
340 // evaluation by another thread (a BLACKHOLE).  see Note [suspend
341 // duplicate work] in ThreadPaused.c
342 //
343 INFO_TABLE(stg_CAF_BLACKHOLE,1,0,BLACKHOLE,"BLACKHOLE","BLACKHOLE")
344     (P_ node)
345 {
346     jump ENTRY_LBL(stg_BLACKHOLE) (node);
347 }
348
349 // EAGER_BLACKHOLE exists for the same reason as CAF_BLACKHOLE (see above).
350 INFO_TABLE(__stg_EAGER_BLACKHOLE,1,0,BLACKHOLE,"BLACKHOLE","BLACKHOLE")
351     (P_ node)
352 {
353     jump ENTRY_LBL(stg_BLACKHOLE) (node);
354 }
355
356 INFO_TABLE(stg_BLOCKING_QUEUE_CLEAN,4,0,BLOCKING_QUEUE,"BLOCKING_QUEUE","BLOCKING_QUEUE")
357 { foreign "C" barf("BLOCKING_QUEUE_CLEAN object entered!") never returns; }
358
359
360 INFO_TABLE(stg_BLOCKING_QUEUE_DIRTY,4,0,BLOCKING_QUEUE,"BLOCKING_QUEUE","BLOCKING_QUEUE")
361 { foreign "C" barf("BLOCKING_QUEUE_DIRTY object entered!") never returns; }
362
363
364 /* ----------------------------------------------------------------------------
365    Whiteholes are used for the "locked" state of a closure (see lockClosure())
366    ------------------------------------------------------------------------- */
367
368 INFO_TABLE(stg_WHITEHOLE, 0,0, WHITEHOLE, "WHITEHOLE", "WHITEHOLE")
369     (P_ node)
370 {
371 #if defined(THREADED_RTS)
372     W_ info, i;
373
374     i = 0;
375 loop:
376     // spin until the WHITEHOLE is updated
377     info = StgHeader_info(node);
378     if (info == stg_WHITEHOLE_info) {
379 #if defined(PROF_SPIN)
380         W_[whitehole_lockClosure_spin] =
381             W_[whitehole_lockClosure_spin] + 1;
382 #endif
383         i = i + 1;
384         if (i == SPIN_COUNT) {
385             i = 0;
386 #if defined(PROF_SPIN)
387             W_[whitehole_lockClosure_yield] =
388                 W_[whitehole_lockClosure_yield] + 1;
389 #endif
390             ccall yieldThread();
391         }
392         // TODO: We should busy_wait_nop() here, but that's not currently
393         // defined in CMM.
394         goto loop;
395     }
396     jump %ENTRY_CODE(info) (node);
397 #else
398     ccall barf("WHITEHOLE object entered!") never returns;
399 #endif
400 }
401
402 /* ----------------------------------------------------------------------------
403    Some static info tables for things that don't get entered, and
404    therefore don't need entry code (i.e. boxed but unpointed objects)
405    NON_ENTERABLE_ENTRY_CODE now defined at the beginning of the file
406    ------------------------------------------------------------------------- */
407
408 INFO_TABLE(stg_TSO, 0,0,TSO, "TSO", "TSO")
409 { foreign "C" barf("TSO object entered!") never returns; }
410
411 INFO_TABLE(stg_STACK, 0,0, STACK, "STACK", "STACK")
412 { foreign "C" barf("STACK object entered!") never returns; }
413
414 /* ----------------------------------------------------------------------------
415    Weak pointers
416
417    Live weak pointers have a special closure type.  Dead ones are just
418    nullary constructors (although they live on the heap - we overwrite
419    live weak pointers with dead ones).
420    ------------------------------------------------------------------------- */
421
422 INFO_TABLE(stg_WEAK,1,4,WEAK,"WEAK","WEAK")
423 { foreign "C" barf("WEAK object entered!") never returns; }
424
425 /*
426  * It's important when turning an existing WEAK into a DEAD_WEAK
427  * (which is what finalizeWeak# does) that we don't lose the link
428  * field and break the linked list of weak pointers.  Hence, we give
429  * DEAD_WEAK 5 non-pointer fields.
430  */
431 INFO_TABLE_CONSTR(stg_DEAD_WEAK,0,5,0,CONSTR,"DEAD_WEAK","DEAD_WEAK")
432 { foreign "C" barf("DEAD_WEAK object entered!") never returns; }
433
434 /* ----------------------------------------------------------------------------
435    C finalizer lists
436
437    Singly linked lists that chain multiple C finalizers on a weak pointer.
438    ------------------------------------------------------------------------- */
439
440 INFO_TABLE_CONSTR(stg_C_FINALIZER_LIST,1,4,0,CONSTR,"C_FINALIZER_LIST","C_FINALIZER_LIST")
441 { foreign "C" barf("C_FINALIZER_LIST object entered!") never returns; }
442
443 /* ----------------------------------------------------------------------------
444    NO_FINALIZER
445
446    This is a static nullary constructor (like []) that we use to mark an empty
447    finalizer in a weak pointer object.
448    ------------------------------------------------------------------------- */
449
450 INFO_TABLE_CONSTR(stg_NO_FINALIZER,0,0,0,CONSTR_NOCAF,"NO_FINALIZER","NO_FINALIZER")
451 { foreign "C" barf("NO_FINALIZER object entered!") never returns; }
452
453 CLOSURE(stg_NO_FINALIZER_closure,stg_NO_FINALIZER);
454
455 /* ----------------------------------------------------------------------------
456    Stable Names are unlifted too.
457    ------------------------------------------------------------------------- */
458
459 INFO_TABLE(stg_STABLE_NAME,0,1,PRIM,"STABLE_NAME","STABLE_NAME")
460 { foreign "C" barf("STABLE_NAME object entered!") never returns; }
461
462 /* ----------------------------------------------------------------------------
463    MVars
464
465    There are two kinds of these: full and empty.  We need an info table
466    and entry code for each type.
467    ------------------------------------------------------------------------- */
468
469 INFO_TABLE(stg_MVAR_CLEAN,3,0,MVAR_CLEAN,"MVAR","MVAR")
470 { foreign "C" barf("MVAR object entered!") never returns; }
471
472 INFO_TABLE(stg_MVAR_DIRTY,3,0,MVAR_DIRTY,"MVAR","MVAR")
473 { foreign "C" barf("MVAR object entered!") never returns; }
474
475 /* -----------------------------------------------------------------------------
476    STM
477    -------------------------------------------------------------------------- */
478
479 INFO_TABLE(stg_TVAR_CLEAN, 2, 1, TVAR, "TVAR", "TVAR")
480 { foreign "C" barf("TVAR_CLEAN object entered!") never returns; }
481
482 INFO_TABLE(stg_TVAR_DIRTY, 2, 1, TVAR, "TVAR", "TVAR")
483 { foreign "C" barf("TVAR_DIRTY object entered!") never returns; }
484
485 INFO_TABLE(stg_TVAR_WATCH_QUEUE, 3, 0, MUT_PRIM, "TVAR_WATCH_QUEUE", "TVAR_WATCH_QUEUE")
486 { foreign "C" barf("TVAR_WATCH_QUEUE object entered!") never returns; }
487
488 INFO_TABLE(stg_ATOMIC_INVARIANT, 2, 1, MUT_PRIM, "ATOMIC_INVARIANT", "ATOMIC_INVARIANT")
489 { foreign "C" barf("ATOMIC_INVARIANT object entered!") never returns; }
490
491 INFO_TABLE(stg_INVARIANT_CHECK_QUEUE, 3, 0, MUT_PRIM, "INVARIANT_CHECK_QUEUE", "INVARIANT_CHECK_QUEUE")
492 { foreign "C" barf("INVARIANT_CHECK_QUEUE object entered!") never returns; }
493
494 INFO_TABLE(stg_TREC_CHUNK, 0, 0, TREC_CHUNK, "TREC_CHUNK", "TREC_CHUNK")
495 { foreign "C" barf("TREC_CHUNK object entered!") never returns; }
496
497 INFO_TABLE(stg_TREC_HEADER, 3, 1, MUT_PRIM, "TREC_HEADER", "TREC_HEADER")
498 { foreign "C" barf("TREC_HEADER object entered!") never returns; }
499
500 INFO_TABLE_CONSTR(stg_END_STM_WATCH_QUEUE,0,0,0,CONSTR_NOCAF,"END_STM_WATCH_QUEUE","END_STM_WATCH_QUEUE")
501 { foreign "C" barf("END_STM_WATCH_QUEUE object entered!") never returns; }
502
503 INFO_TABLE_CONSTR(stg_END_INVARIANT_CHECK_QUEUE,0,0,0,CONSTR_NOCAF,"END_INVARIANT_CHECK_QUEUE","END_INVARIANT_CHECK_QUEUE")
504 { foreign "C" barf("END_INVARIANT_CHECK_QUEUE object entered!") never returns; }
505
506 INFO_TABLE_CONSTR(stg_END_STM_CHUNK_LIST,0,0,0,CONSTR_NOCAF,"END_STM_CHUNK_LIST","END_STM_CHUNK_LIST")
507 { foreign "C" barf("END_STM_CHUNK_LIST object entered!") never returns; }
508
509 INFO_TABLE_CONSTR(stg_NO_TREC,0,0,0,CONSTR_NOCAF,"NO_TREC","NO_TREC")
510 { foreign "C" barf("NO_TREC object entered!") never returns; }
511
512 CLOSURE(stg_END_STM_WATCH_QUEUE_closure,stg_END_STM_WATCH_QUEUE);
513
514 CLOSURE(stg_END_INVARIANT_CHECK_QUEUE_closure,stg_END_INVARIANT_CHECK_QUEUE);
515
516 CLOSURE(stg_END_STM_CHUNK_LIST_closure,stg_END_STM_CHUNK_LIST);
517
518 CLOSURE(stg_NO_TREC_closure,stg_NO_TREC);
519
520 /* ----------------------------------------------------------------------------
521    Messages
522    ------------------------------------------------------------------------- */
523
524 // PRIM rather than CONSTR, because PRIM objects cannot be duplicated by the GC.
525
526 INFO_TABLE_CONSTR(stg_MSG_TRY_WAKEUP,2,0,0,PRIM,"MSG_TRY_WAKEUP","MSG_TRY_WAKEUP")
527 { foreign "C" barf("MSG_TRY_WAKEUP object entered!") never returns; }
528
529 INFO_TABLE_CONSTR(stg_MSG_THROWTO,4,0,0,PRIM,"MSG_THROWTO","MSG_THROWTO")
530 { foreign "C" barf("MSG_THROWTO object entered!") never returns; }
531
532 INFO_TABLE_CONSTR(stg_MSG_BLACKHOLE,3,0,0,PRIM,"MSG_BLACKHOLE","MSG_BLACKHOLE")
533 { foreign "C" barf("MSG_BLACKHOLE object entered!") never returns; }
534
535 // used to overwrite a MSG_THROWTO when the message has been used/revoked
536 INFO_TABLE_CONSTR(stg_MSG_NULL,1,0,0,PRIM,"MSG_NULL","MSG_NULL")
537 { foreign "C" barf("MSG_NULL object entered!") never returns; }
538
539 /* ----------------------------------------------------------------------------
540    END_TSO_QUEUE
541
542    This is a static nullary constructor (like []) that we use to mark the
543    end of a linked TSO queue.
544    ------------------------------------------------------------------------- */
545
546 INFO_TABLE_CONSTR(stg_END_TSO_QUEUE,0,0,0,CONSTR_NOCAF,"END_TSO_QUEUE","END_TSO_QUEUE")
547 { foreign "C" barf("END_TSO_QUEUE object entered!") never returns; }
548
549 CLOSURE(stg_END_TSO_QUEUE_closure,stg_END_TSO_QUEUE);
550
551 /* ----------------------------------------------------------------------------
552    GCD_CAF
553    ------------------------------------------------------------------------- */
554
555 INFO_TABLE_CONSTR(stg_GCD_CAF,0,0,0,CONSTR_NOCAF,"GCD_CAF","GCD_CAF")
556 { foreign "C" barf("Evaluated a CAF that was GC'd!") never returns; }
557
558 /* ----------------------------------------------------------------------------
559    STM_AWOKEN
560
561    This is a static nullary constructor (like []) that we use to mark a
562    thread waiting on an STM wakeup
563    ------------------------------------------------------------------------- */
564
565 INFO_TABLE_CONSTR(stg_STM_AWOKEN,0,0,0,CONSTR_NOCAF,"STM_AWOKEN","STM_AWOKEN")
566 { foreign "C" barf("STM_AWOKEN object entered!") never returns; }
567
568 CLOSURE(stg_STM_AWOKEN_closure,stg_STM_AWOKEN);
569
570 /* ----------------------------------------------------------------------------
571    Arrays
572
573    These come in two basic flavours: arrays of data (StgArrWords) and arrays of
574    pointers (StgArrPtrs).  They all have a similar layout:
575
576    ___________________________
577    | Info | No. of | data....
578    |  Ptr | Words  |
579    ---------------------------
580
581    These are *unpointed* objects: i.e. they cannot be entered.
582
583    ------------------------------------------------------------------------- */
584
585 INFO_TABLE(stg_ARR_WORDS, 0, 0, ARR_WORDS, "ARR_WORDS", "ARR_WORDS")
586 { foreign "C" barf("ARR_WORDS object entered!") never returns; }
587
588 INFO_TABLE(stg_MUT_ARR_PTRS_CLEAN, 0, 0, MUT_ARR_PTRS_CLEAN, "MUT_ARR_PTRS_CLEAN", "MUT_ARR_PTRS_CLEAN")
589 { foreign "C" barf("MUT_ARR_PTRS_CLEAN object entered!") never returns; }
590
591 INFO_TABLE(stg_MUT_ARR_PTRS_DIRTY, 0, 0, MUT_ARR_PTRS_DIRTY, "MUT_ARR_PTRS_DIRTY", "MUT_ARR_PTRS_DIRTY")
592 { foreign "C" barf("MUT_ARR_PTRS_DIRTY object entered!") never returns; }
593
594 INFO_TABLE(stg_MUT_ARR_PTRS_FROZEN, 0, 0, MUT_ARR_PTRS_FROZEN, "MUT_ARR_PTRS_FROZEN", "MUT_ARR_PTRS_FROZEN")
595 { foreign "C" barf("MUT_ARR_PTRS_FROZEN object entered!") never returns; }
596
597 INFO_TABLE(stg_MUT_ARR_PTRS_FROZEN0, 0, 0, MUT_ARR_PTRS_FROZEN0, "MUT_ARR_PTRS_FROZEN0", "MUT_ARR_PTRS_FROZEN0")
598 { foreign "C" barf("MUT_ARR_PTRS_FROZEN0 object entered!") never returns; }
599
600 INFO_TABLE(stg_SMALL_MUT_ARR_PTRS_CLEAN, 0, 0, SMALL_MUT_ARR_PTRS_CLEAN, "SMALL_MUT_ARR_PTRS_CLEAN", "SMALL_MUT_ARR_PTRS_CLEAN")
601 { foreign "C" barf("SMALL_MUT_ARR_PTRS_CLEAN object entered!") never returns; }
602
603 INFO_TABLE(stg_SMALL_MUT_ARR_PTRS_DIRTY, 0, 0, SMALL_MUT_ARR_PTRS_DIRTY, "SMALL_MUT_ARR_PTRS_DIRTY", "SMALL_MUT_ARR_PTRS_DIRTY")
604 { foreign "C" barf("SMALL_MUT_ARR_PTRS_DIRTY object entered!") never returns; }
605
606 INFO_TABLE(stg_SMALL_MUT_ARR_PTRS_FROZEN, 0, 0, SMALL_MUT_ARR_PTRS_FROZEN, "SMALL_MUT_ARR_PTRS_FROZEN", "SMALL_MUT_ARR_PTRS_FROZEN")
607 { foreign "C" barf("SMALL_MUT_ARR_PTRS_FROZEN object entered!") never returns; }
608
609 INFO_TABLE(stg_SMALL_MUT_ARR_PTRS_FROZEN0, 0, 0, SMALL_MUT_ARR_PTRS_FROZEN0, "SMALL_MUT_ARR_PTRS_FROZEN0", "SMALL_MUT_ARR_PTRS_FROZEN0")
610 { foreign "C" barf("SMALL_MUT_ARR_PTRS_FROZEN0 object entered!") never returns; }
611
612 /* ----------------------------------------------------------------------------
613    Mutable Variables
614    ------------------------------------------------------------------------- */
615
616 INFO_TABLE(stg_MUT_VAR_CLEAN, 1, 0, MUT_VAR_CLEAN, "MUT_VAR_CLEAN", "MUT_VAR_CLEAN")
617 { foreign "C" barf("MUT_VAR_CLEAN object entered!") never returns; }
618 INFO_TABLE(stg_MUT_VAR_DIRTY, 1, 0, MUT_VAR_DIRTY, "MUT_VAR_DIRTY", "MUT_VAR_DIRTY")
619 { foreign "C" barf("MUT_VAR_DIRTY object entered!") never returns; }
620
621 /* ----------------------------------------------------------------------------
622    Dummy return closure
623
624    Entering this closure will just return to the address on the top of the
625    stack.  Useful for getting a thread in a canonical form where we can
626    just enter the top stack word to start the thread.  (see deleteThread)
627  * ------------------------------------------------------------------------- */
628
629 INFO_TABLE( stg_dummy_ret, 0, 0, CONSTR_NOCAF, "DUMMY_RET", "DUMMY_RET")
630     ()
631 {
632     return ();
633 }
634 CLOSURE(stg_dummy_ret_closure,stg_dummy_ret);
635
636 /* ----------------------------------------------------------------------------
637    MVAR_TSO_QUEUE
638    ------------------------------------------------------------------------- */
639
640 INFO_TABLE_CONSTR(stg_MVAR_TSO_QUEUE,2,0,0,PRIM,"MVAR_TSO_QUEUE","MVAR_TSO_QUEUE")
641 { foreign "C" barf("MVAR_TSO_QUEUE object entered!") never returns; }
642
643 /* ----------------------------------------------------------------------------
644    COMPACT_NFDATA (a blob of data in NF with no outgoing pointers)
645
646    See Note [Compact Normal Forms] in sm/CNF.c
647
648    CLEAN/DIRTY refer to the state of the "hash" field: DIRTY means that
649    compaction is in progress and the hash table needs to be scanned by the GC.
650    ------------------------------------------------------------------------- */
651
652 INFO_TABLE( stg_COMPACT_NFDATA_CLEAN, 0, 5, COMPACT_NFDATA, "COMPACT_NFDATA", "COMPACT_NFDATA")
653     ()
654 { foreign "C" barf("COMPACT_NFDATA_CLEAN object entered!") never returns; }
655
656 INFO_TABLE( stg_COMPACT_NFDATA_DIRTY, 0, 5, COMPACT_NFDATA, "COMPACT_NFDATA", "COMPACT_NFDATA")
657     ()
658 { foreign "C" barf("COMPACT_NFDATA_DIRTY object entered!") never returns; }
659
660 /* ----------------------------------------------------------------------------
661    CHARLIKE and INTLIKE closures.
662
663    These are static representations of Chars and small Ints, so that
664    we can remove dynamic Chars and Ints during garbage collection and
665    replace them with references to the static objects.
666    ------------------------------------------------------------------------- */
667
668 #if defined(COMPILING_WINDOWS_DLL)
669 /*
670  * When sticking the RTS in a Windows DLL, we delay populating the
671  * Charlike and Intlike tables until load-time, which is only
672  * when we've got the real addresses to the C# and I# closures.
673  *
674  * -- this is currently broken BL 2009/11/14.
675  *    we don't rewrite to static closures at all with Windows DLLs.
676  */
677 // #warning Is this correct? _imp is a pointer!
678 #define Char_hash_con_info _imp__ghczmprim_GHCziTypes_Czh_con_info
679 #define Int_hash_con_info _imp__ghczmprim_GHCziTypes_Izh_con_info
680 #else
681 #define Char_hash_con_info ghczmprim_GHCziTypes_Czh_con_info
682 #define Int_hash_con_info ghczmprim_GHCziTypes_Izh_con_info
683 #endif
684
685
686 #define CHARLIKE_HDR(n)  CLOSURE(Char_hash_con_info, n)
687 #define INTLIKE_HDR(n)   CLOSURE(Int_hash_con_info, n)
688
689 #if !(defined(COMPILING_WINDOWS_DLL))
690 section "data" {
691  stg_CHARLIKE_closure:
692     CHARLIKE_HDR(0)
693     CHARLIKE_HDR(1)
694     CHARLIKE_HDR(2)
695     CHARLIKE_HDR(3)
696     CHARLIKE_HDR(4)
697     CHARLIKE_HDR(5)
698     CHARLIKE_HDR(6)
699     CHARLIKE_HDR(7)
700     CHARLIKE_HDR(8)
701     CHARLIKE_HDR(9)
702     CHARLIKE_HDR(10)
703     CHARLIKE_HDR(11)
704     CHARLIKE_HDR(12)
705     CHARLIKE_HDR(13)
706     CHARLIKE_HDR(14)
707     CHARLIKE_HDR(15)
708     CHARLIKE_HDR(16)
709     CHARLIKE_HDR(17)
710     CHARLIKE_HDR(18)
711     CHARLIKE_HDR(19)
712     CHARLIKE_HDR(20)
713     CHARLIKE_HDR(21)
714     CHARLIKE_HDR(22)
715     CHARLIKE_HDR(23)
716     CHARLIKE_HDR(24)
717     CHARLIKE_HDR(25)
718     CHARLIKE_HDR(26)
719     CHARLIKE_HDR(27)
720     CHARLIKE_HDR(28)
721     CHARLIKE_HDR(29)
722     CHARLIKE_HDR(30)
723     CHARLIKE_HDR(31)
724     CHARLIKE_HDR(32)
725     CHARLIKE_HDR(33)
726     CHARLIKE_HDR(34)
727     CHARLIKE_HDR(35)
728     CHARLIKE_HDR(36)
729     CHARLIKE_HDR(37)
730     CHARLIKE_HDR(38)
731     CHARLIKE_HDR(39)
732     CHARLIKE_HDR(40)
733     CHARLIKE_HDR(41)
734     CHARLIKE_HDR(42)
735     CHARLIKE_HDR(43)
736     CHARLIKE_HDR(44)
737     CHARLIKE_HDR(45)
738     CHARLIKE_HDR(46)
739     CHARLIKE_HDR(47)
740     CHARLIKE_HDR(48)
741     CHARLIKE_HDR(49)
742     CHARLIKE_HDR(50)
743     CHARLIKE_HDR(51)
744     CHARLIKE_HDR(52)
745     CHARLIKE_HDR(53)
746     CHARLIKE_HDR(54)
747     CHARLIKE_HDR(55)
748     CHARLIKE_HDR(56)
749     CHARLIKE_HDR(57)
750     CHARLIKE_HDR(58)
751     CHARLIKE_HDR(59)
752     CHARLIKE_HDR(60)
753     CHARLIKE_HDR(61)
754     CHARLIKE_HDR(62)
755     CHARLIKE_HDR(63)
756     CHARLIKE_HDR(64)
757     CHARLIKE_HDR(65)
758     CHARLIKE_HDR(66)
759     CHARLIKE_HDR(67)
760     CHARLIKE_HDR(68)
761     CHARLIKE_HDR(69)
762     CHARLIKE_HDR(70)
763     CHARLIKE_HDR(71)
764     CHARLIKE_HDR(72)
765     CHARLIKE_HDR(73)
766     CHARLIKE_HDR(74)
767     CHARLIKE_HDR(75)
768     CHARLIKE_HDR(76)
769     CHARLIKE_HDR(77)
770     CHARLIKE_HDR(78)
771     CHARLIKE_HDR(79)
772     CHARLIKE_HDR(80)
773     CHARLIKE_HDR(81)
774     CHARLIKE_HDR(82)
775     CHARLIKE_HDR(83)
776     CHARLIKE_HDR(84)
777     CHARLIKE_HDR(85)
778     CHARLIKE_HDR(86)
779     CHARLIKE_HDR(87)
780     CHARLIKE_HDR(88)
781     CHARLIKE_HDR(89)
782     CHARLIKE_HDR(90)
783     CHARLIKE_HDR(91)
784     CHARLIKE_HDR(92)
785     CHARLIKE_HDR(93)
786     CHARLIKE_HDR(94)
787     CHARLIKE_HDR(95)
788     CHARLIKE_HDR(96)
789     CHARLIKE_HDR(97)
790     CHARLIKE_HDR(98)
791     CHARLIKE_HDR(99)
792     CHARLIKE_HDR(100)
793     CHARLIKE_HDR(101)
794     CHARLIKE_HDR(102)
795     CHARLIKE_HDR(103)
796     CHARLIKE_HDR(104)
797     CHARLIKE_HDR(105)
798     CHARLIKE_HDR(106)
799     CHARLIKE_HDR(107)
800     CHARLIKE_HDR(108)
801     CHARLIKE_HDR(109)
802     CHARLIKE_HDR(110)
803     CHARLIKE_HDR(111)
804     CHARLIKE_HDR(112)
805     CHARLIKE_HDR(113)
806     CHARLIKE_HDR(114)
807     CHARLIKE_HDR(115)
808     CHARLIKE_HDR(116)
809     CHARLIKE_HDR(117)
810     CHARLIKE_HDR(118)
811     CHARLIKE_HDR(119)
812     CHARLIKE_HDR(120)
813     CHARLIKE_HDR(121)
814     CHARLIKE_HDR(122)
815     CHARLIKE_HDR(123)
816     CHARLIKE_HDR(124)
817     CHARLIKE_HDR(125)
818     CHARLIKE_HDR(126)
819     CHARLIKE_HDR(127)
820     CHARLIKE_HDR(128)
821     CHARLIKE_HDR(129)
822     CHARLIKE_HDR(130)
823     CHARLIKE_HDR(131)
824     CHARLIKE_HDR(132)
825     CHARLIKE_HDR(133)
826     CHARLIKE_HDR(134)
827     CHARLIKE_HDR(135)
828     CHARLIKE_HDR(136)
829     CHARLIKE_HDR(137)
830     CHARLIKE_HDR(138)
831     CHARLIKE_HDR(139)
832     CHARLIKE_HDR(140)
833     CHARLIKE_HDR(141)
834     CHARLIKE_HDR(142)
835     CHARLIKE_HDR(143)
836     CHARLIKE_HDR(144)
837     CHARLIKE_HDR(145)
838     CHARLIKE_HDR(146)
839     CHARLIKE_HDR(147)
840     CHARLIKE_HDR(148)
841     CHARLIKE_HDR(149)
842     CHARLIKE_HDR(150)
843     CHARLIKE_HDR(151)
844     CHARLIKE_HDR(152)
845     CHARLIKE_HDR(153)
846     CHARLIKE_HDR(154)
847     CHARLIKE_HDR(155)
848     CHARLIKE_HDR(156)
849     CHARLIKE_HDR(157)
850     CHARLIKE_HDR(158)
851     CHARLIKE_HDR(159)
852     CHARLIKE_HDR(160)
853     CHARLIKE_HDR(161)
854     CHARLIKE_HDR(162)
855     CHARLIKE_HDR(163)
856     CHARLIKE_HDR(164)
857     CHARLIKE_HDR(165)
858     CHARLIKE_HDR(166)
859     CHARLIKE_HDR(167)
860     CHARLIKE_HDR(168)
861     CHARLIKE_HDR(169)
862     CHARLIKE_HDR(170)
863     CHARLIKE_HDR(171)
864     CHARLIKE_HDR(172)
865     CHARLIKE_HDR(173)
866     CHARLIKE_HDR(174)
867     CHARLIKE_HDR(175)
868     CHARLIKE_HDR(176)
869     CHARLIKE_HDR(177)
870     CHARLIKE_HDR(178)
871     CHARLIKE_HDR(179)
872     CHARLIKE_HDR(180)
873     CHARLIKE_HDR(181)
874     CHARLIKE_HDR(182)
875     CHARLIKE_HDR(183)
876     CHARLIKE_HDR(184)
877     CHARLIKE_HDR(185)
878     CHARLIKE_HDR(186)
879     CHARLIKE_HDR(187)
880     CHARLIKE_HDR(188)
881     CHARLIKE_HDR(189)
882     CHARLIKE_HDR(190)
883     CHARLIKE_HDR(191)
884     CHARLIKE_HDR(192)
885     CHARLIKE_HDR(193)
886     CHARLIKE_HDR(194)
887     CHARLIKE_HDR(195)
888     CHARLIKE_HDR(196)
889     CHARLIKE_HDR(197)
890     CHARLIKE_HDR(198)
891     CHARLIKE_HDR(199)
892     CHARLIKE_HDR(200)
893     CHARLIKE_HDR(201)
894     CHARLIKE_HDR(202)
895     CHARLIKE_HDR(203)
896     CHARLIKE_HDR(204)
897     CHARLIKE_HDR(205)
898     CHARLIKE_HDR(206)
899     CHARLIKE_HDR(207)
900     CHARLIKE_HDR(208)
901     CHARLIKE_HDR(209)
902     CHARLIKE_HDR(210)
903     CHARLIKE_HDR(211)
904     CHARLIKE_HDR(212)
905     CHARLIKE_HDR(213)
906     CHARLIKE_HDR(214)
907     CHARLIKE_HDR(215)
908     CHARLIKE_HDR(216)
909     CHARLIKE_HDR(217)
910     CHARLIKE_HDR(218)
911     CHARLIKE_HDR(219)
912     CHARLIKE_HDR(220)
913     CHARLIKE_HDR(221)
914     CHARLIKE_HDR(222)
915     CHARLIKE_HDR(223)
916     CHARLIKE_HDR(224)
917     CHARLIKE_HDR(225)
918     CHARLIKE_HDR(226)
919     CHARLIKE_HDR(227)
920     CHARLIKE_HDR(228)
921     CHARLIKE_HDR(229)
922     CHARLIKE_HDR(230)
923     CHARLIKE_HDR(231)
924     CHARLIKE_HDR(232)
925     CHARLIKE_HDR(233)
926     CHARLIKE_HDR(234)
927     CHARLIKE_HDR(235)
928     CHARLIKE_HDR(236)
929     CHARLIKE_HDR(237)
930     CHARLIKE_HDR(238)
931     CHARLIKE_HDR(239)
932     CHARLIKE_HDR(240)
933     CHARLIKE_HDR(241)
934     CHARLIKE_HDR(242)
935     CHARLIKE_HDR(243)
936     CHARLIKE_HDR(244)
937     CHARLIKE_HDR(245)
938     CHARLIKE_HDR(246)
939     CHARLIKE_HDR(247)
940     CHARLIKE_HDR(248)
941     CHARLIKE_HDR(249)
942     CHARLIKE_HDR(250)
943     CHARLIKE_HDR(251)
944     CHARLIKE_HDR(252)
945     CHARLIKE_HDR(253)
946     CHARLIKE_HDR(254)
947     CHARLIKE_HDR(255)
948 }
949
950 section "data" {
951  stg_INTLIKE_closure:
952     INTLIKE_HDR(-16) /* MIN_INTLIKE == -16 */
953     INTLIKE_HDR(-15)
954     INTLIKE_HDR(-14)
955     INTLIKE_HDR(-13)
956     INTLIKE_HDR(-12)
957     INTLIKE_HDR(-11)
958     INTLIKE_HDR(-10)
959     INTLIKE_HDR(-9)
960     INTLIKE_HDR(-8)
961     INTLIKE_HDR(-7)
962     INTLIKE_HDR(-6)
963     INTLIKE_HDR(-5)
964     INTLIKE_HDR(-4)
965     INTLIKE_HDR(-3)
966     INTLIKE_HDR(-2)
967     INTLIKE_HDR(-1)
968     INTLIKE_HDR(0)
969     INTLIKE_HDR(1)
970     INTLIKE_HDR(2)
971     INTLIKE_HDR(3)
972     INTLIKE_HDR(4)
973     INTLIKE_HDR(5)
974     INTLIKE_HDR(6)
975     INTLIKE_HDR(7)
976     INTLIKE_HDR(8)
977     INTLIKE_HDR(9)
978     INTLIKE_HDR(10)
979     INTLIKE_HDR(11)
980     INTLIKE_HDR(12)
981     INTLIKE_HDR(13)
982     INTLIKE_HDR(14)
983     INTLIKE_HDR(15)
984     INTLIKE_HDR(16)  /* MAX_INTLIKE == 16 */
985 }
986
987 #endif