X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fincludes%2FBlock.h;h=d1705ad68650afddb9451d415d6f3d3db1c9a0b8;hb=28a464a75e14cece5db40f2765a29348273ff2d2;hp=867a73c448dddf066d69cca9f7376650508f92ce;hpb=34beae430c25634b06ee3652e64c0e5f02a3ff8e;p=ghc-hetmet.git diff --git a/ghc/includes/Block.h b/ghc/includes/Block.h index 867a73c..d1705ad 100644 --- a/ghc/includes/Block.h +++ b/ghc/includes/Block.h @@ -1,5 +1,4 @@ /* ----------------------------------------------------------------------------- - * $Id: Block.h,v 1.13 2003/03/28 15:13:52 sof Exp $ * * (c) The GHC Team, 1998-1999 * @@ -47,16 +46,17 @@ * on a 32-bit machine. */ -typedef struct _bdescr { +#ifndef CMINUSMINUS +typedef struct bdescr_ { StgPtr start; /* start addr of memory */ StgPtr free; /* first free byte of memory */ - struct _bdescr *link; /* used for chaining blocks together */ + struct bdescr_ *link; /* used for chaining blocks together */ union { - struct _bdescr *back; /* used (occasionally) for doubly-linked lists*/ + struct bdescr_ *back; /* used (occasionally) for doubly-linked lists*/ StgWord *bitmap; } u; unsigned int gen_no; /* generation */ - struct _step *step; /* step */ + struct step_ *step; /* step */ StgWord32 blocks; /* no. of blocks (if grp head, 0 otherwise) */ StgWord32 flags; /* block is in to-space */ #if SIZEOF_VOID_P == 8 @@ -65,6 +65,7 @@ typedef struct _bdescr { StgWord32 _padding[0]; #endif } bdescr; +#endif #if SIZEOF_VOID_P == 8 #define BDESCR_SIZE 0x40 @@ -76,12 +77,28 @@ typedef struct _bdescr { #define BDESCR_SHIFT 5 #endif +/* Block contains objects evacuated during this GC */ #define BF_EVACUATED 1 +/* Block is a large object */ #define BF_LARGE 2 +/* Block is pinned */ +#define BF_PINNED 4 +/* Block is part of a compacted generation */ +#define BF_COMPACTED 8 +/* Block is free, and on the free list */ +#define BF_FREE 16 /* Finding the block descriptor for a given block -------------------------- */ -static inline bdescr *Bdescr(StgPtr p) +#ifdef CMINUSMINUS + +#define Bdescr(p) \ + ((((p) & MBLOCK_MASK & ~BLOCK_MASK) >> (BLOCK_SHIFT-BDESCR_SHIFT)) \ + | ((p) & ~MBLOCK_MASK)) + +#else + +INLINE_HEADER bdescr *Bdescr(StgPtr p) { return (bdescr *) ((((W_)p & MBLOCK_MASK & ~BLOCK_MASK) >> (BLOCK_SHIFT-BDESCR_SHIFT)) @@ -89,6 +106,8 @@ static inline bdescr *Bdescr(StgPtr p) ); } +#endif + /* Useful Macros ------------------------------------------------------------ */ /* Offset of first real data block in a megablock */ @@ -123,4 +142,61 @@ static inline bdescr *Bdescr(StgPtr p) #define BLOCKS_TO_MBLOCKS(n) \ (1 + (W_)MBLOCK_ROUND_UP((n-BLOCKS_PER_MBLOCK) * BLOCK_SIZE) / MBLOCK_SIZE) + +#ifndef CMINUSMINUS +/* to the end... */ + +/* Double-linked block lists: --------------------------------------------- */ + +INLINE_HEADER void +dbl_link_onto(bdescr *bd, bdescr **list) +{ + bd->link = *list; + bd->u.back = NULL; + if (*list) { + (*list)->u.back = bd; /* double-link the list */ + } + *list = bd; +} + +/* Initialisation ---------------------------------------------------------- */ + +extern void initBlockAllocator(void); + +/* Allocation -------------------------------------------------------------- */ + +bdescr *allocGroup(nat n); +bdescr *allocBlock(void); + +// versions that take the storage manager lock for you: +bdescr *allocGroup_lock(nat n); +bdescr *allocBlock_lock(void); + +/* De-Allocation ----------------------------------------------------------- */ + +void freeGroup(bdescr *p); +void freeChain(bdescr *p); + +// versions that take the storage manager lock for you: +void freeGroup_lock(bdescr *p); +void freeChain_lock(bdescr *p); + +/* Round a value to megablocks --------------------------------------------- */ + +#define WORDS_PER_MBLOCK (BLOCKS_PER_MBLOCK * BLOCK_SIZE_W) + +INLINE_HEADER nat +round_to_mblocks(nat words) +{ + if (words > WORDS_PER_MBLOCK) { + if ((words % WORDS_PER_MBLOCK) < (WORDS_PER_MBLOCK / 2)) { + words = (words / WORDS_PER_MBLOCK) * WORDS_PER_MBLOCK; + } else { + words = ((words / WORDS_PER_MBLOCK) + 1) * WORDS_PER_MBLOCK; + } + } + return words; +} + +#endif /* !CMINUSMINUS */ #endif /* BLOCK_H */