2720
|
1 /* New allocator for XEmacs.
|
|
2 Copyright (C) 2005 Marcus Crestani.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: Not in FSF. */
|
|
22
|
|
23 #ifndef INCLUDED_mc_alloc_h_
|
|
24 #define INCLUDED_mc_alloc_h_
|
|
25
|
|
26 /*--- prototypes -------------------------------------------------------*/
|
|
27
|
|
28 BEGIN_C_DECLS
|
|
29
|
|
30
|
|
31
|
3092
|
32 /* Internal Allocator Functions: */
|
2720
|
33
|
3092
|
34 /* Initialize the allocator. This has to be called prior to
|
|
35 requesting memory. */
|
2720
|
36 void init_mc_allocator (void);
|
|
37
|
3092
|
38 /* Allocate a block of memory of given size and return the pointer to
|
|
39 it. */
|
2720
|
40 void *mc_alloc (size_t size);
|
|
41
|
3092
|
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. */
|
2720
|
54 void mc_free (void *ptr);
|
|
55
|
3092
|
56 /* Modify the size of the memory block pointed to by ptr. Return the
|
|
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.*/
|
2720
|
61 void *mc_realloc (void *ptr, size_t size);
|
|
62
|
3092
|
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);
|
|
70
|
2720
|
71
|
|
72
|
|
73 /* Garbage collection related functions and macros: */
|
|
74
|
3092
|
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 */
|
2720
|
107 /* Set the mark bit of the object pointed to by ptr to value.*/
|
|
108 void set_mark_bit (void *ptr, EMACS_INT value);
|
|
109
|
|
110 /* Return the mark bit of the object pointed to by ptr. */
|
|
111 EMACS_INT get_mark_bit (void *ptr);
|
|
112
|
|
113 /* mark bit macros */
|
|
114 /* Returns true if the mark bit of the object pointed to by ptr is set. */
|
|
115 #define MARKED_P(ptr) (get_mark_bit (ptr) == 1)
|
|
116
|
|
117 /* Marks the object pointed to by ptr (sets the mark bit to 1). */
|
|
118 #define MARK(ptr) set_mark_bit (ptr, 1)
|
|
119
|
|
120 /* Unmarks the object pointed to by ptr (sets the mark bit to 0). */
|
|
121 #define UNMARK(ptr) set_mark_bit (ptr, 0)
|
3092
|
122 #endif /* not NEW_GC */
|
2720
|
123
|
3092
|
124 /* The finalizer of every not marked object is called. The macro
|
2720
|
125 MC_ALLOC_CALL_FINALIZER has to be defined and call the finalizer of
|
|
126 the object. */
|
|
127 void mc_finalize (void);
|
|
128
|
|
129 /* All not marked objects of the used heap are freed. */
|
|
130 void mc_sweep (void);
|
|
131
|
|
132
|
|
133
|
|
134 /* Portable dumper related functions and macros: */
|
|
135
|
|
136 /* The finalizer for disksave of every object is called to shrink the
|
3092
|
137 dump image. The macro MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE has to
|
2720
|
138 be defined and call the finalizer for disksave of the object. */
|
|
139 void mc_finalize_for_disksave (void);
|
|
140
|
|
141
|
|
142
|
|
143 /* Functions and macros related with allocation statistics: */
|
|
144
|
|
145 #ifdef MEMORY_USAGE_STATS
|
|
146 /* Returns the real size, including overhead, which is actually alloced
|
|
147 for an object with given claimed_size. */
|
|
148 Bytecount mc_alloced_storage_size (Bytecount claimed_size,
|
|
149 struct overhead_stats *stats);
|
|
150 #endif /* MEMORY_USAGE_STATS */
|
|
151
|
3092
|
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
|
2720
|
185 END_C_DECLS
|
|
186
|
|
187 #endif /* INCLUDED_mc_alloc_h_ */
|