X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=ghc%2Frts%2FBlockAlloc.c;h=8e09d0cc5ccdbf2a1b22b4ee4619cf613f08b812;hb=324e96d2ebfcb113cd97c43ef043d591ef87de71;hp=220928520ed8f264a0d122518d8420511014bfb2;hpb=18b3cd979a185d02c88df1de61814ed808c62010;p=ghc-hetmet.git diff --git a/ghc/rts/BlockAlloc.c b/ghc/rts/BlockAlloc.c index 2209285..8e09d0c 100644 --- a/ghc/rts/BlockAlloc.c +++ b/ghc/rts/BlockAlloc.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: BlockAlloc.c,v 1.11 2001/11/08 10:18:49 simonmar Exp $ + * $Id: BlockAlloc.c,v 1.16 2003/02/18 05:47:53 sof Exp $ * * (c) The GHC Team 1998-2000 * @@ -23,11 +23,13 @@ #include "BlockAlloc.h" #include "MBlock.h" +#include + static void initMBlock(void *mblock); static bdescr *allocMegaGroup(nat mblocks); static void freeMegaGroup(bdescr *bd); -static bdescr *free_list; +static bdescr *free_list = NULL; /* ----------------------------------------------------------------------------- Initialisation @@ -35,7 +37,7 @@ static bdescr *free_list; void initBlockAllocator(void) { - free_list = NULL; + // The free list starts off NULL } /* ----------------------------------------------------------------------------- @@ -196,15 +198,17 @@ static inline bdescr * coalesce(bdescr *p) { bdescr *bd, *q; - nat i; + nat i, blocks; q = p->link; if (q != NULL && p->start + p->blocks * BLOCK_SIZE_W == q->start) { /* can coalesce */ p->blocks += q->blocks; p->link = q->link; - for (i = 0, bd = q; i < q->blocks; bd++, i++) { + blocks = q->blocks; + for (i = 0, bd = q; i < blocks; bd++, i++) { bd->free = 0; + bd->blocks = 0; bd->link = p; } return p; @@ -261,7 +265,7 @@ freeMegaGroup(bdescr *p) n = p->blocks * BLOCK_SIZE / MBLOCK_SIZE + 1; for (; n > 0; (W_)p += MBLOCK_SIZE, n--) { - initMBlock((void *)((W_)p & ~MBLOCK_MASK)); + initMBlock(MBLOCK_ROUND_DOWN(p)); initGroup(BLOCKS_PER_MBLOCK, p); freeGroup(p); } @@ -302,6 +306,18 @@ initMBlock(void *mblock) -------------------------------------------------------------------------- */ #ifdef DEBUG +static void +checkWellFormedGroup( bdescr *bd ) +{ + nat i; + + for (i = 1; i < bd->blocks; i++) { + ASSERT(bd[i].blocks == 0); + ASSERT(bd[i].free == 0); + ASSERT(bd[i].link == bd); + } +} + void checkFreeListSanity(void) { @@ -312,6 +328,7 @@ checkFreeListSanity(void) fprintf(stderr,"group at 0x%x, length %d blocks\n", (nat)bd->start, bd->blocks)); ASSERT(bd->blocks > 0); + checkWellFormedGroup(bd); if (bd->link != NULL) { /* make sure we're fully coalesced */ ASSERT(bd->start + bd->blocks * BLOCK_SIZE_W != bd->link->start);