1 /* -----------------------------------------------------------------------------
2 * $Id: Updates.h,v 1.15 1999/11/09 15:47:09 simonmar Exp $
4 * (c) The GHC Team, 1998-1999
6 * Definitions related to updates.
8 * ---------------------------------------------------------------------------*/
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
17 -------------------------------------------------------------------------- */
19 /* ToDo: overwrite slop words with something safe in case sanity checking
21 * (I think the fancy version of the GC is supposed to do this too.)
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.
30 # define UPD_IND(updclosure, heapptr) UPD_PERM_IND(updclosure,heapptr)
32 # define UPD_IND(updclosure, heapptr) UPD_REAL_IND(updclosure,heapptr)
35 /* UPD_IND actually does a PERM_IND if TICKY_TICKY is on;
36 if you *really* need an IND use UPD_REAL_IND
39 #define UPD_REAL_IND(updclosure, heapptr) \
41 const StgInfoTable *info; \
42 if (Bdescr((P_)updclosure)->back != (bdescr *)BaseReg) { \
43 info = LOCK_CLOSURE(updclosure); \
45 info = updclosure->header.info; \
47 AWAKEN_BQ(info,updclosure); \
48 updateWithIndirection(info, \
49 (StgClosure *)updclosure, \
50 (StgClosure *)heapptr); \
53 #define UPD_REAL_IND(updclosure, heapptr) \
55 const StgInfoTable *info; \
56 info = ((StgClosure *)updclosure)->header.info; \
57 AWAKEN_BQ(info,updclosure); \
58 updateWithIndirection(info, \
59 (StgClosure *)updclosure, \
60 (StgClosure *)heapptr); \
64 #if defined(PROFILING) || defined(TICKY_TICKY)
65 #define UPD_PERM_IND(updclosure, heapptr) \
67 const StgInfoTable *info; \
68 info = ((StgClosure *)updclosure)->header.info; \
69 AWAKEN_BQ(info,updclosure); \
70 updateWithPermIndirection(info, \
71 (StgClosure *)updclosure, \
72 (StgClosure *)heapptr); \
77 #define UPD_IND_NOLOCK(updclosure, heapptr) \
79 const StgInfoTable *info; \
80 info = updclosure->header.info; \
81 AWAKEN_BQ(info,updclosure); \
82 updateWithIndirection(info, \
83 (StgClosure *)updclosure, \
84 (StgClosure *)heapptr); \
87 #define UPD_IND_NOLOCK(updclosure,heapptr) UPD_IND(updclosure,heapptr)
90 /* -----------------------------------------------------------------------------
91 Awaken any threads waiting on this computation
92 -------------------------------------------------------------------------- */
94 extern void awakenBlockedQueue(StgTSO *q);
96 #define AWAKEN_BQ(info,closure) \
97 if (info == &BLACKHOLE_BQ_info) { \
98 STGCALL1(awakenBlockedQueue, \
99 ((StgBlockingQueue *)closure)->blocking_queue); \
103 /* -----------------------------------------------------------------------------
104 Push an update frame on the stack.
105 -------------------------------------------------------------------------- */
107 #if defined(PROFILING)
108 #define PUSH_STD_CCCS(frame) frame->header.prof.ccs = CCCS
110 #define PUSH_STD_CCCS(frame)
113 extern DLL_IMPORT_DATA const StgPolyInfoTable Upd_frame_info;
115 #define PUSH_UPD_FRAME(target, Sp_offset) \
117 StgUpdateFrame *__frame; \
118 TICK_UPDF_PUSHED(target, GET_INFO((StgClosure*)target)); \
119 __frame = (StgUpdateFrame *)(Sp + (Sp_offset)) - 1; \
120 SET_INFO(__frame, (StgInfoTable *)&Upd_frame_info); \
121 __frame->link = Su; \
122 __frame->updatee = (StgClosure *)(target); \
123 PUSH_STD_CCCS(__frame); \
127 /* -----------------------------------------------------------------------------
130 When a CAF is first entered, it creates a black hole in the heap,
131 and updates itself with an indirection to this new black hole.
133 We update the CAF with an indirection to a newly-allocated black
134 hole in the heap. We also set the blocking queue on the newly
135 allocated black hole to be empty.
137 Why do we make a black hole in the heap when we enter a CAF?
139 - for a generational garbage collector, which needs a fast
140 test for whether an updatee is in an old generation or not
142 - for the parallel system, which can implement updates more
143 easily if the updatee is always in the heap. (allegedly).
145 When debugging, we maintain a separate CAF list so we can tell when
146 a CAF has been garbage collected.
147 -------------------------------------------------------------------------- */
149 /* ToDo: only call newCAF when debugging. */
151 extern void newCAF(StgClosure*);
153 #define UPD_CAF(cafptr, bhptr) \
155 LOCK_CLOSURE(cafptr); \
156 ((StgInd *)cafptr)->indirectee = (StgClosure *)(bhptr); \
157 SET_INFO((StgInd *)cafptr,(const StgInfoTable*)&IND_STATIC_info); \
158 STGCALL1(newCAF,(StgClosure *)cafptr); \
161 /* -----------------------------------------------------------------------------
162 Update-related prototypes
163 -------------------------------------------------------------------------- */
165 DLL_IMPORT_RTS extern STGFUN(Upd_frame_entry);
167 extern DLL_IMPORT_DATA const StgInfoTable PAP_info;
168 DLL_IMPORT_RTS STGFUN(PAP_entry);
170 EXTFUN_RTS(stg_update_PAP);
172 extern DLL_IMPORT_DATA const StgInfoTable AP_UPD_info;
173 DLL_IMPORT_RTS STGFUN(AP_UPD_entry);
175 extern DLL_IMPORT_DATA const StgInfoTable raise_info;
177 #endif /* UPDATES_H */