1 /* -----------------------------------------------------------------------------
2 * $Id: Updates.h,v 1.7 1999/02/05 16:02:31 simonm 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.
29 #define UPD_IND(updclosure, heapptr) \
30 AWAKEN_BQ(updclosure); \
31 updateWithIndirection((StgClosure *)updclosure, \
32 (StgClosure *)heapptr);
34 /* -----------------------------------------------------------------------------
35 Awaken any threads waiting on this computation
36 -------------------------------------------------------------------------- */
38 extern void awaken_blocked_queue(StgTSO *q);
40 #define AWAKEN_BQ(closure) \
41 if (closure->header.info == &BLACKHOLE_BQ_info) { \
42 StgTSO *bq = ((StgBlockingQueue *)closure)->blocking_queue;\
43 if (bq != (StgTSO *)&END_TSO_QUEUE_closure) { \
44 STGCALL1(awaken_blocked_queue, bq); \
49 /* -----------------------------------------------------------------------------
50 Push an update frame on the stack.
51 -------------------------------------------------------------------------- */
53 #if defined(PROFILING)
54 #define PUSH_STD_CCCS(frame) frame->header.prof.ccs = CCCS
56 #define PUSH_STD_CCCS(frame)
59 extern const StgPolyInfoTable Upd_frame_info;
61 #define PUSH_UPD_FRAME(target, Sp_offset) \
63 StgUpdateFrame *__frame; \
65 __frame = stgCast(StgUpdateFrame*,Sp + (Sp_offset)) - 1; \
66 SET_INFO(__frame,stgCast(StgInfoTable*,&Upd_frame_info)); \
68 __frame->updatee = (StgClosure *)(target); \
69 PUSH_STD_CCCS(__frame); \
73 /* -----------------------------------------------------------------------------
76 When a CAF is first entered, it creates a black hole in the heap,
77 and updates itself with an indirection to this new black hole.
79 We update the CAF with an indirection to a newly-allocated black
80 hole in the heap. We also set the blocking queue on the newly
81 allocated black hole to be empty.
83 Why do we make a black hole in the heap when we enter a CAF?
85 - for a generational garbage collector, which needs a fast
86 test for whether an updatee is in an old generation or not
88 - for the parallel system, which can implement updates more
89 easily if the updatee is always in the heap. (allegedly).
91 When debugging, we maintain a separate CAF list so we can tell when
92 a CAF has been garbage collected.
93 -------------------------------------------------------------------------- */
95 /* ToDo: only call newCAF when debugging. */
97 extern void newCAF(StgClosure*);
99 #define UPD_CAF(cafptr, bhptr) \
101 SET_INFO((StgInd *)cafptr,&IND_STATIC_info); \
102 ((StgInd *)cafptr)->indirectee = (StgClosure *)(bhptr); \
103 STGCALL1(newCAF,(StgClosure *)cafptr); \
106 /* -----------------------------------------------------------------------------
107 Update-related prototypes
108 -------------------------------------------------------------------------- */
110 extern STGFUN(Upd_frame_entry);
112 extern const StgInfoTable PAP_info;
115 EXTFUN(stg_update_PAP);
117 extern const StgInfoTable AP_UPD_info;
118 STGFUN(AP_UPD_entry);
120 extern const StgInfoTable raise_info;
122 #endif /* UPDATES_H */