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