[project @ 2005-05-12 11:36:50 by stolz]
[ghc-hetmet.git] / ghc / rts / Storage.c
index 99d36d2..7bb6e39 100644 (file)
@@ -672,9 +672,13 @@ allocateLocal( StgRegTable *reg, nat n )
                // it at the *front* of the nursery list, and use it
                // to allocate() from.
                reg->rCurrentNursery->link = bd->link;
+               if (bd->link != NULL) {
+                   bd->link->u.back = reg->rCurrentNursery;
+               }
            }
            dbl_link_onto(bd, &reg->rNursery->blocks);
            reg->rCurrentAlloc = bd;
+           IF_DEBUG(sanity, checkNurserySanity(reg->rNursery));
        }
     }
     p = bd->free;
@@ -824,6 +828,7 @@ calcAllocated( void )
   allocated = allocated_bytes();
   allocated += countNurseryBlocks() * BLOCK_SIZE_W;
   
+  {
 #ifdef SMP
   nat i;
   for (i = 0; i < n_nurseries; i++) {
@@ -850,6 +855,7 @@ calcAllocated( void )
          - current_nursery->free;
   }
 #endif
+  }
 
   total_allocated += allocated;
   return allocated;
@@ -1057,6 +1063,22 @@ checkSanity( void )
     }
 }
 
+/* Nursery sanity check */
+void
+checkNurserySanity( step *stp )
+{
+    bdescr *bd, *prev;
+    nat blocks = 0;
+
+    prev = NULL;
+    for (bd = stp->blocks; bd != NULL; bd = bd->link) {
+       ASSERT(bd->u.back == prev);
+       prev = bd;
+       blocks += bd->blocks;
+    }
+    ASSERT(blocks == stp->n_blocks);
+}
+
 // handy function for use in gdb, because Bdescr() is inlined.
 extern bdescr *_bdescr( StgPtr p );