1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 2001
6 * Lag/Drag/Void profiling.
8 * ---------------------------------------------------------------------------*/
12 #include "PosixSource.h"
15 #include "Profiling.h"
16 #include "LdvProfile.h"
21 /* --------------------------------------------------------------------------
22 * This function is called eventually on every object destroyed during
23 * a garbage collection, whether it is a major garbage collection or
24 * not. If c is an 'inherently used' closure, nothing happens. If c
25 * is an ordinary closure, LDV_recordDead() is called on c with its
26 * proper size which excludes the profiling header portion in the
27 * closure. Returns the size of the closure, including the profiling
28 * header portion, so that the caller can find the next closure.
29 * ----------------------------------------------------------------------- */
31 processHeapClosureForDead( StgClosure *c )
34 const StgInfoTable *info;
38 info = c->header.info;
39 if (IS_FORWARDING_PTR(info)) {
40 // The size of the evacuated closure is currently stored in
41 // the LDV field. See SET_EVACUAEE_FOR_LDV() in
42 // includes/StgLdvProf.h.
45 info = INFO_PTR_TO_STRUCT(info);
47 ASSERT(((LDVW(c) & LDV_CREATE_MASK) >> LDV_SHIFT) <= era &&
48 ((LDVW(c) & LDV_CREATE_MASK) >> LDV_SHIFT) > 0);
49 ASSERT(((LDVW(c) & LDV_STATE_MASK) == LDV_STATE_CREATE) ||
51 (LDVW(c) & LDV_LAST_MASK) <= era &&
52 (LDVW(c) & LDV_LAST_MASK) > 0
56 size = closure_sizeW(c);
60 'inherently used' cases: do nothing.
66 case MUT_ARR_PTRS_CLEAN:
67 case MUT_ARR_PTRS_DIRTY:
68 case MUT_ARR_PTRS_FROZEN:
69 case MUT_ARR_PTRS_FROZEN0:
81 ordinary cases: call LDV_recordDead().
111 // Why can we ignore IND closures? We assume that
112 // any census is preceded by a major garbage collection, which
113 // IND closures cannot survive. Therefore, it is no
114 // use considering IND closures in the meanwhile
115 // because they will perish before the next census at any
118 // Found a dead closure: record its size
119 LDV_recordDead(c, size);
130 case CONSTR_NOCAF_STATIC:
134 case UNDERFLOW_FRAME:
143 barf("Invalid object in processHeapClosureForDead(): %d", info->type);
148 /* --------------------------------------------------------------------------
149 * Calls processHeapClosureForDead() on every *dead* closures in the
150 * heap blocks starting at bd.
151 * ----------------------------------------------------------------------- */
153 processHeapForDead( bdescr *bd )
159 while (p < bd->free) {
160 p += processHeapClosureForDead((StgClosure *)p);
161 while (p < bd->free && !*p) // skip slop
164 ASSERT(p == bd->free);
169 /* --------------------------------------------------------------------------
170 * Calls processHeapClosureForDead() on every *dead* closures in the nursery.
171 * ----------------------------------------------------------------------- */
173 processNurseryForDead( void )
178 bd = MainCapability.r.rNursery->blocks;
179 while (bd->start < bd->free) {
181 bdLimit = bd->start + BLOCK_SIZE_W;
182 while (p < bd->free && p < bdLimit) {
183 p += processHeapClosureForDead((StgClosure *)p);
184 while (p < bd->free && p < bdLimit && !*p) // skip slop
193 /* --------------------------------------------------------------------------
194 * Calls processHeapClosureForDead() on every *dead* closures in the closure
196 * ----------------------------------------------------------------------- */
198 processChainForDead( bdescr *bd )
200 // Any object still in the chain is dead!
202 if (!(bd->flags & BF_PINNED)) {
203 processHeapClosureForDead((StgClosure *)bd->start);
209 /* --------------------------------------------------------------------------
210 * Start a census for *dead* closures, and calls
211 * processHeapClosureForDead() on every closure which died in the
212 * current garbage collection. This function is called from a garbage
213 * collector right before tidying up, when all dead closures are still
214 * stored in the heap and easy to identify. Generations 0 through N
215 * have just beed garbage collected.
216 * ----------------------------------------------------------------------- */
218 LdvCensusForDead( nat N )
222 // ldvTime == 0 means that LDV profiling is currently turned off.
226 if (RtsFlags.GcFlags.generations == 1) {
228 // Todo: support LDV for two-space garbage collection.
230 barf("Lag/Drag/Void profiling not supported with -G1");
232 processNurseryForDead();
233 for (g = 0; g <= N; g++) {
234 processHeapForDead(generations[g].old_blocks);
235 processChainForDead(generations[g].large_objects);
240 /* --------------------------------------------------------------------------
241 * Regard any closure in the current heap as dead or moribund and update
242 * LDV statistics accordingly.
243 * Called from shutdownHaskell() in RtsStartup.c.
244 * Also, stops LDV profiling by resetting ldvTime to 0.
245 * ----------------------------------------------------------------------- */
247 LdvCensusKillAll( void )
249 LdvCensusForDead(RtsFlags.GcFlags.generations - 1);
252 #endif /* PROFILING */