1 /* -----------------------------------------------------------------------------
2 * $Id: Storage.h,v 1.9 1999/05/11 16:47:59 keithw Exp $
4 * (c) The GHC Team, 1998-1999
6 * External Storage Manger Interface
8 * ---------------------------------------------------------------------------*/
14 #include "BlockAlloc.h"
15 #include "StoragePriv.h"
17 /* -----------------------------------------------------------------------------
18 Initialisation / De-initialisation
19 -------------------------------------------------------------------------- */
21 extern void initStorage(void);
22 extern void exitStorage(void);
24 /* -----------------------------------------------------------------------------
27 StgPtr allocate(int n) Allocates a chunk of contiguous store
28 n words long, returning a pointer to
29 the first word. Always succeeds.
31 Don't forget to TICK_ALLOC_XXX(...)
32 after calling allocate, for the
33 benefit of the ticky-ticky profiler.
35 rtsBool doYouWantToGC(void) Returns True if the storage manager is
36 ready to perform a GC, False otherwise.
38 lnat allocated_bytes(void) Returns the number of bytes allocated
39 via allocate() since the last GC.
40 Used in the reoprting of statistics.
41 -------------------------------------------------------------------------- */
43 extern StgPtr allocate(nat n);
44 static inline rtsBool doYouWantToGC(void)
46 return (alloc_blocks >= alloc_blocks_lim);
48 extern lnat allocated_bytes(void);
50 /* -----------------------------------------------------------------------------
51 ExtendNursery(hp,hplim) When hplim is reached, try to grab
52 some more allocation space. Returns
53 False if the allocation space is
54 exhausted, and the application should
55 call GarbageCollect().
56 -------------------------------------------------------------------------- */
58 #define ExtendNursery(hp,hplim) \
59 (current_nursery->free = (P_)(hp)+1, \
60 current_nursery->link == NULL ? rtsFalse : \
61 (current_nursery = current_nursery->link, \
62 OpenNursery(hp,hplim), \
65 extern void PleaseStopAllocating(void);
67 /* -----------------------------------------------------------------------------
68 Performing Garbage Collection
70 GarbageCollect(get_roots) Performs a garbage collection.
71 'get_roots' is called to find all the
72 roots that the system knows about.
74 StgClosure Called by get_roots on each root.
75 MarkRoot(StgClosure *p) Returns the new location of the root.
76 -------------------------------------------------------------------------- */
78 extern void GarbageCollect(void (*get_roots)(void));
79 extern StgClosure *MarkRoot(StgClosure *p);
81 /* -----------------------------------------------------------------------------
82 Generational garbage collection support
84 recordMutable(StgPtr p) Informs the garbage collector that a
85 previously immutable object has
86 become (permanently) mutable. Used
87 by thawArray and similar.
89 updateWithIndirection(p1,p2) Updates the object at p1 with an
90 indirection pointing to p2. This is
91 normally called for objects in an old
92 generation (>0) when they are updated.
94 updateWithPermIndirection(p1,p2) As above but uses a permanent indir.
96 -------------------------------------------------------------------------- */
99 recordMutable(StgMutClosure *p)
103 ASSERT(closure_MUTABLE(p));
106 if (bd->gen->no > 0) {
107 p->mut_link = bd->gen->mut_list;
108 bd->gen->mut_list = p;
113 recordOldToNewPtrs(StgMutClosure *p)
118 if (bd->gen->no > 0) {
119 p->mut_link = bd->gen->mut_once_list;
120 bd->gen->mut_once_list = p;
125 updateWithIndirection(StgClosure *p1, StgClosure *p2)
130 if (bd->gen->no == 0) {
131 SET_INFO(p1,&IND_info);
132 ((StgInd *)p1)->indirectee = p2;
135 SET_INFO(p1,&IND_OLDGEN_info);
136 ((StgIndOldGen *)p1)->indirectee = p2;
137 ((StgIndOldGen *)p1)->mut_link = bd->gen->mut_once_list;
138 bd->gen->mut_once_list = (StgMutClosure *)p1;
143 #if defined(TICKY_TICKY) || defined(PROFILING)
145 updateWithPermIndirection(StgClosure *p1, StgClosure *p2)
150 if (bd->gen->no == 0) {
151 SET_INFO(p1,&IND_PERM_info);
152 ((StgInd *)p1)->indirectee = p2;
153 TICK_UPD_NEW_PERM_IND(p1);
155 SET_INFO(p1,&IND_OLDGEN_PERM_info);
156 ((StgIndOldGen *)p1)->indirectee = p2;
157 ((StgIndOldGen *)p1)->mut_link = bd->gen->mut_once_list;
158 bd->gen->mut_once_list = (StgMutClosure *)p1;
159 TICK_UPD_OLD_PERM_IND();
164 /* -----------------------------------------------------------------------------
165 The CAF list - used to let us revert CAFs
167 -------------------------------------------------------------------------- */
169 extern StgCAF* enteredCAFs;