[project @ 2005-07-25 13:59:09 by simonmar]
[ghc-hetmet.git] / ghc / rts / Storage.c
index 7e07ff2..f4e3bab 100644 (file)
@@ -71,13 +71,16 @@ initStep (step *stp, int g, int s)
 {
     stp->no = s;
     stp->blocks = NULL;
-    stp->n_to_blocks = 0;
     stp->n_blocks = 0;
+    stp->old_blocks = NULL;
+    stp->n_old_blocks = 0;
     stp->gen = &generations[g];
     stp->gen_no = g;
     stp->hp = NULL;
     stp->hpLim = NULL;
     stp->hp_bd = NULL;
+    stp->scavd_hp = NULL;
+    stp->scavd_hpLim = NULL;
     stp->scan = NULL;
     stp->scan_bd = NULL;
     stp->large_objects = NULL;
@@ -427,8 +430,8 @@ allocNurseries( void )
            allocNursery(&nurseries[i], NULL, 
                         RtsFlags.GcFlags.minAllocAreaSize);
        nurseries[i].n_blocks    = RtsFlags.GcFlags.minAllocAreaSize;
-       nurseries[i].to_blocks   = NULL;
-       nurseries[i].n_to_blocks = 0;
+       nurseries[i].old_blocks   = NULL;
+       nurseries[i].n_old_blocks = 0;
        /* hp, hpLim, hp_bd, to_space etc. aren't used in the nursery */
     }
     assignNurseriesToCapabilities();
@@ -662,7 +665,7 @@ allocateLocal( StgRegTable *reg, nat n )
                // full: allocate a fresh block (we can't fail here).
                ACQUIRE_SM_LOCK;
                bd = allocBlock();
-               alloc_blocks++;
+               reg->rNursery->n_blocks++;
                RELEASE_SM_LOCK;
                bd->gen_no = 0;
                bd->step = g0s0;
@@ -672,11 +675,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;
+               }
            }
-           bd->link = reg->rNursery->blocks;
-           reg->rNursery->blocks = bd;
-           bd->u.back = NULL;
+           dbl_link_onto(bd, &reg->rNursery->blocks);
            reg->rCurrentAlloc = bd;
+           IF_DEBUG(sanity, checkNurserySanity(reg->rNursery));
        }
     }
     p = bd->free;
@@ -822,12 +827,13 @@ calcAllocated( void )
 {
   nat allocated;
   bdescr *bd;
-  nat i;
 
   allocated = allocated_bytes();
   allocated += countNurseryBlocks() * BLOCK_SIZE_W;
   
+  {
 #ifdef SMP
+  nat i;
   for (i = 0; i < n_nurseries; i++) {
       Capability *cap;
       for ( bd = capabilities[i].r.rCurrentNursery->link; 
@@ -852,6 +858,7 @@ calcAllocated( void )
          - current_nursery->free;
   }
 #endif
+  }
 
   total_allocated += allocated;
   return allocated;
@@ -868,7 +875,7 @@ calcLive(void)
   step *stp;
 
   if (RtsFlags.GcFlags.generations == 1) {
-    live = (g0s0->n_to_blocks - 1) * BLOCK_SIZE_W + 
+    live = (g0s0->n_blocks - 1) * BLOCK_SIZE_W + 
       ((lnat)g0s0->hp_bd->free - (lnat)g0s0->hp_bd->start) / sizeof(W_);
     return live;
   }
@@ -887,6 +894,9 @@ calcLive(void)
          live += ((lnat)stp->hp_bd->free - (lnat)stp->hp_bd->start) 
              / sizeof(W_);
       }
+      if (stp->scavd_hp != NULL) {
+         live -= (P_)(BLOCK_ROUND_UP(stp->scavd_hp)) - stp->scavd_hp;
+      }
     }
   }
   return live;
@@ -981,7 +991,7 @@ memInventory(void)
 
   if (RtsFlags.GcFlags.generations == 1) {
       /* two-space collector has a to-space too :-) */
-      total_blocks += g0s0->n_to_blocks;
+      total_blocks += g0s0->n_old_blocks;
   }
 
   /* any blocks held by allocate() */
@@ -1029,7 +1039,7 @@ checkSanity( void )
     nat g, s;
 
     if (RtsFlags.GcFlags.generations == 1) {
-       checkHeap(g0s0->to_blocks);
+       checkHeap(g0s0->blocks);
        checkChain(g0s0->large_objects);
     } else {
        
@@ -1059,6 +1069,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 );