1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team 1998-2008
5 * Functions called from outside the GC need to be separate from GC.c,
6 * because GC.c is compiled with register variable(s).
8 * ---------------------------------------------------------------------------*/
16 #include "Capability.h"
19 // DO NOT include "GCThread.h", we don't want the register variable
21 /* -----------------------------------------------------------------------------
22 isAlive determines whether the given closure is still alive (after
23 a garbage collection) or not. It returns the new address of the
24 closure if it is alive, or NULL otherwise.
26 NOTE: Use it before compaction only!
27 It untags and (if needed) retags pointers to closures.
28 -------------------------------------------------------------------------- */
31 isAlive(StgClosure *p)
33 const StgInfoTable *info;
39 /* The tag and the pointer are split, to be merged later when needed. */
40 tag = GET_CLOSURE_TAG(p);
43 ASSERT(LOOKS_LIKE_CLOSURE_PTR(q));
46 // ignore static closures
48 // ToDo: for static closures, check the static link field.
49 // Problem here is that we sometimes don't set the link field, eg.
50 // for static closures with an empty SRT or CONSTR_STATIC_NOCAFs.
52 if (!HEAP_ALLOCED(q)) {
56 // ignore closures in generations that we're not collecting.
62 // if it's a pointer into to-space, then we're done
63 if (bd->flags & BF_EVACUATED) {
67 // large objects use the evacuated flag
68 if (bd->flags & BF_LARGE) {
72 // check the mark bit for compacted steps
73 if ((bd->flags & BF_COMPACTED) && is_marked((P_)q,bd)) {
82 case IND_OLDGEN: // rely on compatible layout with StgInd
84 // follow indirections
85 p = ((StgInd *)q)->indirectee;
90 return ((StgEvacuated *)q)->evacuee;
93 if (((StgTSO *)q)->what_next == ThreadRelocated) {
94 p = (StgClosure *)((StgTSO *)q)->link;
106 /* -----------------------------------------------------------------------------
108 -------------------------------------------------------------------------- */
115 for (c = (StgIndStatic *)revertible_caf_list; c != NULL;
116 c = (StgIndStatic *)c->static_link)
118 SET_INFO(c, c->saved_info);
119 c->saved_info = NULL;
120 // could, but not necessary: c->static_link = NULL;
122 revertible_caf_list = NULL;
126 markCAFs (evac_fn evac, void *user)
130 for (c = (StgIndStatic *)caf_list; c != NULL;
131 c = (StgIndStatic *)c->static_link)
133 evac(user, &c->indirectee);
135 for (c = (StgIndStatic *)revertible_caf_list; c != NULL;
136 c = (StgIndStatic *)c->static_link)
138 evac(user, &c->indirectee);