/* -----------------------------------------------------------------------------
- * $Id: GC.c,v 1.22 1999/01/28 15:04:00 simonm Exp $
+ * $Id: GC.c,v 1.23 1999/02/02 14:21:29 simonm Exp $
*
* Two-space garbage collector
*
static void scavenge(step *step);
static void scavenge_static(void);
static StgMutClosure *scavenge_mutable_list(StgMutClosure *p, nat gen);
+static StgMutClosure *scavenge_mut_once_list(StgMutClosure *p, nat gen);
#ifdef DEBUG
static void gcCAFs(void);
* zeroMutableList below).
*/
if (major_gc) {
- zeroMutableList(generations[RtsFlags.GcFlags.generations-1].mut_list);
+ zeroMutableList(generations[RtsFlags.GcFlags.generations-1].mut_once_list);
}
/* Save the old to-space if we're doing a two-space collection
* collecting.
*/
for (g = 0; g <= N; g++) {
+ generations[g].mut_once_list = END_MUT_LIST;
generations[g].mut_list = END_MUT_LIST;
for (s = 0; s < generations[g].n_steps; s++) {
generations[g].mut_list = END_MUT_LIST;
}
+ /* Do the mut-once lists first */
+ for (g = RtsFlags.GcFlags.generations-1; g > N; g--) {
+ generations[g].mut_once_list =
+ scavenge_mut_once_list(generations[g].mut_once_list, g);
+ }
+
for (g = RtsFlags.GcFlags.generations-1; g > N; g--) {
tmp = scavenge_mutable_list(generations[g].saved_mut_list, g);
pp = &generations[g].mut_list;
{
P_ to, from, dest;
+ TICK_GC_WORDS_COPIED(size);
/* Find out where we're going, using the handy "to" pointer in
* the step of the source object. If it turns out we need to
* evacuate to an older generation, adjust it here (see comment
{
P_ dest, to, from;
+ TICK_GC_WORDS_COPIED(size_to_copy);
if (step->gen->no < evac_gen) {
step = &generations[evac_gen].steps[0];
}
}
/* -----------------------------------------------------------------------------
- Evacuate a mutable object
-
- If we evacuate a mutable object to an old generation, cons the
- object onto the older generation's mutable list.
- -------------------------------------------------------------------------- */
-
-static inline void
-evacuate_mutable(StgMutClosure *c)
-{
- bdescr *bd;
-
- bd = Bdescr((P_)c);
- if (bd->gen->no > 0) {
- c->mut_link = bd->gen->mut_list;
- bd->gen->mut_list = c;
- }
-}
-
-/* -----------------------------------------------------------------------------
Evacuate a large object
This just consists of removing the object from the (doubly-linked)
bd->evacuated = 1;
if (mutable) {
- evacuate_mutable((StgMutClosure *)p);
+ recordMutable((StgMutClosure *)p);
}
}
SET_HDR(q,&MUT_CONS_info,CCS_GC);
q->var = ptr;
- evacuate_mutable((StgMutClosure *)q);
+ recordOldToNewPtrs((StgMutClosure *)q);
return (StgClosure *)q;
}
return to;
case MUT_VAR:
+ ASSERT(q->header.info != &MUT_CONS_info);
case MVAR:
to = copy(q,sizeW_fromITBL(info),step);
upd_evacuee(q,to);
- evacuate_mutable((StgMutClosure *)to);
+ recordMutable((StgMutClosure *)to);
return to;
case STABLE_NAME:
case BLACKHOLE_BQ:
to = copy(q,BLACKHOLE_sizeW(),step);
upd_evacuee(q,to);
- evacuate_mutable((StgMutClosure *)to);
+ recordMutable((StgMutClosure *)to);
return to;
case THUNK_SELECTOR:
/* fprintf(stderr,"evac failed!\n");*/
failed_to_evac = rtsTrue;
TICK_GC_FAILED_PROMOTION();
- }
+ }
}
return ((StgEvacuated*)q)->evacuee;
to = copy(q,size,step);
upd_evacuee(q,to);
if (info->type == MUT_ARR_PTRS) {
- evacuate_mutable((StgMutClosure *)to);
+ recordMutable((StgMutClosure *)to);
}
}
return to;
relocate_TSO(tso, new_tso);
upd_evacuee(q,(StgClosure *)new_tso);
- evacuate_mutable((StgMutClosure *)new_tso);
+ recordMutable((StgMutClosure *)new_tso);
return (StgClosure *)new_tso;
}
}
evacuate((StgClosure *)bh->blocking_queue);
if (failed_to_evac) {
failed_to_evac = rtsFalse;
- evacuate_mutable((StgMutClosure *)bh);
+ recordMutable((StgMutClosure *)bh);
}
p += BLACKHOLE_sizeW();
break;
}
if (failed_to_evac) {
/* we can do this easier... */
- evacuate_mutable((StgMutClosure *)start);
+ recordMutable((StgMutClosure *)start);
failed_to_evac = rtsFalse;
}
break;
objects can have this property.
-------------------------------------------------------------------------- */
static rtsBool
-scavenge_one(StgPtr p)
+scavenge_one(StgClosure *p)
{
StgInfoTable *info;
rtsBool no_luck;
- ASSERT(p && (LOOKS_LIKE_GHC_INFO(GET_INFO((StgClosure *)p))
- || IS_HUGS_CONSTR_INFO(GET_INFO((StgClosure *)p))));
+ ASSERT(p && (LOOKS_LIKE_GHC_INFO(GET_INFO(p))
+ || IS_HUGS_CONSTR_INFO(GET_INFO(p))));
- info = get_itbl((StgClosure *)p);
+ info = get_itbl(p);
switch (info -> type) {
case CAF_UNENTERED:
case CAF_ENTERED:
{
- StgPtr end;
+ StgPtr q, end;
- end = (P_)((StgClosure *)p)->payload + info->layout.payload.ptrs;
- for (p = (P_)((StgClosure *)p)->payload; p < end; p++) {
- (StgClosure *)*p = evacuate((StgClosure *)*p);
+ end = (P_)p->payload + info->layout.payload.ptrs;
+ for (q = (P_)p->payload; q < end; q++) {
+ (StgClosure *)*q = evacuate((StgClosure *)*q);
}
break;
}
{
StgSelector *s = (StgSelector *)p;
s->selectee = evacuate(s->selectee);
- break;
+ break;
}
case AP_UPD: /* same as PAPs */
* evacuate the function pointer too...
*/
{
- StgPAP* pap = stgCast(StgPAP*,p);
+ StgPAP* pap = (StgPAP *)p;
pap->fun = evacuate(pap->fun);
scavenge_stack((P_)pap->payload, (P_)pap->payload + pap->n_args);
-------------------------------------------------------------------------- */
static StgMutClosure *
+scavenge_mut_once_list(StgMutClosure *p, nat gen)
+{
+ StgInfoTable *info;
+ StgMutClosure *start;
+ StgMutClosure **prev;
+
+ prev = &start;
+ start = p;
+
+ evac_gen = gen;
+ failed_to_evac = rtsFalse;
+
+ for (; p != END_MUT_LIST; p = *prev) {
+
+ /* make sure the info pointer is into text space */
+ ASSERT(p && (LOOKS_LIKE_GHC_INFO(GET_INFO(p))
+ || IS_HUGS_CONSTR_INFO(GET_INFO(p))));
+
+ info = get_itbl(p);
+ switch(info->type) {
+
+ case IND_OLDGEN:
+ case IND_OLDGEN_PERM:
+ case IND_STATIC:
+ /* Try to pull the indirectee into this generation, so we can
+ * remove the indirection from the mutable list.
+ */
+ ((StgIndOldGen *)p)->indirectee =
+ evacuate(((StgIndOldGen *)p)->indirectee);
+
+ /* failed_to_evac might happen if we've got more than two
+ * generations, we're collecting only generation 0, the
+ * indirection resides in generation 2 and the indirectee is
+ * in generation 1.
+ */
+ if (failed_to_evac) {
+ failed_to_evac = rtsFalse;
+ prev = &p->mut_link;
+ } else {
+ *prev = p->mut_link;
+ /* the mut_link field of an IND_STATIC is overloaded as the
+ * static link field too (it just so happens that we don't need
+ * both at the same time), so we need to NULL it out when
+ * removing this object from the mutable list because the static
+ * link fields are all assumed to be NULL before doing a major
+ * collection.
+ */
+ p->mut_link = NULL;
+ }
+ continue;
+
+ case MUT_VAR:
+ /* MUT_CONS is a kind of MUT_VAR, except it that we try to remove
+ * it from the mutable list if possible by promoting whatever it
+ * points to.
+ */
+ ASSERT(p->header.info == &MUT_CONS_info);
+ if (scavenge_one(((StgMutVar *)p)->var) == rtsTrue) {
+ /* didn't manage to promote everything, so leave the
+ * MUT_CONS on the list.
+ */
+ prev = &p->mut_link;
+ } else {
+ *prev = p->mut_link;
+ }
+ continue;
+
+ default:
+ /* shouldn't have anything else on the mutables list */
+ barf("scavenge_mut_once_list: strange object?");
+ }
+ }
+ return start;
+}
+
+
+static StgMutClosure *
scavenge_mutable_list(StgMutClosure *p, nat gen)
{
StgInfoTable *info;
* it from the mutable list if possible by promoting whatever it
* points to.
*/
- if (p->header.info == &MUT_CONS_info) {
- evac_gen = gen;
- if (scavenge_one((P_)((StgMutVar *)p)->var) == rtsTrue) {
- /* didn't manage to promote everything, so leave the
- * MUT_CONS on the list.
- */
- prev = &p->mut_link;
- } else {
- *prev = p->mut_link;
- }
- evac_gen = 0;
- } else {
- ((StgMutVar *)p)->var = evacuate(((StgMutVar *)p)->var);
- prev = &p->mut_link;
- }
+ ASSERT(p->header.info != &MUT_CONS_info);
+ ((StgMutVar *)p)->var = evacuate(((StgMutVar *)p)->var);
+ prev = &p->mut_link;
continue;
case MVAR:
continue;
}
- case IND_OLDGEN:
- case IND_OLDGEN_PERM:
- case IND_STATIC:
- /* Try to pull the indirectee into this generation, so we can
- * remove the indirection from the mutable list.
- */
- evac_gen = gen;
- ((StgIndOldGen *)p)->indirectee =
- evacuate(((StgIndOldGen *)p)->indirectee);
- evac_gen = 0;
-
- if (failed_to_evac) {
- failed_to_evac = rtsFalse;
- prev = &p->mut_link;
- } else {
- *prev = p->mut_link;
- /* the mut_link field of an IND_STATIC is overloaded as the
- * static link field too (it just so happens that we don't need
- * both at the same time), so we need to NULL it out when
- * removing this object from the mutable list because the static
- * link fields are all assumed to be NULL before doing a major
- * collection.
- */
- p->mut_link = NULL;
- }
- continue;
-
case BLACKHOLE_BQ:
{
StgBlockingQueue *bh = (StgBlockingQueue *)p;
default:
/* shouldn't have anything else on the mutables list */
- barf("scavenge_mutable_object: non-mutable object?");
+ barf("scavenge_mut_list: strange object?");
}
}
return start;
if (failed_to_evac) {
failed_to_evac = rtsFalse;
scavenged_static_objects = STATIC_LINK(info,p);
- ((StgMutClosure *)ind)->mut_link = oldest_gen->mut_list;
- oldest_gen->mut_list = (StgMutClosure *)ind;
+ ((StgMutClosure *)ind)->mut_link = oldest_gen->mut_once_list;
+ oldest_gen->mut_once_list = (StgMutClosure *)ind;
}
break;
}
to = copy(frame->updatee, BLACKHOLE_sizeW(), step);
upd_evacuee(frame->updatee,to);
frame->updatee = to;
- evacuate_mutable((StgMutClosure *)to);
+ recordMutable((StgMutClosure *)to);
continue;
default:
barf("scavenge_stack: UPDATE_FRAME updatee");
}
evac_gen = 0;
if (failed_to_evac) {
- evacuate_mutable((StgMutClosure *)start);
+ recordMutable((StgMutClosure *)start);
}
continue;
}