X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fincludes%2FStable.h;h=cfe768f1f3e1765c01738430745c35cb48cf52f1;hb=195abb24fa1f5d3bf8fcb8252d0f0b00e6b4f8b7;hp=7ffa369d5fdd6182221732125c49b2279c31ba8c;hpb=f9a1e689ac9b5bfea3a4af406f59b7e46cbf1ffe;p=ghc-hetmet.git diff --git a/ghc/includes/Stable.h b/ghc/includes/Stable.h index 7ffa369..cfe768f 100644 --- a/ghc/includes/Stable.h +++ b/ghc/includes/Stable.h @@ -1,9 +1,21 @@ /* ----------------------------------------------------------------------------- - * $Id: Stable.h,v 1.1 1999/01/26 14:04:46 simonm Exp $ + * $Id: Stable.h,v 1.8 2001/07/23 17:23:19 simonmar Exp $ * - * Stable names and stable pointers + * (c) The GHC Team, 1998-2000 * - * ---------------------------------------------------------------------------*/ + * Stable Pointers: A stable pointer is represented as an index into + * the stable pointer table in the low BITS_PER_WORD-8 bits with a + * weight in the upper 8 bits. + * + * SUP: StgStablePtr used to be a synonym for StgWord, but stable pointers + * are guaranteed to be void* on the C-side, so we have to do some occasional + * casting. Size is not a matter, because StgWord is always the same size as + * a void*. + * + * ----------------------------------------------------------------------------*/ + +#define STABLEPTR_WEIGHT_MASK ((StgWord)0xff << ((sizeof(StgWord)-1) * BITS_PER_BYTE)) +#define STABLEPTR_WEIGHT_SHIFT (BITS_IN(StgWord) - 8) /* ----------------------------------------------------------------------------- External C Interface @@ -20,41 +32,43 @@ extern StgStablePtr splitStablePtr(StgStablePtr sp); extern StgStablePtr getStablePtr(StgPtr p); typedef struct { - StgPtr addr; /* either Haskell object or free list */ + StgPtr addr; /* Haskell object, free list, or NULL */ + StgPtr old; /* old Haskell object, used during GC */ StgWord weight; /* used for reference counting */ - unsigned int keep; /* set by the garbage collector */ + StgClosure *sn_obj; /* the StableName object (or NULL) */ } snEntry; -extern snEntry *stable_ptr_table; -extern snEntry *stable_ptr_free; +extern DLL_IMPORT_RTS snEntry *stable_ptr_table; +extern DLL_IMPORT_RTS snEntry *stable_ptr_free; -extern unsigned int SPT_size; +extern DLL_IMPORT_RTS unsigned int SPT_size; extern inline StgPtr deRefStablePtr(StgStablePtr sp) { - ASSERT(stable_ptr_table[sp & ~STABLEPTR_WEIGHT_MASK].weight > 0); - return stable_ptr_table[sp & ~STABLEPTR_WEIGHT_MASK].addr; + ASSERT(stable_ptr_table[stgCast(StgWord,sp) & ~STABLEPTR_WEIGHT_MASK].weight > 0); + return stable_ptr_table[stgCast(StgWord,sp) & ~STABLEPTR_WEIGHT_MASK].addr; } extern inline void freeStablePtr(StgStablePtr sp) { - StgWord sn = sp & ~STABLEPTR_WEIGHT_MASK; + StgWord sn = stgCast(StgWord,sp) & ~STABLEPTR_WEIGHT_MASK; ASSERT(sn < SPT_size && stable_ptr_table[sn].addr != NULL && stable_ptr_table[sn].weight > 0); - stable_ptr_table[sn].weight += (sp & STABLEPTR_WEIGHT_MASK) >> STABLEPTR_WEIGHT_SHIFT; + stable_ptr_table[sn].weight += + 1 << ((((StgWord)sp & STABLEPTR_WEIGHT_MASK) >> STABLEPTR_WEIGHT_SHIFT) - 1); } extern inline StgStablePtr splitStablePtr(StgStablePtr sp) { /* doesn't need access to the stable pointer table */ - StgWord weight = (sp & STABLEPTR_WEIGHT_MASK) / 2; - return (sp & ~STABLEPTR_WEIGHT_MASK) + weight; + StgWord weight = (stgCast(StgWord,sp) & STABLEPTR_WEIGHT_MASK) / 2; + return stgCast(StgStablePtr,(stgCast(StgWord,sp) & ~STABLEPTR_WEIGHT_MASK) + weight); } /* No deRefStableName, because the existence of a stable name doesn't