1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 2001
6 * Lag/Drag/Void profiling.
8 * ---------------------------------------------------------------------------*/
13 #include "LdvProfile.h"
15 #include "Profiling.h"
21 /* --------------------------------------------------------------------------
22 * Fills in the slop when a *dynamic* closure changes its type.
23 * First calls LDV_recordDead() to declare the closure is dead, and then
27 * 1) blackholing, UPD_BH_UPDATABLE() and UPD_BH_SINGLE_ENTRY (in
28 * includes/StgMacros.h), threadLazyBlackHole() and
29 * threadSqueezeStack() (in GC.c).
30 * 2) updating with indirection closures, updateWithIndirection()
31 * and updateWithPermIndirection() (in Storage.h).
33 * LDV_recordDead_FILL_SLOP_DYNAMIC() is not called on 'inherently used'
34 * closures such as TSO. It is not called on PAP because PAP is not updatable.
35 * ----------------------------------------------------------------------- */
37 LDV_recordDead_FILL_SLOP_DYNAMIC( StgClosure *p )
41 #if defined(__GNUC__) && __GNUC__ < 3 && defined(DEBUG)
42 #error Please use gcc 3.0+ to compile this file with DEBUG; gcc < 3.0 miscompiles it
46 // very like FILL_SLOP(), except that we call LDV_recordDead().
47 size = closure_sizeW(p);
49 LDV_recordDead((StgClosure *)(p), size);
51 if (size > sizeofW(StgThunkHeader)) {
52 for (i = 0; i < size - sizeofW(StgThunkHeader); i++) {
53 ((StgThunk *)(p))->payload[i] = 0;
59 /* --------------------------------------------------------------------------
60 * This function is called eventually on every object destroyed during
61 * a garbage collection, whether it is a major garbage collection or
62 * not. If c is an 'inherently used' closure, nothing happens. If c
63 * is an ordinary closure, LDV_recordDead() is called on c with its
64 * proper size which excludes the profiling header portion in the
65 * closure. Returns the size of the closure, including the profiling
66 * header portion, so that the caller can find the next closure.
67 * ----------------------------------------------------------------------- */
69 processHeapClosureForDead( StgClosure *c )
76 if (info->type != EVACUATED) {
77 ASSERT(((LDVW(c) & LDV_CREATE_MASK) >> LDV_SHIFT) <= era &&
78 ((LDVW(c) & LDV_CREATE_MASK) >> LDV_SHIFT) > 0);
79 ASSERT(((LDVW(c) & LDV_STATE_MASK) == LDV_STATE_CREATE) ||
81 (LDVW(c) & LDV_LAST_MASK) <= era &&
82 (LDVW(c) & LDV_LAST_MASK) > 0
86 if (info->type == EVACUATED) {
87 // The size of the evacuated closure is currently stored in
88 // the LDV field. See SET_EVACUAEE_FOR_LDV() in
89 // includes/StgLdvProf.h.
93 size = closure_sizeW(c);
97 'inherently used' cases: do nothing.
101 case MUT_ARR_PTRS_CLEAN:
102 case MUT_ARR_PTRS_DIRTY:
103 case MUT_ARR_PTRS_FROZEN:
104 case MUT_ARR_PTRS_FROZEN0:
114 ordinary cases: call LDV_recordDead().
141 case SE_CAF_BLACKHOLE:
143 case IND_OLDGEN_PERM:
147 // Why can we ignore IND/IND_OLDGEN closures? We assume that
148 // any census is preceded by a major garbage collection, which
149 // IND/IND_OLDGEN closures cannot survive. Therefore, it is no
150 // use considering IND/IND_OLDGEN closures in the meanwhile
151 // because they will perish before the next census at any
155 // Found a dead closure: record its size
156 LDV_recordDead(c, size);
168 case CONSTR_CHARLIKE:
169 case CONSTR_NOCAF_STATIC:
188 barf("Invalid object in processHeapClosureForDead(): %d", info->type);
193 /* --------------------------------------------------------------------------
194 * Calls processHeapClosureForDead() on every *dead* closures in the
195 * heap blocks starting at bd.
196 * ----------------------------------------------------------------------- */
198 processHeapForDead( bdescr *bd )
204 while (p < bd->free) {
205 p += processHeapClosureForDead((StgClosure *)p);
206 while (p < bd->free && !*p) // skip slop
209 ASSERT(p == bd->free);
214 /* --------------------------------------------------------------------------
215 * Calls processHeapClosureForDead() on every *dead* closures in the nursery.
216 * ----------------------------------------------------------------------- */
218 processNurseryForDead( void )
223 bd = MainCapability.r.rNursery->blocks;
224 while (bd->start < bd->free) {
226 bdLimit = bd->start + BLOCK_SIZE_W;
227 while (p < bd->free && p < bdLimit) {
228 p += processHeapClosureForDead((StgClosure *)p);
229 while (p < bd->free && p < bdLimit && !*p) // skip slop
238 /* --------------------------------------------------------------------------
239 * Calls processHeapClosureForDead() on every *dead* closures in the
241 * ----------------------------------------------------------------------- */
243 processSmallObjectPoolForDead( void )
248 bd = small_alloc_list;
255 while (p < alloc_Hp) {
256 p += processHeapClosureForDead((StgClosure *)p);
257 while (p < alloc_Hp && !*p) // skip slop
260 ASSERT(p == alloc_Hp);
265 while (p < bd->free) {
266 p += processHeapClosureForDead((StgClosure *)p);
267 while (p < bd->free && !*p) // skip slop
270 ASSERT(p == bd->free);
275 /* --------------------------------------------------------------------------
276 * Calls processHeapClosureForDead() on every *dead* closures in the closure
278 * ----------------------------------------------------------------------- */
280 processChainForDead( bdescr *bd )
282 // Any object still in the chain is dead!
284 processHeapClosureForDead((StgClosure *)bd->start);
289 /* --------------------------------------------------------------------------
290 * Start a census for *dead* closures, and calls
291 * processHeapClosureForDead() on every closure which died in the
292 * current garbage collection. This function is called from a garbage
293 * collector right before tidying up, when all dead closures are still
294 * stored in the heap and easy to identify. Generations 0 through N
295 * have just beed garbage collected.
296 * ----------------------------------------------------------------------- */
298 LdvCensusForDead( nat N )
302 // ldvTime == 0 means that LDV profiling is currently turned off.
306 if (RtsFlags.GcFlags.generations == 1) {
308 // Todo: support LDV for two-space garbage collection.
310 barf("Lag/Drag/Void profiling not supported with -G1");
312 for (g = 0; g <= N; g++)
313 for (s = 0; s < generations[g].n_steps; s++) {
314 if (g == 0 && s == 0) {
315 processSmallObjectPoolForDead();
316 processNurseryForDead();
317 processChainForDead(generations[g].steps[s].large_objects);
319 processHeapForDead(generations[g].steps[s].blocks);
320 processChainForDead(generations[g].steps[s].large_objects);
326 /* --------------------------------------------------------------------------
327 * Regard any closure in the current heap as dead or moribund and update
328 * LDV statistics accordingly.
329 * Called from shutdownHaskell() in RtsStartup.c.
330 * Also, stops LDV profiling by resetting ldvTime to 0.
331 * ----------------------------------------------------------------------- */
333 LdvCensusKillAll( void )
335 LdvCensusForDead(RtsFlags.GcFlags.generations - 1);
338 #endif /* PROFILING */