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