1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2004
7 * ---------------------------------------------------------------------------*/
13 #include "BeginPrivate.h"
16 /* -----------------------------------------------------------------------------
18 -------------------------------------------------------------------------- */
21 * We call LDV_recordDead_FILL_SLOP_DYNAMIC(p1) regardless of the generation in
25 * After all, we do *NOT* need to call LDV_RECORD_CREATE() for IND
26 * closures because they are inherently used. But, it corrupts
27 * the invariants that every closure keeps its creation time in the profiling
28 * field. So, we call LDV_RECORD_CREATE().
31 /* In the DEBUG case, we also zero out the slop of the old closure,
32 * so that the sanity checker can tell where the next closure is.
34 * Two important invariants: we should never try to update a closure
35 * to point to itself, and the closure being updated should not
36 * already have been updated (the mutable list will get messed up
39 * NB. We do *not* do this in THREADED_RTS mode, because when we have the
40 * possibility of multiple threads entering the same closure, zeroing
41 * the slop in one of the threads would have a disastrous effect on
42 * the other (seen in the wild!).
46 #define FILL_SLOP(p) \
50 inf = %GET_STD_INFO(p); \
51 if (%INFO_TYPE(inf) != HALF_W_(BLACKHOLE)) { \
52 if (%INFO_TYPE(inf) == HALF_W_(THUNK_SELECTOR)) { \
53 sz = BYTES_TO_WDS(SIZEOF_StgSelector_NoThunkHdr); \
55 if (%INFO_TYPE(inf) == HALF_W_(AP_STACK)) { \
56 sz = StgAP_STACK_size(p) + BYTES_TO_WDS(SIZEOF_StgAP_STACK_NoThunkHdr); \
58 if (%INFO_TYPE(inf) == HALF_W_(AP)) { \
59 sz = TO_W_(StgAP_n_args(p)) + BYTES_TO_WDS(SIZEOF_StgAP_NoThunkHdr); \
61 sz = TO_W_(%INFO_PTRS(inf)) + TO_W_(%INFO_NPTRS(inf)); \
68 StgThunk_payload(p,i) = 0; \
74 #else /* !CMINUSMINUS */
77 FILL_SLOP(StgClosure *p)
79 StgInfoTable *inf = get_itbl(p);
85 // we already filled in the slop when we overwrote the thunk
86 // with BLACKHOLE, and also an evacuated BLACKHOLE is only the
89 sz = sizeofW(StgSelector) - sizeofW(StgThunkHeader);
92 sz = ((StgAP *)p)->n_args + sizeofW(StgAP) - sizeofW(StgThunkHeader);
95 sz = ((StgAP_STACK *)p)->size + sizeofW(StgAP_STACK) - sizeofW(StgThunkHeader);
98 sz = inf->layout.payload.ptrs + inf->layout.payload.nptrs;
101 for (i = 0; i < sz; i++) {
102 ((StgThunk *)p)->payload[i] = 0;
108 #endif /* CMINUSMINUS */
110 #if !defined(DEBUG) || defined(THREADED_RTS)
111 #define DEBUG_FILL_SLOP(p) /* do nothing */
113 #define DEBUG_FILL_SLOP(p) FILL_SLOP(p)
116 /* We have two versions of this macro (sadly), one for use in C-- code,
117 * and the other for C.
119 * The and_then argument is a performance hack so that we can paste in
120 * the continuation code directly. It helps shave a couple of
121 * instructions off the common case in the update code, which is
122 * worthwhile (the update code is often part of the inner loop).
123 * (except that gcc now appears to common up this code again and
124 * invert the optimisation. Grrrr --SDM).
128 #define updateWithIndirection(p1, p2, and_then) \
131 DEBUG_FILL_SLOP(p1); \
132 LDV_RECORD_DEAD_FILL_SLOP_DYNAMIC(p1); \
133 StgInd_indirectee(p1) = p2; \
134 prim %write_barrier() []; \
135 SET_INFO(p1, stg_BLACKHOLE_info); \
136 LDV_RECORD_CREATE(p1); \
138 if (bdescr_gen_no(bd) != 0 :: bits16) { \
139 recordMutableCap(p1, TO_W_(bdescr_gen_no(bd)), R1); \
140 TICK_UPD_OLD_IND(); \
143 TICK_UPD_NEW_IND(); \
147 #else /* !CMINUSMINUS */
149 INLINE_HEADER void updateWithIndirection (Capability *cap,
155 ASSERT( (P_)p1 != (P_)p2 );
156 /* not necessarily true: ASSERT( !closure_IND(p1) ); */
157 /* occurs in RaiseAsync.c:raiseAsync() */
159 LDV_RECORD_DEAD_FILL_SLOP_DYNAMIC(p1);
160 ((StgInd *)p1)->indirectee = p2;
162 SET_INFO(p1, &stg_BLACKHOLE_info);
163 LDV_RECORD_CREATE(p1);
164 bd = Bdescr((StgPtr)p1);
165 if (bd->gen_no != 0) {
166 recordMutableCap(p1, cap, bd->gen_no);
173 #endif /* CMINUSMINUS */
176 #include "EndPrivate.h"
179 #endif /* UPDATES_H */