Split GC.c, and move storage manager into sm/ directory
[ghc-hetmet.git] / rts / sm / GCUtils.c
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team 1998-2006
4  *
5  * Generational garbage collector: utilities
6  *
7  * ---------------------------------------------------------------------------*/
8
9 #include "Rts.h"
10 #include "Storage.h"
11 #include "GC.h"
12 #include "GCUtils.h"
13
14 /* -----------------------------------------------------------------------------
15    Allocate a new to-space block in the given step.
16    -------------------------------------------------------------------------- */
17
18 bdescr *
19 gc_alloc_block(step *stp)
20 {
21     bdescr *bd = allocBlock();
22     bd->gen_no = stp->gen_no;
23     bd->step = stp;
24     bd->link = NULL;
25
26     // blocks in to-space in generations up to and including N
27     // get the BF_EVACUATED flag.
28     if (stp->gen_no <= N) {
29         bd->flags = BF_EVACUATED;
30     } else {
31         bd->flags = 0;
32     }
33
34     // Start a new to-space block, chain it on after the previous one.
35     if (stp->hp_bd != NULL) {
36         stp->hp_bd->free = stp->hp;
37         stp->hp_bd->link = bd;
38     }
39
40     stp->hp_bd = bd;
41     stp->hp    = bd->start;
42     stp->hpLim = stp->hp + BLOCK_SIZE_W;
43
44     stp->n_blocks++;
45     new_blocks++;
46
47     return bd;
48 }
49
50 bdescr *
51 gc_alloc_scavd_block(step *stp)
52 {
53     bdescr *bd = allocBlock();
54     bd->gen_no = stp->gen_no;
55     bd->step = stp;
56
57     // blocks in to-space in generations up to and including N
58     // get the BF_EVACUATED flag.
59     if (stp->gen_no <= N) {
60         bd->flags = BF_EVACUATED;
61     } else {
62         bd->flags = 0;
63     }
64
65     bd->link = stp->blocks;
66     stp->blocks = bd;
67
68     if (stp->scavd_hp != NULL) {
69         Bdescr(stp->scavd_hp)->free = stp->scavd_hp;
70     }
71     stp->scavd_hp    = bd->start;
72     stp->scavd_hpLim = stp->scavd_hp + BLOCK_SIZE_W;
73
74     stp->n_blocks++;
75     new_scavd_blocks++;
76
77     return bd;
78 }
79