[project @ 1999-05-11 16:47:39 by keithw]
[ghc-hetmet.git] / ghc / includes / Updates.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Updates.h,v 1.10 1999/05/11 16:47:42 keithw Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * Definitions related to updates.
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #ifndef UPDATES_H
11 #define UPDATES_H
12
13 /* -----------------------------------------------------------------------------
14    Update a closure with an indirection.  This may also involve waking
15    up a queue of blocked threads waiting on the result of this
16    computation.
17    -------------------------------------------------------------------------- */
18
19 /* ToDo: overwrite slop words with something safe in case sanity checking 
20  *       is turned on.  
21  *       (I think the fancy version of the GC is supposed to do this too.)
22  */
23
24 /* This expands to a fair chunk of code, what with waking up threads 
25  * and checking whether we're updating something in a old generation.
26  * preferably don't use this macro inline in compiled code.
27  */
28
29 #ifdef TICKY_TICKY
30 # define UPD_IND(updclosure, heapptr) UPD_PERM_IND(updclosure,heapptr)
31 #else
32 # define UPD_IND(updclosure, heapptr) UPD_REAL_IND(updclosure,heapptr)
33 #endif
34
35 /* UPD_IND actually does a PERM_IND if TICKY_TICKY is on;
36    if you *really* need an IND use UPD_REAL_IND
37  */
38 #define UPD_REAL_IND(updclosure, heapptr)                       \
39         AWAKEN_BQ(updclosure);                                  \
40         updateWithIndirection((StgClosure *)updclosure,         \
41                               (StgClosure *)heapptr);
42
43 #if defined(PROFILING) || defined(TICKY_TICKY)
44 #define UPD_PERM_IND(updclosure, heapptr)                       \
45         AWAKEN_BQ(updclosure);                                  \
46         updateWithPermIndirection((StgClosure *)updclosure,     \
47                                   (StgClosure *)heapptr);
48 #endif
49
50 /* -----------------------------------------------------------------------------
51    Awaken any threads waiting on this computation
52    -------------------------------------------------------------------------- */
53
54 extern void awaken_blocked_queue(StgTSO *q);
55
56 #define AWAKEN_BQ(closure)                                              \
57         if (closure->header.info == &BLACKHOLE_BQ_info) {               \
58                 StgTSO *bq = ((StgBlockingQueue *)closure)->blocking_queue;\
59                 if (bq != (StgTSO *)&END_TSO_QUEUE_closure) {           \
60                         STGCALL1(awaken_blocked_queue, bq);             \
61                 }                                                       \
62         }
63
64
65 /* -----------------------------------------------------------------------------
66    Push an update frame on the stack.
67    -------------------------------------------------------------------------- */
68
69 #if defined(PROFILING)
70 #define PUSH_STD_CCCS(frame) frame->header.prof.ccs = CCCS
71 #else
72 #define PUSH_STD_CCCS(frame)
73 #endif
74
75 extern DLL_IMPORT_DATA const StgPolyInfoTable Upd_frame_info; 
76
77 #define PUSH_UPD_FRAME(target, Sp_offset)                       \
78         {                                                       \
79                 StgUpdateFrame *__frame;                        \
80                 TICK_UPDF_PUSHED(target, GET_INFO((StgClosure*)target));                        \
81                 __frame = stgCast(StgUpdateFrame*,Sp + (Sp_offset)) - 1; \
82                 SET_INFO(__frame,stgCast(StgInfoTable*,&Upd_frame_info));   \
83                 __frame->link = Su;                             \
84                 __frame->updatee = (StgClosure *)(target);      \
85                 PUSH_STD_CCCS(__frame);                         \
86                 Su = __frame;                                   \
87         }
88
89 /* -----------------------------------------------------------------------------
90    Entering CAFs
91
92    When a CAF is first entered, it creates a black hole in the heap,
93    and updates itself with an indirection to this new black hole.
94
95    We update the CAF with an indirection to a newly-allocated black
96    hole in the heap.  We also set the blocking queue on the newly
97    allocated black hole to be empty.
98
99    Why do we make a black hole in the heap when we enter a CAF?
100       
101        - for a  generational garbage collector, which needs a fast
102          test for whether an updatee is in an old generation or not
103
104        - for the parallel system, which can implement updates more
105          easily if the updatee is always in the heap. (allegedly).
106
107    When debugging, we maintain a separate CAF list so we can tell when
108    a CAF has been garbage collected.
109    -------------------------------------------------------------------------- */
110    
111 /* ToDo: only call newCAF when debugging. */
112
113 extern void newCAF(StgClosure*);
114
115 #define UPD_CAF(cafptr, bhptr)                                  \
116   {                                                             \
117     SET_INFO((StgInd *)cafptr,(const StgInfoTable*)&IND_STATIC_info);           \
118     ((StgInd *)cafptr)->indirectee   = (StgClosure *)(bhptr);   \
119     STGCALL1(newCAF,(StgClosure *)cafptr);                      \
120   }
121
122 /* -----------------------------------------------------------------------------
123    Update-related prototypes
124    -------------------------------------------------------------------------- */
125
126 DLL_IMPORT_RTS extern STGFUN(Upd_frame_entry);
127
128 extern DLL_IMPORT_DATA const StgInfoTable PAP_info;
129 DLL_IMPORT_RTS STGFUN(PAP_entry);
130
131 EXTFUN_RTS(stg_update_PAP);
132
133 extern DLL_IMPORT_DATA const StgInfoTable AP_UPD_info;
134 DLL_IMPORT_RTS STGFUN(AP_UPD_entry);
135
136 extern DLL_IMPORT_DATA const StgInfoTable raise_info;
137
138 #endif /* UPDATES_H */