Mercurial > hg > xemacs-beta
comparison src/mc-alloc.h @ 3092:141c2920ea48
[xemacs-hg @ 2005-11-25 01:41:31 by crestani]
Incremental Garbage Collector
author | crestani |
---|---|
date | Fri, 25 Nov 2005 01:42:08 +0000 |
parents | ec5f23ea6d2e |
children | d674024a8674 |
comparison
equal
deleted
inserted
replaced
3091:c22d8984148c | 3092:141c2920ea48 |
---|---|
21 /* Synched up with: Not in FSF. */ | 21 /* Synched up with: Not in FSF. */ |
22 | 22 |
23 #ifndef INCLUDED_mc_alloc_h_ | 23 #ifndef INCLUDED_mc_alloc_h_ |
24 #define INCLUDED_mc_alloc_h_ | 24 #define INCLUDED_mc_alloc_h_ |
25 | 25 |
26 | |
27 /* This is moved here from alloc.c. */ | |
28 #ifndef MALLOC_OVERHEAD | |
29 # ifdef GNU_MALLOC | |
30 # define MALLOC_OVERHEAD 0 | |
31 # elif defined (rcheck) | |
32 # define MALLOC_OVERHEAD 20 | |
33 # else | |
34 # define MALLOC_OVERHEAD 8 | |
35 # endif | |
36 #endif /* MALLOC_OVERHEAD */ | |
37 | |
38 /*--- prototypes -------------------------------------------------------*/ | 26 /*--- prototypes -------------------------------------------------------*/ |
39 | 27 |
40 BEGIN_C_DECLS | 28 BEGIN_C_DECLS |
41 | 29 |
42 | 30 |
43 | 31 |
44 /* Allocation related functions and macros: */ | 32 /* Internal Allocator Functions: */ |
45 | 33 |
46 /* Builds and initializes all needed datastructures of the new allocator. */ | 34 /* Initialize the allocator. This has to be called prior to |
35 requesting memory. */ | |
47 void init_mc_allocator (void); | 36 void init_mc_allocator (void); |
48 | 37 |
49 /* Returns a pointer to a block of memory of given size on the used heap. */ | 38 /* Allocate a block of memory of given size and return the pointer to |
39 it. */ | |
50 void *mc_alloc (size_t size); | 40 void *mc_alloc (size_t size); |
51 | 41 |
52 /* Frees the object pointed to by pointer. */ | 42 /* Allocate a block of memory as an array with elemcount elements of |
43 given size and return the pointer to it. Arrays contain several | |
44 objects that are allocated in one consecutive block of memory with | |
45 each element being a fully qualified object---that is, it has a | |
46 Lisp object header and a mark bit. Objects like hash tables and | |
47 dynamic arrays use this function. */ | |
48 void *mc_alloc_array (size_t size, EMACS_INT elemcount); | |
49 | |
50 /* Free the object pointed to by ptr and make its memory re-usable | |
51 again. The memory must have been returned by a previous call to | |
52 mc_alloc(). This can be used to free memory explicitly, outside a | |
53 garbage collection. */ | |
53 void mc_free (void *ptr); | 54 void mc_free (void *ptr); |
54 | 55 |
55 /* Modifies the size of the memory block pointed to by ptr. The | 56 /* Modify the size of the memory block pointed to by ptr. Return the |
56 Address of the new block of given size is returned. */ | 57 address of the new block of given size. The content of the memory |
58 block will be unchanged to the minimum of the old and new sizes: if | |
59 the new size is smaller, the overlaying data is cut off; if the new | |
60 size is bigger, the newly allocated memory will be uninitialized.*/ | |
57 void *mc_realloc (void *ptr, size_t size); | 61 void *mc_realloc (void *ptr, size_t size); |
62 | |
63 /* Modify the size of the array pointed to by ptr. Return the address | |
64 of the new array block with elemcount elements of given size. The | |
65 content of the memory block will be unchanged to the minimum of the | |
66 old and new sizes: if the new size is smaller, the overlaying data | |
67 is cut off; if the new size is bigger, the newly allocated memory | |
68 will be uninitialized.*/ | |
69 void *mc_realloc_array (void *ptr, size_t size, EMACS_INT elemcount); | |
58 | 70 |
59 | 71 |
60 | 72 |
61 /* Garbage collection related functions and macros: */ | 73 /* Garbage collection related functions and macros: */ |
62 | 74 |
75 #ifdef NEW_GC | |
76 enum mark_bit_colors | |
77 { | |
78 WHITE = 0, | |
79 BLACK = 1, | |
80 GREY = 2 | |
81 }; | |
82 | |
83 /* Set the mark bit of the object pointed to by ptr to value.*/ | |
84 void set_mark_bit (void *ptr, EMACS_INT value); | |
85 | |
86 /* Return the mark bit of the object pointed to by ptr. */ | |
87 EMACS_INT get_mark_bit (void *ptr); | |
88 | |
89 /* mark bit macros */ | |
90 /* Returns true if the mark bit of the object pointed to by ptr is set. */ | |
91 #define MARKED_P(ptr) (get_mark_bit (ptr) != WHITE) | |
92 | |
93 /* Marks the object pointed to by ptr (sets the mark bit to 1). */ | |
94 #define MARK(ptr) set_mark_bit (ptr, BLACK) | |
95 | |
96 /* Unmarks the object pointed to by ptr (sets the mark bit to 0). */ | |
97 #define UNMARK(ptr) set_mark_bit (ptr, WHITE) | |
98 | |
99 #define MARK_WHITE(ptr) set_mark_bit (ptr, WHITE) | |
100 #define MARK_GREY(ptr) set_mark_bit (ptr, GREY) | |
101 #define MARK_BLACK(ptr) set_mark_bit (ptr, BLACK) | |
102 | |
103 #define MARKED_WHITE_P(ptr) (get_mark_bit (ptr) == WHITE) | |
104 #define MARKED_GREY_P(ptr) (get_mark_bit (ptr) == GREY) | |
105 #define MARKED_BLACK_P(ptr) (get_mark_bit (ptr) == BLACK) | |
106 #else /* not NEW_GC */ | |
63 /* Set the mark bit of the object pointed to by ptr to value.*/ | 107 /* Set the mark bit of the object pointed to by ptr to value.*/ |
64 void set_mark_bit (void *ptr, EMACS_INT value); | 108 void set_mark_bit (void *ptr, EMACS_INT value); |
65 | 109 |
66 /* Return the mark bit of the object pointed to by ptr. */ | 110 /* Return the mark bit of the object pointed to by ptr. */ |
67 EMACS_INT get_mark_bit (void *ptr); | 111 EMACS_INT get_mark_bit (void *ptr); |
73 /* Marks the object pointed to by ptr (sets the mark bit to 1). */ | 117 /* Marks the object pointed to by ptr (sets the mark bit to 1). */ |
74 #define MARK(ptr) set_mark_bit (ptr, 1) | 118 #define MARK(ptr) set_mark_bit (ptr, 1) |
75 | 119 |
76 /* Unmarks the object pointed to by ptr (sets the mark bit to 0). */ | 120 /* Unmarks the object pointed to by ptr (sets the mark bit to 0). */ |
77 #define UNMARK(ptr) set_mark_bit (ptr, 0) | 121 #define UNMARK(ptr) set_mark_bit (ptr, 0) |
122 #endif /* not NEW_GC */ | |
78 | 123 |
79 /* The finalizer of every not marked object is called. The macro | 124 /* The finalizer of every not marked object is called. The macro |
80 MC_ALLOC_CALL_FINALIZER has to be defined and call the finalizer of | 125 MC_ALLOC_CALL_FINALIZER has to be defined and call the finalizer of |
81 the object. */ | 126 the object. */ |
82 void mc_finalize (void); | 127 void mc_finalize (void); |
83 | 128 |
84 /* All not marked objects of the used heap are freed. */ | 129 /* All not marked objects of the used heap are freed. */ |
87 | 132 |
88 | 133 |
89 /* Portable dumper related functions and macros: */ | 134 /* Portable dumper related functions and macros: */ |
90 | 135 |
91 /* The finalizer for disksave of every object is called to shrink the | 136 /* The finalizer for disksave of every object is called to shrink the |
92 dump image. The macro MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE has to | 137 dump image. The macro MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE has to |
93 be defined and call the finalizer for disksave of the object. */ | 138 be defined and call the finalizer for disksave of the object. */ |
94 void mc_finalize_for_disksave (void); | 139 void mc_finalize_for_disksave (void); |
95 | |
96 | |
97 | |
98 /* Allocation function for the unmanaged heap: */ | |
99 | |
100 /* Returns a pointer to a block of memory of given size on the | |
101 unmanaged heap. */ | |
102 void *mc_alloc_unmanaged (size_t size); | |
103 | |
104 /* Modifies the size of the memory block pointed to by ptr. The | |
105 Address of the new block of given size is returned. */ | |
106 void *mc_realloc_unmanaged (void *ptr, size_t size); | |
107 | 140 |
108 | 141 |
109 | 142 |
110 /* Functions and macros related with allocation statistics: */ | 143 /* Functions and macros related with allocation statistics: */ |
111 | 144 |
114 for an object with given claimed_size. */ | 147 for an object with given claimed_size. */ |
115 Bytecount mc_alloced_storage_size (Bytecount claimed_size, | 148 Bytecount mc_alloced_storage_size (Bytecount claimed_size, |
116 struct overhead_stats *stats); | 149 struct overhead_stats *stats); |
117 #endif /* MEMORY_USAGE_STATS */ | 150 #endif /* MEMORY_USAGE_STATS */ |
118 | 151 |
152 | |
153 #ifdef NEW_GC | |
154 /* Incremental Garbage Collector / Write Barrier Support: */ | |
155 | |
156 /* Return the PAGESIZE the allocator uses. Generally equals to the | |
157 system's PAGESIZE. */ | |
158 EMACS_INT mc_get_page_size (void); | |
159 | |
160 /* Is the fault at ptr on a protected page? */ | |
161 EMACS_INT fault_on_protected_page (void *ptr); | |
162 | |
163 /* Remove protection (if there) of heap page of given page header | |
164 ph. */ | |
165 void protect_heap_pages (void); | |
166 | |
167 /* Remove protection for all heap pages which are protected. */ | |
168 void unprotect_heap_pages (void); | |
169 | |
170 /* Remove protection and mark page dirty. */ | |
171 void unprotect_page_and_mark_dirty (void *ptr); | |
172 | |
173 /* Repush all objects on dirty pages onto the mark stack. Return | |
174 number of repushed objects. */ | |
175 int repush_all_objects_on_page (void *ptr); | |
176 | |
177 /* Mark black if object is currently grey. */ | |
178 EMACS_INT maybe_mark_black (void *ptr); | |
179 | |
180 /* Only for debugging---not used anywhere in the sources. */ | |
181 EMACS_INT object_on_heap_p (void *ptr); | |
182 | |
183 #endif /* NEW_GC */ | |
184 | |
119 END_C_DECLS | 185 END_C_DECLS |
120 | 186 |
121 #endif /* INCLUDED_mc_alloc_h_ */ | 187 #endif /* INCLUDED_mc_alloc_h_ */ |