Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/runtime/gc/heap.h
ViewVC logotype

Annotation of /sml/trunk/src/runtime/gc/heap.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 250 - (view) (download) (as text)

1 : monnier 249 /* heap.h
2 :     *
3 :     * COPYRIGHT (c) 1993 by AT&T Bell Laboratories.
4 :     *
5 :     * These are the definitions for the heap structure.
6 :     */
7 :    
8 :     #ifndef _HEAP_
9 :     #define _HEAP_
10 :    
11 :     #ifndef _ML_BASE_
12 :     #include "ml-base.h"
13 :     #endif
14 :    
15 :     #ifndef _GC_
16 :     #include "gc.h"
17 :     #endif
18 :    
19 :     #ifndef _ARENA_ID_
20 :     #include "arena-id.h"
21 :     #endif
22 :    
23 :     #ifndef _TAGS_
24 :     #include "tags.h"
25 :     #endif
26 :    
27 :     #ifndef _MEMORY_
28 :     typedef struct mem_obj mem_obj_t;
29 :     #endif
30 :    
31 :     #ifndef _CARD_MAP_
32 :     typedef struct card_map card_map_t;
33 :     #endif
34 :    
35 :     #if ((defined(COLLECT_STATS) || defined(GC_STATS)) && (! defined(_CNTR_)))
36 :     #include "cntr.h"
37 :     #endif
38 :    
39 :     struct heap_params {
40 :     Addr_t allocSz; /* the size of the allocation arena */
41 :     int numGens;
42 :     int cacheGen;
43 :     };
44 :    
45 :     typedef struct repair repair_t;
46 :     typedef struct arena arena_t;
47 :     typedef struct bigobj_region bigobj_region_t;
48 :     typedef struct bigobj_desc bigobj_desc_t;
49 :     typedef struct generation gen_t;
50 :     /* typedef struct heap heap_t; */ /** defined in ml-base.h **/
51 :    
52 :    
53 :     /** A heap **
54 :     * A heap consists of an allocation space and one or more generations.
55 :     */
56 :     struct heap {
57 :     ml_val_t *allocBase; /* The base address of the allocation arena */
58 :     Addr_t allocSzB; /* The size in bytes of the allocation arena */
59 :     mem_obj_t *baseObj; /* The OS memory object that contains the */
60 :     /* BIBOP and allocation arena. */
61 :     int numGens; /* The number of active generations. */
62 :     int cacheGen; /* Cache the from-space for gens 1..cacheGen. */
63 :     int numMinorGCs; /* The number of times the allocation space */
64 :     /* has been collected. */
65 :     gen_t *gen[MAX_NUM_GENS]; /* generation #i is gen[i-1] */
66 :     int numBORegions; /* the number of active big-object regions */
67 :     bigobj_region_t *bigRegions; /* points to the list of big object regions. */
68 :     bigobj_desc_t *freeBigObjs; /* points to the header of the free-list */
69 :     /* of big objects. */
70 :     ml_val_t *weakList; /* A list of weak pointers forwarded*/
71 :     /* during GC. */
72 :     #if (defined(COLLECT_STATS) || defined(GC_STATS))
73 :     cntr_t numAlloc; /* Keep track of the number of bytes */
74 :     /* allocated and the number copied into */
75 :     #ifdef GC_STATS
76 :     cntr_t numCopied /* each arena. */
77 :     [MAX_NUM_GENS][NUM_ARENAS];
78 :     #endif
79 :     #endif
80 :     #ifdef HEAP_MONITOR
81 :     struct monitor *monitor; /* The various graphical data structures */
82 :     /* for monitoring the heap. */
83 :     #endif
84 :     };
85 :    
86 :     #ifdef OLD
87 :     /* once we figure out multiple arenas for the MP version, we should
88 :     * be able to go back to the old version of this.
89 :     */
90 :     #define HEAP_LIMIT(hp) \
91 :     (ml_val_t *)((Addr_t)((hp)->allocBase) + (hp)->allocSzB - HEAP_BUF_SZB)
92 :     #else
93 :     #define HEAP_LIMIT_SIZE(base,size) \
94 :     (ml_val_t *)((Addr_t)(base) + (size) - HEAP_BUF_SZB)
95 :    
96 :     #define HEAP_LIMIT(hp) HEAP_LIMIT_SIZE((hp)->allocBase,(hp)->allocSzB)
97 :     #endif
98 :    
99 :    
100 :     /** A generation **/
101 :     struct generation {
102 :     heap_t *heap; /* A back pointer to the heap data structure */
103 :     int genNum; /* Which generation this is (1..numGens) */
104 :     int numGCs; /* The number of times this generation has been */
105 :     /* collected. */
106 :     int lastPrevGC; /* The number GCs of the previous (younger) generation */
107 :     /* the last time this generation was collected. */
108 :     int ratio; /* The desired number of collections of the previous */
109 :     /* generation for one collection of this generation */
110 :     arena_t *arena[NUM_ARENAS];
111 :     bigobj_desc_t *bigObjs[NUM_BIGOBJ_KINDS];
112 :     mem_obj_t *toObj; /* The O.S. memory objects that this generation is */
113 :     mem_obj_t *fromObj; /* using for the to-space and from-space */
114 :     mem_obj_t *cacheObj; /* For younger generations, we cache the virtual */
115 :     /* memory of from-space, instead of giving it back. */
116 :     card_map_t *dirty; /* The dirty cards in the array arena of this gen. */
117 :     };
118 :    
119 :    
120 :     /** An arena **/
121 :     struct arena {
122 :     aid_t id; /* The to-space version of this arena's identifier */
123 :     ml_val_t *nextw; /* The next word to allocate in this arena's to-space */
124 :     ml_val_t *tospBase; /* the base address and size of to-space. */
125 :     Addr_t tospSizeB;
126 :     ml_val_t *tospTop; /* The top of the to-space (tospBase+tospSizeB). */
127 :     ml_val_t *sweep_nextw; /* The next word to sweep in the to-space arena */
128 :     repair_t *repairList; /* points to the top of the repair list (for */
129 :     /* blasting out objects). The repair list grows */
130 :     /* down in to-space. */
131 :     ml_val_t *frspBase; /* the base address and size of from-space. */
132 :     Word_t frspSizeB;
133 :     ml_val_t *frspTop; /* The top of the used portion of from-space. */
134 :     ml_val_t *oldTop; /* The top of the "older" from-space region. Objects */
135 :     /* below oldTop get promoted, those above don't. */
136 :     arena_t *nextGen; /* The arena to promote objects to. */
137 :     bool_t needsRepair; /* Set to TRUE when exporting, if the arena had */
138 :     /* external references that require repair */
139 :     /* Heap sizing parameters: */
140 :     Word_t reqSizeB; /* requested minimum size for this arena (this is */
141 :     /* in addition to the required min. size). */
142 :     Word_t maxSizeB; /* a soft maximum size for this arena. */
143 :     };
144 :    
145 :     /* Make to-space into from-space */
146 :     #define FLIP_ARENA(ap) { \
147 :     arena_t *__ap = (ap); \
148 :     __ap->frspBase = __ap->tospBase; \
149 :     __ap->frspSizeB = __ap->tospSizeB; \
150 :     __ap->frspTop = __ap->nextw; \
151 :     }
152 :    
153 :     /* Return true if this arena has an allocated ToSpace */
154 :     #define isACTIVE(a) ((a)->tospSizeB > 0)
155 :    
156 :     /* Return true if this arena's ToSpace needs sweeping */
157 :     #define NEEDS_SWEEPING(a) ((a)->sweep_nextw < (a)->nextw)
158 :    
159 :     /* Return the amount of free space (in bytes) available in an arena */
160 :     #define AVAIL_SPACE(a) ((Addr_t)((a)->tospTop) - (Addr_t)((a)->nextw))
161 :    
162 :     /* Return true if the address addr is an older object in this arena */
163 :     #define isOLDER(a,addr) ((addr) < (a)->oldTop)
164 :    
165 :    
166 :     /** Big object regions **
167 :     *
168 :     * Currently, the only big objects are code objects.
169 :     */
170 :    
171 :     /*#define BIGOBJ_PAGE_SHIFT 12*/ /* 4Kb */
172 :     #define BIGOBJ_PAGE_SHIFT 10 /* 1Kb */
173 :     #define BIGOBJ_PAGE_SZB (1 << BIGOBJ_PAGE_SHIFT)
174 :     #define MIN_BOREGION_SZB (128*ONE_K)
175 :    
176 :     struct bigobj_region { /* A big-object region header */
177 :     Addr_t firstPage; /* the address of the first page of the region */
178 :     int nPages; /* the number of big-object pages in this region */
179 :     int nFree; /* the number of free pages */
180 :     int minGen; /* the minimum generation of the live objects in */
181 :     /* this region. */
182 :     mem_obj_t *memObj; /* the memory object that this is allocated in */
183 :     bigobj_region_t *next; /* the next region in the list of regions */
184 :     bigobj_desc_t *objMap[1]; /* the map from pages to big-object descriptors */
185 :     };
186 :    
187 :     /* the size of a big-object region header */
188 :     #define BOREGION_HDR_SZB(NPAGES) \
189 :     (sizeof(bigobj_region_t) + ((NPAGES-1)*sizeof(bigobj_desc_t *)))
190 :    
191 :     /* map an address to a big-object page index */
192 :     #define ADDR_TO_BOPAGE(R, ADDR) \
193 :     (((Addr_t)(ADDR) - (R)->firstPage) >> BIGOBJ_PAGE_SHIFT)
194 :    
195 :     /* map an address to a big-object descriptor */
196 :     #define ADDR_TO_BODESC(R, ADDR) \
197 :     ((R)->objMap[ADDR_TO_BOPAGE(R, ADDR)])
198 :    
199 :    
200 :     struct bigobj_desc { /* A big-object descriptor. */
201 :     Addr_t obj; /* the actual object */
202 :     Addr_t sizeB; /* the size of the object in bytes. When the object */
203 :     /* is in the free list, this will be a multiple of */
204 :     /* BIGOBJ_PAGE_SZB, otherwise it is the exact size. */
205 :     unsigned char objc; /* the object class */
206 :     unsigned char state; /* the state of the object */
207 :     unsigned char gen; /* the object's generation */
208 :     bigobj_region_t *region; /* the region this big object is in */
209 :     bigobj_desc_t *prev; /* the prev and next links. The big-object free */
210 :     bigobj_desc_t *next; /* list is a doubly linked list; the other lists */
211 :     /* are singly linked lists */
212 :     };
213 :    
214 :     /* the rounded size of a big-object */
215 :     #define BO_ROUNDED_SZB(BDP) ROUNDUP((BDP)->sizeB, BIGOBJ_PAGE_SZB)
216 :    
217 :     /* the number of big-object pages occupied by a big-object */
218 :     #define BO_NUM_BOPAGES(BDP) (BO_ROUNDED_SZB(BDP) >> BIGOBJ_PAGE_SHIFT)
219 :    
220 :     /* big-object descriptor states */
221 :     #define BO_FREE 0 /* a free big-object */
222 :     #define BO_YOUNG 1 /* a young object (i.e., one that has never */
223 :     /* been forwarded in its generation */
224 :     #define BO_FORWARD 2 /* a forwarded young object */
225 :     #define BO_OLD 3 /* an old object */
226 :     #define BO_PROMOTE 4 /* a promoted old object */
227 :    
228 :     #define BO_IS_FROM_SPACE(dp) (((dp)->state & 0x1) != 0)
229 :     #define BO_IS_FREE(dp) ((dp)->state == BO_FREE)
230 :    
231 :     /* remove a descriptor from a doubly linked list */
232 :     #define REMOVE_BODESC(dp) { \
233 :     bigobj_desc_t *__dp = (dp), *__p, *__n; \
234 :     __p = __dp->prev; \
235 :     __n = __dp->next; \
236 :     __p->next = __n; \
237 :     __n->prev = __p; \
238 :     }
239 :    
240 :     /* add a descriptor to a doubly linked list */
241 :     #define ADD_BODESC(hdr, desc) { \
242 :     bigobj_desc_t *__hdr = (hdr), *__dp = (desc); \
243 :     __dp->next = __hdr->next; \
244 :     __dp->prev = __hdr; \
245 :     __hdr->next->prev = __dp; \
246 :     __hdr->next = __dp; \
247 :     }
248 :    
249 :    
250 :     /** operations on forward pointers **/
251 :    
252 :     /* follow a forward pointer. HDR is the object header, P is the pointer to
253 :     * the object.
254 :     * NOTE: we need the two type casts for 32/64 bit systems.
255 :     */
256 :     #define FOLLOW_FWDOBJ(HDR) ((ml_val_t *)(((ml_val_t *)(HDR))[0]))
257 :     /* follow a pair-space forward pointer (this is tagged as a descriptor). */
258 :     #define FOLLOW_FWDPAIR(DESC, HDR) \
259 :     ((ml_val_t *)(((Addr_t)(DESC)) & ~MAJOR_MASK))
260 :    
261 :     /* make a pair-space forward pointer (this is tagged as a descriptor). */
262 :     #define MAKE_PAIR_FP(NEW_ADDR) ((ml_val_t)((Addr_t)(NEW_ADDR) | TAG_desc))
263 :    
264 :    
265 :     /** External GC functions **/
266 :     extern void MinorGC (ml_state_t *msp, ml_val_t **roots);
267 :     extern void MajorGC (ml_state_t *msp, ml_val_t **roots, int level);
268 :     extern int Flip (heap_t *heap, int min_gc_level);
269 :     extern status_t NewGeneration (gen_t *gen);
270 :     extern void FreeGeneration (heap_t *heap, int g);
271 :     extern void NewDirtyVector (gen_t *gen);
272 :     extern void MarkRegion (bibop_t bibop, ml_val_t *base, Word_t sizeB, aid_t id);
273 :     extern void ScanWeakPtrs (heap_t *heap);
274 :    
275 :     extern bigobj_desc_t *BO_AllocRegion (heap_t *heap, Addr_t szB);
276 :     extern bigobj_desc_t *BO_Alloc (heap_t *heap, int gen, Addr_t objSzB);
277 :     extern void BO_Free (heap_t *heap, bigobj_desc_t *desc);
278 :     extern bigobj_desc_t *BO_GetDesc (ml_val_t addr);
279 :     extern char *BO_GetCodeObjTag (bigobj_desc_t *bdp, char *buf, int bufSz);
280 :    
281 :     #ifdef BO_DEBUG
282 :     extern void PrintRegionMap (bigobj_region_t *r);
283 :     #endif
284 :     #ifdef CHECK_GC
285 :     extern void CheckHeap (heap_t *heap, int maxSweptGen);
286 :     #endif
287 :    
288 :     #endif /* !_HEAP_ */

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0