[project @ 1999-03-18 17:57:19 by simonm]
[ghc-hetmet.git] / ghc / rts / Storage.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Storage.h,v 1.8 1999/03/18 17:57:23 simonm Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * External Storage Manger Interface
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #ifndef STORAGE_H
11 #define STORAGE_H
12
13 #include "Block.h"
14 #include "BlockAlloc.h"
15 #include "StoragePriv.h"
16
17 /* -----------------------------------------------------------------------------
18    Initialisation / De-initialisation
19    -------------------------------------------------------------------------- */
20
21 extern void initStorage(void);
22 extern void exitStorage(void);
23
24 /* -----------------------------------------------------------------------------
25    Generic allocation
26
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.
30                                 
31                                 Don't forget to TICK_ALLOC_XXX(...)
32                                 after calling allocate, for the
33                                 benefit of the ticky-ticky profiler.
34
35    rtsBool doYouWantToGC(void)  Returns True if the storage manager is
36                                 ready to perform a GC, False otherwise.
37
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    -------------------------------------------------------------------------- */
42
43 extern StgPtr  allocate(nat n);
44 static inline rtsBool doYouWantToGC(void)
45 {
46   return (alloc_blocks >= alloc_blocks_lim);
47 }
48 extern lnat allocated_bytes(void);
49
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   -------------------------------------------------------------------------- */
57
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),                      \
63     rtsTrue))
64
65 extern void PleaseStopAllocating(void);
66
67 /* -----------------------------------------------------------------------------
68    Performing Garbage Collection
69
70    GarbageCollect(get_roots)    Performs a garbage collection.  
71                                 'get_roots' is called to find all the 
72                                 roots that the system knows about.
73
74    StgClosure                   Called by get_roots on each root.       
75    MarkRoot(StgClosure *p)      Returns the new location of the root.
76    -------------------------------------------------------------------------- */
77
78 extern void   GarbageCollect(void (*get_roots)(void));
79 extern StgClosure *MarkRoot(StgClosure *p);
80
81 /* -----------------------------------------------------------------------------
82    Generational garbage collection support
83
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.
88
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.
93
94    -------------------------------------------------------------------------- */
95
96 static inline void
97 recordMutable(StgMutClosure *p)
98 {
99   bdescr *bd;
100
101   ASSERT(closure_MUTABLE(p));
102
103   bd = Bdescr((P_)p);
104   if (bd->gen->no > 0) {
105     p->mut_link = bd->gen->mut_list;
106     bd->gen->mut_list = p;
107   }
108 }
109
110 static inline void
111 recordOldToNewPtrs(StgMutClosure *p)
112 {
113   bdescr *bd;
114   
115   bd = Bdescr((P_)p);
116   if (bd->gen->no > 0) {
117     p->mut_link = bd->gen->mut_once_list;
118     bd->gen->mut_once_list = p;
119   }
120 }
121
122 static inline void
123 updateWithIndirection(StgClosure *p1, StgClosure *p2) 
124 {
125   bdescr *bd;
126
127   bd = Bdescr((P_)p1);
128   if (bd->gen->no == 0) {
129     SET_INFO(p1,&IND_info);
130     ((StgInd *)p1)->indirectee = p2;
131     TICK_UPD_NEW_IND();
132   } else {
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;
137     TICK_UPD_OLD_IND();
138   }
139 }
140
141 #ifdef PROFILING
142 static inline void
143 updateWithPermIndirection(StgClosure *p1, StgClosure *p2) 
144 {
145   bdescr *bd;
146
147   bd = Bdescr((P_)p1);
148   if (bd->gen->no == 0) {
149     SET_INFO(p1,&IND_PERM_info);
150     ((StgInd *)p1)->indirectee = p2;
151     TICK_UPD_NEW_IND();
152   } else {
153     SET_INFO(p1,&IND_OLDGEN_PERM_info);
154     ((StgIndOldGen *)p1)->indirectee = p2;
155     ((StgIndOldGen *)p1)->mut_link = bd->gen->mut_once_list;
156     bd->gen->mut_once_list = (StgMutClosure *)p1;
157     TICK_UPD_OLD_IND();
158   }
159 }
160 #endif
161
162 /* -----------------------------------------------------------------------------
163    The CAF list - used to let us revert CAFs
164
165    -------------------------------------------------------------------------- */
166
167 extern StgCAF* enteredCAFs;
168
169 #endif STORAGE_H
170