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
|
3305
|
30 /* Set to 1 if memory becomes short. */
|
|
31 extern EMACS_INT memory_shortage;
|
2720
|
32
|
|
33
|
3092
|
34 /* Internal Allocator Functions: */
|
2720
|
35
|
3092
|
36 /* Initialize the allocator. This has to be called prior to
|
|
37 requesting memory. */
|
2720
|
38 void init_mc_allocator (void);
|
|
39
|
3092
|
40 /* Allocate a block of memory of given size and return the pointer to
|
|
41 it. */
|
2720
|
42 void *mc_alloc (size_t size);
|
|
43
|
3092
|
44 /* Allocate a block of memory as an array with elemcount elements of
|
|
45 given size and return the pointer to it. Arrays contain several
|
|
46 objects that are allocated in one consecutive block of memory with
|
|
47 each element being a fully qualified object---that is, it has a
|
|
48 Lisp object header and a mark bit. Objects like hash tables and
|
|
49 dynamic arrays use this function. */
|
|
50 void *mc_alloc_array (size_t size, EMACS_INT elemcount);
|
|
51
|
|
52 /* Modify the size of the memory block pointed to by ptr. Return the
|
|
53 address of the new block of given size. The content of the memory
|
|
54 block will be unchanged to the minimum of the old and new sizes: if
|
|
55 the new size is smaller, the overlaying data is cut off; if the new
|
|
56 size is bigger, the newly allocated memory will be uninitialized.*/
|
2720
|
57 void *mc_realloc (void *ptr, size_t size);
|
|
58
|
3092
|
59 /* Modify the size of the array pointed to by ptr. Return the address
|
|
60 of the new array block with elemcount elements of given size. The
|
|
61 content of the memory block will be unchanged to the minimum of the
|
|
62 old and new sizes: if the new size is smaller, the overlaying data
|
|
63 is cut off; if the new size is bigger, the newly allocated memory
|
|
64 will be uninitialized.*/
|
|
65 void *mc_realloc_array (void *ptr, size_t size, EMACS_INT elemcount);
|
|
66
|
2720
|
67
|
|
68
|
|
69 /* Garbage collection related functions and macros: */
|
|
70
|
3092
|
71 enum mark_bit_colors
|
|
72 {
|
|
73 WHITE = 0,
|
|
74 BLACK = 1,
|
|
75 GREY = 2
|
|
76 };
|
|
77
|
|
78 /* Set the mark bit of the object pointed to by ptr to value.*/
|
|
79 void set_mark_bit (void *ptr, EMACS_INT value);
|
|
80
|
|
81 /* Return the mark bit of the object pointed to by ptr. */
|
|
82 EMACS_INT get_mark_bit (void *ptr);
|
|
83
|
|
84 /* mark bit macros */
|
|
85 /* Returns true if the mark bit of the object pointed to by ptr is set. */
|
|
86 #define MARKED_P(ptr) (get_mark_bit (ptr) != WHITE)
|
|
87
|
|
88 /* Marks the object pointed to by ptr (sets the mark bit to 1). */
|
|
89 #define MARK(ptr) set_mark_bit (ptr, BLACK)
|
|
90
|
|
91 /* Unmarks the object pointed to by ptr (sets the mark bit to 0). */
|
|
92 #define UNMARK(ptr) set_mark_bit (ptr, WHITE)
|
|
93
|
|
94 #define MARK_WHITE(ptr) set_mark_bit (ptr, WHITE)
|
|
95 #define MARK_GREY(ptr) set_mark_bit (ptr, GREY)
|
|
96 #define MARK_BLACK(ptr) set_mark_bit (ptr, BLACK)
|
|
97
|
|
98 #define MARKED_WHITE_P(ptr) (get_mark_bit (ptr) == WHITE)
|
|
99 #define MARKED_GREY_P(ptr) (get_mark_bit (ptr) == GREY)
|
|
100 #define MARKED_BLACK_P(ptr) (get_mark_bit (ptr) == BLACK)
|
2720
|
101
|
3092
|
102 /* The finalizer of every not marked object is called. The macro
|
2720
|
103 MC_ALLOC_CALL_FINALIZER has to be defined and call the finalizer of
|
3303
|
104 the object. Returns number of processed pages. */
|
|
105 EMACS_INT mc_finalize (void);
|
2720
|
106
|
3303
|
107 /* All not marked objects of the used heap are freed. Returns number
|
|
108 of processed pages. */
|
|
109 EMACS_INT mc_sweep (void);
|
2720
|
110
|
|
111
|
|
112
|
|
113 /* Portable dumper related functions and macros: */
|
|
114
|
|
115 /* The finalizer for disksave of every object is called to shrink the
|
3092
|
116 dump image. The macro MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE has to
|
3303
|
117 be defined and call the finalizer for disksave of the object.
|
|
118 Returns number of processed pages. */
|
|
119 EMACS_INT mc_finalize_for_disksave (void);
|
2720
|
120
|
|
121
|
|
122
|
|
123 /* Functions and macros related with allocation statistics: */
|
|
124
|
|
125 #ifdef MEMORY_USAGE_STATS
|
|
126 /* Returns the real size, including overhead, which is actually alloced
|
|
127 for an object with given claimed_size. */
|
|
128 Bytecount mc_alloced_storage_size (Bytecount claimed_size,
|
|
129 struct overhead_stats *stats);
|
|
130 #endif /* MEMORY_USAGE_STATS */
|
|
131
|
3092
|
132
|
|
133 /* Incremental Garbage Collector / Write Barrier Support: */
|
|
134
|
|
135 /* Return the PAGESIZE the allocator uses. Generally equals to the
|
|
136 system's PAGESIZE. */
|
|
137 EMACS_INT mc_get_page_size (void);
|
|
138
|
|
139 /* Is the fault at ptr on a protected page? */
|
|
140 EMACS_INT fault_on_protected_page (void *ptr);
|
|
141
|
3303
|
142 /* Remove protection (if there) of heap page of given page header ph.
|
|
143 Returns number of processed pages. */
|
|
144 EMACS_INT protect_heap_pages (void);
|
3092
|
145
|
3303
|
146 /* Remove protection for all heap pages which are protected. Returns
|
|
147 number of processed pages. */
|
|
148 EMACS_INT unprotect_heap_pages (void);
|
3092
|
149
|
|
150 /* Remove protection and mark page dirty. */
|
|
151 void unprotect_page_and_mark_dirty (void *ptr);
|
|
152
|
|
153 /* Repush all objects on dirty pages onto the mark stack. Return
|
|
154 number of repushed objects. */
|
|
155 int repush_all_objects_on_page (void *ptr);
|
|
156
|
|
157 /* Mark black if object is currently grey. */
|
|
158 EMACS_INT maybe_mark_black (void *ptr);
|
|
159
|
|
160 /* Only for debugging---not used anywhere in the sources. */
|
|
161 EMACS_INT object_on_heap_p (void *ptr);
|
|
162
|
2720
|
163 END_C_DECLS
|
|
164
|
|
165 #endif /* INCLUDED_mc_alloc_h_ */
|