X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FStable.c;h=0ed18bcec2c94992a7af8e7b6d7d4b186944b724;hb=5123ae93cfc5cdfcecc84340a9517580ad900d64;hp=a4db5cd749de174afa28a9a89b2b8d8d35fe8ed0;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1;p=ghc-hetmet.git diff --git a/rts/Stable.c b/rts/Stable.c index a4db5cd..0ed18bc 100644 --- a/rts/Stable.c +++ b/rts/Stable.c @@ -18,6 +18,8 @@ #include "RtsAPI.h" #include "RtsFlags.h" #include "OSThreads.h" +#include "Trace.h" +#include "Stable.h" /* Comment from ADR's implementation in old RTS: @@ -158,8 +160,26 @@ initStablePtrTable(void) #endif } +void +exitStablePtrTable(void) +{ + if (addrToStableHash) + freeHashTable(addrToStableHash, NULL); + addrToStableHash = NULL; + if (stable_ptr_table) + stgFree(stable_ptr_table); + stable_ptr_table = NULL; + SPT_size = 0; +#ifdef THREADED_RTS + closeMutex(&stable_mutex); +#endif +} + /* * get at the real stuff...remove indirections. + * It untags pointers before dereferencing and + * retags the real stuff with its tag (if there + * is any) when returning. * * ToDo: move to a better home. */ @@ -167,16 +187,18 @@ static StgClosure* removeIndirections(StgClosure* p) { - StgClosure* q = p; + StgWord tag = GET_CLOSURE_TAG(p); + StgClosure* q = UNTAG_CLOSURE(p); while (get_itbl(q)->type == IND || get_itbl(q)->type == IND_STATIC || get_itbl(q)->type == IND_OLDGEN || get_itbl(q)->type == IND_PERM || get_itbl(q)->type == IND_OLDGEN_PERM ) { - q = ((StgInd *)q)->indirectee; + tag = GET_CLOSURE_TAG(q); + q = UNTAG_CLOSURE(((StgInd *)q)->indirectee); } - return q; + return TAG_CLOSURE(tag,q); } static StgWord @@ -199,7 +221,7 @@ lookupStableName_(StgPtr p) if (sn != 0) { ASSERT(stable_ptr_table[sn].addr == p); - IF_DEBUG(stable,debugBelch("cached stable name %ld at %p\n",sn,p)); + debugTrace(DEBUG_stable, "cached stable name %ld at %p",sn,p); return sn; } else { sn = stable_ptr_free - stable_ptr_table; @@ -207,7 +229,7 @@ lookupStableName_(StgPtr p) stable_ptr_table[sn].ref = 0; stable_ptr_table[sn].addr = p; stable_ptr_table[sn].sn_obj = NULL; - /* IF_DEBUG(stable,debugBelch("new stable name %d at %p\n",sn,p)); */ + /* debugTrace(DEBUG_stable, "new stable name %d at %p\n",sn,p); */ /* add the new stable name to the hash table */ insertHashTable(addrToStableHash, (W_)p, (void *)sn); @@ -399,13 +421,15 @@ gcStablePtrTable( void ) if (p->sn_obj == NULL) { // StableName object is dead freeStableName(p); - IF_DEBUG(stable, debugBelch("GC'd Stable name %ld\n", - p - stable_ptr_table)); + debugTrace(DEBUG_stable, "GC'd Stable name %ld", + (long)(p - stable_ptr_table)); continue; } else { p->addr = (StgPtr)isAlive((StgClosure *)p->addr); - IF_DEBUG(stable, debugBelch("Stable name %ld still alive at %p, ref %ld\n", p - stable_ptr_table, p->addr, p->ref)); + debugTrace(DEBUG_stable, + "stable name %ld still alive at %p, ref %ld\n", + (long)(p - stable_ptr_table), p->addr, p->ref); } } }