1 /* -----------------------------------------------------------------------------
2 * $Id: Storage.h,v 1.7 1999/02/05 16:03:01 simonm 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 -------------------------------------------------------------------------- */
97 recordMutable(StgMutClosure *p)
101 ASSERT(closure_MUTABLE(p));
104 if (bd->gen->no > 0) {
105 p->mut_link = bd->gen->mut_list;
106 bd->gen->mut_list = p;
111 recordOldToNewPtrs(StgMutClosure *p)
116 if (bd->gen->no > 0) {
117 p->mut_link = bd->gen->mut_once_list;
118 bd->gen->mut_once_list = p;
123 updateWithIndirection(StgClosure *p1, StgClosure *p2)
128 if (bd->gen->no == 0) {
129 SET_INFO(p1,&IND_info);
130 ((StgInd *)p1)->indirectee = p2;
133 SET_INFO(p1,&IND_OLDGEN_info);
134 ((StgIndOldGen *)p1)->indirectee = p2;
135 ((StgIndOldGen *)p1)->mut_link = bd->gen->mut_once_list;
136 bd->gen->mut_once_list = (StgMutClosure *)p1;
141 /* -----------------------------------------------------------------------------
142 The CAF list - used to let us revert CAFs
144 -------------------------------------------------------------------------- */
146 extern StgCAF* enteredCAFs;