1 /* -----------------------------------------------------------------------------
2 * $Id: Storage.h,v 1.6 1999/02/02 14:21:34 simonm Exp $
4 * External Storage Manger Interface
6 * ---------------------------------------------------------------------------*/
12 #include "BlockAlloc.h"
13 #include "StoragePriv.h"
15 /* -----------------------------------------------------------------------------
16 Initialisation / De-initialisation
17 -------------------------------------------------------------------------- */
19 extern void initStorage(void);
20 extern void exitStorage(void);
22 /* -----------------------------------------------------------------------------
25 StgPtr allocate(int n) Allocates a chunk of contiguous store
26 n words long, returning a pointer to
27 the first word. Always succeeds.
29 Don't forget to TICK_ALLOC_XXX(...)
30 after calling allocate, for the
31 benefit of the ticky-ticky profiler.
33 rtsBool doYouWantToGC(void) Returns True if the storage manager is
34 ready to perform a GC, False otherwise.
36 lnat allocated_bytes(void) Returns the number of bytes allocated
37 via allocate() since the last GC.
38 Used in the reoprting of statistics.
39 -------------------------------------------------------------------------- */
41 extern StgPtr allocate(nat n);
42 static inline rtsBool doYouWantToGC(void)
44 return (alloc_blocks >= alloc_blocks_lim);
46 extern lnat allocated_bytes(void);
48 /* -----------------------------------------------------------------------------
49 ExtendNursery(hp,hplim) When hplim is reached, try to grab
50 some more allocation space. Returns
51 False if the allocation space is
52 exhausted, and the application should
53 call GarbageCollect().
54 -------------------------------------------------------------------------- */
56 #define ExtendNursery(hp,hplim) \
57 (current_nursery->free = (P_)(hp)+1, \
58 current_nursery->link == NULL ? rtsFalse : \
59 (current_nursery = current_nursery->link, \
60 OpenNursery(hp,hplim), \
63 extern void PleaseStopAllocating(void);
65 /* -----------------------------------------------------------------------------
66 Performing Garbage Collection
68 GarbageCollect(get_roots) Performs a garbage collection.
69 'get_roots' is called to find all the
70 roots that the system knows about.
72 StgClosure Called by get_roots on each root.
73 MarkRoot(StgClosure *p) Returns the new location of the root.
74 -------------------------------------------------------------------------- */
76 extern void GarbageCollect(void (*get_roots)(void));
77 extern StgClosure *MarkRoot(StgClosure *p);
79 /* -----------------------------------------------------------------------------
80 Generational garbage collection support
82 RecordMutable(StgPtr p) Informs the garbage collector that a
83 previously immutable object has
84 become (permanently) mutable. Used
85 by thawArray and similar.
87 UpdateWithIndirection(p1,p2) Updates the object at p1 with an
88 indirection pointing to p2. This is
89 normally called for objects in an old
90 generation (>0) when they are updated.
92 -------------------------------------------------------------------------- */
95 recordMutable(StgMutClosure *p)
99 ASSERT(closure_MUTABLE(p));
102 if (bd->gen->no > 0) {
103 p->mut_link = bd->gen->mut_list;
104 bd->gen->mut_list = p;
109 recordOldToNewPtrs(StgMutClosure *p)
114 if (bd->gen->no > 0) {
115 p->mut_link = bd->gen->mut_once_list;
116 bd->gen->mut_once_list = p;
121 updateWithIndirection(StgClosure *p1, StgClosure *p2)
126 if (bd->gen->no == 0) {
127 SET_INFO(p1,&IND_info);
128 ((StgInd *)p1)->indirectee = p2;
131 SET_INFO(p1,&IND_OLDGEN_info);
132 ((StgIndOldGen *)p1)->indirectee = p2;
133 ((StgIndOldGen *)p1)->mut_link = bd->gen->mut_once_list;
134 bd->gen->mut_once_list = (StgMutClosure *)p1;
139 /* -----------------------------------------------------------------------------
140 The CAF list - used to let us revert CAFs
142 -------------------------------------------------------------------------- */
144 extern StgCAF* enteredCAFs;