[project @ 1999-05-11 16:47:39 by keithw]
[ghc-hetmet.git] / ghc / rts / Storage.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Storage.h,v 1.9 1999/05/11 16:47:59 keithw 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    updateWithPermIndirection(p1,p2)  As above but uses a permanent indir.
95
96    -------------------------------------------------------------------------- */
97
98 static inline void
99 recordMutable(StgMutClosure *p)
100 {
101   bdescr *bd;
102
103   ASSERT(closure_MUTABLE(p));
104
105   bd = Bdescr((P_)p);
106   if (bd->gen->no > 0) {
107     p->mut_link = bd->gen->mut_list;
108     bd->gen->mut_list = p;
109   }
110 }
111
112 static inline void
113 recordOldToNewPtrs(StgMutClosure *p)
114 {
115   bdescr *bd;
116   
117   bd = Bdescr((P_)p);
118   if (bd->gen->no > 0) {
119     p->mut_link = bd->gen->mut_once_list;
120     bd->gen->mut_once_list = p;
121   }
122 }
123
124 static inline void
125 updateWithIndirection(StgClosure *p1, StgClosure *p2) 
126 {
127   bdescr *bd;
128
129   bd = Bdescr((P_)p1);
130   if (bd->gen->no == 0) {
131     SET_INFO(p1,&IND_info);
132     ((StgInd *)p1)->indirectee = p2;
133     TICK_UPD_NEW_IND();
134   } else {
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;
139     TICK_UPD_OLD_IND();
140   }
141 }
142
143 #if defined(TICKY_TICKY) || defined(PROFILING)
144 static inline void
145 updateWithPermIndirection(StgClosure *p1, StgClosure *p2) 
146 {
147   bdescr *bd;
148
149   bd = Bdescr((P_)p1);
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);
154   } else {
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();
160   }
161 }
162 #endif
163
164 /* -----------------------------------------------------------------------------
165    The CAF list - used to let us revert CAFs
166
167    -------------------------------------------------------------------------- */
168
169 extern StgCAF* enteredCAFs;
170
171 #endif STORAGE_H
172