Implement stack chunks and separate TSO/STACK objects
[ghc.git] / rts / Updates.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1998-2004
4 *
5 * Performing updates.
6 *
7 * ---------------------------------------------------------------------------*/
8
9 #ifndef UPDATES_H
10 #define UPDATES_H
11
12 #ifndef CMINUSMINUS
13 #include "BeginPrivate.h"
14 #endif
15
16 /* -----------------------------------------------------------------------------
17 Updates
18 -------------------------------------------------------------------------- */
19
20 /* LDV profiling:
21 * After all, we do *NOT* need to call LDV_RECORD_CREATE() for IND
22 * closures because they are inherently used. But, it corrupts
23 * the invariants that every closure keeps its creation time in the profiling
24 * field. So, we call LDV_RECORD_CREATE().
25 */
26
27 /* We have two versions of this macro (sadly), one for use in C-- code,
28 * and the other for C.
29 *
30 * The and_then argument is a performance hack so that we can paste in
31 * the continuation code directly. It helps shave a couple of
32 * instructions off the common case in the update code, which is
33 * worthwhile (the update code is often part of the inner loop).
34 * (except that gcc now appears to common up this code again and
35 * invert the optimisation. Grrrr --SDM).
36 */
37 #ifdef CMINUSMINUS
38
39 #define updateWithIndirection(p1, p2, and_then) \
40 W_ bd; \
41 \
42 OVERWRITING_CLOSURE(p1); \
43 StgInd_indirectee(p1) = p2; \
44 prim %write_barrier() []; \
45 SET_INFO(p1, stg_BLACKHOLE_info); \
46 LDV_RECORD_CREATE(p1); \
47 bd = Bdescr(p1); \
48 if (bdescr_gen_no(bd) != 0 :: bits16) { \
49 recordMutableCap(p1, TO_W_(bdescr_gen_no(bd)), R1); \
50 TICK_UPD_OLD_IND(); \
51 and_then; \
52 } else { \
53 TICK_UPD_NEW_IND(); \
54 and_then; \
55 }
56
57 #else /* !CMINUSMINUS */
58
59 INLINE_HEADER void updateWithIndirection (Capability *cap,
60 StgClosure *p1,
61 StgClosure *p2)
62 {
63 bdescr *bd;
64
65 ASSERT( (P_)p1 != (P_)p2 );
66 /* not necessarily true: ASSERT( !closure_IND(p1) ); */
67 /* occurs in RaiseAsync.c:raiseAsync() */
68 OVERWRITING_CLOSURE(p1);
69 ((StgInd *)p1)->indirectee = p2;
70 write_barrier();
71 SET_INFO(p1, &stg_BLACKHOLE_info);
72 LDV_RECORD_CREATE(p1);
73 bd = Bdescr((StgPtr)p1);
74 if (bd->gen_no != 0) {
75 recordMutableCap(p1, cap, bd->gen_no);
76 TICK_UPD_OLD_IND();
77 } else {
78 TICK_UPD_NEW_IND();
79 }
80 }
81
82 #endif /* CMINUSMINUS */
83
84 #ifndef CMINUSMINUS
85 #include "EndPrivate.h"
86 #endif
87
88 #endif /* UPDATES_H */