comparison src/mc-alloc.h @ 5118:e0db3c197671 ben-lisp-object

merge up to latest default branch, doesn't compile yet
author Ben Wing <ben@xemacs.org>
date Sat, 26 Dec 2009 21:18:49 -0600
parents 229bd619740a
children 1fae11d56ad2
comparison
equal deleted inserted replaced
5117:3742ea8250b5 5118:e0db3c197671
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
30 /* Set to 1 if memory becomes short. */
31 extern EMACS_INT memory_shortage;
42 32
43 33
44 /* Allocation related functions and macros: */ 34 /* Internal Allocator Functions: */
45 35
46 /* Builds and initializes all needed datastructures of the new allocator. */ 36 /* Initialize the allocator. This has to be called prior to
37 requesting memory. */
47 void init_mc_allocator (void); 38 void init_mc_allocator (void);
48 39
49 /* Returns a pointer to a block of memory of given size on the used heap. */ 40 /* Allocate a block of memory of given size and return the pointer to
41 it. */
50 void *mc_alloc (size_t size); 42 void *mc_alloc (size_t size);
51 43
52 /* Frees the object pointed to by pointer. */ 44 /* Allocate a block of memory as an array with elemcount elements of
53 void mc_free (void *ptr); 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);
54 51
55 /* Modifies the size of the memory block pointed to by ptr. The 52 /* Modify the size of the memory block pointed to by ptr. Return the
56 Address of the new block of given size is returned. */ 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.*/
57 void *mc_realloc (void *ptr, size_t size); 57 void *mc_realloc (void *ptr, size_t size);
58
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);
58 66
59 67
60 68
61 /* Garbage collection related functions and macros: */ 69 /* Garbage collection related functions and macros: */
70
71 enum mark_bit_colors
72 {
73 WHITE = 0,
74 BLACK = 1,
75 GREY = 2
76 };
62 77
63 /* Set the mark bit of the object pointed to by ptr to value.*/ 78 /* Set the mark bit of the object pointed to by ptr to value.*/
64 void set_mark_bit (void *ptr, EMACS_INT value); 79 void set_mark_bit (void *ptr, EMACS_INT value);
65 80
66 /* Return the mark bit of the object pointed to by ptr. */ 81 /* Return the mark bit of the object pointed to by ptr. */
67 EMACS_INT get_mark_bit (void *ptr); 82 EMACS_INT get_mark_bit (void *ptr);
68 83
69 /* mark bit macros */ 84 /* mark bit macros */
70 /* Returns true if the mark bit of the object pointed to by ptr is set. */ 85 /* Returns true if the mark bit of the object pointed to by ptr is set. */
71 #define MARKED_P(ptr) (get_mark_bit (ptr) == 1) 86 #define MARKED_P(ptr) (get_mark_bit (ptr) != WHITE)
72 87
73 /* Marks the object pointed to by ptr (sets the mark bit to 1). */ 88 /* Marks the object pointed to by ptr (sets the mark bit to 1). */
74 #define MARK(ptr) set_mark_bit (ptr, 1) 89 #define MARK(ptr) set_mark_bit (ptr, BLACK)
75 90
76 /* Unmarks the object pointed to by ptr (sets the mark bit to 0). */ 91 /* Unmarks the object pointed to by ptr (sets the mark bit to 0). */
77 #define UNMARK(ptr) set_mark_bit (ptr, 0) 92 #define UNMARK(ptr) set_mark_bit (ptr, WHITE)
78 93
79 /* The finalizer of every not marked object is called. The macro 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)
101
102 /* 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 103 MC_ALLOC_CALL_FINALIZER has to be defined and call the finalizer of
81 the object. */ 104 the object. Returns number of processed pages. */
82 void mc_finalize (void); 105 EMACS_INT mc_finalize (void);
83 106
84 /* All not marked objects of the used heap are freed. */ 107 /* All not marked objects of the used heap are freed. Returns number
85 void mc_sweep (void); 108 of processed pages. */
109 EMACS_INT mc_sweep (void);
86 110
87 111
88 112
89 /* Portable dumper related functions and macros: */ 113 /* Portable dumper related functions and macros: */
90 114
91 /* The finalizer for disksave of every object is called to shrink the 115 /* 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 116 dump image. The macro MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE has to
93 be defined and call the finalizer for disksave of the object. */ 117 be defined and call the finalizer for disksave of the object.
94 void mc_finalize_for_disksave (void); 118 Returns number of processed pages. */
95 119 EMACS_INT mc_finalize_for_disksave (void);
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 120
108 121
109 122
110 /* Functions and macros related with allocation statistics: */ 123 /* Functions and macros related with allocation statistics: */
111 124
114 for an object with given claimed_size. */ 127 for an object with given claimed_size. */
115 Bytecount mc_alloced_storage_size (Bytecount claimed_size, 128 Bytecount mc_alloced_storage_size (Bytecount claimed_size,
116 struct overhead_stats *stats); 129 struct overhead_stats *stats);
117 #endif /* MEMORY_USAGE_STATS */ 130 #endif /* MEMORY_USAGE_STATS */
118 131
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
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);
145
146 /* Remove protection for all heap pages which are protected. Returns
147 number of processed pages. */
148 EMACS_INT unprotect_heap_pages (void);
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
119 END_C_DECLS 163 END_C_DECLS
120 164
121 #endif /* INCLUDED_mc_alloc_h_ */ 165 #endif /* INCLUDED_mc_alloc_h_ */