[project @ 1999-01-21 10:31:41 by simonm]
[ghc-hetmet.git] / ghc / rts / Storage.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Storage.h,v 1.5 1999/01/21 10:31:52 simonm Exp $
3  *
4  * External Storage Manger Interface
5  *
6  * ---------------------------------------------------------------------------*/
7
8 #ifndef STORAGE_H
9 #define STORAGE_H
10
11 #include "Block.h"
12 #include "BlockAlloc.h"
13 #include "StoragePriv.h"
14
15 /* -----------------------------------------------------------------------------
16    Initialisation / De-initialisation
17    -------------------------------------------------------------------------- */
18
19 extern void initStorage(void);
20 extern void exitStorage(void);
21
22 /* -----------------------------------------------------------------------------
23    Generic allocation
24
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.
28                                 
29                                 Don't forget to TICK_ALLOC_XXX(...)
30                                 after calling allocate, for the
31                                 benefit of the ticky-ticky profiler.
32
33    rtsBool doYouWantToGC(void)  Returns True if the storage manager is
34                                 ready to perform a GC, False otherwise.
35
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    -------------------------------------------------------------------------- */
40
41 extern StgPtr  allocate(nat n);
42 static inline rtsBool doYouWantToGC(void)
43 {
44   return (alloc_blocks >= alloc_blocks_lim);
45 }
46 extern lnat allocated_bytes(void);
47
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   -------------------------------------------------------------------------- */
55
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),                      \
61     rtsTrue))
62
63 extern void PleaseStopAllocating(void);
64
65 /* -----------------------------------------------------------------------------
66    Performing Garbage Collection
67
68    GarbageCollect(get_roots)    Performs a garbage collection.  
69                                 'get_roots' is called to find all the 
70                                 roots that the system knows about.
71
72    StgClosure                   Called by get_roots on each root.       
73    MarkRoot(StgClosure *p)      Returns the new location of the root.
74    -------------------------------------------------------------------------- */
75
76 extern void   GarbageCollect(void (*get_roots)(void));
77 extern StgClosure *MarkRoot(StgClosure *p);
78
79 /* -----------------------------------------------------------------------------
80    Generational garbage collection support
81
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.
86
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.
91
92    -------------------------------------------------------------------------- */
93
94 extern void recordMutable(StgMutClosure *p);
95
96 static inline void
97 updateWithIndirection(StgClosure *p1, StgClosure *p2) 
98 {
99   bdescr *bd;
100
101   bd = Bdescr((P_)p1);
102   if (bd->gen->no == 0) {
103     SET_INFO(p1,&IND_info);
104     ((StgInd *)p1)->indirectee = p2;
105     TICK_UPD_NEW_IND();
106   } else {
107     SET_INFO(p1,&IND_OLDGEN_info);
108     ((StgIndOldGen *)p1)->indirectee = p2;
109     ((StgIndOldGen *)p1)->mut_link = bd->gen->mut_list;
110     bd->gen->mut_list = (StgMutClosure *)p1;
111     TICK_UPD_OLD_IND();
112   }
113 }
114
115 /* -----------------------------------------------------------------------------
116    The CAF list - used to let us revert CAFs
117
118    -------------------------------------------------------------------------- */
119
120 extern StgCAF* enteredCAFs;
121
122 #endif STORAGE_H
123