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