X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=rts%2Fsm%2FStorage.c;h=0bc15c075e6d8732843163acd84bcdb1504dcd1c;hb=1231d33279f25e931bcac1bac046b0f839290d61;hp=c441826a147769172c308eda4e928cc76f39eeab;hpb=c357244371ca5eeaa0d56a6bd349e26a3b16b7dc;p=ghc-hetmet.git diff --git a/rts/sm/Storage.c b/rts/sm/Storage.c index c441826..0bc15c0 100644 --- a/rts/sm/Storage.c +++ b/rts/sm/Storage.c @@ -918,15 +918,15 @@ calcAllocated( void ) /* Approximate the amount of live data in the heap. To be called just * after garbage collection (see GarbageCollect()). */ -extern lnat -calcLive(void) +lnat +calcLiveBlocks(void) { nat g, s; lnat live = 0; step *stp; if (RtsFlags.GcFlags.generations == 1) { - return (g0s0->n_large_blocks + g0s0->n_blocks) * BLOCK_SIZE_W; + return g0s0->n_large_blocks + g0s0->n_blocks; } for (g = 0; g < RtsFlags.GcFlags.generations; g++) { @@ -938,12 +938,49 @@ calcLive(void) continue; } stp = &generations[g].steps[s]; - live += (stp->n_large_blocks + stp->n_blocks) * BLOCK_SIZE_W; + live += stp->n_large_blocks + stp->n_blocks; } } return live; } +lnat +countOccupied(bdescr *bd) +{ + lnat words; + + words = 0; + for (; bd != NULL; bd = bd->link) { + words += bd->free - bd->start; + } + return words; +} + +// Return an accurate count of the live data in the heap, excluding +// generation 0. +lnat +calcLiveWords(void) +{ + nat g, s; + lnat live; + step *stp; + + if (RtsFlags.GcFlags.generations == 1) { + return countOccupied(g0s0->blocks) + countOccupied(g0s0->large_objects); + } + + live = 0; + for (g = 0; g < RtsFlags.GcFlags.generations; g++) { + for (s = 0; s < generations[g].n_steps; s++) { + if (g == 0 && s == 0) continue; + stp = &generations[g].steps[s]; + live += countOccupied(stp->blocks) + + countOccupied(stp->large_objects); + } + } + return live; +} + /* Approximate the number of blocks that will be needed at the next * garbage collection. * @@ -966,9 +1003,9 @@ calcNeeded(void) generations[g].steps[0].n_large_blocks > generations[g].max_blocks && stp->is_compacted == 0) { - needed += 2 * stp->n_blocks; + needed += 2 * stp->n_blocks + stp->n_large_blocks; } else { - needed += stp->n_blocks; + needed += stp->n_blocks + stp->n_large_blocks; } } } @@ -1080,6 +1117,21 @@ void freeExec (void *addr) #ifdef DEBUG +// Useful for finding partially full blocks in gdb +void findSlop(bdescr *bd); +void findSlop(bdescr *bd) +{ + lnat slop; + + for (; bd != NULL; bd = bd->link) { + slop = (bd->blocks * BLOCK_SIZE_W) - (bd->free - bd->start); + if (slop > (1024/sizeof(W_))) { + debugBelch("block at %p (bdescr %p) has %ldKB slop\n", + bd->start, bd, slop / (1024/sizeof(W_))); + } + } +} + nat countBlocks(bdescr *bd) {