1 /* -----------------------------------------------------------------------------
2 * $Id: StgStorage.h,v 1.7 2000/04/11 16:36:53 sewardj Exp $
4 * (c) The GHC Team, 1998-1999
6 * STG Storage Manager Interface
8 * ---------------------------------------------------------------------------*/
13 /* GENERATION GC NOTES
15 * We support an arbitrary number of generations, with an arbitrary number
16 * of steps per generation. Notes (in no particular order):
18 * - all generations except the oldest should have two steps. This gives
19 * objects a decent chance to age before being promoted, and in
20 * particular will ensure that we don't end up with too many
21 * thunks being updated in older generations.
23 * - the oldest generation has one step. There's no point in aging
24 * objects in the oldest generation.
26 * - generation 0, step 0 (G0S0) is the allocation area. It is given
27 * a fixed set of blocks during initialisation, and these blocks
30 * - during garbage collection, each step which is an evacuation
31 * destination (i.e. all steps except G0S0) is allocated a to-space.
32 * evacuated objects are allocated into the step's to-space until
33 * GC is finished, when the original step's contents may be freed
34 * and replaced by the to-space.
36 * - the mutable-list is per-generation (not per-step). G0 doesn't
37 * have one (since every garbage collection collects at least G0).
39 * - block descriptors contain pointers to both the step and the
40 * generation that the block belongs to, for convenience.
42 * - static objects are stored in per-generation lists. See GC.c for
43 * details of how we collect CAFs in the generational scheme.
45 * - large objects are per-step, and are promoted in the same way
46 * as small objects, except that we may allocate large objects into
47 * generation 1 initially.
50 typedef struct _step {
51 unsigned int no; /* step number */
52 bdescr *blocks; /* blocks in this step */
53 unsigned int n_blocks; /* number of blocks */
54 struct _step *to; /* where collected objects from this step go */
55 struct _generation *gen; /* generation this step belongs to */
56 bdescr *large_objects; /* large objects (doubly linked) */
58 /* temporary use during GC: */
59 StgPtr hp; /* next free locn in to-space */
60 StgPtr hpLim; /* end of current to-space block */
61 bdescr *hp_bd; /* bdescr of current to-space block */
62 bdescr *to_space; /* bdescr of first to-space block */
63 unsigned int to_blocks; /* number of blocks in to-space */
64 bdescr *scan_bd; /* block currently being scanned */
65 StgPtr scan; /* scan pointer in current block */
66 bdescr *new_large_objects; /* large objects collected so far */
67 bdescr *scavenged_large_objects; /* live large objects after GC (dbl link) */
70 typedef struct _generation {
71 unsigned int no; /* generation number */
72 step *steps; /* steps */
73 unsigned int n_steps; /* number of steps */
74 unsigned int max_blocks; /* max blocks in step 0 */
75 StgMutClosure *mut_list; /* mutable objects in this generation (not G0)*/
76 StgMutClosure *mut_once_list; /* objects that point to younger generations */
78 /* temporary use during GC: */
79 StgMutClosure *saved_mut_list;
81 /* stats information */
82 unsigned int collections;
83 unsigned int failed_promotions;
86 /* -----------------------------------------------------------------------------
87 Allocation area for compiled code
89 OpenNursery(hp,hplim) Opens the allocation area, and sets hp
90 and hplim appropriately.
92 CloseNursery(hp) Closes the allocation area.
94 PleaseStopAllocating(void) Arranges that the next call to
95 ExtendNursery() will fail, triggering
96 a return to the scheduler. This is
97 useful for asynchronous interupts etc.
98 -------------------------------------------------------------------------- */
100 #define OpenNursery(hp,hplim) \
101 (hp = CurrentNursery->free-1, \
102 hplim = CurrentNursery->start + BLOCK_SIZE_W - 1)
104 #define CloseNursery(hp) (CurrentNursery->free = (P_)(hp)+1)
106 /* -----------------------------------------------------------------------------
107 Trigger a GC from Haskell land.
108 -------------------------------------------------------------------------- */
110 extern void performGC(void);
111 extern void performMajorGC(void);
112 extern void performGCWithRoots(void (*get_roots)(void));
114 #endif /* STGSTORAGE_H */