- // generation 0, step 0 doesn't need to-space
- if (g == 0 && s == 0 && RtsFlags.GcFlags.generations > 1) {
- continue;
- }
-
- // deprecate the existing blocks
- stp->old_blocks = stp->blocks;
- stp->n_old_blocks = stp->n_blocks;
- stp->blocks = NULL;
- stp->n_blocks = 0;
- stp->n_words = 0;
- stp->live_estimate = 0;
-
- // we don't have any to-be-scavenged blocks yet
- stp->todos = NULL;
- stp->todos_last = NULL;
- stp->n_todos = 0;
-
- // initialise the large object queues.
- stp->scavenged_large_objects = NULL;
- stp->n_scavenged_large_blocks = 0;
-
- // mark the small objects as from-space
- for (bd = stp->old_blocks; bd; bd = bd->link) {
- bd->flags &= ~BF_EVACUATED;
- }
-
- // mark the large objects as from-space
- for (bd = stp->large_objects; bd; bd = bd->link) {
- bd->flags &= ~BF_EVACUATED;
- }
-
- // for a compacted step, we need to allocate the bitmap
- if (stp->mark) {
- nat bitmap_size; // in bytes
- bdescr *bitmap_bdescr;
- StgWord *bitmap;
-
- bitmap_size = stp->n_old_blocks * BLOCK_SIZE / (sizeof(W_)*BITS_PER_BYTE);
-
- if (bitmap_size > 0) {
- bitmap_bdescr = allocGroup((lnat)BLOCK_ROUND_UP(bitmap_size)
- / BLOCK_SIZE);
- stp->bitmap = bitmap_bdescr;
- bitmap = bitmap_bdescr->start;
-
- debugTrace(DEBUG_gc, "bitmap_size: %d, bitmap: %p",
- bitmap_size, bitmap);
-
- // don't forget to fill it with zeros!
- memset(bitmap, 0, bitmap_size);
-
- // For each block in this step, point to its bitmap from the
- // block descriptor.
- for (bd=stp->old_blocks; bd != NULL; bd = bd->link) {
- bd->u.bitmap = bitmap;
- bitmap += BLOCK_SIZE_W / (sizeof(W_)*BITS_PER_BYTE);
-
- // Also at this point we set the BF_MARKED flag
- // for this block. The invariant is that
- // BF_MARKED is always unset, except during GC
- // when it is set on those blocks which will be
- // compacted.
- if (!(bd->flags & BF_FRAGMENTED)) {
- bd->flags |= BF_MARKED;
- }
- }
- }
- }
- }