X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FStable.c;h=a2829c6341b6508b66b1b5b49b46c4734ff330dc;hb=4ab216140652b1ebdc011bba06f77cd05c614b91;hp=72b3a98c7b006d309d81dd18915d3b12cd74485e;hpb=f74458a707d766e7b9b04db7d27cb3f697100e4f;p=ghc-hetmet.git diff --git a/ghc/rts/Stable.c b/ghc/rts/Stable.c index 72b3a98..a2829c6 100644 --- a/ghc/rts/Stable.c +++ b/ghc/rts/Stable.c @@ -1,5 +1,4 @@ /* ----------------------------------------------------------------------------- - * $Id: Stable.c,v 1.25 2003/03/31 19:19:34 sof Exp $ * * (c) The GHC Team, 1998-2002 * @@ -13,8 +12,8 @@ #include "PosixSource.h" #include "Rts.h" #include "Hash.h" -#include "StablePriv.h" #include "RtsUtils.h" +#include "OSThreads.h" #include "Storage.h" #include "RtsAPI.h" #include "RtsFlags.h" @@ -73,21 +72,6 @@ There may be additional functions on the C side to allow evaluation, application, etc of a stable pointer. - When Haskell calls C, it normally just passes over primitive integers, - floats, bools, strings, etc. This doesn't cause any problems at all - for garbage collection because the act of passing them makes a copy - from the heap, stack or wherever they are onto the C-world stack. - However, if we were to pass a heap object such as a (Haskell) @String@ - and a garbage collection occured before we finished using it, we'd run - into problems since the heap object might have been moved or even - deleted. - - So, if a C call is able to cause a garbage collection or we want to - store a pointer to a heap object between C calls, we must be careful - when passing heap objects. Our solution is to keep a table of all - objects we've given to the C-world and to make sure that the garbage - collector collects these objects --- updating the table as required to - make sure we can still find the object. */ snEntry *stable_ptr_table = NULL; @@ -132,7 +116,7 @@ static HashTable *addrToStableHash = NULL; #define INIT_SPT_SIZE 64 -static inline void +STATIC_INLINE void initFreeList(snEntry *table, nat n, snEntry *free) { snEntry *p; @@ -153,6 +137,9 @@ initStablePtrTable(void) // Nothing to do: // the table will be allocated the first time makeStablePtr is // called, and we want the table to persist through multiple inits. + // + // Also, getStablePtr is now called from __attribute__((constructor)) + // functions, so initialising things here wouldn't work anyway. } /* @@ -180,6 +167,7 @@ StgWord lookupStableName(StgPtr p) { StgWord sn; + void* sn_tmp; if (stable_ptr_free == NULL) { enlargeStablePtrTable(); @@ -190,20 +178,20 @@ lookupStableName(StgPtr p) */ p = (StgPtr)removeIndirections((StgClosure*)p); - (void *)sn = lookupHashTable(addrToStableHash,(W_)p); + sn_tmp = lookupHashTable(addrToStableHash,(W_)p); + sn = (StgWord)sn_tmp; if (sn != 0) { ASSERT(stable_ptr_table[sn].addr == p); - IF_DEBUG(stable,fprintf(stderr,"cached stable name %d at %p\n",sn,p)); + IF_DEBUG(stable,debugBelch("cached stable name %ld at %p\n",sn,p)); return sn; } else { sn = stable_ptr_free - stable_ptr_table; - (P_)stable_ptr_free = stable_ptr_free->addr; + stable_ptr_free = (snEntry*)(stable_ptr_free->addr); stable_ptr_table[sn].ref = 0; stable_ptr_table[sn].addr = p; stable_ptr_table[sn].sn_obj = NULL; - /* IF_DEBUG(stable,fprintf(stderr,"new stable name %d at - %p\n",sn,p)); */ + /* IF_DEBUG(stable,debugBelch("new stable name %d at %p\n",sn,p)); */ /* add the new stable name to the hash table */ insertHashTable(addrToStableHash, (W_)p, (void *)sn); @@ -212,7 +200,7 @@ lookupStableName(StgPtr p) } } -static inline void +STATIC_INLINE void freeStableName(snEntry *sn) { ASSERT(sn->sn_obj == NULL); @@ -388,13 +376,13 @@ gcStablePtrTable( void ) if (p->sn_obj == NULL) { // StableName object is dead freeStableName(p); - IF_DEBUG(stable, fprintf(stderr,"GC'd Stable name %d\n", - p - stable_ptr_table)); + IF_DEBUG(stable, debugBelch("GC'd Stable name %ld\n", + p - stable_ptr_table)); continue; } else { - (StgClosure *)p->addr = isAlive((StgClosure *)p->addr); - IF_DEBUG(stable, fprintf(stderr,"Stable name %d still alive at %p, ref %d\n", p - stable_ptr_table, p->addr, p->ref)); + 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)); } } }