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 enum mark_bit_colors
|
|
76 {
|
|
77 WHITE = 0,
|
|
78 BLACK = 1,
|
|
79 GREY = 2
|
|
80 };
|
|
81
|
|
82 /* Set the mark bit of the object pointed to by ptr to value.*/
|
|
83 void set_mark_bit (void *ptr, EMACS_INT value);
|
|
84
|
|
85 /* Return the mark bit of the object pointed to by ptr. */
|
|
86 EMACS_INT get_mark_bit (void *ptr);
|
|
87
|
|
88 /* mark bit macros */
|
|
89 /* Returns true if the mark bit of the object pointed to by ptr is set. */
|
|
90 #define MARKED_P(ptr) (get_mark_bit (ptr) != WHITE)
|
|
91
|
|
92 /* Marks the object pointed to by ptr (sets the mark bit to 1). */
|
|
93 #define MARK(ptr) set_mark_bit (ptr, BLACK)
|
|
94
|
|
95 /* Unmarks the object pointed to by ptr (sets the mark bit to 0). */
|
|
96 #define UNMARK(ptr) set_mark_bit (ptr, WHITE)
|
|
97
|
|
98 #define MARK_WHITE(ptr) set_mark_bit (ptr, WHITE)
|
|
99 #define MARK_GREY(ptr) set_mark_bit (ptr, GREY)
|
|
100 #define MARK_BLACK(ptr) set_mark_bit (ptr, BLACK)
|
|
101
|
|
102 #define MARKED_WHITE_P(ptr) (get_mark_bit (ptr) == WHITE)
|
|
103 #define MARKED_GREY_P(ptr) (get_mark_bit (ptr) == GREY)
|
|
104 #define MARKED_BLACK_P(ptr) (get_mark_bit (ptr) == BLACK)
|
2720
|
105
|
3092
|
106 /* The finalizer of every not marked object is called. The macro
|
2720
|
107 MC_ALLOC_CALL_FINALIZER has to be defined and call the finalizer of
|
|
108 the object. */
|
|
109 void mc_finalize (void);
|
|
110
|
|
111 /* All not marked objects of the used heap are freed. */
|
|
112 void mc_sweep (void);
|
|
113
|
|
114
|
|
115
|
|
116 /* Portable dumper related functions and macros: */
|
|
117
|
|
118 /* The finalizer for disksave of every object is called to shrink the
|
3092
|
119 dump image. The macro MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE has to
|
2720
|
120 be defined and call the finalizer for disksave of the object. */
|
|
121 void mc_finalize_for_disksave (void);
|
|
122
|
|
123
|
|
124
|
|
125 /* Functions and macros related with allocation statistics: */
|
|
126
|
|
127 #ifdef MEMORY_USAGE_STATS
|
|
128 /* Returns the real size, including overhead, which is actually alloced
|
|
129 for an object with given claimed_size. */
|
|
130 Bytecount mc_alloced_storage_size (Bytecount claimed_size,
|
|
131 struct overhead_stats *stats);
|
|
132 #endif /* MEMORY_USAGE_STATS */
|
|
133
|
3092
|
134
|
|
135 /* Incremental Garbage Collector / Write Barrier Support: */
|
|
136
|
|
137 /* Return the PAGESIZE the allocator uses. Generally equals to the
|
|
138 system's PAGESIZE. */
|
|
139 EMACS_INT mc_get_page_size (void);
|
|
140
|
|
141 /* Is the fault at ptr on a protected page? */
|
|
142 EMACS_INT fault_on_protected_page (void *ptr);
|
|
143
|
|
144 /* Remove protection (if there) of heap page of given page header
|
|
145 ph. */
|
|
146 void protect_heap_pages (void);
|
|
147
|
|
148 /* Remove protection for all heap pages which are protected. */
|
|
149 void unprotect_heap_pages (void);
|
|
150
|
|
151 /* Remove protection and mark page dirty. */
|
|
152 void unprotect_page_and_mark_dirty (void *ptr);
|
|
153
|
|
154 /* Repush all objects on dirty pages onto the mark stack. Return
|
|
155 number of repushed objects. */
|
|
156 int repush_all_objects_on_page (void *ptr);
|
|
157
|
|
158 /* Mark black if object is currently grey. */
|
|
159 EMACS_INT maybe_mark_black (void *ptr);
|
|
160
|
|
161 /* Only for debugging---not used anywhere in the sources. */
|
|
162 EMACS_INT object_on_heap_p (void *ptr);
|
|
163
|
2720
|
164 END_C_DECLS
|
|
165
|
|
166 #endif /* INCLUDED_mc_alloc_h_ */
|