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