0
|
1 /* Storage allocation and gc for XEmacs Lisp interpreter.
|
|
2 Copyright (C) 1985, 1986, 1988, 1992, 1993, 1994
|
|
3 Free Software Foundation, Inc.
|
|
4 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
5 Copyright (C) 1995, 1996 Ben Wing.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: FSF 19.28, Mule 2.0. Substantially different from
|
|
25 FSF. */
|
|
26
|
|
27 /* Authorship:
|
|
28
|
|
29 FSF: Original version; a long time ago.
|
|
30 Mly: Significantly rewritten to use new 3-bit tags and
|
|
31 nicely abstracted object definitions, for 19.8.
|
|
32 JWZ: Improved code to keep track of purespace usage and
|
|
33 issue nice purespace and GC stats.
|
|
34 Ben Wing: Cleaned up frob-block lrecord code, added error-checking
|
|
35 and various changes for Mule, for 19.12.
|
|
36 Added bit vectors for 19.13.
|
|
37 Added lcrecord lists for 19.14.
|
|
38 */
|
|
39
|
|
40 #include <config.h>
|
|
41 #include "lisp.h"
|
165
|
42 #include "sysdep.h"
|
0
|
43
|
|
44 #ifndef standalone
|
|
45 #include "backtrace.h"
|
|
46 #include "buffer.h"
|
|
47 #include "bytecode.h"
|
70
|
48 #include "chartab.h"
|
0
|
49 #include "device.h"
|
|
50 #include "elhash.h"
|
|
51 #include "events.h"
|
|
52 #include "extents.h"
|
|
53 #include "frame.h"
|
|
54 #include "glyphs.h"
|
|
55 #include "redisplay.h"
|
|
56 #include "specifier.h"
|
|
57 #include "window.h"
|
|
58 #endif
|
|
59
|
|
60 /* #define GDB_SUCKS */
|
|
61
|
|
62 /* #define VERIFY_STRING_CHARS_INTEGRITY */
|
|
63
|
|
64 /* Define this to see where all that space is going... */
|
|
65 #define PURESTAT
|
|
66
|
|
67 /* Define this to use malloc/free with no freelist for all datatypes,
|
|
68 the hope being that some debugging tools may help detect
|
|
69 freed memory references */
|
|
70 /* #define ALLOC_NO_POOLS */
|
|
71
|
|
72 #include "puresize.h"
|
|
73
|
|
74 #ifdef DEBUG_XEMACS
|
|
75 int debug_allocation;
|
|
76
|
|
77 int debug_allocation_backtrace_length;
|
|
78 #endif
|
|
79
|
|
80 /* Number of bytes of consing done since the last gc */
|
|
81 EMACS_INT consing_since_gc;
|
|
82 #ifdef EMACS_BTL
|
|
83 extern void cadillac_record_backtrace ();
|
|
84 #define INCREMENT_CONS_COUNTER_1(size) \
|
|
85 do { \
|
|
86 EMACS_INT __sz__ = ((EMACS_INT) (size)); \
|
|
87 consing_since_gc += __sz__; \
|
|
88 cadillac_record_backtrace (2, __sz__); \
|
|
89 } while (0)
|
|
90 #else
|
|
91 #define INCREMENT_CONS_COUNTER_1(size) (consing_since_gc += (size))
|
|
92 #endif
|
|
93
|
|
94 #define debug_allocation_backtrace() \
|
|
95 do { \
|
|
96 if (debug_allocation_backtrace_length > 0) \
|
|
97 debug_short_backtrace (debug_allocation_backtrace_length); \
|
|
98 } while (0)
|
|
99
|
|
100 #ifdef DEBUG_XEMACS
|
|
101 #define INCREMENT_CONS_COUNTER(foosize, type) \
|
|
102 do { \
|
|
103 if (debug_allocation) \
|
|
104 { \
|
|
105 stderr_out ("allocating %s (size %ld)\n", type, (long)foosize); \
|
|
106 debug_allocation_backtrace (); \
|
|
107 } \
|
|
108 INCREMENT_CONS_COUNTER_1 (foosize); \
|
|
109 } while (0)
|
|
110 #define NOSEEUM_INCREMENT_CONS_COUNTER(foosize, type) \
|
|
111 do { \
|
|
112 if (debug_allocation > 1) \
|
|
113 { \
|
|
114 stderr_out ("allocating noseeum %s (size %ld)\n", type, (long)foosize); \
|
|
115 debug_allocation_backtrace (); \
|
|
116 } \
|
|
117 INCREMENT_CONS_COUNTER_1 (foosize); \
|
|
118 } while (0)
|
|
119 #else
|
|
120 #define INCREMENT_CONS_COUNTER(size, type) INCREMENT_CONS_COUNTER_1 (size)
|
|
121 #define NOSEEUM_INCREMENT_CONS_COUNTER(size, type) \
|
|
122 INCREMENT_CONS_COUNTER_1 (size)
|
|
123 #endif
|
|
124
|
|
125 #define DECREMENT_CONS_COUNTER(size) \
|
|
126 do { \
|
|
127 EMACS_INT __sz__ = ((EMACS_INT) (size)); \
|
|
128 if (consing_since_gc >= __sz__) \
|
|
129 consing_since_gc -= __sz__; \
|
|
130 else \
|
|
131 consing_since_gc = 0; \
|
|
132 } while (0)
|
|
133
|
|
134 /* Number of bytes of consing since gc before another gc should be done. */
|
|
135 EMACS_INT gc_cons_threshold;
|
|
136
|
|
137 /* Nonzero during gc */
|
|
138 int gc_in_progress;
|
|
139
|
|
140 /* Number of times GC has happened at this level or below.
|
|
141 * Level 0 is most volatile, contrary to usual convention.
|
|
142 * (Of course, there's only one level at present) */
|
|
143 EMACS_INT gc_generation_number[1];
|
|
144
|
|
145 /* This is just for use by the printer, to allow things to print uniquely */
|
|
146 static int lrecord_uid_counter;
|
|
147
|
|
148 /* Nonzero when calling certain hooks or doing other things where
|
|
149 a GC would be bad */
|
|
150 int gc_currently_forbidden;
|
|
151
|
|
152 /* Hooks. */
|
|
153 Lisp_Object Vpre_gc_hook, Qpre_gc_hook;
|
|
154 Lisp_Object Vpost_gc_hook, Qpost_gc_hook;
|
|
155
|
|
156 /* "Garbage collecting" */
|
|
157 Lisp_Object Vgc_message;
|
|
158 Lisp_Object Vgc_pointer_glyph;
|
|
159 static CONST char gc_default_message[] = "Garbage collecting";
|
|
160 Lisp_Object Qgarbage_collecting;
|
|
161
|
|
162 #ifndef VIRT_ADDR_VARIES
|
|
163 extern
|
|
164 #endif /* VIRT_ADDR_VARIES */
|
|
165 EMACS_INT malloc_sbrk_used;
|
|
166
|
|
167 #ifndef VIRT_ADDR_VARIES
|
|
168 extern
|
|
169 #endif /* VIRT_ADDR_VARIES */
|
|
170 EMACS_INT malloc_sbrk_unused;
|
|
171
|
|
172 /* Non-zero means defun should do purecopy on the function definition */
|
|
173 int purify_flag;
|
|
174
|
|
175 extern Lisp_Object pure[];/* moved to pure.c to speed incremental linking */
|
|
176
|
|
177 #define PUREBEG ((unsigned char *) pure)
|
|
178
|
|
179 /* Index in pure at which next pure object will be allocated. */
|
|
180 static long pureptr;
|
|
181
|
|
182 #define PURIFIED(ptr) \
|
165
|
183 ((uintptr_t) (ptr) < \
|
171
|
184 (uintptr_t) (PUREBEG + get_PURESIZE()) && \
|
165
|
185 (uintptr_t) (ptr) >= \
|
|
186 (uintptr_t) PUREBEG)
|
0
|
187
|
171
|
188 /* Non-zero if pureptr > get_PURESIZE(); accounts for excess purespace needs. */
|
0
|
189 static long pure_lossage;
|
|
190
|
|
191 #ifdef ERROR_CHECK_TYPECHECK
|
|
192
|
|
193 Error_behavior ERROR_ME, ERROR_ME_NOT, ERROR_ME_WARN;
|
|
194
|
|
195 #endif
|
|
196
|
|
197 int
|
|
198 purified (Lisp_Object obj)
|
|
199 {
|
173
|
200 return !POINTER_TYPE_P (XGCTYPE (obj)) ? 0 : PURIFIED (XPNTR (obj));
|
0
|
201 }
|
|
202
|
|
203 int
|
|
204 purespace_usage (void)
|
|
205 {
|
|
206 return (int) pureptr;
|
|
207 }
|
|
208
|
|
209 static int
|
|
210 check_purespace (EMACS_INT size)
|
|
211 {
|
|
212 if (pure_lossage)
|
|
213 {
|
|
214 pure_lossage += size;
|
173
|
215 return 0;
|
0
|
216 }
|
171
|
217 else if (pureptr + size > get_PURESIZE())
|
0
|
218 {
|
104
|
219 /* This can cause recursive bad behavior, we'll yell at the end */
|
|
220 /* when we're done. */
|
|
221 /* message ("\nERROR: Pure Lisp storage exhausted!\n"); */
|
0
|
222 pure_lossage = size;
|
173
|
223 return 0;
|
0
|
224 }
|
|
225 else
|
173
|
226 return 1;
|
0
|
227 }
|
|
228
|
|
229
|
|
230
|
|
231 #ifndef PURESTAT
|
|
232
|
|
233 #define bump_purestat(p,b) do {} while (0) /* Do nothing */
|
|
234
|
|
235 #else /* PURESTAT */
|
|
236
|
|
237 static int purecopying_for_bytecode;
|
|
238
|
|
239 static int pure_sizeof (Lisp_Object /*, int recurse */);
|
|
240
|
|
241 /* Keep statistics on how much of what is in purespace */
|
|
242 struct purestat
|
|
243 {
|
|
244 int nobjects;
|
|
245 int nbytes;
|
|
246 CONST char *name;
|
|
247 };
|
|
248
|
|
249 #define FMH(s,n) static struct purestat s = { 0, 0, n }
|
|
250 FMH (purestat_cons, "cons cells:");
|
|
251 FMH (purestat_float, "float objects:");
|
|
252 FMH (purestat_string_pname, "symbol-name strings:");
|
|
253 FMH (purestat_bytecode, "compiled-function objects:");
|
|
254 FMH (purestat_string_bytecodes, "byte-code strings:");
|
|
255 FMH (purestat_vector_bytecode_constants, "byte-constant vectors:");
|
|
256 FMH (purestat_string_interactive, "interactive strings:");
|
|
257 #ifdef I18N3
|
|
258 FMH (purestat_string_domain, "domain strings:");
|
|
259 #endif
|
|
260 FMH (purestat_string_documentation, "documentation strings:");
|
|
261 FMH (purestat_string_other_function, "other function strings:");
|
|
262 FMH (purestat_vector_other, "other vectors:");
|
|
263 FMH (purestat_string_other, "other strings:");
|
|
264 FMH (purestat_string_all, "all strings:");
|
|
265 FMH (purestat_vector_all, "all vectors:");
|
|
266
|
|
267 static struct purestat *purestats[] =
|
|
268 {
|
|
269 &purestat_cons,
|
|
270 &purestat_float,
|
|
271 &purestat_string_pname,
|
|
272 &purestat_bytecode,
|
|
273 &purestat_string_bytecodes,
|
|
274 &purestat_vector_bytecode_constants,
|
|
275 &purestat_string_interactive,
|
|
276 #ifdef I18N3
|
|
277 &purestat_string_domain,
|
|
278 #endif
|
|
279 &purestat_string_documentation,
|
|
280 &purestat_string_other_function,
|
|
281 &purestat_vector_other,
|
|
282 &purestat_string_other,
|
|
283 0,
|
|
284 &purestat_string_all,
|
|
285 &purestat_vector_all
|
|
286 };
|
|
287 #undef FMH
|
|
288
|
|
289 static void
|
|
290 bump_purestat (struct purestat *purestat, int nbytes)
|
|
291 {
|
|
292 if (pure_lossage) return;
|
|
293 purestat->nobjects += 1;
|
|
294 purestat->nbytes += nbytes;
|
|
295 }
|
|
296 #endif /* PURESTAT */
|
|
297
|
|
298
|
|
299 /* Maximum amount of C stack to save when a GC happens. */
|
|
300
|
|
301 #ifndef MAX_SAVE_STACK
|
|
302 #define MAX_SAVE_STACK 16000
|
|
303 #endif
|
|
304
|
|
305 /* Buffer in which we save a copy of the C stack at each GC. */
|
|
306
|
|
307 static char *stack_copy;
|
|
308 static int stack_copy_size;
|
|
309
|
|
310 /* Non-zero means ignore malloc warnings. Set during initialization. */
|
|
311 int ignore_malloc_warnings;
|
|
312
|
|
313
|
|
314 static void *breathing_space;
|
|
315
|
|
316 void
|
|
317 release_breathing_space (void)
|
|
318 {
|
|
319 if (breathing_space)
|
|
320 {
|
|
321 void *tmp = breathing_space;
|
|
322 breathing_space = 0;
|
|
323 xfree (tmp);
|
|
324 }
|
|
325 }
|
|
326
|
|
327 /* malloc calls this if it finds we are near exhausting storage */
|
|
328 void
|
|
329 malloc_warning (CONST char *str)
|
|
330 {
|
|
331 if (ignore_malloc_warnings)
|
|
332 return;
|
|
333
|
|
334 warn_when_safe
|
|
335 (Qmemory, Qcritical,
|
|
336 "%s\n"
|
|
337 "Killing some buffers may delay running out of memory.\n"
|
|
338 "However, certainly by the time you receive the 95%% warning,\n"
|
|
339 "you should clean up, kill this Emacs, and start a new one.",
|
|
340 str);
|
|
341 }
|
|
342
|
|
343 /* Called if malloc returns zero */
|
|
344 DOESNT_RETURN
|
|
345 memory_full (void)
|
|
346 {
|
|
347 /* Force a GC next time eval is called.
|
|
348 It's better to loop garbage-collecting (we might reclaim enough
|
|
349 to win) than to loop beeping and barfing "Memory exhausted"
|
|
350 */
|
|
351 consing_since_gc = gc_cons_threshold + 1;
|
|
352 release_breathing_space ();
|
|
353
|
|
354 #ifndef standalone
|
|
355 /* Flush some histories which might conceivably contain
|
|
356 * garbalogical inhibitors */
|
|
357 if (!NILP (Fboundp (Qvalues)))
|
|
358 Fset (Qvalues, Qnil);
|
|
359 Vcommand_history = Qnil;
|
|
360 #endif
|
|
361
|
|
362 error ("Memory exhausted");
|
|
363 }
|
|
364
|
|
365 /* like malloc and realloc but check for no memory left, and block input. */
|
|
366
|
|
367 void *
|
|
368 xmalloc (int size)
|
|
369 {
|
|
370 void *val;
|
|
371
|
|
372 val = (void *) malloc (size);
|
|
373
|
|
374 if (!val && (size != 0)) memory_full ();
|
|
375 return val;
|
|
376 }
|
|
377
|
|
378 void *
|
|
379 xmalloc_and_zero (int size)
|
|
380 {
|
|
381 void *val = xmalloc (size);
|
|
382 memset (val, 0, size);
|
|
383 return val;
|
|
384 }
|
|
385
|
|
386 void *
|
|
387 xrealloc (void *block, int size)
|
|
388 {
|
|
389 void *val;
|
|
390
|
|
391 /* We must call malloc explicitly when BLOCK is 0, since some
|
|
392 reallocs don't do this. */
|
|
393 if (! block)
|
|
394 val = (void *) malloc (size);
|
|
395 else
|
|
396 val = (void *) realloc (block, size);
|
|
397
|
|
398 if (!val && (size != 0)) memory_full ();
|
|
399 return val;
|
|
400 }
|
|
401
|
|
402 void
|
|
403 #ifdef ERROR_CHECK_MALLOC
|
|
404 xfree_1 (void *block)
|
|
405 #else
|
|
406 xfree (void *block)
|
|
407 #endif
|
|
408 {
|
|
409 #ifdef ERROR_CHECK_MALLOC
|
|
410 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an
|
|
411 error until much later on for many system mallocs, such as
|
|
412 the one that comes with Solaris 2.3. FMH!! */
|
|
413 assert (block != (void *) 0xDEADBEEF);
|
|
414 assert (block);
|
|
415 #endif
|
|
416 free (block);
|
|
417 }
|
|
418
|
|
419 #if INTBITS == 32
|
|
420 # define FOUR_BYTE_TYPE unsigned int
|
|
421 #elif LONGBITS == 32
|
|
422 # define FOUR_BYTE_TYPE unsigned long
|
|
423 #elif SHORTBITS == 32
|
|
424 # define FOUR_BYTE_TYPE unsigned short
|
|
425 #else
|
|
426 What kind of strange-ass system are we running on?
|
|
427 #endif
|
|
428
|
|
429 #ifdef ERROR_CHECK_GC
|
|
430
|
|
431 #ifdef WORDS_BIGENDIAN
|
|
432 static unsigned char deadbeef_as_char[] = {0xDE, 0xAD, 0xBE, 0xEF};
|
|
433 #else
|
|
434 static unsigned char deadbeef_as_char[] = {0xEF, 0xBE, 0xAD, 0xDE};
|
|
435 #endif
|
|
436
|
|
437 static void
|
|
438 deadbeef_memory (void *ptr, unsigned long size)
|
|
439 {
|
|
440 unsigned long long_length = size / sizeof (FOUR_BYTE_TYPE);
|
|
441 unsigned long i;
|
|
442 unsigned long bytes_left_over = size - sizeof (FOUR_BYTE_TYPE) * long_length;
|
|
443
|
|
444 for (i = 0; i < long_length; i++)
|
|
445 ((FOUR_BYTE_TYPE *) ptr)[i] = 0xdeadbeef;
|
|
446 for (i = i; i < bytes_left_over; i++)
|
|
447 ((unsigned char *) ptr + long_length)[i] = deadbeef_as_char[i];
|
|
448 }
|
|
449
|
|
450 #else
|
|
451
|
|
452 #define deadbeef_memory(ptr, size)
|
|
453
|
|
454 #endif
|
|
455
|
|
456 char *
|
|
457 xstrdup (CONST char *str)
|
|
458 {
|
|
459 char *val;
|
|
460 int len = strlen (str) + 1; /* for stupid terminating 0 */
|
|
461
|
|
462 val = xmalloc (len);
|
|
463 if (val == 0) return 0;
|
|
464 memcpy (val, str, len);
|
173
|
465 return val;
|
0
|
466 }
|
|
467
|
|
468 #ifdef NEED_STRDUP
|
|
469 char *
|
|
470 strdup (CONST char *s)
|
|
471 {
|
|
472 return xstrdup (s);
|
|
473 }
|
|
474 #endif /* NEED_STRDUP */
|
|
475
|
|
476
|
|
477 static void *
|
|
478 allocate_lisp_storage (int size)
|
|
479 {
|
|
480 void *p = xmalloc (size);
|
|
481 char *lim = ((char *) p) + size;
|
|
482 Lisp_Object val = Qnil;
|
|
483
|
|
484 XSETCONS (val, lim);
|
|
485 if ((char *) XCONS (val) != lim)
|
|
486 {
|
|
487 xfree (p);
|
|
488 memory_full ();
|
|
489 }
|
173
|
490 return p;
|
0
|
491 }
|
|
492
|
|
493
|
|
494 #define MARKED_RECORD_HEADER_P(lheader) \
|
|
495 (((lheader)->implementation->finalizer) == this_marks_a_marked_record)
|
|
496 #define UNMARKABLE_RECORD_HEADER_P(lheader) \
|
|
497 (((lheader)->implementation->marker) == this_one_is_unmarkable)
|
|
498 #define MARK_RECORD_HEADER(lheader) \
|
|
499 do { (((lheader)->implementation)++); } while (0)
|
|
500 #define UNMARK_RECORD_HEADER(lheader) \
|
|
501 do { (((lheader)->implementation)--); } while (0)
|
|
502
|
|
503
|
|
504 /* lrecords are chained together through their "next.v" field.
|
|
505 * After doing the mark phase, the GC will walk this linked
|
|
506 * list and free any record which hasn't been marked
|
|
507 */
|
|
508 static struct lcrecord_header *all_lcrecords;
|
|
509
|
|
510 void *
|
|
511 alloc_lcrecord (int size, CONST struct lrecord_implementation *implementation)
|
|
512 {
|
|
513 struct lcrecord_header *lcheader;
|
|
514
|
|
515 if (size <= 0) abort ();
|
|
516 if (implementation->static_size == 0)
|
|
517 {
|
|
518 if (!implementation->size_in_bytes_method)
|
|
519 abort ();
|
|
520 }
|
|
521 else if (implementation->static_size != size)
|
|
522 abort ();
|
|
523
|
|
524 lcheader = allocate_lisp_storage (size);
|
|
525 lcheader->lheader.implementation = implementation;
|
|
526 lcheader->next = all_lcrecords;
|
|
527 #if 1 /* mly prefers to see small ID numbers */
|
|
528 lcheader->uid = lrecord_uid_counter++;
|
|
529 #else /* jwz prefers to see real addrs */
|
|
530 lcheader->uid = (int) &lcheader;
|
|
531 #endif
|
|
532 lcheader->free = 0;
|
|
533 all_lcrecords = lcheader;
|
|
534 INCREMENT_CONS_COUNTER (size, implementation->name);
|
173
|
535 return lcheader;
|
0
|
536 }
|
|
537
|
|
538 #if 0 /* Presently unused */
|
|
539 /* Very, very poor man's EGC?
|
|
540 * This may be slow and thrash pages all over the place.
|
|
541 * Only call it if you really feel you must (and if the
|
|
542 * lrecord was fairly recently allocated).
|
|
543 * Otherwise, just let the GC do its job -- that's what it's there for
|
|
544 */
|
|
545 void
|
|
546 free_lcrecord (struct lcrecord_header *lcrecord)
|
|
547 {
|
|
548 if (all_lcrecords == lcrecord)
|
|
549 {
|
|
550 all_lcrecords = lcrecord->next;
|
|
551 }
|
|
552 else
|
|
553 {
|
|
554 struct lrecord_header *header = all_lcrecords;
|
|
555 for (;;)
|
|
556 {
|
|
557 struct lrecord_header *next = header->next;
|
|
558 if (next == lcrecord)
|
|
559 {
|
|
560 header->next = lrecord->next;
|
|
561 break;
|
|
562 }
|
|
563 else if (next == 0)
|
|
564 abort ();
|
|
565 else
|
|
566 header = next;
|
|
567 }
|
|
568 }
|
|
569 if (lrecord->implementation->finalizer)
|
|
570 ((lrecord->implementation->finalizer) (lrecord, 0));
|
|
571 xfree (lrecord);
|
|
572 return;
|
|
573 }
|
|
574 #endif /* Unused */
|
|
575
|
|
576
|
|
577 static void
|
|
578 disksave_object_finalization_1 (void)
|
|
579 {
|
|
580 struct lcrecord_header *header;
|
|
581
|
|
582 for (header = all_lcrecords; header; header = header->next)
|
|
583 {
|
|
584 if (header->lheader.implementation->finalizer && !header->free)
|
|
585 ((header->lheader.implementation->finalizer) (header, 1));
|
|
586 }
|
|
587 }
|
|
588
|
|
589
|
|
590 /* This must not be called -- it just serves as for EQ test
|
|
591 * If lheader->implementation->finalizer is this_marks_a_marked_record,
|
|
592 * then lrecord has been marked by the GC sweeper
|
|
593 * header->implementation is put back to its correct value by
|
|
594 * sweep_records */
|
|
595 void
|
|
596 this_marks_a_marked_record (void *dummy0, int dummy1)
|
|
597 {
|
|
598 abort ();
|
|
599 }
|
|
600
|
|
601 /* Semi-kludge -- lrecord_symbol_value_forward objects get stuck
|
|
602 in CONST space and you get SEGV's if you attempt to mark them.
|
|
603 This sits in lheader->implementation->marker. */
|
|
604
|
|
605 Lisp_Object
|
|
606 this_one_is_unmarkable (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
607 {
|
|
608 abort ();
|
|
609 return Qnil;
|
|
610 }
|
|
611
|
|
612 /* XGCTYPE for records */
|
|
613 int
|
|
614 gc_record_type_p (Lisp_Object frob, CONST struct lrecord_implementation *type)
|
|
615 {
|
|
616 return (XGCTYPE (frob) == Lisp_Record
|
|
617 && (XRECORD_LHEADER (frob)->implementation == type
|
|
618 || XRECORD_LHEADER (frob)->implementation == type + 1));
|
|
619 }
|
|
620
|
|
621
|
|
622 /**********************************************************************/
|
|
623 /* Fixed-size type macros */
|
|
624 /**********************************************************************/
|
|
625
|
|
626 /* For fixed-size types that are commonly used, we malloc() large blocks
|
|
627 of memory at a time and subdivide them into chunks of the correct
|
|
628 size for an object of that type. This is more efficient than
|
|
629 malloc()ing each object separately because we save on malloc() time
|
|
630 and overhead due to the fewer number of malloc()ed blocks, and
|
|
631 also because we don't need any extra pointers within each object
|
|
632 to keep them threaded together for GC purposes. For less common
|
|
633 (and frequently large-size) types, we use lcrecords, which are
|
|
634 malloc()ed individually and chained together through a pointer
|
|
635 in the lcrecord header. lcrecords do not need to be fixed-size
|
|
636 (i.e. two objects of the same type need not have the same size;
|
|
637 however, the size of a particular object cannot vary dynamically).
|
|
638 It is also much easier to create a new lcrecord type because no
|
|
639 additional code needs to be added to alloc.c. Finally, lcrecords
|
|
640 may be more efficient when there are only a small number of them.
|
|
641
|
|
642 The types that are stored in these large blocks (or "frob blocks")
|
|
643 are cons, float, compiled-function, symbol, marker, extent, event,
|
|
644 and string.
|
|
645
|
|
646 Note that strings are special in that they are actually stored in
|
|
647 two parts: a structure containing information about the string, and
|
|
648 the actual data associated with the string. The former structure
|
|
649 (a struct Lisp_String) is a fixed-size structure and is managed the
|
|
650 same way as all the other such types. This structure contains a
|
|
651 pointer to the actual string data, which is stored in structures of
|
|
652 type struct string_chars_block. Each string_chars_block consists
|
|
653 of a pointer to a struct Lisp_String, followed by the data for that
|
|
654 string, followed by another pointer to a struct Lisp_String,
|
|
655 followed by the data for that string, etc. At GC time, the data in
|
|
656 these blocks is compacted by searching sequentially through all the
|
|
657 blocks and compressing out any holes created by unmarked strings.
|
|
658 Strings that are more than a certain size (bigger than the size of
|
|
659 a string_chars_block, although something like half as big might
|
|
660 make more sense) are malloc()ed separately and not stored in
|
|
661 string_chars_blocks. Furthermore, no one string stretches across
|
|
662 two string_chars_blocks.
|
|
663
|
|
664 Vectors are each malloc()ed separately, similar to lcrecords.
|
|
665
|
|
666 In the following discussion, we use conses, but it applies equally
|
|
667 well to the other fixed-size types.
|
|
668
|
|
669 We store cons cells inside of cons_blocks, allocating a new
|
|
670 cons_block with malloc() whenever necessary. Cons cells reclaimed
|
|
671 by GC are put on a free list to be reallocated before allocating
|
|
672 any new cons cells from the latest cons_block. Each cons_block is
|
|
673 just under 2^n - MALLOC_OVERHEAD bytes long, since malloc (at least
|
|
674 the versions in malloc.c and gmalloc.c) really allocates in units
|
|
675 of powers of two and uses 4 bytes for its own overhead.
|
|
676
|
|
677 What GC actually does is to search through all the cons_blocks,
|
|
678 from the most recently allocated to the oldest, and put all
|
|
679 cons cells that are not marked (whether or not they're already
|
|
680 free) on a cons_free_list. The cons_free_list is a stack, and
|
|
681 so the cons cells in the oldest-allocated cons_block end up
|
|
682 at the head of the stack and are the first to be reallocated.
|
|
683 If any cons_block is entirely free, it is freed with free()
|
|
684 and its cons cells removed from the cons_free_list. Because
|
|
685 the cons_free_list ends up basically in memory order, we have
|
|
686 a high locality of reference (assuming a reasonable turnover
|
|
687 of allocating and freeing) and have a reasonable probability
|
|
688 of entirely freeing up cons_blocks that have been more recently
|
|
689 allocated. This stage is called the "sweep stage" of GC, and
|
|
690 is executed after the "mark stage", which involves starting
|
|
691 from all places that are known to point to in-use Lisp objects
|
|
692 (e.g. the obarray, where are all symbols are stored; the
|
|
693 current catches and condition-cases; the backtrace list of
|
|
694 currently executing functions; the gcpro list; etc.) and
|
|
695 recursively marking all objects that are accessible.
|
|
696
|
|
697 At the beginning of the sweep stage, the conses in the cons
|
|
698 blocks are in one of three states: in use and marked, in use
|
|
699 but not marked, and not in use (already freed). Any conses
|
|
700 that are marked have been marked in the mark stage just
|
|
701 executed, because as part of the sweep stage we unmark any
|
|
702 marked objects. The way we tell whether or not a cons cell
|
|
703 is in use is through the FREE_STRUCT_P macro. This basically
|
|
704 looks at the first 4 bytes (or however many bytes a pointer
|
|
705 fits in) to see if all the bits in those bytes are 1. The
|
|
706 resulting value (0xFFFFFFFF) is not a valid pointer and is
|
|
707 not a valid Lisp_Object. All current fixed-size types have
|
|
708 a pointer or Lisp_Object as their first element with the
|
|
709 exception of strings; they have a size value, which can
|
|
710 never be less than zero, and so 0xFFFFFFFF is invalid for
|
|
711 strings as well. Now assuming that a cons cell is in use,
|
|
712 the way we tell whether or not it is marked is to look at
|
|
713 the mark bit of its car (each Lisp_Object has one bit
|
|
714 reserved as a mark bit, in case it's needed). Note that
|
|
715 different types of objects use different fields to indicate
|
|
716 whether the object is marked, but the principle is the same.
|
|
717
|
|
718 Conses on the free_cons_list are threaded through a pointer
|
|
719 stored in the bytes directly after the bytes that are set
|
|
720 to 0xFFFFFFFF (we cannot overwrite these because the cons
|
|
721 is still in a cons_block and needs to remain marked as
|
|
722 not in use for the next time that GC happens). This
|
|
723 implies that all fixed-size types must be at least big
|
|
724 enough to store two pointers, which is indeed the case
|
|
725 for all current fixed-size types.
|
|
726
|
|
727 Some types of objects need additional "finalization" done
|
|
728 when an object is converted from in use to not in use;
|
|
729 this is the purpose of the ADDITIONAL_FREE_type macro.
|
|
730 For example, markers need to be removed from the chain
|
|
731 of markers that is kept in each buffer. This is because
|
|
732 markers in a buffer automatically disappear if the marker
|
|
733 is no longer referenced anywhere (the same does not
|
|
734 apply to extents, however).
|
|
735
|
|
736 WARNING: Things are in an extremely bizarre state when
|
|
737 the ADDITIONAL_FREE_type macros are called, so beware!
|
|
738
|
|
739 When ERROR_CHECK_GC is defined, we do things differently
|
|
740 so as to maximize our chances of catching places where
|
|
741 there is insufficient GCPROing. The thing we want to
|
|
742 avoid is having an object that we're using but didn't
|
|
743 GCPRO get freed by GC and then reallocated while we're
|
|
744 in the process of using it -- this will result in something
|
|
745 seemingly unrelated getting trashed, and is extremely
|
|
746 difficult to track down. If the object gets freed but
|
|
747 not reallocated, we can usually catch this because we
|
|
748 set all bytes of a freed object to 0xDEADBEEF. (The
|
|
749 first four bytes, however, are 0xFFFFFFFF, and the next
|
|
750 four are a pointer used to chain freed objects together;
|
|
751 we play some tricks with this pointer to make it more
|
|
752 bogus, so crashes are more likely to occur right away.)
|
|
753
|
|
754 We want freed objects to stay free as long as possible,
|
|
755 so instead of doing what we do above, we maintain the
|
|
756 free objects in a first-in first-out queue. We also
|
|
757 don't recompute the free list each GC, unlike above;
|
|
758 this ensures that the queue ordering is preserved.
|
|
759 [This means that we are likely to have worse locality
|
|
760 of reference, and that we can never free a frob block
|
|
761 once it's allocated. (Even if we know that all cells
|
|
762 in it are free, there's no easy way to remove all those
|
|
763 cells from the free list because the objects on the
|
|
764 free list are unlikely to be in memory order.)]
|
|
765 Furthermore, we never take objects off the free list
|
|
766 unless there's a large number (usually 1000, but
|
|
767 varies depending on type) of them already on the list.
|
|
768 This way, we ensure that an object that gets freed will
|
|
769 remain free for the next 1000 (or whatever) times that
|
|
770 an object of that type is allocated.
|
|
771 */
|
|
772
|
|
773 #ifndef MALLOC_OVERHEAD
|
|
774 #ifdef GNU_MALLOC
|
|
775 #define MALLOC_OVERHEAD 0
|
|
776 #elif defined (rcheck)
|
|
777 #define MALLOC_OVERHEAD 20
|
|
778 #else
|
|
779 #define MALLOC_OVERHEAD 8
|
|
780 #endif
|
|
781 #endif
|
|
782
|
|
783 #ifdef ALLOC_NO_POOLS
|
|
784 # define TYPE_ALLOC_SIZE(type, structtype) 1
|
|
785 #else
|
|
786 # define TYPE_ALLOC_SIZE(type, structtype) \
|
|
787 ((2048 - MALLOC_OVERHEAD - sizeof (struct type##_block *)) \
|
|
788 / sizeof (structtype))
|
|
789 #endif
|
|
790
|
|
791 #define DECLARE_FIXED_TYPE_ALLOC(type, structtype) \
|
|
792 \
|
|
793 struct type##_block \
|
|
794 { \
|
|
795 struct type##_block *prev; \
|
|
796 structtype block[TYPE_ALLOC_SIZE (type, structtype)]; \
|
|
797 }; \
|
|
798 \
|
|
799 static struct type##_block *current_##type##_block; \
|
|
800 static int current_##type##_block_index; \
|
|
801 \
|
|
802 static structtype *type##_free_list; \
|
|
803 static structtype *type##_free_list_tail; \
|
|
804 \
|
|
805 static void \
|
|
806 init_##type##_alloc (void) \
|
|
807 { \
|
|
808 current_##type##_block = 0; \
|
|
809 current_##type##_block_index = countof (current_##type##_block->block); \
|
|
810 type##_free_list = 0; \
|
|
811 type##_free_list_tail = 0; \
|
|
812 } \
|
|
813 \
|
|
814 static int gc_count_num_##type##_in_use, gc_count_num_##type##_freelist
|
|
815
|
|
816 #define ALLOCATE_FIXED_TYPE_FROM_BLOCK(type, result) \
|
|
817 do { \
|
|
818 if (current_##type##_block_index \
|
|
819 == countof (current_##type##_block->block)) \
|
|
820 { \
|
|
821 struct type##_block *__new__ \
|
|
822 = allocate_lisp_storage (sizeof (struct type##_block)); \
|
|
823 __new__->prev = current_##type##_block; \
|
|
824 current_##type##_block = __new__; \
|
|
825 current_##type##_block_index = 0; \
|
|
826 } \
|
|
827 (result) = \
|
|
828 &(current_##type##_block->block[current_##type##_block_index++]); \
|
|
829 } while (0)
|
|
830
|
|
831 /* Allocate an instance of a type that is stored in blocks.
|
|
832 TYPE is the "name" of the type, STRUCTTYPE is the corresponding
|
|
833 structure type. */
|
|
834
|
|
835 #ifdef ERROR_CHECK_GC
|
|
836
|
|
837 /* Note: if you get crashes in this function, suspect incorrect calls
|
|
838 to free_cons() and friends. This happened once because the cons
|
|
839 cell was not GC-protected and was getting collected before
|
|
840 free_cons() was called. */
|
|
841
|
|
842 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) \
|
|
843 do \
|
|
844 { \
|
|
845 if (gc_count_num_##type##_freelist > \
|
|
846 MINIMUM_ALLOWED_FIXED_TYPE_CELLS_##type) \
|
|
847 { \
|
|
848 result = type##_free_list; \
|
|
849 /* Before actually using the chain pointer, we complement all its \
|
|
850 bits; see FREE_FIXED_TYPE(). */ \
|
|
851 type##_free_list = \
|
|
852 (structtype *) ~(unsigned long) \
|
|
853 (* (structtype **) ((char *) result + sizeof (void *))); \
|
|
854 gc_count_num_##type##_freelist--; \
|
|
855 } \
|
|
856 else \
|
|
857 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \
|
|
858 MARK_STRUCT_AS_NOT_FREE (result); \
|
|
859 } while (0)
|
|
860
|
|
861 #else
|
|
862
|
|
863 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) \
|
|
864 do \
|
|
865 { \
|
|
866 if (type##_free_list) \
|
|
867 { \
|
|
868 result = type##_free_list; \
|
|
869 type##_free_list = \
|
|
870 * (structtype **) ((char *) result + sizeof (void *)); \
|
|
871 } \
|
|
872 else \
|
|
873 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \
|
|
874 MARK_STRUCT_AS_NOT_FREE (result); \
|
|
875 } while (0)
|
|
876
|
|
877 #endif
|
|
878
|
|
879 #define ALLOCATE_FIXED_TYPE(type, structtype, result) \
|
|
880 do \
|
|
881 { \
|
|
882 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \
|
|
883 INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \
|
|
884 } while (0)
|
|
885
|
|
886 #define NOSEEUM_ALLOCATE_FIXED_TYPE(type, structtype, result) \
|
|
887 do \
|
|
888 { \
|
|
889 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \
|
|
890 NOSEEUM_INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \
|
|
891 } while (0)
|
|
892
|
|
893 /* INVALID_POINTER_VALUE should be a value that is invalid as a pointer
|
|
894 to a Lisp object and invalid as an actual Lisp_Object value. We have
|
|
895 to make sure that this value cannot be an integer in Lisp_Object form.
|
|
896 0xFFFFFFFF could be so on a 64-bit system, so we extend it to 64 bits.
|
|
897 On a 32-bit system, the type bits will be non-zero, making the value
|
|
898 be a pointer, and the pointer will be misaligned.
|
|
899
|
|
900 Even if Emacs is run on some weirdo system that allows and allocates
|
|
901 byte-aligned pointers, this pointer is at the very top of the address
|
|
902 space and so it's almost inconceivable that it could ever be valid. */
|
|
903
|
|
904 #if INTBITS == 32
|
|
905 # define INVALID_POINTER_VALUE 0xFFFFFFFF
|
|
906 #elif INTBITS == 48
|
|
907 # define INVALID_POINTER_VALUE 0xFFFFFFFFFFFF
|
|
908 #elif INTBITS == 64
|
|
909 # define INVALID_POINTER_VALUE 0xFFFFFFFFFFFFFFFF
|
|
910 #else
|
|
911 You have some weird system and need to supply a reasonable value here.
|
|
912 #endif
|
|
913
|
|
914 #define FREE_STRUCT_P(ptr) \
|
|
915 (* (void **) ptr == (void *) INVALID_POINTER_VALUE)
|
|
916 #define MARK_STRUCT_AS_FREE(ptr) \
|
|
917 (* (void **) ptr = (void *) INVALID_POINTER_VALUE)
|
|
918 #define MARK_STRUCT_AS_NOT_FREE(ptr) \
|
|
919 (* (void **) ptr = 0)
|
|
920
|
|
921 #ifdef ERROR_CHECK_GC
|
|
922
|
|
923 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) \
|
|
924 do { if (type##_free_list_tail) \
|
|
925 { \
|
|
926 /* When we store the chain pointer, we complement all \
|
|
927 its bits; this should significantly increase its \
|
|
928 bogosity in case someone tries to use the value, and \
|
|
929 should make us dump faster if someone stores something \
|
|
930 over the pointer because when it gets un-complemented in \
|
|
931 ALLOCATED_FIXED_TYPE(), the resulting pointer will be \
|
|
932 extremely bogus. */ \
|
|
933 * (structtype **) \
|
|
934 ((char *) type##_free_list_tail + sizeof (void *)) = \
|
|
935 (structtype *) ~(unsigned long) ptr; \
|
|
936 } \
|
|
937 else \
|
|
938 type##_free_list = ptr; \
|
|
939 type##_free_list_tail = ptr; \
|
|
940 } while (0)
|
|
941
|
|
942 #else
|
|
943
|
|
944 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) \
|
|
945 do { * (structtype **) ((char *) ptr + sizeof (void *)) = \
|
|
946 type##_free_list; \
|
|
947 type##_free_list = ptr; \
|
|
948 } while (0)
|
|
949
|
|
950 #endif
|
|
951
|
|
952 /* TYPE and STRUCTTYPE are the same as in ALLOCATE_FIXED_TYPE(). */
|
|
953
|
|
954 #define FREE_FIXED_TYPE(type, structtype, ptr) \
|
|
955 do { structtype *_weird_ = (ptr); \
|
|
956 ADDITIONAL_FREE_##type (_weird_); \
|
|
957 deadbeef_memory (ptr, sizeof (structtype)); \
|
|
958 PUT_FIXED_TYPE_ON_FREE_LIST (type, structtype, ptr); \
|
|
959 MARK_STRUCT_AS_FREE (_weird_); \
|
|
960 } while (0)
|
|
961
|
|
962 /* Like FREE_FIXED_TYPE() but used when we are explicitly
|
|
963 freeing a structure through free_cons(), free_marker(), etc.
|
|
964 rather than through the normal process of sweeping.
|
|
965 We attempt to undo the changes made to the allocation counters
|
|
966 as a result of this structure being allocated. This is not
|
|
967 completely necessary but helps keep things saner: e.g. this way,
|
|
968 repeatedly allocating and freeing a cons will not result in
|
|
969 the consing-since-gc counter advancing, which would cause a GC
|
|
970 and somewhat defeat the purpose of explicitly freeing. */
|
|
971
|
|
972 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(type, structtype, ptr) \
|
|
973 do { FREE_FIXED_TYPE (type, structtype, ptr); \
|
|
974 DECREMENT_CONS_COUNTER (sizeof (structtype)); \
|
|
975 gc_count_num_##type##_freelist++; \
|
|
976 } while (0)
|
|
977
|
|
978
|
|
979
|
|
980 /**********************************************************************/
|
|
981 /* Cons allocation */
|
|
982 /**********************************************************************/
|
|
983
|
|
984 DECLARE_FIXED_TYPE_ALLOC (cons, struct Lisp_Cons);
|
|
985 /* conses are used and freed so often that we set this really high */
|
|
986 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 20000 */
|
|
987 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 2000
|
|
988
|
20
|
989 DEFUN ("cons", Fcons, 2, 2, 0, /*
|
0
|
990 Create a new cons, give it CAR and CDR as components, and return it.
|
20
|
991 */
|
|
992 (car, cdr))
|
0
|
993 {
|
|
994 /* This cannot GC. */
|
|
995 Lisp_Object val = Qnil;
|
|
996 struct Lisp_Cons *c;
|
|
997
|
|
998 ALLOCATE_FIXED_TYPE (cons, struct Lisp_Cons, c);
|
|
999 XSETCONS (val, c);
|
|
1000 XCAR (val) = car;
|
|
1001 XCDR (val) = cdr;
|
|
1002 return val;
|
|
1003 }
|
|
1004
|
|
1005 /* This is identical to Fcons() but it used for conses that we're
|
|
1006 going to free later, and is useful when trying to track down
|
|
1007 "real" consing. */
|
|
1008 Lisp_Object
|
|
1009 noseeum_cons (Lisp_Object car, Lisp_Object cdr)
|
|
1010 {
|
|
1011 Lisp_Object val = Qnil;
|
|
1012 struct Lisp_Cons *c;
|
|
1013
|
|
1014 NOSEEUM_ALLOCATE_FIXED_TYPE (cons, struct Lisp_Cons, c);
|
|
1015 XSETCONS (val, c);
|
|
1016 XCAR (val) = car;
|
|
1017 XCDR (val) = cdr;
|
|
1018 return val;
|
|
1019 }
|
|
1020
|
20
|
1021 DEFUN ("list", Flist, 0, MANY, 0, /*
|
0
|
1022 Return a newly created list with specified arguments as elements.
|
|
1023 Any number of arguments, even zero arguments, are allowed.
|
20
|
1024 */
|
|
1025 (int nargs, Lisp_Object *args))
|
0
|
1026 {
|
165
|
1027 Lisp_Object val = Qnil;
|
|
1028 Lisp_Object *argp = args + nargs;
|
|
1029
|
|
1030 while (nargs-- > 0)
|
|
1031 val = Fcons (*--argp, val);
|
0
|
1032 return val;
|
|
1033 }
|
|
1034
|
|
1035 Lisp_Object
|
|
1036 list1 (Lisp_Object obj0)
|
|
1037 {
|
|
1038 /* This cannot GC. */
|
173
|
1039 return Fcons (obj0, Qnil);
|
0
|
1040 }
|
|
1041
|
|
1042 Lisp_Object
|
|
1043 list2 (Lisp_Object obj0, Lisp_Object obj1)
|
|
1044 {
|
|
1045 /* This cannot GC. */
|
|
1046 return Fcons (obj0, list1 (obj1));
|
|
1047 }
|
|
1048
|
|
1049 Lisp_Object
|
|
1050 list3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
|
|
1051 {
|
|
1052 /* This cannot GC. */
|
|
1053 return Fcons (obj0, list2 (obj1, obj2));
|
|
1054 }
|
|
1055
|
|
1056 static Lisp_Object
|
|
1057 cons3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
|
|
1058 {
|
|
1059 /* This cannot GC. */
|
|
1060 return Fcons (obj0, Fcons (obj1, obj2));
|
|
1061 }
|
|
1062
|
|
1063 Lisp_Object
|
|
1064 list4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3)
|
|
1065 {
|
|
1066 /* This cannot GC. */
|
|
1067 return Fcons (obj0, list3 (obj1, obj2, obj3));
|
|
1068 }
|
|
1069
|
|
1070 Lisp_Object
|
|
1071 list5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3,
|
|
1072 Lisp_Object obj4)
|
|
1073 {
|
|
1074 /* This cannot GC. */
|
|
1075 return Fcons (obj0, list4 (obj1, obj2, obj3, obj4));
|
|
1076 }
|
|
1077
|
|
1078 Lisp_Object
|
|
1079 list6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3,
|
|
1080 Lisp_Object obj4, Lisp_Object obj5)
|
|
1081 {
|
|
1082 /* This cannot GC. */
|
|
1083 return Fcons (obj0, list5 (obj1, obj2, obj3, obj4, obj5));
|
|
1084 }
|
|
1085
|
20
|
1086 DEFUN ("make-list", Fmake_list, 2, 2, 0, /*
|
0
|
1087 Return a newly created list of length LENGTH, with each element being INIT.
|
20
|
1088 */
|
|
1089 (length, init))
|
0
|
1090 {
|
|
1091 Lisp_Object val;
|
|
1092 int size;
|
|
1093
|
|
1094 CHECK_NATNUM (length);
|
|
1095 size = XINT (length);
|
|
1096
|
|
1097 val = Qnil;
|
|
1098 while (size-- > 0)
|
|
1099 val = Fcons (init, val);
|
|
1100 return val;
|
|
1101 }
|
|
1102
|
|
1103
|
|
1104 /**********************************************************************/
|
|
1105 /* Float allocation */
|
|
1106 /**********************************************************************/
|
|
1107
|
|
1108 #ifdef LISP_FLOAT_TYPE
|
|
1109
|
|
1110 DECLARE_FIXED_TYPE_ALLOC (float, struct Lisp_Float);
|
|
1111 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_float 1000
|
|
1112
|
|
1113 Lisp_Object
|
|
1114 make_float (double float_value)
|
|
1115 {
|
|
1116 Lisp_Object val;
|
|
1117 struct Lisp_Float *f;
|
|
1118
|
|
1119 ALLOCATE_FIXED_TYPE (float, struct Lisp_Float, f);
|
|
1120 f->lheader.implementation = lrecord_float;
|
|
1121 float_next (f) = ((struct Lisp_Float *) -1);
|
|
1122 float_data (f) = float_value;
|
|
1123 XSETFLOAT (val, f);
|
173
|
1124 return val;
|
0
|
1125 }
|
|
1126
|
|
1127 #endif /* LISP_FLOAT_TYPE */
|
|
1128
|
|
1129
|
|
1130 /**********************************************************************/
|
|
1131 /* Vector allocation */
|
|
1132 /**********************************************************************/
|
|
1133
|
|
1134 static Lisp_Object all_vectors;
|
|
1135
|
|
1136 /* #### should allocate `small' vectors from a frob-block */
|
|
1137 static struct Lisp_Vector *
|
|
1138 make_vector_internal (EMACS_INT sizei)
|
|
1139 {
|
|
1140 EMACS_INT sizem = (sizeof (struct Lisp_Vector)
|
|
1141 /* -1 because struct Lisp_Vector includes 1 slot,
|
|
1142 * +1 to account for vector_next */
|
|
1143 + (sizei - 1 + 1) * sizeof (Lisp_Object)
|
|
1144 );
|
|
1145 struct Lisp_Vector *p = allocate_lisp_storage (sizem);
|
|
1146 #ifdef LRECORD_VECTOR
|
|
1147 set_lheader_implementation (&(p->lheader), lrecord_vector);
|
|
1148 #endif
|
|
1149
|
|
1150 INCREMENT_CONS_COUNTER (sizem, "vector");
|
|
1151
|
|
1152 p->size = sizei;
|
|
1153 vector_next (p) = all_vectors;
|
|
1154 XSETVECTOR (all_vectors, p);
|
173
|
1155 return p;
|
0
|
1156 }
|
|
1157
|
|
1158 Lisp_Object
|
|
1159 make_vector (EMACS_INT length, Lisp_Object init)
|
|
1160 {
|
|
1161 EMACS_INT elt;
|
|
1162 Lisp_Object vector = Qnil;
|
|
1163 struct Lisp_Vector *p;
|
|
1164
|
|
1165 if (length < 0)
|
|
1166 length = XINT (wrong_type_argument (Qnatnump, make_int (length)));
|
|
1167
|
|
1168 p = make_vector_internal (length);
|
|
1169 XSETVECTOR (vector, p);
|
|
1170
|
|
1171 #if 0
|
|
1172 /* Initialize big arrays full of 0's quickly, for what that's worth */
|
|
1173 {
|
|
1174 char *travesty = (char *) &init;
|
|
1175 for (i = 1; i < sizeof (Lisp_Object); i++)
|
|
1176 {
|
|
1177 if (travesty[i] != travesty[0])
|
|
1178 goto fill;
|
|
1179 }
|
|
1180 memset (vector_data (p), travesty[0], length * sizeof (Lisp_Object));
|
173
|
1181 return vector;
|
0
|
1182 }
|
|
1183 fill:
|
|
1184 #endif
|
|
1185 for (elt = 0; elt < length; elt++)
|
|
1186 vector_data(p)[elt] = init;
|
|
1187
|
173
|
1188 return vector;
|
0
|
1189 }
|
|
1190
|
20
|
1191 DEFUN ("make-vector", Fmake_vector, 2, 2, 0, /*
|
0
|
1192 Return a newly created vector of length LENGTH, with each element being INIT.
|
|
1193 See also the function `vector'.
|
20
|
1194 */
|
|
1195 (length, init))
|
0
|
1196 {
|
|
1197 if (!INTP (length) || XINT (length) < 0)
|
|
1198 length = wrong_type_argument (Qnatnump, length);
|
|
1199
|
173
|
1200 return make_vector (XINT (length), init);
|
0
|
1201 }
|
|
1202
|
20
|
1203 DEFUN ("vector", Fvector, 0, MANY, 0, /*
|
0
|
1204 Return a newly created vector with specified arguments as elements.
|
|
1205 Any number of arguments, even zero arguments, are allowed.
|
20
|
1206 */
|
|
1207 (int nargs, Lisp_Object *args))
|
0
|
1208 {
|
|
1209 Lisp_Object vector = Qnil;
|
|
1210 int elt;
|
|
1211 struct Lisp_Vector *p;
|
|
1212
|
|
1213 p = make_vector_internal (nargs);
|
|
1214 XSETVECTOR (vector, p);
|
|
1215
|
|
1216 for (elt = 0; elt < nargs; elt++)
|
|
1217 vector_data(p)[elt] = args[elt];
|
|
1218
|
173
|
1219 return vector;
|
0
|
1220 }
|
|
1221
|
|
1222 Lisp_Object
|
|
1223 vector1 (Lisp_Object obj0)
|
|
1224 {
|
|
1225 return Fvector (1, &obj0);
|
|
1226 }
|
|
1227
|
|
1228 Lisp_Object
|
|
1229 vector2 (Lisp_Object obj0, Lisp_Object obj1)
|
|
1230 {
|
|
1231 Lisp_Object args[2];
|
|
1232 args[0] = obj0;
|
|
1233 args[1] = obj1;
|
|
1234 return Fvector (2, args);
|
|
1235 }
|
|
1236
|
|
1237 Lisp_Object
|
|
1238 vector3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
|
|
1239 {
|
|
1240 Lisp_Object args[3];
|
|
1241 args[0] = obj0;
|
|
1242 args[1] = obj1;
|
|
1243 args[2] = obj2;
|
|
1244 return Fvector (3, args);
|
|
1245 }
|
|
1246
|
|
1247 Lisp_Object
|
|
1248 vector4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1249 Lisp_Object obj3)
|
|
1250 {
|
|
1251 Lisp_Object args[4];
|
|
1252 args[0] = obj0;
|
|
1253 args[1] = obj1;
|
|
1254 args[2] = obj2;
|
|
1255 args[3] = obj3;
|
|
1256 return Fvector (4, args);
|
|
1257 }
|
|
1258
|
|
1259 Lisp_Object
|
|
1260 vector5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1261 Lisp_Object obj3, Lisp_Object obj4)
|
|
1262 {
|
|
1263 Lisp_Object args[5];
|
|
1264 args[0] = obj0;
|
|
1265 args[1] = obj1;
|
|
1266 args[2] = obj2;
|
|
1267 args[3] = obj3;
|
|
1268 args[4] = obj4;
|
|
1269 return Fvector (5, args);
|
|
1270 }
|
|
1271
|
|
1272 Lisp_Object
|
|
1273 vector6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1274 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5)
|
|
1275 {
|
|
1276 Lisp_Object args[6];
|
|
1277 args[0] = obj0;
|
|
1278 args[1] = obj1;
|
|
1279 args[2] = obj2;
|
|
1280 args[3] = obj3;
|
|
1281 args[4] = obj4;
|
|
1282 args[5] = obj5;
|
|
1283 return Fvector (6, args);
|
|
1284 }
|
|
1285
|
|
1286 Lisp_Object
|
|
1287 vector7 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1288 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5,
|
|
1289 Lisp_Object obj6)
|
|
1290 {
|
|
1291 Lisp_Object args[7];
|
|
1292 args[0] = obj0;
|
|
1293 args[1] = obj1;
|
|
1294 args[2] = obj2;
|
|
1295 args[3] = obj3;
|
|
1296 args[4] = obj4;
|
|
1297 args[5] = obj5;
|
|
1298 args[6] = obj6;
|
|
1299 return Fvector (7, args);
|
|
1300 }
|
|
1301
|
|
1302 Lisp_Object
|
|
1303 vector8 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1304 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5,
|
|
1305 Lisp_Object obj6, Lisp_Object obj7)
|
|
1306 {
|
|
1307 Lisp_Object args[8];
|
|
1308 args[0] = obj0;
|
|
1309 args[1] = obj1;
|
|
1310 args[2] = obj2;
|
|
1311 args[3] = obj3;
|
|
1312 args[4] = obj4;
|
|
1313 args[5] = obj5;
|
|
1314 args[6] = obj6;
|
|
1315 args[7] = obj7;
|
|
1316 return Fvector (8, args);
|
|
1317 }
|
|
1318
|
|
1319 /**********************************************************************/
|
|
1320 /* Bit Vector allocation */
|
|
1321 /**********************************************************************/
|
|
1322
|
|
1323 static Lisp_Object all_bit_vectors;
|
|
1324
|
|
1325 /* #### should allocate `small' bit vectors from a frob-block */
|
|
1326 static struct Lisp_Bit_Vector *
|
|
1327 make_bit_vector_internal (EMACS_INT sizei)
|
|
1328 {
|
|
1329 EMACS_INT sizem = (sizeof (struct Lisp_Bit_Vector) +
|
|
1330 /* -1 because struct Lisp_Bit_Vector includes 1 slot */
|
|
1331 sizeof (long) * (BIT_VECTOR_LONG_STORAGE (sizei) - 1));
|
|
1332 struct Lisp_Bit_Vector *p = allocate_lisp_storage (sizem);
|
|
1333 set_lheader_implementation (&(p->lheader), lrecord_bit_vector);
|
|
1334
|
|
1335 INCREMENT_CONS_COUNTER (sizem, "bit-vector");
|
|
1336
|
|
1337 bit_vector_length (p) = sizei;
|
|
1338 bit_vector_next (p) = all_bit_vectors;
|
|
1339 /* make sure the extra bits in the last long are 0; the calling
|
|
1340 functions might not set them. */
|
|
1341 p->bits[BIT_VECTOR_LONG_STORAGE (sizei) - 1] = 0;
|
|
1342 XSETBIT_VECTOR (all_bit_vectors, p);
|
173
|
1343 return p;
|
0
|
1344 }
|
|
1345
|
|
1346 Lisp_Object
|
|
1347 make_bit_vector (EMACS_INT length, Lisp_Object init)
|
|
1348 {
|
|
1349 Lisp_Object bit_vector = Qnil;
|
|
1350 struct Lisp_Bit_Vector *p;
|
|
1351 EMACS_INT num_longs;
|
|
1352
|
|
1353 if (length < 0)
|
|
1354 length = XINT (wrong_type_argument (Qnatnump, make_int (length)));
|
|
1355
|
|
1356 CHECK_BIT (init);
|
|
1357
|
|
1358 num_longs = BIT_VECTOR_LONG_STORAGE (length);
|
|
1359 p = make_bit_vector_internal (length);
|
|
1360 XSETBIT_VECTOR (bit_vector, p);
|
|
1361
|
|
1362 if (ZEROP (init))
|
|
1363 memset (p->bits, 0, num_longs * sizeof (long));
|
|
1364 else
|
|
1365 {
|
|
1366 EMACS_INT bits_in_last = length & (LONGBITS_POWER_OF_2 - 1);
|
|
1367 memset (p->bits, ~0, num_longs * sizeof (long));
|
|
1368 /* But we have to make sure that the unused bits in the
|
|
1369 last integer are 0, so that equal/hash is easy. */
|
|
1370 if (bits_in_last)
|
|
1371 p->bits[num_longs - 1] &= (1 << bits_in_last) - 1;
|
|
1372 }
|
|
1373
|
173
|
1374 return bit_vector;
|
0
|
1375 }
|
|
1376
|
|
1377 Lisp_Object
|
|
1378 make_bit_vector_from_byte_vector (unsigned char *bytevec, EMACS_INT length)
|
|
1379 {
|
|
1380 Lisp_Object bit_vector = Qnil;
|
|
1381 struct Lisp_Bit_Vector *p;
|
|
1382 EMACS_INT i;
|
|
1383
|
|
1384 if (length < 0)
|
|
1385 length = XINT (wrong_type_argument (Qnatnump, make_int (length)));
|
|
1386
|
|
1387 p = make_bit_vector_internal (length);
|
|
1388 XSETBIT_VECTOR (bit_vector, p);
|
|
1389
|
|
1390 for (i = 0; i < length; i++)
|
|
1391 set_bit_vector_bit (p, i, bytevec[i]);
|
|
1392
|
|
1393 return bit_vector;
|
|
1394 }
|
|
1395
|
20
|
1396 DEFUN ("make-bit-vector", Fmake_bit_vector, 2, 2, 0, /*
|
0
|
1397 Return a newly created bit vector of length LENGTH.
|
|
1398 Each element is set to INIT. See also the function `bit-vector'.
|
20
|
1399 */
|
|
1400 (length, init))
|
0
|
1401 {
|
|
1402 if (!INTP (length) || XINT (length) < 0)
|
|
1403 length = wrong_type_argument (Qnatnump, length);
|
|
1404
|
173
|
1405 return make_bit_vector (XINT (length), init);
|
0
|
1406 }
|
|
1407
|
20
|
1408 DEFUN ("bit-vector", Fbit_vector, 0, MANY, 0, /*
|
0
|
1409 Return a newly created bit vector with specified arguments as elements.
|
|
1410 Any number of arguments, even zero arguments, are allowed.
|
20
|
1411 */
|
|
1412 (int nargs, Lisp_Object *args))
|
0
|
1413 {
|
|
1414 Lisp_Object bit_vector = Qnil;
|
|
1415 int elt;
|
|
1416 struct Lisp_Bit_Vector *p;
|
|
1417
|
|
1418 for (elt = 0; elt < nargs; elt++)
|
|
1419 CHECK_BIT (args[elt]);
|
|
1420
|
|
1421 p = make_bit_vector_internal (nargs);
|
|
1422 XSETBIT_VECTOR (bit_vector, p);
|
|
1423
|
|
1424 for (elt = 0; elt < nargs; elt++)
|
|
1425 set_bit_vector_bit (p, elt, !ZEROP (args[elt]));
|
|
1426
|
173
|
1427 return bit_vector;
|
0
|
1428 }
|
|
1429
|
|
1430
|
|
1431 /**********************************************************************/
|
|
1432 /* Compiled-function allocation */
|
|
1433 /**********************************************************************/
|
|
1434
|
|
1435 DECLARE_FIXED_TYPE_ALLOC (compiled_function, struct Lisp_Compiled_Function);
|
|
1436 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_compiled_function 1000
|
|
1437
|
|
1438 static Lisp_Object
|
|
1439 make_compiled_function (int make_pure)
|
|
1440 {
|
|
1441 struct Lisp_Compiled_Function *b;
|
|
1442 Lisp_Object new;
|
|
1443 int size = sizeof (struct Lisp_Compiled_Function);
|
|
1444
|
|
1445 if (make_pure && check_purespace (size))
|
|
1446 {
|
|
1447 b = (struct Lisp_Compiled_Function *) (PUREBEG + pureptr);
|
|
1448 set_lheader_implementation (&(b->lheader), lrecord_compiled_function);
|
|
1449 pureptr += size;
|
|
1450 bump_purestat (&purestat_bytecode, size);
|
|
1451 }
|
|
1452 else
|
|
1453 {
|
|
1454 ALLOCATE_FIXED_TYPE (compiled_function, struct Lisp_Compiled_Function,
|
|
1455 b);
|
|
1456 set_lheader_implementation (&(b->lheader), lrecord_compiled_function);
|
|
1457 }
|
|
1458 b->maxdepth = 0;
|
|
1459 b->flags.documentationp = 0;
|
|
1460 b->flags.interactivep = 0;
|
|
1461 b->flags.domainp = 0; /* I18N3 */
|
|
1462 b->bytecodes = Qzero;
|
|
1463 b->constants = Qzero;
|
|
1464 b->arglist = Qnil;
|
|
1465 b->doc_and_interactive = Qnil;
|
|
1466 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1467 b->annotated = Qnil;
|
|
1468 #endif
|
|
1469 XSETCOMPILED_FUNCTION (new, b);
|
173
|
1470 return new;
|
0
|
1471 }
|
|
1472
|
20
|
1473 DEFUN ("make-byte-code", Fmake_byte_code, 4, MANY, 0, /*
|
0
|
1474 Create a compiled-function object.
|
|
1475 Usage: (arglist instructions constants stack-size
|
|
1476 &optional doc-string interactive-spec)
|
|
1477 Note that, unlike all other emacs-lisp functions, calling this with five
|
|
1478 arguments is NOT the same as calling it with six arguments, the last of
|
|
1479 which is nil. If the INTERACTIVE arg is specified as nil, then that means
|
|
1480 that this function was defined with `(interactive)'. If the arg is not
|
|
1481 specified, then that means the function is not interactive.
|
|
1482 This is terrible behavior which is retained for compatibility with old
|
|
1483 `.elc' files which expected these semantics.
|
20
|
1484 */
|
|
1485 (int nargs, Lisp_Object *args))
|
0
|
1486 {
|
|
1487 /* In a non-insane world this function would have this arglist...
|
|
1488 (arglist, instructions, constants, stack_size, doc_string, interactive)
|
|
1489 Lisp_Object arglist, instructions, constants, stack_size, doc_string,
|
|
1490 interactive;
|
|
1491 */
|
|
1492 Lisp_Object arglist = args[0];
|
|
1493 Lisp_Object instructions = args[1];
|
|
1494 Lisp_Object constants = args[2];
|
|
1495 Lisp_Object stack_size = args[3];
|
|
1496 Lisp_Object doc_string = ((nargs > 4) ? args[4] : Qnil);
|
|
1497 Lisp_Object interactive = ((nargs > 5) ? args[5] : Qunbound);
|
|
1498 /* Don't purecopy the doc references in instructions because it's
|
|
1499 wasteful; they will get fixed up later.
|
|
1500
|
|
1501 #### If something goes wrong and they don't get fixed up,
|
|
1502 we're screwed, because pure stuff isn't marked and thus the
|
|
1503 cons references won't be marked and will get reused.
|
|
1504
|
|
1505 Note: there will be a window after the byte code is created and
|
|
1506 before the doc references are fixed up in which there will be
|
|
1507 impure objects inside a pure object, which apparently won't
|
|
1508 get marked, leading the trouble. But during that entire window,
|
|
1509 the objects are sitting on Vload_force_doc_string_list, which
|
|
1510 is staticpro'd, so we're OK. */
|
|
1511 int purecopy_instructions = 1;
|
|
1512
|
|
1513 if (nargs > 6)
|
|
1514 return Fsignal (Qwrong_number_of_arguments,
|
|
1515 list2 (intern ("make-byte-code"), make_int (nargs)));
|
|
1516
|
|
1517 CHECK_LIST (arglist);
|
|
1518 /* instructions is a string or a cons (string . int) for a
|
|
1519 lazy-loaded function. */
|
|
1520 if (CONSP (instructions))
|
|
1521 {
|
|
1522 CHECK_STRING (XCAR (instructions));
|
|
1523 CHECK_INT (XCDR (instructions));
|
|
1524 if (!NILP (constants))
|
|
1525 CHECK_VECTOR (constants);
|
|
1526 purecopy_instructions = 0;
|
|
1527 }
|
|
1528 else
|
|
1529 {
|
|
1530 CHECK_STRING (instructions);
|
|
1531 CHECK_VECTOR (constants);
|
|
1532 }
|
|
1533 CHECK_NATNUM (stack_size);
|
|
1534 /* doc_string may be nil, string, int, or a cons (string . int). */
|
|
1535
|
|
1536 /* interactive may be list or string (or unbound). */
|
|
1537
|
|
1538 if (purify_flag)
|
|
1539 {
|
|
1540 if (!purified (arglist))
|
|
1541 arglist = Fpurecopy (arglist);
|
|
1542 if (purecopy_instructions && !purified (instructions))
|
|
1543 instructions = Fpurecopy (instructions);
|
|
1544 if (!purified (doc_string))
|
|
1545 doc_string = Fpurecopy (doc_string);
|
|
1546 if (!purified (interactive) && !UNBOUNDP (interactive))
|
|
1547 interactive = Fpurecopy (interactive);
|
|
1548
|
|
1549 /* Statistics are kept differently for the constants */
|
|
1550 if (!purified (constants))
|
|
1551 #ifdef PURESTAT
|
|
1552 {
|
|
1553 int old = purecopying_for_bytecode;
|
|
1554 purecopying_for_bytecode = 1;
|
|
1555 constants = Fpurecopy (constants);
|
|
1556 purecopying_for_bytecode = old;
|
|
1557 }
|
|
1558 #else
|
|
1559 constants = Fpurecopy (constants);
|
|
1560 #endif /* PURESTAT */
|
|
1561
|
|
1562 #ifdef PURESTAT
|
|
1563 if (STRINGP (instructions))
|
|
1564 bump_purestat (&purestat_string_bytecodes, pure_sizeof (instructions));
|
|
1565 if (VECTORP (constants))
|
|
1566 bump_purestat (&purestat_vector_bytecode_constants,
|
|
1567 pure_sizeof (constants));
|
|
1568 if (STRINGP (doc_string))
|
|
1569 /* These should be have been snagged by make-docfile... */
|
|
1570 bump_purestat (&purestat_string_documentation,
|
|
1571 pure_sizeof (doc_string));
|
|
1572 if (STRINGP (interactive))
|
|
1573 bump_purestat (&purestat_string_interactive,
|
|
1574 pure_sizeof (interactive));
|
|
1575 #endif /* PURESTAT */
|
|
1576 }
|
|
1577
|
|
1578 {
|
|
1579 int docp = !NILP (doc_string);
|
|
1580 int intp = !UNBOUNDP (interactive);
|
|
1581 #ifdef I18N3
|
|
1582 int domp = !NILP (Vfile_domain);
|
|
1583 #endif
|
|
1584 Lisp_Object val = make_compiled_function (purify_flag);
|
|
1585 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (val);
|
|
1586 b->flags.documentationp = docp;
|
|
1587 b->flags.interactivep = intp;
|
|
1588 #ifdef I18N3
|
|
1589 b->flags.domainp = domp;
|
|
1590 #endif
|
|
1591 b->maxdepth = XINT (stack_size);
|
|
1592 b->bytecodes = instructions;
|
|
1593 b->constants = constants;
|
|
1594 b->arglist = arglist;
|
|
1595 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1596 if (!NILP (Vcurrent_compiled_function_annotation))
|
|
1597 b->annotated = Fpurecopy (Vcurrent_compiled_function_annotation);
|
|
1598 else if (!NILP (Vload_file_name_internal_the_purecopy))
|
|
1599 b->annotated = Vload_file_name_internal_the_purecopy;
|
|
1600 else if (!NILP (Vload_file_name_internal))
|
|
1601 {
|
|
1602 Vload_file_name_internal_the_purecopy =
|
|
1603 Fpurecopy (Ffile_name_nondirectory (Vload_file_name_internal));
|
|
1604 b->annotated = Vload_file_name_internal_the_purecopy;
|
|
1605 }
|
|
1606 #endif
|
|
1607
|
|
1608 #ifdef I18N3
|
|
1609 if (docp && intp && domp)
|
|
1610 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
|
|
1611 (doc_string,
|
|
1612 (((purify_flag) ? pure_cons : Fcons)
|
|
1613 (interactive, Vfile_domain))));
|
|
1614 else if (docp && domp)
|
|
1615 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
|
|
1616 (doc_string, Vfile_domain));
|
|
1617 else if (intp && domp)
|
|
1618 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
|
|
1619 (interactive, Vfile_domain));
|
|
1620 else
|
|
1621 #endif
|
|
1622 if (docp && intp)
|
|
1623 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
|
|
1624 (doc_string, interactive));
|
|
1625 else if (intp)
|
|
1626 b->doc_and_interactive = interactive;
|
|
1627 #ifdef I18N3
|
|
1628 else if (domp)
|
|
1629 b->doc_and_interactive = Vfile_domain;
|
|
1630 #endif
|
|
1631 else
|
|
1632 b->doc_and_interactive = doc_string;
|
|
1633
|
173
|
1634 return val;
|
0
|
1635 }
|
|
1636 }
|
|
1637
|
|
1638
|
|
1639 /**********************************************************************/
|
|
1640 /* Symbol allocation */
|
|
1641 /**********************************************************************/
|
|
1642
|
|
1643 DECLARE_FIXED_TYPE_ALLOC (symbol, struct Lisp_Symbol);
|
|
1644 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_symbol 1000
|
|
1645
|
20
|
1646 DEFUN ("make-symbol", Fmake_symbol, 1, 1, 0, /*
|
0
|
1647 Return a newly allocated uninterned symbol whose name is NAME.
|
|
1648 Its value and function definition are void, and its property list is nil.
|
20
|
1649 */
|
|
1650 (str))
|
0
|
1651 {
|
|
1652 Lisp_Object val;
|
|
1653 struct Lisp_Symbol *p;
|
|
1654
|
|
1655 CHECK_STRING (str);
|
|
1656
|
|
1657 ALLOCATE_FIXED_TYPE (symbol, struct Lisp_Symbol, p);
|
|
1658 #ifdef LRECORD_SYMBOL
|
|
1659 set_lheader_implementation (&(p->lheader), lrecord_symbol);
|
|
1660 #endif
|
|
1661 p->name = XSTRING (str);
|
|
1662 p->plist = Qnil;
|
|
1663 p->value = Qunbound;
|
|
1664 p->function = Qunbound;
|
|
1665 symbol_next (p) = 0;
|
|
1666 XSETSYMBOL (val, p);
|
|
1667 return val;
|
|
1668 }
|
|
1669
|
|
1670
|
|
1671 /**********************************************************************/
|
|
1672 /* Extent allocation */
|
|
1673 /**********************************************************************/
|
|
1674
|
|
1675 DECLARE_FIXED_TYPE_ALLOC (extent, struct extent);
|
|
1676 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_extent 1000
|
|
1677
|
|
1678 struct extent *
|
|
1679 allocate_extent (void)
|
|
1680 {
|
|
1681 struct extent *e;
|
|
1682
|
|
1683 ALLOCATE_FIXED_TYPE (extent, struct extent, e);
|
|
1684 /* memset (e, 0, sizeof (struct extent)); */
|
|
1685 set_lheader_implementation (&(e->lheader), lrecord_extent);
|
|
1686 extent_object (e) = Qnil;
|
|
1687 set_extent_start (e, -1);
|
|
1688 set_extent_end (e, -1);
|
|
1689 e->plist = Qnil;
|
|
1690
|
|
1691 memset (&e->flags, 0, sizeof (e->flags));
|
|
1692
|
|
1693 extent_face (e) = Qnil;
|
|
1694 e->flags.end_open = 1; /* default is for endpoints to behave like markers */
|
|
1695 e->flags.detachable = 1;
|
|
1696
|
173
|
1697 return e;
|
0
|
1698 }
|
|
1699
|
|
1700
|
|
1701 /**********************************************************************/
|
|
1702 /* Event allocation */
|
|
1703 /**********************************************************************/
|
|
1704
|
|
1705 DECLARE_FIXED_TYPE_ALLOC (event, struct Lisp_Event);
|
|
1706 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_event 1000
|
|
1707
|
|
1708 Lisp_Object
|
|
1709 allocate_event (void)
|
|
1710 {
|
|
1711 Lisp_Object val;
|
|
1712 struct Lisp_Event *e;
|
|
1713
|
|
1714 ALLOCATE_FIXED_TYPE (event, struct Lisp_Event, e);
|
|
1715 set_lheader_implementation (&(e->lheader), lrecord_event);
|
|
1716
|
|
1717 XSETEVENT (val, e);
|
|
1718 return val;
|
|
1719 }
|
|
1720
|
|
1721
|
|
1722 /**********************************************************************/
|
|
1723 /* Marker allocation */
|
|
1724 /**********************************************************************/
|
|
1725
|
|
1726 DECLARE_FIXED_TYPE_ALLOC (marker, struct Lisp_Marker);
|
|
1727 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_marker 1000
|
|
1728
|
20
|
1729 DEFUN ("make-marker", Fmake_marker, 0, 0, 0, /*
|
0
|
1730 Return a newly allocated marker which does not point at any place.
|
20
|
1731 */
|
|
1732 ())
|
0
|
1733 {
|
|
1734 Lisp_Object val;
|
|
1735 struct Lisp_Marker *p;
|
|
1736
|
|
1737 ALLOCATE_FIXED_TYPE (marker, struct Lisp_Marker, p);
|
|
1738 set_lheader_implementation (&(p->lheader), lrecord_marker);
|
|
1739 p->buffer = 0;
|
|
1740 p->memind = 0;
|
|
1741 marker_next (p) = 0;
|
|
1742 marker_prev (p) = 0;
|
|
1743 p->insertion_type = 0;
|
|
1744 XSETMARKER (val, p);
|
|
1745 return val;
|
|
1746 }
|
|
1747
|
|
1748 Lisp_Object
|
|
1749 noseeum_make_marker (void)
|
|
1750 {
|
|
1751 Lisp_Object val;
|
|
1752 struct Lisp_Marker *p;
|
|
1753
|
|
1754 NOSEEUM_ALLOCATE_FIXED_TYPE (marker, struct Lisp_Marker, p);
|
|
1755 set_lheader_implementation (&(p->lheader), lrecord_marker);
|
|
1756 p->buffer = 0;
|
|
1757 p->memind = 0;
|
|
1758 marker_next (p) = 0;
|
|
1759 marker_prev (p) = 0;
|
|
1760 p->insertion_type = 0;
|
|
1761 XSETMARKER (val, p);
|
|
1762 return val;
|
|
1763 }
|
|
1764
|
|
1765
|
|
1766 /**********************************************************************/
|
|
1767 /* String allocation */
|
|
1768 /**********************************************************************/
|
|
1769
|
|
1770 /* The data for "short" strings generally resides inside of structs of type
|
|
1771 string_chars_block. The Lisp_String structure is allocated just like any
|
|
1772 other Lisp object (except for vectors), and these are freelisted when
|
|
1773 they get garbage collected. The data for short strings get compacted,
|
|
1774 but the data for large strings do not.
|
|
1775
|
|
1776 Previously Lisp_String structures were relocated, but this caused a lot
|
|
1777 of bus-errors because the C code didn't include enough GCPRO's for
|
|
1778 strings (since EVERY REFERENCE to a short string needed to be GCPRO'd so
|
|
1779 that the reference would get relocated).
|
|
1780
|
|
1781 This new method makes things somewhat bigger, but it is MUCH safer. */
|
|
1782
|
|
1783 DECLARE_FIXED_TYPE_ALLOC (string, struct Lisp_String);
|
|
1784 /* strings are used and freed quite often */
|
|
1785 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 10000 */
|
|
1786 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 1000
|
|
1787
|
|
1788 /* String blocks contain this many useful bytes. */
|
|
1789 #define STRING_CHARS_BLOCK_SIZE \
|
|
1790 (8192 - MALLOC_OVERHEAD - ((2 * sizeof (struct string_chars_block *)) \
|
|
1791 + sizeof (EMACS_INT)))
|
|
1792 /* Block header for small strings. */
|
|
1793 struct string_chars_block
|
|
1794 {
|
|
1795 EMACS_INT pos;
|
|
1796 struct string_chars_block *next;
|
|
1797 struct string_chars_block *prev;
|
|
1798 /* Contents of string_chars_block->string_chars are interleaved
|
|
1799 string_chars structures (see below) and the actual string data */
|
|
1800 unsigned char string_chars[STRING_CHARS_BLOCK_SIZE];
|
|
1801 };
|
|
1802
|
|
1803 struct string_chars_block *first_string_chars_block;
|
|
1804 struct string_chars_block *current_string_chars_block;
|
|
1805
|
|
1806 /* If SIZE is the length of a string, this returns how many bytes
|
|
1807 * the string occupies in string_chars_block->string_chars
|
|
1808 * (including alignment padding).
|
|
1809 */
|
|
1810 #define STRING_FULLSIZE(s) \
|
|
1811 ALIGN_SIZE (((s) + 1 + sizeof (struct Lisp_String *)),\
|
|
1812 ALIGNOF (struct Lisp_String *))
|
|
1813
|
|
1814 #define BIG_STRING_FULLSIZE_P(fullsize) ((fullsize) >= STRING_CHARS_BLOCK_SIZE)
|
|
1815 #define BIG_STRING_SIZE_P(size) (BIG_STRING_FULLSIZE_P (STRING_FULLSIZE(size)))
|
|
1816
|
|
1817 #define CHARS_TO_STRING_CHAR(x) \
|
|
1818 ((struct string_chars *) \
|
173
|
1819 (((char *) (x)) - (slot_offset (struct string_chars, chars[0]))))
|
0
|
1820
|
|
1821
|
|
1822 struct string_chars
|
|
1823 {
|
|
1824 struct Lisp_String *string;
|
|
1825 unsigned char chars[1];
|
|
1826 };
|
|
1827
|
|
1828 struct unused_string_chars
|
|
1829 {
|
|
1830 struct Lisp_String *string;
|
|
1831 EMACS_INT fullsize;
|
|
1832 };
|
|
1833
|
|
1834 static void
|
|
1835 init_string_chars_alloc (void)
|
|
1836 {
|
|
1837 first_string_chars_block =
|
|
1838 (struct string_chars_block *) xmalloc (sizeof (struct string_chars_block));
|
|
1839 first_string_chars_block->prev = 0;
|
|
1840 first_string_chars_block->next = 0;
|
|
1841 first_string_chars_block->pos = 0;
|
|
1842 current_string_chars_block = first_string_chars_block;
|
|
1843 }
|
|
1844
|
|
1845 static struct string_chars *
|
|
1846 allocate_string_chars_struct (struct Lisp_String *string_it_goes_with,
|
|
1847 EMACS_INT fullsize)
|
|
1848 {
|
|
1849 struct string_chars *s_chars;
|
|
1850
|
|
1851 /* Allocate the string's actual data */
|
|
1852 if (BIG_STRING_FULLSIZE_P (fullsize))
|
|
1853 {
|
|
1854 s_chars = (struct string_chars *) xmalloc (fullsize);
|
|
1855 }
|
|
1856 else if (fullsize <=
|
|
1857 (countof (current_string_chars_block->string_chars)
|
|
1858 - current_string_chars_block->pos))
|
|
1859 {
|
|
1860 /* This string can fit in the current string chars block */
|
|
1861 s_chars = (struct string_chars *)
|
|
1862 (current_string_chars_block->string_chars
|
|
1863 + current_string_chars_block->pos);
|
|
1864 current_string_chars_block->pos += fullsize;
|
|
1865 }
|
|
1866 else
|
|
1867 {
|
|
1868 /* Make a new current string chars block */
|
|
1869 struct string_chars_block *new
|
|
1870 = (struct string_chars_block *)
|
|
1871 xmalloc (sizeof (struct string_chars_block));
|
|
1872
|
|
1873 current_string_chars_block->next = new;
|
|
1874 new->prev = current_string_chars_block;
|
|
1875 new->next = 0;
|
|
1876 current_string_chars_block = new;
|
|
1877 new->pos = fullsize;
|
|
1878 s_chars = (struct string_chars *)
|
|
1879 current_string_chars_block->string_chars;
|
|
1880 }
|
|
1881
|
|
1882 s_chars->string = string_it_goes_with;
|
|
1883
|
|
1884 INCREMENT_CONS_COUNTER (fullsize, "string chars");
|
|
1885
|
|
1886 return s_chars;
|
|
1887 }
|
|
1888
|
|
1889 Lisp_Object
|
|
1890 make_uninit_string (Bytecount length)
|
|
1891 {
|
|
1892 struct Lisp_String *s;
|
|
1893 struct string_chars *s_chars;
|
|
1894 EMACS_INT fullsize = STRING_FULLSIZE (length);
|
|
1895 Lisp_Object val;
|
|
1896
|
|
1897 if ((length < 0) || (fullsize <= 0))
|
|
1898 abort ();
|
|
1899
|
|
1900 /* Allocate the string header */
|
|
1901 ALLOCATE_FIXED_TYPE (string, struct Lisp_String, s);
|
|
1902
|
|
1903 s_chars = allocate_string_chars_struct (s, fullsize);
|
|
1904
|
|
1905 set_string_data (s, &(s_chars->chars[0]));
|
|
1906 set_string_length (s, length);
|
|
1907 s->plist = Qnil;
|
|
1908
|
|
1909 set_string_byte (s, length, 0);
|
|
1910
|
|
1911 XSETSTRING (val, s);
|
173
|
1912 return val;
|
0
|
1913 }
|
|
1914
|
|
1915 #ifdef VERIFY_STRING_CHARS_INTEGRITY
|
|
1916 static void verify_string_chars_integrity (void);
|
|
1917 #endif
|
|
1918
|
|
1919 /* Resize the string S so that DELTA bytes can be inserted starting
|
|
1920 at POS. If DELTA < 0, it means deletion starting at POS. If
|
|
1921 POS < 0, resize the string but don't copy any characters. Use
|
|
1922 this if you're planning on completely overwriting the string.
|
|
1923 */
|
|
1924
|
|
1925 void
|
|
1926 resize_string (struct Lisp_String *s, Bytecount pos, Bytecount delta)
|
|
1927 {
|
|
1928 #ifdef VERIFY_STRING_CHARS_INTEGRITY
|
|
1929 verify_string_chars_integrity ();
|
|
1930 #endif
|
|
1931
|
|
1932 #ifdef ERROR_CHECK_BUFPOS
|
|
1933 if (pos >= 0)
|
|
1934 {
|
|
1935 assert (pos <= string_length (s));
|
|
1936 if (delta < 0)
|
|
1937 assert (pos + (-delta) <= string_length (s));
|
|
1938 }
|
|
1939 else
|
|
1940 {
|
|
1941 if (delta < 0)
|
|
1942 assert ((-delta) <= string_length (s));
|
|
1943 }
|
|
1944 #endif
|
|
1945
|
|
1946 if (pos >= 0 && delta < 0)
|
|
1947 /* If DELTA < 0, the functions below will delete the characters
|
|
1948 before POS. We want to delete characters *after* POS, however,
|
|
1949 so convert this to the appropriate form. */
|
|
1950 pos += -delta;
|
|
1951
|
|
1952 if (delta == 0)
|
|
1953 /* simplest case: no size change. */
|
|
1954 return;
|
|
1955 else
|
|
1956 {
|
|
1957 EMACS_INT oldfullsize = STRING_FULLSIZE (string_length (s));
|
|
1958 EMACS_INT newfullsize = STRING_FULLSIZE (string_length (s) + delta);
|
|
1959
|
|
1960 if (oldfullsize == newfullsize)
|
|
1961 {
|
|
1962 /* next simplest case; size change but the necessary
|
|
1963 allocation size won't change (up or down; code somewhere
|
|
1964 depends on there not being any unused allocation space,
|
|
1965 modulo any alignment constraints). */
|
|
1966 if (pos >= 0)
|
|
1967 {
|
|
1968 Bufbyte *addroff = pos + string_data (s);
|
|
1969
|
|
1970 memmove (addroff + delta, addroff,
|
|
1971 /* +1 due to zero-termination. */
|
|
1972 string_length (s) + 1 - pos);
|
|
1973 }
|
|
1974 }
|
|
1975 else if (BIG_STRING_FULLSIZE_P (oldfullsize) &&
|
|
1976 BIG_STRING_FULLSIZE_P (newfullsize))
|
|
1977 {
|
|
1978 /* next simplest case; the string is big enough to be malloc()ed
|
|
1979 itself, so we just realloc.
|
|
1980
|
|
1981 It's important not to let the string get below the threshold
|
|
1982 for making big strings and still remain malloc()ed; if that
|
|
1983 were the case, repeated calls to this function on the same
|
|
1984 string could result in memory leakage. */
|
|
1985 set_string_data (s, (Bufbyte *) xrealloc (string_data (s),
|
|
1986 newfullsize));
|
|
1987 if (pos >= 0)
|
|
1988 {
|
|
1989 Bufbyte *addroff = pos + string_data (s);
|
|
1990
|
|
1991 memmove (addroff + delta, addroff,
|
|
1992 /* +1 due to zero-termination. */
|
|
1993 string_length (s) + 1 - pos);
|
|
1994 }
|
|
1995 }
|
|
1996 else
|
|
1997 {
|
|
1998 /* worst case. We make a new string_chars struct and copy
|
|
1999 the string's data into it, inserting/deleting the delta
|
|
2000 in the process. The old string data will either get
|
|
2001 freed by us (if it was malloc()ed) or will be reclaimed
|
|
2002 in the normal course of garbage collection. */
|
|
2003 struct string_chars *s_chars =
|
|
2004 allocate_string_chars_struct (s, newfullsize);
|
|
2005 Bufbyte *new_addr = &(s_chars->chars[0]);
|
|
2006 Bufbyte *old_addr = string_data (s);
|
|
2007 if (pos >= 0)
|
|
2008 {
|
|
2009 memcpy (new_addr, old_addr, pos);
|
|
2010 memcpy (new_addr + pos + delta, old_addr + pos,
|
|
2011 string_length (s) + 1 - pos);
|
|
2012 }
|
|
2013 set_string_data (s, new_addr);
|
|
2014 if (BIG_STRING_FULLSIZE_P (oldfullsize))
|
|
2015 xfree (old_addr);
|
|
2016 else
|
|
2017 {
|
|
2018 /* We need to mark this chunk of the string_chars_block
|
|
2019 as unused so that compact_string_chars() doesn't
|
|
2020 freak. */
|
|
2021 struct string_chars *old_s_chars =
|
|
2022 (struct string_chars *) ((char *) old_addr -
|
|
2023 sizeof (struct Lisp_String *));
|
|
2024 /* Sanity check to make sure we aren't hosed by strange
|
|
2025 alignment/padding. */
|
|
2026 assert (old_s_chars->string == s);
|
|
2027 MARK_STRUCT_AS_FREE (old_s_chars);
|
|
2028 ((struct unused_string_chars *) old_s_chars)->fullsize =
|
|
2029 oldfullsize;
|
|
2030 }
|
|
2031 }
|
|
2032
|
|
2033 set_string_length (s, string_length (s) + delta);
|
|
2034 /* If pos < 0, the string won't be zero-terminated.
|
|
2035 Terminate now just to make sure. */
|
|
2036 string_data (s)[string_length (s)] = '\0';
|
|
2037
|
|
2038 if (pos >= 0)
|
|
2039 {
|
|
2040 Lisp_Object string = Qnil;
|
|
2041
|
|
2042 XSETSTRING (string, s);
|
|
2043 /* We also have to adjust all of the extent indices after the
|
|
2044 place we did the change. We say "pos - 1" because
|
|
2045 adjust_extents() is exclusive of the starting position
|
|
2046 passed to it. */
|
|
2047 adjust_extents (string, pos - 1, string_length (s),
|
|
2048 delta);
|
|
2049 }
|
|
2050 }
|
|
2051
|
|
2052 #ifdef VERIFY_STRING_CHARS_INTEGRITY
|
|
2053 verify_string_chars_integrity ();
|
|
2054 #endif
|
|
2055 }
|
|
2056
|
70
|
2057 #ifdef MULE
|
|
2058
|
|
2059 void
|
|
2060 set_string_char (struct Lisp_String *s, Charcount i, Emchar c)
|
|
2061 {
|
|
2062 Bytecount oldlen, newlen;
|
|
2063 Bufbyte newstr[MAX_EMCHAR_LEN];
|
|
2064 Bytecount bytoff = charcount_to_bytecount (string_data (s), i);
|
|
2065
|
|
2066 oldlen = charcount_to_bytecount (string_data (s) + bytoff, 1);
|
|
2067 newlen = set_charptr_emchar (newstr, c);
|
|
2068
|
|
2069 if (oldlen != newlen)
|
|
2070 resize_string (s, bytoff, newlen - oldlen);
|
|
2071 /* Remember, string_data (s) might have changed so we can't
|
|
2072 cache it. */
|
|
2073 memcpy (string_data (s) + bytoff, newstr, newlen);
|
|
2074 }
|
|
2075
|
|
2076 #endif /* MULE */
|
|
2077
|
20
|
2078 DEFUN ("make-string", Fmake_string, 2, 2, 0, /*
|
0
|
2079 Return a newly created string of length LENGTH, with each element being INIT.
|
|
2080 LENGTH must be an integer and INIT must be a character.
|
20
|
2081 */
|
|
2082 (length, init))
|
0
|
2083 {
|
|
2084 Lisp_Object val;
|
|
2085
|
|
2086 CHECK_NATNUM (length);
|
|
2087 CHECK_CHAR_COERCE_INT (init);
|
|
2088 {
|
|
2089 Bufbyte str[MAX_EMCHAR_LEN];
|
|
2090 int len = set_charptr_emchar (str, XCHAR (init));
|
|
2091
|
|
2092 val = make_uninit_string (len * XINT (length));
|
|
2093 if (len == 1)
|
|
2094 /* Optimize the single-byte case */
|
14
|
2095 memset (XSTRING_DATA (val), XCHAR (init), XSTRING_LENGTH (val));
|
0
|
2096 else
|
|
2097 {
|
|
2098 int i, j, k;
|
14
|
2099 Bufbyte *ptr = XSTRING_DATA (val);
|
0
|
2100
|
|
2101 k = 0;
|
|
2102 for (i = 0; i < XINT (length); i++)
|
|
2103 for (j = 0; j < len; j++)
|
|
2104 ptr[k++] = str[j];
|
|
2105 }
|
|
2106 }
|
173
|
2107 return val;
|
0
|
2108 }
|
|
2109
|
|
2110 /* Take some raw memory, which MUST already be in internal format,
|
|
2111 and package it up it into a Lisp string. */
|
|
2112 Lisp_Object
|
|
2113 make_string (CONST Bufbyte *contents, Bytecount length)
|
|
2114 {
|
|
2115 Lisp_Object val;
|
70
|
2116
|
|
2117 /* Make sure we find out about bad make_string's when they happen */
|
|
2118 #if defined (ERROR_CHECK_BUFPOS) && defined (MULE)
|
|
2119 bytecount_to_charcount (contents, length); /* Just for the assertions */
|
|
2120 #endif
|
0
|
2121
|
|
2122 val = make_uninit_string (length);
|
14
|
2123 memcpy (XSTRING_DATA (val), contents, length);
|
173
|
2124 return val;
|
0
|
2125 }
|
|
2126
|
|
2127 /* Take some raw memory, encoded in some external data format,
|
|
2128 and convert it into a Lisp string. */
|
|
2129 Lisp_Object
|
|
2130 make_ext_string (CONST Extbyte *contents, EMACS_INT length,
|
|
2131 enum external_data_format fmt)
|
|
2132 {
|
|
2133 CONST Bufbyte *intstr;
|
|
2134 Bytecount intlen;
|
|
2135
|
|
2136 GET_CHARPTR_INT_DATA_ALLOCA (contents, length, fmt, intstr, intlen);
|
|
2137 return make_string (intstr, intlen);
|
|
2138 }
|
|
2139
|
|
2140 Lisp_Object
|
|
2141 build_string (CONST char *str)
|
|
2142 {
|
|
2143 Bytecount length;
|
|
2144
|
|
2145 /* Some strlen crash and burn if passed null. */
|
|
2146 if (!str)
|
|
2147 length = 0;
|
|
2148 else
|
|
2149 length = strlen (str);
|
|
2150
|
|
2151 return make_string ((CONST Bufbyte *) str, length);
|
|
2152 }
|
|
2153
|
|
2154 Lisp_Object
|
|
2155 build_ext_string (CONST char *str, enum external_data_format fmt)
|
|
2156 {
|
|
2157 Bytecount length;
|
|
2158
|
|
2159 /* Some strlen crash and burn if passed null. */
|
|
2160 if (!str)
|
|
2161 length = 0;
|
|
2162 else
|
|
2163 length = strlen (str);
|
|
2164
|
|
2165 return make_ext_string ((Extbyte *) str, length, fmt);
|
|
2166 }
|
|
2167
|
|
2168 Lisp_Object
|
|
2169 build_translated_string (CONST char *str)
|
|
2170 {
|
|
2171 return build_string (GETTEXT (str));
|
|
2172 }
|
|
2173
|
|
2174
|
|
2175 /************************************************************************/
|
|
2176 /* lcrecord lists */
|
|
2177 /************************************************************************/
|
|
2178
|
|
2179 /* Lcrecord lists are used to manage the allocation of particular
|
|
2180 sorts of lcrecords, to avoid calling alloc_lcrecord() (and thus
|
|
2181 malloc() and garbage-collection junk) as much as possible.
|
|
2182 It is similar to the Blocktype class.
|
|
2183
|
|
2184 It works like this:
|
|
2185
|
|
2186 1) Create an lcrecord-list object using make_lcrecord_list().
|
|
2187 This is often done at initialization. Remember to staticpro
|
|
2188 this object! The arguments to make_lcrecord_list() are the
|
|
2189 same as would be passed to alloc_lcrecord().
|
|
2190 2) Instead of calling alloc_lcrecord(), call allocate_managed_lcrecord()
|
|
2191 and pass the lcrecord-list earlier created.
|
|
2192 3) When done with the lcrecord, call free_managed_lcrecord().
|
|
2193 The standard freeing caveats apply: ** make sure there are no
|
|
2194 pointers to the object anywhere! **
|
|
2195 4) Calling free_managed_lcrecord() is just like kissing the
|
|
2196 lcrecord goodbye as if it were garbage-collected. This means:
|
|
2197 -- the contents of the freed lcrecord are undefined, and the
|
|
2198 contents of something produced by allocate_managed_lcrecord()
|
|
2199 are undefined, just like for alloc_lcrecord().
|
|
2200 -- the mark method for the lcrecord's type will *NEVER* be called
|
|
2201 on freed lcrecords.
|
|
2202 -- the finalize method for the lcrecord's type will be called
|
|
2203 at the time that free_managed_lcrecord() is called.
|
|
2204
|
|
2205 */
|
|
2206
|
|
2207 static Lisp_Object mark_lcrecord_list (Lisp_Object, void (*) (Lisp_Object));
|
|
2208 DEFINE_LRECORD_IMPLEMENTATION ("lcrecord-list", lcrecord_list,
|
|
2209 mark_lcrecord_list, internal_object_printer,
|
|
2210 0, 0, 0, struct lcrecord_list);
|
|
2211
|
|
2212 static Lisp_Object
|
|
2213 mark_lcrecord_list (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
2214 {
|
|
2215 struct lcrecord_list *list = XLCRECORD_LIST (obj);
|
|
2216 Lisp_Object chain = list->free;
|
|
2217
|
|
2218 while (!NILP (chain))
|
|
2219 {
|
|
2220 struct lrecord_header *lheader = XRECORD_LHEADER (chain);
|
|
2221 struct free_lcrecord_header *free_header =
|
|
2222 (struct free_lcrecord_header *) lheader;
|
14
|
2223
|
|
2224 #ifdef ERROR_CHECK_GC
|
0
|
2225 CONST struct lrecord_implementation *implementation
|
|
2226 = lheader->implementation;
|
80
|
2227
|
0
|
2228 /* There should be no other pointers to the free list. */
|
|
2229 assert (!MARKED_RECORD_HEADER_P (lheader));
|
|
2230 /* Only lcrecords should be here. */
|
|
2231 assert (!implementation->basic_p);
|
|
2232 /* Only free lcrecords should be here. */
|
|
2233 assert (free_header->lcheader.free);
|
|
2234 /* The type of the lcrecord must be right. */
|
|
2235 assert (implementation == list->implementation);
|
|
2236 /* So must the size. */
|
|
2237 assert (implementation->static_size == 0
|
|
2238 || implementation->static_size == list->size);
|
14
|
2239 #endif /* ERROR_CHECK_GC */
|
80
|
2240
|
0
|
2241 MARK_RECORD_HEADER (lheader);
|
|
2242 chain = free_header->chain;
|
|
2243 }
|
|
2244
|
|
2245 return Qnil;
|
|
2246 }
|
|
2247
|
|
2248 Lisp_Object
|
|
2249 make_lcrecord_list (int size,
|
|
2250 CONST struct lrecord_implementation *implementation)
|
|
2251 {
|
|
2252 struct lcrecord_list *p = alloc_lcrecord (sizeof (*p),
|
|
2253 lrecord_lcrecord_list);
|
|
2254 Lisp_Object val = Qnil;
|
|
2255
|
|
2256 p->implementation = implementation;
|
|
2257 p->size = size;
|
|
2258 p->free = Qnil;
|
|
2259 XSETLCRECORD_LIST (val, p);
|
|
2260 return val;
|
|
2261 }
|
|
2262
|
|
2263 Lisp_Object
|
|
2264 allocate_managed_lcrecord (Lisp_Object lcrecord_list)
|
|
2265 {
|
|
2266 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list);
|
|
2267 if (!NILP (list->free))
|
|
2268 {
|
|
2269 Lisp_Object val = list->free;
|
|
2270 struct free_lcrecord_header *free_header =
|
|
2271 (struct free_lcrecord_header *) XPNTR (val);
|
|
2272
|
|
2273 #ifdef ERROR_CHECK_GC
|
|
2274 struct lrecord_header *lheader =
|
|
2275 (struct lrecord_header *) free_header;
|
|
2276 CONST struct lrecord_implementation *implementation
|
|
2277 = lheader->implementation;
|
|
2278
|
|
2279 /* There should be no other pointers to the free list. */
|
|
2280 assert (!MARKED_RECORD_HEADER_P (lheader));
|
|
2281 /* Only lcrecords should be here. */
|
|
2282 assert (!implementation->basic_p);
|
|
2283 /* Only free lcrecords should be here. */
|
|
2284 assert (free_header->lcheader.free);
|
|
2285 /* The type of the lcrecord must be right. */
|
|
2286 assert (implementation == list->implementation);
|
|
2287 /* So must the size. */
|
|
2288 assert (implementation->static_size == 0
|
|
2289 || implementation->static_size == list->size);
|
|
2290 #endif
|
|
2291 list->free = free_header->chain;
|
|
2292 free_header->lcheader.free = 0;
|
|
2293 return val;
|
|
2294 }
|
|
2295 else
|
|
2296 {
|
|
2297 Lisp_Object foo = Qnil;
|
|
2298
|
|
2299 XSETOBJ (foo, Lisp_Record,
|
|
2300 alloc_lcrecord (list->size, list->implementation));
|
|
2301 return foo;
|
|
2302 }
|
|
2303 }
|
|
2304
|
|
2305 void
|
|
2306 free_managed_lcrecord (Lisp_Object lcrecord_list, Lisp_Object lcrecord)
|
|
2307 {
|
|
2308 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list);
|
|
2309 struct free_lcrecord_header *free_header =
|
|
2310 (struct free_lcrecord_header *) XPNTR (lcrecord);
|
|
2311 struct lrecord_header *lheader =
|
|
2312 (struct lrecord_header *) free_header;
|
|
2313 CONST struct lrecord_implementation *implementation
|
|
2314 = lheader->implementation;
|
|
2315
|
|
2316 #ifdef ERROR_CHECK_GC
|
|
2317 /* Make sure the size is correct. This will catch, for example,
|
|
2318 putting a window configuration on the wrong free list. */
|
|
2319 if (implementation->size_in_bytes_method)
|
|
2320 assert (((implementation->size_in_bytes_method) (lheader))
|
|
2321 == list->size);
|
|
2322 else
|
|
2323 assert (implementation->static_size == list->size);
|
|
2324 #endif
|
|
2325
|
|
2326 if (implementation->finalizer)
|
|
2327 ((implementation->finalizer) (lheader, 0));
|
|
2328 free_header->chain = list->free;
|
|
2329 free_header->lcheader.free = 1;
|
|
2330 list->free = lcrecord;
|
|
2331 }
|
|
2332
|
|
2333
|
|
2334 /**********************************************************************/
|
|
2335 /* Purity of essence, peace on earth */
|
|
2336 /**********************************************************************/
|
|
2337
|
|
2338 static int symbols_initialized;
|
|
2339
|
|
2340 Lisp_Object
|
|
2341 make_pure_string (CONST Bufbyte *data, Bytecount length,
|
|
2342 Lisp_Object plist, int no_need_to_copy_data)
|
|
2343 {
|
|
2344 Lisp_Object new;
|
|
2345 struct Lisp_String *s;
|
|
2346 int size = (sizeof (struct Lisp_String) + ((no_need_to_copy_data)
|
|
2347 ? 0
|
|
2348 /* + 1 for terminating 0 */
|
|
2349 : (length + 1)));
|
|
2350 size = ALIGN_SIZE (size, ALIGNOF (Lisp_Object));
|
|
2351
|
|
2352 if (symbols_initialized && !pure_lossage)
|
|
2353 {
|
|
2354 /* Try to share some names. Saves a few kbytes. */
|
|
2355 Lisp_Object tem = oblookup (Vobarray, data, length);
|
|
2356 if (SYMBOLP (tem))
|
|
2357 {
|
|
2358 s = XSYMBOL (tem)->name;
|
|
2359 if (!PURIFIED (s)) abort ();
|
|
2360 XSETSTRING (new, s);
|
173
|
2361 return new;
|
0
|
2362 }
|
|
2363 }
|
|
2364
|
|
2365 if (!check_purespace (size))
|
173
|
2366 return make_string (data, length);
|
0
|
2367
|
|
2368 s = (struct Lisp_String *) (PUREBEG + pureptr);
|
|
2369 set_string_length (s, length);
|
|
2370 if (no_need_to_copy_data)
|
|
2371 {
|
|
2372 set_string_data (s, (Bufbyte *) data);
|
|
2373 }
|
|
2374 else
|
|
2375 {
|
|
2376 set_string_data (s, (Bufbyte *) s + sizeof (struct Lisp_String));
|
|
2377 memcpy (string_data (s), data, length);
|
|
2378 set_string_byte (s, length, 0);
|
|
2379 }
|
|
2380 s->plist = Qnil;
|
|
2381 pureptr += size;
|
|
2382
|
|
2383 #ifdef PURESTAT
|
|
2384 bump_purestat (&purestat_string_all, size);
|
|
2385 if (purecopying_for_bytecode)
|
|
2386 bump_purestat (&purestat_string_other_function, size);
|
|
2387 #endif
|
|
2388
|
|
2389 /* Do this after the official "completion" of the purecopying. */
|
|
2390 s->plist = Fpurecopy (plist);
|
|
2391
|
|
2392 XSETSTRING (new, s);
|
173
|
2393 return new;
|
0
|
2394 }
|
|
2395
|
|
2396
|
|
2397 Lisp_Object
|
|
2398 make_pure_pname (CONST Bufbyte *data, Bytecount length,
|
|
2399 int no_need_to_copy_data)
|
|
2400 {
|
|
2401 Lisp_Object name = make_pure_string (data, length, Qnil,
|
|
2402 no_need_to_copy_data);
|
|
2403 bump_purestat (&purestat_string_pname, pure_sizeof (name));
|
|
2404
|
|
2405 /* We've made (at least) Qnil now, and Vobarray will soon be set up. */
|
|
2406 symbols_initialized = 1;
|
|
2407
|
173
|
2408 return name;
|
0
|
2409 }
|
|
2410
|
|
2411
|
|
2412 Lisp_Object
|
|
2413 pure_cons (Lisp_Object car, Lisp_Object cdr)
|
|
2414 {
|
|
2415 Lisp_Object new;
|
|
2416
|
|
2417 if (!check_purespace (sizeof (struct Lisp_Cons)))
|
173
|
2418 return Fcons (Fpurecopy (car), Fpurecopy (cdr));
|
0
|
2419
|
|
2420 XSETCONS (new, PUREBEG + pureptr);
|
|
2421 pureptr += sizeof (struct Lisp_Cons);
|
|
2422 bump_purestat (&purestat_cons, sizeof (struct Lisp_Cons));
|
|
2423
|
|
2424 XCAR (new) = Fpurecopy (car);
|
|
2425 XCDR (new) = Fpurecopy (cdr);
|
173
|
2426 return new;
|
0
|
2427 }
|
|
2428
|
|
2429 Lisp_Object
|
|
2430 pure_list (int nargs, Lisp_Object *args)
|
|
2431 {
|
|
2432 Lisp_Object foo = Qnil;
|
|
2433
|
|
2434 for (--nargs; nargs >= 0; nargs--)
|
|
2435 foo = pure_cons (args[nargs], foo);
|
|
2436
|
|
2437 return foo;
|
|
2438 }
|
|
2439
|
|
2440 #ifdef LISP_FLOAT_TYPE
|
|
2441
|
|
2442 Lisp_Object
|
|
2443 make_pure_float (double num)
|
|
2444 {
|
|
2445 struct Lisp_Float *f;
|
|
2446 Lisp_Object val;
|
|
2447
|
|
2448 /* Make sure that PUREBEG + pureptr is aligned on at least a sizeof
|
|
2449 (double) boundary. Some architectures (like the sparc) require
|
|
2450 this, and I suspect that floats are rare enough that it's no
|
|
2451 tragedy for those that don't. */
|
|
2452 {
|
|
2453 #if defined (__GNUC__) && (__GNUC__ >= 2)
|
|
2454 /* In gcc, we can directly ask what the alignment constraints of a
|
|
2455 structure are, but in general, that's not possible... Arrgh!!
|
|
2456 */
|
|
2457 int alignment = __alignof (struct Lisp_Float);
|
|
2458 #else /* !GNUC */
|
|
2459 /* Best guess is to make the `double' slot be aligned to the size
|
|
2460 of double (which is probably 8 bytes). This assumes that it's
|
|
2461 ok to align the beginning of the structure to the same boundary
|
|
2462 that the `double' slot in it is supposed to be aligned to; this
|
|
2463 should be ok because presumably there is padding in the layout
|
|
2464 of the struct to account for this.
|
|
2465 */
|
|
2466 int alignment = sizeof (float_data (f));
|
|
2467 #endif
|
|
2468 char *p = ((char *) PUREBEG + pureptr);
|
|
2469
|
|
2470 p = (char *) (((unsigned EMACS_INT) p + alignment - 1) & - alignment);
|
|
2471 pureptr = p - (char *) PUREBEG;
|
|
2472 }
|
|
2473
|
|
2474 if (!check_purespace (sizeof (struct Lisp_Float)))
|
173
|
2475 return make_float (num);
|
0
|
2476
|
|
2477 f = (struct Lisp_Float *) (PUREBEG + pureptr);
|
|
2478 set_lheader_implementation (&(f->lheader), lrecord_float);
|
|
2479 pureptr += sizeof (struct Lisp_Float);
|
|
2480 bump_purestat (&purestat_float, sizeof (struct Lisp_Float));
|
|
2481
|
|
2482 float_next (f) = ((struct Lisp_Float *) -1);
|
|
2483 float_data (f) = num;
|
|
2484 XSETFLOAT (val, f);
|
173
|
2485 return val;
|
0
|
2486 }
|
|
2487
|
|
2488 #endif /* LISP_FLOAT_TYPE */
|
|
2489
|
|
2490 Lisp_Object
|
|
2491 make_pure_vector (EMACS_INT len, Lisp_Object init)
|
|
2492 {
|
|
2493 Lisp_Object new;
|
|
2494 EMACS_INT size = (sizeof (struct Lisp_Vector)
|
|
2495 + (len - 1) * sizeof (Lisp_Object));
|
|
2496
|
|
2497 init = Fpurecopy (init);
|
|
2498
|
|
2499 if (!check_purespace (size))
|
173
|
2500 return make_vector (len, init);
|
0
|
2501
|
|
2502 XSETVECTOR (new, PUREBEG + pureptr);
|
|
2503 pureptr += size;
|
|
2504 bump_purestat (&purestat_vector_all, size);
|
|
2505
|
173
|
2506 XVECTOR_LENGTH (new) = len;
|
0
|
2507
|
|
2508 for (size = 0; size < len; size++)
|
173
|
2509 XVECTOR_DATA (new)[size] = init;
|
|
2510
|
|
2511 return new;
|
0
|
2512 }
|
|
2513
|
|
2514 #if 0
|
|
2515 /* Presently unused */
|
|
2516 void *
|
|
2517 alloc_pure_lrecord (int size, struct lrecord_implementation *implementation)
|
|
2518 {
|
|
2519 struct lrecord_header *header = (void *) (PUREBEG + pureptr);
|
|
2520
|
171
|
2521 if (pureptr + size > get_PURESIZE())
|
0
|
2522 pure_storage_exhausted ();
|
|
2523
|
|
2524 set_lheader_implementation (header, implementation);
|
|
2525 header->next = 0;
|
173
|
2526 return header;
|
0
|
2527 }
|
|
2528 #endif
|
|
2529
|
|
2530
|
|
2531
|
20
|
2532 DEFUN ("purecopy", Fpurecopy, 1, 1, 0, /*
|
0
|
2533 Make a copy of OBJECT in pure storage.
|
|
2534 Recursively copies contents of vectors and cons cells.
|
|
2535 Does not copy symbols.
|
20
|
2536 */
|
|
2537 (obj))
|
0
|
2538 {
|
|
2539 int i;
|
|
2540 if (!purify_flag)
|
173
|
2541 return obj;
|
0
|
2542
|
|
2543 if (!POINTER_TYPE_P (XTYPE (obj))
|
|
2544 || PURIFIED (XPNTR (obj)))
|
173
|
2545 return obj;
|
0
|
2546
|
|
2547 switch (XTYPE (obj))
|
|
2548 {
|
|
2549 case Lisp_Cons:
|
|
2550 return pure_cons (XCAR (obj), XCDR (obj));
|
|
2551
|
|
2552 case Lisp_String:
|
16
|
2553 return make_pure_string (XSTRING_DATA (obj),
|
|
2554 XSTRING_LENGTH (obj),
|
0
|
2555 XSTRING (obj)->plist,
|
|
2556 0);
|
|
2557
|
|
2558 case Lisp_Vector:
|
|
2559 {
|
|
2560 struct Lisp_Vector *o = XVECTOR (obj);
|
|
2561 Lisp_Object new = make_pure_vector (vector_length (o), Qnil);
|
|
2562 for (i = 0; i < vector_length (o); i++)
|
173
|
2563 XVECTOR_DATA (new)[i] = Fpurecopy (o->contents[i]);
|
|
2564 return new;
|
0
|
2565 }
|
|
2566
|
|
2567 default:
|
|
2568 {
|
|
2569 if (COMPILED_FUNCTIONP (obj))
|
|
2570 {
|
|
2571 struct Lisp_Compiled_Function *o = XCOMPILED_FUNCTION (obj);
|
|
2572 Lisp_Object new = make_compiled_function (1);
|
104
|
2573 /* How on earth could this code have worked before? -sb */
|
|
2574 struct Lisp_Compiled_Function *n = XCOMPILED_FUNCTION (new);
|
0
|
2575 n->flags = o->flags;
|
|
2576 n->bytecodes = Fpurecopy (o->bytecodes);
|
|
2577 n->constants = Fpurecopy (o->constants);
|
|
2578 n->arglist = Fpurecopy (o->arglist);
|
|
2579 n->doc_and_interactive = Fpurecopy (o->doc_and_interactive);
|
104
|
2580 n->maxdepth = o->maxdepth;
|
173
|
2581 return new;
|
0
|
2582 }
|
|
2583 #ifdef LISP_FLOAT_TYPE
|
|
2584 else if (FLOATP (obj))
|
|
2585 return make_pure_float (float_data (XFLOAT (obj)));
|
|
2586 #endif /* LISP_FLOAT_TYPE */
|
|
2587 else if (!SYMBOLP (obj))
|
|
2588 signal_simple_error ("Can't purecopy %S", obj);
|
|
2589 }
|
|
2590 }
|
173
|
2591 return obj;
|
0
|
2592 }
|
|
2593
|
|
2594
|
|
2595
|
102
|
2596 static void
|
|
2597 PURESIZE_h(long int puresize)
|
|
2598 {
|
|
2599 int fd;
|
104
|
2600 char *PURESIZE_h_file = "puresize_adjust.h";
|
102
|
2601 char *WARNING = "/* This file is generated by XEmacs, DO NOT MODIFY!!! */\n";
|
|
2602 char define_PURESIZE[256];
|
|
2603
|
104
|
2604 if ((fd = open(PURESIZE_h_file, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
|
|
2605 report_file_error("Can't write PURESIZE_ADJUSTMENT",
|
102
|
2606 Fcons(build_ext_string(PURESIZE_h_file, FORMAT_FILENAME),
|
|
2607 Qnil));
|
|
2608 }
|
|
2609
|
|
2610 write(fd, WARNING, strlen(WARNING));
|
108
|
2611 sprintf(define_PURESIZE, "# define PURESIZE_ADJUSTMENT (%ld)\n",
|
104
|
2612 puresize - RAW_PURESIZE);
|
102
|
2613 write(fd, define_PURESIZE, strlen(define_PURESIZE));
|
|
2614 close(fd);
|
|
2615 }
|
|
2616
|
0
|
2617 void
|
|
2618 report_pure_usage (int report_impurities,
|
|
2619 int die_if_pure_storage_exceeded)
|
|
2620 {
|
102
|
2621 int rc = 0;
|
|
2622
|
0
|
2623 if (pure_lossage)
|
|
2624 {
|
|
2625 message ("\n****\tPure Lisp storage exhausted!\n"
|
108
|
2626 "\tPurespace usage: %ld of %ld\n"
|
0
|
2627 "****",
|
171
|
2628 get_PURESIZE()+pure_lossage, (long) get_PURESIZE());
|
102
|
2629 if (die_if_pure_storage_exceeded) {
|
171
|
2630 PURESIZE_h(get_PURESIZE() + pure_lossage);
|
102
|
2631 rc = -1;
|
|
2632 }
|
0
|
2633 }
|
|
2634 else
|
|
2635 {
|
171
|
2636 int lost = (get_PURESIZE() - pureptr) / 1024;
|
0
|
2637 char buf[200];
|
|
2638
|
|
2639 sprintf (buf, "Purespace usage: %ld of %ld (%d%%",
|
171
|
2640 pureptr, (long) get_PURESIZE(),
|
|
2641 (int) (pureptr / (get_PURESIZE() / 100.0) + 0.5));
|
102
|
2642 if (lost > 2) {
|
0
|
2643 sprintf (buf + strlen (buf), " -- %dk wasted", lost);
|
102
|
2644 if (die_if_pure_storage_exceeded) {
|
|
2645 PURESIZE_h(pureptr + 16);
|
|
2646 rc = -1;
|
|
2647 }
|
|
2648 }
|
|
2649
|
0
|
2650 strcat (buf, ").");
|
|
2651 message ("%s", buf);
|
|
2652 }
|
|
2653
|
|
2654 #ifdef PURESTAT
|
|
2655 {
|
|
2656 int iii;
|
|
2657
|
|
2658 purestat_vector_other.nbytes =
|
|
2659 purestat_vector_all.nbytes - purestat_vector_bytecode_constants.nbytes;
|
|
2660 purestat_vector_other.nobjects =
|
|
2661 purestat_vector_all.nobjects -
|
|
2662 purestat_vector_bytecode_constants.nobjects;
|
|
2663
|
|
2664 purestat_string_other.nbytes =
|
|
2665 purestat_string_all.nbytes - (purestat_string_pname.nbytes +
|
|
2666 purestat_string_bytecodes.nbytes +
|
|
2667 purestat_string_interactive.nbytes +
|
|
2668 purestat_string_documentation.nbytes +
|
|
2669 #ifdef I18N3
|
|
2670 purestat_string_domain.nbytes +
|
|
2671 #endif
|
|
2672 purestat_string_other_function.nbytes);
|
|
2673 purestat_string_other.nobjects =
|
|
2674 purestat_string_all.nobjects - (purestat_string_pname.nobjects +
|
|
2675 purestat_string_bytecodes.nobjects +
|
|
2676 purestat_string_interactive.nobjects +
|
|
2677 purestat_string_documentation.nobjects +
|
|
2678 #ifdef I18N3
|
|
2679 purestat_string_domain.nobjects +
|
|
2680 #endif
|
|
2681 purestat_string_other_function.nobjects);
|
|
2682
|
|
2683 message (" %-24stotal: bytes:", "");
|
|
2684
|
|
2685 for (iii = 0; iii < countof (purestats); iii++)
|
|
2686 if (!purestats[iii])
|
|
2687 clear_message ();
|
|
2688 else
|
|
2689 message (" %-24s%5d %7d %2d%%",
|
|
2690 purestats[iii]->name,
|
|
2691 purestats[iii]->nobjects,
|
|
2692 purestats[iii]->nbytes,
|
|
2693 (int) (purestats[iii]->nbytes / (pureptr / 100.0) + 0.5));
|
|
2694 }
|
|
2695 #endif /* PURESTAT */
|
|
2696
|
|
2697
|
|
2698 if (report_impurities)
|
|
2699 {
|
|
2700 Lisp_Object tem = Felt (Fgarbage_collect (), make_int (5));
|
|
2701 struct gcpro gcpro1;
|
|
2702 GCPRO1 (tem);
|
|
2703 message ("\nImpurities:");
|
|
2704 while (!NILP (tem))
|
|
2705 {
|
|
2706 if (CONSP (tem) && SYMBOLP (Fcar (tem)) && CONSP (Fcdr (tem)))
|
|
2707 {
|
|
2708 int total = XINT (Fcar (Fcdr (tem)));
|
|
2709 if (total > 0)
|
|
2710 {
|
|
2711 char buf [100];
|
|
2712 char *s = buf;
|
|
2713 memcpy (buf, string_data (XSYMBOL (Fcar (tem))->name),
|
|
2714 string_length (XSYMBOL (Fcar (tem))->name) + 1);
|
|
2715 while (*s++) if (*s == '-') *s = ' ';
|
|
2716 s--; *s++ = ':'; *s = 0;
|
|
2717 message (" %-32s%6d", buf, total);
|
|
2718 }
|
|
2719 tem = Fcdr (Fcdr (tem));
|
|
2720 }
|
|
2721 else /* WTF?! */
|
|
2722 {
|
|
2723 Fprin1 (tem, Qexternal_debugging_output);
|
|
2724 tem = Qnil;
|
|
2725 }
|
|
2726 }
|
|
2727 UNGCPRO;
|
|
2728 garbage_collect_1 (); /* GC garbage_collect's garbage */
|
|
2729 }
|
|
2730 clear_message ();
|
|
2731
|
102
|
2732 if (rc < 0) {
|
112
|
2733 (void)unlink("SATISFIED");
|
118
|
2734 /* Current build process on NT does */
|
|
2735 /* not know how to restart itself. */
|
|
2736 /* --marcpa */
|
|
2737 #ifndef WINDOWSNT
|
171
|
2738 fatal ("Pure size adjusted, Don't Panic! I will restart the `make'");
|
118
|
2739 #endif
|
102
|
2740 } else if (pure_lossage && die_if_pure_storage_exceeded) {
|
0
|
2741 fatal ("Pure storage exhausted");
|
102
|
2742 }
|
0
|
2743 }
|
|
2744
|
|
2745
|
|
2746 /**********************************************************************/
|
|
2747 /* staticpro */
|
|
2748 /**********************************************************************/
|
|
2749
|
|
2750 struct gcpro *gcprolist;
|
|
2751
|
|
2752 /* 415 used Mly 29-Jun-93 */
|
|
2753 #define NSTATICS 1500
|
|
2754 /* Not "static" because of linker lossage on some systems */
|
|
2755 Lisp_Object *staticvec[NSTATICS]
|
|
2756 /* Force it into data space! */
|
|
2757 = {0};
|
|
2758 static int staticidx;
|
|
2759
|
|
2760 /* Put an entry in staticvec, pointing at the variable whose address is given
|
|
2761 */
|
|
2762 void
|
|
2763 staticpro (Lisp_Object *varaddress)
|
|
2764 {
|
|
2765 if (staticidx >= countof (staticvec))
|
|
2766 abort ();
|
|
2767 staticvec[staticidx++] = varaddress;
|
|
2768 }
|
|
2769
|
|
2770
|
|
2771 /* Mark reference to a Lisp_Object. If the object referred to has not been
|
|
2772 seen yet, recursively mark all the references contained in it. */
|
|
2773
|
|
2774 static void
|
|
2775 mark_object (Lisp_Object obj)
|
|
2776 {
|
|
2777 tail_recurse:
|
|
2778
|
|
2779 if (!POINTER_TYPE_P (XGCTYPE (obj)))
|
|
2780 return;
|
|
2781 if (PURIFIED (XPNTR (obj)))
|
|
2782 return;
|
|
2783 switch (XGCTYPE (obj))
|
|
2784 {
|
|
2785 case Lisp_Cons:
|
|
2786 {
|
|
2787 struct Lisp_Cons *ptr = XCONS (obj);
|
|
2788 if (CONS_MARKED_P (ptr))
|
|
2789 break;
|
|
2790 MARK_CONS (ptr);
|
|
2791 /* If the cdr is nil, tail-recurse on the car. */
|
|
2792 if (NILP (ptr->cdr))
|
|
2793 {
|
|
2794 obj = ptr->car;
|
|
2795 }
|
|
2796 else
|
|
2797 {
|
|
2798 mark_object (ptr->car);
|
|
2799 obj = ptr->cdr;
|
|
2800 }
|
|
2801 goto tail_recurse;
|
|
2802 }
|
|
2803
|
|
2804 case Lisp_Record:
|
|
2805 /* case Lisp_Symbol_Value_Magic: */
|
|
2806 {
|
|
2807 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
|
|
2808 CONST struct lrecord_implementation *implementation
|
|
2809 = lheader->implementation;
|
|
2810
|
|
2811 if (! MARKED_RECORD_HEADER_P (lheader) &&
|
|
2812 ! UNMARKABLE_RECORD_HEADER_P (lheader))
|
|
2813 {
|
|
2814 MARK_RECORD_HEADER (lheader);
|
|
2815 #ifdef ERROR_CHECK_GC
|
|
2816 if (!implementation->basic_p)
|
|
2817 assert (! ((struct lcrecord_header *) lheader)->free);
|
|
2818 #endif
|
|
2819 if (implementation->marker != 0)
|
|
2820 {
|
|
2821 obj = ((implementation->marker) (obj, mark_object));
|
|
2822 if (!NILP (obj)) goto tail_recurse;
|
|
2823 }
|
|
2824 }
|
|
2825 }
|
|
2826 break;
|
|
2827
|
|
2828 case Lisp_String:
|
|
2829 {
|
|
2830 struct Lisp_String *ptr = XSTRING (obj);
|
|
2831
|
|
2832 if (!XMARKBIT (ptr->plist))
|
|
2833 {
|
|
2834 if (CONSP (ptr->plist) &&
|
|
2835 EXTENT_INFOP (XCAR (ptr->plist)))
|
|
2836 flush_cached_extent_info (XCAR (ptr->plist));
|
|
2837 XMARK (ptr->plist);
|
|
2838 obj = ptr->plist;
|
|
2839 goto tail_recurse;
|
|
2840 }
|
|
2841 }
|
|
2842 break;
|
|
2843
|
|
2844 case Lisp_Vector:
|
|
2845 {
|
|
2846 struct Lisp_Vector *ptr = XVECTOR (obj);
|
|
2847 int len = vector_length (ptr);
|
|
2848 int i;
|
|
2849
|
|
2850 if (len < 0)
|
|
2851 break; /* Already marked */
|
|
2852 ptr->size = -1 - len; /* Else mark it */
|
|
2853 for (i = 0; i < len - 1; i++) /* and then mark its elements */
|
|
2854 mark_object (ptr->contents[i]);
|
|
2855 if (len > 0)
|
|
2856 {
|
|
2857 obj = ptr->contents[len - 1];
|
|
2858 goto tail_recurse;
|
|
2859 }
|
|
2860 }
|
|
2861 break;
|
|
2862
|
|
2863 #ifndef LRECORD_SYMBOL
|
|
2864 case Lisp_Symbol:
|
|
2865 {
|
|
2866 struct Lisp_Symbol *sym = XSYMBOL (obj);
|
|
2867
|
|
2868 while (!XMARKBIT (sym->plist))
|
|
2869 {
|
|
2870 XMARK (sym->plist);
|
|
2871 mark_object (sym->value);
|
|
2872 mark_object (sym->function);
|
|
2873 {
|
|
2874 /* Open-code mark_string */
|
|
2875 /* symbol->name is a struct Lisp_String *, not a Lisp_Object */
|
|
2876 struct Lisp_String *pname = sym->name;
|
|
2877 if (!PURIFIED (pname)
|
|
2878 && !XMARKBIT (pname->plist))
|
|
2879 {
|
|
2880 XMARK (pname->plist);
|
|
2881 mark_object (pname->plist);
|
|
2882 }
|
|
2883 }
|
|
2884 if (!symbol_next (sym))
|
|
2885 {
|
|
2886 obj = sym->plist;
|
|
2887 goto tail_recurse;
|
|
2888 }
|
|
2889 mark_object (sym->plist);
|
|
2890 /* Mark the rest of the symbols in the hash-chain */
|
|
2891 sym = symbol_next (sym);
|
|
2892 }
|
|
2893 }
|
|
2894 break;
|
|
2895 #endif /* !LRECORD_SYMBOL */
|
|
2896
|
|
2897 default:
|
|
2898 abort ();
|
|
2899 }
|
|
2900 }
|
|
2901
|
|
2902 /* mark all of the conses in a list and mark the final cdr; but
|
|
2903 DO NOT mark the cars.
|
|
2904
|
|
2905 Use only for internal lists! There should never be other pointers
|
|
2906 to the cons cells, because if so, the cars will remain unmarked
|
|
2907 even when they maybe should be marked. */
|
|
2908 void
|
|
2909 mark_conses_in_list (Lisp_Object obj)
|
|
2910 {
|
|
2911 Lisp_Object rest;
|
|
2912
|
|
2913 for (rest = obj; CONSP (rest); rest = XCDR (rest))
|
|
2914 {
|
|
2915 if (CONS_MARKED_P (XCONS (rest)))
|
|
2916 return;
|
|
2917 MARK_CONS (XCONS (rest));
|
|
2918 }
|
|
2919
|
|
2920 mark_object (rest);
|
|
2921 }
|
|
2922
|
|
2923
|
|
2924 #ifdef PURESTAT
|
|
2925 /* Simpler than mark-object, because pure structure can't
|
|
2926 have any circularities
|
|
2927 */
|
|
2928
|
|
2929 #if 0 /* unused */
|
|
2930 static int idiot_c_doesnt_have_closures;
|
|
2931 static void
|
|
2932 idiot_c (Lisp_Object obj)
|
|
2933 {
|
|
2934 idiot_c_doesnt_have_closures += pure_sizeof (obj, 1);
|
|
2935 }
|
|
2936 #endif /* unused */
|
|
2937
|
|
2938 /* recurse arg isn't actually used */
|
|
2939 static int
|
|
2940 pure_sizeof (Lisp_Object obj /*, int recurse */)
|
|
2941 {
|
|
2942 int total = 0;
|
|
2943
|
|
2944 /*tail_recurse: */
|
|
2945 if (!POINTER_TYPE_P (XTYPE (obj))
|
|
2946 || !PURIFIED (XPNTR (obj)))
|
173
|
2947 return total;
|
0
|
2948
|
|
2949 /* symbol's sizes are accounted for separately */
|
|
2950 if (SYMBOLP (obj))
|
173
|
2951 return total;
|
0
|
2952
|
|
2953 switch (XTYPE (obj))
|
|
2954 {
|
|
2955 case Lisp_String:
|
|
2956 {
|
|
2957 struct Lisp_String *ptr = XSTRING (obj);
|
|
2958 int size = string_length (ptr);
|
|
2959
|
|
2960 if (string_data (ptr) !=
|
|
2961 (unsigned char *) ptr + sizeof (struct Lisp_String))
|
|
2962 {
|
|
2963 /* string-data not allocated contiguously.
|
|
2964 Probably (better be!!) a pointer constant "C" data. */
|
|
2965 size = sizeof (struct Lisp_String);
|
|
2966 }
|
|
2967 else
|
|
2968 {
|
|
2969 size = sizeof (struct Lisp_String) + size + 1;
|
|
2970 size = ALIGN_SIZE (size, sizeof (Lisp_Object));
|
|
2971 }
|
|
2972 total += size;
|
|
2973 }
|
|
2974 break;
|
|
2975
|
|
2976 case Lisp_Vector:
|
|
2977 {
|
|
2978 struct Lisp_Vector *ptr = XVECTOR (obj);
|
|
2979 int len = vector_length (ptr);
|
|
2980
|
|
2981 total += (sizeof (struct Lisp_Vector)
|
|
2982 + (len - 1) * sizeof (Lisp_Object));
|
|
2983 #if 0 /* unused */
|
|
2984 if (!recurse)
|
|
2985 break;
|
|
2986 {
|
|
2987 int i;
|
|
2988 for (i = 0; i < len - 1; i++)
|
|
2989 total += pure_sizeof (ptr->contents[i], 1);
|
|
2990 }
|
|
2991 if (len > 0)
|
|
2992 {
|
|
2993 obj = ptr->contents[len - 1];
|
|
2994 goto tail_recurse;
|
|
2995 }
|
|
2996 #endif /* unused */
|
|
2997 }
|
|
2998 break;
|
|
2999
|
|
3000 case Lisp_Record:
|
|
3001 {
|
|
3002 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
|
|
3003 CONST struct lrecord_implementation *implementation
|
|
3004 = lheader->implementation;
|
|
3005
|
|
3006 if (implementation->size_in_bytes_method)
|
|
3007 total += ((implementation->size_in_bytes_method) (lheader));
|
|
3008 else
|
|
3009 total += implementation->static_size;
|
|
3010
|
|
3011 #if 0 /* unused */
|
|
3012 if (!recurse)
|
|
3013 break;
|
|
3014
|
|
3015 if (implementation->marker != 0)
|
|
3016 {
|
|
3017 int old = idiot_c_doesnt_have_closures;
|
|
3018
|
|
3019 idiot_c_doesnt_have_closures = 0;
|
|
3020 obj = ((implementation->marker) (obj, idiot_c));
|
|
3021 total += idiot_c_doesnt_have_closures;
|
|
3022 idiot_c_doesnt_have_closures = old;
|
|
3023
|
|
3024 if (!NILP (obj)) goto tail_recurse;
|
|
3025 }
|
|
3026 #endif /* unused */
|
|
3027 }
|
|
3028 break;
|
|
3029
|
|
3030 case Lisp_Cons:
|
|
3031 {
|
|
3032 struct Lisp_Cons *ptr = XCONS (obj);
|
|
3033 total += sizeof (*ptr);
|
|
3034 #if 0 /* unused */
|
|
3035 if (!recurse)
|
|
3036 break;
|
|
3037 /* If the cdr is nil, tail-recurse on the car. */
|
|
3038 if (NILP (ptr->cdr))
|
|
3039 {
|
|
3040 obj = ptr->car;
|
|
3041 }
|
|
3042 else
|
|
3043 {
|
|
3044 total += pure_sizeof (ptr->car, 1);
|
|
3045 obj = ptr->cdr;
|
|
3046 }
|
|
3047 goto tail_recurse;
|
|
3048 #endif /* unused */
|
|
3049 }
|
|
3050 break;
|
|
3051
|
|
3052 /* Others can't be purified */
|
|
3053 default:
|
|
3054 abort ();
|
|
3055 }
|
173
|
3056 return total;
|
0
|
3057 }
|
|
3058 #endif /* PURESTAT */
|
|
3059
|
|
3060
|
|
3061
|
|
3062
|
|
3063 /* Find all structures not marked, and free them. */
|
|
3064
|
|
3065 static int gc_count_num_vector_used, gc_count_vector_total_size;
|
|
3066 static int gc_count_vector_storage;
|
|
3067 static int gc_count_num_bit_vector_used, gc_count_bit_vector_total_size;
|
|
3068 static int gc_count_bit_vector_storage;
|
|
3069 static int gc_count_num_short_string_in_use;
|
|
3070 static int gc_count_string_total_size;
|
|
3071 static int gc_count_short_string_total_size;
|
|
3072
|
|
3073 /* static int gc_count_total_records_used, gc_count_records_total_size; */
|
|
3074
|
|
3075
|
|
3076 /* This will be used more extensively In The Future */
|
|
3077 static int last_lrecord_type_index_assigned;
|
|
3078
|
|
3079 static CONST struct lrecord_implementation *lrecord_implementations_table[128];
|
|
3080 #define max_lrecord_type (countof (lrecord_implementations_table) - 1)
|
|
3081
|
|
3082 static int
|
|
3083 lrecord_type_index (CONST struct lrecord_implementation *implementation)
|
|
3084 {
|
|
3085 int type_index = *(implementation->lrecord_type_index);
|
|
3086 /* Have to do this circuitous and validation test because of problems
|
|
3087 dumping out initialized variables (ie can't set xxx_type_index to -1
|
|
3088 because that would make xxx_type_index read-only in a dumped emacs. */
|
|
3089 if (type_index < 0 || type_index > max_lrecord_type
|
|
3090 || lrecord_implementations_table[type_index] != implementation)
|
|
3091 {
|
|
3092 if (last_lrecord_type_index_assigned == max_lrecord_type)
|
|
3093 abort ();
|
|
3094 type_index = ++last_lrecord_type_index_assigned;
|
|
3095 lrecord_implementations_table[type_index] = implementation;
|
|
3096 *(implementation->lrecord_type_index) = type_index;
|
|
3097 }
|
173
|
3098 return type_index;
|
0
|
3099 }
|
|
3100
|
|
3101 /* stats on lcrecords in use - kinda kludgy */
|
|
3102
|
|
3103 static struct
|
|
3104 {
|
|
3105 int instances_in_use;
|
|
3106 int bytes_in_use;
|
|
3107 int instances_freed;
|
|
3108 int bytes_freed;
|
|
3109 int instances_on_free_list;
|
|
3110 } lcrecord_stats [countof (lrecord_implementations_table)];
|
|
3111
|
|
3112
|
|
3113 static void
|
|
3114 reset_lcrecord_stats (void)
|
|
3115 {
|
|
3116 int i;
|
|
3117 for (i = 0; i < countof (lcrecord_stats); i++)
|
|
3118 {
|
|
3119 lcrecord_stats[i].instances_in_use = 0;
|
|
3120 lcrecord_stats[i].bytes_in_use = 0;
|
|
3121 lcrecord_stats[i].instances_freed = 0;
|
|
3122 lcrecord_stats[i].bytes_freed = 0;
|
|
3123 lcrecord_stats[i].instances_on_free_list = 0;
|
|
3124 }
|
|
3125 }
|
|
3126
|
|
3127 static void
|
|
3128 tick_lcrecord_stats (CONST struct lrecord_header *h, int free_p)
|
|
3129 {
|
|
3130 CONST struct lrecord_implementation *implementation = h->implementation;
|
|
3131 int type_index = lrecord_type_index (implementation);
|
|
3132
|
|
3133 if (((struct lcrecord_header *) h)->free)
|
|
3134 {
|
|
3135 assert (!free_p);
|
|
3136 lcrecord_stats[type_index].instances_on_free_list++;
|
|
3137 }
|
|
3138 else
|
|
3139 {
|
|
3140 unsigned int sz = (implementation->size_in_bytes_method
|
|
3141 ? ((implementation->size_in_bytes_method) (h))
|
|
3142 : implementation->static_size);
|
|
3143
|
|
3144 if (free_p)
|
|
3145 {
|
|
3146 lcrecord_stats[type_index].instances_freed++;
|
|
3147 lcrecord_stats[type_index].bytes_freed += sz;
|
|
3148 }
|
|
3149 else
|
|
3150 {
|
|
3151 lcrecord_stats[type_index].instances_in_use++;
|
|
3152 lcrecord_stats[type_index].bytes_in_use += sz;
|
|
3153 }
|
|
3154 }
|
|
3155 }
|
|
3156
|
|
3157
|
|
3158 /* Free all unmarked records */
|
|
3159 static void
|
|
3160 sweep_lcrecords_1 (struct lcrecord_header **prev, int *used)
|
|
3161 {
|
|
3162 struct lcrecord_header *header;
|
|
3163 int num_used = 0;
|
|
3164 /* int total_size = 0; */
|
|
3165 reset_lcrecord_stats ();
|
|
3166
|
|
3167 /* First go through and call all the finalize methods.
|
|
3168 Then go through and free the objects. There used to
|
|
3169 be only one loop here, with the call to the finalizer
|
|
3170 occurring directly before the xfree() below. That
|
|
3171 is marginally faster but much less safe -- if the
|
|
3172 finalize method for an object needs to reference any
|
|
3173 other objects contained within it (and many do),
|
|
3174 we could easily be screwed by having already freed that
|
|
3175 other object. */
|
|
3176
|
|
3177 for (header = *prev; header; header = header->next)
|
|
3178 {
|
|
3179 struct lrecord_header *h = &(header->lheader);
|
|
3180 if (!MARKED_RECORD_HEADER_P (h) && ! (header->free))
|
|
3181 {
|
|
3182 if (h->implementation->finalizer)
|
|
3183 ((h->implementation->finalizer) (h, 0));
|
|
3184 }
|
|
3185 }
|
|
3186
|
|
3187 for (header = *prev; header; )
|
|
3188 {
|
|
3189 struct lrecord_header *h = &(header->lheader);
|
|
3190 if (MARKED_RECORD_HEADER_P (h))
|
|
3191 {
|
|
3192 UNMARK_RECORD_HEADER (h);
|
|
3193 num_used++;
|
|
3194 /* total_size += ((n->implementation->size_in_bytes) (h));*/
|
|
3195 prev = &(header->next);
|
|
3196 header = *prev;
|
|
3197 tick_lcrecord_stats (h, 0);
|
|
3198 }
|
|
3199 else
|
|
3200 {
|
|
3201 struct lcrecord_header *next = header->next;
|
|
3202 *prev = next;
|
|
3203 tick_lcrecord_stats (h, 1);
|
|
3204 /* used to call finalizer right here. */
|
|
3205 xfree (header);
|
|
3206 header = next;
|
|
3207 }
|
|
3208 }
|
|
3209 *used = num_used;
|
|
3210 /* *total = total_size; */
|
|
3211 }
|
|
3212
|
|
3213 static void
|
|
3214 sweep_vectors_1 (Lisp_Object *prev,
|
|
3215 int *used, int *total, int *storage)
|
|
3216 {
|
|
3217 Lisp_Object vector;
|
|
3218 int num_used = 0;
|
|
3219 int total_size = 0;
|
|
3220 int total_storage = 0;
|
|
3221
|
|
3222 for (vector = *prev; VECTORP (vector); )
|
|
3223 {
|
|
3224 struct Lisp_Vector *v = XVECTOR (vector);
|
|
3225 int len = v->size;
|
|
3226 if (len < 0) /* marked */
|
|
3227 {
|
|
3228 len = - (len + 1);
|
|
3229 v->size = len;
|
|
3230 total_size += len;
|
|
3231 total_storage += (MALLOC_OVERHEAD
|
|
3232 + sizeof (struct Lisp_Vector)
|
|
3233 + (len - 1 + 1) * sizeof (Lisp_Object));
|
|
3234 num_used++;
|
|
3235 prev = &(vector_next (v));
|
|
3236 vector = *prev;
|
|
3237 }
|
|
3238 else
|
|
3239 {
|
|
3240 Lisp_Object next = vector_next (v);
|
|
3241 *prev = next;
|
|
3242 xfree (v);
|
|
3243 vector = next;
|
|
3244 }
|
|
3245 }
|
|
3246 *used = num_used;
|
|
3247 *total = total_size;
|
|
3248 *storage = total_storage;
|
|
3249 }
|
|
3250
|
|
3251 static void
|
|
3252 sweep_bit_vectors_1 (Lisp_Object *prev,
|
|
3253 int *used, int *total, int *storage)
|
|
3254 {
|
|
3255 Lisp_Object bit_vector;
|
|
3256 int num_used = 0;
|
|
3257 int total_size = 0;
|
|
3258 int total_storage = 0;
|
|
3259
|
|
3260 /* BIT_VECTORP fails because the objects are marked, which changes
|
|
3261 their implementation */
|
|
3262 for (bit_vector = *prev; !EQ (bit_vector, Qzero); )
|
|
3263 {
|
|
3264 struct Lisp_Bit_Vector *v = XBIT_VECTOR (bit_vector);
|
|
3265 int len = v->size;
|
|
3266 if (MARKED_RECORD_P (bit_vector))
|
|
3267 {
|
|
3268 UNMARK_RECORD_HEADER (&(v->lheader));
|
|
3269 total_size += len;
|
|
3270 total_storage += (MALLOC_OVERHEAD
|
|
3271 + sizeof (struct Lisp_Bit_Vector)
|
|
3272 + (BIT_VECTOR_LONG_STORAGE (len) - 1)
|
|
3273 * sizeof (long));
|
|
3274 num_used++;
|
|
3275 prev = &(bit_vector_next (v));
|
|
3276 bit_vector = *prev;
|
|
3277 }
|
|
3278 else
|
|
3279 {
|
|
3280 Lisp_Object next = bit_vector_next (v);
|
|
3281 *prev = next;
|
|
3282 xfree (v);
|
|
3283 bit_vector = next;
|
|
3284 }
|
|
3285 }
|
|
3286 *used = num_used;
|
|
3287 *total = total_size;
|
|
3288 *storage = total_storage;
|
|
3289 }
|
|
3290
|
|
3291 /* And the Lord said: Thou shalt use the `c-backslash-region' command
|
|
3292 to make macros prettier. */
|
|
3293
|
|
3294 #ifdef ERROR_CHECK_GC
|
|
3295
|
|
3296 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \
|
|
3297 do { \
|
|
3298 struct typename##_block *_frob_current; \
|
|
3299 struct typename##_block **_frob_prev; \
|
|
3300 int _frob_limit; \
|
|
3301 int num_free = 0, num_used = 0; \
|
|
3302 \
|
|
3303 for (_frob_prev = ¤t_##typename##_block, \
|
|
3304 _frob_current = current_##typename##_block, \
|
|
3305 _frob_limit = current_##typename##_block_index; \
|
|
3306 _frob_current; \
|
|
3307 ) \
|
|
3308 { \
|
|
3309 int _frob_iii; \
|
|
3310 \
|
|
3311 for (_frob_iii = 0; _frob_iii < _frob_limit; _frob_iii++) \
|
|
3312 { \
|
|
3313 obj_type *_frob_victim = &(_frob_current->block[_frob_iii]); \
|
|
3314 \
|
|
3315 if (FREE_STRUCT_P (_frob_victim)) \
|
|
3316 { \
|
|
3317 num_free++; \
|
|
3318 } \
|
|
3319 else if (!MARKED_##typename##_P (_frob_victim)) \
|
|
3320 { \
|
|
3321 num_free++; \
|
|
3322 FREE_FIXED_TYPE (typename, obj_type, _frob_victim); \
|
|
3323 } \
|
|
3324 else \
|
|
3325 { \
|
|
3326 num_used++; \
|
|
3327 UNMARK_##typename (_frob_victim); \
|
|
3328 } \
|
|
3329 } \
|
|
3330 _frob_prev = &(_frob_current->prev); \
|
|
3331 _frob_current = _frob_current->prev; \
|
|
3332 _frob_limit = countof (current_##typename##_block->block); \
|
|
3333 } \
|
|
3334 \
|
|
3335 gc_count_num_##typename##_in_use = num_used; \
|
|
3336 gc_count_num_##typename##_freelist = num_free; \
|
|
3337 } while (0)
|
|
3338
|
|
3339 #else
|
|
3340
|
|
3341 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \
|
|
3342 do { \
|
|
3343 struct typename##_block *_frob_current; \
|
|
3344 struct typename##_block **_frob_prev; \
|
|
3345 int _frob_limit; \
|
|
3346 int num_free = 0, num_used = 0; \
|
|
3347 \
|
|
3348 typename##_free_list = 0; \
|
|
3349 \
|
|
3350 for (_frob_prev = ¤t_##typename##_block, \
|
|
3351 _frob_current = current_##typename##_block, \
|
|
3352 _frob_limit = current_##typename##_block_index; \
|
|
3353 _frob_current; \
|
|
3354 ) \
|
|
3355 { \
|
|
3356 int _frob_iii; \
|
|
3357 int _frob_empty = 1; \
|
|
3358 obj_type *_frob_old_free_list = typename##_free_list; \
|
|
3359 \
|
|
3360 for (_frob_iii = 0; _frob_iii < _frob_limit; _frob_iii++) \
|
|
3361 { \
|
|
3362 obj_type *_frob_victim = &(_frob_current->block[_frob_iii]); \
|
|
3363 \
|
|
3364 if (FREE_STRUCT_P (_frob_victim)) \
|
|
3365 { \
|
|
3366 num_free++; \
|
|
3367 PUT_FIXED_TYPE_ON_FREE_LIST (typename, obj_type, _frob_victim); \
|
|
3368 } \
|
|
3369 else if (!MARKED_##typename##_P (_frob_victim)) \
|
|
3370 { \
|
|
3371 num_free++; \
|
|
3372 FREE_FIXED_TYPE (typename, obj_type, _frob_victim); \
|
|
3373 } \
|
|
3374 else \
|
|
3375 { \
|
|
3376 _frob_empty = 0; \
|
|
3377 num_used++; \
|
|
3378 UNMARK_##typename (_frob_victim); \
|
|
3379 } \
|
|
3380 } \
|
|
3381 if (!_frob_empty) \
|
|
3382 { \
|
|
3383 _frob_prev = &(_frob_current->prev); \
|
|
3384 _frob_current = _frob_current->prev; \
|
|
3385 } \
|
|
3386 else if (_frob_current == current_##typename##_block \
|
|
3387 && !_frob_current->prev) \
|
|
3388 { \
|
|
3389 /* No real point in freeing sole allocation block */ \
|
|
3390 break; \
|
|
3391 } \
|
|
3392 else \
|
|
3393 { \
|
|
3394 struct typename##_block *_frob_victim_block = _frob_current; \
|
|
3395 if (_frob_victim_block == current_##typename##_block) \
|
|
3396 current_##typename##_block_index \
|
|
3397 = countof (current_##typename##_block->block); \
|
|
3398 _frob_current = _frob_current->prev; \
|
|
3399 { \
|
|
3400 *_frob_prev = _frob_current; \
|
|
3401 xfree (_frob_victim_block); \
|
|
3402 /* Restore free list to what it was before victim was swept */ \
|
|
3403 typename##_free_list = _frob_old_free_list; \
|
|
3404 num_free -= _frob_limit; \
|
|
3405 } \
|
|
3406 } \
|
|
3407 _frob_limit = countof (current_##typename##_block->block); \
|
|
3408 } \
|
|
3409 \
|
|
3410 gc_count_num_##typename##_in_use = num_used; \
|
|
3411 gc_count_num_##typename##_freelist = num_free; \
|
|
3412 } while (0)
|
|
3413
|
|
3414 #endif
|
|
3415
|
|
3416
|
|
3417
|
|
3418
|
|
3419 static void
|
|
3420 sweep_conses (void)
|
|
3421 {
|
|
3422 #define MARKED_cons_P(ptr) XMARKBIT ((ptr)->car)
|
|
3423 #define UNMARK_cons(ptr) do { XUNMARK ((ptr)->car); } while (0)
|
|
3424 #define ADDITIONAL_FREE_cons(ptr)
|
|
3425
|
|
3426 SWEEP_FIXED_TYPE_BLOCK (cons, struct Lisp_Cons);
|
|
3427 }
|
|
3428
|
|
3429 /* Explicitly free a cons cell. */
|
|
3430 void
|
|
3431 free_cons (struct Lisp_Cons *ptr)
|
|
3432 {
|
|
3433 #ifdef ERROR_CHECK_GC
|
|
3434 /* If the CAR is not an int, then it will be a pointer, which will
|
|
3435 always be four-byte aligned. If this cons cell has already been
|
|
3436 placed on the free list, however, its car will probably contain
|
|
3437 a chain pointer to the next cons on the list, which has cleverly
|
|
3438 had all its 0's and 1's inverted. This allows for a quick
|
|
3439 check to make sure we're not freeing something already freed. */
|
|
3440 if (POINTER_TYPE_P (XTYPE (ptr->car)))
|
|
3441 ASSERT_VALID_POINTER (XPNTR (ptr->car));
|
|
3442 #endif
|
|
3443 #ifndef ALLOC_NO_POOLS
|
|
3444 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (cons, struct Lisp_Cons, ptr);
|
|
3445 #endif /* ALLOC_NO_POOLS */
|
|
3446 }
|
|
3447
|
|
3448 /* explicitly free a list. You **must make sure** that you have
|
|
3449 created all the cons cells that make up this list and that there
|
|
3450 are no pointers to any of these cons cells anywhere else. If there
|
|
3451 are, you will lose. */
|
|
3452
|
|
3453 void
|
|
3454 free_list (Lisp_Object list)
|
|
3455 {
|
|
3456 Lisp_Object rest, next;
|
|
3457
|
|
3458 for (rest = list; !NILP (rest); rest = next)
|
|
3459 {
|
|
3460 next = XCDR (rest);
|
|
3461 free_cons (XCONS (rest));
|
|
3462 }
|
|
3463 }
|
|
3464
|
|
3465 /* explicitly free an alist. You **must make sure** that you have
|
|
3466 created all the cons cells that make up this alist and that there
|
|
3467 are no pointers to any of these cons cells anywhere else. If there
|
|
3468 are, you will lose. */
|
|
3469
|
|
3470 void
|
|
3471 free_alist (Lisp_Object alist)
|
|
3472 {
|
|
3473 Lisp_Object rest, next;
|
|
3474
|
|
3475 for (rest = alist; !NILP (rest); rest = next)
|
|
3476 {
|
|
3477 next = XCDR (rest);
|
|
3478 free_cons (XCONS (XCAR (rest)));
|
|
3479 free_cons (XCONS (rest));
|
|
3480 }
|
|
3481 }
|
|
3482
|
|
3483 static void
|
|
3484 sweep_compiled_functions (void)
|
|
3485 {
|
|
3486 #define MARKED_compiled_function_P(ptr) \
|
|
3487 MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3488 #define UNMARK_compiled_function(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3489 #define ADDITIONAL_FREE_compiled_function(ptr)
|
|
3490
|
|
3491 SWEEP_FIXED_TYPE_BLOCK (compiled_function, struct Lisp_Compiled_Function);
|
|
3492 }
|
|
3493
|
|
3494
|
|
3495 #ifdef LISP_FLOAT_TYPE
|
|
3496 static void
|
|
3497 sweep_floats (void)
|
|
3498 {
|
|
3499 #define MARKED_float_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3500 #define UNMARK_float(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3501 #define ADDITIONAL_FREE_float(ptr)
|
|
3502
|
|
3503 SWEEP_FIXED_TYPE_BLOCK (float, struct Lisp_Float);
|
|
3504 }
|
|
3505 #endif /* LISP_FLOAT_TYPE */
|
|
3506
|
|
3507 static void
|
|
3508 sweep_symbols (void)
|
|
3509 {
|
|
3510 #ifndef LRECORD_SYMBOL
|
|
3511 # define MARKED_symbol_P(ptr) XMARKBIT ((ptr)->plist)
|
|
3512 # define UNMARK_symbol(ptr) do { XUNMARK ((ptr)->plist); } while (0)
|
|
3513 #else
|
|
3514 # define MARKED_symbol_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3515 # define UNMARK_symbol(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3516 #endif /* !LRECORD_SYMBOL */
|
|
3517 #define ADDITIONAL_FREE_symbol(ptr)
|
|
3518
|
|
3519 SWEEP_FIXED_TYPE_BLOCK (symbol, struct Lisp_Symbol);
|
|
3520 }
|
|
3521
|
|
3522
|
|
3523 #ifndef standalone
|
|
3524
|
|
3525 static void
|
|
3526 sweep_extents (void)
|
|
3527 {
|
|
3528 #define MARKED_extent_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3529 #define UNMARK_extent(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3530 #define ADDITIONAL_FREE_extent(ptr)
|
|
3531
|
|
3532 SWEEP_FIXED_TYPE_BLOCK (extent, struct extent);
|
|
3533 }
|
|
3534
|
|
3535 static void
|
|
3536 sweep_events (void)
|
|
3537 {
|
|
3538 #define MARKED_event_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3539 #define UNMARK_event(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3540 #define ADDITIONAL_FREE_event(ptr)
|
|
3541
|
|
3542 SWEEP_FIXED_TYPE_BLOCK (event, struct Lisp_Event);
|
|
3543 }
|
|
3544
|
|
3545 static void
|
|
3546 sweep_markers (void)
|
|
3547 {
|
|
3548 #define MARKED_marker_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3549 #define UNMARK_marker(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3550 #define ADDITIONAL_FREE_marker(ptr) \
|
|
3551 do { Lisp_Object tem; \
|
|
3552 XSETMARKER (tem, ptr); \
|
|
3553 unchain_marker (tem); \
|
|
3554 } while (0)
|
|
3555
|
|
3556 SWEEP_FIXED_TYPE_BLOCK (marker, struct Lisp_Marker);
|
|
3557 }
|
|
3558
|
|
3559 /* Explicitly free a marker. */
|
|
3560 void
|
|
3561 free_marker (struct Lisp_Marker *ptr)
|
|
3562 {
|
|
3563 #ifdef ERROR_CHECK_GC
|
|
3564 /* Perhaps this will catch freeing an already-freed marker. */
|
|
3565 Lisp_Object temmy;
|
|
3566 XSETMARKER (temmy, ptr);
|
|
3567 assert (GC_MARKERP (temmy));
|
|
3568 #endif
|
|
3569 #ifndef ALLOC_NO_POOLS
|
|
3570 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (marker, struct Lisp_Marker, ptr);
|
|
3571 #endif /* ALLOC_NO_POOLS */
|
|
3572 }
|
|
3573
|
|
3574 #endif /* not standalone */
|
|
3575
|
|
3576
|
70
|
3577
|
|
3578 #if defined (MULE) && defined (VERIFY_STRING_CHARS_INTEGRITY)
|
|
3579
|
|
3580 static void
|
|
3581 verify_string_chars_integrity (void)
|
|
3582 {
|
|
3583 struct string_chars_block *sb;
|
|
3584
|
|
3585 /* Scan each existing string block sequentially, string by string. */
|
|
3586 for (sb = first_string_chars_block; sb; sb = sb->next)
|
|
3587 {
|
|
3588 int pos = 0;
|
|
3589 /* POS is the index of the next string in the block. */
|
|
3590 while (pos < sb->pos)
|
|
3591 {
|
|
3592 struct string_chars *s_chars =
|
|
3593 (struct string_chars *) &(sb->string_chars[pos]);
|
|
3594 struct Lisp_String *string;
|
|
3595 int size;
|
|
3596 int fullsize;
|
|
3597
|
|
3598 /* If the string_chars struct is marked as free (i.e. the STRING
|
|
3599 pointer is 0xFFFFFFFF) then this is an unused chunk of string
|
|
3600 storage. (See below.) */
|
|
3601
|
|
3602 if (FREE_STRUCT_P (s_chars))
|
|
3603 {
|
|
3604 fullsize = ((struct unused_string_chars *) s_chars)->fullsize;
|
|
3605 pos += fullsize;
|
|
3606 continue;
|
|
3607 }
|
|
3608
|
|
3609 string = s_chars->string;
|
|
3610 /* Must be 32-bit aligned. */
|
|
3611 assert ((((int) string) & 3) == 0);
|
|
3612
|
|
3613 size = string_length (string);
|
|
3614 fullsize = STRING_FULLSIZE (size);
|
|
3615
|
|
3616 assert (!BIG_STRING_FULLSIZE_P (fullsize));
|
|
3617 assert (string_data (string) == s_chars->chars);
|
|
3618 pos += fullsize;
|
|
3619 }
|
|
3620 assert (pos == sb->pos);
|
|
3621 }
|
|
3622 }
|
|
3623
|
|
3624 #endif /* MULE && ERROR_CHECK_GC */
|
|
3625
|
0
|
3626 /* Compactify string chars, relocating the reference to each --
|
|
3627 free any empty string_chars_block we see. */
|
|
3628 static void
|
|
3629 compact_string_chars (void)
|
|
3630 {
|
|
3631 struct string_chars_block *to_sb = first_string_chars_block;
|
|
3632 int to_pos = 0;
|
|
3633 struct string_chars_block *from_sb;
|
|
3634
|
|
3635 /* Scan each existing string block sequentially, string by string. */
|
|
3636 for (from_sb = first_string_chars_block; from_sb; from_sb = from_sb->next)
|
|
3637 {
|
|
3638 int from_pos = 0;
|
|
3639 /* FROM_POS is the index of the next string in the block. */
|
|
3640 while (from_pos < from_sb->pos)
|
|
3641 {
|
|
3642 struct string_chars *from_s_chars =
|
|
3643 (struct string_chars *) &(from_sb->string_chars[from_pos]);
|
|
3644 struct string_chars *to_s_chars;
|
|
3645 struct Lisp_String *string;
|
|
3646 int size;
|
|
3647 int fullsize;
|
|
3648
|
|
3649 /* If the string_chars struct is marked as free (i.e. the STRING
|
|
3650 pointer is 0xFFFFFFFF) then this is an unused chunk of string
|
|
3651 storage. This happens under Mule when a string's size changes
|
|
3652 in such a way that its fullsize changes. (Strings can change
|
|
3653 size because a different-length character can be substituted
|
|
3654 for another character.) In this case, after the bogus string
|
|
3655 pointer is the "fullsize" of this entry, i.e. how many bytes
|
|
3656 to skip. */
|
|
3657
|
|
3658 if (FREE_STRUCT_P (from_s_chars))
|
|
3659 {
|
|
3660 fullsize = ((struct unused_string_chars *) from_s_chars)->fullsize;
|
|
3661 from_pos += fullsize;
|
|
3662 continue;
|
|
3663 }
|
|
3664
|
|
3665 string = from_s_chars->string;
|
|
3666 assert (!(FREE_STRUCT_P (string)));
|
|
3667
|
|
3668 size = string_length (string);
|
|
3669 fullsize = STRING_FULLSIZE (size);
|
|
3670
|
|
3671 if (BIG_STRING_FULLSIZE_P (fullsize))
|
|
3672 abort ();
|
|
3673
|
|
3674 /* Just skip it if it isn't marked. */
|
|
3675 if (!XMARKBIT (string->plist))
|
|
3676 {
|
|
3677 from_pos += fullsize;
|
|
3678 continue;
|
|
3679 }
|
|
3680
|
|
3681 /* If it won't fit in what's left of TO_SB, close TO_SB out
|
|
3682 and go on to the next string_chars_block. We know that TO_SB
|
|
3683 cannot advance past FROM_SB here since FROM_SB is large enough
|
|
3684 to currently contain this string. */
|
|
3685 if ((to_pos + fullsize) > countof (to_sb->string_chars))
|
|
3686 {
|
|
3687 to_sb->pos = to_pos;
|
|
3688 to_sb = to_sb->next;
|
|
3689 to_pos = 0;
|
|
3690 }
|
|
3691
|
|
3692 /* Compute new address of this string
|
|
3693 and update TO_POS for the space being used. */
|
|
3694 to_s_chars = (struct string_chars *) &(to_sb->string_chars[to_pos]);
|
|
3695
|
|
3696 /* Copy the string_chars to the new place. */
|
|
3697 if (from_s_chars != to_s_chars)
|
|
3698 memmove (to_s_chars, from_s_chars, fullsize);
|
|
3699
|
|
3700 /* Relocate FROM_S_CHARS's reference */
|
|
3701 set_string_data (string, &(to_s_chars->chars[0]));
|
|
3702
|
|
3703 from_pos += fullsize;
|
|
3704 to_pos += fullsize;
|
|
3705 }
|
|
3706 }
|
|
3707
|
|
3708 /* Set current to the last string chars block still used and
|
|
3709 free any that follow. */
|
|
3710 {
|
|
3711 struct string_chars_block *victim;
|
|
3712
|
|
3713 for (victim = to_sb->next; victim; )
|
|
3714 {
|
|
3715 struct string_chars_block *next = victim->next;
|
|
3716 xfree (victim);
|
|
3717 victim = next;
|
|
3718 }
|
|
3719
|
|
3720 current_string_chars_block = to_sb;
|
|
3721 current_string_chars_block->pos = to_pos;
|
|
3722 current_string_chars_block->next = 0;
|
|
3723 }
|
|
3724 }
|
|
3725
|
|
3726 #if 1 /* Hack to debug missing purecopy's */
|
|
3727 static int debug_string_purity;
|
|
3728
|
|
3729 static void
|
|
3730 debug_string_purity_print (struct Lisp_String *p)
|
|
3731 {
|
|
3732 Charcount i;
|
|
3733 Charcount s = string_char_length (p);
|
|
3734 putc ('\"', stderr);
|
|
3735 for (i = 0; i < s; i++)
|
|
3736 {
|
|
3737 Emchar ch = string_char (p, i);
|
|
3738 if (ch < 32 || ch >= 126)
|
|
3739 stderr_out ("\\%03o", ch);
|
|
3740 else if (ch == '\\' || ch == '\"')
|
|
3741 stderr_out ("\\%c", ch);
|
|
3742 else
|
|
3743 stderr_out ("%c", ch);
|
|
3744 }
|
|
3745 stderr_out ("\"\n");
|
|
3746 }
|
|
3747 #endif
|
|
3748
|
|
3749
|
|
3750 static void
|
|
3751 sweep_strings (void)
|
|
3752 {
|
|
3753 int num_small_used = 0, num_small_bytes = 0, num_bytes = 0;
|
|
3754 int debug = debug_string_purity;
|
|
3755
|
|
3756 #define MARKED_string_P(ptr) XMARKBIT ((ptr)->plist)
|
|
3757 #define UNMARK_string(ptr) \
|
|
3758 do { struct Lisp_String *p = (ptr); \
|
|
3759 int size = string_length (p); \
|
|
3760 XUNMARK (p->plist); \
|
|
3761 num_bytes += size; \
|
|
3762 if (!BIG_STRING_SIZE_P (size)) \
|
|
3763 { num_small_bytes += size; \
|
|
3764 num_small_used++; \
|
|
3765 } \
|
|
3766 if (debug) debug_string_purity_print (p); \
|
|
3767 } while (0)
|
|
3768 #define ADDITIONAL_FREE_string(p) \
|
|
3769 do { int size = string_length (p); \
|
|
3770 if (BIG_STRING_SIZE_P (size)) \
|
|
3771 xfree_1 (CHARS_TO_STRING_CHAR (string_data (p))); \
|
|
3772 } while (0)
|
|
3773
|
|
3774 SWEEP_FIXED_TYPE_BLOCK (string, struct Lisp_String);
|
|
3775
|
|
3776 gc_count_num_short_string_in_use = num_small_used;
|
|
3777 gc_count_string_total_size = num_bytes;
|
|
3778 gc_count_short_string_total_size = num_small_bytes;
|
|
3779 }
|
|
3780
|
|
3781
|
|
3782 /* I hate duplicating all this crap! */
|
|
3783 static int
|
|
3784 marked_p (Lisp_Object obj)
|
|
3785 {
|
|
3786 if (!POINTER_TYPE_P (XGCTYPE (obj))) return 1;
|
|
3787 if (PURIFIED (XPNTR (obj))) return 1;
|
|
3788 switch (XGCTYPE (obj))
|
|
3789 {
|
|
3790 case Lisp_Cons:
|
|
3791 return XMARKBIT (XCAR (obj));
|
|
3792 case Lisp_Record:
|
|
3793 return MARKED_RECORD_HEADER_P (XRECORD_LHEADER (obj));
|
|
3794 case Lisp_String:
|
|
3795 return XMARKBIT (XSTRING (obj)->plist);
|
|
3796 case Lisp_Vector:
|
173
|
3797 return XVECTOR_LENGTH (obj) < 0;
|
0
|
3798 #ifndef LRECORD_SYMBOL
|
|
3799 case Lisp_Symbol:
|
|
3800 return XMARKBIT (XSYMBOL (obj)->plist);
|
|
3801 #endif
|
|
3802 default:
|
|
3803 abort ();
|
|
3804 }
|
|
3805 return 0; /* suppress compiler warning */
|
|
3806 }
|
|
3807
|
|
3808 static void
|
|
3809 gc_sweep (void)
|
|
3810 {
|
|
3811 /* Free all unmarked records. Do this at the very beginning,
|
|
3812 before anything else, so that the finalize methods can safely
|
|
3813 examine items in the objects. sweep_lcrecords_1() makes
|
|
3814 sure to call all the finalize methods *before* freeing anything,
|
|
3815 to complete the safety. */
|
|
3816 {
|
|
3817 int ignored;
|
|
3818 sweep_lcrecords_1 (&all_lcrecords, &ignored);
|
|
3819 }
|
|
3820
|
|
3821 compact_string_chars ();
|
|
3822
|
|
3823 /* Finalize methods below (called through the ADDITIONAL_FREE_foo
|
|
3824 macros) must be *extremely* careful to make sure they're not
|
|
3825 referencing freed objects. The only two existing finalize
|
|
3826 methods (for strings and markers) pass muster -- the string
|
|
3827 finalizer doesn't look at anything but its own specially-
|
|
3828 created block, and the marker finalizer only looks at live
|
|
3829 buffers (which will never be freed) and at the markers before
|
|
3830 and after it in the chain (which, by induction, will never be
|
|
3831 freed because if so, they would have already removed themselves
|
|
3832 from the chain). */
|
|
3833
|
|
3834 /* Put all unmarked strings on free list, free'ing the string chars
|
|
3835 of large unmarked strings */
|
|
3836 sweep_strings ();
|
|
3837
|
|
3838 /* Put all unmarked conses on free list */
|
|
3839 sweep_conses ();
|
|
3840
|
|
3841 /* Free all unmarked vectors */
|
|
3842 sweep_vectors_1 (&all_vectors,
|
|
3843 &gc_count_num_vector_used, &gc_count_vector_total_size,
|
|
3844 &gc_count_vector_storage);
|
|
3845
|
|
3846 /* Free all unmarked bit vectors */
|
|
3847 sweep_bit_vectors_1 (&all_bit_vectors,
|
|
3848 &gc_count_num_bit_vector_used,
|
|
3849 &gc_count_bit_vector_total_size,
|
|
3850 &gc_count_bit_vector_storage);
|
|
3851
|
|
3852 /* Free all unmarked compiled-function objects */
|
|
3853 sweep_compiled_functions ();
|
|
3854
|
|
3855 #ifdef LISP_FLOAT_TYPE
|
|
3856 /* Put all unmarked floats on free list */
|
|
3857 sweep_floats ();
|
|
3858 #endif
|
|
3859
|
|
3860 /* Put all unmarked symbols on free list */
|
|
3861 sweep_symbols ();
|
|
3862
|
|
3863 /* Put all unmarked extents on free list */
|
|
3864 sweep_extents ();
|
|
3865
|
|
3866 /* Put all unmarked markers on free list.
|
|
3867 Dechain each one first from the buffer into which it points. */
|
|
3868 sweep_markers ();
|
|
3869
|
|
3870 sweep_events ();
|
|
3871
|
|
3872 }
|
|
3873
|
|
3874 /* Clearing for disksave. */
|
|
3875
|
|
3876 extern Lisp_Object Vprocess_environment;
|
|
3877 extern Lisp_Object Vdoc_directory;
|
|
3878 extern Lisp_Object Vconfigure_info_directory;
|
|
3879 extern Lisp_Object Vload_path;
|
|
3880 extern Lisp_Object Vload_history;
|
|
3881 extern Lisp_Object Vshell_file_name;
|
|
3882
|
|
3883 void
|
|
3884 disksave_object_finalization (void)
|
|
3885 {
|
|
3886 /* It's important that certain information from the environment not get
|
|
3887 dumped with the executable (pathnames, environment variables, etc.).
|
|
3888 To make it easier to tell when this has happend with strings(1) we
|
|
3889 clear some known-to-be-garbage blocks of memory, so that leftover
|
|
3890 results of old evaluation don't look like potential problems.
|
|
3891 But first we set some notable variables to nil and do one more GC,
|
|
3892 to turn those strings into garbage.
|
|
3893 */
|
|
3894
|
|
3895 /* Yeah, this list is pretty ad-hoc... */
|
|
3896 Vprocess_environment = Qnil;
|
|
3897 Vexec_directory = Qnil;
|
|
3898 Vdata_directory = Qnil;
|
110
|
3899 Vsite_directory = Qnil;
|
0
|
3900 Vdoc_directory = Qnil;
|
|
3901 Vconfigure_info_directory = Qnil;
|
|
3902 Vexec_path = Qnil;
|
|
3903 Vload_path = Qnil;
|
|
3904 /* Vdump_load_path = Qnil; */
|
|
3905 Vload_history = Qnil;
|
|
3906 Vshell_file_name = Qnil;
|
|
3907
|
|
3908 garbage_collect_1 ();
|
|
3909
|
|
3910 /* Run the disksave finalization methods of all live objects. */
|
|
3911 disksave_object_finalization_1 ();
|
|
3912
|
|
3913 /* Zero out the unused portion of purespace */
|
|
3914 if (!pure_lossage)
|
|
3915 memset ( (char *) (PUREBEG + pureptr), 0,
|
171
|
3916 (((char *) (PUREBEG + get_PURESIZE())) -
|
0
|
3917 ((char *) (PUREBEG + pureptr))));
|
|
3918
|
|
3919 /* Zero out the uninitialized (really, unused) part of the containers
|
|
3920 for the live strings. */
|
|
3921 {
|
|
3922 struct string_chars_block *scb;
|
|
3923 for (scb = first_string_chars_block; scb; scb = scb->next)
|
|
3924 /* from the block's fill ptr to the end */
|
|
3925 memset ((scb->string_chars + scb->pos), 0,
|
|
3926 sizeof (scb->string_chars) - scb->pos);
|
|
3927 }
|
|
3928
|
|
3929 /* There, that ought to be enough... */
|
|
3930
|
|
3931 }
|
|
3932
|
|
3933
|
|
3934 Lisp_Object
|
|
3935 restore_gc_inhibit (Lisp_Object val)
|
|
3936 {
|
|
3937 gc_currently_forbidden = XINT (val);
|
|
3938 return val;
|
|
3939 }
|
|
3940
|
|
3941 /* Maybe we want to use this when doing a "panic" gc after memory_full()? */
|
|
3942 static int gc_hooks_inhibited;
|
|
3943
|
|
3944
|
|
3945 void
|
|
3946 garbage_collect_1 (void)
|
|
3947 {
|
|
3948 char stack_top_variable;
|
|
3949 extern char *stack_bottom;
|
|
3950 int i;
|
163
|
3951 struct frame *f = selected_frame ();
|
0
|
3952 int speccount = specpdl_depth ();
|
|
3953 Lisp_Object pre_gc_cursor = Qnil;
|
|
3954 struct gcpro gcpro1;
|
|
3955
|
163
|
3956 int cursor_changed = 0;
|
0
|
3957
|
|
3958 if (gc_in_progress != 0)
|
|
3959 return;
|
|
3960
|
|
3961 if (gc_currently_forbidden || in_display)
|
|
3962 return;
|
|
3963
|
|
3964 if (preparing_for_armageddon)
|
|
3965 return;
|
|
3966
|
163
|
3967 GCPRO1 (pre_gc_cursor);
|
0
|
3968
|
|
3969 /* Very important to prevent GC during any of the following
|
|
3970 stuff that might run Lisp code; otherwise, we'll likely
|
|
3971 have infinite GC recursion. */
|
|
3972 record_unwind_protect (restore_gc_inhibit,
|
|
3973 make_int (gc_currently_forbidden));
|
|
3974 gc_currently_forbidden = 1;
|
|
3975
|
|
3976 if (!gc_hooks_inhibited)
|
|
3977 run_hook_trapping_errors ("Error in pre-gc-hook", Qpre_gc_hook);
|
|
3978
|
|
3979 /* Now show the GC cursor/message. */
|
|
3980 if (!noninteractive)
|
|
3981 {
|
163
|
3982 if (FRAME_WIN_P (f))
|
0
|
3983 {
|
163
|
3984 Lisp_Object frame = make_frame (f);
|
|
3985 Lisp_Object cursor = glyph_image_instance (Vgc_pointer_glyph,
|
|
3986 FRAME_SELECTED_WINDOW (f),
|
|
3987 ERROR_ME_NOT, 1);
|
|
3988 pre_gc_cursor = f->pointer;
|
|
3989 if (POINTER_IMAGE_INSTANCEP (cursor)
|
|
3990 /* don't change if we don't know how to change back. */
|
|
3991 && POINTER_IMAGE_INSTANCEP (pre_gc_cursor))
|
0
|
3992 {
|
163
|
3993 cursor_changed = 1;
|
|
3994 Fset_frame_pointer (frame, cursor);
|
0
|
3995 }
|
|
3996 }
|
163
|
3997
|
|
3998 /* Don't print messages to the stream device. */
|
|
3999 if (!cursor_changed && !FRAME_STREAM_P (f))
|
|
4000 {
|
|
4001 char *msg = (STRINGP (Vgc_message)
|
|
4002 ? GETTEXT ((char *) XSTRING_DATA (Vgc_message))
|
|
4003 : 0);
|
|
4004 Lisp_Object args[2], whole_msg;
|
|
4005 args[0] = build_string (msg ? msg :
|
|
4006 GETTEXT ((CONST char *) gc_default_message));
|
|
4007 args[1] = build_string ("...");
|
|
4008 whole_msg = Fconcat (2, args);
|
|
4009 echo_area_message (f, (Bufbyte *) 0, whole_msg, 0, -1,
|
|
4010 Qgarbage_collecting);
|
|
4011 }
|
0
|
4012 }
|
|
4013
|
|
4014 /***** Now we actually start the garbage collection. */
|
|
4015
|
|
4016 gc_in_progress = 1;
|
|
4017
|
|
4018 gc_generation_number[0]++;
|
|
4019
|
|
4020 #if MAX_SAVE_STACK > 0
|
|
4021
|
|
4022 /* Save a copy of the contents of the stack, for debugging. */
|
|
4023 if (!purify_flag)
|
|
4024 {
|
|
4025 i = &stack_top_variable - stack_bottom;
|
|
4026 if (i < 0) i = -i;
|
|
4027 if (i < MAX_SAVE_STACK)
|
|
4028 {
|
|
4029 if (stack_copy == 0)
|
|
4030 stack_copy = (char *) malloc (stack_copy_size = i);
|
|
4031 else if (stack_copy_size < i)
|
|
4032 stack_copy = (char *) realloc (stack_copy, (stack_copy_size = i));
|
|
4033 if (stack_copy)
|
|
4034 {
|
|
4035 if ((int) (&stack_top_variable - stack_bottom) > 0)
|
|
4036 memcpy (stack_copy, stack_bottom, i);
|
|
4037 else
|
|
4038 memcpy (stack_copy, &stack_top_variable, i);
|
|
4039 }
|
|
4040 }
|
|
4041 }
|
|
4042 #endif /* MAX_SAVE_STACK > 0 */
|
|
4043
|
|
4044 /* Do some totally ad-hoc resource clearing. */
|
|
4045 /* #### generalize this? */
|
|
4046 clear_event_resource ();
|
|
4047 cleanup_specifiers ();
|
|
4048
|
|
4049 /* Mark all the special slots that serve as the roots of accessibility. */
|
|
4050 {
|
|
4051 struct gcpro *tail;
|
|
4052 struct catchtag *catch;
|
|
4053 struct backtrace *backlist;
|
|
4054 struct specbinding *bind;
|
|
4055
|
|
4056 for (i = 0; i < staticidx; i++)
|
|
4057 {
|
|
4058 #ifdef GDB_SUCKS
|
|
4059 printf ("%d\n", i);
|
|
4060 debug_print (*staticvec[i]);
|
|
4061 #endif
|
|
4062 mark_object (*(staticvec[i]));
|
|
4063 }
|
|
4064
|
|
4065 for (tail = gcprolist; tail; tail = tail->next)
|
|
4066 {
|
|
4067 for (i = 0; i < tail->nvars; i++)
|
|
4068 mark_object (tail->var[i]);
|
|
4069 }
|
|
4070
|
|
4071 for (bind = specpdl; bind != specpdl_ptr; bind++)
|
|
4072 {
|
|
4073 mark_object (bind->symbol);
|
|
4074 mark_object (bind->old_value);
|
|
4075 }
|
|
4076
|
|
4077 for (catch = catchlist; catch; catch = catch->next)
|
|
4078 {
|
|
4079 mark_object (catch->tag);
|
|
4080 mark_object (catch->val);
|
|
4081 }
|
|
4082
|
|
4083 for (backlist = backtrace_list; backlist; backlist = backlist->next)
|
|
4084 {
|
|
4085 int nargs = backlist->nargs;
|
|
4086
|
|
4087 mark_object (*backlist->function);
|
|
4088 if (nargs == UNEVALLED || nargs == MANY)
|
|
4089 mark_object (backlist->args[0]);
|
|
4090 else
|
|
4091 for (i = 0; i < nargs; i++)
|
|
4092 mark_object (backlist->args[i]);
|
|
4093 }
|
|
4094
|
|
4095 mark_redisplay (mark_object);
|
100
|
4096 #ifndef WINDOWSNT
|
0
|
4097 mark_profiling_info (mark_object);
|
100
|
4098 #endif
|
0
|
4099 }
|
|
4100
|
|
4101 /* OK, now do the after-mark stuff. This is for things that
|
|
4102 are only marked when something else is marked (e.g. weak hashtables).
|
|
4103 There may be complex dependencies between such objects -- e.g.
|
|
4104 a weak hashtable might be unmarked, but after processing a later
|
|
4105 weak hashtable, the former one might get marked. So we have to
|
|
4106 iterate until nothing more gets marked. */
|
|
4107 {
|
|
4108 int did_mark;
|
|
4109 /* Need to iterate until there's nothing more to mark, in case
|
|
4110 of chains of mark dependencies. */
|
|
4111 do
|
|
4112 {
|
|
4113 did_mark = 0;
|
|
4114 did_mark += !!finish_marking_weak_hashtables (marked_p, mark_object);
|
|
4115 did_mark += !!finish_marking_weak_lists (marked_p, mark_object);
|
|
4116 }
|
|
4117 while (did_mark);
|
|
4118 }
|
|
4119
|
|
4120 /* And prune (this needs to be called after everything else has been
|
|
4121 marked and before we do any sweeping). */
|
|
4122 /* #### this is somewhat ad-hoc and should probably be an object
|
|
4123 method */
|
|
4124 prune_weak_hashtables (marked_p);
|
|
4125 prune_weak_lists (marked_p);
|
|
4126 prune_specifiers (marked_p);
|
70
|
4127 prune_syntax_tables (marked_p);
|
0
|
4128
|
|
4129 gc_sweep ();
|
|
4130
|
|
4131 consing_since_gc = 0;
|
|
4132 #ifndef DEBUG_XEMACS
|
|
4133 /* Allow you to set it really fucking low if you really want ... */
|
|
4134 if (gc_cons_threshold < 10000)
|
|
4135 gc_cons_threshold = 10000;
|
|
4136 #endif
|
|
4137
|
|
4138 gc_in_progress = 0;
|
|
4139
|
|
4140 /******* End of garbage collection ********/
|
|
4141
|
|
4142 run_hook_trapping_errors ("Error in post-gc-hook", Qpost_gc_hook);
|
|
4143
|
|
4144 /* Now remove the GC cursor/message */
|
|
4145 if (!noninteractive)
|
|
4146 {
|
163
|
4147 if (cursor_changed)
|
|
4148 Fset_frame_pointer (make_frame (f), pre_gc_cursor);
|
|
4149 else if (!FRAME_STREAM_P (f))
|
0
|
4150 {
|
|
4151 char *msg = (STRINGP (Vgc_message)
|
14
|
4152 ? GETTEXT ((char *) XSTRING_DATA (Vgc_message))
|
0
|
4153 : 0);
|
|
4154
|
|
4155 /* Show "...done" only if the echo area would otherwise be empty. */
|
|
4156 if (NILP (clear_echo_area (selected_frame (),
|
|
4157 Qgarbage_collecting, 0)))
|
|
4158 {
|
|
4159 Lisp_Object args[2], whole_msg;
|
|
4160 args[0] = build_string (msg ? msg :
|
|
4161 GETTEXT ((CONST char *)
|
|
4162 gc_default_message));
|
|
4163 args[1] = build_string ("... done");
|
|
4164 whole_msg = Fconcat (2, args);
|
|
4165 echo_area_message (selected_frame (), (Bufbyte *) 0,
|
|
4166 whole_msg, 0, -1,
|
|
4167 Qgarbage_collecting);
|
|
4168 }
|
|
4169 }
|
|
4170 }
|
|
4171
|
|
4172 /* now stop inhibiting GC */
|
|
4173 unbind_to (speccount, Qnil);
|
|
4174
|
|
4175 if (!breathing_space)
|
|
4176 {
|
|
4177 breathing_space = (void *) malloc (4096 - MALLOC_OVERHEAD);
|
|
4178 }
|
|
4179
|
|
4180 UNGCPRO;
|
|
4181 return;
|
|
4182 }
|
|
4183
|
|
4184 #ifdef EMACS_BTL
|
|
4185 /* This isn't actually called. BTL recognizes the stack frame of the top
|
|
4186 of the garbage collector by noting that PC is between &garbage_collect_1
|
|
4187 and &BTL_after_garbage_collect_1_stub. So this fn must be right here.
|
|
4188 There's not any other way to know the address of the end of a function.
|
|
4189 */
|
|
4190 void BTL_after_garbage_collect_1_stub () { abort (); }
|
|
4191 #endif
|
|
4192
|
|
4193 /* Debugging aids. */
|
|
4194
|
|
4195 static Lisp_Object
|
|
4196 gc_plist_hack (CONST char *name, int value, Lisp_Object tail)
|
|
4197 {
|
|
4198 /* C doesn't have local functions (or closures, or GC, or readable syntax,
|
|
4199 or portable numeric datatypes, or bit-vectors, or characters, or
|
|
4200 arrays, or exceptions, or ...) */
|
173
|
4201 return cons3 (intern (name), make_int (value), tail);
|
0
|
4202 }
|
|
4203
|
|
4204 #define HACK_O_MATIC(type, name, pl) \
|
|
4205 { \
|
|
4206 int s = 0; \
|
|
4207 struct type##_block *x = current_##type##_block; \
|
|
4208 while (x) { s += sizeof (*x) + MALLOC_OVERHEAD; x = x->prev; } \
|
|
4209 (pl) = gc_plist_hack ((name), s, (pl)); \
|
|
4210 }
|
|
4211
|
20
|
4212 DEFUN ("garbage-collect", Fgarbage_collect, 0, 0, "", /*
|
0
|
4213 Reclaim storage for Lisp objects no longer needed.
|
|
4214 Returns info on amount of space in use:
|
|
4215 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS)
|
|
4216 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS
|
|
4217 PLIST)
|
|
4218 where `PLIST' is a list of alternating keyword/value pairs providing
|
|
4219 more detailed information.
|
|
4220 Garbage collection happens automatically if you cons more than
|
|
4221 `gc-cons-threshold' bytes of Lisp data since previous garbage collection.
|
20
|
4222 */
|
|
4223 ())
|
0
|
4224 {
|
|
4225 Lisp_Object pl = Qnil;
|
|
4226 Lisp_Object ret[6];
|
|
4227 int i;
|
|
4228
|
104
|
4229 if (purify_flag && pure_lossage)
|
|
4230 {
|
|
4231 return Qnil;
|
|
4232 }
|
|
4233
|
0
|
4234 garbage_collect_1 ();
|
|
4235
|
|
4236 for (i = 0; i < last_lrecord_type_index_assigned; i++)
|
|
4237 {
|
|
4238 if (lcrecord_stats[i].bytes_in_use != 0
|
|
4239 || lcrecord_stats[i].bytes_freed != 0
|
|
4240 || lcrecord_stats[i].instances_on_free_list != 0)
|
|
4241 {
|
|
4242 char buf [255];
|
|
4243 CONST char *name = lrecord_implementations_table[i]->name;
|
|
4244 int len = strlen (name);
|
|
4245 sprintf (buf, "%s-storage", name);
|
|
4246 pl = gc_plist_hack (buf, lcrecord_stats[i].bytes_in_use, pl);
|
|
4247 /* Okay, simple pluralization check for `symbol-value-varalias' */
|
|
4248 if (name[len-1] == 's')
|
|
4249 sprintf (buf, "%ses-freed", name);
|
|
4250 else
|
|
4251 sprintf (buf, "%ss-freed", name);
|
|
4252 if (lcrecord_stats[i].instances_freed != 0)
|
|
4253 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_freed, pl);
|
|
4254 if (name[len-1] == 's')
|
|
4255 sprintf (buf, "%ses-on-free-list", name);
|
|
4256 else
|
|
4257 sprintf (buf, "%ss-on-free-list", name);
|
|
4258 if (lcrecord_stats[i].instances_on_free_list != 0)
|
|
4259 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_on_free_list,
|
|
4260 pl);
|
|
4261 if (name[len-1] == 's')
|
|
4262 sprintf (buf, "%ses-used", name);
|
|
4263 else
|
|
4264 sprintf (buf, "%ss-used", name);
|
|
4265 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_in_use, pl);
|
|
4266 }
|
|
4267 }
|
|
4268
|
|
4269 HACK_O_MATIC (extent, "extent-storage", pl);
|
|
4270 pl = gc_plist_hack ("extents-free", gc_count_num_extent_freelist, pl);
|
|
4271 pl = gc_plist_hack ("extents-used", gc_count_num_extent_in_use, pl);
|
|
4272 HACK_O_MATIC (event, "event-storage", pl);
|
|
4273 pl = gc_plist_hack ("events-free", gc_count_num_event_freelist, pl);
|
|
4274 pl = gc_plist_hack ("events-used", gc_count_num_event_in_use, pl);
|
|
4275 HACK_O_MATIC (marker, "marker-storage", pl);
|
|
4276 pl = gc_plist_hack ("markers-free", gc_count_num_marker_freelist, pl);
|
|
4277 pl = gc_plist_hack ("markers-used", gc_count_num_marker_in_use, pl);
|
|
4278 #ifdef LISP_FLOAT_TYPE
|
|
4279 HACK_O_MATIC (float, "float-storage", pl);
|
|
4280 pl = gc_plist_hack ("floats-free", gc_count_num_float_freelist, pl);
|
|
4281 pl = gc_plist_hack ("floats-used", gc_count_num_float_in_use, pl);
|
|
4282 #endif /* LISP_FLOAT_TYPE */
|
|
4283 HACK_O_MATIC (string, "string-header-storage", pl);
|
|
4284 pl = gc_plist_hack ("long-strings-total-length",
|
|
4285 gc_count_string_total_size
|
|
4286 - gc_count_short_string_total_size, pl);
|
|
4287 HACK_O_MATIC (string_chars, "short-string-storage", pl);
|
|
4288 pl = gc_plist_hack ("short-strings-total-length",
|
|
4289 gc_count_short_string_total_size, pl);
|
|
4290 pl = gc_plist_hack ("strings-free", gc_count_num_string_freelist, pl);
|
|
4291 pl = gc_plist_hack ("long-strings-used",
|
|
4292 gc_count_num_string_in_use
|
|
4293 - gc_count_num_short_string_in_use, pl);
|
|
4294 pl = gc_plist_hack ("short-strings-used",
|
|
4295 gc_count_num_short_string_in_use, pl);
|
|
4296
|
|
4297 HACK_O_MATIC (compiled_function, "compiled-function-storage", pl);
|
|
4298 pl = gc_plist_hack ("compiled-functions-free",
|
|
4299 gc_count_num_compiled_function_freelist, pl);
|
|
4300 pl = gc_plist_hack ("compiled-functions-used",
|
|
4301 gc_count_num_compiled_function_in_use, pl);
|
|
4302
|
|
4303 pl = gc_plist_hack ("vector-storage", gc_count_vector_storage, pl);
|
|
4304 pl = gc_plist_hack ("vectors-total-length",
|
|
4305 gc_count_vector_total_size, pl);
|
|
4306 pl = gc_plist_hack ("vectors-used", gc_count_num_vector_used, pl);
|
|
4307
|
|
4308 pl = gc_plist_hack ("bit-vector-storage", gc_count_bit_vector_storage, pl);
|
|
4309 pl = gc_plist_hack ("bit-vectors-total-length",
|
|
4310 gc_count_bit_vector_total_size, pl);
|
|
4311 pl = gc_plist_hack ("bit-vectors-used", gc_count_num_bit_vector_used, pl);
|
|
4312
|
|
4313 HACK_O_MATIC (symbol, "symbol-storage", pl);
|
|
4314 pl = gc_plist_hack ("symbols-free", gc_count_num_symbol_freelist, pl);
|
|
4315 pl = gc_plist_hack ("symbols-used", gc_count_num_symbol_in_use, pl);
|
|
4316
|
|
4317 HACK_O_MATIC (cons, "cons-storage", pl);
|
|
4318 pl = gc_plist_hack ("conses-free", gc_count_num_cons_freelist, pl);
|
|
4319 pl = gc_plist_hack ("conses-used", gc_count_num_cons_in_use, pl);
|
|
4320
|
|
4321 /* The things we do for backwards-compatibility */
|
|
4322 ret[0] = Fcons (make_int (gc_count_num_cons_in_use),
|
|
4323 make_int (gc_count_num_cons_freelist));
|
|
4324 ret[1] = Fcons (make_int (gc_count_num_symbol_in_use),
|
|
4325 make_int (gc_count_num_symbol_freelist));
|
|
4326 ret[2] = Fcons (make_int (gc_count_num_marker_in_use),
|
|
4327 make_int (gc_count_num_marker_freelist));
|
|
4328 ret[3] = make_int (gc_count_string_total_size);
|
|
4329 ret[4] = make_int (gc_count_vector_total_size);
|
|
4330 ret[5] = pl;
|
173
|
4331 return Flist (6, ret);
|
0
|
4332 }
|
|
4333 #undef HACK_O_MATIC
|
|
4334
|
20
|
4335 DEFUN ("consing-since-gc", Fconsing_since_gc, 0, 0, "", /*
|
0
|
4336 Return the number of bytes consed since the last garbage collection.
|
|
4337 \"Consed\" is a misnomer in that this actually counts allocation
|
|
4338 of all different kinds of objects, not just conses.
|
|
4339
|
|
4340 If this value exceeds `gc-cons-threshold', a garbage collection happens.
|
20
|
4341 */
|
|
4342 ())
|
0
|
4343 {
|
173
|
4344 return make_int (consing_since_gc);
|
0
|
4345 }
|
|
4346
|
20
|
4347 DEFUN ("memory-limit", Fmemory_limit, 0, 0, "", /*
|
0
|
4348 Return the address of the last byte Emacs has allocated, divided by 1024.
|
|
4349 This may be helpful in debugging Emacs's memory usage.
|
|
4350 The value is divided by 1024 to make sure it will fit in a lisp integer.
|
20
|
4351 */
|
|
4352 ())
|
0
|
4353 {
|
173
|
4354 return make_int ((EMACS_INT) sbrk (0) / 1024);
|
0
|
4355 }
|
|
4356
|
|
4357
|
|
4358
|
|
4359 int
|
|
4360 object_dead_p (Lisp_Object obj)
|
|
4361 {
|
173
|
4362 return ((BUFFERP (obj) && !BUFFER_LIVE_P (XBUFFER (obj))) ||
|
|
4363 (FRAMEP (obj) && !FRAME_LIVE_P (XFRAME (obj))) ||
|
|
4364 (WINDOWP (obj) && !WINDOW_LIVE_P (XWINDOW (obj))) ||
|
|
4365 (DEVICEP (obj) && !DEVICE_LIVE_P (XDEVICE (obj))) ||
|
0
|
4366 (CONSOLEP (obj) && !CONSOLE_LIVE_P (XCONSOLE (obj))) ||
|
173
|
4367 (EVENTP (obj) && !EVENT_LIVE_P (XEVENT (obj))) ||
|
|
4368 (EXTENTP (obj) && !EXTENT_LIVE_P (XEXTENT (obj))));
|
0
|
4369
|
|
4370 }
|
|
4371
|
|
4372 #ifdef MEMORY_USAGE_STATS
|
|
4373
|
|
4374 /* Attempt to determine the actual amount of space that is used for
|
|
4375 the block allocated starting at PTR, supposedly of size "CLAIMED_SIZE".
|
|
4376
|
|
4377 It seems that the following holds:
|
|
4378
|
|
4379 1. When using the old allocator (malloc.c):
|
|
4380
|
|
4381 -- blocks are always allocated in chunks of powers of two. For
|
|
4382 each block, there is an overhead of 8 bytes if rcheck is not
|
|
4383 defined, 20 bytes if it is defined. In other words, a
|
|
4384 one-byte allocation needs 8 bytes of overhead for a total of
|
|
4385 9 bytes, and needs to have 16 bytes of memory chunked out for
|
|
4386 it.
|
|
4387
|
|
4388 2. When using the new allocator (gmalloc.c):
|
|
4389
|
|
4390 -- blocks are always allocated in chunks of powers of two up
|
|
4391 to 4096 bytes. Larger blocks are allocated in chunks of
|
|
4392 an integral multiple of 4096 bytes. The minimum block
|
|
4393 size is 2*sizeof (void *), or 16 bytes if SUNOS_LOCALTIME_BUG
|
|
4394 is defined. There is no per-block overhead, but there
|
|
4395 is an overhead of 3*sizeof (size_t) for each 4096 bytes
|
|
4396 allocated.
|
|
4397
|
|
4398 3. When using the system malloc, anything goes, but they are
|
|
4399 generally slower and more space-efficient than the GNU
|
|
4400 allocators. One possibly reasonable assumption to make
|
|
4401 for want of better data is that sizeof (void *), or maybe
|
|
4402 2 * sizeof (void *), is required as overhead and that
|
|
4403 blocks are allocated in the minimum required size except
|
|
4404 that some minimum block size is imposed (e.g. 16 bytes). */
|
|
4405
|
|
4406 int
|
|
4407 malloced_storage_size (void *ptr, int claimed_size,
|
|
4408 struct overhead_stats *stats)
|
|
4409 {
|
|
4410 int orig_claimed_size = claimed_size;
|
|
4411
|
|
4412 #ifdef GNU_MALLOC
|
|
4413
|
|
4414 if (claimed_size < 2 * sizeof (void *))
|
|
4415 claimed_size = 2 * sizeof (void *);
|
|
4416 # ifdef SUNOS_LOCALTIME_BUG
|
|
4417 if (claimed_size < 16)
|
|
4418 claimed_size = 16;
|
|
4419 # endif
|
|
4420 if (claimed_size < 4096)
|
|
4421 {
|
|
4422 int log = 1;
|
|
4423
|
|
4424 /* compute the log base two, more or less, then use it to compute
|
|
4425 the block size needed. */
|
|
4426 claimed_size--;
|
|
4427 /* It's big, it's heavy, it's wood! */
|
|
4428 while ((claimed_size /= 2) != 0)
|
|
4429 ++log;
|
|
4430 claimed_size = 1;
|
|
4431 /* It's better than bad, it's good! */
|
|
4432 while (log > 0)
|
|
4433 {
|
|
4434 claimed_size *= 2;
|
|
4435 log--;
|
|
4436 }
|
|
4437 /* We have to come up with some average about the amount of
|
|
4438 blocks used. */
|
|
4439 if ((rand () & 4095) < claimed_size)
|
|
4440 claimed_size += 3 * sizeof (void *);
|
|
4441 }
|
|
4442 else
|
|
4443 {
|
|
4444 claimed_size += 4095;
|
|
4445 claimed_size &= ~4095;
|
|
4446 claimed_size += (claimed_size / 4096) * 3 * sizeof (size_t);
|
|
4447 }
|
|
4448
|
|
4449 #elif defined (SYSTEM_MALLOC)
|
|
4450
|
|
4451 if (claimed_size < 16)
|
|
4452 claimed_size = 16;
|
|
4453 claimed_size += 2 * sizeof (void *);
|
|
4454
|
|
4455 #else /* old GNU allocator */
|
|
4456
|
|
4457 # ifdef rcheck /* #### may not be defined here */
|
|
4458 claimed_size += 20;
|
|
4459 # else
|
|
4460 claimed_size += 8;
|
|
4461 # endif
|
|
4462 {
|
|
4463 int log = 1;
|
|
4464
|
|
4465 /* compute the log base two, more or less, then use it to compute
|
|
4466 the block size needed. */
|
|
4467 claimed_size--;
|
|
4468 /* It's big, it's heavy, it's wood! */
|
|
4469 while ((claimed_size /= 2) != 0)
|
|
4470 ++log;
|
|
4471 claimed_size = 1;
|
|
4472 /* It's better than bad, it's good! */
|
|
4473 while (log > 0)
|
|
4474 {
|
|
4475 claimed_size *= 2;
|
|
4476 log--;
|
|
4477 }
|
|
4478 }
|
|
4479
|
|
4480 #endif /* old GNU allocator */
|
|
4481
|
|
4482 if (stats)
|
|
4483 {
|
|
4484 stats->was_requested += orig_claimed_size;
|
|
4485 stats->malloc_overhead += claimed_size - orig_claimed_size;
|
|
4486 }
|
|
4487 return claimed_size;
|
|
4488 }
|
|
4489
|
|
4490 int
|
|
4491 fixed_type_block_overhead (int size)
|
|
4492 {
|
|
4493 int per_block = TYPE_ALLOC_SIZE (cons, unsigned char);
|
|
4494 int overhead = 0;
|
|
4495 int storage_size = malloced_storage_size (0, per_block, 0);
|
|
4496 while (size >= per_block)
|
|
4497 {
|
|
4498 size -= per_block;
|
|
4499 overhead += sizeof (void *) + per_block - storage_size;
|
|
4500
|
|
4501 }
|
|
4502 if (rand () % per_block < size)
|
|
4503 overhead += sizeof (void *) + per_block - storage_size;
|
|
4504 return overhead;
|
|
4505 }
|
|
4506
|
|
4507 #endif /* MEMORY_USAGE_STATS */
|
|
4508
|
|
4509
|
|
4510 /* Initialization */
|
|
4511 void
|
|
4512 init_alloc_once_early (void)
|
|
4513 {
|
|
4514 int iii;
|
|
4515
|
|
4516 #ifdef PURESTAT
|
|
4517 for (iii = 0; iii < countof (purestats); iii++)
|
|
4518 {
|
|
4519 if (! purestats[iii]) continue;
|
|
4520 purestats[iii]->nobjects = 0;
|
|
4521 purestats[iii]->nbytes = 0;
|
|
4522 }
|
|
4523 purecopying_for_bytecode = 0;
|
|
4524 #endif
|
|
4525
|
|
4526 last_lrecord_type_index_assigned = -1;
|
|
4527 for (iii = 0; iii < countof (lrecord_implementations_table); iii++)
|
|
4528 {
|
|
4529 lrecord_implementations_table[iii] = 0;
|
|
4530 }
|
|
4531
|
|
4532 symbols_initialized = 0;
|
|
4533
|
|
4534 gc_generation_number[0] = 0;
|
|
4535 /* purify_flag 1 is correct even if CANNOT_DUMP.
|
|
4536 * loadup.el will set to nil at end. */
|
|
4537 purify_flag = 1;
|
|
4538 pureptr = 0;
|
|
4539 pure_lossage = 0;
|
|
4540 breathing_space = 0;
|
|
4541 XSETINT (all_vectors, 0); /* Qzero may not be set yet. */
|
|
4542 XSETINT (all_bit_vectors, 0); /* Qzero may not be set yet. */
|
|
4543 XSETINT (Vgc_message, 0);
|
|
4544 all_lcrecords = 0;
|
|
4545 ignore_malloc_warnings = 1;
|
|
4546 init_string_alloc ();
|
|
4547 init_string_chars_alloc ();
|
|
4548 init_cons_alloc ();
|
|
4549 init_symbol_alloc ();
|
|
4550 init_compiled_function_alloc ();
|
|
4551 #ifdef LISP_FLOAT_TYPE
|
|
4552 init_float_alloc ();
|
|
4553 #endif /* LISP_FLOAT_TYPE */
|
|
4554 #ifndef standalone
|
|
4555 init_marker_alloc ();
|
|
4556 init_extent_alloc ();
|
|
4557 init_event_alloc ();
|
|
4558 #endif
|
|
4559 ignore_malloc_warnings = 0;
|
|
4560 staticidx = 0;
|
|
4561 consing_since_gc = 0;
|
|
4562 #if 1
|
|
4563 gc_cons_threshold = 500000; /* XEmacs change */
|
|
4564 #else
|
|
4565 gc_cons_threshold = 15000; /* debugging */
|
|
4566 #endif
|
|
4567 #ifdef VIRT_ADDR_VARIES
|
|
4568 malloc_sbrk_unused = 1<<22; /* A large number */
|
|
4569 malloc_sbrk_used = 100000; /* as reasonable as any number */
|
|
4570 #endif /* VIRT_ADDR_VARIES */
|
|
4571 lrecord_uid_counter = 259;
|
|
4572 debug_string_purity = 0;
|
|
4573 gcprolist = 0;
|
|
4574
|
|
4575 gc_currently_forbidden = 0;
|
|
4576 gc_hooks_inhibited = 0;
|
|
4577
|
|
4578 #ifdef ERROR_CHECK_TYPECHECK
|
|
4579 ERROR_ME.really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
|
|
4580 666;
|
|
4581 ERROR_ME_NOT.
|
|
4582 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = 42;
|
|
4583 ERROR_ME_WARN.
|
|
4584 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
|
|
4585 3333632;
|
|
4586 #endif
|
|
4587 }
|
|
4588
|
|
4589 void
|
|
4590 reinit_alloc (void)
|
|
4591 {
|
|
4592 gcprolist = 0;
|
|
4593 }
|
|
4594
|
|
4595 void
|
|
4596 syms_of_alloc (void)
|
|
4597 {
|
|
4598 defsymbol (&Qpre_gc_hook, "pre-gc-hook");
|
|
4599 defsymbol (&Qpost_gc_hook, "post-gc-hook");
|
|
4600 defsymbol (&Qgarbage_collecting, "garbage-collecting");
|
|
4601
|
20
|
4602 DEFSUBR (Fcons);
|
|
4603 DEFSUBR (Flist);
|
|
4604 DEFSUBR (Fvector);
|
|
4605 DEFSUBR (Fbit_vector);
|
|
4606 DEFSUBR (Fmake_byte_code);
|
|
4607 DEFSUBR (Fmake_list);
|
|
4608 DEFSUBR (Fmake_vector);
|
|
4609 DEFSUBR (Fmake_bit_vector);
|
|
4610 DEFSUBR (Fmake_string);
|
|
4611 DEFSUBR (Fmake_symbol);
|
|
4612 DEFSUBR (Fmake_marker);
|
|
4613 DEFSUBR (Fpurecopy);
|
|
4614 DEFSUBR (Fgarbage_collect);
|
|
4615 DEFSUBR (Fmemory_limit);
|
|
4616 DEFSUBR (Fconsing_since_gc);
|
0
|
4617 }
|
|
4618
|
|
4619 void
|
|
4620 vars_of_alloc (void)
|
|
4621 {
|
|
4622 DEFVAR_INT ("gc-cons-threshold", &gc_cons_threshold /*
|
|
4623 *Number of bytes of consing between garbage collections.
|
|
4624 \"Consing\" is a misnomer in that this actually counts allocation
|
|
4625 of all different kinds of objects, not just conses.
|
|
4626 Garbage collection can happen automatically once this many bytes have been
|
|
4627 allocated since the last garbage collection. All data types count.
|
|
4628
|
|
4629 Garbage collection happens automatically when `eval' or `funcall' are
|
|
4630 called. (Note that `funcall' is called implicitly as part of evaluation.)
|
|
4631 By binding this temporarily to a large number, you can effectively
|
|
4632 prevent garbage collection during a part of the program.
|
|
4633
|
|
4634 See also `consing-since-gc'.
|
|
4635 */ );
|
|
4636
|
|
4637 DEFVAR_INT ("pure-bytes-used", &pureptr /*
|
|
4638 Number of bytes of sharable Lisp data allocated so far.
|
|
4639 */ );
|
|
4640
|
|
4641 #if 0
|
|
4642 DEFVAR_INT ("data-bytes-used", &malloc_sbrk_used /*
|
|
4643 Number of bytes of unshared memory allocated in this session.
|
|
4644 */ );
|
|
4645
|
|
4646 DEFVAR_INT ("data-bytes-free", &malloc_sbrk_unused /*
|
|
4647 Number of bytes of unshared memory remaining available in this session.
|
|
4648 */ );
|
|
4649 #endif
|
|
4650
|
|
4651 #ifdef DEBUG_XEMACS
|
|
4652 DEFVAR_INT ("debug-allocation", &debug_allocation /*
|
|
4653 If non-zero, print out information to stderr about all objects allocated.
|
|
4654 See also `debug-allocation-backtrace-length'.
|
|
4655 */ );
|
|
4656 debug_allocation = 0;
|
|
4657
|
|
4658 DEFVAR_INT ("debug-allocation-backtrace-length",
|
|
4659 &debug_allocation_backtrace_length /*
|
|
4660 Length (in stack frames) of short backtrace printed out by `debug-allocation'.
|
|
4661 */ );
|
|
4662 debug_allocation_backtrace_length = 2;
|
|
4663 #endif
|
|
4664
|
|
4665 DEFVAR_BOOL ("purify-flag", &purify_flag /*
|
|
4666 Non-nil means loading Lisp code in order to dump an executable.
|
|
4667 This means that certain objects should be allocated in shared (pure) space.
|
|
4668 */ );
|
|
4669
|
|
4670 DEFVAR_LISP ("pre-gc-hook", &Vpre_gc_hook /*
|
|
4671 Function or functions to be run just before each garbage collection.
|
|
4672 Interrupts, garbage collection, and errors are inhibited while this hook
|
|
4673 runs, so be extremely careful in what you add here. In particular, avoid
|
|
4674 consing, and do not interact with the user.
|
|
4675 */ );
|
|
4676 Vpre_gc_hook = Qnil;
|
|
4677
|
|
4678 DEFVAR_LISP ("post-gc-hook", &Vpost_gc_hook /*
|
|
4679 Function or functions to be run just after each garbage collection.
|
|
4680 Interrupts, garbage collection, and errors are inhibited while this hook
|
|
4681 runs, so be extremely careful in what you add here. In particular, avoid
|
|
4682 consing, and do not interact with the user.
|
|
4683 */ );
|
|
4684 Vpost_gc_hook = Qnil;
|
|
4685
|
|
4686 DEFVAR_LISP ("gc-message", &Vgc_message /*
|
|
4687 String to print to indicate that a garbage collection is in progress.
|
|
4688 This is printed in the echo area. If the selected frame is on a
|
|
4689 window system and `gc-pointer-glyph' specifies a value (i.e. a pointer
|
|
4690 image instance) in the domain of the selected frame, the mouse pointer
|
|
4691 will change instead of this message being printed.
|
|
4692 */ );
|
|
4693 Vgc_message = make_pure_string ((CONST Bufbyte *) gc_default_message,
|
|
4694 countof (gc_default_message) - 1,
|
|
4695 Qnil, 1);
|
|
4696
|
|
4697 DEFVAR_LISP ("gc-pointer-glyph", &Vgc_pointer_glyph /*
|
|
4698 Pointer glyph used to indicate that a garbage collection is in progress.
|
|
4699 If the selected window is on a window system and this glyph specifies a
|
|
4700 value (i.e. a pointer image instance) in the domain of the selected
|
|
4701 window, the pointer will be changed as specified during garbage collection.
|
|
4702 Otherwise, a message will be printed in the echo area, as controlled
|
|
4703 by `gc-message'.
|
|
4704 */ );
|
|
4705 }
|
|
4706
|
|
4707 void
|
|
4708 complex_vars_of_alloc (void)
|
|
4709 {
|
|
4710 Vgc_pointer_glyph = Fmake_glyph_internal (Qpointer);
|
|
4711 }
|