1 /* -----------------------------------------------------------------------------
2 * $Id: Updates.h,v 1.13 1999/10/20 10:14:47 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
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 awakenBlockedQueue(StgTSO *q);
56 #define AWAKEN_BQ(closure) \
57 if (closure->header.info == &BLACKHOLE_BQ_info) { \
58 STGCALL1(awakenBlockedQueue, \
59 ((StgBlockingQueue *)closure)->blocking_queue); \
63 /* -----------------------------------------------------------------------------
64 Push an update frame on the stack.
65 -------------------------------------------------------------------------- */
67 #if defined(PROFILING)
68 #define PUSH_STD_CCCS(frame) frame->header.prof.ccs = CCCS
70 #define PUSH_STD_CCCS(frame)
73 extern DLL_IMPORT_DATA const StgPolyInfoTable Upd_frame_info;
75 #define PUSH_UPD_FRAME(target, Sp_offset) \
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); \
82 __frame->updatee = (StgClosure *)(target); \
83 PUSH_STD_CCCS(__frame); \
87 /* -----------------------------------------------------------------------------
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.
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.
97 Why do we make a black hole in the heap when we enter a CAF?
99 - for a generational garbage collector, which needs a fast
100 test for whether an updatee is in an old generation or not
102 - for the parallel system, which can implement updates more
103 easily if the updatee is always in the heap. (allegedly).
105 When debugging, we maintain a separate CAF list so we can tell when
106 a CAF has been garbage collected.
107 -------------------------------------------------------------------------- */
109 /* ToDo: only call newCAF when debugging. */
111 extern void newCAF(StgClosure*);
113 #define UPD_CAF(cafptr, bhptr) \
115 SET_INFO((StgInd *)cafptr,(const StgInfoTable*)&IND_STATIC_info); \
116 ((StgInd *)cafptr)->indirectee = (StgClosure *)(bhptr); \
117 STGCALL1(newCAF,(StgClosure *)cafptr); \
120 /* -----------------------------------------------------------------------------
121 Update-related prototypes
122 -------------------------------------------------------------------------- */
124 DLL_IMPORT_RTS extern STGFUN(Upd_frame_entry);
126 extern DLL_IMPORT_DATA const StgInfoTable PAP_info;
127 DLL_IMPORT_RTS STGFUN(PAP_entry);
129 EXTFUN_RTS(stg_update_PAP);
131 extern DLL_IMPORT_DATA const StgInfoTable AP_UPD_info;
132 DLL_IMPORT_RTS STGFUN(AP_UPD_entry);
134 extern DLL_IMPORT_DATA const StgInfoTable raise_info;
136 #endif /* UPDATES_H */