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 * ---------------------------------------------------------------------------*/
10 #include "PosixSource.h"
17 #include "Capability.h"
20 // DO NOT include "GCThread.h", we don't want the register variable
22 /* -----------------------------------------------------------------------------
23 isAlive determines whether the given closure is still alive (after
24 a garbage collection) or not. It returns the new address of the
25 closure if it is alive, or NULL otherwise.
27 NOTE: Use it before compaction only!
28 It untags and (if needed) retags pointers to closures.
29 -------------------------------------------------------------------------- */
32 isAlive(StgClosure *p)
34 const StgInfoTable *info;
40 /* The tag and the pointer are split, to be merged later when needed. */
41 tag = GET_CLOSURE_TAG(p);
44 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_GC(q)) {
56 // ignore closures in generations that we're not collecting.
59 // if it's a pointer into to-space, then we're done
60 if (bd->flags & BF_EVACUATED) {
64 // large objects use the evacuated flag
65 if (bd->flags & BF_LARGE) {
66 if (get_itbl(q)->type == TSO &&
67 ((StgTSO *)p)->what_next == ThreadRelocated) {
68 p = (StgClosure *)((StgTSO *)p)->_link;
74 // check the mark bit for compacted steps
75 if ((bd->flags & BF_MARKED) && is_marked((P_)q,bd)) {
79 info = q->header.info;
81 if (IS_FORWARDING_PTR(info)) {
83 return (StgClosure*)UN_FORWARDING_PTR(info);
86 info = INFO_PTR_TO_STRUCT(info);
93 case IND_OLDGEN: // rely on compatible layout with StgInd
95 // follow indirections
96 p = ((StgInd *)q)->indirectee;
100 if (((StgTSO *)q)->what_next == ThreadRelocated) {
101 p = (StgClosure *)((StgTSO *)q)->_link;
113 /* -----------------------------------------------------------------------------
115 -------------------------------------------------------------------------- */
122 for (c = (StgIndStatic *)revertible_caf_list;
123 c != (StgIndStatic *)END_OF_STATIC_LIST;
124 c = (StgIndStatic *)c->static_link)
126 SET_INFO(c, c->saved_info);
127 c->saved_info = NULL;
128 // could, but not necessary: c->static_link = NULL;
130 revertible_caf_list = END_OF_STATIC_LIST;
134 markCAFs (evac_fn evac, void *user)
138 for (c = (StgIndStatic *)caf_list;
139 c != (StgIndStatic*)END_OF_STATIC_LIST;
140 c = (StgIndStatic *)c->static_link)
142 evac(user, &c->indirectee);
144 for (c = (StgIndStatic *)revertible_caf_list;
145 c != (StgIndStatic*)END_OF_STATIC_LIST;
146 c = (StgIndStatic *)c->static_link)
148 evac(user, &c->indirectee);