1 /*
2  * Part of Scheme 48 1.9.  See file COPYING for notices and license.
3  *
4  * Authors: David Frese, Robert Ransom
5  */
6 
7 #ifndef __S48_AREAS_H
8 #define __S48_AREAS_H
9 
10 #include "memory.h"
11 #include "gc_config.h"
12 #include "remset.h"
13 
14 /* Areas
15 
16  Memory is divided into areas, each of which has:
17   start address
18   end pointer
19   allocation pointer (points to next unused space)
20   next area in this category
21 
22  Each generation is a set of areas, grouped into lists by metatype and
23  fixed-ness
24 */
25 
26 typedef struct {
27 #if S48_DIRTY_VECTOR_METHOD==S48_ADDRESS_DIRTY_VECTORS
28   int length;
29   s48_address* items;
30 #endif
31 } Dirty_vector;
32 
33 /* must be synchronized with the Scheme-side definition in ALLOCATION */
34 typedef enum { AREA_TYPE_SIZE_SMALL, AREA_TYPE_SIZE_LARGE, AREA_TYPE_SIZE_WEAKS,
35                AREA_TYPE_SIZE_ILLEGAL }
36   area_type_size_t;
37 
38 typedef enum {GC_ACTION_IGNORE = 0, GC_ACTION_ERROR, GC_ACTION_COPY_MIXED,
39 	      GC_ACTION_COPY_SMALL, GC_ACTION_MARK_LARGE,
40 	      GC_ACTION_COPY_WEAK}
41   gc_action_t;
42 
43 typedef struct Area {
44   s48_address start;
45   s48_address end;
46   s48_address frontier;
47 
48   struct Area* next;
49   int generation_index;
50   area_type_size_t area_type_size;
51 
52   /* only used during collection: */
53   gc_action_t action;
54   s48_address trace;
55   Dirty_vector dirty_vector;
56   struct Space* target_space;
57 #if S48_USE_REMEMBERED_SETS==TRUE
58   RemSet* remset;
59 #endif
60 } Area;
61 
62 typedef struct Space {
63   int generation_index;
64   Area* small_area;
65   Area* large_area;
66   Area* weaks_area;
67 } Space;
68 
69 #define AREA_REMAINING(area) ((area) == NULL ? 0 :\
70                      (area)->end - (area)->frontier)
71 
72 
73 /* Allocate an area of between MINIMUM and MAXIMUM pages, inclusive. */
74 extern Area* s48_allocate_area_without_crashing(unsigned long minimum,
75 						unsigned long maximum,
76 						unsigned char generation_index,
77 						area_type_size_t area_type_size);
78 extern Area* s48_allocate_area(unsigned long minimum, unsigned long maximum,
79 			       unsigned char generation_index, area_type_size_t area_type_size);
80 
81 /* Remove AREA from the list starting with START */
82 extern Area* s48_delete_area(Area* start, Area* area);
83 
84 /* Free all pages covered by AREA, update the memory_map and free Area
85    struct itself too. */
86 extern void s48_free_area(Area* area);
87 
88 /* Call s48_free_area on all areas in the list starting with START */
89 extern void s48_free_areas(Area* start);
90 
91 /* Allocate a block for the whole image */
92 void s48_allocate_image_area(long bytes, s48_address* start, s48_address* end);
93 
94 /* Wrap the static make_area */
95 Area* s48_make_area(s48_address start, s48_address end,
96 		    s48_address frontier,
97 		    unsigned char generation_index,
98 		    area_type_size_t area_type_size);
99 
100 #endif
101