Mercurial > hg > xemacs-beta
annotate src/alloc.c @ 5158:9e0b43d3095c
more cleanups to object-memory-usage stuff
-------------------- ChangeLog entries follow: --------------------
lisp/ChangeLog addition:
2010-03-19 Ben Wing <ben@xemacs.org>
* diagnose.el (show-object-memory-usage-stats):
Rewrite to take into account non-lisp-storage statistics
returned by garbage-collect-1 and friends.
src/ChangeLog addition:
2010-03-19 Ben Wing <ben@xemacs.org>
* alloc.c:
* alloc.c (struct):
* alloc.c (tick_lrecord_stats):
* alloc.c (gc_sweep_1):
* alloc.c (finish_object_memory_usage_stats):
* alloc.c (object_memory_usage_stats):
* alloc.c (compute_memusage_stats_length):
Call new memory-usage mechanism at sweep time to compute extra
memory utilization for all objects. Add up the values element-by-
element to get an aggregrate set of statistics, where each is the
sum of the values of a single statistic across different objects
of the same type. At end of sweep time, call
finish_object_memory_usage_stats() to add up all the aggreggrate
stats that are related to non-Lisp memory storage to compute
a single value, and add it to the list of values returned by
`garbage-collect' and `object-memory-usage-stats'.
* buffer.c (compute_buffer_text_usage):
Don't crash on buffers without text (killed buffers?) and don't
double-count indirect buffers.
* elhash.c:
* elhash.c (hash_table_objects_create):
* elhash.c (vars_of_elhash):
* symsinit.h:
Add memory-usage method to count the size of `hentries'.
* emacs.c (main_1):
Call new functions in elhash.c, frame.c at init.
* frame.c:
* frame.c (compute_frame_usage):
* frame.c (frame_memory_usage):
* frame.c (frame_objects_create):
* symsinit.h:
Add memory-usage method to count gutter display structures,
subwindow exposures.
* gc.c (gc_finish):
* lisp.h:
Declare finish_object_memory_usage_stats(), call it in gc_finish().
* lrecord.h (struct lrecord_implementation):
* lrecord.h (INIT_MEMORY_USAGE_STATS):
New value in implementation struct to track number of non-Lisp-memory
statistics. Computed in alloc.c.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Fri, 19 Mar 2010 14:47:44 -0500 |
parents | 1fae11d56ad2 |
children | cb303ff63e76 |
rev | line source |
---|---|
428 | 1 /* Storage allocation and gc for XEmacs Lisp interpreter. |
2 Copyright (C) 1985-1998 Free Software Foundation, Inc. | |
3 Copyright (C) 1995 Sun Microsystems, Inc. | |
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
4 Copyright (C) 1995, 1996, 2001, 2002, 2003, 2004, 2005, 2010 Ben Wing. |
428 | 5 |
6 This file is part of XEmacs. | |
7 | |
8 XEmacs is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
10 Free Software Foundation; either version 2, or (at your option) any | |
11 later version. | |
12 | |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with XEmacs; see the file COPYING. If not, write to | |
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 Boston, MA 02111-1307, USA. */ | |
22 | |
23 /* Synched up with: FSF 19.28, Mule 2.0. Substantially different from | |
24 FSF. */ | |
25 | |
26 /* Authorship: | |
27 | |
28 FSF: Original version; a long time ago. | |
29 Mly: Significantly rewritten to use new 3-bit tags and | |
30 nicely abstracted object definitions, for 19.8. | |
31 JWZ: Improved code to keep track of purespace usage and | |
32 issue nice purespace and GC stats. | |
33 Ben Wing: Cleaned up frob-block lrecord code, added error-checking | |
34 and various changes for Mule, for 19.12. | |
35 Added bit vectors for 19.13. | |
36 Added lcrecord lists for 19.14. | |
37 slb: Lots of work on the purification and dump time code. | |
38 Synched Doug Lea malloc support from Emacs 20.2. | |
442 | 39 og: Killed the purespace. Portable dumper (moved to dumper.c) |
428 | 40 */ |
41 | |
42 #include <config.h> | |
43 #include "lisp.h" | |
44 | |
45 #include "backtrace.h" | |
46 #include "buffer.h" | |
47 #include "bytecode.h" | |
48 #include "chartab.h" | |
49 #include "device.h" | |
50 #include "elhash.h" | |
51 #include "events.h" | |
872 | 52 #include "extents-impl.h" |
1204 | 53 #include "file-coding.h" |
872 | 54 #include "frame-impl.h" |
3092 | 55 #include "gc.h" |
428 | 56 #include "glyphs.h" |
57 #include "opaque.h" | |
1204 | 58 #include "lstream.h" |
872 | 59 #include "process.h" |
1292 | 60 #include "profile.h" |
428 | 61 #include "redisplay.h" |
62 #include "specifier.h" | |
63 #include "sysfile.h" | |
442 | 64 #include "sysdep.h" |
428 | 65 #include "window.h" |
3092 | 66 #ifdef NEW_GC |
67 #include "vdb.h" | |
68 #endif /* NEW_GC */ | |
428 | 69 #include "console-stream.h" |
70 | |
71 #ifdef DOUG_LEA_MALLOC | |
72 #include <malloc.h> | |
73 #endif | |
4803
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
74 #ifdef USE_VALGRIND |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
75 #include <valgrind/memcheck.h> |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
76 #endif |
428 | 77 |
78 EXFUN (Fgarbage_collect, 0); | |
79 | |
80 #if 0 /* this is _way_ too slow to be part of the standard debug options */ | |
81 #if defined(DEBUG_XEMACS) && defined(MULE) | |
82 #define VERIFY_STRING_CHARS_INTEGRITY | |
83 #endif | |
84 #endif | |
85 | |
86 /* Define this to use malloc/free with no freelist for all datatypes, | |
87 the hope being that some debugging tools may help detect | |
88 freed memory references */ | |
89 #ifdef USE_DEBUG_MALLOC /* Taking the above comment at face value -slb */ | |
90 #include <dmalloc.h> | |
91 #define ALLOC_NO_POOLS | |
92 #endif | |
93 | |
94 #ifdef DEBUG_XEMACS | |
458 | 95 static Fixnum debug_allocation; |
96 static Fixnum debug_allocation_backtrace_length; | |
428 | 97 #endif |
98 | |
851 | 99 int need_to_check_c_alloca; |
887 | 100 int need_to_signal_post_gc; |
851 | 101 int funcall_allocation_flag; |
102 Bytecount __temp_alloca_size__; | |
103 Bytecount funcall_alloca_count; | |
814 | 104 |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
105 /* All the built-in lisp object types are enumerated in `enum lrecord_type'. |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
106 Additional ones may be defined by a module (none yet). We leave some |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
107 room in `lrecord_implementations_table' for such new lisp object types. */ |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
108 struct lrecord_implementation *lrecord_implementations_table[(int)lrecord_type_last_built_in_type + MODULE_DEFINABLE_TYPE_COUNT]; |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
109 int lrecord_type_count = lrecord_type_last_built_in_type; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
110 |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
111 /* This is just for use by the printer, to allow things to print uniquely. |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
112 We have a separate UID space for each object. (Important because the |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
113 UID is only 20 bits in old-GC, and 22 in NEW_GC.) */ |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
114 int lrecord_uid_counter[countof (lrecord_implementations_table)]; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
115 |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
116 /* Non-zero means we're in the process of doing the dump */ |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
117 int purify_flag; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
118 |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
119 /* Non-zero means we're pdumping out or in */ |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
120 #ifdef PDUMP |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
121 int in_pdump; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
122 #endif |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
123 |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
124 #ifdef ERROR_CHECK_TYPES |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
125 |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
126 Error_Behavior ERROR_ME, ERROR_ME_NOT, ERROR_ME_WARN, ERROR_ME_DEBUG_WARN; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
127 |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
128 #endif |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
129 |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
130 #ifdef MEMORY_USAGE_STATS |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
131 Lisp_Object Qobject_actually_requested, Qobject_malloc_overhead; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
132 Lisp_Object Qother_memory_actually_requested, Qother_memory_malloc_overhead; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
133 Lisp_Object Qother_memory_dynarr_overhead, Qother_memory_gap_overhead; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
134 #endif /* MEMORY_USAGE_STATS */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
135 |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
136 /* Very cheesy ways of figuring out how much memory is being used for |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
137 data. #### Need better (system-dependent) ways. */ |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
138 void *minimum_address_seen; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
139 void *maximum_address_seen; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
140 |
814 | 141 /* Determine now whether we need to garbage collect or not, to make |
142 Ffuncall() faster */ | |
143 #define INCREMENT_CONS_COUNTER_1(size) \ | |
144 do \ | |
145 { \ | |
146 consing_since_gc += (size); \ | |
1292 | 147 total_consing += (size); \ |
148 if (profiling_active) \ | |
149 profile_record_consing (size); \ | |
814 | 150 recompute_need_to_garbage_collect (); \ |
151 } while (0) | |
428 | 152 |
153 #define debug_allocation_backtrace() \ | |
154 do { \ | |
155 if (debug_allocation_backtrace_length > 0) \ | |
156 debug_short_backtrace (debug_allocation_backtrace_length); \ | |
157 } while (0) | |
158 | |
159 #ifdef DEBUG_XEMACS | |
801 | 160 #define INCREMENT_CONS_COUNTER(foosize, type) \ |
161 do { \ | |
162 if (debug_allocation) \ | |
163 { \ | |
164 stderr_out ("allocating %s (size %ld)\n", type, \ | |
165 (long) foosize); \ | |
166 debug_allocation_backtrace (); \ | |
167 } \ | |
168 INCREMENT_CONS_COUNTER_1 (foosize); \ | |
428 | 169 } while (0) |
170 #define NOSEEUM_INCREMENT_CONS_COUNTER(foosize, type) \ | |
171 do { \ | |
172 if (debug_allocation > 1) \ | |
173 { \ | |
801 | 174 stderr_out ("allocating noseeum %s (size %ld)\n", type, \ |
175 (long) foosize); \ | |
428 | 176 debug_allocation_backtrace (); \ |
177 } \ | |
178 INCREMENT_CONS_COUNTER_1 (foosize); \ | |
179 } while (0) | |
180 #else | |
181 #define INCREMENT_CONS_COUNTER(size, type) INCREMENT_CONS_COUNTER_1 (size) | |
182 #define NOSEEUM_INCREMENT_CONS_COUNTER(size, type) \ | |
183 INCREMENT_CONS_COUNTER_1 (size) | |
184 #endif | |
185 | |
3092 | 186 #ifdef NEW_GC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
187 /* [[ The call to recompute_need_to_garbage_collect is moved to |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
188 free_normal_lisp_object, since DECREMENT_CONS_COUNTER is extensively called |
3092 | 189 during sweep and recomputing need_to_garbage_collect all the time |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
190 is not needed. ]] -- not accurate! */ |
3092 | 191 #define DECREMENT_CONS_COUNTER(size) do { \ |
192 consing_since_gc -= (size); \ | |
193 total_consing -= (size); \ | |
194 if (profiling_active) \ | |
195 profile_record_unconsing (size); \ | |
196 if (consing_since_gc < 0) \ | |
197 consing_since_gc = 0; \ | |
198 } while (0) | |
199 #else /* not NEW_GC */ | |
428 | 200 #define DECREMENT_CONS_COUNTER(size) do { \ |
201 consing_since_gc -= (size); \ | |
1292 | 202 total_consing -= (size); \ |
203 if (profiling_active) \ | |
204 profile_record_unconsing (size); \ | |
428 | 205 if (consing_since_gc < 0) \ |
206 consing_since_gc = 0; \ | |
814 | 207 recompute_need_to_garbage_collect (); \ |
428 | 208 } while (0) |
3092 | 209 #endif /*not NEW_GC */ |
428 | 210 |
3263 | 211 #ifndef NEW_GC |
428 | 212 int |
213 c_readonly (Lisp_Object obj) | |
214 { | |
215 return POINTER_TYPE_P (XTYPE (obj)) && C_READONLY (obj); | |
216 } | |
3263 | 217 #endif /* not NEW_GC */ |
428 | 218 |
219 int | |
220 lisp_readonly (Lisp_Object obj) | |
221 { | |
222 return POINTER_TYPE_P (XTYPE (obj)) && LISP_READONLY (obj); | |
223 } | |
224 | |
225 | |
226 /* Maximum amount of C stack to save when a GC happens. */ | |
227 | |
228 #ifndef MAX_SAVE_STACK | |
229 #define MAX_SAVE_STACK 0 /* 16000 */ | |
230 #endif | |
231 | |
232 /* Non-zero means ignore malloc warnings. Set during initialization. */ | |
233 int ignore_malloc_warnings; | |
234 | |
235 | |
3263 | 236 #ifndef NEW_GC |
3092 | 237 void *breathing_space; |
428 | 238 |
239 void | |
240 release_breathing_space (void) | |
241 { | |
242 if (breathing_space) | |
243 { | |
244 void *tmp = breathing_space; | |
245 breathing_space = 0; | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
246 xfree (tmp); |
428 | 247 } |
248 } | |
3263 | 249 #endif /* not NEW_GC */ |
428 | 250 |
801 | 251 static void |
252 set_alloc_mins_and_maxes (void *val, Bytecount size) | |
253 { | |
254 if (!val) | |
255 return; | |
256 if ((char *) val + size > (char *) maximum_address_seen) | |
257 maximum_address_seen = (char *) val + size; | |
258 if (!minimum_address_seen) | |
259 minimum_address_seen = | |
260 #if SIZEOF_VOID_P == 8 | |
261 (void *) 0xFFFFFFFFFFFFFFFF; | |
262 #else | |
263 (void *) 0xFFFFFFFF; | |
264 #endif | |
265 if ((char *) val < (char *) minimum_address_seen) | |
266 minimum_address_seen = (char *) val; | |
267 } | |
268 | |
1315 | 269 #ifdef ERROR_CHECK_MALLOC |
3176 | 270 static int in_malloc; |
1333 | 271 extern int regex_malloc_disallowed; |
2367 | 272 |
273 #define MALLOC_BEGIN() \ | |
274 do \ | |
275 { \ | |
3176 | 276 assert (!in_malloc); \ |
2367 | 277 assert (!regex_malloc_disallowed); \ |
278 in_malloc = 1; \ | |
279 } \ | |
280 while (0) | |
281 | |
3263 | 282 #ifdef NEW_GC |
2720 | 283 #define FREE_OR_REALLOC_BEGIN(block) \ |
284 do \ | |
285 { \ | |
286 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an \ | |
287 error until much later on for many system mallocs, such as \ | |
288 the one that comes with Solaris 2.3. FMH!! */ \ | |
4938
299dce99bdad
(for main branch) when freeing check against DEADBEEF_CONSTANT since that's what we use elsewhere
Ben Wing <ben@xemacs.org>
parents:
4934
diff
changeset
|
289 assert (block != (void *) DEADBEEF_CONSTANT); \ |
2720 | 290 MALLOC_BEGIN (); \ |
291 } \ | |
292 while (0) | |
3263 | 293 #else /* not NEW_GC */ |
2367 | 294 #define FREE_OR_REALLOC_BEGIN(block) \ |
295 do \ | |
296 { \ | |
297 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an \ | |
298 error until much later on for many system mallocs, such as \ | |
299 the one that comes with Solaris 2.3. FMH!! */ \ | |
4938
299dce99bdad
(for main branch) when freeing check against DEADBEEF_CONSTANT since that's what we use elsewhere
Ben Wing <ben@xemacs.org>
parents:
4934
diff
changeset
|
300 assert (block != (void *) DEADBEEF_CONSTANT); \ |
2367 | 301 /* You cannot free something within dumped space, because there is \ |
302 no longer any sort of malloc structure associated with the block. \ | |
303 If you are tripping this, you may need to conditionalize on \ | |
304 DUMPEDP. */ \ | |
305 assert (!DUMPEDP (block)); \ | |
306 MALLOC_BEGIN (); \ | |
307 } \ | |
308 while (0) | |
3263 | 309 #endif /* not NEW_GC */ |
2367 | 310 |
311 #define MALLOC_END() \ | |
312 do \ | |
313 { \ | |
314 in_malloc = 0; \ | |
315 } \ | |
316 while (0) | |
317 | |
318 #else /* ERROR_CHECK_MALLOC */ | |
319 | |
2658 | 320 #define MALLOC_BEGIN() |
2367 | 321 #define FREE_OR_REALLOC_BEGIN(block) |
322 #define MALLOC_END() | |
323 | |
324 #endif /* ERROR_CHECK_MALLOC */ | |
325 | |
326 static void | |
327 malloc_after (void *val, Bytecount size) | |
328 { | |
329 if (!val && size != 0) | |
330 memory_full (); | |
331 set_alloc_mins_and_maxes (val, size); | |
332 } | |
333 | |
3305 | 334 /* malloc calls this if it finds we are near exhausting storage */ |
335 void | |
336 malloc_warning (const char *str) | |
337 { | |
338 if (ignore_malloc_warnings) | |
339 return; | |
340 | |
341 /* Remove the malloc lock here, because warn_when_safe may allocate | |
342 again. It is safe to remove the malloc lock here, because malloc | |
343 is already finished (malloc_warning is called via | |
344 after_morecore_hook -> check_memory_limits -> save_warn_fun -> | |
345 malloc_warning). */ | |
346 MALLOC_END (); | |
347 | |
348 warn_when_safe | |
349 (Qmemory, Qemergency, | |
350 "%s\n" | |
351 "Killing some buffers may delay running out of memory.\n" | |
352 "However, certainly by the time you receive the 95%% warning,\n" | |
353 "you should clean up, kill this Emacs, and start a new one.", | |
354 str); | |
355 } | |
356 | |
357 /* Called if malloc returns zero */ | |
358 DOESNT_RETURN | |
359 memory_full (void) | |
360 { | |
361 /* Force a GC next time eval is called. | |
362 It's better to loop garbage-collecting (we might reclaim enough | |
363 to win) than to loop beeping and barfing "Memory exhausted" | |
364 */ | |
365 consing_since_gc = gc_cons_threshold + 1; | |
366 recompute_need_to_garbage_collect (); | |
367 #ifdef NEW_GC | |
368 /* Put mc-alloc into memory shortage mode. This may keep XEmacs | |
369 alive until the garbage collector can free enough memory to get | |
370 us out of the memory exhaustion. If already in memory shortage | |
371 mode, we are in a loop and hopelessly lost. */ | |
372 if (memory_shortage) | |
373 { | |
374 fprintf (stderr, "Memory full, cannot recover.\n"); | |
375 ABORT (); | |
376 } | |
377 fprintf (stderr, | |
378 "Memory full, try to recover.\n" | |
379 "You should clean up, kill this Emacs, and start a new one.\n"); | |
380 memory_shortage++; | |
381 #else /* not NEW_GC */ | |
382 release_breathing_space (); | |
383 #endif /* not NEW_GC */ | |
384 | |
385 /* Flush some histories which might conceivably contain garbalogical | |
386 inhibitors. */ | |
387 if (!NILP (Fboundp (Qvalues))) | |
388 Fset (Qvalues, Qnil); | |
389 Vcommand_history = Qnil; | |
390 | |
391 out_of_memory ("Memory exhausted", Qunbound); | |
392 } | |
393 | |
2367 | 394 /* like malloc, calloc, realloc, free but: |
395 | |
396 -- check for no memory left | |
397 -- set internal mins and maxes | |
398 -- with error-checking on, check for reentrancy, invalid freeing, etc. | |
399 */ | |
1292 | 400 |
428 | 401 #undef xmalloc |
402 void * | |
665 | 403 xmalloc (Bytecount size) |
428 | 404 { |
1292 | 405 void *val; |
2367 | 406 MALLOC_BEGIN (); |
1292 | 407 val = malloc (size); |
2367 | 408 MALLOC_END (); |
409 malloc_after (val, size); | |
428 | 410 return val; |
411 } | |
412 | |
413 #undef xcalloc | |
414 static void * | |
665 | 415 xcalloc (Elemcount nelem, Bytecount elsize) |
428 | 416 { |
1292 | 417 void *val; |
2367 | 418 MALLOC_BEGIN (); |
1292 | 419 val= calloc (nelem, elsize); |
2367 | 420 MALLOC_END (); |
421 malloc_after (val, nelem * elsize); | |
428 | 422 return val; |
423 } | |
424 | |
425 void * | |
665 | 426 xmalloc_and_zero (Bytecount size) |
428 | 427 { |
428 return xcalloc (size, sizeof (char)); | |
429 } | |
430 | |
431 #undef xrealloc | |
432 void * | |
665 | 433 xrealloc (void *block, Bytecount size) |
428 | 434 { |
2367 | 435 FREE_OR_REALLOC_BEGIN (block); |
551 | 436 block = realloc (block, size); |
2367 | 437 MALLOC_END (); |
438 malloc_after (block, size); | |
551 | 439 return block; |
428 | 440 } |
441 | |
442 void | |
443 xfree_1 (void *block) | |
444 { | |
445 #ifdef ERROR_CHECK_MALLOC | |
446 assert (block); | |
447 #endif /* ERROR_CHECK_MALLOC */ | |
2367 | 448 FREE_OR_REALLOC_BEGIN (block); |
428 | 449 free (block); |
2367 | 450 MALLOC_END (); |
428 | 451 } |
452 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
453 void |
665 | 454 deadbeef_memory (void *ptr, Bytecount size) |
428 | 455 { |
826 | 456 UINT_32_BIT *ptr4 = (UINT_32_BIT *) ptr; |
665 | 457 Bytecount beefs = size >> 2; |
428 | 458 |
459 /* In practice, size will always be a multiple of four. */ | |
460 while (beefs--) | |
1204 | 461 (*ptr4++) = 0xDEADBEEF; /* -559038737 base 10 */ |
428 | 462 } |
463 | |
464 #undef xstrdup | |
465 char * | |
442 | 466 xstrdup (const char *str) |
428 | 467 { |
468 int len = strlen (str) + 1; /* for stupid terminating 0 */ | |
469 void *val = xmalloc (len); | |
771 | 470 |
428 | 471 if (val == 0) return 0; |
472 return (char *) memcpy (val, str, len); | |
473 } | |
474 | |
475 #ifdef NEED_STRDUP | |
476 char * | |
442 | 477 strdup (const char *s) |
428 | 478 { |
479 return xstrdup (s); | |
480 } | |
481 #endif /* NEED_STRDUP */ | |
482 | |
483 | |
3263 | 484 #ifndef NEW_GC |
428 | 485 static void * |
665 | 486 allocate_lisp_storage (Bytecount size) |
428 | 487 { |
793 | 488 void *val = xmalloc (size); |
489 /* We don't increment the cons counter anymore. Calling functions do | |
490 that now because we have two different kinds of cons counters -- one | |
491 for normal objects, and one for no-see-um conses (and possibly others | |
492 similar) where the conses are used totally internally, never escape, | |
493 and are created and then freed and shouldn't logically increment the | |
494 cons counting. #### (Or perhaps, we should decrement it when an object | |
495 get freed?) */ | |
496 | |
497 /* But we do now (as of 3-27-02) go and zero out the memory. This is a | |
498 good thing, as it will guarantee we won't get any intermittent bugs | |
1204 | 499 coming from an uninitiated field. The speed loss is unnoticeable, |
500 esp. as the objects are not large -- large stuff like buffer text and | |
501 redisplay structures are allocated separately. */ | |
793 | 502 memset (val, 0, size); |
851 | 503 |
504 if (need_to_check_c_alloca) | |
505 xemacs_c_alloca (0); | |
506 | |
793 | 507 return val; |
428 | 508 } |
3263 | 509 #endif /* not NEW_GC */ |
510 | |
511 #if defined (NEW_GC) && defined (ALLOC_TYPE_STATS) | |
2720 | 512 static struct |
513 { | |
514 int instances_in_use; | |
515 int bytes_in_use; | |
516 int bytes_in_use_including_overhead; | |
3461 | 517 } lrecord_stats [countof (lrecord_implementations_table)]; |
2720 | 518 |
519 void | |
520 init_lrecord_stats () | |
521 { | |
522 xzero (lrecord_stats); | |
523 } | |
524 | |
525 void | |
526 inc_lrecord_stats (Bytecount size, const struct lrecord_header *h) | |
527 { | |
528 int type_index = h->type; | |
529 if (!size) | |
530 size = detagged_lisp_object_size (h); | |
531 | |
532 lrecord_stats[type_index].instances_in_use++; | |
533 lrecord_stats[type_index].bytes_in_use += size; | |
534 lrecord_stats[type_index].bytes_in_use_including_overhead | |
535 #ifdef MEMORY_USAGE_STATS | |
536 += mc_alloced_storage_size (size, 0); | |
537 #else /* not MEMORY_USAGE_STATS */ | |
538 += size; | |
539 #endif /* not MEMORY_USAGE_STATS */ | |
540 } | |
541 | |
542 void | |
543 dec_lrecord_stats (Bytecount size_including_overhead, | |
544 const struct lrecord_header *h) | |
545 { | |
546 int type_index = h->type; | |
2775 | 547 int size = detagged_lisp_object_size (h); |
2720 | 548 |
549 lrecord_stats[type_index].instances_in_use--; | |
2775 | 550 lrecord_stats[type_index].bytes_in_use -= size; |
2720 | 551 lrecord_stats[type_index].bytes_in_use_including_overhead |
552 -= size_including_overhead; | |
553 | |
2775 | 554 DECREMENT_CONS_COUNTER (size); |
2720 | 555 } |
3092 | 556 |
557 int | |
558 lrecord_stats_heap_size (void) | |
559 { | |
560 int i; | |
561 int size = 0; | |
3461 | 562 for (i = 0; i < countof (lrecord_implementations_table); i++) |
3092 | 563 size += lrecord_stats[i].bytes_in_use; |
564 return size; | |
565 } | |
3263 | 566 #endif /* NEW_GC && ALLOC_TYPE_STATS */ |
567 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
568 #define assert_proper_sizing(size) \ |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
569 type_checking_assert \ |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
570 (implementation->static_size == 0 ? \ |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
571 implementation->size_in_bytes_method != NULL : \ |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
572 implementation->size_in_bytes_method == NULL && \ |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
573 implementation->static_size == size) |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
574 |
3263 | 575 #ifndef NEW_GC |
442 | 576 /* lcrecords are chained together through their "next" field. |
577 After doing the mark phase, GC will walk this linked list | |
578 and free any lcrecord which hasn't been marked. */ | |
3024 | 579 static struct old_lcrecord_header *all_lcrecords; |
3263 | 580 #endif /* not NEW_GC */ |
581 | |
582 #ifdef NEW_GC | |
2720 | 583 /* The basic lrecord allocation functions. See lrecord.h for details. */ |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
584 static Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
585 alloc_sized_lrecord_1 (Bytecount size, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
586 const struct lrecord_implementation *implementation, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
587 int noseeum) |
2720 | 588 { |
589 struct lrecord_header *lheader; | |
590 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
591 assert_proper_sizing (size); |
2720 | 592 |
593 lheader = (struct lrecord_header *) mc_alloc (size); | |
594 gc_checking_assert (LRECORD_FREE_P (lheader)); | |
595 set_lheader_implementation (lheader, implementation); | |
2994 | 596 #ifdef ALLOC_TYPE_STATS |
2720 | 597 inc_lrecord_stats (size, lheader); |
2994 | 598 #endif /* ALLOC_TYPE_STATS */ |
3263 | 599 if (implementation->finalizer) |
600 add_finalizable_obj (wrap_pointer_1 (lheader)); | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
601 if (noseeum) |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
602 NOSEEUM_INCREMENT_CONS_COUNTER (size, implementation->name); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
603 else |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
604 INCREMENT_CONS_COUNTER (size, implementation->name); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
605 return wrap_pointer_1 (lheader); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
606 } |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
607 |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
608 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
609 alloc_sized_lrecord (Bytecount size, |
3092 | 610 const struct lrecord_implementation *implementation) |
611 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
612 return alloc_sized_lrecord_1 (size, implementation, 0); |
2720 | 613 } |
614 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
615 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
616 noseeum_alloc_sized_lrecord (Bytecount size, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
617 const struct lrecord_implementation * |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
618 implementation) |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
619 { |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
620 return alloc_sized_lrecord_1 (size, implementation, 1); |
2720 | 621 } |
622 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
623 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
624 alloc_lrecord (const struct lrecord_implementation *implementation) |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
625 { |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
626 type_checking_assert (implementation->static_size > 0); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
627 return alloc_sized_lrecord (implementation->static_size, implementation); |
2720 | 628 } |
629 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
630 Lisp_Object |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
631 noseeum_alloc_lrecord (const struct lrecord_implementation *implementation) |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
632 { |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
633 type_checking_assert (implementation->static_size > 0); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
634 return noseeum_alloc_sized_lrecord (implementation->static_size, implementation); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
635 } |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
636 |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
637 Lisp_Object |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
638 alloc_sized_lrecord_array (Bytecount size, int elemcount, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
639 const struct lrecord_implementation *implementation) |
3092 | 640 { |
641 struct lrecord_header *lheader; | |
642 Rawbyte *start, *stop; | |
643 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
644 assert_proper_sizing (size); |
3092 | 645 |
646 lheader = (struct lrecord_header *) mc_alloc_array (size, elemcount); | |
647 gc_checking_assert (LRECORD_FREE_P (lheader)); | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
648 |
3092 | 649 for (start = (Rawbyte *) lheader, |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
650 /* #### FIXME: why is this -1 present? */ |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
651 stop = ((Rawbyte *) lheader) + (size * elemcount -1); |
3092 | 652 start < stop; start += size) |
653 { | |
654 struct lrecord_header *lh = (struct lrecord_header *) start; | |
655 set_lheader_implementation (lh, implementation); | |
656 #ifdef ALLOC_TYPE_STATS | |
657 inc_lrecord_stats (size, lh); | |
658 #endif /* not ALLOC_TYPE_STATS */ | |
3263 | 659 if (implementation->finalizer) |
660 add_finalizable_obj (wrap_pointer_1 (lh)); | |
3092 | 661 } |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
662 |
3092 | 663 INCREMENT_CONS_COUNTER (size * elemcount, implementation->name); |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
664 return wrap_pointer_1 (lheader); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
665 } |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
666 |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
667 Lisp_Object |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
668 alloc_lrecord_array (int elemcount, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
669 const struct lrecord_implementation *implementation) |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
670 { |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
671 type_checking_assert (implementation->static_size > 0); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
672 return alloc_sized_lrecord_array (implementation->static_size, elemcount, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
673 implementation); |
3092 | 674 } |
675 | |
3263 | 676 #else /* not NEW_GC */ |
428 | 677 |
1204 | 678 /* The most basic of the lcrecord allocation functions. Not usually called |
679 directly. Allocates an lrecord not managed by any lcrecord-list, of a | |
680 specified size. See lrecord.h. */ | |
681 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
682 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
683 old_alloc_sized_lcrecord (Bytecount size, |
3024 | 684 const struct lrecord_implementation *implementation) |
685 { | |
686 struct old_lcrecord_header *lcheader; | |
428 | 687 |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
688 assert_proper_sizing (size); |
442 | 689 type_checking_assert |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
690 (!implementation->frob_block_p |
442 | 691 && |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
692 !(implementation->hash == NULL && implementation->equal != NULL)); |
428 | 693 |
3024 | 694 lcheader = (struct old_lcrecord_header *) allocate_lisp_storage (size); |
442 | 695 set_lheader_implementation (&lcheader->lheader, implementation); |
428 | 696 lcheader->next = all_lcrecords; |
697 all_lcrecords = lcheader; | |
698 INCREMENT_CONS_COUNTER (size, implementation->name); | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
699 return wrap_pointer_1 (lcheader); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
700 } |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
701 |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
702 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
703 old_alloc_lcrecord (const struct lrecord_implementation *implementation) |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
704 { |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
705 type_checking_assert (implementation->static_size > 0); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
706 return old_alloc_sized_lcrecord (implementation->static_size, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
707 implementation); |
428 | 708 } |
709 | |
710 #if 0 /* Presently unused */ | |
711 /* Very, very poor man's EGC? | |
712 * This may be slow and thrash pages all over the place. | |
713 * Only call it if you really feel you must (and if the | |
714 * lrecord was fairly recently allocated). | |
715 * Otherwise, just let the GC do its job -- that's what it's there for | |
716 */ | |
717 void | |
3024 | 718 very_old_free_lcrecord (struct old_lcrecord_header *lcrecord) |
428 | 719 { |
720 if (all_lcrecords == lcrecord) | |
721 { | |
722 all_lcrecords = lcrecord->next; | |
723 } | |
724 else | |
725 { | |
3024 | 726 struct old_lcrecord_header *header = all_lcrecords; |
428 | 727 for (;;) |
728 { | |
3024 | 729 struct old_lcrecord_header *next = header->next; |
428 | 730 if (next == lcrecord) |
731 { | |
732 header->next = lrecord->next; | |
733 break; | |
734 } | |
735 else if (next == 0) | |
2500 | 736 ABORT (); |
428 | 737 else |
738 header = next; | |
739 } | |
740 } | |
741 if (lrecord->implementation->finalizer) | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
742 lrecord->implementation->finalizer (wrap_pointer_1 (lrecord)); |
428 | 743 xfree (lrecord); |
744 return; | |
745 } | |
746 #endif /* Unused */ | |
3263 | 747 #endif /* not NEW_GC */ |
428 | 748 |
749 | |
750 static void | |
751 disksave_object_finalization_1 (void) | |
752 { | |
3263 | 753 #ifdef NEW_GC |
2720 | 754 mc_finalize_for_disksave (); |
3263 | 755 #else /* not NEW_GC */ |
3024 | 756 struct old_lcrecord_header *header; |
428 | 757 |
758 for (header = all_lcrecords; header; header = header->next) | |
759 { | |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
760 struct lrecord_header *objh = &header->lheader; |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
761 const struct lrecord_implementation *imp = LHEADER_IMPLEMENTATION (objh); |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
762 #if 0 /* possibly useful for debugging */ |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
763 if (!RECORD_DUMPABLE (objh) && !objh->free) |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
764 { |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
765 stderr_out ("Disksaving a non-dumpable object: "); |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
766 debug_print (wrap_pointer_1 (header)); |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
767 } |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
768 #endif |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
769 if (imp->disksave && !objh->free) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
770 (imp->disksave) (wrap_pointer_1 (header)); |
428 | 771 } |
3263 | 772 #endif /* not NEW_GC */ |
428 | 773 } |
774 | |
1204 | 775 /* Bitwise copy all parts of a Lisp object other than the header */ |
776 | |
777 void | |
778 copy_lisp_object (Lisp_Object dst, Lisp_Object src) | |
779 { | |
780 const struct lrecord_implementation *imp = | |
781 XRECORD_LHEADER_IMPLEMENTATION (src); | |
782 Bytecount size = lisp_object_size (src); | |
783 | |
784 assert (imp == XRECORD_LHEADER_IMPLEMENTATION (dst)); | |
785 assert (size == lisp_object_size (dst)); | |
786 | |
3263 | 787 #ifdef NEW_GC |
2720 | 788 memcpy ((char *) XRECORD_LHEADER (dst) + sizeof (struct lrecord_header), |
789 (char *) XRECORD_LHEADER (src) + sizeof (struct lrecord_header), | |
790 size - sizeof (struct lrecord_header)); | |
3263 | 791 #else /* not NEW_GC */ |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
792 if (imp->frob_block_p) |
1204 | 793 memcpy ((char *) XRECORD_LHEADER (dst) + sizeof (struct lrecord_header), |
794 (char *) XRECORD_LHEADER (src) + sizeof (struct lrecord_header), | |
795 size - sizeof (struct lrecord_header)); | |
796 else | |
3024 | 797 memcpy ((char *) XRECORD_LHEADER (dst) + |
798 sizeof (struct old_lcrecord_header), | |
799 (char *) XRECORD_LHEADER (src) + | |
800 sizeof (struct old_lcrecord_header), | |
801 size - sizeof (struct old_lcrecord_header)); | |
3263 | 802 #endif /* not NEW_GC */ |
1204 | 803 } |
804 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
805 /* Zero out all parts of a Lisp object other than the header, for a |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
806 variable-sized object. The size needs to be given explicitly because |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
807 at the time this is called, the contents of the object may not be |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
808 defined, or may not be set up in such a way that we can reliably |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
809 retrieve the size, since it may depend on settings inside of the object. */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
810 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
811 void |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
812 zero_sized_lisp_object (Lisp_Object obj, Bytecount size) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
813 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
814 #ifndef NEW_GC |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
815 const struct lrecord_implementation *imp = |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
816 XRECORD_LHEADER_IMPLEMENTATION (obj); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
817 #endif /* not NEW_GC */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
818 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
819 #ifdef NEW_GC |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
820 memset ((char *) XRECORD_LHEADER (obj) + sizeof (struct lrecord_header), 0, |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
821 size - sizeof (struct lrecord_header)); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
822 #else /* not NEW_GC */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
823 if (imp->frob_block_p) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
824 memset ((char *) XRECORD_LHEADER (obj) + sizeof (struct lrecord_header), 0, |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
825 size - sizeof (struct lrecord_header)); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
826 else |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
827 memset ((char *) XRECORD_LHEADER (obj) + |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
828 sizeof (struct old_lcrecord_header), 0, |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
829 size - sizeof (struct old_lcrecord_header)); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
830 #endif /* not NEW_GC */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
831 } |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
832 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
833 /* Zero out all parts of a Lisp object other than the header, for an object |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
834 that isn't variable-size. Objects that are variable-size need to use |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
835 zero_sized_lisp_object(). |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
836 */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
837 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
838 void |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
839 zero_nonsized_lisp_object (Lisp_Object obj) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
840 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
841 const struct lrecord_implementation *imp = |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
842 XRECORD_LHEADER_IMPLEMENTATION (obj); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
843 assert (!imp->size_in_bytes_method); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
844 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
845 zero_sized_lisp_object (obj, lisp_object_size (obj)); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
846 } |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
847 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
848 #ifdef MEMORY_USAGE_STATS |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
849 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
850 Bytecount |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
851 lisp_object_storage_size (Lisp_Object obj, struct usage_stats *ustats) |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
852 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
853 #ifndef NEW_GC |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
854 const struct lrecord_implementation *imp = |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
855 XRECORD_LHEADER_IMPLEMENTATION (obj); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
856 #endif /* not NEW_GC */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
857 Bytecount size = lisp_object_size (obj); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
858 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
859 #ifdef NEW_GC |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
860 return mc_alloced_storage_size (size, ustats); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
861 #else |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
862 if (imp->frob_block_p) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
863 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
864 Bytecount overhead = fixed_type_block_overhead (size); |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
865 if (ustats) |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
866 { |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
867 ustats->was_requested += size; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
868 ustats->malloc_overhead += overhead; |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
869 } |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
870 return size + overhead; |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
871 } |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
872 else |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
873 return malloced_storage_size (XPNTR (obj), size, ustats); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
874 #endif |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
875 } |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
876 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
877 #endif /* MEMORY_USAGE_STATS */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
878 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
879 void |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
880 free_normal_lisp_object (Lisp_Object obj) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
881 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
882 #ifndef NEW_GC |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
883 const struct lrecord_implementation *imp = |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
884 XRECORD_LHEADER_IMPLEMENTATION (obj); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
885 #endif /* not NEW_GC */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
886 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
887 #ifdef NEW_GC |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
888 /* Manual frees are not allowed with asynchronous finalization */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
889 return; |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
890 #else |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
891 assert (!imp->frob_block_p); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
892 assert (!imp->size_in_bytes_method); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
893 old_free_lcrecord (obj); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
894 #endif |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
895 } |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
896 |
428 | 897 |
898 /************************************************************************/ | |
899 /* Debugger support */ | |
900 /************************************************************************/ | |
901 /* Give gdb/dbx enough information to decode Lisp Objects. We make | |
902 sure certain symbols are always defined, so gdb doesn't complain | |
438 | 903 about expressions in src/.gdbinit. See src/.gdbinit or src/.dbxrc |
904 to see how this is used. */ | |
428 | 905 |
458 | 906 EMACS_UINT dbg_valmask = ((1UL << VALBITS) - 1) << GCBITS; |
907 EMACS_UINT dbg_typemask = (1UL << GCTYPEBITS) - 1; | |
428 | 908 |
909 #ifdef USE_UNION_TYPE | |
458 | 910 unsigned char dbg_USE_UNION_TYPE = 1; |
428 | 911 #else |
458 | 912 unsigned char dbg_USE_UNION_TYPE = 0; |
428 | 913 #endif |
914 | |
458 | 915 unsigned char dbg_valbits = VALBITS; |
916 unsigned char dbg_gctypebits = GCTYPEBITS; | |
917 | |
918 /* On some systems, the above definitions will be optimized away by | |
919 the compiler or linker unless they are referenced in some function. */ | |
920 long dbg_inhibit_dbg_symbol_deletion (void); | |
921 long | |
922 dbg_inhibit_dbg_symbol_deletion (void) | |
923 { | |
924 return | |
925 (dbg_valmask + | |
926 dbg_typemask + | |
927 dbg_USE_UNION_TYPE + | |
928 dbg_valbits + | |
929 dbg_gctypebits); | |
930 } | |
428 | 931 |
932 /* Macros turned into functions for ease of debugging. | |
933 Debuggers don't know about macros! */ | |
934 int dbg_eq (Lisp_Object obj1, Lisp_Object obj2); | |
935 int | |
936 dbg_eq (Lisp_Object obj1, Lisp_Object obj2) | |
937 { | |
938 return EQ (obj1, obj2); | |
939 } | |
940 | |
941 | |
3263 | 942 #ifdef NEW_GC |
3017 | 943 #define DECLARE_FIXED_TYPE_ALLOC(type, structture) struct __foo__ |
944 #else | |
428 | 945 /************************************************************************/ |
946 /* Fixed-size type macros */ | |
947 /************************************************************************/ | |
948 | |
949 /* For fixed-size types that are commonly used, we malloc() large blocks | |
950 of memory at a time and subdivide them into chunks of the correct | |
951 size for an object of that type. This is more efficient than | |
952 malloc()ing each object separately because we save on malloc() time | |
953 and overhead due to the fewer number of malloc()ed blocks, and | |
954 also because we don't need any extra pointers within each object | |
955 to keep them threaded together for GC purposes. For less common | |
956 (and frequently large-size) types, we use lcrecords, which are | |
957 malloc()ed individually and chained together through a pointer | |
958 in the lcrecord header. lcrecords do not need to be fixed-size | |
959 (i.e. two objects of the same type need not have the same size; | |
960 however, the size of a particular object cannot vary dynamically). | |
961 It is also much easier to create a new lcrecord type because no | |
962 additional code needs to be added to alloc.c. Finally, lcrecords | |
963 may be more efficient when there are only a small number of them. | |
964 | |
965 The types that are stored in these large blocks (or "frob blocks") | |
1983 | 966 are cons, all number types except fixnum, compiled-function, symbol, |
967 marker, extent, event, and string. | |
428 | 968 |
969 Note that strings are special in that they are actually stored in | |
970 two parts: a structure containing information about the string, and | |
971 the actual data associated with the string. The former structure | |
972 (a struct Lisp_String) is a fixed-size structure and is managed the | |
973 same way as all the other such types. This structure contains a | |
974 pointer to the actual string data, which is stored in structures of | |
975 type struct string_chars_block. Each string_chars_block consists | |
976 of a pointer to a struct Lisp_String, followed by the data for that | |
440 | 977 string, followed by another pointer to a Lisp_String, followed by |
978 the data for that string, etc. At GC time, the data in these | |
979 blocks is compacted by searching sequentially through all the | |
428 | 980 blocks and compressing out any holes created by unmarked strings. |
981 Strings that are more than a certain size (bigger than the size of | |
982 a string_chars_block, although something like half as big might | |
983 make more sense) are malloc()ed separately and not stored in | |
984 string_chars_blocks. Furthermore, no one string stretches across | |
985 two string_chars_blocks. | |
986 | |
1204 | 987 Vectors are each malloc()ed separately as lcrecords. |
428 | 988 |
989 In the following discussion, we use conses, but it applies equally | |
990 well to the other fixed-size types. | |
991 | |
992 We store cons cells inside of cons_blocks, allocating a new | |
993 cons_block with malloc() whenever necessary. Cons cells reclaimed | |
994 by GC are put on a free list to be reallocated before allocating | |
995 any new cons cells from the latest cons_block. Each cons_block is | |
996 just under 2^n - MALLOC_OVERHEAD bytes long, since malloc (at least | |
997 the versions in malloc.c and gmalloc.c) really allocates in units | |
998 of powers of two and uses 4 bytes for its own overhead. | |
999 | |
1000 What GC actually does is to search through all the cons_blocks, | |
1001 from the most recently allocated to the oldest, and put all | |
1002 cons cells that are not marked (whether or not they're already | |
1003 free) on a cons_free_list. The cons_free_list is a stack, and | |
1004 so the cons cells in the oldest-allocated cons_block end up | |
1005 at the head of the stack and are the first to be reallocated. | |
1006 If any cons_block is entirely free, it is freed with free() | |
1007 and its cons cells removed from the cons_free_list. Because | |
1008 the cons_free_list ends up basically in memory order, we have | |
1009 a high locality of reference (assuming a reasonable turnover | |
1010 of allocating and freeing) and have a reasonable probability | |
1011 of entirely freeing up cons_blocks that have been more recently | |
1012 allocated. This stage is called the "sweep stage" of GC, and | |
1013 is executed after the "mark stage", which involves starting | |
1014 from all places that are known to point to in-use Lisp objects | |
1015 (e.g. the obarray, where are all symbols are stored; the | |
1016 current catches and condition-cases; the backtrace list of | |
1017 currently executing functions; the gcpro list; etc.) and | |
1018 recursively marking all objects that are accessible. | |
1019 | |
454 | 1020 At the beginning of the sweep stage, the conses in the cons blocks |
1021 are in one of three states: in use and marked, in use but not | |
1022 marked, and not in use (already freed). Any conses that are marked | |
1023 have been marked in the mark stage just executed, because as part | |
1024 of the sweep stage we unmark any marked objects. The way we tell | |
1025 whether or not a cons cell is in use is through the LRECORD_FREE_P | |
1026 macro. This uses a special lrecord type `lrecord_type_free', | |
1027 which is never associated with any valid object. | |
1028 | |
1029 Conses on the free_cons_list are threaded through a pointer stored | |
1030 in the conses themselves. Because the cons is still in a | |
1031 cons_block and needs to remain marked as not in use for the next | |
1032 time that GC happens, we need room to store both the "free" | |
1033 indicator and the chaining pointer. So this pointer is stored | |
1034 after the lrecord header (actually where C places a pointer after | |
1035 the lrecord header; they are not necessarily contiguous). This | |
1036 implies that all fixed-size types must be big enough to contain at | |
1037 least one pointer. This is true for all current fixed-size types, | |
1038 with the possible exception of Lisp_Floats, for which we define the | |
1039 meat of the struct using a union of a pointer and a double to | |
1040 ensure adequate space for the free list chain pointer. | |
428 | 1041 |
1042 Some types of objects need additional "finalization" done | |
1043 when an object is converted from in use to not in use; | |
1044 this is the purpose of the ADDITIONAL_FREE_type macro. | |
1045 For example, markers need to be removed from the chain | |
1046 of markers that is kept in each buffer. This is because | |
1047 markers in a buffer automatically disappear if the marker | |
1048 is no longer referenced anywhere (the same does not | |
1049 apply to extents, however). | |
1050 | |
1051 WARNING: Things are in an extremely bizarre state when | |
1052 the ADDITIONAL_FREE_type macros are called, so beware! | |
1053 | |
454 | 1054 When ERROR_CHECK_GC is defined, we do things differently so as to |
1055 maximize our chances of catching places where there is insufficient | |
1056 GCPROing. The thing we want to avoid is having an object that | |
1057 we're using but didn't GCPRO get freed by GC and then reallocated | |
1058 while we're in the process of using it -- this will result in | |
1059 something seemingly unrelated getting trashed, and is extremely | |
1060 difficult to track down. If the object gets freed but not | |
1061 reallocated, we can usually catch this because we set most of the | |
1062 bytes of a freed object to 0xDEADBEEF. (The lisp object type is set | |
1063 to the invalid type `lrecord_type_free', however, and a pointer | |
1064 used to chain freed objects together is stored after the lrecord | |
1065 header; we play some tricks with this pointer to make it more | |
428 | 1066 bogus, so crashes are more likely to occur right away.) |
1067 | |
1068 We want freed objects to stay free as long as possible, | |
1069 so instead of doing what we do above, we maintain the | |
1070 free objects in a first-in first-out queue. We also | |
1071 don't recompute the free list each GC, unlike above; | |
1072 this ensures that the queue ordering is preserved. | |
1073 [This means that we are likely to have worse locality | |
1074 of reference, and that we can never free a frob block | |
1075 once it's allocated. (Even if we know that all cells | |
1076 in it are free, there's no easy way to remove all those | |
1077 cells from the free list because the objects on the | |
1078 free list are unlikely to be in memory order.)] | |
1079 Furthermore, we never take objects off the free list | |
1080 unless there's a large number (usually 1000, but | |
1081 varies depending on type) of them already on the list. | |
1082 This way, we ensure that an object that gets freed will | |
1083 remain free for the next 1000 (or whatever) times that | |
440 | 1084 an object of that type is allocated. */ |
428 | 1085 |
1086 #if !defined(HAVE_MMAP) || defined(DOUG_LEA_MALLOC) | |
1087 /* If we released our reserve (due to running out of memory), | |
1088 and we have a fair amount free once again, | |
1089 try to set aside another reserve in case we run out once more. | |
1090 | |
1091 This is called when a relocatable block is freed in ralloc.c. */ | |
1092 void refill_memory_reserve (void); | |
1093 void | |
442 | 1094 refill_memory_reserve (void) |
428 | 1095 { |
1096 if (breathing_space == 0) | |
1097 breathing_space = (char *) malloc (4096 - MALLOC_OVERHEAD); | |
1098 } | |
1099 #endif | |
1100 | |
1101 #ifdef ALLOC_NO_POOLS | |
1102 # define TYPE_ALLOC_SIZE(type, structtype) 1 | |
1103 #else | |
1104 # define TYPE_ALLOC_SIZE(type, structtype) \ | |
1105 ((2048 - MALLOC_OVERHEAD - sizeof (struct type##_block *)) \ | |
1106 / sizeof (structtype)) | |
1107 #endif /* ALLOC_NO_POOLS */ | |
1108 | |
1109 #define DECLARE_FIXED_TYPE_ALLOC(type, structtype) \ | |
1110 \ | |
1111 struct type##_block \ | |
1112 { \ | |
1113 struct type##_block *prev; \ | |
1114 structtype block[TYPE_ALLOC_SIZE (type, structtype)]; \ | |
1115 }; \ | |
1116 \ | |
1117 static struct type##_block *current_##type##_block; \ | |
1118 static int current_##type##_block_index; \ | |
1119 \ | |
454 | 1120 static Lisp_Free *type##_free_list; \ |
1121 static Lisp_Free *type##_free_list_tail; \ | |
428 | 1122 \ |
1123 static void \ | |
1124 init_##type##_alloc (void) \ | |
1125 { \ | |
1126 current_##type##_block = 0; \ | |
1127 current_##type##_block_index = \ | |
1128 countof (current_##type##_block->block); \ | |
1129 type##_free_list = 0; \ | |
1130 type##_free_list_tail = 0; \ | |
1131 } \ | |
1132 \ | |
1133 static int gc_count_num_##type##_in_use; \ | |
1134 static int gc_count_num_##type##_freelist | |
1135 | |
1136 #define ALLOCATE_FIXED_TYPE_FROM_BLOCK(type, result) do { \ | |
1137 if (current_##type##_block_index \ | |
1138 == countof (current_##type##_block->block)) \ | |
1139 { \ | |
1140 struct type##_block *AFTFB_new = (struct type##_block *) \ | |
1141 allocate_lisp_storage (sizeof (struct type##_block)); \ | |
1142 AFTFB_new->prev = current_##type##_block; \ | |
1143 current_##type##_block = AFTFB_new; \ | |
1144 current_##type##_block_index = 0; \ | |
1145 } \ | |
1146 (result) = \ | |
1147 &(current_##type##_block->block[current_##type##_block_index++]); \ | |
1148 } while (0) | |
1149 | |
1150 /* Allocate an instance of a type that is stored in blocks. | |
1151 TYPE is the "name" of the type, STRUCTTYPE is the corresponding | |
1152 structure type. */ | |
1153 | |
1154 #ifdef ERROR_CHECK_GC | |
1155 | |
1156 /* Note: if you get crashes in this function, suspect incorrect calls | |
1157 to free_cons() and friends. This happened once because the cons | |
1158 cell was not GC-protected and was getting collected before | |
1159 free_cons() was called. */ | |
1160 | |
454 | 1161 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) do { \ |
1162 if (gc_count_num_##type##_freelist > \ | |
1163 MINIMUM_ALLOWED_FIXED_TYPE_CELLS_##type) \ | |
1164 { \ | |
1165 result = (structtype *) type##_free_list; \ | |
1204 | 1166 assert (LRECORD_FREE_P (result)); \ |
1167 /* Before actually using the chain pointer, we complement \ | |
1168 all its bits; see PUT_FIXED_TYPE_ON_FREE_LIST(). */ \ | |
454 | 1169 type##_free_list = (Lisp_Free *) \ |
1170 (~ (EMACS_UINT) (type##_free_list->chain)); \ | |
1171 gc_count_num_##type##_freelist--; \ | |
1172 } \ | |
1173 else \ | |
1174 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \ | |
1175 MARK_LRECORD_AS_NOT_FREE (result); \ | |
428 | 1176 } while (0) |
1177 | |
1178 #else /* !ERROR_CHECK_GC */ | |
1179 | |
454 | 1180 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) do { \ |
428 | 1181 if (type##_free_list) \ |
1182 { \ | |
454 | 1183 result = (structtype *) type##_free_list; \ |
1184 type##_free_list = type##_free_list->chain; \ | |
428 | 1185 } \ |
1186 else \ | |
1187 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \ | |
454 | 1188 MARK_LRECORD_AS_NOT_FREE (result); \ |
428 | 1189 } while (0) |
1190 | |
1191 #endif /* !ERROR_CHECK_GC */ | |
1192 | |
454 | 1193 |
428 | 1194 #define ALLOCATE_FIXED_TYPE(type, structtype, result) \ |
1195 do \ | |
1196 { \ | |
1197 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \ | |
1198 INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \ | |
1199 } while (0) | |
1200 | |
1201 #define NOSEEUM_ALLOCATE_FIXED_TYPE(type, structtype, result) \ | |
1202 do \ | |
1203 { \ | |
1204 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \ | |
1205 NOSEEUM_INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \ | |
1206 } while (0) | |
1207 | |
454 | 1208 /* Lisp_Free is the type to represent a free list member inside a frob |
1209 block of any lisp object type. */ | |
1210 typedef struct Lisp_Free | |
1211 { | |
1212 struct lrecord_header lheader; | |
1213 struct Lisp_Free *chain; | |
1214 } Lisp_Free; | |
1215 | |
1216 #define LRECORD_FREE_P(ptr) \ | |
771 | 1217 (((struct lrecord_header *) ptr)->type == lrecord_type_free) |
454 | 1218 |
1219 #define MARK_LRECORD_AS_FREE(ptr) \ | |
771 | 1220 ((void) (((struct lrecord_header *) ptr)->type = lrecord_type_free)) |
454 | 1221 |
1222 #ifdef ERROR_CHECK_GC | |
1223 #define MARK_LRECORD_AS_NOT_FREE(ptr) \ | |
771 | 1224 ((void) (((struct lrecord_header *) ptr)->type = lrecord_type_undefined)) |
428 | 1225 #else |
454 | 1226 #define MARK_LRECORD_AS_NOT_FREE(ptr) DO_NOTHING |
428 | 1227 #endif |
1228 | |
1229 #ifdef ERROR_CHECK_GC | |
1230 | |
454 | 1231 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) do { \ |
1232 if (type##_free_list_tail) \ | |
1233 { \ | |
1234 /* When we store the chain pointer, we complement all \ | |
1235 its bits; this should significantly increase its \ | |
1236 bogosity in case someone tries to use the value, and \ | |
1237 should make us crash faster if someone overwrites the \ | |
1238 pointer because when it gets un-complemented in \ | |
1239 ALLOCATED_FIXED_TYPE(), the resulting pointer will be \ | |
1240 extremely bogus. */ \ | |
1241 type##_free_list_tail->chain = \ | |
1242 (Lisp_Free *) ~ (EMACS_UINT) (ptr); \ | |
1243 } \ | |
1244 else \ | |
1245 type##_free_list = (Lisp_Free *) (ptr); \ | |
1246 type##_free_list_tail = (Lisp_Free *) (ptr); \ | |
1247 } while (0) | |
428 | 1248 |
1249 #else /* !ERROR_CHECK_GC */ | |
1250 | |
454 | 1251 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) do { \ |
1252 ((Lisp_Free *) (ptr))->chain = type##_free_list; \ | |
1253 type##_free_list = (Lisp_Free *) (ptr); \ | |
1254 } while (0) \ | |
428 | 1255 |
1256 #endif /* !ERROR_CHECK_GC */ | |
1257 | |
1258 /* TYPE and STRUCTTYPE are the same as in ALLOCATE_FIXED_TYPE(). */ | |
1259 | |
1260 #define FREE_FIXED_TYPE(type, structtype, ptr) do { \ | |
1261 structtype *FFT_ptr = (ptr); \ | |
1204 | 1262 gc_checking_assert (!LRECORD_FREE_P (FFT_ptr)); \ |
2367 | 1263 gc_checking_assert (!DUMPEDP (FFT_ptr)); \ |
428 | 1264 ADDITIONAL_FREE_##type (FFT_ptr); \ |
1265 deadbeef_memory (FFT_ptr, sizeof (structtype)); \ | |
1266 PUT_FIXED_TYPE_ON_FREE_LIST (type, structtype, FFT_ptr); \ | |
454 | 1267 MARK_LRECORD_AS_FREE (FFT_ptr); \ |
428 | 1268 } while (0) |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1269 #endif /* NEW_GC */ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1270 |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1271 #ifdef NEW_GC |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1272 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(lo, type, structtype, ptr) \ |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1273 free_normal_lisp_object (lo) |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1274 #else /* not NEW_GC */ |
428 | 1275 /* Like FREE_FIXED_TYPE() but used when we are explicitly |
1276 freeing a structure through free_cons(), free_marker(), etc. | |
1277 rather than through the normal process of sweeping. | |
1278 We attempt to undo the changes made to the allocation counters | |
1279 as a result of this structure being allocated. This is not | |
1280 completely necessary but helps keep things saner: e.g. this way, | |
1281 repeatedly allocating and freeing a cons will not result in | |
1282 the consing-since-gc counter advancing, which would cause a GC | |
1204 | 1283 and somewhat defeat the purpose of explicitly freeing. |
1284 | |
1285 We also disable this mechanism entirely when ALLOC_NO_POOLS is | |
1286 set, which is used for Purify and the like. */ | |
1287 | |
1288 #ifndef ALLOC_NO_POOLS | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1289 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(lo, type, structtype, ptr) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1290 do { FREE_FIXED_TYPE (type, structtype, ptr); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1291 DECREMENT_CONS_COUNTER (sizeof (structtype)); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1292 gc_count_num_##type##_freelist++; \ |
428 | 1293 } while (0) |
1204 | 1294 #else |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1295 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(lo, type, structtype, ptr) |
1204 | 1296 #endif |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1297 #endif /* (not) NEW_GC */ |
3263 | 1298 |
1299 #ifdef NEW_GC | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1300 #define ALLOC_FROB_BLOCK_LISP_OBJECT(type, lisp_type, var, lrec_ptr)\ |
3017 | 1301 do { \ |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1302 (var) = (lisp_type *) XPNTR (ALLOC_NORMAL_LISP_OBJECT (type)); \ |
3017 | 1303 } while (0) |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1304 #define NOSEEUM_ALLOC_FROB_BLOCK_LISP_OBJECT(type, lisp_type, var, \ |
3017 | 1305 lrec_ptr) \ |
1306 do { \ | |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1307 (var) = (lisp_type *) XPNTR (noseeum_alloc_lrecord (lrec_ptr)); \ |
3017 | 1308 } while (0) |
3263 | 1309 #else /* not NEW_GC */ |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1310 #define ALLOC_FROB_BLOCK_LISP_OBJECT(type, lisp_type, var, lrec_ptr) \ |
3017 | 1311 do \ |
1312 { \ | |
1313 ALLOCATE_FIXED_TYPE (type, lisp_type, var); \ | |
1314 set_lheader_implementation (&(var)->lheader, lrec_ptr); \ | |
1315 } while (0) | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1316 #define NOSEEUM_ALLOC_FROB_BLOCK_LISP_OBJECT(type, lisp_type, var, \ |
3017 | 1317 lrec_ptr) \ |
1318 do \ | |
1319 { \ | |
1320 NOSEEUM_ALLOCATE_FIXED_TYPE (type, lisp_type, var); \ | |
1321 set_lheader_implementation (&(var)->lheader, lrec_ptr); \ | |
1322 } while (0) | |
3263 | 1323 #endif /* not NEW_GC */ |
3017 | 1324 |
428 | 1325 |
1326 | |
1327 /************************************************************************/ | |
1328 /* Cons allocation */ | |
1329 /************************************************************************/ | |
1330 | |
440 | 1331 DECLARE_FIXED_TYPE_ALLOC (cons, Lisp_Cons); |
428 | 1332 /* conses are used and freed so often that we set this really high */ |
1333 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 20000 */ | |
1334 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 2000 | |
1335 | |
1336 static Lisp_Object | |
1337 mark_cons (Lisp_Object obj) | |
1338 { | |
1339 if (NILP (XCDR (obj))) | |
1340 return XCAR (obj); | |
1341 | |
1342 mark_object (XCAR (obj)); | |
1343 return XCDR (obj); | |
1344 } | |
1345 | |
1346 static int | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1347 cons_equal (Lisp_Object ob1, Lisp_Object ob2, int depth, int foldcase) |
428 | 1348 { |
442 | 1349 depth++; |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1350 while (internal_equal_0 (XCAR (ob1), XCAR (ob2), depth, foldcase)) |
428 | 1351 { |
1352 ob1 = XCDR (ob1); | |
1353 ob2 = XCDR (ob2); | |
1354 if (! CONSP (ob1) || ! CONSP (ob2)) | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1355 return internal_equal_0 (ob1, ob2, depth, foldcase); |
428 | 1356 } |
1357 return 0; | |
1358 } | |
1359 | |
1204 | 1360 static const struct memory_description cons_description[] = { |
853 | 1361 { XD_LISP_OBJECT, offsetof (Lisp_Cons, car_) }, |
1362 { XD_LISP_OBJECT, offsetof (Lisp_Cons, cdr_) }, | |
428 | 1363 { XD_END } |
1364 }; | |
1365 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1366 DEFINE_DUMPABLE_FROB_BLOCK_LISP_OBJECT ("cons", cons, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1367 mark_cons, print_cons, 0, cons_equal, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1368 /* |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1369 * No `hash' method needed. |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1370 * internal_hash knows how to |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1371 * handle conses. |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1372 */ |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1373 0, cons_description, Lisp_Cons); |
428 | 1374 |
1375 DEFUN ("cons", Fcons, 2, 2, 0, /* | |
3355 | 1376 Create a new cons cell, give it CAR and CDR as components, and return it. |
1377 | |
1378 A cons cell is a Lisp object (an area in memory) made up of two pointers | |
1379 called the CAR and the CDR. Each of these pointers can point to any other | |
1380 Lisp object. The common Lisp data type, the list, is a specially-structured | |
1381 series of cons cells. | |
1382 | |
1383 The pointers are accessed from Lisp with `car' and `cdr', and mutated with | |
1384 `setcar' and `setcdr' respectively. For historical reasons, the aliases | |
1385 `rplaca' and `rplacd' (for `setcar' and `setcdr') are supported. | |
428 | 1386 */ |
1387 (car, cdr)) | |
1388 { | |
1389 /* This cannot GC. */ | |
1390 Lisp_Object val; | |
440 | 1391 Lisp_Cons *c; |
1392 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1393 ALLOC_FROB_BLOCK_LISP_OBJECT (cons, Lisp_Cons, c, &lrecord_cons); |
793 | 1394 val = wrap_cons (c); |
853 | 1395 XSETCAR (val, car); |
1396 XSETCDR (val, cdr); | |
428 | 1397 return val; |
1398 } | |
1399 | |
1400 /* This is identical to Fcons() but it used for conses that we're | |
1401 going to free later, and is useful when trying to track down | |
1402 "real" consing. */ | |
1403 Lisp_Object | |
1404 noseeum_cons (Lisp_Object car, Lisp_Object cdr) | |
1405 { | |
1406 Lisp_Object val; | |
440 | 1407 Lisp_Cons *c; |
1408 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1409 NOSEEUM_ALLOC_FROB_BLOCK_LISP_OBJECT (cons, Lisp_Cons, c, &lrecord_cons); |
793 | 1410 val = wrap_cons (c); |
428 | 1411 XCAR (val) = car; |
1412 XCDR (val) = cdr; | |
1413 return val; | |
1414 } | |
1415 | |
1416 DEFUN ("list", Flist, 0, MANY, 0, /* | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1417 Return a newly created list with specified ARGS as elements. |
428 | 1418 Any number of arguments, even zero arguments, are allowed. |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1419 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1420 arguments: (&rest ARGS) |
428 | 1421 */ |
1422 (int nargs, Lisp_Object *args)) | |
1423 { | |
1424 Lisp_Object val = Qnil; | |
1425 Lisp_Object *argp = args + nargs; | |
1426 | |
1427 while (argp > args) | |
1428 val = Fcons (*--argp, val); | |
1429 return val; | |
1430 } | |
1431 | |
1432 Lisp_Object | |
1433 list1 (Lisp_Object obj0) | |
1434 { | |
1435 /* This cannot GC. */ | |
1436 return Fcons (obj0, Qnil); | |
1437 } | |
1438 | |
1439 Lisp_Object | |
1440 list2 (Lisp_Object obj0, Lisp_Object obj1) | |
1441 { | |
1442 /* This cannot GC. */ | |
1443 return Fcons (obj0, Fcons (obj1, Qnil)); | |
1444 } | |
1445 | |
1446 Lisp_Object | |
1447 list3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2) | |
1448 { | |
1449 /* This cannot GC. */ | |
1450 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Qnil))); | |
1451 } | |
1452 | |
1453 Lisp_Object | |
1454 cons3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2) | |
1455 { | |
1456 /* This cannot GC. */ | |
1457 return Fcons (obj0, Fcons (obj1, obj2)); | |
1458 } | |
1459 | |
1460 Lisp_Object | |
1461 acons (Lisp_Object key, Lisp_Object value, Lisp_Object alist) | |
1462 { | |
1463 return Fcons (Fcons (key, value), alist); | |
1464 } | |
1465 | |
1466 Lisp_Object | |
1467 list4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3) | |
1468 { | |
1469 /* This cannot GC. */ | |
1470 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Qnil)))); | |
1471 } | |
1472 | |
1473 Lisp_Object | |
1474 list5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3, | |
1475 Lisp_Object obj4) | |
1476 { | |
1477 /* This cannot GC. */ | |
1478 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Fcons (obj4, Qnil))))); | |
1479 } | |
1480 | |
1481 Lisp_Object | |
1482 list6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3, | |
1483 Lisp_Object obj4, Lisp_Object obj5) | |
1484 { | |
1485 /* This cannot GC. */ | |
1486 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Fcons (obj4, Fcons (obj5, Qnil)))))); | |
1487 } | |
1488 | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1489 /* Return a list of arbitrary length, terminated by Qunbound. */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1490 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1491 Lisp_Object |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1492 listu (Lisp_Object first, ...) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1493 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1494 Lisp_Object obj = Qnil; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1495 Lisp_Object val; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1496 va_list va; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1497 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1498 va_start (va, first); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1499 val = first; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1500 while (!UNBOUNDP (val)) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1501 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1502 obj = Fcons (val, obj); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1503 val = va_arg (va, Lisp_Object); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1504 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1505 va_end (va); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1506 return Fnreverse (obj); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1507 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1508 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1509 /* Return a list of arbitrary length, with length specified and remaining |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1510 args making up the list. */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1511 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1512 Lisp_Object |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1513 listn (int num_args, ...) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1514 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1515 int i; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1516 Lisp_Object obj = Qnil; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1517 va_list va; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1518 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1519 va_start (va, num_args); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1520 for (i = 0; i < num_args; i++) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1521 obj = Fcons (va_arg (va, Lisp_Object), obj); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1522 va_end (va); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1523 return Fnreverse (obj); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1524 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1525 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1526 /* Return a list of arbitrary length, with length specified and an array |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1527 of elements. */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1528 |
428 | 1529 DEFUN ("make-list", Fmake_list, 2, 2, 0, /* |
444 | 1530 Return a new list of length LENGTH, with each element being OBJECT. |
428 | 1531 */ |
444 | 1532 (length, object)) |
428 | 1533 { |
1534 CHECK_NATNUM (length); | |
1535 | |
1536 { | |
1537 Lisp_Object val = Qnil; | |
647 | 1538 EMACS_INT size = XINT (length); |
428 | 1539 |
1540 while (size--) | |
444 | 1541 val = Fcons (object, val); |
428 | 1542 return val; |
1543 } | |
1544 } | |
1545 | |
1546 | |
1547 /************************************************************************/ | |
1548 /* Float allocation */ | |
1549 /************************************************************************/ | |
1550 | |
1983 | 1551 /*** With enhanced number support, these are short floats */ |
1552 | |
440 | 1553 DECLARE_FIXED_TYPE_ALLOC (float, Lisp_Float); |
428 | 1554 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_float 1000 |
1555 | |
1556 Lisp_Object | |
1557 make_float (double float_value) | |
1558 { | |
440 | 1559 Lisp_Float *f; |
1560 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1561 ALLOC_FROB_BLOCK_LISP_OBJECT (float, Lisp_Float, f, &lrecord_float); |
440 | 1562 |
1563 /* Avoid dump-time `uninitialized memory read' purify warnings. */ | |
1564 if (sizeof (struct lrecord_header) + sizeof (double) != sizeof (*f)) | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1565 zero_nonsized_lisp_object (wrap_float (f)); |
3017 | 1566 |
428 | 1567 float_data (f) = float_value; |
793 | 1568 return wrap_float (f); |
428 | 1569 } |
1570 | |
1571 | |
1572 /************************************************************************/ | |
1983 | 1573 /* Enhanced number allocation */ |
1574 /************************************************************************/ | |
1575 | |
1576 /*** Bignum ***/ | |
1577 #ifdef HAVE_BIGNUM | |
1578 DECLARE_FIXED_TYPE_ALLOC (bignum, Lisp_Bignum); | |
1579 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bignum 250 | |
1580 | |
1581 /* WARNING: This function returns a bignum even if its argument fits into a | |
1582 fixnum. See Fcanonicalize_number(). */ | |
1583 Lisp_Object | |
1584 make_bignum (long bignum_value) | |
1585 { | |
1586 Lisp_Bignum *b; | |
1587 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1588 ALLOC_FROB_BLOCK_LISP_OBJECT (bignum, Lisp_Bignum, b, &lrecord_bignum); |
1983 | 1589 bignum_init (bignum_data (b)); |
1590 bignum_set_long (bignum_data (b), bignum_value); | |
1591 return wrap_bignum (b); | |
1592 } | |
1593 | |
1594 /* WARNING: This function returns a bignum even if its argument fits into a | |
1595 fixnum. See Fcanonicalize_number(). */ | |
1596 Lisp_Object | |
1597 make_bignum_bg (bignum bg) | |
1598 { | |
1599 Lisp_Bignum *b; | |
1600 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1601 ALLOC_FROB_BLOCK_LISP_OBJECT (bignum, Lisp_Bignum, b, &lrecord_bignum); |
1983 | 1602 bignum_init (bignum_data (b)); |
1603 bignum_set (bignum_data (b), bg); | |
1604 return wrap_bignum (b); | |
1605 } | |
1606 #endif /* HAVE_BIGNUM */ | |
1607 | |
1608 /*** Ratio ***/ | |
1609 #ifdef HAVE_RATIO | |
1610 DECLARE_FIXED_TYPE_ALLOC (ratio, Lisp_Ratio); | |
1611 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_ratio 250 | |
1612 | |
1613 Lisp_Object | |
1614 make_ratio (long numerator, unsigned long denominator) | |
1615 { | |
1616 Lisp_Ratio *r; | |
1617 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1618 ALLOC_FROB_BLOCK_LISP_OBJECT (ratio, Lisp_Ratio, r, &lrecord_ratio); |
1983 | 1619 ratio_init (ratio_data (r)); |
1620 ratio_set_long_ulong (ratio_data (r), numerator, denominator); | |
1621 ratio_canonicalize (ratio_data (r)); | |
1622 return wrap_ratio (r); | |
1623 } | |
1624 | |
1625 Lisp_Object | |
1626 make_ratio_bg (bignum numerator, bignum denominator) | |
1627 { | |
1628 Lisp_Ratio *r; | |
1629 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1630 ALLOC_FROB_BLOCK_LISP_OBJECT (ratio, Lisp_Ratio, r, &lrecord_ratio); |
1983 | 1631 ratio_init (ratio_data (r)); |
1632 ratio_set_bignum_bignum (ratio_data (r), numerator, denominator); | |
1633 ratio_canonicalize (ratio_data (r)); | |
1634 return wrap_ratio (r); | |
1635 } | |
1636 | |
1637 Lisp_Object | |
1638 make_ratio_rt (ratio rat) | |
1639 { | |
1640 Lisp_Ratio *r; | |
1641 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1642 ALLOC_FROB_BLOCK_LISP_OBJECT (ratio, Lisp_Ratio, r, &lrecord_ratio); |
1983 | 1643 ratio_init (ratio_data (r)); |
1644 ratio_set (ratio_data (r), rat); | |
1645 return wrap_ratio (r); | |
1646 } | |
1647 #endif /* HAVE_RATIO */ | |
1648 | |
1649 /*** Bigfloat ***/ | |
1650 #ifdef HAVE_BIGFLOAT | |
1651 DECLARE_FIXED_TYPE_ALLOC (bigfloat, Lisp_Bigfloat); | |
1652 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bigfloat 250 | |
1653 | |
1654 /* This function creates a bigfloat with the default precision if the | |
1655 PRECISION argument is zero. */ | |
1656 Lisp_Object | |
1657 make_bigfloat (double float_value, unsigned long precision) | |
1658 { | |
1659 Lisp_Bigfloat *f; | |
1660 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1661 ALLOC_FROB_BLOCK_LISP_OBJECT (bigfloat, Lisp_Bigfloat, f, &lrecord_bigfloat); |
1983 | 1662 if (precision == 0UL) |
1663 bigfloat_init (bigfloat_data (f)); | |
1664 else | |
1665 bigfloat_init_prec (bigfloat_data (f), precision); | |
1666 bigfloat_set_double (bigfloat_data (f), float_value); | |
1667 return wrap_bigfloat (f); | |
1668 } | |
1669 | |
1670 /* This function creates a bigfloat with the precision of its argument */ | |
1671 Lisp_Object | |
1672 make_bigfloat_bf (bigfloat float_value) | |
1673 { | |
1674 Lisp_Bigfloat *f; | |
1675 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1676 ALLOC_FROB_BLOCK_LISP_OBJECT (bigfloat, Lisp_Bigfloat, f, &lrecord_bigfloat); |
1983 | 1677 bigfloat_init_prec (bigfloat_data (f), bigfloat_get_prec (float_value)); |
1678 bigfloat_set (bigfloat_data (f), float_value); | |
1679 return wrap_bigfloat (f); | |
1680 } | |
1681 #endif /* HAVE_BIGFLOAT */ | |
1682 | |
1683 /************************************************************************/ | |
428 | 1684 /* Vector allocation */ |
1685 /************************************************************************/ | |
1686 | |
1687 static Lisp_Object | |
1688 mark_vector (Lisp_Object obj) | |
1689 { | |
1690 Lisp_Vector *ptr = XVECTOR (obj); | |
1691 int len = vector_length (ptr); | |
1692 int i; | |
1693 | |
1694 for (i = 0; i < len - 1; i++) | |
1695 mark_object (ptr->contents[i]); | |
1696 return (len > 0) ? ptr->contents[len - 1] : Qnil; | |
1697 } | |
1698 | |
665 | 1699 static Bytecount |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1700 size_vector (Lisp_Object obj) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1701 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1702 |
456 | 1703 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object, contents, |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1704 XVECTOR (obj)->size); |
428 | 1705 } |
1706 | |
1707 static int | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1708 vector_equal (Lisp_Object obj1, Lisp_Object obj2, int depth, int foldcase) |
428 | 1709 { |
1710 int len = XVECTOR_LENGTH (obj1); | |
1711 if (len != XVECTOR_LENGTH (obj2)) | |
1712 return 0; | |
1713 | |
1714 { | |
1715 Lisp_Object *ptr1 = XVECTOR_DATA (obj1); | |
1716 Lisp_Object *ptr2 = XVECTOR_DATA (obj2); | |
1717 while (len--) | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1718 if (!internal_equal_0 (*ptr1++, *ptr2++, depth + 1, foldcase)) |
428 | 1719 return 0; |
1720 } | |
1721 return 1; | |
1722 } | |
1723 | |
665 | 1724 static Hashcode |
442 | 1725 vector_hash (Lisp_Object obj, int depth) |
1726 { | |
1727 return HASH2 (XVECTOR_LENGTH (obj), | |
1728 internal_array_hash (XVECTOR_DATA (obj), | |
1729 XVECTOR_LENGTH (obj), | |
1730 depth + 1)); | |
1731 } | |
1732 | |
1204 | 1733 static const struct memory_description vector_description[] = { |
440 | 1734 { XD_LONG, offsetof (Lisp_Vector, size) }, |
1735 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Vector, contents), XD_INDIRECT(0, 0) }, | |
428 | 1736 { XD_END } |
1737 }; | |
1738 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1739 DEFINE_DUMPABLE_SIZABLE_LISP_OBJECT ("vector", vector, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1740 mark_vector, print_vector, 0, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1741 vector_equal, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1742 vector_hash, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1743 vector_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1744 size_vector, Lisp_Vector); |
428 | 1745 /* #### should allocate `small' vectors from a frob-block */ |
1746 static Lisp_Vector * | |
665 | 1747 make_vector_internal (Elemcount sizei) |
428 | 1748 { |
1204 | 1749 /* no `next' field; we use lcrecords */ |
665 | 1750 Bytecount sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object, |
1204 | 1751 contents, sizei); |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1752 Lisp_Object obj = ALLOC_SIZED_LISP_OBJECT (sizem, vector); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1753 Lisp_Vector *p = XVECTOR (obj); |
428 | 1754 |
1755 p->size = sizei; | |
1756 return p; | |
1757 } | |
1758 | |
1759 Lisp_Object | |
665 | 1760 make_vector (Elemcount length, Lisp_Object object) |
428 | 1761 { |
1762 Lisp_Vector *vecp = make_vector_internal (length); | |
1763 Lisp_Object *p = vector_data (vecp); | |
1764 | |
1765 while (length--) | |
444 | 1766 *p++ = object; |
428 | 1767 |
793 | 1768 return wrap_vector (vecp); |
428 | 1769 } |
1770 | |
1771 DEFUN ("make-vector", Fmake_vector, 2, 2, 0, /* | |
444 | 1772 Return a new vector of length LENGTH, with each element being OBJECT. |
428 | 1773 See also the function `vector'. |
1774 */ | |
444 | 1775 (length, object)) |
428 | 1776 { |
1777 CONCHECK_NATNUM (length); | |
444 | 1778 return make_vector (XINT (length), object); |
428 | 1779 } |
1780 | |
1781 DEFUN ("vector", Fvector, 0, MANY, 0, /* | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1782 Return a newly created vector with specified ARGS as elements. |
428 | 1783 Any number of arguments, even zero arguments, are allowed. |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1784 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1785 arguments: (&rest ARGS) |
428 | 1786 */ |
1787 (int nargs, Lisp_Object *args)) | |
1788 { | |
1789 Lisp_Vector *vecp = make_vector_internal (nargs); | |
1790 Lisp_Object *p = vector_data (vecp); | |
1791 | |
1792 while (nargs--) | |
1793 *p++ = *args++; | |
1794 | |
793 | 1795 return wrap_vector (vecp); |
428 | 1796 } |
1797 | |
1798 Lisp_Object | |
1799 vector1 (Lisp_Object obj0) | |
1800 { | |
1801 return Fvector (1, &obj0); | |
1802 } | |
1803 | |
1804 Lisp_Object | |
1805 vector2 (Lisp_Object obj0, Lisp_Object obj1) | |
1806 { | |
1807 Lisp_Object args[2]; | |
1808 args[0] = obj0; | |
1809 args[1] = obj1; | |
1810 return Fvector (2, args); | |
1811 } | |
1812 | |
1813 Lisp_Object | |
1814 vector3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2) | |
1815 { | |
1816 Lisp_Object args[3]; | |
1817 args[0] = obj0; | |
1818 args[1] = obj1; | |
1819 args[2] = obj2; | |
1820 return Fvector (3, args); | |
1821 } | |
1822 | |
1823 #if 0 /* currently unused */ | |
1824 | |
1825 Lisp_Object | |
1826 vector4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1827 Lisp_Object obj3) | |
1828 { | |
1829 Lisp_Object args[4]; | |
1830 args[0] = obj0; | |
1831 args[1] = obj1; | |
1832 args[2] = obj2; | |
1833 args[3] = obj3; | |
1834 return Fvector (4, args); | |
1835 } | |
1836 | |
1837 Lisp_Object | |
1838 vector5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1839 Lisp_Object obj3, Lisp_Object obj4) | |
1840 { | |
1841 Lisp_Object args[5]; | |
1842 args[0] = obj0; | |
1843 args[1] = obj1; | |
1844 args[2] = obj2; | |
1845 args[3] = obj3; | |
1846 args[4] = obj4; | |
1847 return Fvector (5, args); | |
1848 } | |
1849 | |
1850 Lisp_Object | |
1851 vector6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1852 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5) | |
1853 { | |
1854 Lisp_Object args[6]; | |
1855 args[0] = obj0; | |
1856 args[1] = obj1; | |
1857 args[2] = obj2; | |
1858 args[3] = obj3; | |
1859 args[4] = obj4; | |
1860 args[5] = obj5; | |
1861 return Fvector (6, args); | |
1862 } | |
1863 | |
1864 Lisp_Object | |
1865 vector7 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1866 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5, | |
1867 Lisp_Object obj6) | |
1868 { | |
1869 Lisp_Object args[7]; | |
1870 args[0] = obj0; | |
1871 args[1] = obj1; | |
1872 args[2] = obj2; | |
1873 args[3] = obj3; | |
1874 args[4] = obj4; | |
1875 args[5] = obj5; | |
1876 args[6] = obj6; | |
1877 return Fvector (7, args); | |
1878 } | |
1879 | |
1880 Lisp_Object | |
1881 vector8 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1882 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5, | |
1883 Lisp_Object obj6, Lisp_Object obj7) | |
1884 { | |
1885 Lisp_Object args[8]; | |
1886 args[0] = obj0; | |
1887 args[1] = obj1; | |
1888 args[2] = obj2; | |
1889 args[3] = obj3; | |
1890 args[4] = obj4; | |
1891 args[5] = obj5; | |
1892 args[6] = obj6; | |
1893 args[7] = obj7; | |
1894 return Fvector (8, args); | |
1895 } | |
1896 #endif /* unused */ | |
1897 | |
1898 /************************************************************************/ | |
1899 /* Bit Vector allocation */ | |
1900 /************************************************************************/ | |
1901 | |
1902 /* #### should allocate `small' bit vectors from a frob-block */ | |
440 | 1903 static Lisp_Bit_Vector * |
665 | 1904 make_bit_vector_internal (Elemcount sizei) |
428 | 1905 { |
1204 | 1906 /* no `next' field; we use lcrecords */ |
665 | 1907 Elemcount num_longs = BIT_VECTOR_LONG_STORAGE (sizei); |
1908 Bytecount sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Bit_Vector, | |
1204 | 1909 unsigned long, |
1910 bits, num_longs); | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1911 Lisp_Object obj = ALLOC_SIZED_LISP_OBJECT (sizem, bit_vector); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1912 Lisp_Bit_Vector *p = XBIT_VECTOR (obj); |
428 | 1913 |
1914 bit_vector_length (p) = sizei; | |
1915 return p; | |
1916 } | |
1917 | |
1918 Lisp_Object | |
665 | 1919 make_bit_vector (Elemcount length, Lisp_Object bit) |
428 | 1920 { |
440 | 1921 Lisp_Bit_Vector *p = make_bit_vector_internal (length); |
665 | 1922 Elemcount num_longs = BIT_VECTOR_LONG_STORAGE (length); |
428 | 1923 |
444 | 1924 CHECK_BIT (bit); |
1925 | |
1926 if (ZEROP (bit)) | |
428 | 1927 memset (p->bits, 0, num_longs * sizeof (long)); |
1928 else | |
1929 { | |
665 | 1930 Elemcount bits_in_last = length & (LONGBITS_POWER_OF_2 - 1); |
428 | 1931 memset (p->bits, ~0, num_longs * sizeof (long)); |
1932 /* But we have to make sure that the unused bits in the | |
1933 last long are 0, so that equal/hash is easy. */ | |
1934 if (bits_in_last) | |
1935 p->bits[num_longs - 1] &= (1 << bits_in_last) - 1; | |
1936 } | |
1937 | |
793 | 1938 return wrap_bit_vector (p); |
428 | 1939 } |
1940 | |
1941 Lisp_Object | |
665 | 1942 make_bit_vector_from_byte_vector (unsigned char *bytevec, Elemcount length) |
428 | 1943 { |
665 | 1944 Elemcount i; |
428 | 1945 Lisp_Bit_Vector *p = make_bit_vector_internal (length); |
1946 | |
1947 for (i = 0; i < length; i++) | |
1948 set_bit_vector_bit (p, i, bytevec[i]); | |
1949 | |
793 | 1950 return wrap_bit_vector (p); |
428 | 1951 } |
1952 | |
1953 DEFUN ("make-bit-vector", Fmake_bit_vector, 2, 2, 0, /* | |
444 | 1954 Return a new bit vector of length LENGTH. with each bit set to BIT. |
1955 BIT must be one of the integers 0 or 1. See also the function `bit-vector'. | |
428 | 1956 */ |
444 | 1957 (length, bit)) |
428 | 1958 { |
1959 CONCHECK_NATNUM (length); | |
1960 | |
444 | 1961 return make_bit_vector (XINT (length), bit); |
428 | 1962 } |
1963 | |
1964 DEFUN ("bit-vector", Fbit_vector, 0, MANY, 0, /* | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1965 Return a newly created bit vector with specified ARGS as elements. |
428 | 1966 Any number of arguments, even zero arguments, are allowed. |
444 | 1967 Each argument must be one of the integers 0 or 1. |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1968 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1969 arguments: (&rest ARGS) |
428 | 1970 */ |
1971 (int nargs, Lisp_Object *args)) | |
1972 { | |
1973 int i; | |
1974 Lisp_Bit_Vector *p = make_bit_vector_internal (nargs); | |
1975 | |
1976 for (i = 0; i < nargs; i++) | |
1977 { | |
1978 CHECK_BIT (args[i]); | |
1979 set_bit_vector_bit (p, i, !ZEROP (args[i])); | |
1980 } | |
1981 | |
793 | 1982 return wrap_bit_vector (p); |
428 | 1983 } |
1984 | |
1985 | |
1986 /************************************************************************/ | |
1987 /* Compiled-function allocation */ | |
1988 /************************************************************************/ | |
1989 | |
1990 DECLARE_FIXED_TYPE_ALLOC (compiled_function, Lisp_Compiled_Function); | |
1991 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_compiled_function 1000 | |
1992 | |
1993 static Lisp_Object | |
1994 make_compiled_function (void) | |
1995 { | |
1996 Lisp_Compiled_Function *f; | |
1997 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1998 ALLOC_FROB_BLOCK_LISP_OBJECT (compiled_function, Lisp_Compiled_Function, |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1999 f, &lrecord_compiled_function); |
428 | 2000 |
2001 f->stack_depth = 0; | |
2002 f->specpdl_depth = 0; | |
2003 f->flags.documentationp = 0; | |
2004 f->flags.interactivep = 0; | |
2005 f->flags.domainp = 0; /* I18N3 */ | |
2006 f->instructions = Qzero; | |
2007 f->constants = Qzero; | |
2008 f->arglist = Qnil; | |
3092 | 2009 #ifdef NEW_GC |
2010 f->arguments = Qnil; | |
2011 #else /* not NEW_GC */ | |
1739 | 2012 f->args = NULL; |
3092 | 2013 #endif /* not NEW_GC */ |
1739 | 2014 f->max_args = f->min_args = f->args_in_array = 0; |
428 | 2015 f->doc_and_interactive = Qnil; |
2016 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
2017 f->annotated = Qnil; | |
2018 #endif | |
793 | 2019 return wrap_compiled_function (f); |
428 | 2020 } |
2021 | |
2022 DEFUN ("make-byte-code", Fmake_byte_code, 4, MANY, 0, /* | |
2023 Return a new compiled-function object. | |
2024 Note that, unlike all other emacs-lisp functions, calling this with five | |
2025 arguments is NOT the same as calling it with six arguments, the last of | |
2026 which is nil. If the INTERACTIVE arg is specified as nil, then that means | |
2027 that this function was defined with `(interactive)'. If the arg is not | |
2028 specified, then that means the function is not interactive. | |
2029 This is terrible behavior which is retained for compatibility with old | |
2030 `.elc' files which expect these semantics. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
2031 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
2032 arguments: (ARGLIST INSTRUCTIONS CONSTANTS STACK-DEPTH &optional DOC-STRING INTERACTIVE) |
428 | 2033 */ |
2034 (int nargs, Lisp_Object *args)) | |
2035 { | |
2036 /* In a non-insane world this function would have this arglist... | |
2037 (arglist instructions constants stack_depth &optional doc_string interactive) | |
2038 */ | |
2039 Lisp_Object fun = make_compiled_function (); | |
2040 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (fun); | |
2041 | |
2042 Lisp_Object arglist = args[0]; | |
2043 Lisp_Object instructions = args[1]; | |
2044 Lisp_Object constants = args[2]; | |
2045 Lisp_Object stack_depth = args[3]; | |
2046 Lisp_Object doc_string = (nargs > 4) ? args[4] : Qnil; | |
2047 Lisp_Object interactive = (nargs > 5) ? args[5] : Qunbound; | |
2048 | |
2049 if (nargs < 4 || nargs > 6) | |
2050 return Fsignal (Qwrong_number_of_arguments, | |
2051 list2 (intern ("make-byte-code"), make_int (nargs))); | |
2052 | |
2053 /* Check for valid formal parameter list now, to allow us to use | |
2054 SPECBIND_FAST_UNSAFE() later in funcall_compiled_function(). */ | |
2055 { | |
814 | 2056 EXTERNAL_LIST_LOOP_2 (symbol, arglist) |
428 | 2057 { |
2058 CHECK_SYMBOL (symbol); | |
2059 if (EQ (symbol, Qt) || | |
2060 EQ (symbol, Qnil) || | |
2061 SYMBOL_IS_KEYWORD (symbol)) | |
563 | 2062 invalid_constant_2 |
428 | 2063 ("Invalid constant symbol in formal parameter list", |
2064 symbol, arglist); | |
2065 } | |
2066 } | |
2067 f->arglist = arglist; | |
2068 | |
2069 /* `instructions' is a string or a cons (string . int) for a | |
2070 lazy-loaded function. */ | |
2071 if (CONSP (instructions)) | |
2072 { | |
2073 CHECK_STRING (XCAR (instructions)); | |
2074 CHECK_INT (XCDR (instructions)); | |
2075 } | |
2076 else | |
2077 { | |
2078 CHECK_STRING (instructions); | |
2079 } | |
2080 f->instructions = instructions; | |
2081 | |
2082 if (!NILP (constants)) | |
2083 CHECK_VECTOR (constants); | |
2084 f->constants = constants; | |
2085 | |
2086 CHECK_NATNUM (stack_depth); | |
442 | 2087 f->stack_depth = (unsigned short) XINT (stack_depth); |
428 | 2088 |
2089 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
4923
8ee3c10d1ed5
remove old no-longer-useful kludgy compiled-fun annotations hack
Ben Wing <ben@xemacs.org>
parents:
4921
diff
changeset
|
2090 f->annotated = Vload_file_name_internal; |
428 | 2091 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */ |
2092 | |
2093 /* doc_string may be nil, string, int, or a cons (string . int). | |
2094 interactive may be list or string (or unbound). */ | |
2095 f->doc_and_interactive = Qunbound; | |
2096 #ifdef I18N3 | |
2097 if ((f->flags.domainp = !NILP (Vfile_domain)) != 0) | |
2098 f->doc_and_interactive = Vfile_domain; | |
2099 #endif | |
2100 if ((f->flags.interactivep = !UNBOUNDP (interactive)) != 0) | |
2101 { | |
2102 f->doc_and_interactive | |
2103 = (UNBOUNDP (f->doc_and_interactive) ? interactive : | |
2104 Fcons (interactive, f->doc_and_interactive)); | |
2105 } | |
2106 if ((f->flags.documentationp = !NILP (doc_string)) != 0) | |
2107 { | |
2108 f->doc_and_interactive | |
2109 = (UNBOUNDP (f->doc_and_interactive) ? doc_string : | |
2110 Fcons (doc_string, f->doc_and_interactive)); | |
2111 } | |
2112 if (UNBOUNDP (f->doc_and_interactive)) | |
2113 f->doc_and_interactive = Qnil; | |
2114 | |
2115 return fun; | |
2116 } | |
2117 | |
2118 | |
2119 /************************************************************************/ | |
2120 /* Symbol allocation */ | |
2121 /************************************************************************/ | |
2122 | |
440 | 2123 DECLARE_FIXED_TYPE_ALLOC (symbol, Lisp_Symbol); |
428 | 2124 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_symbol 1000 |
2125 | |
2126 DEFUN ("make-symbol", Fmake_symbol, 1, 1, 0, /* | |
2127 Return a newly allocated uninterned symbol whose name is NAME. | |
2128 Its value and function definition are void, and its property list is nil. | |
2129 */ | |
2130 (name)) | |
2131 { | |
440 | 2132 Lisp_Symbol *p; |
428 | 2133 |
2134 CHECK_STRING (name); | |
2135 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2136 ALLOC_FROB_BLOCK_LISP_OBJECT (symbol, Lisp_Symbol, p, &lrecord_symbol); |
793 | 2137 p->name = name; |
428 | 2138 p->plist = Qnil; |
2139 p->value = Qunbound; | |
2140 p->function = Qunbound; | |
2141 symbol_next (p) = 0; | |
793 | 2142 return wrap_symbol (p); |
428 | 2143 } |
2144 | |
2145 | |
2146 /************************************************************************/ | |
2147 /* Extent allocation */ | |
2148 /************************************************************************/ | |
2149 | |
2150 DECLARE_FIXED_TYPE_ALLOC (extent, struct extent); | |
2151 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_extent 1000 | |
2152 | |
2153 struct extent * | |
2154 allocate_extent (void) | |
2155 { | |
2156 struct extent *e; | |
2157 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2158 ALLOC_FROB_BLOCK_LISP_OBJECT (extent, struct extent, e, &lrecord_extent); |
428 | 2159 extent_object (e) = Qnil; |
2160 set_extent_start (e, -1); | |
2161 set_extent_end (e, -1); | |
2162 e->plist = Qnil; | |
2163 | |
2164 xzero (e->flags); | |
2165 | |
2166 extent_face (e) = Qnil; | |
2167 e->flags.end_open = 1; /* default is for endpoints to behave like markers */ | |
2168 e->flags.detachable = 1; | |
2169 | |
2170 return e; | |
2171 } | |
2172 | |
2173 | |
2174 /************************************************************************/ | |
2175 /* Event allocation */ | |
2176 /************************************************************************/ | |
2177 | |
440 | 2178 DECLARE_FIXED_TYPE_ALLOC (event, Lisp_Event); |
428 | 2179 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_event 1000 |
2180 | |
2181 Lisp_Object | |
2182 allocate_event (void) | |
2183 { | |
440 | 2184 Lisp_Event *e; |
2185 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2186 ALLOC_FROB_BLOCK_LISP_OBJECT (event, Lisp_Event, e, &lrecord_event); |
428 | 2187 |
793 | 2188 return wrap_event (e); |
428 | 2189 } |
2190 | |
1204 | 2191 #ifdef EVENT_DATA_AS_OBJECTS |
934 | 2192 DECLARE_FIXED_TYPE_ALLOC (key_data, Lisp_Key_Data); |
2193 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_key_data 1000 | |
2194 | |
2195 Lisp_Object | |
1204 | 2196 make_key_data (void) |
934 | 2197 { |
2198 Lisp_Key_Data *d; | |
2199 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2200 ALLOC_FROB_BLOCK_LISP_OBJECT (key_data, Lisp_Key_Data, d, |
3017 | 2201 &lrecord_key_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2202 zero_nonsized_lisp_object (wrap_key_data (d)); |
1204 | 2203 d->keysym = Qnil; |
2204 | |
2205 return wrap_key_data (d); | |
934 | 2206 } |
2207 | |
2208 DECLARE_FIXED_TYPE_ALLOC (button_data, Lisp_Button_Data); | |
2209 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_button_data 1000 | |
2210 | |
2211 Lisp_Object | |
1204 | 2212 make_button_data (void) |
934 | 2213 { |
2214 Lisp_Button_Data *d; | |
2215 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2216 ALLOC_FROB_BLOCK_LISP_OBJECT (button_data, Lisp_Button_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2217 &lrecord_button_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2218 zero_nonsized_lisp_object (wrap_button_data (d)); |
1204 | 2219 return wrap_button_data (d); |
934 | 2220 } |
2221 | |
2222 DECLARE_FIXED_TYPE_ALLOC (motion_data, Lisp_Motion_Data); | |
2223 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_motion_data 1000 | |
2224 | |
2225 Lisp_Object | |
1204 | 2226 make_motion_data (void) |
934 | 2227 { |
2228 Lisp_Motion_Data *d; | |
2229 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2230 ALLOC_FROB_BLOCK_LISP_OBJECT (motion_data, Lisp_Motion_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2231 &lrecord_motion_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2232 zero_nonsized_lisp_object (wrap_motion_data (d)); |
934 | 2233 |
1204 | 2234 return wrap_motion_data (d); |
934 | 2235 } |
2236 | |
2237 DECLARE_FIXED_TYPE_ALLOC (process_data, Lisp_Process_Data); | |
2238 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_process_data 1000 | |
2239 | |
2240 Lisp_Object | |
1204 | 2241 make_process_data (void) |
934 | 2242 { |
2243 Lisp_Process_Data *d; | |
2244 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2245 ALLOC_FROB_BLOCK_LISP_OBJECT (process_data, Lisp_Process_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2246 &lrecord_process_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2247 zero_nonsized_lisp_object (wrap_process_data (d)); |
1204 | 2248 d->process = Qnil; |
2249 | |
2250 return wrap_process_data (d); | |
934 | 2251 } |
2252 | |
2253 DECLARE_FIXED_TYPE_ALLOC (timeout_data, Lisp_Timeout_Data); | |
2254 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_timeout_data 1000 | |
2255 | |
2256 Lisp_Object | |
1204 | 2257 make_timeout_data (void) |
934 | 2258 { |
2259 Lisp_Timeout_Data *d; | |
2260 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2261 ALLOC_FROB_BLOCK_LISP_OBJECT (timeout_data, Lisp_Timeout_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2262 &lrecord_timeout_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2263 zero_nonsized_lisp_object (wrap_timeout_data (d)); |
1204 | 2264 d->function = Qnil; |
2265 d->object = Qnil; | |
2266 | |
2267 return wrap_timeout_data (d); | |
934 | 2268 } |
2269 | |
2270 DECLARE_FIXED_TYPE_ALLOC (magic_data, Lisp_Magic_Data); | |
2271 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_magic_data 1000 | |
2272 | |
2273 Lisp_Object | |
1204 | 2274 make_magic_data (void) |
934 | 2275 { |
2276 Lisp_Magic_Data *d; | |
2277 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2278 ALLOC_FROB_BLOCK_LISP_OBJECT (magic_data, Lisp_Magic_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2279 &lrecord_magic_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2280 zero_nonsized_lisp_object (wrap_magic_data (d)); |
934 | 2281 |
1204 | 2282 return wrap_magic_data (d); |
934 | 2283 } |
2284 | |
2285 DECLARE_FIXED_TYPE_ALLOC (magic_eval_data, Lisp_Magic_Eval_Data); | |
2286 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_magic_eval_data 1000 | |
2287 | |
2288 Lisp_Object | |
1204 | 2289 make_magic_eval_data (void) |
934 | 2290 { |
2291 Lisp_Magic_Eval_Data *d; | |
2292 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2293 ALLOC_FROB_BLOCK_LISP_OBJECT (magic_eval_data, Lisp_Magic_Eval_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2294 &lrecord_magic_eval_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2295 zero_nonsized_lisp_object (wrap_magic_eval_data (d)); |
1204 | 2296 d->object = Qnil; |
2297 | |
2298 return wrap_magic_eval_data (d); | |
934 | 2299 } |
2300 | |
2301 DECLARE_FIXED_TYPE_ALLOC (eval_data, Lisp_Eval_Data); | |
2302 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_eval_data 1000 | |
2303 | |
2304 Lisp_Object | |
1204 | 2305 make_eval_data (void) |
934 | 2306 { |
2307 Lisp_Eval_Data *d; | |
2308 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2309 ALLOC_FROB_BLOCK_LISP_OBJECT (eval_data, Lisp_Eval_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2310 &lrecord_eval_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2311 zero_nonsized_lisp_object (wrap_eval_data (d)); |
1204 | 2312 d->function = Qnil; |
2313 d->object = Qnil; | |
2314 | |
2315 return wrap_eval_data (d); | |
934 | 2316 } |
2317 | |
2318 DECLARE_FIXED_TYPE_ALLOC (misc_user_data, Lisp_Misc_User_Data); | |
2319 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_misc_user_data 1000 | |
2320 | |
2321 Lisp_Object | |
1204 | 2322 make_misc_user_data (void) |
934 | 2323 { |
2324 Lisp_Misc_User_Data *d; | |
2325 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2326 ALLOC_FROB_BLOCK_LISP_OBJECT (misc_user_data, Lisp_Misc_User_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2327 &lrecord_misc_user_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2328 zero_nonsized_lisp_object (wrap_misc_user_data (d)); |
1204 | 2329 d->function = Qnil; |
2330 d->object = Qnil; | |
2331 | |
2332 return wrap_misc_user_data (d); | |
934 | 2333 } |
1204 | 2334 |
2335 #endif /* EVENT_DATA_AS_OBJECTS */ | |
428 | 2336 |
2337 /************************************************************************/ | |
2338 /* Marker allocation */ | |
2339 /************************************************************************/ | |
2340 | |
440 | 2341 DECLARE_FIXED_TYPE_ALLOC (marker, Lisp_Marker); |
428 | 2342 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_marker 1000 |
2343 | |
2344 DEFUN ("make-marker", Fmake_marker, 0, 0, 0, /* | |
2345 Return a new marker which does not point at any place. | |
2346 */ | |
2347 ()) | |
2348 { | |
440 | 2349 Lisp_Marker *p; |
2350 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2351 ALLOC_FROB_BLOCK_LISP_OBJECT (marker, Lisp_Marker, p, &lrecord_marker); |
428 | 2352 p->buffer = 0; |
665 | 2353 p->membpos = 0; |
428 | 2354 marker_next (p) = 0; |
2355 marker_prev (p) = 0; | |
2356 p->insertion_type = 0; | |
793 | 2357 return wrap_marker (p); |
428 | 2358 } |
2359 | |
2360 Lisp_Object | |
2361 noseeum_make_marker (void) | |
2362 { | |
440 | 2363 Lisp_Marker *p; |
2364 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2365 NOSEEUM_ALLOC_FROB_BLOCK_LISP_OBJECT (marker, Lisp_Marker, p, |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2366 &lrecord_marker); |
428 | 2367 p->buffer = 0; |
665 | 2368 p->membpos = 0; |
428 | 2369 marker_next (p) = 0; |
2370 marker_prev (p) = 0; | |
2371 p->insertion_type = 0; | |
793 | 2372 return wrap_marker (p); |
428 | 2373 } |
2374 | |
2375 | |
2376 /************************************************************************/ | |
2377 /* String allocation */ | |
2378 /************************************************************************/ | |
2379 | |
2380 /* The data for "short" strings generally resides inside of structs of type | |
2381 string_chars_block. The Lisp_String structure is allocated just like any | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2382 other frob-block lrecord, and these are freelisted when they get garbage |
1204 | 2383 collected. The data for short strings get compacted, but the data for |
2384 large strings do not. | |
428 | 2385 |
2386 Previously Lisp_String structures were relocated, but this caused a lot | |
2387 of bus-errors because the C code didn't include enough GCPRO's for | |
2388 strings (since EVERY REFERENCE to a short string needed to be GCPRO'd so | |
2389 that the reference would get relocated). | |
2390 | |
2391 This new method makes things somewhat bigger, but it is MUCH safer. */ | |
2392 | |
438 | 2393 DECLARE_FIXED_TYPE_ALLOC (string, Lisp_String); |
428 | 2394 /* strings are used and freed quite often */ |
2395 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 10000 */ | |
2396 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 1000 | |
2397 | |
2398 static Lisp_Object | |
2399 mark_string (Lisp_Object obj) | |
2400 { | |
793 | 2401 if (CONSP (XSTRING_PLIST (obj)) && EXTENT_INFOP (XCAR (XSTRING_PLIST (obj)))) |
2402 flush_cached_extent_info (XCAR (XSTRING_PLIST (obj))); | |
2403 return XSTRING_PLIST (obj); | |
428 | 2404 } |
2405 | |
2406 static int | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2407 string_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth), |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2408 int foldcase) |
428 | 2409 { |
2410 Bytecount len; | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2411 if (foldcase) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2412 return !lisp_strcasecmp_i18n (obj1, obj2); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2413 else |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2414 return (((len = XSTRING_LENGTH (obj1)) == XSTRING_LENGTH (obj2)) && |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2415 !memcmp (XSTRING_DATA (obj1), XSTRING_DATA (obj2), len)); |
428 | 2416 } |
2417 | |
1204 | 2418 static const struct memory_description string_description[] = { |
3092 | 2419 #ifdef NEW_GC |
2420 { XD_LISP_OBJECT, offsetof (Lisp_String, data_object) }, | |
2421 #else /* not NEW_GC */ | |
793 | 2422 { XD_BYTECOUNT, offsetof (Lisp_String, size_) }, |
2423 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String, data_), XD_INDIRECT(0, 1) }, | |
3092 | 2424 #endif /* not NEW_GC */ |
440 | 2425 { XD_LISP_OBJECT, offsetof (Lisp_String, plist) }, |
428 | 2426 { XD_END } |
2427 }; | |
2428 | |
442 | 2429 /* We store the string's extent info as the first element of the string's |
2430 property list; and the string's MODIFF as the first or second element | |
2431 of the string's property list (depending on whether the extent info | |
2432 is present), but only if the string has been modified. This is ugly | |
2433 but it reduces the memory allocated for the string in the vast | |
2434 majority of cases, where the string is never modified and has no | |
2435 extent info. | |
2436 | |
2437 #### This means you can't use an int as a key in a string's plist. */ | |
2438 | |
2439 static Lisp_Object * | |
2440 string_plist_ptr (Lisp_Object string) | |
2441 { | |
793 | 2442 Lisp_Object *ptr = &XSTRING_PLIST (string); |
442 | 2443 |
2444 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr))) | |
2445 ptr = &XCDR (*ptr); | |
2446 if (CONSP (*ptr) && INTP (XCAR (*ptr))) | |
2447 ptr = &XCDR (*ptr); | |
2448 return ptr; | |
2449 } | |
2450 | |
2451 static Lisp_Object | |
2452 string_getprop (Lisp_Object string, Lisp_Object property) | |
2453 { | |
2454 return external_plist_get (string_plist_ptr (string), property, 0, ERROR_ME); | |
2455 } | |
2456 | |
2457 static int | |
2458 string_putprop (Lisp_Object string, Lisp_Object property, Lisp_Object value) | |
2459 { | |
2460 external_plist_put (string_plist_ptr (string), property, value, 0, ERROR_ME); | |
2461 return 1; | |
2462 } | |
2463 | |
2464 static int | |
2465 string_remprop (Lisp_Object string, Lisp_Object property) | |
2466 { | |
2467 return external_remprop (string_plist_ptr (string), property, 0, ERROR_ME); | |
2468 } | |
2469 | |
2470 static Lisp_Object | |
2471 string_plist (Lisp_Object string) | |
2472 { | |
2473 return *string_plist_ptr (string); | |
2474 } | |
2475 | |
3263 | 2476 #ifndef NEW_GC |
442 | 2477 /* No `finalize', or `hash' methods. |
2478 internal_hash() already knows how to hash strings and finalization | |
2479 is done with the ADDITIONAL_FREE_string macro, which is the | |
2480 standard way to do finalization when using | |
2481 SWEEP_FIXED_TYPE_BLOCK(). */ | |
2720 | 2482 |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2483 DEFINE_DUMPABLE_FROB_BLOCK_LISP_OBJECT ("string", string, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2484 mark_string, print_string, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2485 0, string_equal, 0, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2486 string_description, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2487 Lisp_String); |
3263 | 2488 #endif /* not NEW_GC */ |
2720 | 2489 |
3092 | 2490 #ifdef NEW_GC |
2491 #define STRING_FULLSIZE(size) \ | |
2492 ALIGN_SIZE (FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_String_Direct_Data, Lisp_Object, data, (size) + 1), sizeof (Lisp_Object *)); | |
2493 #else /* not NEW_GC */ | |
428 | 2494 /* String blocks contain this many useful bytes. */ |
2495 #define STRING_CHARS_BLOCK_SIZE \ | |
814 | 2496 ((Bytecount) (8192 - MALLOC_OVERHEAD - \ |
2497 ((2 * sizeof (struct string_chars_block *)) \ | |
2498 + sizeof (EMACS_INT)))) | |
428 | 2499 /* Block header for small strings. */ |
2500 struct string_chars_block | |
2501 { | |
2502 EMACS_INT pos; | |
2503 struct string_chars_block *next; | |
2504 struct string_chars_block *prev; | |
2505 /* Contents of string_chars_block->string_chars are interleaved | |
2506 string_chars structures (see below) and the actual string data */ | |
2507 unsigned char string_chars[STRING_CHARS_BLOCK_SIZE]; | |
2508 }; | |
2509 | |
2510 static struct string_chars_block *first_string_chars_block; | |
2511 static struct string_chars_block *current_string_chars_block; | |
2512 | |
2513 /* If SIZE is the length of a string, this returns how many bytes | |
2514 * the string occupies in string_chars_block->string_chars | |
2515 * (including alignment padding). | |
2516 */ | |
438 | 2517 #define STRING_FULLSIZE(size) \ |
826 | 2518 ALIGN_FOR_TYPE (((size) + 1 + sizeof (Lisp_String *)), Lisp_String *) |
428 | 2519 |
2520 #define BIG_STRING_FULLSIZE_P(fullsize) ((fullsize) >= STRING_CHARS_BLOCK_SIZE) | |
2521 #define BIG_STRING_SIZE_P(size) (BIG_STRING_FULLSIZE_P (STRING_FULLSIZE(size))) | |
2522 | |
454 | 2523 #define STRING_CHARS_FREE_P(ptr) ((ptr)->string == NULL) |
2524 #define MARK_STRING_CHARS_AS_FREE(ptr) ((void) ((ptr)->string = NULL)) | |
3092 | 2525 #endif /* not NEW_GC */ |
454 | 2526 |
3263 | 2527 #ifdef NEW_GC |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2528 DEFINE_DUMPABLE_LISP_OBJECT ("string", string, mark_string, print_string, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2529 0, string_equal, 0, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2530 string_description, Lisp_String); |
3092 | 2531 |
2532 | |
2533 static const struct memory_description string_direct_data_description[] = { | |
3514 | 2534 { XD_BYTECOUNT, offsetof (Lisp_String_Direct_Data, size) }, |
3092 | 2535 { XD_END } |
2536 }; | |
2537 | |
2538 static Bytecount | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2539 size_string_direct_data (Lisp_Object obj) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2540 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2541 return STRING_FULLSIZE (XSTRING_DIRECT_DATA (obj)->size); |
3092 | 2542 } |
2543 | |
2544 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2545 DEFINE_DUMPABLE_SIZABLE_INTERNAL_LISP_OBJECT ("string-direct-data", |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2546 string_direct_data, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2547 0, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2548 string_direct_data_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2549 size_string_direct_data, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2550 Lisp_String_Direct_Data); |
3092 | 2551 |
2552 | |
2553 static const struct memory_description string_indirect_data_description[] = { | |
2554 { XD_BYTECOUNT, offsetof (Lisp_String_Indirect_Data, size) }, | |
2555 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String_Indirect_Data, data), | |
2556 XD_INDIRECT(0, 1) }, | |
2557 { XD_END } | |
2558 }; | |
2559 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2560 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("string-indirect-data", |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2561 string_indirect_data, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2562 0, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2563 string_indirect_data_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2564 Lisp_String_Indirect_Data); |
3092 | 2565 #endif /* NEW_GC */ |
2720 | 2566 |
3092 | 2567 #ifndef NEW_GC |
428 | 2568 struct string_chars |
2569 { | |
438 | 2570 Lisp_String *string; |
428 | 2571 unsigned char chars[1]; |
2572 }; | |
2573 | |
2574 struct unused_string_chars | |
2575 { | |
438 | 2576 Lisp_String *string; |
428 | 2577 EMACS_INT fullsize; |
2578 }; | |
2579 | |
2580 static void | |
2581 init_string_chars_alloc (void) | |
2582 { | |
2583 first_string_chars_block = xnew (struct string_chars_block); | |
2584 first_string_chars_block->prev = 0; | |
2585 first_string_chars_block->next = 0; | |
2586 first_string_chars_block->pos = 0; | |
2587 current_string_chars_block = first_string_chars_block; | |
2588 } | |
2589 | |
1550 | 2590 static Ibyte * |
2591 allocate_big_string_chars (Bytecount length) | |
2592 { | |
2593 Ibyte *p = xnew_array (Ibyte, length); | |
2594 INCREMENT_CONS_COUNTER (length, "string chars"); | |
2595 return p; | |
2596 } | |
2597 | |
428 | 2598 static struct string_chars * |
793 | 2599 allocate_string_chars_struct (Lisp_Object string_it_goes_with, |
814 | 2600 Bytecount fullsize) |
428 | 2601 { |
2602 struct string_chars *s_chars; | |
2603 | |
438 | 2604 if (fullsize <= |
2605 (countof (current_string_chars_block->string_chars) | |
2606 - current_string_chars_block->pos)) | |
428 | 2607 { |
2608 /* This string can fit in the current string chars block */ | |
2609 s_chars = (struct string_chars *) | |
2610 (current_string_chars_block->string_chars | |
2611 + current_string_chars_block->pos); | |
2612 current_string_chars_block->pos += fullsize; | |
2613 } | |
2614 else | |
2615 { | |
2616 /* Make a new current string chars block */ | |
2617 struct string_chars_block *new_scb = xnew (struct string_chars_block); | |
2618 | |
2619 current_string_chars_block->next = new_scb; | |
2620 new_scb->prev = current_string_chars_block; | |
2621 new_scb->next = 0; | |
2622 current_string_chars_block = new_scb; | |
2623 new_scb->pos = fullsize; | |
2624 s_chars = (struct string_chars *) | |
2625 current_string_chars_block->string_chars; | |
2626 } | |
2627 | |
793 | 2628 s_chars->string = XSTRING (string_it_goes_with); |
428 | 2629 |
2630 INCREMENT_CONS_COUNTER (fullsize, "string chars"); | |
2631 | |
2632 return s_chars; | |
2633 } | |
3092 | 2634 #endif /* not NEW_GC */ |
428 | 2635 |
771 | 2636 #ifdef SLEDGEHAMMER_CHECK_ASCII_BEGIN |
2637 void | |
2638 sledgehammer_check_ascii_begin (Lisp_Object str) | |
2639 { | |
2640 Bytecount i; | |
2641 | |
2642 for (i = 0; i < XSTRING_LENGTH (str); i++) | |
2643 { | |
826 | 2644 if (!byte_ascii_p (string_byte (str, i))) |
771 | 2645 break; |
2646 } | |
2647 | |
2648 assert (i == (Bytecount) XSTRING_ASCII_BEGIN (str) || | |
2649 (i > MAX_STRING_ASCII_BEGIN && | |
2650 (Bytecount) XSTRING_ASCII_BEGIN (str) == | |
2651 (Bytecount) MAX_STRING_ASCII_BEGIN)); | |
2652 } | |
2653 #endif | |
2654 | |
2655 /* You do NOT want to be calling this! (And if you do, you must call | |
851 | 2656 XSET_STRING_ASCII_BEGIN() after modifying the string.) Use ALLOCA () |
771 | 2657 instead and then call make_string() like the rest of the world. */ |
2658 | |
428 | 2659 Lisp_Object |
2660 make_uninit_string (Bytecount length) | |
2661 { | |
438 | 2662 Lisp_String *s; |
814 | 2663 Bytecount fullsize = STRING_FULLSIZE (length); |
428 | 2664 |
438 | 2665 assert (length >= 0 && fullsize > 0); |
428 | 2666 |
3263 | 2667 #ifdef NEW_GC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2668 s = XSTRING (ALLOC_NORMAL_LISP_OBJECT (string)); |
3263 | 2669 #else /* not NEW_GC */ |
428 | 2670 /* Allocate the string header */ |
438 | 2671 ALLOCATE_FIXED_TYPE (string, Lisp_String, s); |
793 | 2672 xzero (*s); |
771 | 2673 set_lheader_implementation (&s->u.lheader, &lrecord_string); |
3263 | 2674 #endif /* not NEW_GC */ |
2720 | 2675 |
3063 | 2676 /* The above allocations set the UID field, which overlaps with the |
2677 ascii-length field, to some non-zero value. We need to zero it. */ | |
2678 XSET_STRING_ASCII_BEGIN (wrap_string (s), 0); | |
2679 | |
3092 | 2680 #ifdef NEW_GC |
3304 | 2681 set_lispstringp_direct (s); |
3092 | 2682 STRING_DATA_OBJECT (s) = |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2683 alloc_sized_lrecord (fullsize, &lrecord_string_direct_data); |
3092 | 2684 #else /* not NEW_GC */ |
826 | 2685 set_lispstringp_data (s, BIG_STRING_FULLSIZE_P (fullsize) |
2720 | 2686 ? allocate_big_string_chars (length + 1) |
2687 : allocate_string_chars_struct (wrap_string (s), | |
2688 fullsize)->chars); | |
3092 | 2689 #endif /* not NEW_GC */ |
438 | 2690 |
826 | 2691 set_lispstringp_length (s, length); |
428 | 2692 s->plist = Qnil; |
793 | 2693 set_string_byte (wrap_string (s), length, 0); |
2694 | |
2695 return wrap_string (s); | |
428 | 2696 } |
2697 | |
2698 #ifdef VERIFY_STRING_CHARS_INTEGRITY | |
2699 static void verify_string_chars_integrity (void); | |
2700 #endif | |
2701 | |
2702 /* Resize the string S so that DELTA bytes can be inserted starting | |
2703 at POS. If DELTA < 0, it means deletion starting at POS. If | |
2704 POS < 0, resize the string but don't copy any characters. Use | |
2705 this if you're planning on completely overwriting the string. | |
2706 */ | |
2707 | |
2708 void | |
793 | 2709 resize_string (Lisp_Object s, Bytecount pos, Bytecount delta) |
428 | 2710 { |
3092 | 2711 #ifdef NEW_GC |
2712 Bytecount newfullsize, len; | |
2713 #else /* not NEW_GC */ | |
438 | 2714 Bytecount oldfullsize, newfullsize; |
3092 | 2715 #endif /* not NEW_GC */ |
428 | 2716 #ifdef VERIFY_STRING_CHARS_INTEGRITY |
2717 verify_string_chars_integrity (); | |
2718 #endif | |
800 | 2719 #ifdef ERROR_CHECK_TEXT |
428 | 2720 if (pos >= 0) |
2721 { | |
793 | 2722 assert (pos <= XSTRING_LENGTH (s)); |
428 | 2723 if (delta < 0) |
793 | 2724 assert (pos + (-delta) <= XSTRING_LENGTH (s)); |
428 | 2725 } |
2726 else | |
2727 { | |
2728 if (delta < 0) | |
793 | 2729 assert ((-delta) <= XSTRING_LENGTH (s)); |
428 | 2730 } |
800 | 2731 #endif /* ERROR_CHECK_TEXT */ |
428 | 2732 |
2733 if (delta == 0) | |
2734 /* simplest case: no size change. */ | |
2735 return; | |
438 | 2736 |
2737 if (pos >= 0 && delta < 0) | |
2738 /* If DELTA < 0, the functions below will delete the characters | |
2739 before POS. We want to delete characters *after* POS, however, | |
2740 so convert this to the appropriate form. */ | |
2741 pos += -delta; | |
2742 | |
3092 | 2743 #ifdef NEW_GC |
2744 newfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s) + delta); | |
2745 | |
2746 len = XSTRING_LENGTH (s) + 1 - pos; | |
2747 | |
2748 if (delta < 0 && pos >= 0) | |
2749 memmove (XSTRING_DATA (s) + pos + delta, | |
2750 XSTRING_DATA (s) + pos, len); | |
2751 | |
2752 XSTRING_DATA_OBJECT (s) = | |
2753 wrap_string_direct_data (mc_realloc (XPNTR (XSTRING_DATA_OBJECT (s)), | |
2754 newfullsize)); | |
2755 if (delta > 0 && pos >= 0) | |
2756 memmove (XSTRING_DATA (s) + pos + delta, XSTRING_DATA (s) + pos, | |
2757 len); | |
2758 | |
3263 | 2759 #else /* not NEW_GC */ |
793 | 2760 oldfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s)); |
2761 newfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s) + delta); | |
438 | 2762 |
2763 if (BIG_STRING_FULLSIZE_P (oldfullsize)) | |
428 | 2764 { |
438 | 2765 if (BIG_STRING_FULLSIZE_P (newfullsize)) |
428 | 2766 { |
440 | 2767 /* Both strings are big. We can just realloc(). |
2768 But careful! If the string is shrinking, we have to | |
2769 memmove() _before_ realloc(), and if growing, we have to | |
2770 memmove() _after_ realloc() - otherwise the access is | |
2771 illegal, and we might crash. */ | |
793 | 2772 Bytecount len = XSTRING_LENGTH (s) + 1 - pos; |
440 | 2773 |
2774 if (delta < 0 && pos >= 0) | |
793 | 2775 memmove (XSTRING_DATA (s) + pos + delta, |
2776 XSTRING_DATA (s) + pos, len); | |
2777 XSET_STRING_DATA | |
867 | 2778 (s, (Ibyte *) xrealloc (XSTRING_DATA (s), |
793 | 2779 XSTRING_LENGTH (s) + delta + 1)); |
440 | 2780 if (delta > 0 && pos >= 0) |
793 | 2781 memmove (XSTRING_DATA (s) + pos + delta, XSTRING_DATA (s) + pos, |
2782 len); | |
1550 | 2783 /* Bump the cons counter. |
2784 Conservative; Martin let the increment be delta. */ | |
2785 INCREMENT_CONS_COUNTER (newfullsize, "string chars"); | |
428 | 2786 } |
438 | 2787 else /* String has been demoted from BIG_STRING. */ |
428 | 2788 { |
867 | 2789 Ibyte *new_data = |
438 | 2790 allocate_string_chars_struct (s, newfullsize)->chars; |
867 | 2791 Ibyte *old_data = XSTRING_DATA (s); |
438 | 2792 |
2793 if (pos >= 0) | |
2794 { | |
2795 memcpy (new_data, old_data, pos); | |
2796 memcpy (new_data + pos + delta, old_data + pos, | |
793 | 2797 XSTRING_LENGTH (s) + 1 - pos); |
438 | 2798 } |
793 | 2799 XSET_STRING_DATA (s, new_data); |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
2800 xfree (old_data); |
438 | 2801 } |
2802 } | |
2803 else /* old string is small */ | |
2804 { | |
2805 if (oldfullsize == newfullsize) | |
2806 { | |
2807 /* special case; size change but the necessary | |
2808 allocation size won't change (up or down; code | |
2809 somewhere depends on there not being any unused | |
2810 allocation space, modulo any alignment | |
2811 constraints). */ | |
428 | 2812 if (pos >= 0) |
2813 { | |
867 | 2814 Ibyte *addroff = pos + XSTRING_DATA (s); |
428 | 2815 |
2816 memmove (addroff + delta, addroff, | |
2817 /* +1 due to zero-termination. */ | |
793 | 2818 XSTRING_LENGTH (s) + 1 - pos); |
428 | 2819 } |
2820 } | |
2821 else | |
2822 { | |
867 | 2823 Ibyte *old_data = XSTRING_DATA (s); |
2824 Ibyte *new_data = | |
438 | 2825 BIG_STRING_FULLSIZE_P (newfullsize) |
1550 | 2826 ? allocate_big_string_chars (XSTRING_LENGTH (s) + delta + 1) |
438 | 2827 : allocate_string_chars_struct (s, newfullsize)->chars; |
2828 | |
428 | 2829 if (pos >= 0) |
2830 { | |
438 | 2831 memcpy (new_data, old_data, pos); |
2832 memcpy (new_data + pos + delta, old_data + pos, | |
793 | 2833 XSTRING_LENGTH (s) + 1 - pos); |
428 | 2834 } |
793 | 2835 XSET_STRING_DATA (s, new_data); |
438 | 2836 |
4776
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2837 if (!DUMPEDP (old_data)) /* Can't free dumped data. */ |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2838 { |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2839 /* We need to mark this chunk of the string_chars_block |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2840 as unused so that compact_string_chars() doesn't |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2841 freak. */ |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2842 struct string_chars *old_s_chars = (struct string_chars *) |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2843 ((char *) old_data - offsetof (struct string_chars, chars)); |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2844 /* Sanity check to make sure we aren't hosed by strange |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2845 alignment/padding. */ |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2846 assert (old_s_chars->string == XSTRING (s)); |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2847 MARK_STRING_CHARS_AS_FREE (old_s_chars); |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2848 ((struct unused_string_chars *) old_s_chars)->fullsize = |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2849 oldfullsize; |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2850 } |
428 | 2851 } |
438 | 2852 } |
3092 | 2853 #endif /* not NEW_GC */ |
438 | 2854 |
793 | 2855 XSET_STRING_LENGTH (s, XSTRING_LENGTH (s) + delta); |
438 | 2856 /* If pos < 0, the string won't be zero-terminated. |
2857 Terminate now just to make sure. */ | |
793 | 2858 XSTRING_DATA (s)[XSTRING_LENGTH (s)] = '\0'; |
438 | 2859 |
2860 if (pos >= 0) | |
793 | 2861 /* We also have to adjust all of the extent indices after the |
2862 place we did the change. We say "pos - 1" because | |
2863 adjust_extents() is exclusive of the starting position | |
2864 passed to it. */ | |
2865 adjust_extents (s, pos - 1, XSTRING_LENGTH (s), delta); | |
428 | 2866 |
2867 #ifdef VERIFY_STRING_CHARS_INTEGRITY | |
2868 verify_string_chars_integrity (); | |
2869 #endif | |
2870 } | |
2871 | |
2872 #ifdef MULE | |
2873 | |
771 | 2874 /* WARNING: If you modify an existing string, you must call |
2875 CHECK_LISP_WRITEABLE() before and bump_string_modiff() afterwards. */ | |
428 | 2876 void |
867 | 2877 set_string_char (Lisp_Object s, Charcount i, Ichar c) |
428 | 2878 { |
867 | 2879 Ibyte newstr[MAX_ICHAR_LEN]; |
771 | 2880 Bytecount bytoff = string_index_char_to_byte (s, i); |
867 | 2881 Bytecount oldlen = itext_ichar_len (XSTRING_DATA (s) + bytoff); |
2882 Bytecount newlen = set_itext_ichar (newstr, c); | |
428 | 2883 |
793 | 2884 sledgehammer_check_ascii_begin (s); |
428 | 2885 if (oldlen != newlen) |
2886 resize_string (s, bytoff, newlen - oldlen); | |
793 | 2887 /* Remember, XSTRING_DATA (s) might have changed so we can't cache it. */ |
2888 memcpy (XSTRING_DATA (s) + bytoff, newstr, newlen); | |
771 | 2889 if (oldlen != newlen) |
2890 { | |
793 | 2891 if (newlen > 1 && i <= (Charcount) XSTRING_ASCII_BEGIN (s)) |
771 | 2892 /* Everything starting with the new char is no longer part of |
2893 ascii_begin */ | |
793 | 2894 XSET_STRING_ASCII_BEGIN (s, i); |
2895 else if (newlen == 1 && i == (Charcount) XSTRING_ASCII_BEGIN (s)) | |
771 | 2896 /* We've extended ascii_begin, and we have to figure out how much by */ |
2897 { | |
2898 Bytecount j; | |
814 | 2899 for (j = (Bytecount) i + 1; j < XSTRING_LENGTH (s); j++) |
771 | 2900 { |
826 | 2901 if (!byte_ascii_p (XSTRING_DATA (s)[j])) |
771 | 2902 break; |
2903 } | |
814 | 2904 XSET_STRING_ASCII_BEGIN (s, min (j, (Bytecount) MAX_STRING_ASCII_BEGIN)); |
771 | 2905 } |
2906 } | |
793 | 2907 sledgehammer_check_ascii_begin (s); |
428 | 2908 } |
2909 | |
2910 #endif /* MULE */ | |
2911 | |
2912 DEFUN ("make-string", Fmake_string, 2, 2, 0, /* | |
444 | 2913 Return a new string consisting of LENGTH copies of CHARACTER. |
2914 LENGTH must be a non-negative integer. | |
428 | 2915 */ |
444 | 2916 (length, character)) |
428 | 2917 { |
2918 CHECK_NATNUM (length); | |
444 | 2919 CHECK_CHAR_COERCE_INT (character); |
428 | 2920 { |
867 | 2921 Ibyte init_str[MAX_ICHAR_LEN]; |
2922 int len = set_itext_ichar (init_str, XCHAR (character)); | |
428 | 2923 Lisp_Object val = make_uninit_string (len * XINT (length)); |
2924 | |
2925 if (len == 1) | |
771 | 2926 { |
2927 /* Optimize the single-byte case */ | |
2928 memset (XSTRING_DATA (val), XCHAR (character), XSTRING_LENGTH (val)); | |
793 | 2929 XSET_STRING_ASCII_BEGIN (val, min (MAX_STRING_ASCII_BEGIN, |
2930 len * XINT (length))); | |
771 | 2931 } |
428 | 2932 else |
2933 { | |
647 | 2934 EMACS_INT i; |
867 | 2935 Ibyte *ptr = XSTRING_DATA (val); |
428 | 2936 |
2937 for (i = XINT (length); i; i--) | |
2938 { | |
867 | 2939 Ibyte *init_ptr = init_str; |
428 | 2940 switch (len) |
2941 { | |
2942 case 4: *ptr++ = *init_ptr++; | |
2943 case 3: *ptr++ = *init_ptr++; | |
2944 case 2: *ptr++ = *init_ptr++; | |
2945 case 1: *ptr++ = *init_ptr++; | |
2946 } | |
2947 } | |
2948 } | |
771 | 2949 sledgehammer_check_ascii_begin (val); |
428 | 2950 return val; |
2951 } | |
2952 } | |
2953 | |
2954 DEFUN ("string", Fstring, 0, MANY, 0, /* | |
2955 Concatenate all the argument characters and make the result a string. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
2956 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
2957 arguments: (&rest ARGS) |
428 | 2958 */ |
2959 (int nargs, Lisp_Object *args)) | |
2960 { | |
2367 | 2961 Ibyte *storage = alloca_ibytes (nargs * MAX_ICHAR_LEN); |
867 | 2962 Ibyte *p = storage; |
428 | 2963 |
2964 for (; nargs; nargs--, args++) | |
2965 { | |
2966 Lisp_Object lisp_char = *args; | |
2967 CHECK_CHAR_COERCE_INT (lisp_char); | |
867 | 2968 p += set_itext_ichar (p, XCHAR (lisp_char)); |
428 | 2969 } |
2970 return make_string (storage, p - storage); | |
2971 } | |
2972 | |
771 | 2973 /* Initialize the ascii_begin member of a string to the correct value. */ |
2974 | |
2975 void | |
2976 init_string_ascii_begin (Lisp_Object string) | |
2977 { | |
2978 #ifdef MULE | |
2979 int i; | |
2980 Bytecount length = XSTRING_LENGTH (string); | |
867 | 2981 Ibyte *contents = XSTRING_DATA (string); |
771 | 2982 |
2983 for (i = 0; i < length; i++) | |
2984 { | |
826 | 2985 if (!byte_ascii_p (contents[i])) |
771 | 2986 break; |
2987 } | |
793 | 2988 XSET_STRING_ASCII_BEGIN (string, min (i, MAX_STRING_ASCII_BEGIN)); |
771 | 2989 #else |
793 | 2990 XSET_STRING_ASCII_BEGIN (string, min (XSTRING_LENGTH (string), |
2991 MAX_STRING_ASCII_BEGIN)); | |
771 | 2992 #endif |
2993 sledgehammer_check_ascii_begin (string); | |
2994 } | |
428 | 2995 |
2996 /* Take some raw memory, which MUST already be in internal format, | |
2997 and package it up into a Lisp string. */ | |
2998 Lisp_Object | |
867 | 2999 make_string (const Ibyte *contents, Bytecount length) |
428 | 3000 { |
3001 Lisp_Object val; | |
3002 | |
3003 /* Make sure we find out about bad make_string's when they happen */ | |
800 | 3004 #if defined (ERROR_CHECK_TEXT) && defined (MULE) |
428 | 3005 bytecount_to_charcount (contents, length); /* Just for the assertions */ |
3006 #endif | |
3007 | |
3008 val = make_uninit_string (length); | |
3009 memcpy (XSTRING_DATA (val), contents, length); | |
771 | 3010 init_string_ascii_begin (val); |
3011 sledgehammer_check_ascii_begin (val); | |
428 | 3012 return val; |
3013 } | |
3014 | |
3015 /* Take some raw memory, encoded in some external data format, | |
3016 and convert it into a Lisp string. */ | |
3017 Lisp_Object | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3018 make_extstring (const Extbyte *contents, EMACS_INT length, |
440 | 3019 Lisp_Object coding_system) |
428 | 3020 { |
440 | 3021 Lisp_Object string; |
3022 TO_INTERNAL_FORMAT (DATA, (contents, length), | |
3023 LISP_STRING, string, | |
3024 coding_system); | |
3025 return string; | |
428 | 3026 } |
3027 | |
3028 Lisp_Object | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3029 build_istring (const Ibyte *str) |
771 | 3030 { |
3031 /* Some strlen's crash and burn if passed null. */ | |
814 | 3032 return make_string (str, (str ? qxestrlen (str) : (Bytecount) 0)); |
771 | 3033 } |
3034 | |
3035 Lisp_Object | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3036 build_cistring (const CIbyte *str) |
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3037 { |
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3038 return build_istring ((const Ibyte *) str); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3039 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3040 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3041 Lisp_Object |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3042 build_ascstring (const Ascbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3043 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3044 ASSERT_ASCTEXT_ASCII (str); |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3045 return build_istring ((const Ibyte *) str); |
428 | 3046 } |
3047 | |
3048 Lisp_Object | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3049 build_extstring (const Extbyte *str, Lisp_Object coding_system) |
428 | 3050 { |
3051 /* Some strlen's crash and burn if passed null. */ | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3052 return make_extstring ((const Extbyte *) str, |
2367 | 3053 (str ? dfc_external_data_len (str, coding_system) : |
3054 0), | |
440 | 3055 coding_system); |
428 | 3056 } |
3057 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3058 /* Build a string whose content is a translatable message, and translate |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3059 the message according to the current language environment. */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3060 |
428 | 3061 Lisp_Object |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3062 build_msg_istring (const Ibyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3063 { |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3064 return build_istring (IGETTEXT (str)); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3065 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3066 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3067 /* Build a string whose content is a translatable message, and translate |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3068 the message according to the current language environment. */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3069 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3070 Lisp_Object |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3071 build_msg_cistring (const CIbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3072 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3073 return build_msg_istring ((const Ibyte *) str); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3074 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3075 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3076 /* Build a string whose content is a translatable message, and translate |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3077 the message according to the current language environment. |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3078 String must be pure-ASCII, and when compiled with error-checking, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3079 an abort will have if not pure-ASCII. */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3080 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3081 Lisp_Object |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3082 build_msg_ascstring (const Ascbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3083 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3084 ASSERT_ASCTEXT_ASCII (str); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3085 return build_msg_istring ((const Ibyte *) str); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3086 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3087 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3088 /* Build a string whose content is a translatable message, but don't |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3089 translate the message immediately. Perhaps do something else instead, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3090 such as put a property on the string indicating that it needs to be |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3091 translated. |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3092 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3093 This is useful for strings that are built at dump time or init time, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3094 rather than on-the-fly when the current language environment is set |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3095 properly. */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3096 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3097 Lisp_Object |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3098 build_defer_istring (const Ibyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3099 { |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3100 Lisp_Object retval = build_istring ((Ibyte *) str); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3101 /* Possibly do something to the return value */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3102 return retval; |
771 | 3103 } |
3104 | |
428 | 3105 Lisp_Object |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3106 build_defer_cistring (const CIbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3107 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3108 return build_defer_istring ((Ibyte *) str); |
771 | 3109 } |
3110 | |
3111 Lisp_Object | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3112 build_defer_ascstring (const Ascbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3113 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3114 ASSERT_ASCTEXT_ASCII (str); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3115 return build_defer_istring ((Ibyte *) str); |
428 | 3116 } |
3117 | |
3118 Lisp_Object | |
867 | 3119 make_string_nocopy (const Ibyte *contents, Bytecount length) |
428 | 3120 { |
438 | 3121 Lisp_String *s; |
428 | 3122 Lisp_Object val; |
3123 | |
3124 /* Make sure we find out about bad make_string_nocopy's when they happen */ | |
800 | 3125 #if defined (ERROR_CHECK_TEXT) && defined (MULE) |
428 | 3126 bytecount_to_charcount (contents, length); /* Just for the assertions */ |
3127 #endif | |
3128 | |
3263 | 3129 #ifdef NEW_GC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3130 s = XSTRING (ALLOC_NORMAL_LISP_OBJECT (string)); |
2720 | 3131 mcpro (wrap_pointer_1 (s)); /* otherwise nocopy_strings get |
3132 collected and static data is tried to | |
3133 be freed. */ | |
3263 | 3134 #else /* not NEW_GC */ |
428 | 3135 /* Allocate the string header */ |
438 | 3136 ALLOCATE_FIXED_TYPE (string, Lisp_String, s); |
771 | 3137 set_lheader_implementation (&s->u.lheader, &lrecord_string); |
3138 SET_C_READONLY_RECORD_HEADER (&s->u.lheader); | |
3263 | 3139 #endif /* not NEW_GC */ |
3063 | 3140 /* Don't need to XSET_STRING_ASCII_BEGIN() here because it happens in |
3141 init_string_ascii_begin(). */ | |
428 | 3142 s->plist = Qnil; |
3092 | 3143 #ifdef NEW_GC |
3144 set_lispstringp_indirect (s); | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3145 STRING_DATA_OBJECT (s) = ALLOC_NORMAL_LISP_OBJECT (string_indirect_data); |
3092 | 3146 XSTRING_INDIRECT_DATA_DATA (STRING_DATA_OBJECT (s)) = (Ibyte *) contents; |
3147 XSTRING_INDIRECT_DATA_SIZE (STRING_DATA_OBJECT (s)) = length; | |
3148 #else /* not NEW_GC */ | |
867 | 3149 set_lispstringp_data (s, (Ibyte *) contents); |
826 | 3150 set_lispstringp_length (s, length); |
3092 | 3151 #endif /* not NEW_GC */ |
793 | 3152 val = wrap_string (s); |
771 | 3153 init_string_ascii_begin (val); |
3154 sledgehammer_check_ascii_begin (val); | |
3155 | |
428 | 3156 return val; |
3157 } | |
3158 | |
3159 | |
3263 | 3160 #ifndef NEW_GC |
428 | 3161 /************************************************************************/ |
3162 /* lcrecord lists */ | |
3163 /************************************************************************/ | |
3164 | |
3165 /* Lcrecord lists are used to manage the allocation of particular | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3166 sorts of lcrecords, to avoid calling ALLOC_NORMAL_LISP_OBJECT() (and thus |
428 | 3167 malloc() and garbage-collection junk) as much as possible. |
3168 It is similar to the Blocktype class. | |
3169 | |
1204 | 3170 See detailed comment in lcrecord.h. |
3171 */ | |
3172 | |
3173 const struct memory_description free_description[] = { | |
2551 | 3174 { XD_LISP_OBJECT, offsetof (struct free_lcrecord_header, chain), 0, { 0 }, |
1204 | 3175 XD_FLAG_FREE_LISP_OBJECT }, |
3176 { XD_END } | |
3177 }; | |
3178 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3179 DEFINE_NODUMP_INTERNAL_LISP_OBJECT ("free", free, 0, free_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3180 struct free_lcrecord_header); |
1204 | 3181 |
3182 const struct memory_description lcrecord_list_description[] = { | |
2551 | 3183 { XD_LISP_OBJECT, offsetof (struct lcrecord_list, free), 0, { 0 }, |
1204 | 3184 XD_FLAG_FREE_LISP_OBJECT }, |
3185 { XD_END } | |
3186 }; | |
428 | 3187 |
3188 static Lisp_Object | |
3189 mark_lcrecord_list (Lisp_Object obj) | |
3190 { | |
3191 struct lcrecord_list *list = XLCRECORD_LIST (obj); | |
3192 Lisp_Object chain = list->free; | |
3193 | |
3194 while (!NILP (chain)) | |
3195 { | |
3196 struct lrecord_header *lheader = XRECORD_LHEADER (chain); | |
3197 struct free_lcrecord_header *free_header = | |
3198 (struct free_lcrecord_header *) lheader; | |
3199 | |
442 | 3200 gc_checking_assert |
3201 (/* There should be no other pointers to the free list. */ | |
3202 ! MARKED_RECORD_HEADER_P (lheader) | |
3203 && | |
3204 /* Only lcrecords should be here. */ | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3205 ! list->implementation->frob_block_p |
442 | 3206 && |
3207 /* Only free lcrecords should be here. */ | |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
3208 lheader->free |
442 | 3209 && |
3210 /* The type of the lcrecord must be right. */ | |
1204 | 3211 lheader->type == lrecord_type_free |
442 | 3212 && |
3213 /* So must the size. */ | |
1204 | 3214 (list->implementation->static_size == 0 || |
3215 list->implementation->static_size == list->size) | |
442 | 3216 ); |
428 | 3217 |
3218 MARK_RECORD_HEADER (lheader); | |
3219 chain = free_header->chain; | |
3220 } | |
3221 | |
3222 return Qnil; | |
3223 } | |
3224 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3225 DEFINE_NODUMP_INTERNAL_LISP_OBJECT ("lcrecord-list", lcrecord_list, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3226 mark_lcrecord_list, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3227 lcrecord_list_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3228 struct lcrecord_list); |
934 | 3229 |
428 | 3230 Lisp_Object |
665 | 3231 make_lcrecord_list (Elemcount size, |
442 | 3232 const struct lrecord_implementation *implementation) |
428 | 3233 { |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
3234 /* Don't use alloc_automanaged_lcrecord() avoid infinite recursion |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
3235 allocating this. */ |
1204 | 3236 struct lcrecord_list *p = (struct lcrecord_list *) |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
3237 old_alloc_lcrecord (&lrecord_lcrecord_list); |
428 | 3238 |
3239 p->implementation = implementation; | |
3240 p->size = size; | |
3241 p->free = Qnil; | |
793 | 3242 return wrap_lcrecord_list (p); |
428 | 3243 } |
3244 | |
3245 Lisp_Object | |
1204 | 3246 alloc_managed_lcrecord (Lisp_Object lcrecord_list) |
428 | 3247 { |
3248 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list); | |
3249 if (!NILP (list->free)) | |
3250 { | |
3251 Lisp_Object val = list->free; | |
3252 struct free_lcrecord_header *free_header = | |
3253 (struct free_lcrecord_header *) XPNTR (val); | |
1204 | 3254 struct lrecord_header *lheader = &free_header->lcheader.lheader; |
428 | 3255 |
3256 #ifdef ERROR_CHECK_GC | |
1204 | 3257 /* Major overkill here. */ |
428 | 3258 /* There should be no other pointers to the free list. */ |
442 | 3259 assert (! MARKED_RECORD_HEADER_P (lheader)); |
428 | 3260 /* Only free lcrecords should be here. */ |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
3261 assert (lheader->free); |
1204 | 3262 assert (lheader->type == lrecord_type_free); |
3263 /* Only lcrecords should be here. */ | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3264 assert (! (list->implementation->frob_block_p)); |
1204 | 3265 #if 0 /* Not used anymore, now that we set the type of the header to |
3266 lrecord_type_free. */ | |
428 | 3267 /* The type of the lcrecord must be right. */ |
442 | 3268 assert (LHEADER_IMPLEMENTATION (lheader) == list->implementation); |
1204 | 3269 #endif /* 0 */ |
428 | 3270 /* So must the size. */ |
1204 | 3271 assert (list->implementation->static_size == 0 || |
3272 list->implementation->static_size == list->size); | |
428 | 3273 #endif /* ERROR_CHECK_GC */ |
442 | 3274 |
428 | 3275 list->free = free_header->chain; |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
3276 lheader->free = 0; |
1204 | 3277 /* Put back the correct type, as we set it to lrecord_type_free. */ |
3278 lheader->type = list->implementation->lrecord_type_index; | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3279 zero_sized_lisp_object (val, list->size); |
428 | 3280 return val; |
3281 } | |
3282 else | |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
3283 return wrap_pointer_1 (old_alloc_sized_lcrecord (list->size, |
3024 | 3284 list->implementation)); |
428 | 3285 } |
3286 | |
771 | 3287 /* "Free" a Lisp object LCRECORD by placing it on its associated free list |
1204 | 3288 LCRECORD_LIST; next time alloc_managed_lcrecord() is called with the |
771 | 3289 same LCRECORD_LIST as its parameter, it will return an object from the |
3290 free list, which may be this one. Be VERY VERY SURE there are no | |
3291 pointers to this object hanging around anywhere where they might be | |
3292 used! | |
3293 | |
3294 The first thing this does before making any global state change is to | |
3295 call the finalize method of the object, if it exists. */ | |
3296 | |
428 | 3297 void |
3298 free_managed_lcrecord (Lisp_Object lcrecord_list, Lisp_Object lcrecord) | |
3299 { | |
3300 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list); | |
3301 struct free_lcrecord_header *free_header = | |
3302 (struct free_lcrecord_header *) XPNTR (lcrecord); | |
442 | 3303 struct lrecord_header *lheader = &free_header->lcheader.lheader; |
3304 const struct lrecord_implementation *implementation | |
428 | 3305 = LHEADER_IMPLEMENTATION (lheader); |
3306 | |
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3307 /* If we try to debug-print during GC, we'll likely get a crash on the |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3308 following assert (called from Lstream_delete(), from prin1_to_string()). |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3309 Instead, just don't do anything. Worst comes to worst, we have a |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3310 small memory leak -- and programs being debugged usually won't be |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3311 super long-lived afterwards, anyway. */ |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3312 if (gc_in_progress && in_debug_print) |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3313 return; |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3314 |
771 | 3315 /* Finalizer methods may try to free objects within them, which typically |
3316 won't be marked and thus are scheduled for demolition. Putting them | |
3317 on the free list would be very bad, as we'd have xfree()d memory in | |
3318 the list. Even if for some reason the objects are still live | |
3319 (generally a logic error!), we still will have problems putting such | |
3320 an object on the free list right now (e.g. we'd have to avoid calling | |
3321 the finalizer twice, etc.). So basically, those finalizers should not | |
3322 be freeing any objects if during GC. Abort now to catch those | |
3323 problems. */ | |
3324 gc_checking_assert (!gc_in_progress); | |
3325 | |
428 | 3326 /* Make sure the size is correct. This will catch, for example, |
3327 putting a window configuration on the wrong free list. */ | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3328 gc_checking_assert (lisp_object_size (lcrecord) == list->size); |
771 | 3329 /* Make sure the object isn't already freed. */ |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
3330 gc_checking_assert (!lheader->free); |
2367 | 3331 /* Freeing stuff in dumped memory is bad. If you trip this, you |
3332 may need to check for this before freeing. */ | |
3333 gc_checking_assert (!OBJECT_DUMPED_P (lcrecord)); | |
771 | 3334 |
428 | 3335 if (implementation->finalizer) |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3336 implementation->finalizer (lcrecord); |
1204 | 3337 /* Yes, there are two ways to indicate freeness -- the type is |
3338 lrecord_type_free or the ->free flag is set. We used to do only the | |
3339 latter; now we do the former as well for KKCC purposes. Probably | |
3340 safer in any case, as we will lose quicker this way than keeping | |
3341 around an lrecord of apparently correct type but bogus junk in it. */ | |
3342 MARK_LRECORD_AS_FREE (lheader); | |
428 | 3343 free_header->chain = list->free; |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
3344 lheader->free = 1; |
428 | 3345 list->free = lcrecord; |
3346 } | |
3347 | |
771 | 3348 static Lisp_Object all_lcrecord_lists[countof (lrecord_implementations_table)]; |
3349 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3350 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3351 alloc_automanaged_sized_lcrecord (Bytecount size, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3352 const struct lrecord_implementation *imp) |
771 | 3353 { |
3354 if (EQ (all_lcrecord_lists[imp->lrecord_type_index], Qzero)) | |
3355 all_lcrecord_lists[imp->lrecord_type_index] = | |
3356 make_lcrecord_list (size, imp); | |
3357 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3358 return alloc_managed_lcrecord (all_lcrecord_lists[imp->lrecord_type_index]); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3359 } |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3360 |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3361 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3362 alloc_automanaged_lcrecord (const struct lrecord_implementation *imp) |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3363 { |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3364 type_checking_assert (imp->static_size > 0); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3365 return alloc_automanaged_sized_lcrecord (imp->static_size, imp); |
771 | 3366 } |
3367 | |
3368 void | |
3024 | 3369 old_free_lcrecord (Lisp_Object rec) |
771 | 3370 { |
3371 int type = XRECORD_LHEADER (rec)->type; | |
3372 | |
3373 assert (!EQ (all_lcrecord_lists[type], Qzero)); | |
3374 | |
3375 free_managed_lcrecord (all_lcrecord_lists[type], rec); | |
3376 } | |
3263 | 3377 #endif /* not NEW_GC */ |
428 | 3378 |
3379 | |
3380 DEFUN ("purecopy", Fpurecopy, 1, 1, 0, /* | |
3381 Kept for compatibility, returns its argument. | |
3382 Old: | |
3383 Make a copy of OBJECT in pure storage. | |
3384 Recursively copies contents of vectors and cons cells. | |
3385 Does not copy symbols. | |
3386 */ | |
444 | 3387 (object)) |
428 | 3388 { |
444 | 3389 return object; |
428 | 3390 } |
3391 | |
3392 | |
3393 /************************************************************************/ | |
3394 /* Garbage Collection */ | |
3395 /************************************************************************/ | |
3396 | |
1676 | 3397 #ifndef USE_KKCC |
442 | 3398 /* Object marker functions are in the lrecord_implementation structure. |
3399 But copying them to a parallel array is much more cache-friendly. | |
3400 This hack speeds up (garbage-collect) by about 5%. */ | |
3401 Lisp_Object (*lrecord_markers[countof (lrecord_implementations_table)]) (Lisp_Object); | |
1676 | 3402 #endif /* not USE_KKCC */ |
428 | 3403 |
3404 struct gcpro *gcprolist; | |
3405 | |
771 | 3406 /* We want the staticpro list relocated, but not the pointers found |
3407 therein, because they refer to locations in the global data segment, not | |
3408 in the heap; we only dump heap objects. Hence we use a trivial | |
3409 description, as for pointerless objects. (Note that the data segment | |
3410 objects, which are global variables like Qfoo or Vbar, themselves are | |
3411 pointers to heap objects. Each needs to be described to pdump as a | |
3412 "root pointer"; this happens in the call to staticpro(). */ | |
1204 | 3413 static const struct memory_description staticpro_description_1[] = { |
452 | 3414 { XD_END } |
3415 }; | |
3416 | |
1204 | 3417 static const struct sized_memory_description staticpro_description = { |
452 | 3418 sizeof (Lisp_Object *), |
3419 staticpro_description_1 | |
3420 }; | |
3421 | |
1204 | 3422 static const struct memory_description staticpros_description_1[] = { |
452 | 3423 XD_DYNARR_DESC (Lisp_Object_ptr_dynarr, &staticpro_description), |
3424 { XD_END } | |
3425 }; | |
3426 | |
1204 | 3427 static const struct sized_memory_description staticpros_description = { |
452 | 3428 sizeof (Lisp_Object_ptr_dynarr), |
3429 staticpros_description_1 | |
3430 }; | |
3431 | |
771 | 3432 #ifdef DEBUG_XEMACS |
3433 | |
3434 /* Help debug crashes gc-marking a staticpro'ed object. */ | |
3435 | |
3436 Lisp_Object_ptr_dynarr *staticpros; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3437 const_Ascbyte_ptr_dynarr *staticpro_names; |
771 | 3438 |
3439 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3440 garbage collection, and for dumping. */ | |
3441 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3442 staticpro_1 (Lisp_Object *varaddress, const Ascbyte *varname) |
771 | 3443 { |
3444 Dynarr_add (staticpros, varaddress); | |
3445 Dynarr_add (staticpro_names, varname); | |
1204 | 3446 dump_add_root_lisp_object (varaddress); |
771 | 3447 } |
3448 | |
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3449 const Ascbyte *staticpro_name (int count); |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3450 |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3451 /* External debugging function: Return the name of the variable at offset |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3452 COUNT. */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3453 const Ascbyte * |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3454 staticpro_name (int count) |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3455 { |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3456 return Dynarr_at (staticpro_names, count); |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3457 } |
771 | 3458 |
3459 Lisp_Object_ptr_dynarr *staticpros_nodump; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3460 const_Ascbyte_ptr_dynarr *staticpro_nodump_names; |
771 | 3461 |
3462 /* Mark the Lisp_Object at heap VARADDRESS as a root object for | |
3463 garbage collection, but not for dumping. (See below.) */ | |
3464 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3465 staticpro_nodump_1 (Lisp_Object *varaddress, const Ascbyte *varname) |
771 | 3466 { |
3467 Dynarr_add (staticpros_nodump, varaddress); | |
3468 Dynarr_add (staticpro_nodump_names, varname); | |
3469 } | |
3470 | |
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3471 const Ascbyte *staticpro_nodump_name (int count); |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3472 |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3473 /* External debugging function: Return the name of the variable at offset |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3474 COUNT. */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3475 const Ascbyte * |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3476 staticpro_nodump_name (int count) |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3477 { |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3478 return Dynarr_at (staticpro_nodump_names, count); |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3479 } |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3480 |
996 | 3481 #ifdef HAVE_SHLIB |
3482 /* Stop treating the Lisp_Object at non-heap VARADDRESS as a root object | |
3483 for garbage collection, but not for dumping. */ | |
3484 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3485 unstaticpro_nodump_1 (Lisp_Object *varaddress, const Ascbyte *varname) |
996 | 3486 { |
3487 Dynarr_delete_object (staticpros, varaddress); | |
3488 Dynarr_delete_object (staticpro_names, varname); | |
3489 } | |
3490 #endif | |
3491 | |
771 | 3492 #else /* not DEBUG_XEMACS */ |
3493 | |
452 | 3494 Lisp_Object_ptr_dynarr *staticpros; |
3495 | |
3496 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3497 garbage collection, and for dumping. */ | |
428 | 3498 void |
3499 staticpro (Lisp_Object *varaddress) | |
3500 { | |
452 | 3501 Dynarr_add (staticpros, varaddress); |
1204 | 3502 dump_add_root_lisp_object (varaddress); |
428 | 3503 } |
3504 | |
442 | 3505 |
452 | 3506 Lisp_Object_ptr_dynarr *staticpros_nodump; |
3507 | |
771 | 3508 /* Mark the Lisp_Object at heap VARADDRESS as a root object for garbage |
3509 collection, but not for dumping. This is used for objects where the | |
3510 only sure pointer is in the heap (rather than in the global data | |
3511 segment, as must be the case for pdump root pointers), but not inside of | |
3512 another Lisp object (where it will be marked as a result of that Lisp | |
3513 object's mark method). The call to staticpro_nodump() must occur *BOTH* | |
3514 at initialization time and at "reinitialization" time (startup, after | |
3515 pdump load.) (For example, this is the case with the predicate symbols | |
3516 for specifier and coding system types. The pointer to this symbol is | |
3517 inside of a methods structure, which is allocated on the heap. The | |
3518 methods structure will be written out to the pdump data file, and may be | |
3519 reloaded at a different address.) | |
3520 | |
3521 #### The necessity for reinitialization is a bug in pdump. Pdump should | |
3522 automatically regenerate the staticpro()s for these symbols when it | |
3523 loads the data in. */ | |
3524 | |
428 | 3525 void |
3526 staticpro_nodump (Lisp_Object *varaddress) | |
3527 { | |
452 | 3528 Dynarr_add (staticpros_nodump, varaddress); |
428 | 3529 } |
3530 | |
996 | 3531 #ifdef HAVE_SHLIB |
3532 /* Unmark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3533 garbage collection, but not for dumping. */ | |
3534 void | |
3535 unstaticpro_nodump (Lisp_Object *varaddress) | |
3536 { | |
3537 Dynarr_delete_object (staticpros, varaddress); | |
3538 } | |
3539 #endif | |
3540 | |
771 | 3541 #endif /* not DEBUG_XEMACS */ |
3542 | |
2720 | 3543 |
3544 | |
3545 | |
3546 | |
3263 | 3547 #ifdef NEW_GC |
2720 | 3548 static const struct memory_description mcpro_description_1[] = { |
3549 { XD_END } | |
3550 }; | |
3551 | |
3552 static const struct sized_memory_description mcpro_description = { | |
3553 sizeof (Lisp_Object *), | |
3554 mcpro_description_1 | |
3555 }; | |
3556 | |
3557 static const struct memory_description mcpros_description_1[] = { | |
3558 XD_DYNARR_DESC (Lisp_Object_dynarr, &mcpro_description), | |
3559 { XD_END } | |
3560 }; | |
3561 | |
3562 static const struct sized_memory_description mcpros_description = { | |
3563 sizeof (Lisp_Object_dynarr), | |
3564 mcpros_description_1 | |
3565 }; | |
3566 | |
3567 #ifdef DEBUG_XEMACS | |
3568 | |
3569 /* Help debug crashes gc-marking a mcpro'ed object. */ | |
3570 | |
3571 Lisp_Object_dynarr *mcpros; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3572 const_Ascbyte_ptr_dynarr *mcpro_names; |
2720 | 3573 |
3574 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3575 garbage collection, and for dumping. */ | |
3576 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3577 mcpro_1 (Lisp_Object varaddress, const Ascbyte *varname) |
2720 | 3578 { |
3579 Dynarr_add (mcpros, varaddress); | |
3580 Dynarr_add (mcpro_names, varname); | |
3581 } | |
3582 | |
5046 | 3583 const Ascbyte *mcpro_name (int count); |
3584 | |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3585 /* External debugging function: Return the name of the variable at offset |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3586 COUNT. */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3587 const Ascbyte * |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3588 mcpro_name (int count) |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3589 { |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3590 return Dynarr_at (mcpro_names, count); |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3591 } |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3592 |
2720 | 3593 #else /* not DEBUG_XEMACS */ |
3594 | |
3595 Lisp_Object_dynarr *mcpros; | |
3596 | |
3597 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3598 garbage collection, and for dumping. */ | |
3599 void | |
3600 mcpro (Lisp_Object varaddress) | |
3601 { | |
3602 Dynarr_add (mcpros, varaddress); | |
3603 } | |
3604 | |
3605 #endif /* not DEBUG_XEMACS */ | |
3263 | 3606 #endif /* NEW_GC */ |
3607 | |
3608 | |
3609 #ifndef NEW_GC | |
428 | 3610 static int gc_count_num_short_string_in_use; |
647 | 3611 static Bytecount gc_count_string_total_size; |
3612 static Bytecount gc_count_short_string_total_size; | |
428 | 3613 |
3614 /* static int gc_count_total_records_used, gc_count_records_total_size; */ | |
3615 | |
3616 | |
3617 /* stats on lcrecords in use - kinda kludgy */ | |
3618 | |
3619 static struct | |
3620 { | |
3621 int instances_in_use; | |
3622 int bytes_in_use; | |
3623 int instances_freed; | |
3624 int bytes_freed; | |
3625 int instances_on_free_list; | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3626 int bytes_on_free_list; |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3627 #ifdef MEMORY_USAGE_STATS |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3628 Bytecount nonlisp_bytes_in_use; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3629 struct generic_usage_stats stats; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3630 #endif |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3631 } lrecord_stats [countof (lrecord_implementations_table)]; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3632 |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3633 void |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3634 tick_lrecord_stats (const struct lrecord_header *h, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3635 enum lrecord_alloc_status status) |
428 | 3636 { |
647 | 3637 int type_index = h->type; |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3638 Bytecount sz = detagged_lisp_object_size (h); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3639 |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3640 switch (status) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3641 { |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3642 case ALLOC_IN_USE: |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3643 lrecord_stats[type_index].instances_in_use++; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3644 lrecord_stats[type_index].bytes_in_use += sz; |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3645 #ifdef MEMORY_USAGE_STATS |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3646 { |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3647 struct generic_usage_stats stats; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3648 Lisp_Object obj = wrap_pointer_1 (h); |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3649 if (HAS_OBJECT_METH_P (obj, memory_usage)) |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3650 { |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3651 int i; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3652 int total_stats = OBJECT_PROPERTY (obj, num_extra_memusage_stats); |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3653 xzero (stats); |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3654 OBJECT_METH (obj, memory_usage, (obj, &stats)); |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3655 for (i = 0; i < total_stats; i++) |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3656 lrecord_stats[type_index].stats.othervals[i] += |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3657 stats.othervals[i]; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3658 } |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3659 } |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3660 #endif |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3661 break; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3662 case ALLOC_FREE: |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3663 lrecord_stats[type_index].instances_freed++; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3664 lrecord_stats[type_index].bytes_freed += sz; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3665 break; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3666 case ALLOC_ON_FREE_LIST: |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3667 lrecord_stats[type_index].instances_on_free_list++; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3668 lrecord_stats[type_index].bytes_on_free_list += sz; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3669 break; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3670 default: |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3671 ABORT (); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3672 } |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3673 } |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3674 |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3675 inline static void |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3676 tick_lcrecord_stats (const struct lrecord_header *h, int free_p) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3677 { |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
3678 if (h->free) |
428 | 3679 { |
442 | 3680 gc_checking_assert (!free_p); |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3681 tick_lrecord_stats (h, ALLOC_ON_FREE_LIST); |
428 | 3682 } |
3683 else | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3684 tick_lrecord_stats (h, free_p ? ALLOC_FREE : ALLOC_IN_USE); |
428 | 3685 } |
3263 | 3686 #endif /* not NEW_GC */ |
428 | 3687 |
3688 | |
3263 | 3689 #ifndef NEW_GC |
428 | 3690 /* Free all unmarked records */ |
3691 static void | |
3024 | 3692 sweep_lcrecords_1 (struct old_lcrecord_header **prev, int *used) |
3693 { | |
3694 struct old_lcrecord_header *header; | |
428 | 3695 int num_used = 0; |
3696 /* int total_size = 0; */ | |
3697 | |
3698 /* First go through and call all the finalize methods. | |
3699 Then go through and free the objects. There used to | |
3700 be only one loop here, with the call to the finalizer | |
3701 occurring directly before the xfree() below. That | |
3702 is marginally faster but much less safe -- if the | |
3703 finalize method for an object needs to reference any | |
3704 other objects contained within it (and many do), | |
3705 we could easily be screwed by having already freed that | |
3706 other object. */ | |
3707 | |
3708 for (header = *prev; header; header = header->next) | |
3709 { | |
3710 struct lrecord_header *h = &(header->lheader); | |
442 | 3711 |
3712 GC_CHECK_LHEADER_INVARIANTS (h); | |
3713 | |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
3714 if (! MARKED_RECORD_HEADER_P (h) && !h->free) |
428 | 3715 { |
3716 if (LHEADER_IMPLEMENTATION (h)->finalizer) | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3717 LHEADER_IMPLEMENTATION (h)->finalizer (wrap_pointer_1 (h)); |
428 | 3718 } |
3719 } | |
3720 | |
3721 for (header = *prev; header; ) | |
3722 { | |
3723 struct lrecord_header *h = &(header->lheader); | |
442 | 3724 if (MARKED_RECORD_HEADER_P (h)) |
428 | 3725 { |
442 | 3726 if (! C_READONLY_RECORD_HEADER_P (h)) |
428 | 3727 UNMARK_RECORD_HEADER (h); |
3728 num_used++; | |
3729 /* total_size += n->implementation->size_in_bytes (h);*/ | |
440 | 3730 /* #### May modify header->next on a C_READONLY lcrecord */ |
428 | 3731 prev = &(header->next); |
3732 header = *prev; | |
3733 tick_lcrecord_stats (h, 0); | |
3734 } | |
3735 else | |
3736 { | |
3024 | 3737 struct old_lcrecord_header *next = header->next; |
428 | 3738 *prev = next; |
3739 tick_lcrecord_stats (h, 1); | |
3740 /* used to call finalizer right here. */ | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
3741 xfree (header); |
428 | 3742 header = next; |
3743 } | |
3744 } | |
3745 *used = num_used; | |
3746 /* *total = total_size; */ | |
3747 } | |
3748 | |
3749 /* And the Lord said: Thou shalt use the `c-backslash-region' command | |
3750 to make macros prettier. */ | |
3751 | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3752 #define COUNT_FROB_BLOCK_USAGE(type) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3753 EMACS_INT s = 0; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3754 struct type##_block *x = current_##type##_block; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3755 while (x) { s += sizeof (*x) + MALLOC_OVERHEAD; x = x->prev; } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3756 DO_NOTHING |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3757 |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3758 #define COPY_INTO_LRECORD_STATS(type) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3759 do { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3760 COUNT_FROB_BLOCK_USAGE (type); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3761 lrecord_stats[lrecord_type_##type].bytes_in_use += s; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3762 lrecord_stats[lrecord_type_##type].instances_on_free_list += \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3763 gc_count_num_##type##_freelist; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3764 lrecord_stats[lrecord_type_##type].instances_in_use += \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3765 gc_count_num_##type##_in_use; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3766 } while (0) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3767 |
428 | 3768 #ifdef ERROR_CHECK_GC |
3769 | |
771 | 3770 #define SWEEP_FIXED_TYPE_BLOCK_1(typename, obj_type, lheader) \ |
428 | 3771 do { \ |
3772 struct typename##_block *SFTB_current; \ | |
3773 int SFTB_limit; \ | |
3774 int num_free = 0, num_used = 0; \ | |
3775 \ | |
444 | 3776 for (SFTB_current = current_##typename##_block, \ |
428 | 3777 SFTB_limit = current_##typename##_block_index; \ |
3778 SFTB_current; \ | |
3779 ) \ | |
3780 { \ | |
3781 int SFTB_iii; \ | |
3782 \ | |
3783 for (SFTB_iii = 0; SFTB_iii < SFTB_limit; SFTB_iii++) \ | |
3784 { \ | |
3785 obj_type *SFTB_victim = &(SFTB_current->block[SFTB_iii]); \ | |
3786 \ | |
454 | 3787 if (LRECORD_FREE_P (SFTB_victim)) \ |
428 | 3788 { \ |
3789 num_free++; \ | |
3790 } \ | |
3791 else if (C_READONLY_RECORD_HEADER_P (&SFTB_victim->lheader)) \ | |
3792 { \ | |
3793 num_used++; \ | |
3794 } \ | |
442 | 3795 else if (! MARKED_RECORD_HEADER_P (&SFTB_victim->lheader)) \ |
428 | 3796 { \ |
3797 num_free++; \ | |
3798 FREE_FIXED_TYPE (typename, obj_type, SFTB_victim); \ | |
3799 } \ | |
3800 else \ | |
3801 { \ | |
3802 num_used++; \ | |
3803 UNMARK_##typename (SFTB_victim); \ | |
3804 } \ | |
3805 } \ | |
3806 SFTB_current = SFTB_current->prev; \ | |
3807 SFTB_limit = countof (current_##typename##_block->block); \ | |
3808 } \ | |
3809 \ | |
3810 gc_count_num_##typename##_in_use = num_used; \ | |
3811 gc_count_num_##typename##_freelist = num_free; \ | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3812 COPY_INTO_LRECORD_STATS (typename); \ |
428 | 3813 } while (0) |
3814 | |
3815 #else /* !ERROR_CHECK_GC */ | |
3816 | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3817 #define SWEEP_FIXED_TYPE_BLOCK_1(typename, obj_type, lheader) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3818 do { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3819 struct typename##_block *SFTB_current; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3820 struct typename##_block **SFTB_prev; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3821 int SFTB_limit; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3822 int num_free = 0, num_used = 0; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3823 \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3824 typename##_free_list = 0; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3825 \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3826 for (SFTB_prev = ¤t_##typename##_block, \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3827 SFTB_current = current_##typename##_block, \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3828 SFTB_limit = current_##typename##_block_index; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3829 SFTB_current; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3830 ) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3831 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3832 int SFTB_iii; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3833 int SFTB_empty = 1; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3834 Lisp_Free *SFTB_old_free_list = typename##_free_list; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3835 \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3836 for (SFTB_iii = 0; SFTB_iii < SFTB_limit; SFTB_iii++) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3837 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3838 obj_type *SFTB_victim = &(SFTB_current->block[SFTB_iii]); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3839 \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3840 if (LRECORD_FREE_P (SFTB_victim)) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3841 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3842 num_free++; \ |
771 | 3843 PUT_FIXED_TYPE_ON_FREE_LIST (typename, obj_type, SFTB_victim); \ |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3844 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3845 else if (C_READONLY_RECORD_HEADER_P (&SFTB_victim->lheader)) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3846 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3847 SFTB_empty = 0; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3848 num_used++; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3849 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3850 else if (! MARKED_RECORD_HEADER_P (&SFTB_victim->lheader)) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3851 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3852 num_free++; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3853 FREE_FIXED_TYPE (typename, obj_type, SFTB_victim); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3854 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3855 else \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3856 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3857 SFTB_empty = 0; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3858 num_used++; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3859 UNMARK_##typename (SFTB_victim); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3860 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3861 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3862 if (!SFTB_empty) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3863 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3864 SFTB_prev = &(SFTB_current->prev); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3865 SFTB_current = SFTB_current->prev; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3866 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3867 else if (SFTB_current == current_##typename##_block \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3868 && !SFTB_current->prev) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3869 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3870 /* No real point in freeing sole allocation block */ \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3871 break; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3872 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3873 else \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3874 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3875 struct typename##_block *SFTB_victim_block = SFTB_current; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3876 if (SFTB_victim_block == current_##typename##_block) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3877 current_##typename##_block_index \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3878 = countof (current_##typename##_block->block); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3879 SFTB_current = SFTB_current->prev; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3880 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3881 *SFTB_prev = SFTB_current; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3882 xfree (SFTB_victim_block); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3883 /* Restore free list to what it was before victim was swept */ \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3884 typename##_free_list = SFTB_old_free_list; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3885 num_free -= SFTB_limit; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3886 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3887 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3888 SFTB_limit = countof (current_##typename##_block->block); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3889 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3890 \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3891 gc_count_num_##typename##_in_use = num_used; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3892 gc_count_num_##typename##_freelist = num_free; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3893 COPY_INTO_LRECORD_STATS (typename); \ |
428 | 3894 } while (0) |
3895 | |
3896 #endif /* !ERROR_CHECK_GC */ | |
3897 | |
771 | 3898 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \ |
3899 SWEEP_FIXED_TYPE_BLOCK_1 (typename, obj_type, lheader) | |
3900 | |
3263 | 3901 #endif /* not NEW_GC */ |
2720 | 3902 |
428 | 3903 |
3263 | 3904 #ifndef NEW_GC |
428 | 3905 static void |
3906 sweep_conses (void) | |
3907 { | |
3908 #define UNMARK_cons(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3909 #define ADDITIONAL_FREE_cons(ptr) | |
3910 | |
440 | 3911 SWEEP_FIXED_TYPE_BLOCK (cons, Lisp_Cons); |
428 | 3912 } |
3263 | 3913 #endif /* not NEW_GC */ |
428 | 3914 |
3915 /* Explicitly free a cons cell. */ | |
3916 void | |
853 | 3917 free_cons (Lisp_Object cons) |
428 | 3918 { |
3263 | 3919 #ifndef NEW_GC /* to avoid compiler warning */ |
853 | 3920 Lisp_Cons *ptr = XCONS (cons); |
3263 | 3921 #endif /* not NEW_GC */ |
853 | 3922 |
428 | 3923 #ifdef ERROR_CHECK_GC |
3263 | 3924 #ifdef NEW_GC |
2720 | 3925 Lisp_Cons *ptr = XCONS (cons); |
3263 | 3926 #endif /* NEW_GC */ |
428 | 3927 /* If the CAR is not an int, then it will be a pointer, which will |
3928 always be four-byte aligned. If this cons cell has already been | |
3929 placed on the free list, however, its car will probably contain | |
3930 a chain pointer to the next cons on the list, which has cleverly | |
3931 had all its 0's and 1's inverted. This allows for a quick | |
1204 | 3932 check to make sure we're not freeing something already freed. |
3933 | |
3934 NOTE: This check may not be necessary. Freeing an object sets its | |
3935 type to lrecord_type_free, which will trip up the XCONS() above -- as | |
3936 well as a check in FREE_FIXED_TYPE(). */ | |
853 | 3937 if (POINTER_TYPE_P (XTYPE (cons_car (ptr)))) |
3938 ASSERT_VALID_POINTER (XPNTR (cons_car (ptr))); | |
428 | 3939 #endif /* ERROR_CHECK_GC */ |
3940 | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3941 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (cons, cons, Lisp_Cons, ptr); |
428 | 3942 } |
3943 | |
3944 /* explicitly free a list. You **must make sure** that you have | |
3945 created all the cons cells that make up this list and that there | |
3946 are no pointers to any of these cons cells anywhere else. If there | |
3947 are, you will lose. */ | |
3948 | |
3949 void | |
3950 free_list (Lisp_Object list) | |
3951 { | |
3952 Lisp_Object rest, next; | |
3953 | |
3954 for (rest = list; !NILP (rest); rest = next) | |
3955 { | |
3956 next = XCDR (rest); | |
853 | 3957 free_cons (rest); |
428 | 3958 } |
3959 } | |
3960 | |
3961 /* explicitly free an alist. You **must make sure** that you have | |
3962 created all the cons cells that make up this alist and that there | |
3963 are no pointers to any of these cons cells anywhere else. If there | |
3964 are, you will lose. */ | |
3965 | |
3966 void | |
3967 free_alist (Lisp_Object alist) | |
3968 { | |
3969 Lisp_Object rest, next; | |
3970 | |
3971 for (rest = alist; !NILP (rest); rest = next) | |
3972 { | |
3973 next = XCDR (rest); | |
853 | 3974 free_cons (XCAR (rest)); |
3975 free_cons (rest); | |
428 | 3976 } |
3977 } | |
3978 | |
3263 | 3979 #ifndef NEW_GC |
428 | 3980 static void |
3981 sweep_compiled_functions (void) | |
3982 { | |
3983 #define UNMARK_compiled_function(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
945 | 3984 #define ADDITIONAL_FREE_compiled_function(ptr) \ |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
3985 if (ptr->args_in_array) xfree (ptr->args) |
428 | 3986 |
3987 SWEEP_FIXED_TYPE_BLOCK (compiled_function, Lisp_Compiled_Function); | |
3988 } | |
3989 | |
3990 static void | |
3991 sweep_floats (void) | |
3992 { | |
3993 #define UNMARK_float(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3994 #define ADDITIONAL_FREE_float(ptr) | |
3995 | |
440 | 3996 SWEEP_FIXED_TYPE_BLOCK (float, Lisp_Float); |
428 | 3997 } |
3998 | |
1983 | 3999 #ifdef HAVE_BIGNUM |
4000 static void | |
4001 sweep_bignums (void) | |
4002 { | |
4003 #define UNMARK_bignum(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4004 #define ADDITIONAL_FREE_bignum(ptr) bignum_fini (ptr->data) | |
4005 | |
4006 SWEEP_FIXED_TYPE_BLOCK (bignum, Lisp_Bignum); | |
4007 } | |
4008 #endif /* HAVE_BIGNUM */ | |
4009 | |
4010 #ifdef HAVE_RATIO | |
4011 static void | |
4012 sweep_ratios (void) | |
4013 { | |
4014 #define UNMARK_ratio(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4015 #define ADDITIONAL_FREE_ratio(ptr) ratio_fini (ptr->data) | |
4016 | |
4017 SWEEP_FIXED_TYPE_BLOCK (ratio, Lisp_Ratio); | |
4018 } | |
4019 #endif /* HAVE_RATIO */ | |
4020 | |
4021 #ifdef HAVE_BIGFLOAT | |
4022 static void | |
4023 sweep_bigfloats (void) | |
4024 { | |
4025 #define UNMARK_bigfloat(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4026 #define ADDITIONAL_FREE_bigfloat(ptr) bigfloat_fini (ptr->bf) | |
4027 | |
4028 SWEEP_FIXED_TYPE_BLOCK (bigfloat, Lisp_Bigfloat); | |
4029 } | |
4030 #endif | |
4031 | |
428 | 4032 static void |
4033 sweep_symbols (void) | |
4034 { | |
4035 #define UNMARK_symbol(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4036 #define ADDITIONAL_FREE_symbol(ptr) | |
4037 | |
440 | 4038 SWEEP_FIXED_TYPE_BLOCK (symbol, Lisp_Symbol); |
428 | 4039 } |
4040 | |
4041 static void | |
4042 sweep_extents (void) | |
4043 { | |
4044 #define UNMARK_extent(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4045 #define ADDITIONAL_FREE_extent(ptr) | |
4046 | |
4047 SWEEP_FIXED_TYPE_BLOCK (extent, struct extent); | |
4048 } | |
4049 | |
4050 static void | |
4051 sweep_events (void) | |
4052 { | |
4053 #define UNMARK_event(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4054 #define ADDITIONAL_FREE_event(ptr) | |
4055 | |
440 | 4056 SWEEP_FIXED_TYPE_BLOCK (event, Lisp_Event); |
428 | 4057 } |
3263 | 4058 #endif /* not NEW_GC */ |
428 | 4059 |
1204 | 4060 #ifdef EVENT_DATA_AS_OBJECTS |
934 | 4061 |
3263 | 4062 #ifndef NEW_GC |
934 | 4063 static void |
4064 sweep_key_data (void) | |
4065 { | |
4066 #define UNMARK_key_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4067 #define ADDITIONAL_FREE_key_data(ptr) | |
4068 | |
4069 SWEEP_FIXED_TYPE_BLOCK (key_data, Lisp_Key_Data); | |
4070 } | |
3263 | 4071 #endif /* not NEW_GC */ |
934 | 4072 |
1204 | 4073 void |
4074 free_key_data (Lisp_Object ptr) | |
4075 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4076 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, key_data, Lisp_Key_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4077 XKEY_DATA (ptr)); |
2720 | 4078 } |
4079 | |
3263 | 4080 #ifndef NEW_GC |
934 | 4081 static void |
4082 sweep_button_data (void) | |
4083 { | |
4084 #define UNMARK_button_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4085 #define ADDITIONAL_FREE_button_data(ptr) | |
4086 | |
4087 SWEEP_FIXED_TYPE_BLOCK (button_data, Lisp_Button_Data); | |
4088 } | |
3263 | 4089 #endif /* not NEW_GC */ |
934 | 4090 |
1204 | 4091 void |
4092 free_button_data (Lisp_Object ptr) | |
4093 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4094 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, button_data, Lisp_Button_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4095 XBUTTON_DATA (ptr)); |
2720 | 4096 } |
4097 | |
3263 | 4098 #ifndef NEW_GC |
934 | 4099 static void |
4100 sweep_motion_data (void) | |
4101 { | |
4102 #define UNMARK_motion_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4103 #define ADDITIONAL_FREE_motion_data(ptr) | |
4104 | |
4105 SWEEP_FIXED_TYPE_BLOCK (motion_data, Lisp_Motion_Data); | |
4106 } | |
3263 | 4107 #endif /* not NEW_GC */ |
934 | 4108 |
1204 | 4109 void |
4110 free_motion_data (Lisp_Object ptr) | |
4111 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4112 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, motion_data, Lisp_Motion_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4113 XMOTION_DATA (ptr)); |
2720 | 4114 } |
4115 | |
3263 | 4116 #ifndef NEW_GC |
934 | 4117 static void |
4118 sweep_process_data (void) | |
4119 { | |
4120 #define UNMARK_process_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4121 #define ADDITIONAL_FREE_process_data(ptr) | |
4122 | |
4123 SWEEP_FIXED_TYPE_BLOCK (process_data, Lisp_Process_Data); | |
4124 } | |
3263 | 4125 #endif /* not NEW_GC */ |
934 | 4126 |
1204 | 4127 void |
4128 free_process_data (Lisp_Object ptr) | |
4129 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4130 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, process_data, Lisp_Process_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4131 XPROCESS_DATA (ptr)); |
2720 | 4132 } |
4133 | |
3263 | 4134 #ifndef NEW_GC |
934 | 4135 static void |
4136 sweep_timeout_data (void) | |
4137 { | |
4138 #define UNMARK_timeout_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4139 #define ADDITIONAL_FREE_timeout_data(ptr) | |
4140 | |
4141 SWEEP_FIXED_TYPE_BLOCK (timeout_data, Lisp_Timeout_Data); | |
4142 } | |
3263 | 4143 #endif /* not NEW_GC */ |
934 | 4144 |
1204 | 4145 void |
4146 free_timeout_data (Lisp_Object ptr) | |
4147 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4148 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, timeout_data, Lisp_Timeout_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4149 XTIMEOUT_DATA (ptr)); |
2720 | 4150 } |
4151 | |
3263 | 4152 #ifndef NEW_GC |
934 | 4153 static void |
4154 sweep_magic_data (void) | |
4155 { | |
4156 #define UNMARK_magic_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4157 #define ADDITIONAL_FREE_magic_data(ptr) | |
4158 | |
4159 SWEEP_FIXED_TYPE_BLOCK (magic_data, Lisp_Magic_Data); | |
4160 } | |
3263 | 4161 #endif /* not NEW_GC */ |
934 | 4162 |
1204 | 4163 void |
4164 free_magic_data (Lisp_Object ptr) | |
4165 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4166 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, magic_data, Lisp_Magic_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4167 XMAGIC_DATA (ptr)); |
2720 | 4168 } |
4169 | |
3263 | 4170 #ifndef NEW_GC |
934 | 4171 static void |
4172 sweep_magic_eval_data (void) | |
4173 { | |
4174 #define UNMARK_magic_eval_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4175 #define ADDITIONAL_FREE_magic_eval_data(ptr) | |
4176 | |
4177 SWEEP_FIXED_TYPE_BLOCK (magic_eval_data, Lisp_Magic_Eval_Data); | |
4178 } | |
3263 | 4179 #endif /* not NEW_GC */ |
934 | 4180 |
1204 | 4181 void |
4182 free_magic_eval_data (Lisp_Object ptr) | |
4183 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4184 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, magic_eval_data, Lisp_Magic_Eval_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4185 XMAGIC_EVAL_DATA (ptr)); |
2720 | 4186 } |
4187 | |
3263 | 4188 #ifndef NEW_GC |
934 | 4189 static void |
4190 sweep_eval_data (void) | |
4191 { | |
4192 #define UNMARK_eval_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4193 #define ADDITIONAL_FREE_eval_data(ptr) | |
4194 | |
4195 SWEEP_FIXED_TYPE_BLOCK (eval_data, Lisp_Eval_Data); | |
4196 } | |
3263 | 4197 #endif /* not NEW_GC */ |
934 | 4198 |
1204 | 4199 void |
4200 free_eval_data (Lisp_Object ptr) | |
4201 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4202 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, eval_data, Lisp_Eval_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4203 XEVAL_DATA (ptr)); |
2720 | 4204 } |
4205 | |
3263 | 4206 #ifndef NEW_GC |
934 | 4207 static void |
4208 sweep_misc_user_data (void) | |
4209 { | |
4210 #define UNMARK_misc_user_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4211 #define ADDITIONAL_FREE_misc_user_data(ptr) | |
4212 | |
4213 SWEEP_FIXED_TYPE_BLOCK (misc_user_data, Lisp_Misc_User_Data); | |
4214 } | |
3263 | 4215 #endif /* not NEW_GC */ |
934 | 4216 |
1204 | 4217 void |
4218 free_misc_user_data (Lisp_Object ptr) | |
4219 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4220 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, misc_user_data, Lisp_Misc_User_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4221 XMISC_USER_DATA (ptr)); |
1204 | 4222 } |
4223 | |
4224 #endif /* EVENT_DATA_AS_OBJECTS */ | |
934 | 4225 |
3263 | 4226 #ifndef NEW_GC |
428 | 4227 static void |
4228 sweep_markers (void) | |
4229 { | |
4230 #define UNMARK_marker(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4231 #define ADDITIONAL_FREE_marker(ptr) \ | |
4232 do { Lisp_Object tem; \ | |
793 | 4233 tem = wrap_marker (ptr); \ |
428 | 4234 unchain_marker (tem); \ |
4235 } while (0) | |
4236 | |
440 | 4237 SWEEP_FIXED_TYPE_BLOCK (marker, Lisp_Marker); |
428 | 4238 } |
3263 | 4239 #endif /* not NEW_GC */ |
428 | 4240 |
4241 /* Explicitly free a marker. */ | |
4242 void | |
1204 | 4243 free_marker (Lisp_Object ptr) |
428 | 4244 { |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4245 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, marker, Lisp_Marker, XMARKER (ptr)); |
428 | 4246 } |
4247 | |
4248 | |
4249 #if defined (MULE) && defined (VERIFY_STRING_CHARS_INTEGRITY) | |
4250 | |
4251 static void | |
4252 verify_string_chars_integrity (void) | |
4253 { | |
4254 struct string_chars_block *sb; | |
4255 | |
4256 /* Scan each existing string block sequentially, string by string. */ | |
4257 for (sb = first_string_chars_block; sb; sb = sb->next) | |
4258 { | |
4259 int pos = 0; | |
4260 /* POS is the index of the next string in the block. */ | |
4261 while (pos < sb->pos) | |
4262 { | |
4263 struct string_chars *s_chars = | |
4264 (struct string_chars *) &(sb->string_chars[pos]); | |
438 | 4265 Lisp_String *string; |
428 | 4266 int size; |
4267 int fullsize; | |
4268 | |
454 | 4269 /* If the string_chars struct is marked as free (i.e. the |
4270 STRING pointer is NULL) then this is an unused chunk of | |
4271 string storage. (See below.) */ | |
4272 | |
4273 if (STRING_CHARS_FREE_P (s_chars)) | |
428 | 4274 { |
4275 fullsize = ((struct unused_string_chars *) s_chars)->fullsize; | |
4276 pos += fullsize; | |
4277 continue; | |
4278 } | |
4279 | |
4280 string = s_chars->string; | |
4281 /* Must be 32-bit aligned. */ | |
4282 assert ((((int) string) & 3) == 0); | |
4283 | |
793 | 4284 size = string->size_; |
428 | 4285 fullsize = STRING_FULLSIZE (size); |
4286 | |
4287 assert (!BIG_STRING_FULLSIZE_P (fullsize)); | |
2720 | 4288 assert (XSTRING_DATA (string) == s_chars->chars); |
428 | 4289 pos += fullsize; |
4290 } | |
4291 assert (pos == sb->pos); | |
4292 } | |
4293 } | |
4294 | |
1204 | 4295 #endif /* defined (MULE) && defined (VERIFY_STRING_CHARS_INTEGRITY) */ |
428 | 4296 |
3092 | 4297 #ifndef NEW_GC |
428 | 4298 /* Compactify string chars, relocating the reference to each -- |
4299 free any empty string_chars_block we see. */ | |
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
4300 static void |
428 | 4301 compact_string_chars (void) |
4302 { | |
4303 struct string_chars_block *to_sb = first_string_chars_block; | |
4304 int to_pos = 0; | |
4305 struct string_chars_block *from_sb; | |
4306 | |
4307 /* Scan each existing string block sequentially, string by string. */ | |
4308 for (from_sb = first_string_chars_block; from_sb; from_sb = from_sb->next) | |
4309 { | |
4310 int from_pos = 0; | |
4311 /* FROM_POS is the index of the next string in the block. */ | |
4312 while (from_pos < from_sb->pos) | |
4313 { | |
4314 struct string_chars *from_s_chars = | |
4315 (struct string_chars *) &(from_sb->string_chars[from_pos]); | |
4316 struct string_chars *to_s_chars; | |
438 | 4317 Lisp_String *string; |
428 | 4318 int size; |
4319 int fullsize; | |
4320 | |
454 | 4321 /* If the string_chars struct is marked as free (i.e. the |
4322 STRING pointer is NULL) then this is an unused chunk of | |
4323 string storage. This happens under Mule when a string's | |
4324 size changes in such a way that its fullsize changes. | |
4325 (Strings can change size because a different-length | |
4326 character can be substituted for another character.) | |
4327 In this case, after the bogus string pointer is the | |
4328 "fullsize" of this entry, i.e. how many bytes to skip. */ | |
4329 | |
4330 if (STRING_CHARS_FREE_P (from_s_chars)) | |
428 | 4331 { |
4332 fullsize = ((struct unused_string_chars *) from_s_chars)->fullsize; | |
4333 from_pos += fullsize; | |
4334 continue; | |
4335 } | |
4336 | |
4337 string = from_s_chars->string; | |
1204 | 4338 gc_checking_assert (!(LRECORD_FREE_P (string))); |
428 | 4339 |
793 | 4340 size = string->size_; |
428 | 4341 fullsize = STRING_FULLSIZE (size); |
4342 | |
442 | 4343 gc_checking_assert (! BIG_STRING_FULLSIZE_P (fullsize)); |
428 | 4344 |
4345 /* Just skip it if it isn't marked. */ | |
771 | 4346 if (! MARKED_RECORD_HEADER_P (&(string->u.lheader))) |
428 | 4347 { |
4348 from_pos += fullsize; | |
4349 continue; | |
4350 } | |
4351 | |
4352 /* If it won't fit in what's left of TO_SB, close TO_SB out | |
4353 and go on to the next string_chars_block. We know that TO_SB | |
4354 cannot advance past FROM_SB here since FROM_SB is large enough | |
4355 to currently contain this string. */ | |
4356 if ((to_pos + fullsize) > countof (to_sb->string_chars)) | |
4357 { | |
4358 to_sb->pos = to_pos; | |
4359 to_sb = to_sb->next; | |
4360 to_pos = 0; | |
4361 } | |
4362 | |
4363 /* Compute new address of this string | |
4364 and update TO_POS for the space being used. */ | |
4365 to_s_chars = (struct string_chars *) &(to_sb->string_chars[to_pos]); | |
4366 | |
4367 /* Copy the string_chars to the new place. */ | |
4368 if (from_s_chars != to_s_chars) | |
4369 memmove (to_s_chars, from_s_chars, fullsize); | |
4370 | |
4371 /* Relocate FROM_S_CHARS's reference */ | |
826 | 4372 set_lispstringp_data (string, &(to_s_chars->chars[0])); |
428 | 4373 |
4374 from_pos += fullsize; | |
4375 to_pos += fullsize; | |
4376 } | |
4377 } | |
4378 | |
4379 /* Set current to the last string chars block still used and | |
4380 free any that follow. */ | |
4381 { | |
4382 struct string_chars_block *victim; | |
4383 | |
4384 for (victim = to_sb->next; victim; ) | |
4385 { | |
4386 struct string_chars_block *next = victim->next; | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
4387 xfree (victim); |
428 | 4388 victim = next; |
4389 } | |
4390 | |
4391 current_string_chars_block = to_sb; | |
4392 current_string_chars_block->pos = to_pos; | |
4393 current_string_chars_block->next = 0; | |
4394 } | |
4395 } | |
3092 | 4396 #endif /* not NEW_GC */ |
428 | 4397 |
3263 | 4398 #ifndef NEW_GC |
428 | 4399 #if 1 /* Hack to debug missing purecopy's */ |
4400 static int debug_string_purity; | |
4401 | |
4402 static void | |
793 | 4403 debug_string_purity_print (Lisp_Object p) |
428 | 4404 { |
4405 Charcount i; | |
826 | 4406 Charcount s = string_char_length (p); |
442 | 4407 stderr_out ("\""); |
428 | 4408 for (i = 0; i < s; i++) |
4409 { | |
867 | 4410 Ichar ch = string_ichar (p, i); |
428 | 4411 if (ch < 32 || ch >= 126) |
4412 stderr_out ("\\%03o", ch); | |
4413 else if (ch == '\\' || ch == '\"') | |
4414 stderr_out ("\\%c", ch); | |
4415 else | |
4416 stderr_out ("%c", ch); | |
4417 } | |
4418 stderr_out ("\"\n"); | |
4419 } | |
4420 #endif /* 1 */ | |
3263 | 4421 #endif /* not NEW_GC */ |
4422 | |
4423 #ifndef NEW_GC | |
428 | 4424 static void |
4425 sweep_strings (void) | |
4426 { | |
647 | 4427 int num_small_used = 0; |
4428 Bytecount num_small_bytes = 0, num_bytes = 0; | |
428 | 4429 int debug = debug_string_purity; |
4430 | |
793 | 4431 #define UNMARK_string(ptr) do { \ |
4432 Lisp_String *p = (ptr); \ | |
4433 Bytecount size = p->size_; \ | |
4434 UNMARK_RECORD_HEADER (&(p->u.lheader)); \ | |
4435 num_bytes += size; \ | |
4436 if (!BIG_STRING_SIZE_P (size)) \ | |
4437 { \ | |
4438 num_small_bytes += size; \ | |
4439 num_small_used++; \ | |
4440 } \ | |
4441 if (debug) \ | |
4442 debug_string_purity_print (wrap_string (p)); \ | |
438 | 4443 } while (0) |
4444 #define ADDITIONAL_FREE_string(ptr) do { \ | |
793 | 4445 Bytecount size = ptr->size_; \ |
438 | 4446 if (BIG_STRING_SIZE_P (size)) \ |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
4447 xfree (ptr->data_); \ |
438 | 4448 } while (0) |
4449 | |
771 | 4450 SWEEP_FIXED_TYPE_BLOCK_1 (string, Lisp_String, u.lheader); |
428 | 4451 |
4452 gc_count_num_short_string_in_use = num_small_used; | |
4453 gc_count_string_total_size = num_bytes; | |
4454 gc_count_short_string_total_size = num_small_bytes; | |
4455 } | |
3263 | 4456 #endif /* not NEW_GC */ |
428 | 4457 |
3092 | 4458 #ifndef NEW_GC |
4459 void | |
4460 gc_sweep_1 (void) | |
428 | 4461 { |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4462 /* Reset all statistics to 0. They will be incremented when |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4463 sweeping lcrecords, frob-block lrecords and dumped objects. */ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4464 xzero (lrecord_stats); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4465 |
428 | 4466 /* Free all unmarked records. Do this at the very beginning, |
4467 before anything else, so that the finalize methods can safely | |
4468 examine items in the objects. sweep_lcrecords_1() makes | |
4469 sure to call all the finalize methods *before* freeing anything, | |
4470 to complete the safety. */ | |
4471 { | |
4472 int ignored; | |
4473 sweep_lcrecords_1 (&all_lcrecords, &ignored); | |
4474 } | |
4475 | |
4476 compact_string_chars (); | |
4477 | |
4478 /* Finalize methods below (called through the ADDITIONAL_FREE_foo | |
4479 macros) must be *extremely* careful to make sure they're not | |
4480 referencing freed objects. The only two existing finalize | |
4481 methods (for strings and markers) pass muster -- the string | |
4482 finalizer doesn't look at anything but its own specially- | |
4483 created block, and the marker finalizer only looks at live | |
4484 buffers (which will never be freed) and at the markers before | |
4485 and after it in the chain (which, by induction, will never be | |
4486 freed because if so, they would have already removed themselves | |
4487 from the chain). */ | |
4488 | |
4489 /* Put all unmarked strings on free list, free'ing the string chars | |
4490 of large unmarked strings */ | |
4491 sweep_strings (); | |
4492 | |
4493 /* Put all unmarked conses on free list */ | |
4494 sweep_conses (); | |
4495 | |
4496 /* Free all unmarked compiled-function objects */ | |
4497 sweep_compiled_functions (); | |
4498 | |
4499 /* Put all unmarked floats on free list */ | |
4500 sweep_floats (); | |
4501 | |
1983 | 4502 #ifdef HAVE_BIGNUM |
4503 /* Put all unmarked bignums on free list */ | |
4504 sweep_bignums (); | |
4505 #endif | |
4506 | |
4507 #ifdef HAVE_RATIO | |
4508 /* Put all unmarked ratios on free list */ | |
4509 sweep_ratios (); | |
4510 #endif | |
4511 | |
4512 #ifdef HAVE_BIGFLOAT | |
4513 /* Put all unmarked bigfloats on free list */ | |
4514 sweep_bigfloats (); | |
4515 #endif | |
4516 | |
428 | 4517 /* Put all unmarked symbols on free list */ |
4518 sweep_symbols (); | |
4519 | |
4520 /* Put all unmarked extents on free list */ | |
4521 sweep_extents (); | |
4522 | |
4523 /* Put all unmarked markers on free list. | |
4524 Dechain each one first from the buffer into which it points. */ | |
4525 sweep_markers (); | |
4526 | |
4527 sweep_events (); | |
4528 | |
1204 | 4529 #ifdef EVENT_DATA_AS_OBJECTS |
934 | 4530 sweep_key_data (); |
4531 sweep_button_data (); | |
4532 sweep_motion_data (); | |
4533 sweep_process_data (); | |
4534 sweep_timeout_data (); | |
4535 sweep_magic_data (); | |
4536 sweep_magic_eval_data (); | |
4537 sweep_eval_data (); | |
4538 sweep_misc_user_data (); | |
1204 | 4539 #endif /* EVENT_DATA_AS_OBJECTS */ |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4540 |
428 | 4541 #ifdef PDUMP |
442 | 4542 pdump_objects_unmark (); |
428 | 4543 #endif |
4544 } | |
3092 | 4545 #endif /* not NEW_GC */ |
428 | 4546 |
4547 /* Clearing for disksave. */ | |
4548 | |
4549 void | |
4550 disksave_object_finalization (void) | |
4551 { | |
4552 /* It's important that certain information from the environment not get | |
4553 dumped with the executable (pathnames, environment variables, etc.). | |
4554 To make it easier to tell when this has happened with strings(1) we | |
4555 clear some known-to-be-garbage blocks of memory, so that leftover | |
4556 results of old evaluation don't look like potential problems. | |
4557 But first we set some notable variables to nil and do one more GC, | |
4558 to turn those strings into garbage. | |
440 | 4559 */ |
428 | 4560 |
4561 /* Yeah, this list is pretty ad-hoc... */ | |
4562 Vprocess_environment = Qnil; | |
771 | 4563 env_initted = 0; |
428 | 4564 Vexec_directory = Qnil; |
4565 Vdata_directory = Qnil; | |
4566 Vsite_directory = Qnil; | |
4567 Vdoc_directory = Qnil; | |
4568 Vexec_path = Qnil; | |
4569 Vload_path = Qnil; | |
4570 /* Vdump_load_path = Qnil; */ | |
4571 /* Release hash tables for locate_file */ | |
4572 Flocate_file_clear_hashing (Qt); | |
771 | 4573 uncache_home_directory (); |
776 | 4574 zero_out_command_line_status_vars (); |
872 | 4575 clear_default_devices (); |
428 | 4576 |
4577 #if defined(LOADHIST) && !(defined(LOADHIST_DUMPED) || \ | |
4578 defined(LOADHIST_BUILTIN)) | |
4579 Vload_history = Qnil; | |
4580 #endif | |
4581 Vshell_file_name = Qnil; | |
4582 | |
3092 | 4583 #ifdef NEW_GC |
4584 gc_full (); | |
4585 #else /* not NEW_GC */ | |
428 | 4586 garbage_collect_1 (); |
3092 | 4587 #endif /* not NEW_GC */ |
428 | 4588 |
4589 /* Run the disksave finalization methods of all live objects. */ | |
4590 disksave_object_finalization_1 (); | |
4591 | |
3092 | 4592 #ifndef NEW_GC |
428 | 4593 /* Zero out the uninitialized (really, unused) part of the containers |
4594 for the live strings. */ | |
4595 { | |
4596 struct string_chars_block *scb; | |
4597 for (scb = first_string_chars_block; scb; scb = scb->next) | |
4598 { | |
4599 int count = sizeof (scb->string_chars) - scb->pos; | |
4600 | |
4601 assert (count >= 0 && count < STRING_CHARS_BLOCK_SIZE); | |
440 | 4602 if (count != 0) |
4603 { | |
4604 /* from the block's fill ptr to the end */ | |
4605 memset ((scb->string_chars + scb->pos), 0, count); | |
4606 } | |
428 | 4607 } |
4608 } | |
3092 | 4609 #endif /* not NEW_GC */ |
428 | 4610 |
4611 /* There, that ought to be enough... */ | |
4612 | |
4613 } | |
4614 | |
2994 | 4615 #ifdef ALLOC_TYPE_STATS |
4616 | |
2720 | 4617 static Lisp_Object |
2994 | 4618 gc_plist_hack (const Ascbyte *name, EMACS_INT value, Lisp_Object tail) |
2720 | 4619 { |
4620 /* C doesn't have local functions (or closures, or GC, or readable syntax, | |
4621 or portable numeric datatypes, or bit-vectors, or characters, or | |
4622 arrays, or exceptions, or ...) */ | |
4623 return cons3 (intern (name), make_int (value), tail); | |
4624 } | |
2775 | 4625 |
5058
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4626 /* Pluralize a lowercase English word stored in BUF, assuming BUF has |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4627 enough space to hold the extra letters (at most 2). */ |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4628 static void |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4629 pluralize_word (Ascbyte *buf) |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4630 { |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4631 Bytecount len = strlen (buf); |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4632 int upper = 0; |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4633 Ascbyte d, e; |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4634 |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4635 if (len == 0 || len == 1) |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4636 goto pluralize_apostrophe_s; |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4637 e = buf[len - 1]; |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4638 d = buf[len - 2]; |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4639 upper = isupper (e); |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4640 e = tolower (e); |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4641 d = tolower (d); |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4642 if (e == 'y') |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4643 { |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4644 switch (d) |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4645 { |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4646 case 'a': |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4647 case 'e': |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4648 case 'i': |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4649 case 'o': |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4650 case 'u': |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4651 goto pluralize_s; |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4652 default: |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4653 buf[len - 1] = (upper ? 'I' : 'i'); |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4654 goto pluralize_es; |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4655 } |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4656 } |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4657 else if (e == 's' || e == 'x' || (e == 'h' && (d == 's' || d == 'c'))) |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4658 { |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4659 pluralize_es: |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4660 buf[len++] = (upper ? 'E' : 'e'); |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4661 } |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4662 pluralize_s: |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4663 buf[len++] = (upper ? 'S' : 's'); |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4664 buf[len] = '\0'; |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4665 return; |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4666 |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4667 pluralize_apostrophe_s: |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4668 buf[len++] = '\''; |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4669 goto pluralize_s; |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4670 } |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4671 |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4672 static void |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4673 pluralize_and_append (Ascbyte *buf, const Ascbyte *name, const Ascbyte *suffix) |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4674 { |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4675 strcpy (buf, name); |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4676 pluralize_word (buf); |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4677 strcat (buf, suffix); |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4678 } |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4679 |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4680 void |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4681 finish_object_memory_usage_stats (void) |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4682 { |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4683 #ifdef MEMORY_USAGE_STATS |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4684 int i; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4685 for (i = 0; i < countof (lrecord_implementations_table); i++) |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4686 { |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4687 struct lrecord_implementation *imp = lrecord_implementations_table[i]; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4688 if (imp && imp->num_extra_nonlisp_memusage_stats) |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4689 { |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4690 int j; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4691 for (j = 0; j < imp->num_extra_nonlisp_memusage_stats; j++) |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4692 lrecord_stats[i].nonlisp_bytes_in_use += |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4693 lrecord_stats[i].stats.othervals[j]; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4694 } |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4695 } |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4696 #endif /* MEMORY_USAGE_STATS */ |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4697 } |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4698 |
2994 | 4699 static Lisp_Object |
4700 object_memory_usage_stats (int set_total_gc_usage) | |
2720 | 4701 { |
4702 Lisp_Object pl = Qnil; | |
4703 int i; | |
2994 | 4704 EMACS_INT tgu_val = 0; |
4705 | |
3263 | 4706 #ifdef NEW_GC |
3461 | 4707 for (i = 0; i < countof (lrecord_implementations_table); i++) |
2720 | 4708 { |
4709 if (lrecord_stats[i].instances_in_use != 0) | |
4710 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
4711 Ascbyte buf[255]; |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
4712 const Ascbyte *name = lrecord_implementations_table[i]->name; |
2720 | 4713 |
4714 if (lrecord_stats[i].bytes_in_use_including_overhead != | |
4715 lrecord_stats[i].bytes_in_use) | |
4716 { | |
4717 sprintf (buf, "%s-storage-including-overhead", name); | |
4718 pl = gc_plist_hack (buf, | |
4719 lrecord_stats[i] | |
4720 .bytes_in_use_including_overhead, | |
4721 pl); | |
4722 } | |
4723 | |
4724 sprintf (buf, "%s-storage", name); | |
4725 pl = gc_plist_hack (buf, | |
4726 lrecord_stats[i].bytes_in_use, | |
4727 pl); | |
2994 | 4728 tgu_val += lrecord_stats[i].bytes_in_use_including_overhead; |
5058
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4729 |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4730 pluralize_and_append (buf, name, "-used"); |
2720 | 4731 pl = gc_plist_hack (buf, lrecord_stats[i].instances_in_use, pl); |
4732 } | |
4733 } | |
2994 | 4734 |
3263 | 4735 #else /* not NEW_GC */ |
428 | 4736 |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4737 #define HACK_O_MATIC(type, name, pl) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4738 do { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4739 COUNT_FROB_BLOCK_USAGE (type); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4740 tgu_val += s; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4741 (pl) = gc_plist_hack ((name), s, (pl)); \ |
428 | 4742 } while (0) |
4743 | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4744 #define FROB(type) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4745 do { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4746 COUNT_FROB_BLOCK_USAGE (type); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4747 tgu_val += s; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4748 } while (0) |
5058
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4749 |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4750 FROB (extent); |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4751 FROB (event); |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4752 FROB (marker); |
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4753 FROB (float); |
1983 | 4754 #ifdef HAVE_BIGNUM |
5058
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4755 FROB (bignum); |
1983 | 4756 #endif /* HAVE_BIGNUM */ |
4757 #ifdef HAVE_RATIO | |
5058
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4758 FROB (ratio); |
1983 | 4759 #endif /* HAVE_RATIO */ |
4760 #ifdef HAVE_BIGFLOAT | |
5058
eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
Ben Wing <ben@xemacs.org>
parents:
5046
diff
changeset
|
4761 FROB (bigfloat); |
1983 | 4762 #endif /* HAVE_BIGFLOAT */ |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4763 FROB (compiled_function); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4764 FROB (symbol); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4765 FROB (cons); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4766 |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4767 #undef FROB |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4768 |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4769 for (i = 0; i < lrecord_type_count; i++) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4770 { |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4771 if (lrecord_stats[i].bytes_in_use != 0 |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4772 || lrecord_stats[i].bytes_freed != 0 |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4773 || lrecord_stats[i].instances_on_free_list != 0) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4774 { |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4775 Ascbyte buf[255]; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4776 const Ascbyte *name = lrecord_implementations_table[i]->name; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4777 |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4778 sprintf (buf, "%s-storage", name); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4779 pl = gc_plist_hack (buf, lrecord_stats[i].bytes_in_use, pl); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4780 tgu_val += lrecord_stats[i].bytes_in_use; |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4781 if (lrecord_stats[i].nonlisp_bytes_in_use) |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4782 { |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4783 sprintf (buf, "%s-non-lisp-storage", name); |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4784 pl = gc_plist_hack (buf, lrecord_stats[i].nonlisp_bytes_in_use, |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4785 pl); |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4786 tgu_val += lrecord_stats[i].nonlisp_bytes_in_use; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4787 } |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4788 pluralize_and_append (buf, name, "-freed"); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4789 if (lrecord_stats[i].instances_freed != 0) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4790 pl = gc_plist_hack (buf, lrecord_stats[i].instances_freed, pl); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4791 pluralize_and_append (buf, name, "-on-free-list"); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4792 if (lrecord_stats[i].instances_on_free_list != 0) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4793 pl = gc_plist_hack (buf, lrecord_stats[i].instances_on_free_list, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4794 pl); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4795 pluralize_and_append (buf, name, "-used"); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4796 pl = gc_plist_hack (buf, lrecord_stats[i].instances_in_use, pl); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4797 } |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4798 } |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4799 |
428 | 4800 HACK_O_MATIC (string, "string-header-storage", pl); |
4801 pl = gc_plist_hack ("long-strings-total-length", | |
4802 gc_count_string_total_size | |
4803 - gc_count_short_string_total_size, pl); | |
4804 HACK_O_MATIC (string_chars, "short-string-storage", pl); | |
4805 pl = gc_plist_hack ("short-strings-total-length", | |
4806 gc_count_short_string_total_size, pl); | |
4807 pl = gc_plist_hack ("strings-free", gc_count_num_string_freelist, pl); | |
4808 pl = gc_plist_hack ("long-strings-used", | |
4809 gc_count_num_string_in_use | |
4810 - gc_count_num_short_string_in_use, pl); | |
4811 pl = gc_plist_hack ("short-strings-used", | |
4812 gc_count_num_short_string_in_use, pl); | |
4813 | |
2994 | 4814 #undef HACK_O_MATIC |
4815 | |
3263 | 4816 #endif /* NEW_GC */ |
2994 | 4817 |
4818 if (set_total_gc_usage) | |
4819 { | |
4820 total_gc_usage = tgu_val; | |
4821 total_gc_usage_set = 1; | |
4822 } | |
4823 | |
4824 return pl; | |
4825 } | |
4826 | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4827 DEFUN ("object-memory-usage-stats", Fobject_memory_usage_stats, 0, 0, 0, /* |
2994 | 4828 Return statistics about memory usage of Lisp objects. |
4829 */ | |
4830 ()) | |
4831 { | |
4832 return object_memory_usage_stats (0); | |
4833 } | |
4834 | |
4835 #endif /* ALLOC_TYPE_STATS */ | |
4836 | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4837 #ifdef MEMORY_USAGE_STATS |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4838 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4839 /* Compute the number of extra memory-usage statistics associated with an |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4840 object. We can't compute this at the time INIT_LISP_OBJECT() is called |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4841 because the value of the `memusage_stats_list' property is generally |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4842 set afterwards. So we compute the values for all types of objects |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4843 after all objects have been initialized. */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4844 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4845 static void |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4846 compute_memusage_stats_length (void) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4847 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4848 int i; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4849 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4850 for (i = 0; i < countof (lrecord_implementations_table); i++) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4851 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4852 int len = 0; |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4853 int nonlisp_len = 0; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4854 int seen_break = 0; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4855 |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4856 struct lrecord_implementation *imp = lrecord_implementations_table[i]; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4857 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4858 if (!imp) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4859 continue; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4860 /* For some of the early objects, Qnil was not yet initialized at |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4861 the time of object initialization, so it came up as Qnull_pointer. |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4862 Fix that now. */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4863 if (EQ (imp->memusage_stats_list, Qnull_pointer)) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4864 imp->memusage_stats_list = Qnil; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4865 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4866 LIST_LOOP_2 (item, imp->memusage_stats_list) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4867 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4868 if (!NILP (item) && !EQ (item, Qt)) |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4869 { |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4870 len++; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4871 if (!seen_break) |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4872 nonlisp_len++; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4873 } |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4874 else |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4875 seen_break++; |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4876 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4877 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4878 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4879 imp->num_extra_memusage_stats = len; |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
4880 imp->num_extra_nonlisp_memusage_stats = nonlisp_len; |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4881 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4882 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4883 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4884 DEFUN ("object-memory-usage", Fobject_memory_usage, 1, 1, 0, /* |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4885 Return stats about the memory usage of OBJECT. |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4886 The values returned are in the form of an alist of usage types and byte |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4887 counts. The byte counts attempt to encompass all the memory used |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4888 by the object (separate from the memory logically associated with any |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4889 other object), including internal structures and any malloc() |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4890 overhead associated with them. In practice, the byte counts are |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4891 underestimated because certain memory usage is very hard to determine |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4892 \(e.g. the amount of memory used inside the Xt library or inside the |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4893 X server). |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4894 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4895 Multiple slices of the total memory usage may be returned, separated |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4896 by a nil. Each slice represents a particular view of the memory, a |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4897 particular way of partitioning it into groups. Within a slice, there |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4898 is no overlap between the groups of memory, and each slice collectively |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4899 represents all the memory concerned. The rightmost slice typically |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4900 represents the total memory used plus malloc and dynarr overhead. |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4901 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4902 Slices describing other Lisp objects logically associated with the |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4903 object may be included, separated from other slices by `t' and from |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4904 each other by nil if there is more than one. |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4905 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4906 #### We have to figure out how to handle the memory used by the object |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4907 itself vs. the memory used by substructures. Probably the memory_usage |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4908 method should return info only about substructures and related Lisp |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4909 objects, since the caller can always find and all info about the object |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4910 itself. |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4911 */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4912 (object)) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4913 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4914 struct generic_usage_stats gustats; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4915 struct usage_stats object_stats; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4916 int i; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4917 Lisp_Object val = Qnil; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4918 Lisp_Object stats_list = OBJECT_PROPERTY (object, memusage_stats_list); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4919 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4920 xzero (object_stats); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4921 lisp_object_storage_size (object, &object_stats); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4922 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4923 val = acons (Qobject_actually_requested, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4924 make_int (object_stats.was_requested), val); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4925 val = acons (Qobject_malloc_overhead, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4926 make_int (object_stats.malloc_overhead), val); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4927 assert (!object_stats.dynarr_overhead); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4928 assert (!object_stats.gap_overhead); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4929 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4930 if (!NILP (stats_list)) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4931 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4932 xzero (gustats); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4933 MAYBE_OBJECT_METH (object, memory_usage, (object, &gustats)); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4934 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4935 val = Fcons (Qt, val); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4936 val = acons (Qother_memory_actually_requested, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4937 make_int (gustats.u.was_requested), val); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4938 val = acons (Qother_memory_malloc_overhead, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4939 make_int (gustats.u.malloc_overhead), val); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4940 if (gustats.u.dynarr_overhead) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4941 val = acons (Qother_memory_dynarr_overhead, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4942 make_int (gustats.u.dynarr_overhead), val); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4943 if (gustats.u.gap_overhead) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4944 val = acons (Qother_memory_gap_overhead, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4945 make_int (gustats.u.gap_overhead), val); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4946 val = Fcons (Qnil, val); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4947 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4948 i = 0; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4949 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4950 LIST_LOOP_2 (item, stats_list) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4951 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4952 if (NILP (item) || EQ (item, Qt)) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4953 val = Fcons (item, val); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4954 else |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4955 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4956 val = acons (item, make_int (gustats.othervals[i]), val); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4957 i++; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4958 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4959 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4960 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4961 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4962 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4963 return Fnreverse (val); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4964 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4965 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4966 #endif /* MEMORY_USAGE_STATS */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
4967 |
2994 | 4968 /* Debugging aids. */ |
4969 | |
4970 DEFUN ("garbage-collect", Fgarbage_collect, 0, 0, "", /* | |
4971 Reclaim storage for Lisp objects no longer needed. | |
4972 Return info on amount of space in use: | |
4973 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS) | |
4974 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS | |
4975 PLIST) | |
4976 where `PLIST' is a list of alternating keyword/value pairs providing | |
4977 more detailed information. | |
4978 Garbage collection happens automatically if you cons more than | |
4979 `gc-cons-threshold' bytes of Lisp data since previous garbage collection. | |
4980 */ | |
4981 ()) | |
4982 { | |
4983 /* Record total usage for purposes of determining next GC */ | |
3092 | 4984 #ifdef NEW_GC |
4985 gc_full (); | |
4986 #else /* not NEW_GC */ | |
2994 | 4987 garbage_collect_1 (); |
3092 | 4988 #endif /* not NEW_GC */ |
2994 | 4989 |
4990 /* This will get set to 1, and total_gc_usage computed, as part of the | |
4991 call to object_memory_usage_stats() -- if ALLOC_TYPE_STATS is enabled. */ | |
4992 total_gc_usage_set = 0; | |
4993 #ifdef ALLOC_TYPE_STATS | |
428 | 4994 /* The things we do for backwards-compatibility */ |
3263 | 4995 #ifdef NEW_GC |
2994 | 4996 return |
4997 list6 | |
4998 (Fcons (make_int (lrecord_stats[lrecord_type_cons].instances_in_use), | |
4999 make_int (lrecord_stats[lrecord_type_cons] | |
5000 .bytes_in_use_including_overhead)), | |
5001 Fcons (make_int (lrecord_stats[lrecord_type_symbol].instances_in_use), | |
5002 make_int (lrecord_stats[lrecord_type_symbol] | |
5003 .bytes_in_use_including_overhead)), | |
5004 Fcons (make_int (lrecord_stats[lrecord_type_marker].instances_in_use), | |
5005 make_int (lrecord_stats[lrecord_type_marker] | |
5006 .bytes_in_use_including_overhead)), | |
5007 make_int (lrecord_stats[lrecord_type_string] | |
5008 .bytes_in_use_including_overhead), | |
5009 make_int (lrecord_stats[lrecord_type_vector] | |
5010 .bytes_in_use_including_overhead), | |
5011 object_memory_usage_stats (1)); | |
3263 | 5012 #else /* not NEW_GC */ |
428 | 5013 return |
5014 list6 (Fcons (make_int (gc_count_num_cons_in_use), | |
5015 make_int (gc_count_num_cons_freelist)), | |
5016 Fcons (make_int (gc_count_num_symbol_in_use), | |
5017 make_int (gc_count_num_symbol_freelist)), | |
5018 Fcons (make_int (gc_count_num_marker_in_use), | |
5019 make_int (gc_count_num_marker_freelist)), | |
5020 make_int (gc_count_string_total_size), | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
5021 make_int (lrecord_stats[lrecord_type_vector].bytes_in_use + |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
5022 lrecord_stats[lrecord_type_vector].bytes_freed + |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
5023 lrecord_stats[lrecord_type_vector].bytes_on_free_list), |
2994 | 5024 object_memory_usage_stats (1)); |
3263 | 5025 #endif /* not NEW_GC */ |
2994 | 5026 #else /* not ALLOC_TYPE_STATS */ |
5027 return Qnil; | |
5028 #endif /* ALLOC_TYPE_STATS */ | |
5029 } | |
428 | 5030 |
5031 DEFUN ("consing-since-gc", Fconsing_since_gc, 0, 0, "", /* | |
5032 Return the number of bytes consed since the last garbage collection. | |
5033 \"Consed\" is a misnomer in that this actually counts allocation | |
5034 of all different kinds of objects, not just conses. | |
5035 | |
5036 If this value exceeds `gc-cons-threshold', a garbage collection happens. | |
5037 */ | |
5038 ()) | |
5039 { | |
5040 return make_int (consing_since_gc); | |
5041 } | |
5042 | |
440 | 5043 #if 0 |
444 | 5044 DEFUN ("memory-limit", Fmemory_limit, 0, 0, 0, /* |
801 | 5045 Return the address of the last byte XEmacs has allocated, divided by 1024. |
5046 This may be helpful in debugging XEmacs's memory usage. | |
428 | 5047 The value is divided by 1024 to make sure it will fit in a lisp integer. |
5048 */ | |
5049 ()) | |
5050 { | |
5051 return make_int ((EMACS_INT) sbrk (0) / 1024); | |
5052 } | |
440 | 5053 #endif |
428 | 5054 |
2994 | 5055 DEFUN ("total-memory-usage", Ftotal_memory_usage, 0, 0, 0, /* |
801 | 5056 Return the total number of bytes used by the data segment in XEmacs. |
5057 This may be helpful in debugging XEmacs's memory usage. | |
2994 | 5058 NOTE: This may or may not be accurate! It is hard to determine this |
5059 value in a system-independent fashion. On Windows, for example, the | |
5060 returned number tends to be much greater than reality. | |
801 | 5061 */ |
5062 ()) | |
5063 { | |
5064 return make_int (total_data_usage ()); | |
5065 } | |
5066 | |
2994 | 5067 #ifdef ALLOC_TYPE_STATS |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5068 DEFUN ("total-object-memory-usage", Ftotal_object_memory_usage, 0, 0, 0, /* |
2994 | 5069 Return total number of bytes used for object storage in XEmacs. |
5070 This may be helpful in debugging XEmacs's memory usage. | |
5071 See also `consing-since-gc' and `object-memory-usage-stats'. | |
5072 */ | |
5073 ()) | |
5074 { | |
5075 return make_int (total_gc_usage + consing_since_gc); | |
5076 } | |
5077 #endif /* ALLOC_TYPE_STATS */ | |
5078 | |
4803
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5079 #ifdef USE_VALGRIND |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5080 DEFUN ("valgrind-leak-check", Fvalgrind_leak_check, 0, 0, "", /* |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5081 Ask valgrind to perform a memory leak check. |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5082 The results of the leak check are sent to stderr. |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5083 */ |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5084 ()) |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5085 { |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5086 VALGRIND_DO_LEAK_CHECK; |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5087 return Qnil; |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5088 } |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5089 |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5090 DEFUN ("valgrind-quick-leak-check", Fvalgrind_quick_leak_check, 0, 0, "", /* |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5091 Ask valgrind to perform a quick memory leak check. |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5092 This just prints a summary of leaked memory, rather than all the details. |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5093 The results of the leak check are sent to stderr. |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5094 */ |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5095 ()) |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5096 { |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5097 VALGRIND_DO_QUICK_LEAK_CHECK; |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5098 return Qnil; |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5099 } |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5100 #endif /* USE_VALGRIND */ |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5101 |
851 | 5102 void |
5103 recompute_funcall_allocation_flag (void) | |
5104 { | |
887 | 5105 funcall_allocation_flag = |
5106 need_to_garbage_collect || | |
5107 need_to_check_c_alloca || | |
5108 need_to_signal_post_gc; | |
851 | 5109 } |
5110 | |
428 | 5111 |
5112 int | |
5113 object_dead_p (Lisp_Object obj) | |
5114 { | |
5115 return ((BUFFERP (obj) && !BUFFER_LIVE_P (XBUFFER (obj))) || | |
5116 (FRAMEP (obj) && !FRAME_LIVE_P (XFRAME (obj))) || | |
5117 (WINDOWP (obj) && !WINDOW_LIVE_P (XWINDOW (obj))) || | |
5118 (DEVICEP (obj) && !DEVICE_LIVE_P (XDEVICE (obj))) || | |
5119 (CONSOLEP (obj) && !CONSOLE_LIVE_P (XCONSOLE (obj))) || | |
5120 (EVENTP (obj) && !EVENT_LIVE_P (XEVENT (obj))) || | |
5121 (EXTENTP (obj) && !EXTENT_LIVE_P (XEXTENT (obj)))); | |
5122 } | |
5123 | |
5124 #ifdef MEMORY_USAGE_STATS | |
5125 | |
5126 /* Attempt to determine the actual amount of space that is used for | |
5127 the block allocated starting at PTR, supposedly of size "CLAIMED_SIZE". | |
5128 | |
5129 It seems that the following holds: | |
5130 | |
5131 1. When using the old allocator (malloc.c): | |
5132 | |
5133 -- blocks are always allocated in chunks of powers of two. For | |
5134 each block, there is an overhead of 8 bytes if rcheck is not | |
5135 defined, 20 bytes if it is defined. In other words, a | |
5136 one-byte allocation needs 8 bytes of overhead for a total of | |
5137 9 bytes, and needs to have 16 bytes of memory chunked out for | |
5138 it. | |
5139 | |
5140 2. When using the new allocator (gmalloc.c): | |
5141 | |
5142 -- blocks are always allocated in chunks of powers of two up | |
5143 to 4096 bytes. Larger blocks are allocated in chunks of | |
5144 an integral multiple of 4096 bytes. The minimum block | |
5145 size is 2*sizeof (void *), or 16 bytes if SUNOS_LOCALTIME_BUG | |
5146 is defined. There is no per-block overhead, but there | |
5147 is an overhead of 3*sizeof (size_t) for each 4096 bytes | |
5148 allocated. | |
5149 | |
5150 3. When using the system malloc, anything goes, but they are | |
5151 generally slower and more space-efficient than the GNU | |
5152 allocators. One possibly reasonable assumption to make | |
5153 for want of better data is that sizeof (void *), or maybe | |
5154 2 * sizeof (void *), is required as overhead and that | |
5155 blocks are allocated in the minimum required size except | |
5156 that some minimum block size is imposed (e.g. 16 bytes). */ | |
5157 | |
665 | 5158 Bytecount |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
5159 malloced_storage_size (void * UNUSED (ptr), Bytecount claimed_size, |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5160 struct usage_stats *stats) |
428 | 5161 { |
665 | 5162 Bytecount orig_claimed_size = claimed_size; |
428 | 5163 |
4735
80d74fed5399
Remove "old" GNU malloc in src/malloc.c, and all references to it. Drop the
Jerry James <james@xemacs.org>
parents:
4693
diff
changeset
|
5164 #ifndef SYSTEM_MALLOC |
665 | 5165 if (claimed_size < (Bytecount) (2 * sizeof (void *))) |
428 | 5166 claimed_size = 2 * sizeof (void *); |
5167 # ifdef SUNOS_LOCALTIME_BUG | |
5168 if (claimed_size < 16) | |
5169 claimed_size = 16; | |
5170 # endif | |
5171 if (claimed_size < 4096) | |
5172 { | |
2260 | 5173 /* fxg: rename log->log2 to supress gcc3 shadow warning */ |
5174 int log2 = 1; | |
428 | 5175 |
5176 /* compute the log base two, more or less, then use it to compute | |
5177 the block size needed. */ | |
5178 claimed_size--; | |
5179 /* It's big, it's heavy, it's wood! */ | |
5180 while ((claimed_size /= 2) != 0) | |
2260 | 5181 ++log2; |
428 | 5182 claimed_size = 1; |
5183 /* It's better than bad, it's good! */ | |
2260 | 5184 while (log2 > 0) |
428 | 5185 { |
5186 claimed_size *= 2; | |
2260 | 5187 log2--; |
428 | 5188 } |
5189 /* We have to come up with some average about the amount of | |
5190 blocks used. */ | |
665 | 5191 if ((Bytecount) (rand () & 4095) < claimed_size) |
428 | 5192 claimed_size += 3 * sizeof (void *); |
5193 } | |
5194 else | |
5195 { | |
5196 claimed_size += 4095; | |
5197 claimed_size &= ~4095; | |
5198 claimed_size += (claimed_size / 4096) * 3 * sizeof (size_t); | |
5199 } | |
5200 | |
4735
80d74fed5399
Remove "old" GNU malloc in src/malloc.c, and all references to it. Drop the
Jerry James <james@xemacs.org>
parents:
4693
diff
changeset
|
5201 #else |
428 | 5202 |
5203 if (claimed_size < 16) | |
5204 claimed_size = 16; | |
5205 claimed_size += 2 * sizeof (void *); | |
5206 | |
4735
80d74fed5399
Remove "old" GNU malloc in src/malloc.c, and all references to it. Drop the
Jerry James <james@xemacs.org>
parents:
4693
diff
changeset
|
5207 #endif /* system allocator */ |
428 | 5208 |
5209 if (stats) | |
5210 { | |
5211 stats->was_requested += orig_claimed_size; | |
5212 stats->malloc_overhead += claimed_size - orig_claimed_size; | |
5213 } | |
5214 return claimed_size; | |
5215 } | |
5216 | |
3263 | 5217 #ifndef NEW_GC |
665 | 5218 Bytecount |
5219 fixed_type_block_overhead (Bytecount size) | |
428 | 5220 { |
665 | 5221 Bytecount per_block = TYPE_ALLOC_SIZE (cons, unsigned char); |
5222 Bytecount overhead = 0; | |
5223 Bytecount storage_size = malloced_storage_size (0, per_block, 0); | |
428 | 5224 while (size >= per_block) |
5225 { | |
5226 size -= per_block; | |
5227 overhead += sizeof (void *) + per_block - storage_size; | |
5228 } | |
5229 if (rand () % per_block < size) | |
5230 overhead += sizeof (void *) + per_block - storage_size; | |
5231 return overhead; | |
5232 } | |
3263 | 5233 #endif /* not NEW_GC */ |
428 | 5234 #endif /* MEMORY_USAGE_STATS */ |
5235 | |
5236 | |
5237 /* Initialization */ | |
771 | 5238 static void |
1204 | 5239 common_init_alloc_early (void) |
428 | 5240 { |
771 | 5241 #ifndef Qzero |
5242 Qzero = make_int (0); /* Only used if Lisp_Object is a union type */ | |
5243 #endif | |
5244 | |
5245 #ifndef Qnull_pointer | |
5246 /* C guarantees that Qnull_pointer will be initialized to all 0 bits, | |
5247 so the following is actually a no-op. */ | |
793 | 5248 Qnull_pointer = wrap_pointer_1 (0); |
771 | 5249 #endif |
5250 | |
3263 | 5251 #ifndef NEW_GC |
428 | 5252 breathing_space = 0; |
5253 all_lcrecords = 0; | |
3263 | 5254 #endif /* not NEW_GC */ |
428 | 5255 ignore_malloc_warnings = 1; |
5256 #ifdef DOUG_LEA_MALLOC | |
5257 mallopt (M_TRIM_THRESHOLD, 128*1024); /* trim threshold */ | |
5258 mallopt (M_MMAP_THRESHOLD, 64*1024); /* mmap threshold */ | |
5259 #if 0 /* Moved to emacs.c */ | |
5260 mallopt (M_MMAP_MAX, 64); /* max. number of mmap'ed areas */ | |
5261 #endif | |
5262 #endif | |
3092 | 5263 #ifndef NEW_GC |
2720 | 5264 init_string_chars_alloc (); |
428 | 5265 init_string_alloc (); |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5266 /* #### Is it intentional that this is called twice? --ben */ |
428 | 5267 init_string_chars_alloc (); |
5268 init_cons_alloc (); | |
5269 init_symbol_alloc (); | |
5270 init_compiled_function_alloc (); | |
5271 init_float_alloc (); | |
1983 | 5272 #ifdef HAVE_BIGNUM |
5273 init_bignum_alloc (); | |
5274 #endif | |
5275 #ifdef HAVE_RATIO | |
5276 init_ratio_alloc (); | |
5277 #endif | |
5278 #ifdef HAVE_BIGFLOAT | |
5279 init_bigfloat_alloc (); | |
5280 #endif | |
428 | 5281 init_marker_alloc (); |
5282 init_extent_alloc (); | |
5283 init_event_alloc (); | |
1204 | 5284 #ifdef EVENT_DATA_AS_OBJECTS |
934 | 5285 init_key_data_alloc (); |
5286 init_button_data_alloc (); | |
5287 init_motion_data_alloc (); | |
5288 init_process_data_alloc (); | |
5289 init_timeout_data_alloc (); | |
5290 init_magic_data_alloc (); | |
5291 init_magic_eval_data_alloc (); | |
5292 init_eval_data_alloc (); | |
5293 init_misc_user_data_alloc (); | |
1204 | 5294 #endif /* EVENT_DATA_AS_OBJECTS */ |
3263 | 5295 #endif /* not NEW_GC */ |
428 | 5296 |
5297 ignore_malloc_warnings = 0; | |
5298 | |
452 | 5299 if (staticpros_nodump) |
5300 Dynarr_free (staticpros_nodump); | |
5301 staticpros_nodump = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *); | |
5302 Dynarr_resize (staticpros_nodump, 100); /* merely a small optimization */ | |
771 | 5303 #ifdef DEBUG_XEMACS |
5304 if (staticpro_nodump_names) | |
5305 Dynarr_free (staticpro_nodump_names); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5306 staticpro_nodump_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5307 const Ascbyte *); |
771 | 5308 Dynarr_resize (staticpro_nodump_names, 100); /* ditto */ |
5309 #endif | |
428 | 5310 |
3263 | 5311 #ifdef NEW_GC |
2720 | 5312 mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object); |
5313 Dynarr_resize (mcpros, 1410); /* merely a small optimization */ | |
5314 dump_add_root_block_ptr (&mcpros, &mcpros_description); | |
5315 #ifdef DEBUG_XEMACS | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5316 mcpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *); |
2720 | 5317 Dynarr_resize (mcpro_names, 1410); /* merely a small optimization */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5318 dump_add_root_block_ptr (&mcpro_names, |
4964 | 5319 &const_Ascbyte_ptr_dynarr_description); |
2720 | 5320 #endif |
3263 | 5321 #endif /* NEW_GC */ |
2720 | 5322 |
428 | 5323 consing_since_gc = 0; |
851 | 5324 need_to_check_c_alloca = 0; |
5325 funcall_allocation_flag = 0; | |
5326 funcall_alloca_count = 0; | |
814 | 5327 |
3263 | 5328 #ifndef NEW_GC |
428 | 5329 debug_string_purity = 0; |
3263 | 5330 #endif /* not NEW_GC */ |
428 | 5331 |
800 | 5332 #ifdef ERROR_CHECK_TYPES |
428 | 5333 ERROR_ME.really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = |
5334 666; | |
5335 ERROR_ME_NOT. | |
5336 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = 42; | |
5337 ERROR_ME_WARN. | |
5338 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = | |
5339 3333632; | |
793 | 5340 ERROR_ME_DEBUG_WARN. |
5341 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = | |
5342 8675309; | |
800 | 5343 #endif /* ERROR_CHECK_TYPES */ |
428 | 5344 } |
5345 | |
3263 | 5346 #ifndef NEW_GC |
771 | 5347 static void |
5348 init_lcrecord_lists (void) | |
5349 { | |
5350 int i; | |
5351 | |
5352 for (i = 0; i < countof (lrecord_implementations_table); i++) | |
5353 { | |
5354 all_lcrecord_lists[i] = Qzero; /* Qnil not yet set */ | |
5355 staticpro_nodump (&all_lcrecord_lists[i]); | |
5356 } | |
5357 } | |
3263 | 5358 #endif /* not NEW_GC */ |
771 | 5359 |
5360 void | |
1204 | 5361 init_alloc_early (void) |
771 | 5362 { |
1204 | 5363 #if defined (__cplusplus) && defined (ERROR_CHECK_GC) |
5364 static struct gcpro initial_gcpro; | |
5365 | |
5366 initial_gcpro.next = 0; | |
5367 initial_gcpro.var = &Qnil; | |
5368 initial_gcpro.nvars = 1; | |
5369 gcprolist = &initial_gcpro; | |
5370 #else | |
5371 gcprolist = 0; | |
5372 #endif /* defined (__cplusplus) && defined (ERROR_CHECK_GC) */ | |
5373 } | |
5374 | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5375 static void |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5376 reinit_alloc_objects_early (void) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5377 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5378 OBJECT_HAS_METHOD (string, getprop); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5379 OBJECT_HAS_METHOD (string, putprop); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5380 OBJECT_HAS_METHOD (string, remprop); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5381 OBJECT_HAS_METHOD (string, plist); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5382 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5383 |
1204 | 5384 void |
5385 reinit_alloc_early (void) | |
5386 { | |
5387 common_init_alloc_early (); | |
3263 | 5388 #ifndef NEW_GC |
771 | 5389 init_lcrecord_lists (); |
3263 | 5390 #endif /* not NEW_GC */ |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5391 reinit_alloc_objects_early (); |
771 | 5392 } |
5393 | |
428 | 5394 void |
5395 init_alloc_once_early (void) | |
5396 { | |
1204 | 5397 common_init_alloc_early (); |
428 | 5398 |
442 | 5399 { |
5400 int i; | |
5401 for (i = 0; i < countof (lrecord_implementations_table); i++) | |
5402 lrecord_implementations_table[i] = 0; | |
5403 } | |
5404 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
5405 dump_add_opaque (lrecord_uid_counter, sizeof (lrecord_uid_counter)); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
5406 |
452 | 5407 staticpros = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *); |
5408 Dynarr_resize (staticpros, 1410); /* merely a small optimization */ | |
2367 | 5409 dump_add_root_block_ptr (&staticpros, &staticpros_description); |
771 | 5410 #ifdef DEBUG_XEMACS |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5411 staticpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *); |
771 | 5412 Dynarr_resize (staticpro_names, 1410); /* merely a small optimization */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5413 dump_add_root_block_ptr (&staticpro_names, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5414 &const_Ascbyte_ptr_dynarr_description); |
771 | 5415 #endif |
5416 | |
3263 | 5417 #ifdef NEW_GC |
2720 | 5418 mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object); |
5419 Dynarr_resize (mcpros, 1410); /* merely a small optimization */ | |
5420 dump_add_root_block_ptr (&mcpros, &mcpros_description); | |
5421 #ifdef DEBUG_XEMACS | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5422 mcpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *); |
2720 | 5423 Dynarr_resize (mcpro_names, 1410); /* merely a small optimization */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5424 dump_add_root_block_ptr (&mcpro_names, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5425 &const_Ascbyte_ptr_dynarr_description); |
2720 | 5426 #endif |
3263 | 5427 #else /* not NEW_GC */ |
771 | 5428 init_lcrecord_lists (); |
3263 | 5429 #endif /* not NEW_GC */ |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5430 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5431 INIT_LISP_OBJECT (cons); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5432 INIT_LISP_OBJECT (vector); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5433 INIT_LISP_OBJECT (string); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5434 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5435 #ifdef NEW_GC |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5436 INIT_LISP_OBJECT (string_indirect_data); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5437 INIT_LISP_OBJECT (string_direct_data); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5438 #endif /* NEW_GC */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5439 #ifndef NEW_GC |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5440 INIT_LISP_OBJECT (lcrecord_list); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5441 INIT_LISP_OBJECT (free); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5442 #endif /* not NEW_GC */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5443 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5444 reinit_alloc_objects_early (); |
428 | 5445 } |
5446 | |
5447 void | |
5448 syms_of_alloc (void) | |
5449 { | |
442 | 5450 DEFSYMBOL (Qgarbage_collecting); |
428 | 5451 |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5452 #ifdef MEMORY_USAGE_STATS |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5453 DEFSYMBOL (Qobject_actually_requested); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5454 DEFSYMBOL (Qobject_malloc_overhead); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5455 DEFSYMBOL (Qother_memory_actually_requested); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5456 DEFSYMBOL (Qother_memory_malloc_overhead); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5457 DEFSYMBOL (Qother_memory_dynarr_overhead); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5458 DEFSYMBOL (Qother_memory_gap_overhead); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5459 #endif /* MEMORY_USAGE_STATS */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5460 |
428 | 5461 DEFSUBR (Fcons); |
5462 DEFSUBR (Flist); | |
5463 DEFSUBR (Fvector); | |
5464 DEFSUBR (Fbit_vector); | |
5465 DEFSUBR (Fmake_byte_code); | |
5466 DEFSUBR (Fmake_list); | |
5467 DEFSUBR (Fmake_vector); | |
5468 DEFSUBR (Fmake_bit_vector); | |
5469 DEFSUBR (Fmake_string); | |
5470 DEFSUBR (Fstring); | |
5471 DEFSUBR (Fmake_symbol); | |
5472 DEFSUBR (Fmake_marker); | |
5473 DEFSUBR (Fpurecopy); | |
2994 | 5474 #ifdef ALLOC_TYPE_STATS |
5475 DEFSUBR (Fobject_memory_usage_stats); | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5476 DEFSUBR (Ftotal_object_memory_usage); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5477 #endif /* ALLOC_TYPE_STATS */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5478 #ifdef MEMORY_USAGE_STATS |
2994 | 5479 DEFSUBR (Fobject_memory_usage); |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5480 #endif /* MEMORY_USAGE_STATS */ |
428 | 5481 DEFSUBR (Fgarbage_collect); |
440 | 5482 #if 0 |
428 | 5483 DEFSUBR (Fmemory_limit); |
440 | 5484 #endif |
2994 | 5485 DEFSUBR (Ftotal_memory_usage); |
428 | 5486 DEFSUBR (Fconsing_since_gc); |
4803
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5487 #ifdef USE_VALGRIND |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5488 DEFSUBR (Fvalgrind_leak_check); |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5489 DEFSUBR (Fvalgrind_quick_leak_check); |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5490 #endif |
428 | 5491 } |
5492 | |
5493 void | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5494 reinit_vars_of_alloc (void) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5495 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5496 #ifdef MEMORY_USAGE_STATS |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5497 compute_memusage_stats_length (); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5498 #endif /* MEMORY_USAGE_STATS */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5499 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5500 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5501 void |
428 | 5502 vars_of_alloc (void) |
5503 { | |
5504 #ifdef DEBUG_XEMACS | |
5505 DEFVAR_INT ("debug-allocation", &debug_allocation /* | |
5506 If non-zero, print out information to stderr about all objects allocated. | |
5507 See also `debug-allocation-backtrace-length'. | |
5508 */ ); | |
5509 debug_allocation = 0; | |
5510 | |
5511 DEFVAR_INT ("debug-allocation-backtrace-length", | |
5512 &debug_allocation_backtrace_length /* | |
5513 Length (in stack frames) of short backtrace printed out by `debug-allocation'. | |
5514 */ ); | |
5515 debug_allocation_backtrace_length = 2; | |
5516 #endif | |
5517 | |
5518 DEFVAR_BOOL ("purify-flag", &purify_flag /* | |
5519 Non-nil means loading Lisp code in order to dump an executable. | |
5520 This means that certain objects should be allocated in readonly space. | |
5521 */ ); | |
5522 } |