[project @ 1999-10-20 10:14:47 by simonmar]
[ghc-hetmet.git] / ghc / includes / Updates.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Updates.h,v 1.13 1999/10/20 10:14:47 simonmar 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 awakenBlockedQueue(StgTSO *q);
55
56 #define AWAKEN_BQ(closure)                                               \
57         if (closure->header.info == &BLACKHOLE_BQ_info) {                \
58                 STGCALL1(awakenBlockedQueue,                             \
59                          ((StgBlockingQueue *)closure)->blocking_queue); \
60         }
61
62
63 /* -----------------------------------------------------------------------------
64    Push an update frame on the stack.
65    -------------------------------------------------------------------------- */
66
67 #if defined(PROFILING)
68 #define PUSH_STD_CCCS(frame) frame->header.prof.ccs = CCCS
69 #else
70 #define PUSH_STD_CCCS(frame)
71 #endif
72
73 extern DLL_IMPORT_DATA const StgPolyInfoTable Upd_frame_info; 
74
75 #define PUSH_UPD_FRAME(target, Sp_offset)                       \
76         {                                                       \
77                 StgUpdateFrame *__frame;                        \
78                 TICK_UPDF_PUSHED(target, GET_INFO((StgClosure*)target)); \
79                 __frame = (StgUpdateFrame *)(Sp + (Sp_offset)) - 1; \
80                 SET_INFO(__frame, (StgInfoTable *)&Upd_frame_info);   \
81                 __frame->link = Su;                             \
82                 __frame->updatee = (StgClosure *)(target);      \
83                 PUSH_STD_CCCS(__frame);                         \
84                 Su = __frame;                                   \
85         }
86
87 /* -----------------------------------------------------------------------------
88    Entering CAFs
89
90    When a CAF is first entered, it creates a black hole in the heap,
91    and updates itself with an indirection to this new black hole.
92
93    We update the CAF with an indirection to a newly-allocated black
94    hole in the heap.  We also set the blocking queue on the newly
95    allocated black hole to be empty.
96
97    Why do we make a black hole in the heap when we enter a CAF?
98       
99        - for a  generational garbage collector, which needs a fast
100          test for whether an updatee is in an old generation or not
101
102        - for the parallel system, which can implement updates more
103          easily if the updatee is always in the heap. (allegedly).
104
105    When debugging, we maintain a separate CAF list so we can tell when
106    a CAF has been garbage collected.
107    -------------------------------------------------------------------------- */
108    
109 /* ToDo: only call newCAF when debugging. */
110
111 extern void newCAF(StgClosure*);
112
113 #define UPD_CAF(cafptr, bhptr)                                  \
114   {                                                             \
115     SET_INFO((StgInd *)cafptr,(const StgInfoTable*)&IND_STATIC_info);           \
116     ((StgInd *)cafptr)->indirectee   = (StgClosure *)(bhptr);   \
117     STGCALL1(newCAF,(StgClosure *)cafptr);                      \
118   }
119
120 /* -----------------------------------------------------------------------------
121    Update-related prototypes
122    -------------------------------------------------------------------------- */
123
124 DLL_IMPORT_RTS extern STGFUN(Upd_frame_entry);
125
126 extern DLL_IMPORT_DATA const StgInfoTable PAP_info;
127 DLL_IMPORT_RTS STGFUN(PAP_entry);
128
129 EXTFUN_RTS(stg_update_PAP);
130
131 extern DLL_IMPORT_DATA const StgInfoTable AP_UPD_info;
132 DLL_IMPORT_RTS STGFUN(AP_UPD_entry);
133
134 extern DLL_IMPORT_DATA const StgInfoTable raise_info;
135
136 #endif /* UPDATES_H */