1 /* -----------------------------------------------------------------------------
2 * $Id: Updates.h,v 1.11 1999/05/13 17:31:08 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.
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
38 #define UPD_REAL_IND(updclosure, heapptr) \
39 AWAKEN_BQ(updclosure); \
40 updateWithIndirection((StgClosure *)updclosure, \
41 (StgClosure *)heapptr);
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);
50 /* -----------------------------------------------------------------------------
51 Awaken any threads waiting on this computation
52 -------------------------------------------------------------------------- */
54 extern void awaken_blocked_queue(StgTSO *q);
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); \
65 /* -----------------------------------------------------------------------------
66 Push an update frame on the stack.
67 -------------------------------------------------------------------------- */
69 #if defined(PROFILING)
70 #define PUSH_STD_CCCS(frame) frame->header.prof.ccs = CCCS
72 #define PUSH_STD_CCCS(frame)
75 extern DLL_IMPORT_DATA const StgPolyInfoTable Upd_frame_info;
77 #define PUSH_UPD_FRAME(target, Sp_offset) \
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)); \
84 __frame->updatee = (StgClosure *)(target); \
85 PUSH_STD_CCCS(__frame); \
89 /* -----------------------------------------------------------------------------
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.
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.
99 Why do we make a black hole in the heap when we enter a CAF?
101 - for a generational garbage collector, which needs a fast
102 test for whether an updatee is in an old generation or not
104 - for the parallel system, which can implement updates more
105 easily if the updatee is always in the heap. (allegedly).
107 When debugging, we maintain a separate CAF list so we can tell when
108 a CAF has been garbage collected.
109 -------------------------------------------------------------------------- */
111 /* ToDo: only call newCAF when debugging. */
113 extern void newCAF(StgClosure*);
115 #define UPD_CAF(cafptr, bhptr) \
117 SET_INFO((StgInd *)cafptr,(const StgInfoTable*)&IND_STATIC_info); \
118 ((StgInd *)cafptr)->indirectee = (StgClosure *)(bhptr); \
119 STGCALL1(newCAF,(StgClosure *)cafptr); \
122 /* -----------------------------------------------------------------------------
123 Update-related prototypes
124 -------------------------------------------------------------------------- */
126 DLL_IMPORT_RTS extern STGFUN(Upd_frame_entry);
128 extern DLL_IMPORT_DATA const StgInfoTable PAP_info;
129 DLL_IMPORT_RTS STGFUN(PAP_entry);
131 EXTFUN_RTS(stg_update_PAP);
133 extern DLL_IMPORT_DATA const StgInfoTable AP_UPD_info;
134 DLL_IMPORT_RTS STGFUN(AP_UPD_entry);
136 extern DLL_IMPORT_DATA const StgInfoTable raise_info;
138 #endif /* UPDATES_H */