[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / runtime / storage / SMmarking.lc
1 /*************************************************************************
2                            MARKING OF ROOTS
3 *************************************************************************/
4
5 [Something needed here to explain what this is doing.  KH]
6
7 \begin{code}
8
9 #define MARK_REG_MAP
10 #include "SMinternal.h"
11
12 extern I_ doSanityChks; /* ToDo: move tidily */
13
14 #if defined(_INFO_MARKING)
15
16 #if defined (__STG_GCC_REGS__) /* If we are using registers load _SAVE */
17
18 /* If we are using registers load _SAVE */
19 #define Mark     SAVE_Mark
20 #define MRoot    SAVE_MRoot
21 #define MStack   SAVE_MStack
22 #define BitArray SAVE_BitArray
23 #define HeapBase SAVE_HeapBase
24 #define HeapLim  SAVE_HeapLim
25
26 #endif /* registerized */
27
28 /* These in SMmark.lhc -- need to be in .hc file */
29 EXTFUN(_startMarkWorld);
30
31 EXTFUN(_PRMarking_MarkNextRoot);
32 EXTFUN(_PRMarking_MarkNextCAF);
33 EXTDATA(_PRMarking_MarkNextRoot_closure);
34 EXTDATA(_PRMarking_MarkNextCAF_closure);
35
36 #ifdef CONCURRENT
37 EXTFUN(_PRMarking_MarkNextSpark);
38 EXTDATA(_PRMarking_MarkNextSpark_closure);
39 #endif
40
41 #ifdef PAR
42 EXTFUN(_PRMarking_MarkNextGA);
43 EXTDATA(_PRMarking_MarkNextGA_closure);
44 #else
45 EXTFUN(_PRMarking_MarkNextAStack);
46 EXTFUN(_PRMarking_MarkNextBStack);
47 EXTDATA(_PRMarking_MarkNextAStack_closure);
48 EXTDATA(_PRMarking_MarkNextBStack_closure);
49 #endif /* not parallel */
50
51 P_ sm_roots_end;
52
53 I_
54 markHeapRoots(sm, cafs1, cafs2, base, lim, bit_array)
55     smInfo *sm;
56     P_ cafs1, cafs2;  /* Pointer to CAF lists */
57     P_ base;          /* Heap closure in range only tested for by GCgn */
58     P_ lim;
59     BitWord *bit_array;
60 {
61 #ifdef CONCURRENT
62     int pool;
63 #endif
64
65 #if 0 /* Code to avoid explicit updating of CAF references */
66
67     /* Before marking have to modify CAFs to auxillary info table */
68     P_ CAFptr;
69     DEBUG_STRING("Setting Mark & Upd CAFs:");
70     for (CAFptr = cafs1; CAFptr;
71          CAFptr = (P_) IND_CLOSURE_LINK(CAFptr)) {
72         INFO_PTR(CAFptr) = (W_) Caf_Mark_Upd_info;
73     }
74     for (CAFptr = cafs2; CAFptr;
75          CAFptr = (P_) IND_CLOSURE_LINK(CAFptr)) {
76         INFO_PTR(CAFptr) = (W_) Caf_Mark_Upd_info;
77     }
78     DEBUG_STRING("Marking CAFs:");
79     if (cafs1) {
80         MRoot = (P_) cafs1;
81         Mark = (P_) MRoot;
82         MStack = (P_) _PRMarking_MarkNextCAF_closure;
83         /*ToDo: debugify */
84         miniInterpret((StgFunPtr)_startMarkWorld);
85     }
86     if (cafs2) {
87         MRoot = (P_) cafs2;
88         Mark = (P_) MRoot;
89         MStack = (P_) _PRMarking_MarkNextCAF_closure;
90         /*ToDo: debugify */
91         miniInterpret((StgFunPtr)_startMarkWorld);
92     }
93
94 #endif /* 0 */
95
96     BitArray = bit_array;
97     HeapBase = base;
98     HeapLim = lim;
99
100     DEBUG_STRING("Marking Roots:");
101     if (sm->rootno > 0) {
102         sm_roots_end = (P_) &sm->roots[sm->rootno];
103         MRoot = (P_) sm->roots;
104         Mark = (P_) *MRoot;
105         MStack = (P_) _PRMarking_MarkNextRoot_closure;
106 #if defined(__STG_TAILJUMPS__)
107         miniInterpret((StgFunPtr)_startMarkWorld);
108 #else
109     if (doSanityChks)
110         miniInterpret_debug((StgFunPtr)_startMarkWorld, NULL);
111     else
112         miniInterpret((StgFunPtr)_startMarkWorld);
113 #endif /* ! tail-jumping */
114     }
115
116 #ifdef CONCURRENT
117     for(pool = 0; pool < SPARK_POOLS; pool++) {
118         if (PendingSparksHd[pool] < PendingSparksTl[pool]) {
119             sm_roots_end = (P_) PendingSparksTl[pool];
120             MRoot = (P_) PendingSparksHd[pool];
121             Mark = (P_) *MRoot;
122             MStack = (P_) _PRMarking_MarkNextSpark_closure;
123 #if defined(__STG_TAILJUMPS__)
124             miniInterpret((StgFunPtr)_startMarkWorld);
125 #else
126         if (doSanityChks)
127             miniInterpret_debug((StgFunPtr)_startMarkWorld, NULL);
128         else
129             miniInterpret((StgFunPtr)_startMarkWorld);
130 #endif /* ! tail-jumping */
131         }
132     }
133 #endif
134
135 #ifdef PAR
136     DEBUG_STRING("Marking GA Roots:");
137     MRoot = (P_) liveIndirections;
138     while(MRoot != NULL && ((GALA *)MRoot)->ga.weight == MAX_GA_WEIGHT)
139         MRoot = (P_) ((GALA *)MRoot)->next;
140     if (MRoot != NULL) {
141         Mark = ((GALA *)MRoot)->la;
142         MStack = (P_) _PRMarking_MarkNextGA_closure;
143 #if defined(__STG_TAILJUMPS__)
144         miniInterpret((StgFunPtr) _startMarkWorld);
145 #else
146         if (doSanityChks)
147             miniInterpret_debug((StgFunPtr) _startMarkWorld, NULL);
148         else
149             miniInterpret((StgFunPtr) _startMarkWorld);
150 #endif /* ! tail-jumping */
151     }
152 #else
153     /* Note: no *external* stacks in parallel world */
154     DEBUG_STRING("Marking A Stack:");
155     if (SUBTRACT_A_STK(MAIN_SpA, stackInfo.botA) >= 0) {
156         MRoot = (P_) MAIN_SpA;
157         Mark = (P_) *MRoot;
158         MStack = (P_) _PRMarking_MarkNextAStack_closure;
159 #if defined(__STG_TAILJUMPS__)
160         miniInterpret((StgFunPtr)_startMarkWorld);
161 #else
162     if (doSanityChks)
163         miniInterpret_debug((StgFunPtr)_startMarkWorld, NULL);
164     else
165         miniInterpret((StgFunPtr)_startMarkWorld);
166 #endif /* ! tail-jumping */
167     }
168
169     DEBUG_STRING("Marking B Stack:");
170     if (SUBTRACT_B_STK(MAIN_SuB, stackInfo.botB) > 0) {
171         MRoot = MAIN_SuB;
172         Mark = GRAB_UPDATEE(MRoot);
173         MStack = (P_) _PRMarking_MarkNextBStack_closure;
174         miniInterpret((StgFunPtr)_startMarkWorld);
175     }
176 #endif /* PAR */
177
178     DEBUG_STRING("Marking & Updating CAFs:");
179     if (cafs1) {
180         MRoot = cafs1;
181         Mark = (P_) IND_CLOSURE_PTR(MRoot);
182         MStack = (P_) _PRMarking_MarkNextCAF_closure;
183 #if defined(__STG_TAILJUMPS__)
184         miniInterpret((StgFunPtr)_startMarkWorld);
185 #else
186     if (doSanityChks)
187         miniInterpret_debug((StgFunPtr)_startMarkWorld, NULL);
188     else
189         miniInterpret((StgFunPtr)_startMarkWorld);
190 #endif /* ! tail-jumping */
191     }
192
193     if (cafs2) {
194         MRoot = cafs2;
195         Mark = (P_) IND_CLOSURE_PTR(MRoot);
196         MStack = (P_) _PRMarking_MarkNextCAF_closure;
197 #if defined(__STG_TAILJUMPS__)
198         miniInterpret((StgFunPtr)_startMarkWorld);
199 #else
200     if (doSanityChks)
201         miniInterpret_debug((StgFunPtr)_startMarkWorld, NULL);
202     else
203         miniInterpret((StgFunPtr)_startMarkWorld);
204 #endif /* ! tail-jumping */
205     }
206     return 0;
207 }
208
209 #endif /* _INFO_MARKING */
210
211 \end{code}
212
213
214 CODE REQUIRED (expressed as a loop):
215
216 MARK ROOTS
217
218     MStack = _PRMarking_MarkNextRoot_closure;
219     for (MRoot = (P_) sm->roots;
220          MRoot < (P_) &sm->roots[sm->rootno];
221          MRoot++) {
222         Mark = (P_) *MRoot;
223         (PRMARK_CODE(INFO_PTR(Mark)))();
224 _PRMarking_MarkNextRoot:
225         *MRoot = (W_) Mark;
226     }
227
228
229 MARK AStack
230
231     MStack = _PRMarking_MarkNextAStack_closure;
232     for (MRoot = MAIN_SpA;
233          SUBTRACT_A_STK(MRoot, stackInfo.botA) >= 0;
234          MRoot = MRoot + AREL(1)) {
235         Mark = (P_) *MRoot;
236         (PRMARK_CODE(INFO_PTR(Mark)))();
237 _PRMarking_MarkNextAStack:
238         *MRoot = (W_) Mark;
239     }
240
241
242 MARK BStack
243
244     MStack = _PRMarking_MarkNextBStack_closure;
245     for (MRoot = MAIN_SuB;  --- Topmost Update Frame
246          SUBTRACT_B_STK(MRoot, stackInfo.botB) > 0;
247          MRoot = GRAB_SuB(MRoot)) {
248
249         Mark = GRAB_UPDATEE(MRoot);
250         (PRMARK_CODE(INFO_PTR(Mark)))();
251 _PRMarking_MarkNextBStack:
252         PUSH_UPDATEE(MRoot, Mark);
253     }
254
255
256 MARK CAFs
257
258     MStack = _PRMarking_MarkNextCAF_closure;
259     for (MRoot = sm->CAFlist;
260          MRoot;
261          MRoot = (P_) IND_CLOSURE_LINK(MRoot))
262
263         Mark = IND_CLOSURE_PTR(MRoot);
264         (PRMARK_CODE(INFO_PTR(Mark)))();
265 _PRMarking_MarkNextCAF:
266         IND_CLOSURE_PTR(MRoot) = (W_) Mark;
267     }