1 /* Storage allocation and gc for XEmacs Lisp interpreter.
2 Copyright (C) 1985-1998 Free Software Foundation, Inc.
3 Copyright (C) 1995 Sun Microsystems, Inc.
4 Copyright (C) 1995, 1996 Ben Wing.
6 This file is part of XEmacs.
8 XEmacs is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with XEmacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* Synched up with: FSF 19.28, Mule 2.0. Substantially different from
28 FSF: Original version; a long time ago.
29 Mly: Significantly rewritten to use new 3-bit tags and
30 nicely abstracted object definitions, for 19.8.
31 JWZ: Improved code to keep track of purespace usage and
32 issue nice purespace and GC stats.
33 Ben Wing: Cleaned up frob-block lrecord code, added error-checking
34 and various changes for Mule, for 19.12.
35 Added bit vectors for 19.13.
36 Added lcrecord lists for 19.14.
37 slb: Lots of work on the purification and dump time code.
38 Synched Doug Lea malloc support from Emacs 20.2.
39 og: Killed the purespace. Portable dumper (moved to dumper.c)
46 #include "backtrace.h"
57 #include "redisplay.h"
58 #include "specifier.h"
62 #include "console-stream.h"
64 #ifdef DOUG_LEA_MALLOC
72 EXFUN (Fgarbage_collect, 0);
74 #if 0 /* this is _way_ too slow to be part of the standard debug options */
75 #if defined(DEBUG_XEMACS) && defined(MULE)
76 #define VERIFY_STRING_CHARS_INTEGRITY
80 /* Define this to use malloc/free with no freelist for all datatypes,
81 the hope being that some debugging tools may help detect
82 freed memory references */
83 #ifdef USE_DEBUG_MALLOC /* Taking the above comment at face value -slb */
85 #define ALLOC_NO_POOLS
89 static int debug_allocation;
90 static int debug_allocation_backtrace_length;
93 /* Number of bytes of consing done since the last gc */
94 EMACS_INT consing_since_gc;
95 #define INCREMENT_CONS_COUNTER_1(size) (consing_since_gc += (size))
97 #define debug_allocation_backtrace() \
99 if (debug_allocation_backtrace_length > 0) \
100 debug_short_backtrace (debug_allocation_backtrace_length); \
104 #define INCREMENT_CONS_COUNTER(foosize, type) \
106 if (debug_allocation) \
108 stderr_out ("allocating %s (size %ld)\n", type, (long)foosize); \
109 debug_allocation_backtrace (); \
111 INCREMENT_CONS_COUNTER_1 (foosize); \
113 #define NOSEEUM_INCREMENT_CONS_COUNTER(foosize, type) \
115 if (debug_allocation > 1) \
117 stderr_out ("allocating noseeum %s (size %ld)\n", type, (long)foosize); \
118 debug_allocation_backtrace (); \
120 INCREMENT_CONS_COUNTER_1 (foosize); \
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)
128 #define DECREMENT_CONS_COUNTER(size) do { \
129 consing_since_gc -= (size); \
130 if (consing_since_gc < 0) \
131 consing_since_gc = 0; \
134 /* Number of bytes of consing since gc before another gc should be done. */
135 EMACS_INT gc_cons_threshold;
137 /* Nonzero during gc */
140 /* Number of times GC has happened at this level or below.
141 * Level 0 is most volatile, contrary to usual convention.
142 * (Of course, there's only one level at present) */
143 EMACS_INT gc_generation_number[1];
145 /* This is just for use by the printer, to allow things to print uniquely */
146 static int lrecord_uid_counter;
148 /* Nonzero when calling certain hooks or doing other things where
150 int gc_currently_forbidden;
153 Lisp_Object Vpre_gc_hook, Qpre_gc_hook;
154 Lisp_Object Vpost_gc_hook, Qpost_gc_hook;
156 /* "Garbage collecting" */
157 Lisp_Object Vgc_message;
158 Lisp_Object Vgc_pointer_glyph;
159 static const char gc_default_message[] = "Garbage collecting";
160 Lisp_Object Qgarbage_collecting;
162 #ifndef VIRT_ADDR_VARIES
164 #endif /* VIRT_ADDR_VARIES */
165 EMACS_INT malloc_sbrk_used;
167 #ifndef VIRT_ADDR_VARIES
169 #endif /* VIRT_ADDR_VARIES */
170 EMACS_INT malloc_sbrk_unused;
172 /* Non-zero means we're in the process of doing the dump */
175 #ifdef ERROR_CHECK_TYPECHECK
177 Error_behavior ERROR_ME, ERROR_ME_NOT, ERROR_ME_WARN;
182 c_readonly (Lisp_Object obj)
184 return POINTER_TYPE_P (XTYPE (obj)) && C_READONLY (obj);
188 lisp_readonly (Lisp_Object obj)
190 return POINTER_TYPE_P (XTYPE (obj)) && LISP_READONLY (obj);
194 /* Maximum amount of C stack to save when a GC happens. */
196 #ifndef MAX_SAVE_STACK
197 #define MAX_SAVE_STACK 0 /* 16000 */
200 /* Non-zero means ignore malloc warnings. Set during initialization. */
201 int ignore_malloc_warnings;
204 static void *breathing_space;
207 release_breathing_space (void)
211 void *tmp = breathing_space;
217 /* malloc calls this if it finds we are near exhausting storage */
219 malloc_warning (const char *str)
221 if (ignore_malloc_warnings)
227 "Killing some buffers may delay running out of memory.\n"
228 "However, certainly by the time you receive the 95%% warning,\n"
229 "you should clean up, kill this Emacs, and start a new one.",
233 /* Called if malloc returns zero */
237 /* Force a GC next time eval is called.
238 It's better to loop garbage-collecting (we might reclaim enough
239 to win) than to loop beeping and barfing "Memory exhausted"
241 consing_since_gc = gc_cons_threshold + 1;
242 release_breathing_space ();
244 /* Flush some histories which might conceivably contain garbalogical
246 if (!NILP (Fboundp (Qvalues)))
247 Fset (Qvalues, Qnil);
248 Vcommand_history = Qnil;
250 error ("Memory exhausted");
253 /* like malloc and realloc but check for no memory left, and block input. */
257 xmalloc (size_t size)
259 void *val = malloc (size);
261 if (!val && (size != 0)) memory_full ();
267 xcalloc (size_t nelem, size_t elsize)
269 void *val = calloc (nelem, elsize);
271 if (!val && (nelem != 0)) memory_full ();
276 xmalloc_and_zero (size_t size)
278 return xcalloc (size, sizeof (char));
283 xrealloc (void *block, size_t size)
285 /* We must call malloc explicitly when BLOCK is 0, since some
286 reallocs don't do this. */
287 void *val = block ? realloc (block, size) : malloc (size);
289 if (!val && (size != 0)) memory_full ();
294 #ifdef ERROR_CHECK_MALLOC
295 xfree_1 (void *block)
300 #ifdef ERROR_CHECK_MALLOC
301 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an
302 error until much later on for many system mallocs, such as
303 the one that comes with Solaris 2.3. FMH!! */
304 assert (block != (void *) 0xDEADBEEF);
306 #endif /* ERROR_CHECK_MALLOC */
310 #ifdef ERROR_CHECK_GC
313 typedef unsigned int four_byte_t;
314 #elif SIZEOF_LONG == 4
315 typedef unsigned long four_byte_t;
316 #elif SIZEOF_SHORT == 4
317 typedef unsigned short four_byte_t;
319 What kind of strange-ass system are we running on?
323 deadbeef_memory (void *ptr, size_t size)
325 four_byte_t *ptr4 = (four_byte_t *) ptr;
326 size_t beefs = size >> 2;
328 /* In practice, size will always be a multiple of four. */
330 (*ptr4++) = 0xDEADBEEF;
333 #else /* !ERROR_CHECK_GC */
336 #define deadbeef_memory(ptr, size)
338 #endif /* !ERROR_CHECK_GC */
342 xstrdup (const char *str)
344 int len = strlen (str) + 1; /* for stupid terminating 0 */
346 void *val = xmalloc (len);
347 if (val == 0) return 0;
348 return (char *) memcpy (val, str, len);
353 strdup (const char *s)
357 #endif /* NEED_STRDUP */
361 allocate_lisp_storage (size_t size)
363 return xmalloc (size);
367 /* lcrecords are chained together through their "next" field.
368 After doing the mark phase, GC will walk this linked list
369 and free any lcrecord which hasn't been marked. */
370 static struct lcrecord_header *all_lcrecords;
373 alloc_lcrecord (size_t size, const struct lrecord_implementation *implementation)
375 struct lcrecord_header *lcheader;
378 ((implementation->static_size == 0 ?
379 implementation->size_in_bytes_method != NULL :
380 implementation->static_size == size)
382 (! implementation->basic_p)
384 (! (implementation->hash == NULL && implementation->equal != NULL)));
386 lcheader = (struct lcrecord_header *) allocate_lisp_storage (size);
387 set_lheader_implementation (&lcheader->lheader, implementation);
388 lcheader->next = all_lcrecords;
389 #if 1 /* mly prefers to see small ID numbers */
390 lcheader->uid = lrecord_uid_counter++;
391 #else /* jwz prefers to see real addrs */
392 lcheader->uid = (int) &lcheader;
395 all_lcrecords = lcheader;
396 INCREMENT_CONS_COUNTER (size, implementation->name);
400 #if 0 /* Presently unused */
401 /* Very, very poor man's EGC?
402 * This may be slow and thrash pages all over the place.
403 * Only call it if you really feel you must (and if the
404 * lrecord was fairly recently allocated).
405 * Otherwise, just let the GC do its job -- that's what it's there for
408 free_lcrecord (struct lcrecord_header *lcrecord)
410 if (all_lcrecords == lcrecord)
412 all_lcrecords = lcrecord->next;
416 struct lrecord_header *header = all_lcrecords;
419 struct lrecord_header *next = header->next;
420 if (next == lcrecord)
422 header->next = lrecord->next;
431 if (lrecord->implementation->finalizer)
432 lrecord->implementation->finalizer (lrecord, 0);
440 disksave_object_finalization_1 (void)
442 struct lcrecord_header *header;
444 for (header = all_lcrecords; header; header = header->next)
446 if (LHEADER_IMPLEMENTATION (&header->lheader)->finalizer &&
448 LHEADER_IMPLEMENTATION (&header->lheader)->finalizer (header, 1);
453 /************************************************************************/
454 /* Debugger support */
455 /************************************************************************/
456 /* Give gdb/dbx enough information to decode Lisp Objects. We make
457 sure certain symbols are always defined, so gdb doesn't complain
458 about expressions in src/.gdbinit. See src/.gdbinit or src/.dbxrc
459 to see how this is used. */
461 EMACS_UINT dbg_valmask = ((1UL << VALBITS) - 1) << GCBITS;
462 EMACS_UINT dbg_typemask = (1UL << GCTYPEBITS) - 1;
464 #ifdef USE_UNION_TYPE
465 unsigned char dbg_USE_UNION_TYPE = 1;
467 unsigned char dbg_USE_UNION_TYPE = 0;
470 unsigned char dbg_valbits = VALBITS;
471 unsigned char dbg_gctypebits = GCTYPEBITS;
473 /* Macros turned into functions for ease of debugging.
474 Debuggers don't know about macros! */
475 int dbg_eq (Lisp_Object obj1, Lisp_Object obj2);
477 dbg_eq (Lisp_Object obj1, Lisp_Object obj2)
479 return EQ (obj1, obj2);
483 /************************************************************************/
484 /* Fixed-size type macros */
485 /************************************************************************/
487 /* For fixed-size types that are commonly used, we malloc() large blocks
488 of memory at a time and subdivide them into chunks of the correct
489 size for an object of that type. This is more efficient than
490 malloc()ing each object separately because we save on malloc() time
491 and overhead due to the fewer number of malloc()ed blocks, and
492 also because we don't need any extra pointers within each object
493 to keep them threaded together for GC purposes. For less common
494 (and frequently large-size) types, we use lcrecords, which are
495 malloc()ed individually and chained together through a pointer
496 in the lcrecord header. lcrecords do not need to be fixed-size
497 (i.e. two objects of the same type need not have the same size;
498 however, the size of a particular object cannot vary dynamically).
499 It is also much easier to create a new lcrecord type because no
500 additional code needs to be added to alloc.c. Finally, lcrecords
501 may be more efficient when there are only a small number of them.
503 The types that are stored in these large blocks (or "frob blocks")
504 are cons, float, compiled-function, symbol, marker, extent, event,
507 Note that strings are special in that they are actually stored in
508 two parts: a structure containing information about the string, and
509 the actual data associated with the string. The former structure
510 (a struct Lisp_String) is a fixed-size structure and is managed the
511 same way as all the other such types. This structure contains a
512 pointer to the actual string data, which is stored in structures of
513 type struct string_chars_block. Each string_chars_block consists
514 of a pointer to a struct Lisp_String, followed by the data for that
515 string, followed by another pointer to a Lisp_String, followed by
516 the data for that string, etc. At GC time, the data in these
517 blocks is compacted by searching sequentially through all the
518 blocks and compressing out any holes created by unmarked strings.
519 Strings that are more than a certain size (bigger than the size of
520 a string_chars_block, although something like half as big might
521 make more sense) are malloc()ed separately and not stored in
522 string_chars_blocks. Furthermore, no one string stretches across
523 two string_chars_blocks.
525 Vectors are each malloc()ed separately, similar to lcrecords.
527 In the following discussion, we use conses, but it applies equally
528 well to the other fixed-size types.
530 We store cons cells inside of cons_blocks, allocating a new
531 cons_block with malloc() whenever necessary. Cons cells reclaimed
532 by GC are put on a free list to be reallocated before allocating
533 any new cons cells from the latest cons_block. Each cons_block is
534 just under 2^n - MALLOC_OVERHEAD bytes long, since malloc (at least
535 the versions in malloc.c and gmalloc.c) really allocates in units
536 of powers of two and uses 4 bytes for its own overhead.
538 What GC actually does is to search through all the cons_blocks,
539 from the most recently allocated to the oldest, and put all
540 cons cells that are not marked (whether or not they're already
541 free) on a cons_free_list. The cons_free_list is a stack, and
542 so the cons cells in the oldest-allocated cons_block end up
543 at the head of the stack and are the first to be reallocated.
544 If any cons_block is entirely free, it is freed with free()
545 and its cons cells removed from the cons_free_list. Because
546 the cons_free_list ends up basically in memory order, we have
547 a high locality of reference (assuming a reasonable turnover
548 of allocating and freeing) and have a reasonable probability
549 of entirely freeing up cons_blocks that have been more recently
550 allocated. This stage is called the "sweep stage" of GC, and
551 is executed after the "mark stage", which involves starting
552 from all places that are known to point to in-use Lisp objects
553 (e.g. the obarray, where are all symbols are stored; the
554 current catches and condition-cases; the backtrace list of
555 currently executing functions; the gcpro list; etc.) and
556 recursively marking all objects that are accessible.
558 At the beginning of the sweep stage, the conses in the cons
559 blocks are in one of three states: in use and marked, in use
560 but not marked, and not in use (already freed). Any conses
561 that are marked have been marked in the mark stage just
562 executed, because as part of the sweep stage we unmark any
563 marked objects. The way we tell whether or not a cons cell
564 is in use is through the FREE_STRUCT_P macro. This basically
565 looks at the first 4 bytes (or however many bytes a pointer
566 fits in) to see if all the bits in those bytes are 1. The
567 resulting value (0xFFFFFFFF) is not a valid pointer and is
568 not a valid Lisp_Object. All current fixed-size types have
569 a pointer or Lisp_Object as their first element with the
570 exception of strings; they have a size value, which can
571 never be less than zero, and so 0xFFFFFFFF is invalid for
572 strings as well. Now assuming that a cons cell is in use,
573 the way we tell whether or not it is marked is to look at
574 the mark bit of its car (each Lisp_Object has one bit
575 reserved as a mark bit, in case it's needed). Note that
576 different types of objects use different fields to indicate
577 whether the object is marked, but the principle is the same.
579 Conses on the free_cons_list are threaded through a pointer
580 stored in the bytes directly after the bytes that are set
581 to 0xFFFFFFFF (we cannot overwrite these because the cons
582 is still in a cons_block and needs to remain marked as
583 not in use for the next time that GC happens). This
584 implies that all fixed-size types must be at least big
585 enough to store two pointers, which is indeed the case
586 for all current fixed-size types.
588 Some types of objects need additional "finalization" done
589 when an object is converted from in use to not in use;
590 this is the purpose of the ADDITIONAL_FREE_type macro.
591 For example, markers need to be removed from the chain
592 of markers that is kept in each buffer. This is because
593 markers in a buffer automatically disappear if the marker
594 is no longer referenced anywhere (the same does not
595 apply to extents, however).
597 WARNING: Things are in an extremely bizarre state when
598 the ADDITIONAL_FREE_type macros are called, so beware!
600 When ERROR_CHECK_GC is defined, we do things differently
601 so as to maximize our chances of catching places where
602 there is insufficient GCPROing. The thing we want to
603 avoid is having an object that we're using but didn't
604 GCPRO get freed by GC and then reallocated while we're
605 in the process of using it -- this will result in something
606 seemingly unrelated getting trashed, and is extremely
607 difficult to track down. If the object gets freed but
608 not reallocated, we can usually catch this because we
609 set all bytes of a freed object to 0xDEADBEEF. (The
610 first four bytes, however, are 0xFFFFFFFF, and the next
611 four are a pointer used to chain freed objects together;
612 we play some tricks with this pointer to make it more
613 bogus, so crashes are more likely to occur right away.)
615 We want freed objects to stay free as long as possible,
616 so instead of doing what we do above, we maintain the
617 free objects in a first-in first-out queue. We also
618 don't recompute the free list each GC, unlike above;
619 this ensures that the queue ordering is preserved.
620 [This means that we are likely to have worse locality
621 of reference, and that we can never free a frob block
622 once it's allocated. (Even if we know that all cells
623 in it are free, there's no easy way to remove all those
624 cells from the free list because the objects on the
625 free list are unlikely to be in memory order.)]
626 Furthermore, we never take objects off the free list
627 unless there's a large number (usually 1000, but
628 varies depending on type) of them already on the list.
629 This way, we ensure that an object that gets freed will
630 remain free for the next 1000 (or whatever) times that
631 an object of that type is allocated. */
633 #ifndef MALLOC_OVERHEAD
635 #define MALLOC_OVERHEAD 0
636 #elif defined (rcheck)
637 #define MALLOC_OVERHEAD 20
639 #define MALLOC_OVERHEAD 8
641 #endif /* MALLOC_OVERHEAD */
643 #if !defined(HAVE_MMAP) || defined(DOUG_LEA_MALLOC)
644 /* If we released our reserve (due to running out of memory),
645 and we have a fair amount free once again,
646 try to set aside another reserve in case we run out once more.
648 This is called when a relocatable block is freed in ralloc.c. */
649 void refill_memory_reserve (void);
651 refill_memory_reserve (void)
653 if (breathing_space == 0)
654 breathing_space = (char *) malloc (4096 - MALLOC_OVERHEAD);
658 #ifdef ALLOC_NO_POOLS
659 # define TYPE_ALLOC_SIZE(type, structtype) 1
661 # define TYPE_ALLOC_SIZE(type, structtype) \
662 ((2048 - MALLOC_OVERHEAD - sizeof (struct type##_block *)) \
663 / sizeof (structtype))
664 #endif /* ALLOC_NO_POOLS */
666 #define DECLARE_FIXED_TYPE_ALLOC(type, structtype) \
668 struct type##_block \
670 struct type##_block *prev; \
671 structtype block[TYPE_ALLOC_SIZE (type, structtype)]; \
674 static struct type##_block *current_##type##_block; \
675 static int current_##type##_block_index; \
677 static structtype *type##_free_list; \
678 static structtype *type##_free_list_tail; \
681 init_##type##_alloc (void) \
683 current_##type##_block = 0; \
684 current_##type##_block_index = \
685 countof (current_##type##_block->block); \
686 type##_free_list = 0; \
687 type##_free_list_tail = 0; \
690 static int gc_count_num_##type##_in_use; \
691 static int gc_count_num_##type##_freelist
693 #define ALLOCATE_FIXED_TYPE_FROM_BLOCK(type, result) do { \
694 if (current_##type##_block_index \
695 == countof (current_##type##_block->block)) \
697 struct type##_block *AFTFB_new = (struct type##_block *) \
698 allocate_lisp_storage (sizeof (struct type##_block)); \
699 AFTFB_new->prev = current_##type##_block; \
700 current_##type##_block = AFTFB_new; \
701 current_##type##_block_index = 0; \
704 &(current_##type##_block->block[current_##type##_block_index++]); \
707 /* Allocate an instance of a type that is stored in blocks.
708 TYPE is the "name" of the type, STRUCTTYPE is the corresponding
711 #ifdef ERROR_CHECK_GC
713 /* Note: if you get crashes in this function, suspect incorrect calls
714 to free_cons() and friends. This happened once because the cons
715 cell was not GC-protected and was getting collected before
716 free_cons() was called. */
718 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) \
721 if (gc_count_num_##type##_freelist > \
722 MINIMUM_ALLOWED_FIXED_TYPE_CELLS_##type) \
724 result = type##_free_list; \
725 /* Before actually using the chain pointer, we complement all its \
726 bits; see FREE_FIXED_TYPE(). */ \
728 (structtype *) ~(unsigned long) \
729 (* (structtype **) ((char *) result + sizeof (void *))); \
730 gc_count_num_##type##_freelist--; \
733 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \
734 MARK_STRUCT_AS_NOT_FREE (result); \
737 #else /* !ERROR_CHECK_GC */
739 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) \
742 if (type##_free_list) \
744 result = type##_free_list; \
746 * (structtype **) ((char *) result + sizeof (void *)); \
749 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \
750 MARK_STRUCT_AS_NOT_FREE (result); \
753 #endif /* !ERROR_CHECK_GC */
755 #define ALLOCATE_FIXED_TYPE(type, structtype, result) \
758 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \
759 INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \
762 #define NOSEEUM_ALLOCATE_FIXED_TYPE(type, structtype, result) \
765 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \
766 NOSEEUM_INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \
769 /* INVALID_POINTER_VALUE should be a value that is invalid as a pointer
770 to a Lisp object and invalid as an actual Lisp_Object value. We have
771 to make sure that this value cannot be an integer in Lisp_Object form.
772 0xFFFFFFFF could be so on a 64-bit system, so we extend it to 64 bits.
773 On a 32-bit system, the type bits will be non-zero, making the value
774 be a pointer, and the pointer will be misaligned.
776 Even if Emacs is run on some weirdo system that allows and allocates
777 byte-aligned pointers, this pointer is at the very top of the address
778 space and so it's almost inconceivable that it could ever be valid. */
781 # define INVALID_POINTER_VALUE 0xFFFFFFFF
783 # define INVALID_POINTER_VALUE 0xFFFFFFFFFFFF
785 # define INVALID_POINTER_VALUE 0xFFFFFFFFFFFFFFFF
787 You have some weird system and need to supply a reasonable value here.
790 /* The construct (* (void **) (ptr)) would cause aliasing problems
791 with modern optimizing compilers like `gcc -O3 -fstrict-aliasing'.
792 But `char *' can legally alias any pointer. Hence this union trick. */
793 typedef union { char c; void *p; } *aliasing_voidpp;
794 #define ALIASING_VOIDPP_DEREFERENCE(ptr) \
795 (((aliasing_voidpp) (ptr))->p)
796 #define FREE_STRUCT_P(ptr) \
797 (ALIASING_VOIDPP_DEREFERENCE (ptr) == (void *) INVALID_POINTER_VALUE)
798 #define MARK_STRUCT_AS_FREE(ptr) \
799 (ALIASING_VOIDPP_DEREFERENCE (ptr) = (void *) INVALID_POINTER_VALUE)
800 #define MARK_STRUCT_AS_NOT_FREE(ptr) \
801 (ALIASING_VOIDPP_DEREFERENCE (ptr) = 0)
803 #ifdef ERROR_CHECK_GC
805 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) \
806 do { if (type##_free_list_tail) \
808 /* When we store the chain pointer, we complement all \
809 its bits; this should significantly increase its \
810 bogosity in case someone tries to use the value, and \
811 should make us dump faster if someone stores something \
812 over the pointer because when it gets un-complemented in \
813 ALLOCATED_FIXED_TYPE(), the resulting pointer will be \
814 extremely bogus. */ \
816 ((char *) type##_free_list_tail + sizeof (void *)) = \
817 (structtype *) ~(unsigned long) ptr; \
820 type##_free_list = ptr; \
821 type##_free_list_tail = ptr; \
824 #else /* !ERROR_CHECK_GC */
826 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) \
827 do { * (structtype **) ((char *) (ptr) + sizeof (void *)) = \
829 type##_free_list = (ptr); \
832 #endif /* !ERROR_CHECK_GC */
834 /* TYPE and STRUCTTYPE are the same as in ALLOCATE_FIXED_TYPE(). */
836 #define FREE_FIXED_TYPE(type, structtype, ptr) do { \
837 structtype *FFT_ptr = (ptr); \
838 ADDITIONAL_FREE_##type (FFT_ptr); \
839 deadbeef_memory (FFT_ptr, sizeof (structtype)); \
840 PUT_FIXED_TYPE_ON_FREE_LIST (type, structtype, FFT_ptr); \
841 MARK_STRUCT_AS_FREE (FFT_ptr); \
844 /* Like FREE_FIXED_TYPE() but used when we are explicitly
845 freeing a structure through free_cons(), free_marker(), etc.
846 rather than through the normal process of sweeping.
847 We attempt to undo the changes made to the allocation counters
848 as a result of this structure being allocated. This is not
849 completely necessary but helps keep things saner: e.g. this way,
850 repeatedly allocating and freeing a cons will not result in
851 the consing-since-gc counter advancing, which would cause a GC
852 and somewhat defeat the purpose of explicitly freeing. */
854 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(type, structtype, ptr) \
855 do { FREE_FIXED_TYPE (type, structtype, ptr); \
856 DECREMENT_CONS_COUNTER (sizeof (structtype)); \
857 gc_count_num_##type##_freelist++; \
862 /************************************************************************/
863 /* Cons allocation */
864 /************************************************************************/
866 DECLARE_FIXED_TYPE_ALLOC (cons, Lisp_Cons);
867 /* conses are used and freed so often that we set this really high */
868 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 20000 */
869 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 2000
872 mark_cons (Lisp_Object obj)
874 if (NILP (XCDR (obj)))
877 mark_object (XCAR (obj));
882 cons_equal (Lisp_Object ob1, Lisp_Object ob2, int depth)
885 while (internal_equal (XCAR (ob1), XCAR (ob2), depth))
889 if (! CONSP (ob1) || ! CONSP (ob2))
890 return internal_equal (ob1, ob2, depth);
895 static const struct lrecord_description cons_description[] = {
896 { XD_LISP_OBJECT, offsetof (Lisp_Cons, car) },
897 { XD_LISP_OBJECT, offsetof (Lisp_Cons, cdr) },
901 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("cons", cons,
902 mark_cons, print_cons, 0,
905 * No `hash' method needed.
906 * internal_hash knows how to
913 DEFUN ("cons", Fcons, 2, 2, 0, /*
914 Create a new cons, give it CAR and CDR as components, and return it.
918 /* This cannot GC. */
922 ALLOCATE_FIXED_TYPE (cons, Lisp_Cons, c);
923 set_lheader_implementation (&c->lheader, &lrecord_cons);
930 /* This is identical to Fcons() but it used for conses that we're
931 going to free later, and is useful when trying to track down
934 noseeum_cons (Lisp_Object car, Lisp_Object cdr)
939 NOSEEUM_ALLOCATE_FIXED_TYPE (cons, Lisp_Cons, c);
940 set_lheader_implementation (&c->lheader, &lrecord_cons);
947 DEFUN ("list", Flist, 0, MANY, 0, /*
948 Return a newly created list with specified arguments as elements.
949 Any number of arguments, even zero arguments, are allowed.
951 (int nargs, Lisp_Object *args))
953 Lisp_Object val = Qnil;
954 Lisp_Object *argp = args + nargs;
957 val = Fcons (*--argp, val);
962 list1 (Lisp_Object obj0)
964 /* This cannot GC. */
965 return Fcons (obj0, Qnil);
969 list2 (Lisp_Object obj0, Lisp_Object obj1)
971 /* This cannot GC. */
972 return Fcons (obj0, Fcons (obj1, Qnil));
976 list3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
978 /* This cannot GC. */
979 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Qnil)));
983 cons3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
985 /* This cannot GC. */
986 return Fcons (obj0, Fcons (obj1, obj2));
990 acons (Lisp_Object key, Lisp_Object value, Lisp_Object alist)
992 return Fcons (Fcons (key, value), alist);
996 list4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3)
998 /* This cannot GC. */
999 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Qnil))));
1003 list5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3,
1006 /* This cannot GC. */
1007 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Fcons (obj4, Qnil)))));
1011 list6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3,
1012 Lisp_Object obj4, Lisp_Object obj5)
1014 /* This cannot GC. */
1015 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Fcons (obj4, Fcons (obj5, Qnil))))));
1018 DEFUN ("make-list", Fmake_list, 2, 2, 0, /*
1019 Return a new list of length LENGTH, with each element being INIT.
1023 CHECK_NATNUM (length);
1026 Lisp_Object val = Qnil;
1027 size_t size = XINT (length);
1030 val = Fcons (init, val);
1036 /************************************************************************/
1037 /* Float allocation */
1038 /************************************************************************/
1040 #ifdef LISP_FLOAT_TYPE
1042 DECLARE_FIXED_TYPE_ALLOC (float, Lisp_Float);
1043 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_float 1000
1046 make_float (double float_value)
1051 ALLOCATE_FIXED_TYPE (float, Lisp_Float, f);
1053 /* Avoid dump-time `uninitialized memory read' purify warnings. */
1054 if (sizeof (struct lrecord_header) + sizeof (double) != sizeof (*f))
1057 set_lheader_implementation (&f->lheader, &lrecord_float);
1058 float_data (f) = float_value;
1063 #endif /* LISP_FLOAT_TYPE */
1066 /************************************************************************/
1067 /* Vector allocation */
1068 /************************************************************************/
1071 mark_vector (Lisp_Object obj)
1073 Lisp_Vector *ptr = XVECTOR (obj);
1074 int len = vector_length (ptr);
1077 for (i = 0; i < len - 1; i++)
1078 mark_object (ptr->contents[i]);
1079 return (len > 0) ? ptr->contents[len - 1] : Qnil;
1083 size_vector (const void *lheader)
1085 return offsetof (Lisp_Vector, contents[((Lisp_Vector *) lheader)->size]);
1089 vector_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
1091 int len = XVECTOR_LENGTH (obj1);
1092 if (len != XVECTOR_LENGTH (obj2))
1096 Lisp_Object *ptr1 = XVECTOR_DATA (obj1);
1097 Lisp_Object *ptr2 = XVECTOR_DATA (obj2);
1099 if (!internal_equal (*ptr1++, *ptr2++, depth + 1))
1106 vector_hash (Lisp_Object obj, int depth)
1108 return HASH2 (XVECTOR_LENGTH (obj),
1109 internal_array_hash (XVECTOR_DATA (obj),
1110 XVECTOR_LENGTH (obj),
1114 static const struct lrecord_description vector_description[] = {
1115 { XD_LONG, offsetof (Lisp_Vector, size) },
1116 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Vector, contents), XD_INDIRECT(0, 0) },
1120 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION("vector", vector,
1121 mark_vector, print_vector, 0,
1125 size_vector, Lisp_Vector);
1127 /* #### should allocate `small' vectors from a frob-block */
1128 static Lisp_Vector *
1129 make_vector_internal (size_t sizei)
1131 /* no vector_next */
1132 size_t sizem = offsetof (Lisp_Vector, contents[sizei]);
1133 Lisp_Vector *p = (Lisp_Vector *) alloc_lcrecord (sizem, &lrecord_vector);
1140 make_vector (size_t length, Lisp_Object init)
1142 Lisp_Vector *vecp = make_vector_internal (length);
1143 Lisp_Object *p = vector_data (vecp);
1150 XSETVECTOR (vector, vecp);
1155 DEFUN ("make-vector", Fmake_vector, 2, 2, 0, /*
1156 Return a new vector of length LENGTH, with each element being INIT.
1157 See also the function `vector'.
1161 CONCHECK_NATNUM (length);
1162 return make_vector (XINT (length), init);
1165 DEFUN ("vector", Fvector, 0, MANY, 0, /*
1166 Return a newly created vector with specified arguments as elements.
1167 Any number of arguments, even zero arguments, are allowed.
1169 (int nargs, Lisp_Object *args))
1171 Lisp_Vector *vecp = make_vector_internal (nargs);
1172 Lisp_Object *p = vector_data (vecp);
1179 XSETVECTOR (vector, vecp);
1185 vector1 (Lisp_Object obj0)
1187 return Fvector (1, &obj0);
1191 vector2 (Lisp_Object obj0, Lisp_Object obj1)
1193 Lisp_Object args[2];
1196 return Fvector (2, args);
1200 vector3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
1202 Lisp_Object args[3];
1206 return Fvector (3, args);
1209 #if 0 /* currently unused */
1212 vector4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
1215 Lisp_Object args[4];
1220 return Fvector (4, args);
1224 vector5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
1225 Lisp_Object obj3, Lisp_Object obj4)
1227 Lisp_Object args[5];
1233 return Fvector (5, args);
1237 vector6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
1238 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5)
1240 Lisp_Object args[6];
1247 return Fvector (6, args);
1251 vector7 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
1252 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5,
1255 Lisp_Object args[7];
1263 return Fvector (7, args);
1267 vector8 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
1268 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5,
1269 Lisp_Object obj6, Lisp_Object obj7)
1271 Lisp_Object args[8];
1280 return Fvector (8, args);
1284 /************************************************************************/
1285 /* Bit Vector allocation */
1286 /************************************************************************/
1288 static Lisp_Object all_bit_vectors;
1290 /* #### should allocate `small' bit vectors from a frob-block */
1291 static Lisp_Bit_Vector *
1292 make_bit_vector_internal (size_t sizei)
1294 size_t num_longs = BIT_VECTOR_LONG_STORAGE (sizei);
1295 size_t sizem = offsetof (Lisp_Bit_Vector, bits[num_longs]);
1296 Lisp_Bit_Vector *p = (Lisp_Bit_Vector *) allocate_lisp_storage (sizem);
1297 set_lheader_implementation (&p->lheader, &lrecord_bit_vector);
1299 INCREMENT_CONS_COUNTER (sizem, "bit-vector");
1301 bit_vector_length (p) = sizei;
1302 bit_vector_next (p) = all_bit_vectors;
1303 /* make sure the extra bits in the last long are 0; the calling
1304 functions might not set them. */
1305 p->bits[num_longs - 1] = 0;
1306 XSETBIT_VECTOR (all_bit_vectors, p);
1311 make_bit_vector (size_t length, Lisp_Object init)
1313 Lisp_Bit_Vector *p = make_bit_vector_internal (length);
1314 size_t num_longs = BIT_VECTOR_LONG_STORAGE (length);
1319 memset (p->bits, 0, num_longs * sizeof (long));
1322 size_t bits_in_last = length & (LONGBITS_POWER_OF_2 - 1);
1323 memset (p->bits, ~0, num_longs * sizeof (long));
1324 /* But we have to make sure that the unused bits in the
1325 last long are 0, so that equal/hash is easy. */
1327 p->bits[num_longs - 1] &= (1 << bits_in_last) - 1;
1331 Lisp_Object bit_vector;
1332 XSETBIT_VECTOR (bit_vector, p);
1338 make_bit_vector_from_byte_vector (unsigned char *bytevec, size_t length)
1341 Lisp_Bit_Vector *p = make_bit_vector_internal (length);
1343 for (i = 0; i < length; i++)
1344 set_bit_vector_bit (p, i, bytevec[i]);
1347 Lisp_Object bit_vector;
1348 XSETBIT_VECTOR (bit_vector, p);
1353 DEFUN ("make-bit-vector", Fmake_bit_vector, 2, 2, 0, /*
1354 Return a new bit vector of length LENGTH. with each bit being INIT.
1355 Each element is set to INIT. See also the function `bit-vector'.
1359 CONCHECK_NATNUM (length);
1361 return make_bit_vector (XINT (length), init);
1364 DEFUN ("bit-vector", Fbit_vector, 0, MANY, 0, /*
1365 Return a newly created bit vector with specified arguments as elements.
1366 Any number of arguments, even zero arguments, are allowed.
1368 (int nargs, Lisp_Object *args))
1371 Lisp_Bit_Vector *p = make_bit_vector_internal (nargs);
1373 for (i = 0; i < nargs; i++)
1375 CHECK_BIT (args[i]);
1376 set_bit_vector_bit (p, i, !ZEROP (args[i]));
1380 Lisp_Object bit_vector;
1381 XSETBIT_VECTOR (bit_vector, p);
1387 /************************************************************************/
1388 /* Compiled-function allocation */
1389 /************************************************************************/
1391 DECLARE_FIXED_TYPE_ALLOC (compiled_function, Lisp_Compiled_Function);
1392 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_compiled_function 1000
1395 make_compiled_function (void)
1397 Lisp_Compiled_Function *f;
1400 ALLOCATE_FIXED_TYPE (compiled_function, Lisp_Compiled_Function, f);
1401 set_lheader_implementation (&f->lheader, &lrecord_compiled_function);
1404 f->specpdl_depth = 0;
1405 f->flags.documentationp = 0;
1406 f->flags.interactivep = 0;
1407 f->flags.domainp = 0; /* I18N3 */
1408 f->instructions = Qzero;
1409 f->constants = Qzero;
1411 f->doc_and_interactive = Qnil;
1412 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
1413 f->annotated = Qnil;
1415 XSETCOMPILED_FUNCTION (fun, f);
1419 DEFUN ("make-byte-code", Fmake_byte_code, 4, MANY, 0, /*
1420 Return a new compiled-function object.
1421 Usage: (arglist instructions constants stack-depth
1422 &optional doc-string interactive)
1423 Note that, unlike all other emacs-lisp functions, calling this with five
1424 arguments is NOT the same as calling it with six arguments, the last of
1425 which is nil. If the INTERACTIVE arg is specified as nil, then that means
1426 that this function was defined with `(interactive)'. If the arg is not
1427 specified, then that means the function is not interactive.
1428 This is terrible behavior which is retained for compatibility with old
1429 `.elc' files which expect these semantics.
1431 (int nargs, Lisp_Object *args))
1433 /* In a non-insane world this function would have this arglist...
1434 (arglist instructions constants stack_depth &optional doc_string interactive)
1436 Lisp_Object fun = make_compiled_function ();
1437 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (fun);
1439 Lisp_Object arglist = args[0];
1440 Lisp_Object instructions = args[1];
1441 Lisp_Object constants = args[2];
1442 Lisp_Object stack_depth = args[3];
1443 Lisp_Object doc_string = (nargs > 4) ? args[4] : Qnil;
1444 Lisp_Object interactive = (nargs > 5) ? args[5] : Qunbound;
1446 if (nargs < 4 || nargs > 6)
1447 return Fsignal (Qwrong_number_of_arguments,
1448 list2 (intern ("make-byte-code"), make_int (nargs)));
1450 /* Check for valid formal parameter list now, to allow us to use
1451 SPECBIND_FAST_UNSAFE() later in funcall_compiled_function(). */
1453 Lisp_Object symbol, tail;
1454 EXTERNAL_LIST_LOOP_3 (symbol, arglist, tail)
1456 CHECK_SYMBOL (symbol);
1457 if (EQ (symbol, Qt) ||
1458 EQ (symbol, Qnil) ||
1459 SYMBOL_IS_KEYWORD (symbol))
1460 signal_simple_error_2
1461 ("Invalid constant symbol in formal parameter list",
1465 f->arglist = arglist;
1467 /* `instructions' is a string or a cons (string . int) for a
1468 lazy-loaded function. */
1469 if (CONSP (instructions))
1471 CHECK_STRING (XCAR (instructions));
1472 CHECK_INT (XCDR (instructions));
1476 CHECK_STRING (instructions);
1478 f->instructions = instructions;
1480 if (!NILP (constants))
1481 CHECK_VECTOR (constants);
1482 f->constants = constants;
1484 CHECK_NATNUM (stack_depth);
1485 f->stack_depth = (unsigned short) XINT (stack_depth);
1487 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
1488 if (!NILP (Vcurrent_compiled_function_annotation))
1489 f->annotated = Fcopy (Vcurrent_compiled_function_annotation);
1490 else if (!NILP (Vload_file_name_internal_the_purecopy))
1491 f->annotated = Vload_file_name_internal_the_purecopy;
1492 else if (!NILP (Vload_file_name_internal))
1494 struct gcpro gcpro1;
1495 GCPRO1 (fun); /* don't let fun get reaped */
1496 Vload_file_name_internal_the_purecopy =
1497 Ffile_name_nondirectory (Vload_file_name_internal);
1498 f->annotated = Vload_file_name_internal_the_purecopy;
1501 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */
1503 /* doc_string may be nil, string, int, or a cons (string . int).
1504 interactive may be list or string (or unbound). */
1505 f->doc_and_interactive = Qunbound;
1507 if ((f->flags.domainp = !NILP (Vfile_domain)) != 0)
1508 f->doc_and_interactive = Vfile_domain;
1510 if ((f->flags.interactivep = !UNBOUNDP (interactive)) != 0)
1512 f->doc_and_interactive
1513 = (UNBOUNDP (f->doc_and_interactive) ? interactive :
1514 Fcons (interactive, f->doc_and_interactive));
1516 if ((f->flags.documentationp = !NILP (doc_string)) != 0)
1518 f->doc_and_interactive
1519 = (UNBOUNDP (f->doc_and_interactive) ? doc_string :
1520 Fcons (doc_string, f->doc_and_interactive));
1522 if (UNBOUNDP (f->doc_and_interactive))
1523 f->doc_and_interactive = Qnil;
1529 /************************************************************************/
1530 /* Symbol allocation */
1531 /************************************************************************/
1533 DECLARE_FIXED_TYPE_ALLOC (symbol, Lisp_Symbol);
1534 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_symbol 1000
1536 DEFUN ("make-symbol", Fmake_symbol, 1, 1, 0, /*
1537 Return a newly allocated uninterned symbol whose name is NAME.
1538 Its value and function definition are void, and its property list is nil.
1545 CHECK_STRING (name);
1547 ALLOCATE_FIXED_TYPE (symbol, Lisp_Symbol, p);
1548 set_lheader_implementation (&p->lheader, &lrecord_symbol);
1549 p->name = XSTRING (name);
1551 p->value = Qunbound;
1552 p->function = Qunbound;
1553 symbol_next (p) = 0;
1554 XSETSYMBOL (val, p);
1559 /************************************************************************/
1560 /* Extent allocation */
1561 /************************************************************************/
1563 DECLARE_FIXED_TYPE_ALLOC (extent, struct extent);
1564 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_extent 1000
1567 allocate_extent (void)
1571 ALLOCATE_FIXED_TYPE (extent, struct extent, e);
1572 set_lheader_implementation (&e->lheader, &lrecord_extent);
1573 extent_object (e) = Qnil;
1574 set_extent_start (e, -1);
1575 set_extent_end (e, -1);
1580 extent_face (e) = Qnil;
1581 e->flags.end_open = 1; /* default is for endpoints to behave like markers */
1582 e->flags.detachable = 1;
1588 /************************************************************************/
1589 /* Event allocation */
1590 /************************************************************************/
1592 DECLARE_FIXED_TYPE_ALLOC (event, Lisp_Event);
1593 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_event 1000
1596 allocate_event (void)
1601 ALLOCATE_FIXED_TYPE (event, Lisp_Event, e);
1602 set_lheader_implementation (&e->lheader, &lrecord_event);
1609 /************************************************************************/
1610 /* Marker allocation */
1611 /************************************************************************/
1613 DECLARE_FIXED_TYPE_ALLOC (marker, Lisp_Marker);
1614 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_marker 1000
1616 DEFUN ("make-marker", Fmake_marker, 0, 0, 0, /*
1617 Return a new marker which does not point at any place.
1624 ALLOCATE_FIXED_TYPE (marker, Lisp_Marker, p);
1625 set_lheader_implementation (&p->lheader, &lrecord_marker);
1628 marker_next (p) = 0;
1629 marker_prev (p) = 0;
1630 p->insertion_type = 0;
1631 XSETMARKER (val, p);
1636 noseeum_make_marker (void)
1641 NOSEEUM_ALLOCATE_FIXED_TYPE (marker, Lisp_Marker, p);
1642 set_lheader_implementation (&p->lheader, &lrecord_marker);
1645 marker_next (p) = 0;
1646 marker_prev (p) = 0;
1647 p->insertion_type = 0;
1648 XSETMARKER (val, p);
1653 /************************************************************************/
1654 /* String allocation */
1655 /************************************************************************/
1657 /* The data for "short" strings generally resides inside of structs of type
1658 string_chars_block. The Lisp_String structure is allocated just like any
1659 other Lisp object (except for vectors), and these are freelisted when
1660 they get garbage collected. The data for short strings get compacted,
1661 but the data for large strings do not.
1663 Previously Lisp_String structures were relocated, but this caused a lot
1664 of bus-errors because the C code didn't include enough GCPRO's for
1665 strings (since EVERY REFERENCE to a short string needed to be GCPRO'd so
1666 that the reference would get relocated).
1668 This new method makes things somewhat bigger, but it is MUCH safer. */
1670 DECLARE_FIXED_TYPE_ALLOC (string, Lisp_String);
1671 /* strings are used and freed quite often */
1672 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 10000 */
1673 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 1000
1676 mark_string (Lisp_Object obj)
1678 Lisp_String *ptr = XSTRING (obj);
1680 if (CONSP (ptr->plist) && EXTENT_INFOP (XCAR (ptr->plist)))
1681 flush_cached_extent_info (XCAR (ptr->plist));
1686 string_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
1689 return (((len = XSTRING_LENGTH (obj1)) == XSTRING_LENGTH (obj2)) &&
1690 !memcmp (XSTRING_DATA (obj1), XSTRING_DATA (obj2), len));
1693 static const struct lrecord_description string_description[] = {
1694 { XD_BYTECOUNT, offsetof (Lisp_String, size) },
1695 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String, data), XD_INDIRECT(0, 1) },
1696 { XD_LISP_OBJECT, offsetof (Lisp_String, plist) },
1700 /* We store the string's extent info as the first element of the string's
1701 property list; and the string's MODIFF as the first or second element
1702 of the string's property list (depending on whether the extent info
1703 is present), but only if the string has been modified. This is ugly
1704 but it reduces the memory allocated for the string in the vast
1705 majority of cases, where the string is never modified and has no
1708 #### This means you can't use an int as a key in a string's plist. */
1710 static Lisp_Object *
1711 string_plist_ptr (Lisp_Object string)
1713 Lisp_Object *ptr = &XSTRING (string)->plist;
1715 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr)))
1717 if (CONSP (*ptr) && INTP (XCAR (*ptr)))
1723 string_getprop (Lisp_Object string, Lisp_Object property)
1725 return external_plist_get (string_plist_ptr (string), property, 0, ERROR_ME);
1729 string_putprop (Lisp_Object string, Lisp_Object property, Lisp_Object value)
1731 external_plist_put (string_plist_ptr (string), property, value, 0, ERROR_ME);
1736 string_remprop (Lisp_Object string, Lisp_Object property)
1738 return external_remprop (string_plist_ptr (string), property, 0, ERROR_ME);
1742 string_plist (Lisp_Object string)
1744 return *string_plist_ptr (string);
1747 /* No `finalize', or `hash' methods.
1748 internal_hash() already knows how to hash strings and finalization
1749 is done with the ADDITIONAL_FREE_string macro, which is the
1750 standard way to do finalization when using
1751 SWEEP_FIXED_TYPE_BLOCK(). */
1752 DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS ("string", string,
1753 mark_string, print_string,
1762 /* String blocks contain this many useful bytes. */
1763 #define STRING_CHARS_BLOCK_SIZE \
1764 ((Bytecount) (8192 - MALLOC_OVERHEAD - \
1765 ((2 * sizeof (struct string_chars_block *)) \
1766 + sizeof (EMACS_INT))))
1767 /* Block header for small strings. */
1768 struct string_chars_block
1771 struct string_chars_block *next;
1772 struct string_chars_block *prev;
1773 /* Contents of string_chars_block->string_chars are interleaved
1774 string_chars structures (see below) and the actual string data */
1775 unsigned char string_chars[STRING_CHARS_BLOCK_SIZE];
1778 static struct string_chars_block *first_string_chars_block;
1779 static struct string_chars_block *current_string_chars_block;
1781 /* If SIZE is the length of a string, this returns how many bytes
1782 * the string occupies in string_chars_block->string_chars
1783 * (including alignment padding).
1785 #define STRING_FULLSIZE(size) \
1786 ALIGN_SIZE (((size) + 1 + sizeof (Lisp_String *)),\
1787 ALIGNOF (Lisp_String *))
1789 #define BIG_STRING_FULLSIZE_P(fullsize) ((fullsize) >= STRING_CHARS_BLOCK_SIZE)
1790 #define BIG_STRING_SIZE_P(size) (BIG_STRING_FULLSIZE_P (STRING_FULLSIZE(size)))
1794 Lisp_String *string;
1795 unsigned char chars[1];
1798 struct unused_string_chars
1800 Lisp_String *string;
1805 init_string_chars_alloc (void)
1807 first_string_chars_block = xnew (struct string_chars_block);
1808 first_string_chars_block->prev = 0;
1809 first_string_chars_block->next = 0;
1810 first_string_chars_block->pos = 0;
1811 current_string_chars_block = first_string_chars_block;
1814 static struct string_chars *
1815 allocate_string_chars_struct (Lisp_String *string_it_goes_with,
1818 struct string_chars *s_chars;
1821 (countof (current_string_chars_block->string_chars)
1822 - current_string_chars_block->pos))
1824 /* This string can fit in the current string chars block */
1825 s_chars = (struct string_chars *)
1826 (current_string_chars_block->string_chars
1827 + current_string_chars_block->pos);
1828 current_string_chars_block->pos += fullsize;
1832 /* Make a new current string chars block */
1833 struct string_chars_block *new_scb = xnew (struct string_chars_block);
1835 current_string_chars_block->next = new_scb;
1836 new_scb->prev = current_string_chars_block;
1838 current_string_chars_block = new_scb;
1839 new_scb->pos = fullsize;
1840 s_chars = (struct string_chars *)
1841 current_string_chars_block->string_chars;
1844 s_chars->string = string_it_goes_with;
1846 INCREMENT_CONS_COUNTER (fullsize, "string chars");
1852 make_uninit_string (Bytecount length)
1855 EMACS_INT fullsize = STRING_FULLSIZE (length);
1858 assert (length >= 0 && fullsize > 0);
1860 /* Allocate the string header */
1861 ALLOCATE_FIXED_TYPE (string, Lisp_String, s);
1862 set_lheader_implementation (&s->lheader, &lrecord_string);
1864 set_string_data (s, BIG_STRING_FULLSIZE_P (fullsize)
1865 ? xnew_array (Bufbyte, length + 1)
1866 : allocate_string_chars_struct (s, fullsize)->chars);
1868 set_string_length (s, length);
1871 set_string_byte (s, length, 0);
1873 XSETSTRING (val, s);
1877 #ifdef VERIFY_STRING_CHARS_INTEGRITY
1878 static void verify_string_chars_integrity (void);
1881 /* Resize the string S so that DELTA bytes can be inserted starting
1882 at POS. If DELTA < 0, it means deletion starting at POS. If
1883 POS < 0, resize the string but don't copy any characters. Use
1884 this if you're planning on completely overwriting the string.
1888 resize_string (Lisp_String *s, Bytecount pos, Bytecount delta)
1890 Bytecount oldfullsize, newfullsize;
1891 #ifdef VERIFY_STRING_CHARS_INTEGRITY
1892 verify_string_chars_integrity ();
1895 #ifdef ERROR_CHECK_BUFPOS
1898 assert (pos <= string_length (s));
1900 assert (pos + (-delta) <= string_length (s));
1905 assert ((-delta) <= string_length (s));
1907 #endif /* ERROR_CHECK_BUFPOS */
1910 /* simplest case: no size change. */
1913 if (pos >= 0 && delta < 0)
1914 /* If DELTA < 0, the functions below will delete the characters
1915 before POS. We want to delete characters *after* POS, however,
1916 so convert this to the appropriate form. */
1919 oldfullsize = STRING_FULLSIZE (string_length (s));
1920 newfullsize = STRING_FULLSIZE (string_length (s) + delta);
1922 if (BIG_STRING_FULLSIZE_P (oldfullsize))
1924 if (BIG_STRING_FULLSIZE_P (newfullsize))
1926 /* Both strings are big. We can just realloc().
1927 But careful! If the string is shrinking, we have to
1928 memmove() _before_ realloc(), and if growing, we have to
1929 memmove() _after_ realloc() - otherwise the access is
1930 illegal, and we might crash. */
1931 Bytecount len = string_length (s) + 1 - pos;
1933 if (delta < 0 && pos >= 0)
1934 memmove (string_data (s) + pos + delta, string_data (s) + pos, len);
1935 set_string_data (s, (Bufbyte *) xrealloc (string_data (s),
1936 string_length (s) + delta + 1));
1937 if (delta > 0 && pos >= 0)
1938 memmove (string_data (s) + pos + delta, string_data (s) + pos, len);
1940 else /* String has been demoted from BIG_STRING. */
1943 allocate_string_chars_struct (s, newfullsize)->chars;
1944 Bufbyte *old_data = string_data (s);
1948 memcpy (new_data, old_data, pos);
1949 memcpy (new_data + pos + delta, old_data + pos,
1950 string_length (s) + 1 - pos);
1952 set_string_data (s, new_data);
1956 else /* old string is small */
1958 if (oldfullsize == newfullsize)
1960 /* special case; size change but the necessary
1961 allocation size won't change (up or down; code
1962 somewhere depends on there not being any unused
1963 allocation space, modulo any alignment
1967 Bufbyte *addroff = pos + string_data (s);
1969 memmove (addroff + delta, addroff,
1970 /* +1 due to zero-termination. */
1971 string_length (s) + 1 - pos);
1976 Bufbyte *old_data = string_data (s);
1978 BIG_STRING_FULLSIZE_P (newfullsize)
1979 ? xnew_array (Bufbyte, string_length (s) + delta + 1)
1980 : allocate_string_chars_struct (s, newfullsize)->chars;
1984 memcpy (new_data, old_data, pos);
1985 memcpy (new_data + pos + delta, old_data + pos,
1986 string_length (s) + 1 - pos);
1988 set_string_data (s, new_data);
1991 /* We need to mark this chunk of the string_chars_block
1992 as unused so that compact_string_chars() doesn't
1994 struct string_chars *old_s_chars = (struct string_chars *)
1995 ((char *) old_data - offsetof (struct string_chars, chars));
1996 /* Sanity check to make sure we aren't hosed by strange
1997 alignment/padding. */
1998 assert (old_s_chars->string == s);
1999 MARK_STRUCT_AS_FREE (old_s_chars);
2000 ((struct unused_string_chars *) old_s_chars)->fullsize =
2006 set_string_length (s, string_length (s) + delta);
2007 /* If pos < 0, the string won't be zero-terminated.
2008 Terminate now just to make sure. */
2009 string_data (s)[string_length (s)] = '\0';
2015 XSETSTRING (string, s);
2016 /* We also have to adjust all of the extent indices after the
2017 place we did the change. We say "pos - 1" because
2018 adjust_extents() is exclusive of the starting position
2020 adjust_extents (string, pos - 1, string_length (s),
2024 #ifdef VERIFY_STRING_CHARS_INTEGRITY
2025 verify_string_chars_integrity ();
2032 set_string_char (Lisp_String *s, Charcount i, Emchar c)
2034 Bufbyte newstr[MAX_EMCHAR_LEN];
2035 Bytecount bytoff = charcount_to_bytecount (string_data (s), i);
2036 Bytecount oldlen = charcount_to_bytecount (string_data (s) + bytoff, 1);
2037 Bytecount newlen = set_charptr_emchar (newstr, c);
2039 if (oldlen != newlen)
2040 resize_string (s, bytoff, newlen - oldlen);
2041 /* Remember, string_data (s) might have changed so we can't cache it. */
2042 memcpy (string_data (s) + bytoff, newstr, newlen);
2047 DEFUN ("make-string", Fmake_string, 2, 2, 0, /*
2048 Return a new string of length LENGTH, with each character being INIT.
2049 LENGTH must be an integer and INIT must be a character.
2053 CHECK_NATNUM (length);
2054 CHECK_CHAR_COERCE_INT (init);
2056 Bufbyte init_str[MAX_EMCHAR_LEN];
2057 int len = set_charptr_emchar (init_str, XCHAR (init));
2058 Lisp_Object val = make_uninit_string (len * XINT (length));
2061 /* Optimize the single-byte case */
2062 memset (XSTRING_DATA (val), XCHAR (init), XSTRING_LENGTH (val));
2066 Bufbyte *ptr = XSTRING_DATA (val);
2068 for (i = XINT (length); i; i--)
2070 Bufbyte *init_ptr = init_str;
2073 case 4: *ptr++ = *init_ptr++;
2074 case 3: *ptr++ = *init_ptr++;
2075 case 2: *ptr++ = *init_ptr++;
2076 case 1: *ptr++ = *init_ptr++;
2084 DEFUN ("string", Fstring, 0, MANY, 0, /*
2085 Concatenate all the argument characters and make the result a string.
2087 (int nargs, Lisp_Object *args))
2089 Bufbyte *storage = alloca_array (Bufbyte, nargs * MAX_EMCHAR_LEN);
2090 Bufbyte *p = storage;
2092 for (; nargs; nargs--, args++)
2094 Lisp_Object lisp_char = *args;
2095 CHECK_CHAR_COERCE_INT (lisp_char);
2096 p += set_charptr_emchar (p, XCHAR (lisp_char));
2098 return make_string (storage, p - storage);
2102 /* Take some raw memory, which MUST already be in internal format,
2103 and package it up into a Lisp string. */
2105 make_string (const Bufbyte *contents, Bytecount length)
2109 /* Make sure we find out about bad make_string's when they happen */
2110 #if defined (ERROR_CHECK_BUFPOS) && defined (MULE)
2111 bytecount_to_charcount (contents, length); /* Just for the assertions */
2114 val = make_uninit_string (length);
2115 memcpy (XSTRING_DATA (val), contents, length);
2119 /* Take some raw memory, encoded in some external data format,
2120 and convert it into a Lisp string. */
2122 make_ext_string (const Extbyte *contents, EMACS_INT length,
2123 Lisp_Object coding_system)
2126 TO_INTERNAL_FORMAT (DATA, (contents, length),
2127 LISP_STRING, string,
2133 build_string (const char *str)
2135 /* Some strlen's crash and burn if passed null. */
2136 return make_string ((const Bufbyte *) str, (str ? strlen(str) : 0));
2140 build_ext_string (const char *str, Lisp_Object coding_system)
2142 /* Some strlen's crash and burn if passed null. */
2143 return make_ext_string ((const Extbyte *) str, (str ? strlen(str) : 0),
2148 build_translated_string (const char *str)
2150 return build_string (GETTEXT (str));
2154 make_string_nocopy (const Bufbyte *contents, Bytecount length)
2159 /* Make sure we find out about bad make_string_nocopy's when they happen */
2160 #if defined (ERROR_CHECK_BUFPOS) && defined (MULE)
2161 bytecount_to_charcount (contents, length); /* Just for the assertions */
2164 /* Allocate the string header */
2165 ALLOCATE_FIXED_TYPE (string, Lisp_String, s);
2166 set_lheader_implementation (&s->lheader, &lrecord_string);
2167 SET_C_READONLY_RECORD_HEADER (&s->lheader);
2169 set_string_data (s, (Bufbyte *)contents);
2170 set_string_length (s, length);
2172 XSETSTRING (val, s);
2177 /************************************************************************/
2178 /* lcrecord lists */
2179 /************************************************************************/
2181 /* Lcrecord lists are used to manage the allocation of particular
2182 sorts of lcrecords, to avoid calling alloc_lcrecord() (and thus
2183 malloc() and garbage-collection junk) as much as possible.
2184 It is similar to the Blocktype class.
2188 1) Create an lcrecord-list object using make_lcrecord_list().
2189 This is often done at initialization. Remember to staticpro_nodump
2190 this object! The arguments to make_lcrecord_list() are the
2191 same as would be passed to alloc_lcrecord().
2192 2) Instead of calling alloc_lcrecord(), call allocate_managed_lcrecord()
2193 and pass the lcrecord-list earlier created.
2194 3) When done with the lcrecord, call free_managed_lcrecord().
2195 The standard freeing caveats apply: ** make sure there are no
2196 pointers to the object anywhere! **
2197 4) Calling free_managed_lcrecord() is just like kissing the
2198 lcrecord goodbye as if it were garbage-collected. This means:
2199 -- the contents of the freed lcrecord are undefined, and the
2200 contents of something produced by allocate_managed_lcrecord()
2201 are undefined, just like for alloc_lcrecord().
2202 -- the mark method for the lcrecord's type will *NEVER* be called
2204 -- the finalize method for the lcrecord's type will be called
2205 at the time that free_managed_lcrecord() is called.
2210 mark_lcrecord_list (Lisp_Object obj)
2212 struct lcrecord_list *list = XLCRECORD_LIST (obj);
2213 Lisp_Object chain = list->free;
2215 while (!NILP (chain))
2217 struct lrecord_header *lheader = XRECORD_LHEADER (chain);
2218 struct free_lcrecord_header *free_header =
2219 (struct free_lcrecord_header *) lheader;
2222 (/* There should be no other pointers to the free list. */
2223 ! MARKED_RECORD_HEADER_P (lheader)
2225 /* Only lcrecords should be here. */
2226 ! LHEADER_IMPLEMENTATION (lheader)->basic_p
2228 /* Only free lcrecords should be here. */
2229 free_header->lcheader.free
2231 /* The type of the lcrecord must be right. */
2232 LHEADER_IMPLEMENTATION (lheader) == list->implementation
2234 /* So must the size. */
2235 (LHEADER_IMPLEMENTATION (lheader)->static_size == 0 ||
2236 LHEADER_IMPLEMENTATION (lheader)->static_size == list->size)
2239 MARK_RECORD_HEADER (lheader);
2240 chain = free_header->chain;
2246 DEFINE_LRECORD_IMPLEMENTATION ("lcrecord-list", lcrecord_list,
2247 mark_lcrecord_list, internal_object_printer,
2248 0, 0, 0, 0, struct lcrecord_list);
2250 make_lcrecord_list (size_t size,
2251 const struct lrecord_implementation *implementation)
2253 struct lcrecord_list *p = alloc_lcrecord_type (struct lcrecord_list,
2254 &lrecord_lcrecord_list);
2257 p->implementation = implementation;
2260 XSETLCRECORD_LIST (val, p);
2265 allocate_managed_lcrecord (Lisp_Object lcrecord_list)
2267 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list);
2268 if (!NILP (list->free))
2270 Lisp_Object val = list->free;
2271 struct free_lcrecord_header *free_header =
2272 (struct free_lcrecord_header *) XPNTR (val);
2274 #ifdef ERROR_CHECK_GC
2275 struct lrecord_header *lheader = &free_header->lcheader.lheader;
2277 /* There should be no other pointers to the free list. */
2278 assert (! MARKED_RECORD_HEADER_P (lheader));
2279 /* Only lcrecords should be here. */
2280 assert (! LHEADER_IMPLEMENTATION (lheader)->basic_p);
2281 /* Only free lcrecords should be here. */
2282 assert (free_header->lcheader.free);
2283 /* The type of the lcrecord must be right. */
2284 assert (LHEADER_IMPLEMENTATION (lheader) == list->implementation);
2285 /* So must the size. */
2286 assert (LHEADER_IMPLEMENTATION (lheader)->static_size == 0 ||
2287 LHEADER_IMPLEMENTATION (lheader)->static_size == list->size);
2288 #endif /* ERROR_CHECK_GC */
2290 list->free = free_header->chain;
2291 free_header->lcheader.free = 0;
2298 XSETOBJ (val, Lisp_Type_Record,
2299 alloc_lcrecord (list->size, list->implementation));
2305 free_managed_lcrecord (Lisp_Object lcrecord_list, Lisp_Object lcrecord)
2307 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list);
2308 struct free_lcrecord_header *free_header =
2309 (struct free_lcrecord_header *) XPNTR (lcrecord);
2310 struct lrecord_header *lheader = &free_header->lcheader.lheader;
2311 const struct lrecord_implementation *implementation
2312 = LHEADER_IMPLEMENTATION (lheader);
2314 /* Make sure the size is correct. This will catch, for example,
2315 putting a window configuration on the wrong free list. */
2316 gc_checking_assert ((implementation->size_in_bytes_method ?
2317 implementation->size_in_bytes_method (lheader) :
2318 implementation->static_size)
2321 if (implementation->finalizer)
2322 implementation->finalizer (lheader, 0);
2323 free_header->chain = list->free;
2324 free_header->lcheader.free = 1;
2325 list->free = lcrecord;
2331 DEFUN ("purecopy", Fpurecopy, 1, 1, 0, /*
2332 Kept for compatibility, returns its argument.
2334 Make a copy of OBJECT in pure storage.
2335 Recursively copies contents of vectors and cons cells.
2336 Does not copy symbols.
2344 /************************************************************************/
2345 /* Garbage Collection */
2346 /************************************************************************/
2348 /* All the built-in lisp object types are enumerated in `enum lrecord_type'.
2349 Additional ones may be defined by a module (none yet). We leave some
2350 room in `lrecord_implementations_table' for such new lisp object types. */
2351 #define MODULE_DEFINABLE_TYPE_COUNT 32
2352 const struct lrecord_implementation *lrecord_implementations_table[lrecord_type_count + MODULE_DEFINABLE_TYPE_COUNT];
2354 /* Object marker functions are in the lrecord_implementation structure.
2355 But copying them to a parallel array is much more cache-friendly.
2356 This hack speeds up (garbage-collect) by about 5%. */
2357 Lisp_Object (*lrecord_markers[countof (lrecord_implementations_table)]) (Lisp_Object);
2359 struct gcpro *gcprolist;
2361 /* 415 used Mly 29-Jun-93 */
2362 /* 1327 used slb 28-Feb-98 */
2363 /* 1328 used og 03-Oct-99 (moving slowly, heh?) */
2365 #define NSTATICS 4000
2367 #define NSTATICS 2000
2370 /* Not "static" because used by dumper.c */
2371 Lisp_Object *staticvec[NSTATICS];
2374 /* Put an entry in staticvec, pointing at the variable whose address is given
2377 staticpro (Lisp_Object *varaddress)
2379 /* #### This is now a dubious assert() since this routine may be called */
2380 /* by Lisp attempting to load a DLL. */
2381 assert (staticidx < countof (staticvec));
2382 staticvec[staticidx++] = varaddress;
2386 Lisp_Object *staticvec_nodump[200];
2387 int staticidx_nodump;
2389 /* Put an entry in staticvec_nodump, pointing at the variable whose address is given
2392 staticpro_nodump (Lisp_Object *varaddress)
2394 /* #### This is now a dubious assert() since this routine may be called */
2395 /* by Lisp attempting to load a DLL. */
2396 assert (staticidx_nodump < countof (staticvec_nodump));
2397 staticvec_nodump[staticidx_nodump++] = varaddress;
2401 struct pdump_dumpstructinfo dumpstructvec[200];
2404 /* Put an entry in dumpstructvec, pointing at the variable whose address is given
2407 dumpstruct (void *varaddress, const struct struct_description *desc)
2409 assert (dumpstructidx < countof (dumpstructvec));
2410 dumpstructvec[dumpstructidx].data = varaddress;
2411 dumpstructvec[dumpstructidx].desc = desc;
2415 struct pdump_dumpopaqueinfo dumpopaquevec[250];
2418 /* Put an entry in dumpopaquevec, pointing at the variable whose address is given
2421 dumpopaque (void *varaddress, size_t size)
2423 assert (dumpopaqueidx < countof (dumpopaquevec));
2425 dumpopaquevec[dumpopaqueidx].data = varaddress;
2426 dumpopaquevec[dumpopaqueidx].size = size;
2430 Lisp_Object *pdump_wirevec[50];
2433 /* Put an entry in pdump_wirevec, pointing at the variable whose address is given
2436 pdump_wire (Lisp_Object *varaddress)
2438 assert (pdump_wireidx < countof (pdump_wirevec));
2439 pdump_wirevec[pdump_wireidx++] = varaddress;
2443 Lisp_Object *pdump_wirevec_list[50];
2444 int pdump_wireidx_list;
2446 /* Put an entry in pdump_wirevec_list, pointing at the variable whose address is given
2449 pdump_wire_list (Lisp_Object *varaddress)
2451 assert (pdump_wireidx_list < countof (pdump_wirevec_list));
2452 pdump_wirevec_list[pdump_wireidx_list++] = varaddress;
2455 #ifdef ERROR_CHECK_GC
2456 #define GC_CHECK_LHEADER_INVARIANTS(lheader) do { \
2457 struct lrecord_header * GCLI_lh = (lheader); \
2458 assert (GCLI_lh != 0); \
2459 assert (GCLI_lh->type < lrecord_type_count); \
2460 assert (! C_READONLY_RECORD_HEADER_P (GCLI_lh) || \
2461 (MARKED_RECORD_HEADER_P (GCLI_lh) && \
2462 LISP_READONLY_RECORD_HEADER_P (GCLI_lh))); \
2465 #define GC_CHECK_LHEADER_INVARIANTS(lheader)
2469 /* Mark reference to a Lisp_Object. If the object referred to has not been
2470 seen yet, recursively mark all the references contained in it. */
2473 mark_object (Lisp_Object obj)
2477 /* Checks we used to perform */
2478 /* if (EQ (obj, Qnull_pointer)) return; */
2479 /* if (!POINTER_TYPE_P (XGCTYPE (obj))) return; */
2480 /* if (PURIFIED (XPNTR (obj))) return; */
2482 if (XTYPE (obj) == Lisp_Type_Record)
2484 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
2486 GC_CHECK_LHEADER_INVARIANTS (lheader);
2488 gc_checking_assert (LHEADER_IMPLEMENTATION (lheader)->basic_p ||
2489 ! ((struct lcrecord_header *) lheader)->free);
2491 /* All c_readonly objects have their mark bit set,
2492 so that we only need to check the mark bit here. */
2493 if (! MARKED_RECORD_HEADER_P (lheader))
2495 MARK_RECORD_HEADER (lheader);
2497 if (RECORD_MARKER (lheader))
2499 obj = RECORD_MARKER (lheader) (obj);
2500 if (!NILP (obj)) goto tail_recurse;
2506 /* mark all of the conses in a list and mark the final cdr; but
2507 DO NOT mark the cars.
2509 Use only for internal lists! There should never be other pointers
2510 to the cons cells, because if so, the cars will remain unmarked
2511 even when they maybe should be marked. */
2513 mark_conses_in_list (Lisp_Object obj)
2517 for (rest = obj; CONSP (rest); rest = XCDR (rest))
2519 if (CONS_MARKED_P (XCONS (rest)))
2521 MARK_CONS (XCONS (rest));
2528 /* Find all structures not marked, and free them. */
2530 static int gc_count_num_bit_vector_used, gc_count_bit_vector_total_size;
2531 static int gc_count_bit_vector_storage;
2532 static int gc_count_num_short_string_in_use;
2533 static int gc_count_string_total_size;
2534 static int gc_count_short_string_total_size;
2536 /* static int gc_count_total_records_used, gc_count_records_total_size; */
2539 /* stats on lcrecords in use - kinda kludgy */
2543 int instances_in_use;
2545 int instances_freed;
2547 int instances_on_free_list;
2548 } lcrecord_stats [countof (lrecord_implementations_table)];
2551 tick_lcrecord_stats (const struct lrecord_header *h, int free_p)
2553 unsigned int type_index = h->type;
2555 if (((struct lcrecord_header *) h)->free)
2557 gc_checking_assert (!free_p);
2558 lcrecord_stats[type_index].instances_on_free_list++;
2562 const struct lrecord_implementation *implementation =
2563 LHEADER_IMPLEMENTATION (h);
2565 size_t sz = (implementation->size_in_bytes_method ?
2566 implementation->size_in_bytes_method (h) :
2567 implementation->static_size);
2570 lcrecord_stats[type_index].instances_freed++;
2571 lcrecord_stats[type_index].bytes_freed += sz;
2575 lcrecord_stats[type_index].instances_in_use++;
2576 lcrecord_stats[type_index].bytes_in_use += sz;
2582 /* Free all unmarked records */
2584 sweep_lcrecords_1 (struct lcrecord_header **prev, int *used)
2586 struct lcrecord_header *header;
2588 /* int total_size = 0; */
2590 xzero (lcrecord_stats); /* Reset all statistics to 0. */
2592 /* First go through and call all the finalize methods.
2593 Then go through and free the objects. There used to
2594 be only one loop here, with the call to the finalizer
2595 occurring directly before the xfree() below. That
2596 is marginally faster but much less safe -- if the
2597 finalize method for an object needs to reference any
2598 other objects contained within it (and many do),
2599 we could easily be screwed by having already freed that
2602 for (header = *prev; header; header = header->next)
2604 struct lrecord_header *h = &(header->lheader);
2606 GC_CHECK_LHEADER_INVARIANTS (h);
2608 if (! MARKED_RECORD_HEADER_P (h) && ! header->free)
2610 if (LHEADER_IMPLEMENTATION (h)->finalizer)
2611 LHEADER_IMPLEMENTATION (h)->finalizer (h, 0);
2615 for (header = *prev; header; )
2617 struct lrecord_header *h = &(header->lheader);
2618 if (MARKED_RECORD_HEADER_P (h))
2620 if (! C_READONLY_RECORD_HEADER_P (h))
2621 UNMARK_RECORD_HEADER (h);
2623 /* total_size += n->implementation->size_in_bytes (h);*/
2624 /* #### May modify header->next on a C_READONLY lcrecord */
2625 prev = &(header->next);
2627 tick_lcrecord_stats (h, 0);
2631 struct lcrecord_header *next = header->next;
2633 tick_lcrecord_stats (h, 1);
2634 /* used to call finalizer right here. */
2640 /* *total = total_size; */
2645 sweep_bit_vectors_1 (Lisp_Object *prev,
2646 int *used, int *total, int *storage)
2648 Lisp_Object bit_vector;
2651 int total_storage = 0;
2653 /* BIT_VECTORP fails because the objects are marked, which changes
2654 their implementation */
2655 for (bit_vector = *prev; !EQ (bit_vector, Qzero); )
2657 Lisp_Bit_Vector *v = XBIT_VECTOR (bit_vector);
2659 if (MARKED_RECORD_P (bit_vector))
2661 if (! C_READONLY_RECORD_HEADER_P(&(v->lheader)))
2662 UNMARK_RECORD_HEADER (&(v->lheader));
2666 offsetof (Lisp_Bit_Vector, bits[BIT_VECTOR_LONG_STORAGE (len)]);
2668 /* #### May modify next on a C_READONLY bitvector */
2669 prev = &(bit_vector_next (v));
2674 Lisp_Object next = bit_vector_next (v);
2681 *total = total_size;
2682 *storage = total_storage;
2685 /* And the Lord said: Thou shalt use the `c-backslash-region' command
2686 to make macros prettier. */
2688 #ifdef ERROR_CHECK_GC
2690 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \
2692 struct typename##_block *SFTB_current; \
2693 struct typename##_block **SFTB_prev; \
2695 int num_free = 0, num_used = 0; \
2697 for (SFTB_prev = ¤t_##typename##_block, \
2698 SFTB_current = current_##typename##_block, \
2699 SFTB_limit = current_##typename##_block_index; \
2705 for (SFTB_iii = 0; SFTB_iii < SFTB_limit; SFTB_iii++) \
2707 obj_type *SFTB_victim = &(SFTB_current->block[SFTB_iii]); \
2709 if (FREE_STRUCT_P (SFTB_victim)) \
2713 else if (C_READONLY_RECORD_HEADER_P (&SFTB_victim->lheader)) \
2717 else if (! MARKED_RECORD_HEADER_P (&SFTB_victim->lheader)) \
2720 FREE_FIXED_TYPE (typename, obj_type, SFTB_victim); \
2725 UNMARK_##typename (SFTB_victim); \
2728 SFTB_prev = &(SFTB_current->prev); \
2729 SFTB_current = SFTB_current->prev; \
2730 SFTB_limit = countof (current_##typename##_block->block); \
2733 gc_count_num_##typename##_in_use = num_used; \
2734 gc_count_num_##typename##_freelist = num_free; \
2737 #else /* !ERROR_CHECK_GC */
2739 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \
2741 struct typename##_block *SFTB_current; \
2742 struct typename##_block **SFTB_prev; \
2744 int num_free = 0, num_used = 0; \
2746 typename##_free_list = 0; \
2748 for (SFTB_prev = ¤t_##typename##_block, \
2749 SFTB_current = current_##typename##_block, \
2750 SFTB_limit = current_##typename##_block_index; \
2755 int SFTB_empty = 1; \
2756 obj_type *SFTB_old_free_list = typename##_free_list; \
2758 for (SFTB_iii = 0; SFTB_iii < SFTB_limit; SFTB_iii++) \
2760 obj_type *SFTB_victim = &(SFTB_current->block[SFTB_iii]); \
2762 if (FREE_STRUCT_P (SFTB_victim)) \
2765 PUT_FIXED_TYPE_ON_FREE_LIST (typename, obj_type, SFTB_victim); \
2767 else if (C_READONLY_RECORD_HEADER_P (&SFTB_victim->lheader)) \
2772 else if (! MARKED_RECORD_HEADER_P (&SFTB_victim->lheader)) \
2775 FREE_FIXED_TYPE (typename, obj_type, SFTB_victim); \
2781 UNMARK_##typename (SFTB_victim); \
2786 SFTB_prev = &(SFTB_current->prev); \
2787 SFTB_current = SFTB_current->prev; \
2789 else if (SFTB_current == current_##typename##_block \
2790 && !SFTB_current->prev) \
2792 /* No real point in freeing sole allocation block */ \
2797 struct typename##_block *SFTB_victim_block = SFTB_current; \
2798 if (SFTB_victim_block == current_##typename##_block) \
2799 current_##typename##_block_index \
2800 = countof (current_##typename##_block->block); \
2801 SFTB_current = SFTB_current->prev; \
2803 *SFTB_prev = SFTB_current; \
2804 xfree (SFTB_victim_block); \
2805 /* Restore free list to what it was before victim was swept */ \
2806 typename##_free_list = SFTB_old_free_list; \
2807 num_free -= SFTB_limit; \
2810 SFTB_limit = countof (current_##typename##_block->block); \
2813 gc_count_num_##typename##_in_use = num_used; \
2814 gc_count_num_##typename##_freelist = num_free; \
2817 #endif /* !ERROR_CHECK_GC */
2825 #define UNMARK_cons(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
2826 #define ADDITIONAL_FREE_cons(ptr)
2828 SWEEP_FIXED_TYPE_BLOCK (cons, Lisp_Cons);
2831 /* Explicitly free a cons cell. */
2833 free_cons (Lisp_Cons *ptr)
2835 #ifdef ERROR_CHECK_GC
2836 /* If the CAR is not an int, then it will be a pointer, which will
2837 always be four-byte aligned. If this cons cell has already been
2838 placed on the free list, however, its car will probably contain
2839 a chain pointer to the next cons on the list, which has cleverly
2840 had all its 0's and 1's inverted. This allows for a quick
2841 check to make sure we're not freeing something already freed. */
2842 if (POINTER_TYPE_P (XTYPE (ptr->car)))
2843 ASSERT_VALID_POINTER (XPNTR (ptr->car));
2844 #endif /* ERROR_CHECK_GC */
2846 #ifndef ALLOC_NO_POOLS
2847 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (cons, Lisp_Cons, ptr);
2848 #endif /* ALLOC_NO_POOLS */
2851 /* explicitly free a list. You **must make sure** that you have
2852 created all the cons cells that make up this list and that there
2853 are no pointers to any of these cons cells anywhere else. If there
2854 are, you will lose. */
2857 free_list (Lisp_Object list)
2859 Lisp_Object rest, next;
2861 for (rest = list; !NILP (rest); rest = next)
2864 free_cons (XCONS (rest));
2868 /* explicitly free an alist. You **must make sure** that you have
2869 created all the cons cells that make up this alist and that there
2870 are no pointers to any of these cons cells anywhere else. If there
2871 are, you will lose. */
2874 free_alist (Lisp_Object alist)
2876 Lisp_Object rest, next;
2878 for (rest = alist; !NILP (rest); rest = next)
2881 free_cons (XCONS (XCAR (rest)));
2882 free_cons (XCONS (rest));
2887 sweep_compiled_functions (void)
2889 #define UNMARK_compiled_function(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
2890 #define ADDITIONAL_FREE_compiled_function(ptr)
2892 SWEEP_FIXED_TYPE_BLOCK (compiled_function, Lisp_Compiled_Function);
2896 #ifdef LISP_FLOAT_TYPE
2900 #define UNMARK_float(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
2901 #define ADDITIONAL_FREE_float(ptr)
2903 SWEEP_FIXED_TYPE_BLOCK (float, Lisp_Float);
2905 #endif /* LISP_FLOAT_TYPE */
2908 sweep_symbols (void)
2910 #define UNMARK_symbol(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
2911 #define ADDITIONAL_FREE_symbol(ptr)
2913 SWEEP_FIXED_TYPE_BLOCK (symbol, Lisp_Symbol);
2917 sweep_extents (void)
2919 #define UNMARK_extent(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
2920 #define ADDITIONAL_FREE_extent(ptr)
2922 SWEEP_FIXED_TYPE_BLOCK (extent, struct extent);
2928 #define UNMARK_event(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
2929 #define ADDITIONAL_FREE_event(ptr)
2931 SWEEP_FIXED_TYPE_BLOCK (event, Lisp_Event);
2935 sweep_markers (void)
2937 #define UNMARK_marker(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
2938 #define ADDITIONAL_FREE_marker(ptr) \
2939 do { Lisp_Object tem; \
2940 XSETMARKER (tem, ptr); \
2941 unchain_marker (tem); \
2944 SWEEP_FIXED_TYPE_BLOCK (marker, Lisp_Marker);
2947 /* Explicitly free a marker. */
2949 free_marker (Lisp_Marker *ptr)
2951 /* Perhaps this will catch freeing an already-freed marker. */
2952 gc_checking_assert (ptr->lheader.type = lrecord_type_marker);
2954 #ifndef ALLOC_NO_POOLS
2955 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (marker, Lisp_Marker, ptr);
2956 #endif /* ALLOC_NO_POOLS */
2960 #if defined (MULE) && defined (VERIFY_STRING_CHARS_INTEGRITY)
2963 verify_string_chars_integrity (void)
2965 struct string_chars_block *sb;
2967 /* Scan each existing string block sequentially, string by string. */
2968 for (sb = first_string_chars_block; sb; sb = sb->next)
2971 /* POS is the index of the next string in the block. */
2972 while (pos < sb->pos)
2974 struct string_chars *s_chars =
2975 (struct string_chars *) &(sb->string_chars[pos]);
2976 Lisp_String *string;
2980 /* If the string_chars struct is marked as free (i.e. the STRING
2981 pointer is 0xFFFFFFFF) then this is an unused chunk of string
2982 storage. (See below.) */
2984 if (FREE_STRUCT_P (s_chars))
2986 fullsize = ((struct unused_string_chars *) s_chars)->fullsize;
2991 string = s_chars->string;
2992 /* Must be 32-bit aligned. */
2993 assert ((((int) string) & 3) == 0);
2995 size = string_length (string);
2996 fullsize = STRING_FULLSIZE (size);
2998 assert (!BIG_STRING_FULLSIZE_P (fullsize));
2999 assert (string_data (string) == s_chars->chars);
3002 assert (pos == sb->pos);
3006 #endif /* MULE && ERROR_CHECK_GC */
3008 /* Compactify string chars, relocating the reference to each --
3009 free any empty string_chars_block we see. */
3011 compact_string_chars (void)
3013 struct string_chars_block *to_sb = first_string_chars_block;
3015 struct string_chars_block *from_sb;
3017 /* Scan each existing string block sequentially, string by string. */
3018 for (from_sb = first_string_chars_block; from_sb; from_sb = from_sb->next)
3021 /* FROM_POS is the index of the next string in the block. */
3022 while (from_pos < from_sb->pos)
3024 struct string_chars *from_s_chars =
3025 (struct string_chars *) &(from_sb->string_chars[from_pos]);
3026 struct string_chars *to_s_chars;
3027 Lisp_String *string;
3031 /* If the string_chars struct is marked as free (i.e. the STRING
3032 pointer is 0xFFFFFFFF) then this is an unused chunk of string
3033 storage. This happens under Mule when a string's size changes
3034 in such a way that its fullsize changes. (Strings can change
3035 size because a different-length character can be substituted
3036 for another character.) In this case, after the bogus string
3037 pointer is the "fullsize" of this entry, i.e. how many bytes
3040 if (FREE_STRUCT_P (from_s_chars))
3042 fullsize = ((struct unused_string_chars *) from_s_chars)->fullsize;
3043 from_pos += fullsize;
3047 string = from_s_chars->string;
3048 assert (!(FREE_STRUCT_P (string)));
3050 size = string_length (string);
3051 fullsize = STRING_FULLSIZE (size);
3053 gc_checking_assert (! BIG_STRING_FULLSIZE_P (fullsize));
3055 /* Just skip it if it isn't marked. */
3056 if (! MARKED_RECORD_HEADER_P (&(string->lheader)))
3058 from_pos += fullsize;
3062 /* If it won't fit in what's left of TO_SB, close TO_SB out
3063 and go on to the next string_chars_block. We know that TO_SB
3064 cannot advance past FROM_SB here since FROM_SB is large enough
3065 to currently contain this string. */
3066 if ((to_pos + fullsize) > countof (to_sb->string_chars))
3068 to_sb->pos = to_pos;
3069 to_sb = to_sb->next;
3073 /* Compute new address of this string
3074 and update TO_POS for the space being used. */
3075 to_s_chars = (struct string_chars *) &(to_sb->string_chars[to_pos]);
3077 /* Copy the string_chars to the new place. */
3078 if (from_s_chars != to_s_chars)
3079 memmove (to_s_chars, from_s_chars, fullsize);
3081 /* Relocate FROM_S_CHARS's reference */
3082 set_string_data (string, &(to_s_chars->chars[0]));
3084 from_pos += fullsize;
3089 /* Set current to the last string chars block still used and
3090 free any that follow. */
3092 struct string_chars_block *victim;
3094 for (victim = to_sb->next; victim; )
3096 struct string_chars_block *next = victim->next;
3101 current_string_chars_block = to_sb;
3102 current_string_chars_block->pos = to_pos;
3103 current_string_chars_block->next = 0;
3107 #if 1 /* Hack to debug missing purecopy's */
3108 static int debug_string_purity;
3111 debug_string_purity_print (Lisp_String *p)
3114 Charcount s = string_char_length (p);
3116 for (i = 0; i < s; i++)
3118 Emchar ch = string_char (p, i);
3119 if (ch < 32 || ch >= 126)
3120 stderr_out ("\\%03o", ch);
3121 else if (ch == '\\' || ch == '\"')
3122 stderr_out ("\\%c", ch);
3124 stderr_out ("%c", ch);
3126 stderr_out ("\"\n");
3132 sweep_strings (void)
3134 int num_small_used = 0, num_small_bytes = 0, num_bytes = 0;
3135 int debug = debug_string_purity;
3137 #define UNMARK_string(ptr) do { \
3138 Lisp_String *p = (ptr); \
3139 size_t size = string_length (p); \
3140 UNMARK_RECORD_HEADER (&(p->lheader)); \
3141 num_bytes += size; \
3142 if (!BIG_STRING_SIZE_P (size)) \
3143 { num_small_bytes += size; \
3147 debug_string_purity_print (p); \
3149 #define ADDITIONAL_FREE_string(ptr) do { \
3150 size_t size = string_length (ptr); \
3151 if (BIG_STRING_SIZE_P (size)) \
3152 xfree (ptr->data); \
3155 SWEEP_FIXED_TYPE_BLOCK (string, Lisp_String);
3157 gc_count_num_short_string_in_use = num_small_used;
3158 gc_count_string_total_size = num_bytes;
3159 gc_count_short_string_total_size = num_small_bytes;
3163 /* I hate duplicating all this crap! */
3165 marked_p (Lisp_Object obj)
3167 /* Checks we used to perform. */
3168 /* if (EQ (obj, Qnull_pointer)) return 1; */
3169 /* if (!POINTER_TYPE_P (XGCTYPE (obj))) return 1; */
3170 /* if (PURIFIED (XPNTR (obj))) return 1; */
3172 if (XTYPE (obj) == Lisp_Type_Record)
3174 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
3176 GC_CHECK_LHEADER_INVARIANTS (lheader);
3178 return MARKED_RECORD_HEADER_P (lheader);
3186 /* Free all unmarked records. Do this at the very beginning,
3187 before anything else, so that the finalize methods can safely
3188 examine items in the objects. sweep_lcrecords_1() makes
3189 sure to call all the finalize methods *before* freeing anything,
3190 to complete the safety. */
3193 sweep_lcrecords_1 (&all_lcrecords, &ignored);
3196 compact_string_chars ();
3198 /* Finalize methods below (called through the ADDITIONAL_FREE_foo
3199 macros) must be *extremely* careful to make sure they're not
3200 referencing freed objects. The only two existing finalize
3201 methods (for strings and markers) pass muster -- the string
3202 finalizer doesn't look at anything but its own specially-
3203 created block, and the marker finalizer only looks at live
3204 buffers (which will never be freed) and at the markers before
3205 and after it in the chain (which, by induction, will never be
3206 freed because if so, they would have already removed themselves
3209 /* Put all unmarked strings on free list, free'ing the string chars
3210 of large unmarked strings */
3213 /* Put all unmarked conses on free list */
3216 /* Free all unmarked bit vectors */
3217 sweep_bit_vectors_1 (&all_bit_vectors,
3218 &gc_count_num_bit_vector_used,
3219 &gc_count_bit_vector_total_size,
3220 &gc_count_bit_vector_storage);
3222 /* Free all unmarked compiled-function objects */
3223 sweep_compiled_functions ();
3225 #ifdef LISP_FLOAT_TYPE
3226 /* Put all unmarked floats on free list */
3230 /* Put all unmarked symbols on free list */
3233 /* Put all unmarked extents on free list */
3236 /* Put all unmarked markers on free list.
3237 Dechain each one first from the buffer into which it points. */
3243 pdump_objects_unmark ();
3247 /* Clearing for disksave. */
3250 disksave_object_finalization (void)
3252 /* It's important that certain information from the environment not get
3253 dumped with the executable (pathnames, environment variables, etc.).
3254 To make it easier to tell when this has happened with strings(1) we
3255 clear some known-to-be-garbage blocks of memory, so that leftover
3256 results of old evaluation don't look like potential problems.
3257 But first we set some notable variables to nil and do one more GC,
3258 to turn those strings into garbage.
3261 /* Yeah, this list is pretty ad-hoc... */
3262 Vprocess_environment = Qnil;
3263 Vexec_directory = Qnil;
3264 Vdata_directory = Qnil;
3265 Vsite_directory = Qnil;
3266 Vdoc_directory = Qnil;
3267 Vconfigure_info_directory = Qnil;
3270 /* Vdump_load_path = Qnil; */
3271 /* Release hash tables for locate_file */
3272 Flocate_file_clear_hashing (Qt);
3273 uncache_home_directory();
3275 #if defined(LOADHIST) && !(defined(LOADHIST_DUMPED) || \
3276 defined(LOADHIST_BUILTIN))
3277 Vload_history = Qnil;
3279 Vshell_file_name = Qnil;
3281 garbage_collect_1 ();
3283 /* Run the disksave finalization methods of all live objects. */
3284 disksave_object_finalization_1 ();
3286 /* Zero out the uninitialized (really, unused) part of the containers
3287 for the live strings. */
3289 struct string_chars_block *scb;
3290 for (scb = first_string_chars_block; scb; scb = scb->next)
3292 int count = sizeof (scb->string_chars) - scb->pos;
3294 assert (count >= 0 && count < STRING_CHARS_BLOCK_SIZE);
3297 /* from the block's fill ptr to the end */
3298 memset ((scb->string_chars + scb->pos), 0, count);
3303 /* There, that ought to be enough... */
3309 restore_gc_inhibit (Lisp_Object val)
3311 gc_currently_forbidden = XINT (val);
3315 /* Maybe we want to use this when doing a "panic" gc after memory_full()? */
3316 static int gc_hooks_inhibited;
3320 garbage_collect_1 (void)
3322 #if MAX_SAVE_STACK > 0
3323 char stack_top_variable;
3324 extern char *stack_bottom;
3329 Lisp_Object pre_gc_cursor;
3330 struct gcpro gcpro1;
3333 || gc_currently_forbidden
3335 || preparing_for_armageddon)
3338 /* We used to call selected_frame() here.
3340 The following functions cannot be called inside GC
3341 so we move to after the above tests. */
3344 Lisp_Object device = Fselected_device (Qnil);
3345 if (NILP (device)) /* Could happen during startup, eg. if always_gc */
3347 frame = DEVICE_SELECTED_FRAME (XDEVICE (device));
3349 signal_simple_error ("No frames exist on device", device);
3353 pre_gc_cursor = Qnil;
3356 GCPRO1 (pre_gc_cursor);
3358 /* Very important to prevent GC during any of the following
3359 stuff that might run Lisp code; otherwise, we'll likely
3360 have infinite GC recursion. */
3361 speccount = specpdl_depth ();
3362 record_unwind_protect (restore_gc_inhibit,
3363 make_int (gc_currently_forbidden));
3364 gc_currently_forbidden = 1;
3366 if (!gc_hooks_inhibited)
3367 run_hook_trapping_errors ("Error in pre-gc-hook", Qpre_gc_hook);
3369 /* Now show the GC cursor/message. */
3370 if (!noninteractive)
3372 if (FRAME_WIN_P (f))
3374 Lisp_Object frame = make_frame (f);
3375 Lisp_Object cursor = glyph_image_instance (Vgc_pointer_glyph,
3376 FRAME_SELECTED_WINDOW (f),
3378 pre_gc_cursor = f->pointer;
3379 if (POINTER_IMAGE_INSTANCEP (cursor)
3380 /* don't change if we don't know how to change back. */
3381 && POINTER_IMAGE_INSTANCEP (pre_gc_cursor))
3384 Fset_frame_pointer (frame, cursor);
3388 /* Don't print messages to the stream device. */
3389 if (!cursor_changed && !FRAME_STREAM_P (f))
3391 char *msg = (STRINGP (Vgc_message)
3392 ? GETTEXT ((char *) XSTRING_DATA (Vgc_message))
3394 Lisp_Object args[2], whole_msg;
3395 args[0] = build_string (msg ? msg :
3396 GETTEXT ((const char *) gc_default_message));
3397 args[1] = build_string ("...");
3398 whole_msg = Fconcat (2, args);
3399 echo_area_message (f, (Bufbyte *) 0, whole_msg, 0, -1,
3400 Qgarbage_collecting);
3404 /***** Now we actually start the garbage collection. */
3408 gc_generation_number[0]++;
3410 #if MAX_SAVE_STACK > 0
3412 /* Save a copy of the contents of the stack, for debugging. */
3415 /* Static buffer in which we save a copy of the C stack at each GC. */
3416 static char *stack_copy;
3417 static size_t stack_copy_size;
3419 ptrdiff_t stack_diff = &stack_top_variable - stack_bottom;
3420 size_t stack_size = (stack_diff > 0 ? stack_diff : -stack_diff);
3421 if (stack_size < MAX_SAVE_STACK)
3423 if (stack_copy_size < stack_size)
3425 stack_copy = (char *) xrealloc (stack_copy, stack_size);
3426 stack_copy_size = stack_size;
3430 stack_diff > 0 ? stack_bottom : &stack_top_variable,
3434 #endif /* MAX_SAVE_STACK > 0 */
3436 /* Do some totally ad-hoc resource clearing. */
3437 /* #### generalize this? */
3438 clear_event_resource ();
3439 cleanup_specifiers ();
3441 /* Mark all the special slots that serve as the roots of accessibility. */
3445 for (i = 0; i < staticidx; i++)
3446 mark_object (*(staticvec[i]));
3447 for (i = 0; i < staticidx_nodump; i++)
3448 mark_object (*(staticvec_nodump[i]));
3454 for (tail = gcprolist; tail; tail = tail->next)
3455 for (i = 0; i < tail->nvars; i++)
3456 mark_object (tail->var[i]);
3460 struct specbinding *bind;
3461 for (bind = specpdl; bind != specpdl_ptr; bind++)
3463 mark_object (bind->symbol);
3464 mark_object (bind->old_value);
3469 struct catchtag *catch;
3470 for (catch = catchlist; catch; catch = catch->next)
3472 mark_object (catch->tag);
3473 mark_object (catch->val);
3478 struct backtrace *backlist;
3479 for (backlist = backtrace_list; backlist; backlist = backlist->next)
3481 int nargs = backlist->nargs;
3484 mark_object (*backlist->function);
3485 if (nargs == UNEVALLED || nargs == MANY)
3486 mark_object (backlist->args[0]);
3488 for (i = 0; i < nargs; i++)
3489 mark_object (backlist->args[i]);
3494 mark_profiling_info ();
3496 /* OK, now do the after-mark stuff. This is for things that
3497 are only marked when something else is marked (e.g. weak hash tables).
3498 There may be complex dependencies between such objects -- e.g.
3499 a weak hash table might be unmarked, but after processing a later
3500 weak hash table, the former one might get marked. So we have to
3501 iterate until nothing more gets marked. */
3503 while (finish_marking_weak_hash_tables () > 0 ||
3504 finish_marking_weak_lists () > 0)
3507 /* And prune (this needs to be called after everything else has been
3508 marked and before we do any sweeping). */
3509 /* #### this is somewhat ad-hoc and should probably be an object
3511 prune_weak_hash_tables ();
3512 prune_weak_lists ();
3513 prune_specifiers ();
3514 prune_syntax_tables ();
3518 consing_since_gc = 0;
3519 #ifndef DEBUG_XEMACS
3520 /* Allow you to set it really fucking low if you really want ... */
3521 if (gc_cons_threshold < 10000)
3522 gc_cons_threshold = 10000;
3527 /******* End of garbage collection ********/
3529 run_hook_trapping_errors ("Error in post-gc-hook", Qpost_gc_hook);
3531 /* Now remove the GC cursor/message */
3532 if (!noninteractive)
3535 Fset_frame_pointer (make_frame (f), pre_gc_cursor);
3536 else if (!FRAME_STREAM_P (f))
3538 char *msg = (STRINGP (Vgc_message)
3539 ? GETTEXT ((char *) XSTRING_DATA (Vgc_message))
3542 /* Show "...done" only if the echo area would otherwise be empty. */
3543 if (NILP (clear_echo_area (selected_frame (),
3544 Qgarbage_collecting, 0)))
3546 Lisp_Object args[2], whole_msg;
3547 args[0] = build_string (msg ? msg :
3548 GETTEXT ((const char *)
3549 gc_default_message));
3550 args[1] = build_string ("... done");
3551 whole_msg = Fconcat (2, args);
3552 echo_area_message (selected_frame (), (Bufbyte *) 0,
3554 Qgarbage_collecting);
3559 /* now stop inhibiting GC */
3560 unbind_to (speccount, Qnil);
3562 if (!breathing_space)
3564 breathing_space = malloc (4096 - MALLOC_OVERHEAD);
3571 /* Debugging aids. */
3574 gc_plist_hack (const char *name, int value, Lisp_Object tail)
3576 /* C doesn't have local functions (or closures, or GC, or readable syntax,
3577 or portable numeric datatypes, or bit-vectors, or characters, or
3578 arrays, or exceptions, or ...) */
3579 return cons3 (intern (name), make_int (value), tail);
3582 #define HACK_O_MATIC(type, name, pl) do { \
3584 struct type##_block *x = current_##type##_block; \
3585 while (x) { s += sizeof (*x) + MALLOC_OVERHEAD; x = x->prev; } \
3586 (pl) = gc_plist_hack ((name), s, (pl)); \
3589 DEFUN ("garbage-collect", Fgarbage_collect, 0, 0, "", /*
3590 Reclaim storage for Lisp objects no longer needed.
3591 Return info on amount of space in use:
3592 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS)
3593 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS
3595 where `PLIST' is a list of alternating keyword/value pairs providing
3596 more detailed information.
3597 Garbage collection happens automatically if you cons more than
3598 `gc-cons-threshold' bytes of Lisp data since previous garbage collection.
3602 Lisp_Object pl = Qnil;
3604 int gc_count_vector_total_size = 0;
3606 garbage_collect_1 ();
3608 for (i = 0; i < lrecord_type_count; i++)
3610 if (lcrecord_stats[i].bytes_in_use != 0
3611 || lcrecord_stats[i].bytes_freed != 0
3612 || lcrecord_stats[i].instances_on_free_list != 0)
3615 const char *name = lrecord_implementations_table[i]->name;
3616 int len = strlen (name);
3617 /* save this for the FSFmacs-compatible part of the summary */
3618 if (i == lrecord_vector.lrecord_type_index)
3619 gc_count_vector_total_size =
3620 lcrecord_stats[i].bytes_in_use + lcrecord_stats[i].bytes_freed;
3622 sprintf (buf, "%s-storage", name);
3623 pl = gc_plist_hack (buf, lcrecord_stats[i].bytes_in_use, pl);
3624 /* Okay, simple pluralization check for `symbol-value-varalias' */
3625 if (name[len-1] == 's')
3626 sprintf (buf, "%ses-freed", name);
3628 sprintf (buf, "%ss-freed", name);
3629 if (lcrecord_stats[i].instances_freed != 0)
3630 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_freed, pl);
3631 if (name[len-1] == 's')
3632 sprintf (buf, "%ses-on-free-list", name);
3634 sprintf (buf, "%ss-on-free-list", name);
3635 if (lcrecord_stats[i].instances_on_free_list != 0)
3636 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_on_free_list,
3638 if (name[len-1] == 's')
3639 sprintf (buf, "%ses-used", name);
3641 sprintf (buf, "%ss-used", name);
3642 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_in_use, pl);
3646 HACK_O_MATIC (extent, "extent-storage", pl);
3647 pl = gc_plist_hack ("extents-free", gc_count_num_extent_freelist, pl);
3648 pl = gc_plist_hack ("extents-used", gc_count_num_extent_in_use, pl);
3649 HACK_O_MATIC (event, "event-storage", pl);
3650 pl = gc_plist_hack ("events-free", gc_count_num_event_freelist, pl);
3651 pl = gc_plist_hack ("events-used", gc_count_num_event_in_use, pl);
3652 HACK_O_MATIC (marker, "marker-storage", pl);
3653 pl = gc_plist_hack ("markers-free", gc_count_num_marker_freelist, pl);
3654 pl = gc_plist_hack ("markers-used", gc_count_num_marker_in_use, pl);
3655 #ifdef LISP_FLOAT_TYPE
3656 HACK_O_MATIC (float, "float-storage", pl);
3657 pl = gc_plist_hack ("floats-free", gc_count_num_float_freelist, pl);
3658 pl = gc_plist_hack ("floats-used", gc_count_num_float_in_use, pl);
3659 #endif /* LISP_FLOAT_TYPE */
3660 HACK_O_MATIC (string, "string-header-storage", pl);
3661 pl = gc_plist_hack ("long-strings-total-length",
3662 gc_count_string_total_size
3663 - gc_count_short_string_total_size, pl);
3664 HACK_O_MATIC (string_chars, "short-string-storage", pl);
3665 pl = gc_plist_hack ("short-strings-total-length",
3666 gc_count_short_string_total_size, pl);
3667 pl = gc_plist_hack ("strings-free", gc_count_num_string_freelist, pl);
3668 pl = gc_plist_hack ("long-strings-used",
3669 gc_count_num_string_in_use
3670 - gc_count_num_short_string_in_use, pl);
3671 pl = gc_plist_hack ("short-strings-used",
3672 gc_count_num_short_string_in_use, pl);
3674 HACK_O_MATIC (compiled_function, "compiled-function-storage", pl);
3675 pl = gc_plist_hack ("compiled-functions-free",
3676 gc_count_num_compiled_function_freelist, pl);
3677 pl = gc_plist_hack ("compiled-functions-used",
3678 gc_count_num_compiled_function_in_use, pl);
3680 pl = gc_plist_hack ("bit-vector-storage", gc_count_bit_vector_storage, pl);
3681 pl = gc_plist_hack ("bit-vectors-total-length",
3682 gc_count_bit_vector_total_size, pl);
3683 pl = gc_plist_hack ("bit-vectors-used", gc_count_num_bit_vector_used, pl);
3685 HACK_O_MATIC (symbol, "symbol-storage", pl);
3686 pl = gc_plist_hack ("symbols-free", gc_count_num_symbol_freelist, pl);
3687 pl = gc_plist_hack ("symbols-used", gc_count_num_symbol_in_use, pl);
3689 HACK_O_MATIC (cons, "cons-storage", pl);
3690 pl = gc_plist_hack ("conses-free", gc_count_num_cons_freelist, pl);
3691 pl = gc_plist_hack ("conses-used", gc_count_num_cons_in_use, pl);
3693 /* The things we do for backwards-compatibility */
3695 list6 (Fcons (make_int (gc_count_num_cons_in_use),
3696 make_int (gc_count_num_cons_freelist)),
3697 Fcons (make_int (gc_count_num_symbol_in_use),
3698 make_int (gc_count_num_symbol_freelist)),
3699 Fcons (make_int (gc_count_num_marker_in_use),
3700 make_int (gc_count_num_marker_freelist)),
3701 make_int (gc_count_string_total_size),
3702 make_int (gc_count_vector_total_size),
3707 DEFUN ("consing-since-gc", Fconsing_since_gc, 0, 0, "", /*
3708 Return the number of bytes consed since the last garbage collection.
3709 \"Consed\" is a misnomer in that this actually counts allocation
3710 of all different kinds of objects, not just conses.
3712 If this value exceeds `gc-cons-threshold', a garbage collection happens.
3716 return make_int (consing_since_gc);
3720 DEFUN ("memory-limit", Fmemory_limit, 0, 0, "", /*
3721 Return the address of the last byte Emacs has allocated, divided by 1024.
3722 This may be helpful in debugging Emacs's memory usage.
3723 The value is divided by 1024 to make sure it will fit in a lisp integer.
3727 return make_int ((EMACS_INT) sbrk (0) / 1024);
3733 object_dead_p (Lisp_Object obj)
3735 return ((BUFFERP (obj) && !BUFFER_LIVE_P (XBUFFER (obj))) ||
3736 (FRAMEP (obj) && !FRAME_LIVE_P (XFRAME (obj))) ||
3737 (WINDOWP (obj) && !WINDOW_LIVE_P (XWINDOW (obj))) ||
3738 (DEVICEP (obj) && !DEVICE_LIVE_P (XDEVICE (obj))) ||
3739 (CONSOLEP (obj) && !CONSOLE_LIVE_P (XCONSOLE (obj))) ||
3740 (EVENTP (obj) && !EVENT_LIVE_P (XEVENT (obj))) ||
3741 (EXTENTP (obj) && !EXTENT_LIVE_P (XEXTENT (obj))));
3744 #ifdef MEMORY_USAGE_STATS
3746 /* Attempt to determine the actual amount of space that is used for
3747 the block allocated starting at PTR, supposedly of size "CLAIMED_SIZE".
3749 It seems that the following holds:
3751 1. When using the old allocator (malloc.c):
3753 -- blocks are always allocated in chunks of powers of two. For
3754 each block, there is an overhead of 8 bytes if rcheck is not
3755 defined, 20 bytes if it is defined. In other words, a
3756 one-byte allocation needs 8 bytes of overhead for a total of
3757 9 bytes, and needs to have 16 bytes of memory chunked out for
3760 2. When using the new allocator (gmalloc.c):
3762 -- blocks are always allocated in chunks of powers of two up
3763 to 4096 bytes. Larger blocks are allocated in chunks of
3764 an integral multiple of 4096 bytes. The minimum block
3765 size is 2*sizeof (void *), or 16 bytes if SUNOS_LOCALTIME_BUG
3766 is defined. There is no per-block overhead, but there
3767 is an overhead of 3*sizeof (size_t) for each 4096 bytes
3770 3. When using the system malloc, anything goes, but they are
3771 generally slower and more space-efficient than the GNU
3772 allocators. One possibly reasonable assumption to make
3773 for want of better data is that sizeof (void *), or maybe
3774 2 * sizeof (void *), is required as overhead and that
3775 blocks are allocated in the minimum required size except
3776 that some minimum block size is imposed (e.g. 16 bytes). */
3779 malloced_storage_size (void *ptr, size_t claimed_size,
3780 struct overhead_stats *stats)
3782 size_t orig_claimed_size = claimed_size;
3786 if (claimed_size < 2 * sizeof (void *))
3787 claimed_size = 2 * sizeof (void *);
3788 # ifdef SUNOS_LOCALTIME_BUG
3789 if (claimed_size < 16)
3792 if (claimed_size < 4096)
3796 /* compute the log base two, more or less, then use it to compute
3797 the block size needed. */
3799 /* It's big, it's heavy, it's wood! */
3800 while ((claimed_size /= 2) != 0)
3803 /* It's better than bad, it's good! */
3809 /* We have to come up with some average about the amount of
3811 if ((size_t) (rand () & 4095) < claimed_size)
3812 claimed_size += 3 * sizeof (void *);
3816 claimed_size += 4095;
3817 claimed_size &= ~4095;
3818 claimed_size += (claimed_size / 4096) * 3 * sizeof (size_t);
3821 #elif defined (SYSTEM_MALLOC)
3823 if (claimed_size < 16)
3825 claimed_size += 2 * sizeof (void *);
3827 #else /* old GNU allocator */
3829 # ifdef rcheck /* #### may not be defined here */
3837 /* compute the log base two, more or less, then use it to compute
3838 the block size needed. */
3840 /* It's big, it's heavy, it's wood! */
3841 while ((claimed_size /= 2) != 0)
3844 /* It's better than bad, it's good! */
3852 #endif /* old GNU allocator */
3856 stats->was_requested += orig_claimed_size;
3857 stats->malloc_overhead += claimed_size - orig_claimed_size;
3859 return claimed_size;
3863 fixed_type_block_overhead (size_t size)
3865 size_t per_block = TYPE_ALLOC_SIZE (cons, unsigned char);
3866 size_t overhead = 0;
3867 size_t storage_size = malloced_storage_size (0, per_block, 0);
3868 while (size >= per_block)
3871 overhead += sizeof (void *) + per_block - storage_size;
3873 if (rand () % per_block < size)
3874 overhead += sizeof (void *) + per_block - storage_size;
3878 #endif /* MEMORY_USAGE_STATS */
3881 /* Initialization */
3883 reinit_alloc_once_early (void)
3885 gc_generation_number[0] = 0;
3886 breathing_space = 0;
3887 XSETINT (all_bit_vectors, 0); /* Qzero may not be set yet. */
3888 XSETINT (Vgc_message, 0);
3890 ignore_malloc_warnings = 1;
3891 #ifdef DOUG_LEA_MALLOC
3892 mallopt (M_TRIM_THRESHOLD, 128*1024); /* trim threshold */
3893 mallopt (M_MMAP_THRESHOLD, 64*1024); /* mmap threshold */
3894 #if 0 /* Moved to emacs.c */
3895 mallopt (M_MMAP_MAX, 64); /* max. number of mmap'ed areas */
3898 init_string_alloc ();
3899 init_string_chars_alloc ();
3901 init_symbol_alloc ();
3902 init_compiled_function_alloc ();
3903 #ifdef LISP_FLOAT_TYPE
3904 init_float_alloc ();
3905 #endif /* LISP_FLOAT_TYPE */
3906 init_marker_alloc ();
3907 init_extent_alloc ();
3908 init_event_alloc ();
3910 ignore_malloc_warnings = 0;
3912 staticidx_nodump = 0;
3916 consing_since_gc = 0;
3918 gc_cons_threshold = 500000; /* XEmacs change */
3920 gc_cons_threshold = 15000; /* debugging */
3922 #ifdef VIRT_ADDR_VARIES
3923 malloc_sbrk_unused = 1<<22; /* A large number */
3924 malloc_sbrk_used = 100000; /* as reasonable as any number */
3925 #endif /* VIRT_ADDR_VARIES */
3926 lrecord_uid_counter = 259;
3927 debug_string_purity = 0;
3930 gc_currently_forbidden = 0;
3931 gc_hooks_inhibited = 0;
3933 #ifdef ERROR_CHECK_TYPECHECK
3934 ERROR_ME.really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
3937 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = 42;
3939 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
3941 #endif /* ERROR_CHECK_TYPECHECK */
3945 init_alloc_once_early (void)
3947 reinit_alloc_once_early ();
3951 for (i = 0; i < countof (lrecord_implementations_table); i++)
3952 lrecord_implementations_table[i] = 0;
3955 INIT_LRECORD_IMPLEMENTATION (cons);
3956 INIT_LRECORD_IMPLEMENTATION (vector);
3957 INIT_LRECORD_IMPLEMENTATION (string);
3958 INIT_LRECORD_IMPLEMENTATION (lcrecord_list);
3963 int pure_bytes_used = 0;
3972 syms_of_alloc (void)
3974 defsymbol (&Qpre_gc_hook, "pre-gc-hook");
3975 defsymbol (&Qpost_gc_hook, "post-gc-hook");
3976 defsymbol (&Qgarbage_collecting, "garbage-collecting");
3981 DEFSUBR (Fbit_vector);
3982 DEFSUBR (Fmake_byte_code);
3983 DEFSUBR (Fmake_list);
3984 DEFSUBR (Fmake_vector);
3985 DEFSUBR (Fmake_bit_vector);
3986 DEFSUBR (Fmake_string);
3988 DEFSUBR (Fmake_symbol);
3989 DEFSUBR (Fmake_marker);
3990 DEFSUBR (Fpurecopy);
3991 DEFSUBR (Fgarbage_collect);
3993 DEFSUBR (Fmemory_limit);
3995 DEFSUBR (Fconsing_since_gc);
3999 vars_of_alloc (void)
4001 DEFVAR_INT ("gc-cons-threshold", &gc_cons_threshold /*
4002 *Number of bytes of consing between garbage collections.
4003 \"Consing\" is a misnomer in that this actually counts allocation
4004 of all different kinds of objects, not just conses.
4005 Garbage collection can happen automatically once this many bytes have been
4006 allocated since the last garbage collection. All data types count.
4008 Garbage collection happens automatically when `eval' or `funcall' are
4009 called. (Note that `funcall' is called implicitly as part of evaluation.)
4010 By binding this temporarily to a large number, you can effectively
4011 prevent garbage collection during a part of the program.
4013 See also `consing-since-gc'.
4016 DEFVAR_INT ("pure-bytes-used", &pure_bytes_used /*
4017 Number of bytes of sharable Lisp data allocated so far.
4021 DEFVAR_INT ("data-bytes-used", &malloc_sbrk_used /*
4022 Number of bytes of unshared memory allocated in this session.
4025 DEFVAR_INT ("data-bytes-free", &malloc_sbrk_unused /*
4026 Number of bytes of unshared memory remaining available in this session.
4031 DEFVAR_INT ("debug-allocation", &debug_allocation /*
4032 If non-zero, print out information to stderr about all objects allocated.
4033 See also `debug-allocation-backtrace-length'.
4035 debug_allocation = 0;
4037 DEFVAR_INT ("debug-allocation-backtrace-length",
4038 &debug_allocation_backtrace_length /*
4039 Length (in stack frames) of short backtrace printed out by `debug-allocation'.
4041 debug_allocation_backtrace_length = 2;
4044 DEFVAR_BOOL ("purify-flag", &purify_flag /*
4045 Non-nil means loading Lisp code in order to dump an executable.
4046 This means that certain objects should be allocated in readonly space.
4049 DEFVAR_LISP ("pre-gc-hook", &Vpre_gc_hook /*
4050 Function or functions to be run just before each garbage collection.
4051 Interrupts, garbage collection, and errors are inhibited while this hook
4052 runs, so be extremely careful in what you add here. In particular, avoid
4053 consing, and do not interact with the user.
4055 Vpre_gc_hook = Qnil;
4057 DEFVAR_LISP ("post-gc-hook", &Vpost_gc_hook /*
4058 Function or functions to be run just after each garbage collection.
4059 Interrupts, garbage collection, and errors are inhibited while this hook
4060 runs, so be extremely careful in what you add here. In particular, avoid
4061 consing, and do not interact with the user.
4063 Vpost_gc_hook = Qnil;
4065 DEFVAR_LISP ("gc-message", &Vgc_message /*
4066 String to print to indicate that a garbage collection is in progress.
4067 This is printed in the echo area. If the selected frame is on a
4068 window system and `gc-pointer-glyph' specifies a value (i.e. a pointer
4069 image instance) in the domain of the selected frame, the mouse pointer
4070 will change instead of this message being printed.
4072 Vgc_message = build_string (gc_default_message);
4074 DEFVAR_LISP ("gc-pointer-glyph", &Vgc_pointer_glyph /*
4075 Pointer glyph used to indicate that a garbage collection is in progress.
4076 If the selected window is on a window system and this glyph specifies a
4077 value (i.e. a pointer image instance) in the domain of the selected
4078 window, the pointer will be changed as specified during garbage collection.
4079 Otherwise, a message will be printed in the echo area, as controlled
4085 complex_vars_of_alloc (void)
4087 Vgc_pointer_glyph = Fmake_glyph_internal (Qpointer);