-/* -----------------------------------------------------------------------------
+/* -----------------------------------------------------------------------*-c-*-
*
- * (c) The GHC Team 1998-2006
+ * (c) The GHC Team 1998-2008
*
* Generational garbage collector: scavenging functions
*
*
* ---------------------------------------------------------------------------*/
-// This file is #included into Scav.c, twice: firstly with MINOR_GC
+// This file is #included into Scav.c, twice: firstly with PARALLEL_GC
// defined, the second time without.
-#ifdef MINOR_GC
-#define scavenge_block(a,b) scavenge_block0(a,b)
-#define evacuate(a) evacuate0(a)
+#ifndef PARALLEL_GC
+#define scavenge_block(a) scavenge_block1(a)
+#define evacuate(a) evacuate1(a)
+#define recordMutableGen_GC(a,b) recordMutableGen(a,b)
#else
#undef scavenge_block
#undef evacuate
+#undef recordMutableGen_GC
#endif
-static void scavenge_block (bdescr *bd, StgPtr scan);
+static void scavenge_block (bdescr *bd);
/* -----------------------------------------------------------------------------
Scavenge a block from the given scan pointer up to bd->free.
-------------------------------------------------------------------------- */
static void
-scavenge_block (bdescr *bd, StgPtr scan)
+scavenge_block (bdescr *bd)
{
StgPtr p, q;
StgInfoTable *info;
step *saved_evac_step;
rtsBool saved_eager_promotion;
+ step_workspace *ws;
- p = scan;
-
debugTrace(DEBUG_gc, "scavenging block %p (gen %d, step %d) @ %p",
- bd->start, bd->gen_no, bd->step->no, scan);
+ bd->start, bd->gen_no, bd->step->no, bd->u.scan);
+ gct->scan_bd = bd;
gct->evac_step = bd->step;
saved_evac_step = gct->evac_step;
saved_eager_promotion = gct->eager_promotion;
gct->failed_to_evac = rtsFalse;
+ ws = &gct->steps[bd->step->abs_no];
+
+ p = bd->u.scan;
+
// we might be evacuating into the very object that we're
// scavenging, so we have to check the real bd->free pointer each
// time around the loop.
- while (p < bd->free) {
+ while (p < bd->free || (bd == ws->todo_bd && p < ws->todo_free)) {
ASSERT(LOOKS_LIKE_CLOSURE_PTR(p));
info = get_itbl((StgClosure *)p);
}
case FUN_2_0:
-#ifndef MINOR_GC
scavenge_fun_srt(info);
-#endif
evacuate(&((StgClosure *)p)->payload[1]);
evacuate(&((StgClosure *)p)->payload[0]);
p += sizeofW(StgHeader) + 2;
break;
case THUNK_2_0:
-#ifndef MINOR_GC
scavenge_thunk_srt(info);
-#endif
evacuate(&((StgThunk *)p)->payload[1]);
evacuate(&((StgThunk *)p)->payload[0]);
p += sizeofW(StgThunk) + 2;
break;
case THUNK_1_0:
-#ifndef MINOR_GC
scavenge_thunk_srt(info);
-#endif
evacuate(&((StgThunk *)p)->payload[0]);
p += sizeofW(StgThunk) + 1;
break;
case FUN_1_0:
-#ifndef MINOR_GC
scavenge_fun_srt(info);
-#endif
case CONSTR_1_0:
evacuate(&((StgClosure *)p)->payload[0]);
p += sizeofW(StgHeader) + 1;
break;
case THUNK_0_1:
-#ifndef MINOR_GC
scavenge_thunk_srt(info);
-#endif
p += sizeofW(StgThunk) + 1;
break;
case FUN_0_1:
-#ifndef MINOR_GC
scavenge_fun_srt(info);
-#endif
case CONSTR_0_1:
p += sizeofW(StgHeader) + 1;
break;
case THUNK_0_2:
-#ifndef MINOR_GC
scavenge_thunk_srt(info);
-#endif
p += sizeofW(StgThunk) + 2;
break;
case FUN_0_2:
-#ifndef MINOR_GC
scavenge_fun_srt(info);
-#endif
case CONSTR_0_2:
p += sizeofW(StgHeader) + 2;
break;
case THUNK_1_1:
-#ifndef MINOR_GC
scavenge_thunk_srt(info);
-#endif
evacuate(&((StgThunk *)p)->payload[0]);
p += sizeofW(StgThunk) + 2;
break;
case FUN_1_1:
-#ifndef MINOR_GC
scavenge_fun_srt(info);
-#endif
case CONSTR_1_1:
evacuate(&((StgClosure *)p)->payload[0]);
p += sizeofW(StgHeader) + 2;
break;
case FUN:
-#ifndef MINOR_GC
scavenge_fun_srt(info);
-#endif
goto gen_obj;
case THUNK:
{
StgPtr end;
-#ifndef MINOR_GC
scavenge_thunk_srt(info);
-#endif
end = (P_)((StgThunk *)p)->payload + info->layout.payload.ptrs;
for (p = (P_)((StgThunk *)p)->payload; p < end; p++) {
evacuate((StgClosure **)p);
case TSO:
{
StgTSO *tso = (StgTSO *)p;
-
- gct->eager_promotion = rtsFalse;
- scavengeTSO(tso);
- gct->eager_promotion = saved_eager_promotion;
-
- if (gct->failed_to_evac) {
- tso->flags |= TSO_DIRTY;
- } else {
- tso->flags &= ~TSO_DIRTY;
- }
-
- gct->failed_to_evac = rtsTrue; // always on the mutable list
+ scavengeTSO(tso);
p += tso_sizeW(tso);
break;
}
}
}
- debugTrace(DEBUG_gc, " scavenged %ld bytes", (bd->free - scan) * sizeof(W_));
+ if (p > bd->free) {
+ gct->copied += ws->todo_free - bd->free;
+ bd->free = p;
+ }
+
+ debugTrace(DEBUG_gc, " scavenged %ld bytes",
+ (unsigned long)((bd->free - bd->u.scan) * sizeof(W_)));
+
+ // update stats: this is a block that has been scavenged
+ gct->scanned += bd->free - bd->u.scan;
+ bd->u.scan = bd->free;
+
+ if (bd != ws->todo_bd) {
+ // we're not going to evac any more objects into
+ // this block, so push it now.
+ push_scanned_block(bd, ws);
+ }
+
+ gct->scan_bd = NULL;
}
+
+#undef scavenge_block
+#undef evacuate
+#undef recordMutableGen_GC