Mercurial > emacs
comparison src/alloc.c @ 88155:d7ddb3e565de
sync with trunk
| author | Henrik Enberg <henrik.enberg@telia.com> |
|---|---|
| date | Mon, 16 Jan 2006 00:03:54 +0000 |
| parents | 23a1cea22d13 |
| children |
comparison
equal
deleted
inserted
replaced
| 88154:8ce476d3ba36 | 88155:d7ddb3e565de |
|---|---|
| 1 /* Storage allocation and gc for GNU Emacs Lisp interpreter. | 1 /* Storage allocation and gc for GNU Emacs Lisp interpreter. |
| 2 Copyright (C) 1985, 86, 88, 93, 94, 95, 97, 98, 1999, 2000, 2001, 2002, 2003 | 2 Copyright (C) 1985, 1986, 1988, 1993, 1994, 1995, 1997, 1998, 1999, |
| 3 Free Software Foundation, Inc. | 3 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
| 4 | 4 |
| 5 This file is part of GNU Emacs. | 5 This file is part of GNU Emacs. |
| 6 | 6 |
| 7 GNU Emacs is free software; you can redistribute it and/or modify | 7 GNU Emacs is free software; you can redistribute it and/or modify |
| 8 it under the terms of the GNU General Public License as published by | 8 it under the terms of the GNU General Public License as published by |
| 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
| 16 | 16 |
| 17 You should have received a copy of the GNU General Public License | 17 You should have received a copy of the GNU General Public License |
| 18 along with GNU Emacs; see the file COPYING. If not, write to | 18 along with GNU Emacs; see the file COPYING. If not, write to |
| 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 Boston, MA 02111-1307, USA. */ | 20 Boston, MA 02110-1301, USA. */ |
| 21 | 21 |
| 22 #include <config.h> | 22 #include <config.h> |
| 23 #include <stdio.h> | 23 #include <stdio.h> |
| 24 #include <limits.h> /* For CHAR_BIT. */ | |
| 24 | 25 |
| 25 #ifdef ALLOC_DEBUG | 26 #ifdef ALLOC_DEBUG |
| 26 #undef INLINE | 27 #undef INLINE |
| 27 #endif | 28 #endif |
| 28 | 29 |
| 29 /* Note that this declares bzero on OSF/1. How dumb. */ | 30 /* Note that this declares bzero on OSF/1. How dumb. */ |
| 30 | 31 |
| 31 #include <signal.h> | 32 #include <signal.h> |
| 32 | 33 |
| 33 /* GC_MALLOC_CHECK defined means perform validity checks of malloc'd | 34 #ifdef HAVE_GTK_AND_PTHREAD |
| 34 memory. Can do this only if using gmalloc.c. */ | 35 #include <pthread.h> |
| 35 | |
| 36 #if defined SYSTEM_MALLOC || defined DOUG_LEA_MALLOC | |
| 37 #undef GC_MALLOC_CHECK | |
| 38 #endif | 36 #endif |
| 39 | 37 |
| 40 /* This file is part of the core Lisp implementation, and thus must | 38 /* This file is part of the core Lisp implementation, and thus must |
| 41 deal with the real data structures. If the Lisp implementation is | 39 deal with the real data structures. If the Lisp implementation is |
| 42 replaced, this file likely will not be used. */ | 40 replaced, this file likely will not be used. */ |
| 53 #include "blockinput.h" | 51 #include "blockinput.h" |
| 54 #include "charset.h" | 52 #include "charset.h" |
| 55 #include "syssignal.h" | 53 #include "syssignal.h" |
| 56 #include <setjmp.h> | 54 #include <setjmp.h> |
| 57 | 55 |
| 56 /* GC_MALLOC_CHECK defined means perform validity checks of malloc'd | |
| 57 memory. Can do this only if using gmalloc.c. */ | |
| 58 | |
| 59 #if defined SYSTEM_MALLOC || defined DOUG_LEA_MALLOC | |
| 60 #undef GC_MALLOC_CHECK | |
| 61 #endif | |
| 62 | |
| 58 #ifdef HAVE_UNISTD_H | 63 #ifdef HAVE_UNISTD_H |
| 59 #include <unistd.h> | 64 #include <unistd.h> |
| 60 #else | 65 #else |
| 61 extern POINTER_TYPE *sbrk (); | 66 extern POINTER_TYPE *sbrk (); |
| 62 #endif | 67 #endif |
| 63 | 68 |
| 69 #ifdef HAVE_FCNTL_H | |
| 70 #define INCLUDED_FCNTL | |
| 71 #include <fcntl.h> | |
| 72 #endif | |
| 73 #ifndef O_WRONLY | |
| 74 #define O_WRONLY 1 | |
| 75 #endif | |
| 76 | |
| 64 #ifdef DOUG_LEA_MALLOC | 77 #ifdef DOUG_LEA_MALLOC |
| 65 | 78 |
| 66 #include <malloc.h> | 79 #include <malloc.h> |
| 67 /* malloc.h #defines this as size_t, at least in glibc2. */ | 80 /* malloc.h #defines this as size_t, at least in glibc2. */ |
| 68 #ifndef __malloc_size_t | 81 #ifndef __malloc_size_t |
| 82 extern __malloc_size_t _bytes_used; | 95 extern __malloc_size_t _bytes_used; |
| 83 extern __malloc_size_t __malloc_extra_blocks; | 96 extern __malloc_size_t __malloc_extra_blocks; |
| 84 | 97 |
| 85 #endif /* not DOUG_LEA_MALLOC */ | 98 #endif /* not DOUG_LEA_MALLOC */ |
| 86 | 99 |
| 87 /* Macro to verify that storage intended for Lisp objects is not | 100 #if ! defined (SYSTEM_MALLOC) && defined (HAVE_GTK_AND_PTHREAD) |
| 88 out of range to fit in the space for a pointer. | 101 |
| 89 ADDRESS is the start of the block, and SIZE | 102 /* When GTK uses the file chooser dialog, different backends can be loaded |
| 90 is the amount of space within which objects can start. */ | 103 dynamically. One such a backend is the Gnome VFS backend that gets loaded |
| 91 | 104 if you run Gnome. That backend creates several threads and also allocates |
| 92 #define VALIDATE_LISP_STORAGE(address, size) \ | 105 memory with malloc. |
| 93 do \ | 106 |
| 94 { \ | 107 If Emacs sets malloc hooks (! SYSTEM_MALLOC) and the emacs_blocked_* |
| 95 Lisp_Object val; \ | 108 functions below are called from malloc, there is a chance that one |
| 96 XSETCONS (val, (char *) address + size); \ | 109 of these threads preempts the Emacs main thread and the hook variables |
| 97 if ((char *) XCONS (val) != (char *) address + size) \ | 110 end up in an inconsistent state. So we have a mutex to prevent that (note |
| 98 { \ | 111 that the backend handles concurrent access to malloc within its own threads |
| 99 xfree (address); \ | 112 but Emacs code running in the main thread is not included in that control). |
| 100 memory_full (); \ | 113 |
| 101 } \ | 114 When UNBLOCK_INPUT is called, reinvoke_input_signal may be called. If this |
| 102 } while (0) | 115 happens in one of the backend threads we will have two threads that tries |
| 116 to run Emacs code at once, and the code is not prepared for that. | |
| 117 To prevent that, we only call BLOCK/UNBLOCK from the main thread. */ | |
| 118 | |
| 119 static pthread_mutex_t alloc_mutex; | |
| 120 | |
| 121 #define BLOCK_INPUT_ALLOC \ | |
| 122 do \ | |
| 123 { \ | |
| 124 pthread_mutex_lock (&alloc_mutex); \ | |
| 125 if (pthread_self () == main_thread) \ | |
| 126 BLOCK_INPUT; \ | |
| 127 } \ | |
| 128 while (0) | |
| 129 #define UNBLOCK_INPUT_ALLOC \ | |
| 130 do \ | |
| 131 { \ | |
| 132 if (pthread_self () == main_thread) \ | |
| 133 UNBLOCK_INPUT; \ | |
| 134 pthread_mutex_unlock (&alloc_mutex); \ | |
| 135 } \ | |
| 136 while (0) | |
| 137 | |
| 138 #else /* SYSTEM_MALLOC || not HAVE_GTK_AND_PTHREAD */ | |
| 139 | |
| 140 #define BLOCK_INPUT_ALLOC BLOCK_INPUT | |
| 141 #define UNBLOCK_INPUT_ALLOC UNBLOCK_INPUT | |
| 142 | |
| 143 #endif /* SYSTEM_MALLOC || not HAVE_GTK_AND_PTHREAD */ | |
| 103 | 144 |
| 104 /* Value of _bytes_used, when spare_memory was freed. */ | 145 /* Value of _bytes_used, when spare_memory was freed. */ |
| 105 | 146 |
| 106 static __malloc_size_t bytes_used_when_full; | 147 static __malloc_size_t bytes_used_when_full; |
| 148 | |
| 149 static __malloc_size_t bytes_used_when_reconsidered; | |
| 107 | 150 |
| 108 /* Mark, unmark, query mark bit of a Lisp string. S must be a pointer | 151 /* Mark, unmark, query mark bit of a Lisp string. S must be a pointer |
| 109 to a struct Lisp_String. */ | 152 to a struct Lisp_String. */ |
| 110 | 153 |
| 111 #define MARK_STRING(S) ((S)->size |= MARKBIT) | 154 #define MARK_STRING(S) ((S)->size |= ARRAY_MARK_FLAG) |
| 112 #define UNMARK_STRING(S) ((S)->size &= ~MARKBIT) | 155 #define UNMARK_STRING(S) ((S)->size &= ~ARRAY_MARK_FLAG) |
| 113 #define STRING_MARKED_P(S) ((S)->size & MARKBIT) | 156 #define STRING_MARKED_P(S) (((S)->size & ARRAY_MARK_FLAG) != 0) |
| 157 | |
| 158 #define VECTOR_MARK(V) ((V)->size |= ARRAY_MARK_FLAG) | |
| 159 #define VECTOR_UNMARK(V) ((V)->size &= ~ARRAY_MARK_FLAG) | |
| 160 #define VECTOR_MARKED_P(V) (((V)->size & ARRAY_MARK_FLAG) != 0) | |
| 114 | 161 |
| 115 /* Value is the number of bytes/chars of S, a pointer to a struct | 162 /* Value is the number of bytes/chars of S, a pointer to a struct |
| 116 Lisp_String. This must be used instead of STRING_BYTES (S) or | 163 Lisp_String. This must be used instead of STRING_BYTES (S) or |
| 117 S->size during GC, because S->size contains the mark bit for | 164 S->size during GC, because S->size contains the mark bit for |
| 118 strings. */ | 165 strings. */ |
| 119 | 166 |
| 120 #define GC_STRING_BYTES(S) (STRING_BYTES (S) & ~MARKBIT) | 167 #define GC_STRING_BYTES(S) (STRING_BYTES (S)) |
| 121 #define GC_STRING_CHARS(S) ((S)->size & ~MARKBIT) | 168 #define GC_STRING_CHARS(S) ((S)->size & ~ARRAY_MARK_FLAG) |
| 122 | 169 |
| 123 /* Number of bytes of consing done since the last gc. */ | 170 /* Number of bytes of consing done since the last gc. */ |
| 124 | 171 |
| 125 int consing_since_gc; | 172 int consing_since_gc; |
| 126 | 173 |
| 133 EMACS_INT string_chars_consed; | 180 EMACS_INT string_chars_consed; |
| 134 EMACS_INT misc_objects_consed; | 181 EMACS_INT misc_objects_consed; |
| 135 EMACS_INT intervals_consed; | 182 EMACS_INT intervals_consed; |
| 136 EMACS_INT strings_consed; | 183 EMACS_INT strings_consed; |
| 137 | 184 |
| 138 /* Number of bytes of consing since GC before another GC should be done. */ | 185 /* Minimum number of bytes of consing since GC before next GC. */ |
| 139 | 186 |
| 140 EMACS_INT gc_cons_threshold; | 187 EMACS_INT gc_cons_threshold; |
| 141 | 188 |
| 189 /* Similar minimum, computed from Vgc_cons_percentage. */ | |
| 190 | |
| 191 EMACS_INT gc_relative_threshold; | |
| 192 | |
| 193 static Lisp_Object Vgc_cons_percentage; | |
| 194 | |
| 195 /* Minimum number of bytes of consing since GC before next GC, | |
| 196 when memory is full. */ | |
| 197 | |
| 198 EMACS_INT memory_full_cons_threshold; | |
| 199 | |
| 142 /* Nonzero during GC. */ | 200 /* Nonzero during GC. */ |
| 143 | 201 |
| 144 int gc_in_progress; | 202 int gc_in_progress; |
| 203 | |
| 204 /* Nonzero means abort if try to GC. | |
| 205 This is for code which is written on the assumption that | |
| 206 no GC will happen, so as to verify that assumption. */ | |
| 207 | |
| 208 int abort_on_gc; | |
| 145 | 209 |
| 146 /* Nonzero means display messages at beginning and end of GC. */ | 210 /* Nonzero means display messages at beginning and end of GC. */ |
| 147 | 211 |
| 148 int garbage_collection_messages; | 212 int garbage_collection_messages; |
| 149 | 213 |
| 155 #ifndef VIRT_ADDR_VARIES | 219 #ifndef VIRT_ADDR_VARIES |
| 156 extern | 220 extern |
| 157 #endif /* VIRT_ADDR_VARIES */ | 221 #endif /* VIRT_ADDR_VARIES */ |
| 158 int malloc_sbrk_unused; | 222 int malloc_sbrk_unused; |
| 159 | 223 |
| 160 /* Two limits controlling how much undo information to keep. */ | |
| 161 | |
| 162 EMACS_INT undo_limit; | |
| 163 EMACS_INT undo_strong_limit; | |
| 164 | |
| 165 /* Number of live and free conses etc. */ | 224 /* Number of live and free conses etc. */ |
| 166 | 225 |
| 167 static int total_conses, total_markers, total_symbols, total_vector_size; | 226 static int total_conses, total_markers, total_symbols, total_vector_size; |
| 168 static int total_free_conses, total_free_markers, total_free_symbols; | 227 static int total_free_conses, total_free_markers, total_free_symbols; |
| 169 static int total_free_floats, total_floats; | 228 static int total_free_floats, total_floats; |
| 170 | 229 |
| 171 /* Points to memory space allocated as "spare", to be freed if we run | 230 /* Points to memory space allocated as "spare", to be freed if we run |
| 172 out of memory. */ | 231 out of memory. We keep one large block, four cons-blocks, and |
| 173 | 232 two string blocks. */ |
| 174 static char *spare_memory; | 233 |
| 175 | 234 char *spare_memory[7]; |
| 176 /* Amount of spare memory to keep in reserve. */ | 235 |
| 236 /* Amount of spare memory to keep in large reserve block. */ | |
| 177 | 237 |
| 178 #define SPARE_MEMORY (1 << 14) | 238 #define SPARE_MEMORY (1 << 14) |
| 179 | 239 |
| 180 /* Number of extra blocks malloc should get when it needs more core. */ | 240 /* Number of extra blocks malloc should get when it needs more core. */ |
| 181 | 241 |
| 189 | 249 |
| 190 Lisp_Object Vmemory_full; | 250 Lisp_Object Vmemory_full; |
| 191 | 251 |
| 192 #ifndef HAVE_SHM | 252 #ifndef HAVE_SHM |
| 193 | 253 |
| 194 /* Force it into data space! */ | 254 /* Initialize it to a nonzero value to force it into data space |
| 195 | 255 (rather than bss space). That way unexec will remap it into text |
| 196 EMACS_INT pure[PURESIZE / sizeof (EMACS_INT)] = {0,}; | 256 space (pure), on some systems. We have not implemented the |
| 257 remapping on more recent systems because this is less important | |
| 258 nowadays than in the days of small memories and timesharing. */ | |
| 259 | |
| 260 EMACS_INT pure[PURESIZE / sizeof (EMACS_INT)] = {1,}; | |
| 197 #define PUREBEG (char *) pure | 261 #define PUREBEG (char *) pure |
| 198 | 262 |
| 199 #else /* HAVE_SHM */ | 263 #else /* HAVE_SHM */ |
| 200 | 264 |
| 201 #define pure PURE_SEG_BITS /* Use shared memory segment */ | 265 #define pure PURE_SEG_BITS /* Use shared memory segment */ |
| 258 | 322 |
| 259 Lisp_Object Vgc_elapsed; /* accumulated elapsed time in GC */ | 323 Lisp_Object Vgc_elapsed; /* accumulated elapsed time in GC */ |
| 260 EMACS_INT gcs_done; /* accumulated GCs */ | 324 EMACS_INT gcs_done; /* accumulated GCs */ |
| 261 | 325 |
| 262 static void mark_buffer P_ ((Lisp_Object)); | 326 static void mark_buffer P_ ((Lisp_Object)); |
| 263 static void mark_kboards P_ ((void)); | 327 extern void mark_kboards P_ ((void)); |
| 328 extern void mark_backtrace P_ ((void)); | |
| 264 static void gc_sweep P_ ((void)); | 329 static void gc_sweep P_ ((void)); |
| 265 static void mark_glyph_matrix P_ ((struct glyph_matrix *)); | 330 static void mark_glyph_matrix P_ ((struct glyph_matrix *)); |
| 266 static void mark_face_cache P_ ((struct face_cache *)); | 331 static void mark_face_cache P_ ((struct face_cache *)); |
| 267 | 332 |
| 268 #ifdef HAVE_WINDOW_SYSTEM | 333 #ifdef HAVE_WINDOW_SYSTEM |
| 334 extern void mark_fringe_data P_ ((void)); | |
| 269 static void mark_image P_ ((struct image *)); | 335 static void mark_image P_ ((struct image *)); |
| 270 static void mark_image_cache P_ ((struct frame *)); | 336 static void mark_image_cache P_ ((struct frame *)); |
| 271 #endif /* HAVE_WINDOW_SYSTEM */ | 337 #endif /* HAVE_WINDOW_SYSTEM */ |
| 272 | 338 |
| 273 static struct Lisp_String *allocate_string P_ ((void)); | 339 static struct Lisp_String *allocate_string P_ ((void)); |
| 297 MEM_TYPE_PROCESS, | 363 MEM_TYPE_PROCESS, |
| 298 MEM_TYPE_HASH_TABLE, | 364 MEM_TYPE_HASH_TABLE, |
| 299 MEM_TYPE_FRAME, | 365 MEM_TYPE_FRAME, |
| 300 MEM_TYPE_WINDOW | 366 MEM_TYPE_WINDOW |
| 301 }; | 367 }; |
| 368 | |
| 369 static POINTER_TYPE *lisp_align_malloc P_ ((size_t, enum mem_type)); | |
| 370 static POINTER_TYPE *lisp_malloc P_ ((size_t, enum mem_type)); | |
| 371 void refill_memory_reserve (); | |
| 372 | |
| 302 | 373 |
| 303 #if GC_MARK_STACK || defined GC_MALLOC_CHECK | 374 #if GC_MARK_STACK || defined GC_MALLOC_CHECK |
| 304 | 375 |
| 305 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES | 376 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES |
| 306 #include <stdio.h> /* For fprintf. */ | 377 #include <stdio.h> /* For fprintf. */ |
| 398 static void mem_rotate_right P_ ((struct mem_node *)); | 469 static void mem_rotate_right P_ ((struct mem_node *)); |
| 399 static void mem_delete P_ ((struct mem_node *)); | 470 static void mem_delete P_ ((struct mem_node *)); |
| 400 static void mem_delete_fixup P_ ((struct mem_node *)); | 471 static void mem_delete_fixup P_ ((struct mem_node *)); |
| 401 static INLINE struct mem_node *mem_find P_ ((void *)); | 472 static INLINE struct mem_node *mem_find P_ ((void *)); |
| 402 | 473 |
| 474 | |
| 403 #if GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS | 475 #if GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS |
| 404 static void check_gcpros P_ ((void)); | 476 static void check_gcpros P_ ((void)); |
| 405 #endif | 477 #endif |
| 406 | 478 |
| 407 #endif /* GC_MARK_STACK || GC_MALLOC_CHECK */ | 479 #endif /* GC_MARK_STACK || GC_MALLOC_CHECK */ |
| 408 | 480 |
| 409 /* Recording what needs to be marked for gc. */ | 481 /* Recording what needs to be marked for gc. */ |
| 410 | 482 |
| 411 struct gcpro *gcprolist; | 483 struct gcpro *gcprolist; |
| 412 | 484 |
| 413 /* Addresses of staticpro'd variables. */ | 485 /* Addresses of staticpro'd variables. Initialize it to a nonzero |
| 486 value; otherwise some compilers put it into BSS. */ | |
| 414 | 487 |
| 415 #define NSTATICS 1280 | 488 #define NSTATICS 1280 |
| 416 Lisp_Object *staticvec[NSTATICS] = {0}; | 489 Lisp_Object *staticvec[NSTATICS] = {&Vpurify_flag}; |
| 417 | 490 |
| 418 /* Index of next unused slot in staticvec. */ | 491 /* Index of next unused slot in staticvec. */ |
| 419 | 492 |
| 420 int staticidx = 0; | 493 int staticidx = 0; |
| 421 | 494 |
| 423 | 496 |
| 424 | 497 |
| 425 /* Value is SZ rounded up to the next multiple of ALIGNMENT. | 498 /* Value is SZ rounded up to the next multiple of ALIGNMENT. |
| 426 ALIGNMENT must be a power of 2. */ | 499 ALIGNMENT must be a power of 2. */ |
| 427 | 500 |
| 428 #define ALIGN(SZ, ALIGNMENT) \ | 501 #define ALIGN(ptr, ALIGNMENT) \ |
| 429 (((SZ) + (ALIGNMENT) - 1) & ~((ALIGNMENT) - 1)) | 502 ((POINTER_TYPE *) ((((EMACS_UINT)(ptr)) + (ALIGNMENT) - 1) \ |
| 503 & ~((ALIGNMENT) - 1))) | |
| 430 | 504 |
| 431 | 505 |
| 432 | 506 |
| 433 /************************************************************************ | 507 /************************************************************************ |
| 434 Malloc | 508 Malloc |
| 456 pending_malloc_warning = 0; | 530 pending_malloc_warning = 0; |
| 457 } | 531 } |
| 458 | 532 |
| 459 | 533 |
| 460 #ifdef DOUG_LEA_MALLOC | 534 #ifdef DOUG_LEA_MALLOC |
| 461 # define BYTES_USED (mallinfo ().arena) | 535 # define BYTES_USED (mallinfo ().uordblks) |
| 462 #else | 536 #else |
| 463 # define BYTES_USED _bytes_used | 537 # define BYTES_USED _bytes_used |
| 464 #endif | 538 #endif |
| 465 | 539 |
| 466 | |
| 467 /* Called if malloc returns zero. */ | |
| 468 | |
| 469 void | |
| 470 memory_full () | |
| 471 { | |
| 472 Vmemory_full = Qt; | |
| 473 | |
| 474 #ifndef SYSTEM_MALLOC | |
| 475 bytes_used_when_full = BYTES_USED; | |
| 476 #endif | |
| 477 | |
| 478 /* The first time we get here, free the spare memory. */ | |
| 479 if (spare_memory) | |
| 480 { | |
| 481 free (spare_memory); | |
| 482 spare_memory = 0; | |
| 483 } | |
| 484 | |
| 485 /* This used to call error, but if we've run out of memory, we could | |
| 486 get infinite recursion trying to build the string. */ | |
| 487 while (1) | |
| 488 Fsignal (Qnil, Vmemory_signal_data); | |
| 489 } | |
| 490 | |
| 491 | |
| 492 /* Called if we can't allocate relocatable space for a buffer. */ | 540 /* Called if we can't allocate relocatable space for a buffer. */ |
| 493 | 541 |
| 494 void | 542 void |
| 495 buffer_memory_full () | 543 buffer_memory_full () |
| 496 { | 544 { |
| 503 | 551 |
| 504 #ifndef REL_ALLOC | 552 #ifndef REL_ALLOC |
| 505 memory_full (); | 553 memory_full (); |
| 506 #endif | 554 #endif |
| 507 | 555 |
| 508 Vmemory_full = Qt; | |
| 509 | |
| 510 /* This used to call error, but if we've run out of memory, we could | 556 /* This used to call error, but if we've run out of memory, we could |
| 511 get infinite recursion trying to build the string. */ | 557 get infinite recursion trying to build the string. */ |
| 512 while (1) | 558 while (1) |
| 513 Fsignal (Qnil, Vmemory_signal_data); | 559 Fsignal (Qnil, Vmemory_signal_data); |
| 514 } | 560 } |
| 561 | |
| 562 | |
| 563 #ifdef XMALLOC_OVERRUN_CHECK | |
| 564 | |
| 565 /* Check for overrun in malloc'ed buffers by wrapping a 16 byte header | |
| 566 and a 16 byte trailer around each block. | |
| 567 | |
| 568 The header consists of 12 fixed bytes + a 4 byte integer contaning the | |
| 569 original block size, while the trailer consists of 16 fixed bytes. | |
| 570 | |
| 571 The header is used to detect whether this block has been allocated | |
| 572 through these functions -- as it seems that some low-level libc | |
| 573 functions may bypass the malloc hooks. | |
| 574 */ | |
| 575 | |
| 576 | |
| 577 #define XMALLOC_OVERRUN_CHECK_SIZE 16 | |
| 578 | |
| 579 static char xmalloc_overrun_check_header[XMALLOC_OVERRUN_CHECK_SIZE-4] = | |
| 580 { 0x9a, 0x9b, 0xae, 0xaf, | |
| 581 0xbf, 0xbe, 0xce, 0xcf, | |
| 582 0xea, 0xeb, 0xec, 0xed }; | |
| 583 | |
| 584 static char xmalloc_overrun_check_trailer[XMALLOC_OVERRUN_CHECK_SIZE] = | |
| 585 { 0xaa, 0xab, 0xac, 0xad, | |
| 586 0xba, 0xbb, 0xbc, 0xbd, | |
| 587 0xca, 0xcb, 0xcc, 0xcd, | |
| 588 0xda, 0xdb, 0xdc, 0xdd }; | |
| 589 | |
| 590 /* Macros to insert and extract the block size in the header. */ | |
| 591 | |
| 592 #define XMALLOC_PUT_SIZE(ptr, size) \ | |
| 593 (ptr[-1] = (size & 0xff), \ | |
| 594 ptr[-2] = ((size >> 8) & 0xff), \ | |
| 595 ptr[-3] = ((size >> 16) & 0xff), \ | |
| 596 ptr[-4] = ((size >> 24) & 0xff)) | |
| 597 | |
| 598 #define XMALLOC_GET_SIZE(ptr) \ | |
| 599 (size_t)((unsigned)(ptr[-1]) | \ | |
| 600 ((unsigned)(ptr[-2]) << 8) | \ | |
| 601 ((unsigned)(ptr[-3]) << 16) | \ | |
| 602 ((unsigned)(ptr[-4]) << 24)) | |
| 603 | |
| 604 | |
| 605 /* The call depth in overrun_check functions. For example, this might happen: | |
| 606 xmalloc() | |
| 607 overrun_check_malloc() | |
| 608 -> malloc -> (via hook)_-> emacs_blocked_malloc | |
| 609 -> overrun_check_malloc | |
| 610 call malloc (hooks are NULL, so real malloc is called). | |
| 611 malloc returns 10000. | |
| 612 add overhead, return 10016. | |
| 613 <- (back in overrun_check_malloc) | |
| 614 add overhead again, return 10032 | |
| 615 xmalloc returns 10032. | |
| 616 | |
| 617 (time passes). | |
| 618 | |
| 619 xfree(10032) | |
| 620 overrun_check_free(10032) | |
| 621 decrease overhed | |
| 622 free(10016) <- crash, because 10000 is the original pointer. */ | |
| 623 | |
| 624 static int check_depth; | |
| 625 | |
| 626 /* Like malloc, but wraps allocated block with header and trailer. */ | |
| 627 | |
| 628 POINTER_TYPE * | |
| 629 overrun_check_malloc (size) | |
| 630 size_t size; | |
| 631 { | |
| 632 register unsigned char *val; | |
| 633 size_t overhead = ++check_depth == 1 ? XMALLOC_OVERRUN_CHECK_SIZE*2 : 0; | |
| 634 | |
| 635 val = (unsigned char *) malloc (size + overhead); | |
| 636 if (val && check_depth == 1) | |
| 637 { | |
| 638 bcopy (xmalloc_overrun_check_header, val, XMALLOC_OVERRUN_CHECK_SIZE - 4); | |
| 639 val += XMALLOC_OVERRUN_CHECK_SIZE; | |
| 640 XMALLOC_PUT_SIZE(val, size); | |
| 641 bcopy (xmalloc_overrun_check_trailer, val + size, XMALLOC_OVERRUN_CHECK_SIZE); | |
| 642 } | |
| 643 --check_depth; | |
| 644 return (POINTER_TYPE *)val; | |
| 645 } | |
| 646 | |
| 647 | |
| 648 /* Like realloc, but checks old block for overrun, and wraps new block | |
| 649 with header and trailer. */ | |
| 650 | |
| 651 POINTER_TYPE * | |
| 652 overrun_check_realloc (block, size) | |
| 653 POINTER_TYPE *block; | |
| 654 size_t size; | |
| 655 { | |
| 656 register unsigned char *val = (unsigned char *)block; | |
| 657 size_t overhead = ++check_depth == 1 ? XMALLOC_OVERRUN_CHECK_SIZE*2 : 0; | |
| 658 | |
| 659 if (val | |
| 660 && check_depth == 1 | |
| 661 && bcmp (xmalloc_overrun_check_header, | |
| 662 val - XMALLOC_OVERRUN_CHECK_SIZE, | |
| 663 XMALLOC_OVERRUN_CHECK_SIZE - 4) == 0) | |
| 664 { | |
| 665 size_t osize = XMALLOC_GET_SIZE (val); | |
| 666 if (bcmp (xmalloc_overrun_check_trailer, | |
| 667 val + osize, | |
| 668 XMALLOC_OVERRUN_CHECK_SIZE)) | |
| 669 abort (); | |
| 670 bzero (val + osize, XMALLOC_OVERRUN_CHECK_SIZE); | |
| 671 val -= XMALLOC_OVERRUN_CHECK_SIZE; | |
| 672 bzero (val, XMALLOC_OVERRUN_CHECK_SIZE); | |
| 673 } | |
| 674 | |
| 675 val = (unsigned char *) realloc ((POINTER_TYPE *)val, size + overhead); | |
| 676 | |
| 677 if (val && check_depth == 1) | |
| 678 { | |
| 679 bcopy (xmalloc_overrun_check_header, val, XMALLOC_OVERRUN_CHECK_SIZE - 4); | |
| 680 val += XMALLOC_OVERRUN_CHECK_SIZE; | |
| 681 XMALLOC_PUT_SIZE(val, size); | |
| 682 bcopy (xmalloc_overrun_check_trailer, val + size, XMALLOC_OVERRUN_CHECK_SIZE); | |
| 683 } | |
| 684 --check_depth; | |
| 685 return (POINTER_TYPE *)val; | |
| 686 } | |
| 687 | |
| 688 /* Like free, but checks block for overrun. */ | |
| 689 | |
| 690 void | |
| 691 overrun_check_free (block) | |
| 692 POINTER_TYPE *block; | |
| 693 { | |
| 694 unsigned char *val = (unsigned char *)block; | |
| 695 | |
| 696 ++check_depth; | |
| 697 if (val | |
| 698 && check_depth == 1 | |
| 699 && bcmp (xmalloc_overrun_check_header, | |
| 700 val - XMALLOC_OVERRUN_CHECK_SIZE, | |
| 701 XMALLOC_OVERRUN_CHECK_SIZE - 4) == 0) | |
| 702 { | |
| 703 size_t osize = XMALLOC_GET_SIZE (val); | |
| 704 if (bcmp (xmalloc_overrun_check_trailer, | |
| 705 val + osize, | |
| 706 XMALLOC_OVERRUN_CHECK_SIZE)) | |
| 707 abort (); | |
| 708 #ifdef XMALLOC_CLEAR_FREE_MEMORY | |
| 709 val -= XMALLOC_OVERRUN_CHECK_SIZE; | |
| 710 memset (val, 0xff, osize + XMALLOC_OVERRUN_CHECK_SIZE*2); | |
| 711 #else | |
| 712 bzero (val + osize, XMALLOC_OVERRUN_CHECK_SIZE); | |
| 713 val -= XMALLOC_OVERRUN_CHECK_SIZE; | |
| 714 bzero (val, XMALLOC_OVERRUN_CHECK_SIZE); | |
| 715 #endif | |
| 716 } | |
| 717 | |
| 718 free (val); | |
| 719 --check_depth; | |
| 720 } | |
| 721 | |
| 722 #undef malloc | |
| 723 #undef realloc | |
| 724 #undef free | |
| 725 #define malloc overrun_check_malloc | |
| 726 #define realloc overrun_check_realloc | |
| 727 #define free overrun_check_free | |
| 728 #endif | |
| 515 | 729 |
| 516 | 730 |
| 517 /* Like malloc but check for no memory and block interrupt input.. */ | 731 /* Like malloc but check for no memory and block interrupt input.. */ |
| 518 | 732 |
| 519 POINTER_TYPE * | 733 POINTER_TYPE * |
| 553 if (!val && size) memory_full (); | 767 if (!val && size) memory_full (); |
| 554 return val; | 768 return val; |
| 555 } | 769 } |
| 556 | 770 |
| 557 | 771 |
| 558 /* Like free but block interrupt input.. */ | 772 /* Like free but block interrupt input. */ |
| 559 | 773 |
| 560 void | 774 void |
| 561 xfree (block) | 775 xfree (block) |
| 562 POINTER_TYPE *block; | 776 POINTER_TYPE *block; |
| 563 { | 777 { |
| 564 BLOCK_INPUT; | 778 BLOCK_INPUT; |
| 565 free (block); | 779 free (block); |
| 566 UNBLOCK_INPUT; | 780 UNBLOCK_INPUT; |
| 781 /* We don't call refill_memory_reserve here | |
| 782 because that duplicates doing so in emacs_blocked_free | |
| 783 and the criterion should go there. */ | |
| 567 } | 784 } |
| 568 | 785 |
| 569 | 786 |
| 570 /* Like strdup, but uses xmalloc. */ | 787 /* Like strdup, but uses xmalloc. */ |
| 571 | 788 |
| 578 bcopy (s, p, len); | 795 bcopy (s, p, len); |
| 579 return p; | 796 return p; |
| 580 } | 797 } |
| 581 | 798 |
| 582 | 799 |
| 800 /* Unwind for SAFE_ALLOCA */ | |
| 801 | |
| 802 Lisp_Object | |
| 803 safe_alloca_unwind (arg) | |
| 804 Lisp_Object arg; | |
| 805 { | |
| 806 register struct Lisp_Save_Value *p = XSAVE_VALUE (arg); | |
| 807 | |
| 808 p->dogc = 0; | |
| 809 xfree (p->pointer); | |
| 810 p->pointer = 0; | |
| 811 free_misc (arg); | |
| 812 return Qnil; | |
| 813 } | |
| 814 | |
| 815 | |
| 583 /* Like malloc but used for allocating Lisp data. NBYTES is the | 816 /* Like malloc but used for allocating Lisp data. NBYTES is the |
| 584 number of bytes to allocate, TYPE describes the intended use of the | 817 number of bytes to allocate, TYPE describes the intended use of the |
| 585 allcated memory block (for strings, for conses, ...). */ | 818 allcated memory block (for strings, for conses, ...). */ |
| 819 | |
| 820 #ifndef USE_LSB_TAG | |
| 821 static void *lisp_malloc_loser; | |
| 822 #endif | |
| 586 | 823 |
| 587 static POINTER_TYPE * | 824 static POINTER_TYPE * |
| 588 lisp_malloc (nbytes, type) | 825 lisp_malloc (nbytes, type) |
| 589 size_t nbytes; | 826 size_t nbytes; |
| 590 enum mem_type type; | 827 enum mem_type type; |
| 597 allocated_mem_type = type; | 834 allocated_mem_type = type; |
| 598 #endif | 835 #endif |
| 599 | 836 |
| 600 val = (void *) malloc (nbytes); | 837 val = (void *) malloc (nbytes); |
| 601 | 838 |
| 839 #ifndef USE_LSB_TAG | |
| 840 /* If the memory just allocated cannot be addressed thru a Lisp | |
| 841 object's pointer, and it needs to be, | |
| 842 that's equivalent to running out of memory. */ | |
| 843 if (val && type != MEM_TYPE_NON_LISP) | |
| 844 { | |
| 845 Lisp_Object tem; | |
| 846 XSETCONS (tem, (char *) val + nbytes - 1); | |
| 847 if ((char *) XCONS (tem) != (char *) val + nbytes - 1) | |
| 848 { | |
| 849 lisp_malloc_loser = val; | |
| 850 free (val); | |
| 851 val = 0; | |
| 852 } | |
| 853 } | |
| 854 #endif | |
| 855 | |
| 602 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK | 856 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK |
| 603 if (val && type != MEM_TYPE_NON_LISP) | 857 if (val && type != MEM_TYPE_NON_LISP) |
| 604 mem_insert (val, (char *) val + nbytes, type); | 858 mem_insert (val, (char *) val + nbytes, type); |
| 605 #endif | 859 #endif |
| 606 | 860 |
| 608 if (!val && nbytes) | 862 if (!val && nbytes) |
| 609 memory_full (); | 863 memory_full (); |
| 610 return val; | 864 return val; |
| 611 } | 865 } |
| 612 | 866 |
| 613 | |
| 614 /* Return a new buffer structure allocated from the heap with | |
| 615 a call to lisp_malloc. */ | |
| 616 | |
| 617 struct buffer * | |
| 618 allocate_buffer () | |
| 619 { | |
| 620 struct buffer *b | |
| 621 = (struct buffer *) lisp_malloc (sizeof (struct buffer), | |
| 622 MEM_TYPE_BUFFER); | |
| 623 VALIDATE_LISP_STORAGE (b, sizeof *b); | |
| 624 return b; | |
| 625 } | |
| 626 | |
| 627 | |
| 628 /* Free BLOCK. This must be called to free memory allocated with a | 867 /* Free BLOCK. This must be called to free memory allocated with a |
| 629 call to lisp_malloc. */ | 868 call to lisp_malloc. */ |
| 630 | 869 |
| 631 static void | 870 static void |
| 632 lisp_free (block) | 871 lisp_free (block) |
| 638 mem_delete (mem_find (block)); | 877 mem_delete (mem_find (block)); |
| 639 #endif | 878 #endif |
| 640 UNBLOCK_INPUT; | 879 UNBLOCK_INPUT; |
| 641 } | 880 } |
| 642 | 881 |
| 882 /* Allocation of aligned blocks of memory to store Lisp data. */ | |
| 883 /* The entry point is lisp_align_malloc which returns blocks of at most */ | |
| 884 /* BLOCK_BYTES and guarantees they are aligned on a BLOCK_ALIGN boundary. */ | |
| 885 | |
| 886 | |
| 887 /* BLOCK_ALIGN has to be a power of 2. */ | |
| 888 #define BLOCK_ALIGN (1 << 10) | |
| 889 | |
| 890 /* Padding to leave at the end of a malloc'd block. This is to give | |
| 891 malloc a chance to minimize the amount of memory wasted to alignment. | |
| 892 It should be tuned to the particular malloc library used. | |
| 893 On glibc-2.3.2, malloc never tries to align, so a padding of 0 is best. | |
| 894 posix_memalign on the other hand would ideally prefer a value of 4 | |
| 895 because otherwise, there's 1020 bytes wasted between each ablocks. | |
| 896 In Emacs, testing shows that those 1020 can most of the time be | |
| 897 efficiently used by malloc to place other objects, so a value of 0 can | |
| 898 still preferable unless you have a lot of aligned blocks and virtually | |
| 899 nothing else. */ | |
| 900 #define BLOCK_PADDING 0 | |
| 901 #define BLOCK_BYTES \ | |
| 902 (BLOCK_ALIGN - sizeof (struct ablock *) - BLOCK_PADDING) | |
| 903 | |
| 904 /* Internal data structures and constants. */ | |
| 905 | |
| 906 #define ABLOCKS_SIZE 16 | |
| 907 | |
| 908 /* An aligned block of memory. */ | |
| 909 struct ablock | |
| 910 { | |
| 911 union | |
| 912 { | |
| 913 char payload[BLOCK_BYTES]; | |
| 914 struct ablock *next_free; | |
| 915 } x; | |
| 916 /* `abase' is the aligned base of the ablocks. */ | |
| 917 /* It is overloaded to hold the virtual `busy' field that counts | |
| 918 the number of used ablock in the parent ablocks. | |
| 919 The first ablock has the `busy' field, the others have the `abase' | |
| 920 field. To tell the difference, we assume that pointers will have | |
| 921 integer values larger than 2 * ABLOCKS_SIZE. The lowest bit of `busy' | |
| 922 is used to tell whether the real base of the parent ablocks is `abase' | |
| 923 (if not, the word before the first ablock holds a pointer to the | |
| 924 real base). */ | |
| 925 struct ablocks *abase; | |
| 926 /* The padding of all but the last ablock is unused. The padding of | |
| 927 the last ablock in an ablocks is not allocated. */ | |
| 928 #if BLOCK_PADDING | |
| 929 char padding[BLOCK_PADDING]; | |
| 930 #endif | |
| 931 }; | |
| 932 | |
| 933 /* A bunch of consecutive aligned blocks. */ | |
| 934 struct ablocks | |
| 935 { | |
| 936 struct ablock blocks[ABLOCKS_SIZE]; | |
| 937 }; | |
| 938 | |
| 939 /* Size of the block requested from malloc or memalign. */ | |
| 940 #define ABLOCKS_BYTES (sizeof (struct ablocks) - BLOCK_PADDING) | |
| 941 | |
| 942 #define ABLOCK_ABASE(block) \ | |
| 943 (((unsigned long) (block)->abase) <= (1 + 2 * ABLOCKS_SIZE) \ | |
| 944 ? (struct ablocks *)(block) \ | |
| 945 : (block)->abase) | |
| 946 | |
| 947 /* Virtual `busy' field. */ | |
| 948 #define ABLOCKS_BUSY(abase) ((abase)->blocks[0].abase) | |
| 949 | |
| 950 /* Pointer to the (not necessarily aligned) malloc block. */ | |
| 951 #ifdef HAVE_POSIX_MEMALIGN | |
| 952 #define ABLOCKS_BASE(abase) (abase) | |
| 953 #else | |
| 954 #define ABLOCKS_BASE(abase) \ | |
| 955 (1 & (long) ABLOCKS_BUSY (abase) ? abase : ((void**)abase)[-1]) | |
| 956 #endif | |
| 957 | |
| 958 /* The list of free ablock. */ | |
| 959 static struct ablock *free_ablock; | |
| 960 | |
| 961 /* Allocate an aligned block of nbytes. | |
| 962 Alignment is on a multiple of BLOCK_ALIGN and `nbytes' has to be | |
| 963 smaller or equal to BLOCK_BYTES. */ | |
| 964 static POINTER_TYPE * | |
| 965 lisp_align_malloc (nbytes, type) | |
| 966 size_t nbytes; | |
| 967 enum mem_type type; | |
| 968 { | |
| 969 void *base, *val; | |
| 970 struct ablocks *abase; | |
| 971 | |
| 972 eassert (nbytes <= BLOCK_BYTES); | |
| 973 | |
| 974 BLOCK_INPUT; | |
| 975 | |
| 976 #ifdef GC_MALLOC_CHECK | |
| 977 allocated_mem_type = type; | |
| 978 #endif | |
| 979 | |
| 980 if (!free_ablock) | |
| 981 { | |
| 982 int i; | |
| 983 EMACS_INT aligned; /* int gets warning casting to 64-bit pointer. */ | |
| 984 | |
| 985 #ifdef DOUG_LEA_MALLOC | |
| 986 /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed | |
| 987 because mapped region contents are not preserved in | |
| 988 a dumped Emacs. */ | |
| 989 mallopt (M_MMAP_MAX, 0); | |
| 990 #endif | |
| 991 | |
| 992 #ifdef HAVE_POSIX_MEMALIGN | |
| 993 { | |
| 994 int err = posix_memalign (&base, BLOCK_ALIGN, ABLOCKS_BYTES); | |
| 995 if (err) | |
| 996 base = NULL; | |
| 997 abase = base; | |
| 998 } | |
| 999 #else | |
| 1000 base = malloc (ABLOCKS_BYTES); | |
| 1001 abase = ALIGN (base, BLOCK_ALIGN); | |
| 1002 #endif | |
| 1003 | |
| 1004 if (base == 0) | |
| 1005 { | |
| 1006 UNBLOCK_INPUT; | |
| 1007 memory_full (); | |
| 1008 } | |
| 1009 | |
| 1010 aligned = (base == abase); | |
| 1011 if (!aligned) | |
| 1012 ((void**)abase)[-1] = base; | |
| 1013 | |
| 1014 #ifdef DOUG_LEA_MALLOC | |
| 1015 /* Back to a reasonable maximum of mmap'ed areas. */ | |
| 1016 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); | |
| 1017 #endif | |
| 1018 | |
| 1019 #ifndef USE_LSB_TAG | |
| 1020 /* If the memory just allocated cannot be addressed thru a Lisp | |
| 1021 object's pointer, and it needs to be, that's equivalent to | |
| 1022 running out of memory. */ | |
| 1023 if (type != MEM_TYPE_NON_LISP) | |
| 1024 { | |
| 1025 Lisp_Object tem; | |
| 1026 char *end = (char *) base + ABLOCKS_BYTES - 1; | |
| 1027 XSETCONS (tem, end); | |
| 1028 if ((char *) XCONS (tem) != end) | |
| 1029 { | |
| 1030 lisp_malloc_loser = base; | |
| 1031 free (base); | |
| 1032 UNBLOCK_INPUT; | |
| 1033 memory_full (); | |
| 1034 } | |
| 1035 } | |
| 1036 #endif | |
| 1037 | |
| 1038 /* Initialize the blocks and put them on the free list. | |
| 1039 Is `base' was not properly aligned, we can't use the last block. */ | |
| 1040 for (i = 0; i < (aligned ? ABLOCKS_SIZE : ABLOCKS_SIZE - 1); i++) | |
| 1041 { | |
| 1042 abase->blocks[i].abase = abase; | |
| 1043 abase->blocks[i].x.next_free = free_ablock; | |
| 1044 free_ablock = &abase->blocks[i]; | |
| 1045 } | |
| 1046 ABLOCKS_BUSY (abase) = (struct ablocks *) (long) aligned; | |
| 1047 | |
| 1048 eassert (0 == ((EMACS_UINT)abase) % BLOCK_ALIGN); | |
| 1049 eassert (ABLOCK_ABASE (&abase->blocks[3]) == abase); /* 3 is arbitrary */ | |
| 1050 eassert (ABLOCK_ABASE (&abase->blocks[0]) == abase); | |
| 1051 eassert (ABLOCKS_BASE (abase) == base); | |
| 1052 eassert (aligned == (long) ABLOCKS_BUSY (abase)); | |
| 1053 } | |
| 1054 | |
| 1055 abase = ABLOCK_ABASE (free_ablock); | |
| 1056 ABLOCKS_BUSY (abase) = (struct ablocks *) (2 + (long) ABLOCKS_BUSY (abase)); | |
| 1057 val = free_ablock; | |
| 1058 free_ablock = free_ablock->x.next_free; | |
| 1059 | |
| 1060 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK | |
| 1061 if (val && type != MEM_TYPE_NON_LISP) | |
| 1062 mem_insert (val, (char *) val + nbytes, type); | |
| 1063 #endif | |
| 1064 | |
| 1065 UNBLOCK_INPUT; | |
| 1066 if (!val && nbytes) | |
| 1067 memory_full (); | |
| 1068 | |
| 1069 eassert (0 == ((EMACS_UINT)val) % BLOCK_ALIGN); | |
| 1070 return val; | |
| 1071 } | |
| 1072 | |
| 1073 static void | |
| 1074 lisp_align_free (block) | |
| 1075 POINTER_TYPE *block; | |
| 1076 { | |
| 1077 struct ablock *ablock = block; | |
| 1078 struct ablocks *abase = ABLOCK_ABASE (ablock); | |
| 1079 | |
| 1080 BLOCK_INPUT; | |
| 1081 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK | |
| 1082 mem_delete (mem_find (block)); | |
| 1083 #endif | |
| 1084 /* Put on free list. */ | |
| 1085 ablock->x.next_free = free_ablock; | |
| 1086 free_ablock = ablock; | |
| 1087 /* Update busy count. */ | |
| 1088 ABLOCKS_BUSY (abase) = (struct ablocks *) (-2 + (long) ABLOCKS_BUSY (abase)); | |
| 1089 | |
| 1090 if (2 > (long) ABLOCKS_BUSY (abase)) | |
| 1091 { /* All the blocks are free. */ | |
| 1092 int i = 0, aligned = (long) ABLOCKS_BUSY (abase); | |
| 1093 struct ablock **tem = &free_ablock; | |
| 1094 struct ablock *atop = &abase->blocks[aligned ? ABLOCKS_SIZE : ABLOCKS_SIZE - 1]; | |
| 1095 | |
| 1096 while (*tem) | |
| 1097 { | |
| 1098 if (*tem >= (struct ablock *) abase && *tem < atop) | |
| 1099 { | |
| 1100 i++; | |
| 1101 *tem = (*tem)->x.next_free; | |
| 1102 } | |
| 1103 else | |
| 1104 tem = &(*tem)->x.next_free; | |
| 1105 } | |
| 1106 eassert ((aligned & 1) == aligned); | |
| 1107 eassert (i == (aligned ? ABLOCKS_SIZE : ABLOCKS_SIZE - 1)); | |
| 1108 free (ABLOCKS_BASE (abase)); | |
| 1109 } | |
| 1110 UNBLOCK_INPUT; | |
| 1111 } | |
| 1112 | |
| 1113 /* Return a new buffer structure allocated from the heap with | |
| 1114 a call to lisp_malloc. */ | |
| 1115 | |
| 1116 struct buffer * | |
| 1117 allocate_buffer () | |
| 1118 { | |
| 1119 struct buffer *b | |
| 1120 = (struct buffer *) lisp_malloc (sizeof (struct buffer), | |
| 1121 MEM_TYPE_BUFFER); | |
| 1122 return b; | |
| 1123 } | |
| 1124 | |
| 643 | 1125 |
| 1126 #ifndef SYSTEM_MALLOC | |
| 1127 | |
| 644 /* Arranging to disable input signals while we're in malloc. | 1128 /* Arranging to disable input signals while we're in malloc. |
| 645 | 1129 |
| 646 This only works with GNU malloc. To help out systems which can't | 1130 This only works with GNU malloc. To help out systems which can't |
| 647 use GNU malloc, all the calls to malloc, realloc, and free | 1131 use GNU malloc, all the calls to malloc, realloc, and free |
| 648 elsewhere in the code should be inside a BLOCK_INPUT/UNBLOCK_INPUT | 1132 elsewhere in the code should be inside a BLOCK_INPUT/UNBLOCK_INPUT |
| 649 pairs; unfortunately, we have no idea what C library functions | 1133 pair; unfortunately, we have no idea what C library functions |
| 650 might call malloc, so we can't really protect them unless you're | 1134 might call malloc, so we can't really protect them unless you're |
| 651 using GNU malloc. Fortunately, most of the major operating systems | 1135 using GNU malloc. Fortunately, most of the major operating systems |
| 652 can use GNU malloc. */ | 1136 can use GNU malloc. */ |
| 653 | 1137 |
| 654 #ifndef SYSTEM_MALLOC | 1138 #ifndef SYNC_INPUT |
| 1139 | |
| 655 #ifndef DOUG_LEA_MALLOC | 1140 #ifndef DOUG_LEA_MALLOC |
| 656 extern void * (*__malloc_hook) P_ ((size_t)); | 1141 extern void * (*__malloc_hook) P_ ((size_t, const void *)); |
| 657 extern void * (*__realloc_hook) P_ ((void *, size_t)); | 1142 extern void * (*__realloc_hook) P_ ((void *, size_t, const void *)); |
| 658 extern void (*__free_hook) P_ ((void *)); | 1143 extern void (*__free_hook) P_ ((void *, const void *)); |
| 659 /* Else declared in malloc.h, perhaps with an extra arg. */ | 1144 /* Else declared in malloc.h, perhaps with an extra arg. */ |
| 660 #endif /* DOUG_LEA_MALLOC */ | 1145 #endif /* DOUG_LEA_MALLOC */ |
| 661 static void * (*old_malloc_hook) (); | 1146 static void * (*old_malloc_hook) P_ ((size_t, const void *)); |
| 662 static void * (*old_realloc_hook) (); | 1147 static void * (*old_realloc_hook) P_ ((void *, size_t, const void*)); |
| 663 static void (*old_free_hook) (); | 1148 static void (*old_free_hook) P_ ((void*, const void*)); |
| 664 | 1149 |
| 665 /* This function is used as the hook for free to call. */ | 1150 /* This function is used as the hook for free to call. */ |
| 666 | 1151 |
| 667 static void | 1152 static void |
| 668 emacs_blocked_free (ptr) | 1153 emacs_blocked_free (ptr, ptr2) |
| 669 void *ptr; | 1154 void *ptr; |
| 670 { | 1155 const void *ptr2; |
| 671 BLOCK_INPUT; | 1156 { |
| 1157 EMACS_INT bytes_used_now; | |
| 1158 | |
| 1159 BLOCK_INPUT_ALLOC; | |
| 672 | 1160 |
| 673 #ifdef GC_MALLOC_CHECK | 1161 #ifdef GC_MALLOC_CHECK |
| 674 if (ptr) | 1162 if (ptr) |
| 675 { | 1163 { |
| 676 struct mem_node *m; | 1164 struct mem_node *m; |
| 694 free (ptr); | 1182 free (ptr); |
| 695 | 1183 |
| 696 /* If we released our reserve (due to running out of memory), | 1184 /* If we released our reserve (due to running out of memory), |
| 697 and we have a fair amount free once again, | 1185 and we have a fair amount free once again, |
| 698 try to set aside another reserve in case we run out once more. */ | 1186 try to set aside another reserve in case we run out once more. */ |
| 699 if (spare_memory == 0 | 1187 if (! NILP (Vmemory_full) |
| 700 /* Verify there is enough space that even with the malloc | 1188 /* Verify there is enough space that even with the malloc |
| 701 hysteresis this call won't run out again. | 1189 hysteresis this call won't run out again. |
| 702 The code here is correct as long as SPARE_MEMORY | 1190 The code here is correct as long as SPARE_MEMORY |
| 703 is substantially larger than the block size malloc uses. */ | 1191 is substantially larger than the block size malloc uses. */ |
| 704 && (bytes_used_when_full | 1192 && (bytes_used_when_full |
| 705 > BYTES_USED + max (malloc_hysteresis, 4) * SPARE_MEMORY)) | 1193 > ((bytes_used_when_reconsidered = BYTES_USED) |
| 706 spare_memory = (char *) malloc ((size_t) SPARE_MEMORY); | 1194 + max (malloc_hysteresis, 4) * SPARE_MEMORY))) |
| 1195 refill_memory_reserve (); | |
| 707 | 1196 |
| 708 __free_hook = emacs_blocked_free; | 1197 __free_hook = emacs_blocked_free; |
| 709 UNBLOCK_INPUT; | 1198 UNBLOCK_INPUT_ALLOC; |
| 710 } | |
| 711 | |
| 712 | |
| 713 /* If we released our reserve (due to running out of memory), | |
| 714 and we have a fair amount free once again, | |
| 715 try to set aside another reserve in case we run out once more. | |
| 716 | |
| 717 This is called when a relocatable block is freed in ralloc.c. */ | |
| 718 | |
| 719 void | |
| 720 refill_memory_reserve () | |
| 721 { | |
| 722 if (spare_memory == 0) | |
| 723 spare_memory = (char *) malloc ((size_t) SPARE_MEMORY); | |
| 724 } | 1199 } |
| 725 | 1200 |
| 726 | 1201 |
| 727 /* This function is the malloc hook that Emacs uses. */ | 1202 /* This function is the malloc hook that Emacs uses. */ |
| 728 | 1203 |
| 729 static void * | 1204 static void * |
| 730 emacs_blocked_malloc (size) | 1205 emacs_blocked_malloc (size, ptr) |
| 731 size_t size; | 1206 size_t size; |
| 1207 const void *ptr; | |
| 732 { | 1208 { |
| 733 void *value; | 1209 void *value; |
| 734 | 1210 |
| 735 BLOCK_INPUT; | 1211 BLOCK_INPUT_ALLOC; |
| 736 __malloc_hook = old_malloc_hook; | 1212 __malloc_hook = old_malloc_hook; |
| 737 #ifdef DOUG_LEA_MALLOC | 1213 #ifdef DOUG_LEA_MALLOC |
| 738 mallopt (M_TOP_PAD, malloc_hysteresis * 4096); | 1214 mallopt (M_TOP_PAD, malloc_hysteresis * 4096); |
| 739 #else | 1215 #else |
| 740 __malloc_extra_blocks = malloc_hysteresis; | 1216 __malloc_extra_blocks = malloc_hysteresis; |
| 762 } | 1238 } |
| 763 } | 1239 } |
| 764 #endif /* GC_MALLOC_CHECK */ | 1240 #endif /* GC_MALLOC_CHECK */ |
| 765 | 1241 |
| 766 __malloc_hook = emacs_blocked_malloc; | 1242 __malloc_hook = emacs_blocked_malloc; |
| 767 UNBLOCK_INPUT; | 1243 UNBLOCK_INPUT_ALLOC; |
| 768 | 1244 |
| 769 /* fprintf (stderr, "%p malloc\n", value); */ | 1245 /* fprintf (stderr, "%p malloc\n", value); */ |
| 770 return value; | 1246 return value; |
| 771 } | 1247 } |
| 772 | 1248 |
| 773 | 1249 |
| 774 /* This function is the realloc hook that Emacs uses. */ | 1250 /* This function is the realloc hook that Emacs uses. */ |
| 775 | 1251 |
| 776 static void * | 1252 static void * |
| 777 emacs_blocked_realloc (ptr, size) | 1253 emacs_blocked_realloc (ptr, size, ptr2) |
| 778 void *ptr; | 1254 void *ptr; |
| 779 size_t size; | 1255 size_t size; |
| 1256 const void *ptr2; | |
| 780 { | 1257 { |
| 781 void *value; | 1258 void *value; |
| 782 | 1259 |
| 783 BLOCK_INPUT; | 1260 BLOCK_INPUT_ALLOC; |
| 784 __realloc_hook = old_realloc_hook; | 1261 __realloc_hook = old_realloc_hook; |
| 785 | 1262 |
| 786 #ifdef GC_MALLOC_CHECK | 1263 #ifdef GC_MALLOC_CHECK |
| 787 if (ptr) | 1264 if (ptr) |
| 788 { | 1265 { |
| 823 | 1300 |
| 824 /* fprintf (stderr, "%p <- realloc\n", value); */ | 1301 /* fprintf (stderr, "%p <- realloc\n", value); */ |
| 825 #endif /* GC_MALLOC_CHECK */ | 1302 #endif /* GC_MALLOC_CHECK */ |
| 826 | 1303 |
| 827 __realloc_hook = emacs_blocked_realloc; | 1304 __realloc_hook = emacs_blocked_realloc; |
| 828 UNBLOCK_INPUT; | 1305 UNBLOCK_INPUT_ALLOC; |
| 829 | 1306 |
| 830 return value; | 1307 return value; |
| 831 } | 1308 } |
| 1309 | |
| 1310 | |
| 1311 #ifdef HAVE_GTK_AND_PTHREAD | |
| 1312 /* Called from Fdump_emacs so that when the dumped Emacs starts, it has a | |
| 1313 normal malloc. Some thread implementations need this as they call | |
| 1314 malloc before main. The pthread_self call in BLOCK_INPUT_ALLOC then | |
| 1315 calls malloc because it is the first call, and we have an endless loop. */ | |
| 1316 | |
| 1317 void | |
| 1318 reset_malloc_hooks () | |
| 1319 { | |
| 1320 __free_hook = 0; | |
| 1321 __malloc_hook = 0; | |
| 1322 __realloc_hook = 0; | |
| 1323 } | |
| 1324 #endif /* HAVE_GTK_AND_PTHREAD */ | |
| 832 | 1325 |
| 833 | 1326 |
| 834 /* Called from main to set up malloc to use our hooks. */ | 1327 /* Called from main to set up malloc to use our hooks. */ |
| 835 | 1328 |
| 836 void | 1329 void |
| 837 uninterrupt_malloc () | 1330 uninterrupt_malloc () |
| 838 { | 1331 { |
| 1332 #ifdef HAVE_GTK_AND_PTHREAD | |
| 1333 pthread_mutexattr_t attr; | |
| 1334 | |
| 1335 /* GLIBC has a faster way to do this, but lets keep it portable. | |
| 1336 This is according to the Single UNIX Specification. */ | |
| 1337 pthread_mutexattr_init (&attr); | |
| 1338 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); | |
| 1339 pthread_mutex_init (&alloc_mutex, &attr); | |
| 1340 #endif /* HAVE_GTK_AND_PTHREAD */ | |
| 1341 | |
| 839 if (__free_hook != emacs_blocked_free) | 1342 if (__free_hook != emacs_blocked_free) |
| 840 old_free_hook = __free_hook; | 1343 old_free_hook = __free_hook; |
| 841 __free_hook = emacs_blocked_free; | 1344 __free_hook = emacs_blocked_free; |
| 842 | 1345 |
| 843 if (__malloc_hook != emacs_blocked_malloc) | 1346 if (__malloc_hook != emacs_blocked_malloc) |
| 847 if (__realloc_hook != emacs_blocked_realloc) | 1350 if (__realloc_hook != emacs_blocked_realloc) |
| 848 old_realloc_hook = __realloc_hook; | 1351 old_realloc_hook = __realloc_hook; |
| 849 __realloc_hook = emacs_blocked_realloc; | 1352 __realloc_hook = emacs_blocked_realloc; |
| 850 } | 1353 } |
| 851 | 1354 |
| 1355 #endif /* not SYNC_INPUT */ | |
| 852 #endif /* not SYSTEM_MALLOC */ | 1356 #endif /* not SYSTEM_MALLOC */ |
| 853 | 1357 |
| 854 | 1358 |
| 855 | 1359 |
| 856 /*********************************************************************** | 1360 /*********************************************************************** |
| 866 /* Intervals are allocated in chunks in form of an interval_block | 1370 /* Intervals are allocated in chunks in form of an interval_block |
| 867 structure. */ | 1371 structure. */ |
| 868 | 1372 |
| 869 struct interval_block | 1373 struct interval_block |
| 870 { | 1374 { |
| 1375 /* Place `intervals' first, to preserve alignment. */ | |
| 1376 struct interval intervals[INTERVAL_BLOCK_SIZE]; | |
| 871 struct interval_block *next; | 1377 struct interval_block *next; |
| 872 struct interval intervals[INTERVAL_BLOCK_SIZE]; | |
| 873 }; | 1378 }; |
| 874 | 1379 |
| 875 /* Current interval block. Its `next' pointer points to older | 1380 /* Current interval block. Its `next' pointer points to older |
| 876 blocks. */ | 1381 blocks. */ |
| 877 | 1382 |
| 898 /* Initialize interval allocation. */ | 1403 /* Initialize interval allocation. */ |
| 899 | 1404 |
| 900 static void | 1405 static void |
| 901 init_intervals () | 1406 init_intervals () |
| 902 { | 1407 { |
| 903 interval_block | 1408 interval_block = NULL; |
| 904 = (struct interval_block *) lisp_malloc (sizeof *interval_block, | 1409 interval_block_index = INTERVAL_BLOCK_SIZE; |
| 905 MEM_TYPE_NON_LISP); | |
| 906 interval_block->next = 0; | |
| 907 bzero ((char *) interval_block->intervals, sizeof interval_block->intervals); | |
| 908 interval_block_index = 0; | |
| 909 interval_free_list = 0; | 1410 interval_free_list = 0; |
| 910 n_interval_blocks = 1; | 1411 n_interval_blocks = 0; |
| 911 } | 1412 } |
| 912 | 1413 |
| 913 | 1414 |
| 914 /* Return a new interval. */ | 1415 /* Return a new interval. */ |
| 915 | 1416 |
| 930 register struct interval_block *newi; | 1431 register struct interval_block *newi; |
| 931 | 1432 |
| 932 newi = (struct interval_block *) lisp_malloc (sizeof *newi, | 1433 newi = (struct interval_block *) lisp_malloc (sizeof *newi, |
| 933 MEM_TYPE_NON_LISP); | 1434 MEM_TYPE_NON_LISP); |
| 934 | 1435 |
| 935 VALIDATE_LISP_STORAGE (newi, sizeof *newi); | |
| 936 newi->next = interval_block; | 1436 newi->next = interval_block; |
| 937 interval_block = newi; | 1437 interval_block = newi; |
| 938 interval_block_index = 0; | 1438 interval_block_index = 0; |
| 939 n_interval_blocks++; | 1439 n_interval_blocks++; |
| 940 } | 1440 } |
| 941 val = &interval_block->intervals[interval_block_index++]; | 1441 val = &interval_block->intervals[interval_block_index++]; |
| 942 } | 1442 } |
| 943 consing_since_gc += sizeof (struct interval); | 1443 consing_since_gc += sizeof (struct interval); |
| 944 intervals_consed++; | 1444 intervals_consed++; |
| 945 RESET_INTERVAL (val); | 1445 RESET_INTERVAL (val); |
| 1446 val->gcmarkbit = 0; | |
| 946 return val; | 1447 return val; |
| 947 } | 1448 } |
| 948 | 1449 |
| 949 | 1450 |
| 950 /* Mark Lisp objects in interval I. */ | 1451 /* Mark Lisp objects in interval I. */ |
| 952 static void | 1453 static void |
| 953 mark_interval (i, dummy) | 1454 mark_interval (i, dummy) |
| 954 register INTERVAL i; | 1455 register INTERVAL i; |
| 955 Lisp_Object dummy; | 1456 Lisp_Object dummy; |
| 956 { | 1457 { |
| 957 if (XMARKBIT (i->plist)) | 1458 eassert (!i->gcmarkbit); /* Intervals are never shared. */ |
| 958 abort (); | 1459 i->gcmarkbit = 1; |
| 959 mark_object (&i->plist); | 1460 mark_object (i->plist); |
| 960 XMARK (i->plist); | |
| 961 } | 1461 } |
| 962 | 1462 |
| 963 | 1463 |
| 964 /* Mark the interval tree rooted in TREE. Don't call this directly; | 1464 /* Mark the interval tree rooted in TREE. Don't call this directly; |
| 965 use the macro MARK_INTERVAL_TREE instead. */ | 1465 use the macro MARK_INTERVAL_TREE instead. */ |
| 970 { | 1470 { |
| 971 /* No need to test if this tree has been marked already; this | 1471 /* No need to test if this tree has been marked already; this |
| 972 function is always called through the MARK_INTERVAL_TREE macro, | 1472 function is always called through the MARK_INTERVAL_TREE macro, |
| 973 which takes care of that. */ | 1473 which takes care of that. */ |
| 974 | 1474 |
| 975 /* XMARK expands to an assignment; the LHS of an assignment can't be | |
| 976 a cast. */ | |
| 977 XMARK (tree->up.obj); | |
| 978 | |
| 979 traverse_intervals_noorder (tree, mark_interval, Qnil); | 1475 traverse_intervals_noorder (tree, mark_interval, Qnil); |
| 980 } | 1476 } |
| 981 | 1477 |
| 982 | 1478 |
| 983 /* Mark the interval tree rooted in I. */ | 1479 /* Mark the interval tree rooted in I. */ |
| 984 | 1480 |
| 985 #define MARK_INTERVAL_TREE(i) \ | 1481 #define MARK_INTERVAL_TREE(i) \ |
| 986 do { \ | 1482 do { \ |
| 987 if (!NULL_INTERVAL_P (i) \ | 1483 if (!NULL_INTERVAL_P (i) && !i->gcmarkbit) \ |
| 988 && ! XMARKBIT (i->up.obj)) \ | |
| 989 mark_interval_tree (i); \ | 1484 mark_interval_tree (i); \ |
| 990 } while (0) | 1485 } while (0) |
| 991 | 1486 |
| 992 | |
| 993 /* The oddity in the call to XUNMARK is necessary because XUNMARK | |
| 994 expands to an assignment to its argument, and most C compilers | |
| 995 don't support casts on the left operand of `='. */ | |
| 996 | 1487 |
| 997 #define UNMARK_BALANCE_INTERVALS(i) \ | 1488 #define UNMARK_BALANCE_INTERVALS(i) \ |
| 998 do { \ | 1489 do { \ |
| 999 if (! NULL_INTERVAL_P (i)) \ | 1490 if (! NULL_INTERVAL_P (i)) \ |
| 1000 { \ | 1491 (i) = balance_intervals (i); \ |
| 1001 XUNMARK ((i)->up.obj); \ | |
| 1002 (i) = balance_intervals (i); \ | |
| 1003 } \ | |
| 1004 } while (0) | 1492 } while (0) |
| 1005 | 1493 |
| 1006 | 1494 |
| 1007 /* Number support. If NO_UNION_TYPE isn't in effect, we | 1495 /* Number support. If NO_UNION_TYPE isn't in effect, we |
| 1008 can't create number objects in macros. */ | 1496 can't create number objects in macros. */ |
| 1009 #ifndef make_number | 1497 #ifndef make_number |
| 1010 Lisp_Object | 1498 Lisp_Object |
| 1011 make_number (n) | 1499 make_number (n) |
| 1012 int n; | 1500 EMACS_INT n; |
| 1013 { | 1501 { |
| 1014 Lisp_Object obj; | 1502 Lisp_Object obj; |
| 1015 obj.s.val = n; | 1503 obj.s.val = n; |
| 1016 obj.s.type = Lisp_Int; | 1504 obj.s.type = Lisp_Int; |
| 1017 return obj; | 1505 return obj; |
| 1114 }; | 1602 }; |
| 1115 | 1603 |
| 1116 /* Number of Lisp strings in a string_block structure. The 1020 is | 1604 /* Number of Lisp strings in a string_block structure. The 1020 is |
| 1117 1024 minus malloc overhead. */ | 1605 1024 minus malloc overhead. */ |
| 1118 | 1606 |
| 1119 #define STRINGS_IN_STRING_BLOCK \ | 1607 #define STRING_BLOCK_SIZE \ |
| 1120 ((1020 - sizeof (struct string_block *)) / sizeof (struct Lisp_String)) | 1608 ((1020 - sizeof (struct string_block *)) / sizeof (struct Lisp_String)) |
| 1121 | 1609 |
| 1122 /* Structure describing a block from which Lisp_String structures | 1610 /* Structure describing a block from which Lisp_String structures |
| 1123 are allocated. */ | 1611 are allocated. */ |
| 1124 | 1612 |
| 1125 struct string_block | 1613 struct string_block |
| 1126 { | 1614 { |
| 1615 /* Place `strings' first, to preserve alignment. */ | |
| 1616 struct Lisp_String strings[STRING_BLOCK_SIZE]; | |
| 1127 struct string_block *next; | 1617 struct string_block *next; |
| 1128 struct Lisp_String strings[STRINGS_IN_STRING_BLOCK]; | |
| 1129 }; | 1618 }; |
| 1130 | 1619 |
| 1131 /* Head and tail of the list of sblock structures holding Lisp string | 1620 /* Head and tail of the list of sblock structures holding Lisp string |
| 1132 data. We always allocate from current_sblock. The NEXT pointers | 1621 data. We always allocate from current_sblock. The NEXT pointers |
| 1133 in the sblock structures go from oldest_sblock to current_sblock. */ | 1622 in the sblock structures go from oldest_sblock to current_sblock. */ |
| 1176 | 1665 |
| 1177 #define SDATA_OF_STRING(S) \ | 1666 #define SDATA_OF_STRING(S) \ |
| 1178 ((struct sdata *) ((S)->data - sizeof (struct Lisp_String *))) | 1667 ((struct sdata *) ((S)->data - sizeof (struct Lisp_String *))) |
| 1179 | 1668 |
| 1180 #endif /* not GC_CHECK_STRING_BYTES */ | 1669 #endif /* not GC_CHECK_STRING_BYTES */ |
| 1670 | |
| 1671 | |
| 1672 #ifdef GC_CHECK_STRING_OVERRUN | |
| 1673 | |
| 1674 /* We check for overrun in string data blocks by appending a small | |
| 1675 "cookie" after each allocated string data block, and check for the | |
| 1676 presence of this cookie during GC. */ | |
| 1677 | |
| 1678 #define GC_STRING_OVERRUN_COOKIE_SIZE 4 | |
| 1679 static char string_overrun_cookie[GC_STRING_OVERRUN_COOKIE_SIZE] = | |
| 1680 { 0xde, 0xad, 0xbe, 0xef }; | |
| 1681 | |
| 1682 #else | |
| 1683 #define GC_STRING_OVERRUN_COOKIE_SIZE 0 | |
| 1684 #endif | |
| 1181 | 1685 |
| 1182 /* Value is the size of an sdata structure large enough to hold NBYTES | 1686 /* Value is the size of an sdata structure large enough to hold NBYTES |
| 1183 bytes of string data. The value returned includes a terminating | 1687 bytes of string data. The value returned includes a terminating |
| 1184 NUL byte, the size of the sdata structure, and padding. */ | 1688 NUL byte, the size of the sdata structure, and padding. */ |
| 1185 | 1689 |
| 1200 + sizeof (EMACS_INT) - 1) \ | 1704 + sizeof (EMACS_INT) - 1) \ |
| 1201 & ~(sizeof (EMACS_INT) - 1)) | 1705 & ~(sizeof (EMACS_INT) - 1)) |
| 1202 | 1706 |
| 1203 #endif /* not GC_CHECK_STRING_BYTES */ | 1707 #endif /* not GC_CHECK_STRING_BYTES */ |
| 1204 | 1708 |
| 1709 /* Extra bytes to allocate for each string. */ | |
| 1710 | |
| 1711 #define GC_STRING_EXTRA (GC_STRING_OVERRUN_COOKIE_SIZE) | |
| 1712 | |
| 1205 /* Initialize string allocation. Called from init_alloc_once. */ | 1713 /* Initialize string allocation. Called from init_alloc_once. */ |
| 1206 | 1714 |
| 1207 void | 1715 void |
| 1208 init_strings () | 1716 init_strings () |
| 1209 { | 1717 { |
| 1229 | 1737 |
| 1230 int | 1738 int |
| 1231 string_bytes (s) | 1739 string_bytes (s) |
| 1232 struct Lisp_String *s; | 1740 struct Lisp_String *s; |
| 1233 { | 1741 { |
| 1234 int nbytes = (s->size_byte < 0 ? s->size : s->size_byte) & ~MARKBIT; | 1742 int nbytes = (s->size_byte < 0 ? s->size & ~ARRAY_MARK_FLAG : s->size_byte); |
| 1235 if (!PURE_POINTER_P (s) | 1743 if (!PURE_POINTER_P (s) |
| 1236 && s->data | 1744 && s->data |
| 1237 && nbytes != SDATA_NBYTES (SDATA_OF_STRING (s))) | 1745 && nbytes != SDATA_NBYTES (SDATA_OF_STRING (s))) |
| 1238 abort (); | 1746 abort (); |
| 1239 return nbytes; | 1747 return nbytes; |
| 1264 nbytes = GC_STRING_BYTES (from->string); | 1772 nbytes = GC_STRING_BYTES (from->string); |
| 1265 else | 1773 else |
| 1266 nbytes = SDATA_NBYTES (from); | 1774 nbytes = SDATA_NBYTES (from); |
| 1267 | 1775 |
| 1268 nbytes = SDATA_SIZE (nbytes); | 1776 nbytes = SDATA_SIZE (nbytes); |
| 1269 from_end = (struct sdata *) ((char *) from + nbytes); | 1777 from_end = (struct sdata *) ((char *) from + nbytes + GC_STRING_EXTRA); |
| 1270 } | 1778 } |
| 1271 } | 1779 } |
| 1272 | 1780 |
| 1273 | 1781 |
| 1274 /* Check validity of Lisp strings' string_bytes member. ALL_P | 1782 /* Check validity of Lisp strings' string_bytes member. ALL_P |
| 1297 check_sblock (current_sblock); | 1805 check_sblock (current_sblock); |
| 1298 } | 1806 } |
| 1299 | 1807 |
| 1300 #endif /* GC_CHECK_STRING_BYTES */ | 1808 #endif /* GC_CHECK_STRING_BYTES */ |
| 1301 | 1809 |
| 1810 #ifdef GC_CHECK_STRING_FREE_LIST | |
| 1811 | |
| 1812 /* Walk through the string free list looking for bogus next pointers. | |
| 1813 This may catch buffer overrun from a previous string. */ | |
| 1814 | |
| 1815 static void | |
| 1816 check_string_free_list () | |
| 1817 { | |
| 1818 struct Lisp_String *s; | |
| 1819 | |
| 1820 /* Pop a Lisp_String off the free-list. */ | |
| 1821 s = string_free_list; | |
| 1822 while (s != NULL) | |
| 1823 { | |
| 1824 if ((unsigned)s < 1024) | |
| 1825 abort(); | |
| 1826 s = NEXT_FREE_LISP_STRING (s); | |
| 1827 } | |
| 1828 } | |
| 1829 #else | |
| 1830 #define check_string_free_list() | |
| 1831 #endif | |
| 1302 | 1832 |
| 1303 /* Return a new Lisp_String. */ | 1833 /* Return a new Lisp_String. */ |
| 1304 | 1834 |
| 1305 static struct Lisp_String * | 1835 static struct Lisp_String * |
| 1306 allocate_string () | 1836 allocate_string () |
| 1313 { | 1843 { |
| 1314 struct string_block *b; | 1844 struct string_block *b; |
| 1315 int i; | 1845 int i; |
| 1316 | 1846 |
| 1317 b = (struct string_block *) lisp_malloc (sizeof *b, MEM_TYPE_STRING); | 1847 b = (struct string_block *) lisp_malloc (sizeof *b, MEM_TYPE_STRING); |
| 1318 VALIDATE_LISP_STORAGE (b, sizeof *b); | |
| 1319 bzero (b, sizeof *b); | 1848 bzero (b, sizeof *b); |
| 1320 b->next = string_blocks; | 1849 b->next = string_blocks; |
| 1321 string_blocks = b; | 1850 string_blocks = b; |
| 1322 ++n_string_blocks; | 1851 ++n_string_blocks; |
| 1323 | 1852 |
| 1324 for (i = STRINGS_IN_STRING_BLOCK - 1; i >= 0; --i) | 1853 for (i = STRING_BLOCK_SIZE - 1; i >= 0; --i) |
| 1325 { | 1854 { |
| 1326 s = b->strings + i; | 1855 s = b->strings + i; |
| 1327 NEXT_FREE_LISP_STRING (s) = string_free_list; | 1856 NEXT_FREE_LISP_STRING (s) = string_free_list; |
| 1328 string_free_list = s; | 1857 string_free_list = s; |
| 1329 } | 1858 } |
| 1330 | 1859 |
| 1331 total_free_strings += STRINGS_IN_STRING_BLOCK; | 1860 total_free_strings += STRING_BLOCK_SIZE; |
| 1332 } | 1861 } |
| 1862 | |
| 1863 check_string_free_list (); | |
| 1333 | 1864 |
| 1334 /* Pop a Lisp_String off the free-list. */ | 1865 /* Pop a Lisp_String off the free-list. */ |
| 1335 s = string_free_list; | 1866 s = string_free_list; |
| 1336 string_free_list = NEXT_FREE_LISP_STRING (s); | 1867 string_free_list = NEXT_FREE_LISP_STRING (s); |
| 1337 | 1868 |
| 1388 size_t size = sizeof *b - sizeof (struct sdata) + needed; | 1919 size_t size = sizeof *b - sizeof (struct sdata) + needed; |
| 1389 | 1920 |
| 1390 #ifdef DOUG_LEA_MALLOC | 1921 #ifdef DOUG_LEA_MALLOC |
| 1391 /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed | 1922 /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed |
| 1392 because mapped region contents are not preserved in | 1923 because mapped region contents are not preserved in |
| 1393 a dumped Emacs. */ | 1924 a dumped Emacs. |
| 1925 | |
| 1926 In case you think of allowing it in a dumped Emacs at the | |
| 1927 cost of not being able to re-dump, there's another reason: | |
| 1928 mmap'ed data typically have an address towards the top of the | |
| 1929 address space, which won't fit into an EMACS_INT (at least on | |
| 1930 32-bit systems with the current tagging scheme). --fx */ | |
| 1931 BLOCK_INPUT; | |
| 1394 mallopt (M_MMAP_MAX, 0); | 1932 mallopt (M_MMAP_MAX, 0); |
| 1395 #endif | 1933 UNBLOCK_INPUT; |
| 1396 | 1934 #endif |
| 1397 b = (struct sblock *) lisp_malloc (size, MEM_TYPE_NON_LISP); | 1935 |
| 1936 b = (struct sblock *) lisp_malloc (size + GC_STRING_EXTRA, MEM_TYPE_NON_LISP); | |
| 1398 | 1937 |
| 1399 #ifdef DOUG_LEA_MALLOC | 1938 #ifdef DOUG_LEA_MALLOC |
| 1400 /* Back to a reasonable maximum of mmap'ed areas. */ | 1939 /* Back to a reasonable maximum of mmap'ed areas. */ |
| 1940 BLOCK_INPUT; | |
| 1401 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); | 1941 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); |
| 1942 UNBLOCK_INPUT; | |
| 1402 #endif | 1943 #endif |
| 1403 | 1944 |
| 1404 b->next_free = &b->first_data; | 1945 b->next_free = &b->first_data; |
| 1405 b->first_data.string = NULL; | 1946 b->first_data.string = NULL; |
| 1406 b->next = large_sblocks; | 1947 b->next = large_sblocks; |
| 1407 large_sblocks = b; | 1948 large_sblocks = b; |
| 1408 } | 1949 } |
| 1409 else if (current_sblock == NULL | 1950 else if (current_sblock == NULL |
| 1410 || (((char *) current_sblock + SBLOCK_SIZE | 1951 || (((char *) current_sblock + SBLOCK_SIZE |
| 1411 - (char *) current_sblock->next_free) | 1952 - (char *) current_sblock->next_free) |
| 1412 < needed)) | 1953 < (needed + GC_STRING_EXTRA))) |
| 1413 { | 1954 { |
| 1414 /* Not enough room in the current sblock. */ | 1955 /* Not enough room in the current sblock. */ |
| 1415 b = (struct sblock *) lisp_malloc (SBLOCK_SIZE, MEM_TYPE_NON_LISP); | 1956 b = (struct sblock *) lisp_malloc (SBLOCK_SIZE, MEM_TYPE_NON_LISP); |
| 1416 b->next_free = &b->first_data; | 1957 b->next_free = &b->first_data; |
| 1417 b->first_data.string = NULL; | 1958 b->first_data.string = NULL; |
| 1436 SDATA_NBYTES (data) = nbytes; | 1977 SDATA_NBYTES (data) = nbytes; |
| 1437 #endif | 1978 #endif |
| 1438 s->size = nchars; | 1979 s->size = nchars; |
| 1439 s->size_byte = nbytes; | 1980 s->size_byte = nbytes; |
| 1440 s->data[nbytes] = '\0'; | 1981 s->data[nbytes] = '\0'; |
| 1441 b->next_free = (struct sdata *) ((char *) data + needed); | 1982 #ifdef GC_CHECK_STRING_OVERRUN |
| 1983 bcopy (string_overrun_cookie, (char *) data + needed, | |
| 1984 GC_STRING_OVERRUN_COOKIE_SIZE); | |
| 1985 #endif | |
| 1986 b->next_free = (struct sdata *) ((char *) data + needed + GC_STRING_EXTRA); | |
| 1442 | 1987 |
| 1443 /* If S had already data assigned, mark that as free by setting its | 1988 /* If S had already data assigned, mark that as free by setting its |
| 1444 string back-pointer to null, and recording the size of the data | 1989 string back-pointer to null, and recording the size of the data |
| 1445 in it. */ | 1990 in it. */ |
| 1446 if (old_data) | 1991 if (old_data) |
| 1471 int i, nfree = 0; | 2016 int i, nfree = 0; |
| 1472 struct Lisp_String *free_list_before = string_free_list; | 2017 struct Lisp_String *free_list_before = string_free_list; |
| 1473 | 2018 |
| 1474 next = b->next; | 2019 next = b->next; |
| 1475 | 2020 |
| 1476 for (i = 0; i < STRINGS_IN_STRING_BLOCK; ++i) | 2021 for (i = 0; i < STRING_BLOCK_SIZE; ++i) |
| 1477 { | 2022 { |
| 1478 struct Lisp_String *s = b->strings + i; | 2023 struct Lisp_String *s = b->strings + i; |
| 1479 | 2024 |
| 1480 if (s->data) | 2025 if (s->data) |
| 1481 { | 2026 { |
| 1526 } | 2071 } |
| 1527 } | 2072 } |
| 1528 | 2073 |
| 1529 /* Free blocks that contain free Lisp_Strings only, except | 2074 /* Free blocks that contain free Lisp_Strings only, except |
| 1530 the first two of them. */ | 2075 the first two of them. */ |
| 1531 if (nfree == STRINGS_IN_STRING_BLOCK | 2076 if (nfree == STRING_BLOCK_SIZE |
| 1532 && total_free_strings > STRINGS_IN_STRING_BLOCK) | 2077 && total_free_strings > STRING_BLOCK_SIZE) |
| 1533 { | 2078 { |
| 1534 lisp_free (b); | 2079 lisp_free (b); |
| 1535 --n_string_blocks; | 2080 --n_string_blocks; |
| 1536 string_free_list = free_list_before; | 2081 string_free_list = free_list_before; |
| 1537 } | 2082 } |
| 1541 b->next = live_blocks; | 2086 b->next = live_blocks; |
| 1542 live_blocks = b; | 2087 live_blocks = b; |
| 1543 } | 2088 } |
| 1544 } | 2089 } |
| 1545 | 2090 |
| 2091 check_string_free_list (); | |
| 2092 | |
| 1546 string_blocks = live_blocks; | 2093 string_blocks = live_blocks; |
| 1547 free_large_strings (); | 2094 free_large_strings (); |
| 1548 compact_small_strings (); | 2095 compact_small_strings (); |
| 2096 | |
| 2097 check_string_free_list (); | |
| 1549 } | 2098 } |
| 1550 | 2099 |
| 1551 | 2100 |
| 1552 /* Free dead large strings. */ | 2101 /* Free dead large strings. */ |
| 1553 | 2102 |
| 1615 if (from->string) | 2164 if (from->string) |
| 1616 nbytes = GC_STRING_BYTES (from->string); | 2165 nbytes = GC_STRING_BYTES (from->string); |
| 1617 else | 2166 else |
| 1618 nbytes = SDATA_NBYTES (from); | 2167 nbytes = SDATA_NBYTES (from); |
| 1619 | 2168 |
| 2169 if (nbytes > LARGE_STRING_BYTES) | |
| 2170 abort (); | |
| 2171 | |
| 1620 nbytes = SDATA_SIZE (nbytes); | 2172 nbytes = SDATA_SIZE (nbytes); |
| 1621 from_end = (struct sdata *) ((char *) from + nbytes); | 2173 from_end = (struct sdata *) ((char *) from + nbytes + GC_STRING_EXTRA); |
| 2174 | |
| 2175 #ifdef GC_CHECK_STRING_OVERRUN | |
| 2176 if (bcmp (string_overrun_cookie, | |
| 2177 ((char *) from_end) - GC_STRING_OVERRUN_COOKIE_SIZE, | |
| 2178 GC_STRING_OVERRUN_COOKIE_SIZE)) | |
| 2179 abort (); | |
| 2180 #endif | |
| 1622 | 2181 |
| 1623 /* FROM->string non-null means it's alive. Copy its data. */ | 2182 /* FROM->string non-null means it's alive. Copy its data. */ |
| 1624 if (from->string) | 2183 if (from->string) |
| 1625 { | 2184 { |
| 1626 /* If TB is full, proceed with the next sblock. */ | 2185 /* If TB is full, proceed with the next sblock. */ |
| 1627 to_end = (struct sdata *) ((char *) to + nbytes); | 2186 to_end = (struct sdata *) ((char *) to + nbytes + GC_STRING_EXTRA); |
| 1628 if (to_end > tb_end) | 2187 if (to_end > tb_end) |
| 1629 { | 2188 { |
| 1630 tb->next_free = to; | 2189 tb->next_free = to; |
| 1631 tb = tb->next; | 2190 tb = tb->next; |
| 1632 tb_end = (struct sdata *) ((char *) tb + SBLOCK_SIZE); | 2191 tb_end = (struct sdata *) ((char *) tb + SBLOCK_SIZE); |
| 1633 to = &tb->first_data; | 2192 to = &tb->first_data; |
| 1634 to_end = (struct sdata *) ((char *) to + nbytes); | 2193 to_end = (struct sdata *) ((char *) to + nbytes + GC_STRING_EXTRA); |
| 1635 } | 2194 } |
| 1636 | 2195 |
| 1637 /* Copy, and update the string's `data' pointer. */ | 2196 /* Copy, and update the string's `data' pointer. */ |
| 1638 if (from != to) | 2197 if (from != to) |
| 1639 { | 2198 { |
| 1640 xassert (tb != b || to <= from); | 2199 xassert (tb != b || to <= from); |
| 1641 safe_bcopy ((char *) from, (char *) to, nbytes); | 2200 safe_bcopy ((char *) from, (char *) to, nbytes + GC_STRING_EXTRA); |
| 1642 to->string->data = SDATA_DATA (to); | 2201 to->string->data = SDATA_DATA (to); |
| 1643 } | 2202 } |
| 1644 | 2203 |
| 1645 /* Advance past the sdata we copied to. */ | 2204 /* Advance past the sdata we copied to. */ |
| 1646 to = to_end; | 2205 to = to_end; |
| 1661 current_sblock = tb; | 2220 current_sblock = tb; |
| 1662 } | 2221 } |
| 1663 | 2222 |
| 1664 | 2223 |
| 1665 DEFUN ("make-string", Fmake_string, Smake_string, 2, 2, 0, | 2224 DEFUN ("make-string", Fmake_string, Smake_string, 2, 2, 0, |
| 1666 doc: /* Return a newly created string of length LENGTH, with each element being INIT. | 2225 doc: /* Return a newly created string of length LENGTH, with INIT in each element. |
| 1667 Both LENGTH and INIT must be numbers. */) | 2226 LENGTH must be an integer. |
| 2227 INIT must be an integer that represents a character. */) | |
| 1668 (length, init) | 2228 (length, init) |
| 1669 Lisp_Object length, init; | 2229 Lisp_Object length, init; |
| 1670 { | 2230 { |
| 1671 register Lisp_Object val; | 2231 register Lisp_Object val; |
| 1672 register unsigned char *p, *end; | 2232 register unsigned char *p, *end; |
| 1717 int real_init, i; | 2277 int real_init, i; |
| 1718 int length_in_chars, length_in_elts, bits_per_value; | 2278 int length_in_chars, length_in_elts, bits_per_value; |
| 1719 | 2279 |
| 1720 CHECK_NATNUM (length); | 2280 CHECK_NATNUM (length); |
| 1721 | 2281 |
| 1722 bits_per_value = sizeof (EMACS_INT) * BITS_PER_CHAR; | 2282 bits_per_value = sizeof (EMACS_INT) * BOOL_VECTOR_BITS_PER_CHAR; |
| 1723 | 2283 |
| 1724 length_in_elts = (XFASTINT (length) + bits_per_value - 1) / bits_per_value; | 2284 length_in_elts = (XFASTINT (length) + bits_per_value - 1) / bits_per_value; |
| 1725 length_in_chars = ((XFASTINT (length) + BITS_PER_CHAR - 1) / BITS_PER_CHAR); | 2285 length_in_chars = ((XFASTINT (length) + BOOL_VECTOR_BITS_PER_CHAR - 1) |
| 2286 / BOOL_VECTOR_BITS_PER_CHAR); | |
| 1726 | 2287 |
| 1727 /* We must allocate one more elements than LENGTH_IN_ELTS for the | 2288 /* We must allocate one more elements than LENGTH_IN_ELTS for the |
| 1728 slot `size' of the struct Lisp_Bool_Vector. */ | 2289 slot `size' of the struct Lisp_Bool_Vector. */ |
| 1729 val = Fmake_vector (make_number (length_in_elts + 1), Qnil); | 2290 val = Fmake_vector (make_number (length_in_elts + 1), Qnil); |
| 1730 p = XBOOL_VECTOR (val); | 2291 p = XBOOL_VECTOR (val); |
| 1737 real_init = (NILP (init) ? 0 : -1); | 2298 real_init = (NILP (init) ? 0 : -1); |
| 1738 for (i = 0; i < length_in_chars ; i++) | 2299 for (i = 0; i < length_in_chars ; i++) |
| 1739 p->data[i] = real_init; | 2300 p->data[i] = real_init; |
| 1740 | 2301 |
| 1741 /* Clear the extraneous bits in the last byte. */ | 2302 /* Clear the extraneous bits in the last byte. */ |
| 1742 if (XINT (length) != length_in_chars * BITS_PER_CHAR) | 2303 if (XINT (length) != length_in_chars * BOOL_VECTOR_BITS_PER_CHAR) |
| 1743 XBOOL_VECTOR (val)->data[length_in_chars - 1] | 2304 XBOOL_VECTOR (val)->data[length_in_chars - 1] |
| 1744 &= (1 << (XINT (length) % BITS_PER_CHAR)) - 1; | 2305 &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1; |
| 1745 | 2306 |
| 1746 return val; | 2307 return val; |
| 1747 } | 2308 } |
| 1748 | 2309 |
| 1749 | 2310 |
| 1803 /* Make a string from NCHARS characters occupying NBYTES bytes at | 2364 /* Make a string from NCHARS characters occupying NBYTES bytes at |
| 1804 CONTENTS. It is a multibyte string if NBYTES != NCHARS. */ | 2365 CONTENTS. It is a multibyte string if NBYTES != NCHARS. */ |
| 1805 | 2366 |
| 1806 Lisp_Object | 2367 Lisp_Object |
| 1807 make_string_from_bytes (contents, nchars, nbytes) | 2368 make_string_from_bytes (contents, nchars, nbytes) |
| 1808 char *contents; | 2369 const char *contents; |
| 1809 int nchars, nbytes; | 2370 int nchars, nbytes; |
| 1810 { | 2371 { |
| 1811 register Lisp_Object val; | 2372 register Lisp_Object val; |
| 1812 val = make_uninit_multibyte_string (nchars, nbytes); | 2373 val = make_uninit_multibyte_string (nchars, nbytes); |
| 1813 bcopy (contents, SDATA (val), nbytes); | 2374 bcopy (contents, SDATA (val), nbytes); |
| 1817 } | 2378 } |
| 1818 | 2379 |
| 1819 | 2380 |
| 1820 /* Make a string from NCHARS characters occupying NBYTES bytes at | 2381 /* Make a string from NCHARS characters occupying NBYTES bytes at |
| 1821 CONTENTS. The argument MULTIBYTE controls whether to label the | 2382 CONTENTS. The argument MULTIBYTE controls whether to label the |
| 1822 string as multibyte. */ | 2383 string as multibyte. If NCHARS is negative, it counts the number of |
| 2384 characters by itself. */ | |
| 1823 | 2385 |
| 1824 Lisp_Object | 2386 Lisp_Object |
| 1825 make_specified_string (contents, nchars, nbytes, multibyte) | 2387 make_specified_string (contents, nchars, nbytes, multibyte) |
| 1826 char *contents; | 2388 const char *contents; |
| 1827 int nchars, nbytes; | 2389 int nchars, nbytes; |
| 1828 int multibyte; | 2390 int multibyte; |
| 1829 { | 2391 { |
| 1830 register Lisp_Object val; | 2392 register Lisp_Object val; |
| 2393 | |
| 2394 if (nchars < 0) | |
| 2395 { | |
| 2396 if (multibyte) | |
| 2397 nchars = multibyte_chars_in_text (contents, nbytes); | |
| 2398 else | |
| 2399 nchars = nbytes; | |
| 2400 } | |
| 1831 val = make_uninit_multibyte_string (nchars, nbytes); | 2401 val = make_uninit_multibyte_string (nchars, nbytes); |
| 1832 bcopy (contents, SDATA (val), nbytes); | 2402 bcopy (contents, SDATA (val), nbytes); |
| 1833 if (!multibyte) | 2403 if (!multibyte) |
| 1834 STRING_SET_UNIBYTE (val); | 2404 STRING_SET_UNIBYTE (val); |
| 1835 return val; | 2405 return val; |
| 1888 ***********************************************************************/ | 2458 ***********************************************************************/ |
| 1889 | 2459 |
| 1890 /* We store float cells inside of float_blocks, allocating a new | 2460 /* We store float cells inside of float_blocks, allocating a new |
| 1891 float_block with malloc whenever necessary. Float cells reclaimed | 2461 float_block with malloc whenever necessary. Float cells reclaimed |
| 1892 by GC are put on a free list to be reallocated before allocating | 2462 by GC are put on a free list to be reallocated before allocating |
| 1893 any new float cells from the latest float_block. | 2463 any new float cells from the latest float_block. */ |
| 1894 | 2464 |
| 1895 Each float_block is just under 1020 bytes long, since malloc really | 2465 #define FLOAT_BLOCK_SIZE \ |
| 1896 allocates in units of powers of two and uses 4 bytes for its own | 2466 (((BLOCK_BYTES - sizeof (struct float_block *) \ |
| 1897 overhead. */ | 2467 /* The compiler might add padding at the end. */ \ |
| 1898 | 2468 - (sizeof (struct Lisp_Float) - sizeof (int))) * CHAR_BIT) \ |
| 1899 #define FLOAT_BLOCK_SIZE \ | 2469 / (sizeof (struct Lisp_Float) * CHAR_BIT + 1)) |
| 1900 ((1020 - sizeof (struct float_block *)) / sizeof (struct Lisp_Float)) | 2470 |
| 2471 #define GETMARKBIT(block,n) \ | |
| 2472 (((block)->gcmarkbits[(n) / (sizeof(int) * CHAR_BIT)] \ | |
| 2473 >> ((n) % (sizeof(int) * CHAR_BIT))) \ | |
| 2474 & 1) | |
| 2475 | |
| 2476 #define SETMARKBIT(block,n) \ | |
| 2477 (block)->gcmarkbits[(n) / (sizeof(int) * CHAR_BIT)] \ | |
| 2478 |= 1 << ((n) % (sizeof(int) * CHAR_BIT)) | |
| 2479 | |
| 2480 #define UNSETMARKBIT(block,n) \ | |
| 2481 (block)->gcmarkbits[(n) / (sizeof(int) * CHAR_BIT)] \ | |
| 2482 &= ~(1 << ((n) % (sizeof(int) * CHAR_BIT))) | |
| 2483 | |
| 2484 #define FLOAT_BLOCK(fptr) \ | |
| 2485 ((struct float_block *)(((EMACS_UINT)(fptr)) & ~(BLOCK_ALIGN - 1))) | |
| 2486 | |
| 2487 #define FLOAT_INDEX(fptr) \ | |
| 2488 ((((EMACS_UINT)(fptr)) & (BLOCK_ALIGN - 1)) / sizeof (struct Lisp_Float)) | |
| 1901 | 2489 |
| 1902 struct float_block | 2490 struct float_block |
| 1903 { | 2491 { |
| 2492 /* Place `floats' at the beginning, to ease up FLOAT_INDEX's job. */ | |
| 2493 struct Lisp_Float floats[FLOAT_BLOCK_SIZE]; | |
| 2494 int gcmarkbits[1 + FLOAT_BLOCK_SIZE / (sizeof(int) * CHAR_BIT)]; | |
| 1904 struct float_block *next; | 2495 struct float_block *next; |
| 1905 struct Lisp_Float floats[FLOAT_BLOCK_SIZE]; | |
| 1906 }; | 2496 }; |
| 2497 | |
| 2498 #define FLOAT_MARKED_P(fptr) \ | |
| 2499 GETMARKBIT (FLOAT_BLOCK (fptr), FLOAT_INDEX ((fptr))) | |
| 2500 | |
| 2501 #define FLOAT_MARK(fptr) \ | |
| 2502 SETMARKBIT (FLOAT_BLOCK (fptr), FLOAT_INDEX ((fptr))) | |
| 2503 | |
| 2504 #define FLOAT_UNMARK(fptr) \ | |
| 2505 UNSETMARKBIT (FLOAT_BLOCK (fptr), FLOAT_INDEX ((fptr))) | |
| 1907 | 2506 |
| 1908 /* Current float_block. */ | 2507 /* Current float_block. */ |
| 1909 | 2508 |
| 1910 struct float_block *float_block; | 2509 struct float_block *float_block; |
| 1911 | 2510 |
| 1925 /* Initialize float allocation. */ | 2524 /* Initialize float allocation. */ |
| 1926 | 2525 |
| 1927 void | 2526 void |
| 1928 init_float () | 2527 init_float () |
| 1929 { | 2528 { |
| 1930 float_block = (struct float_block *) lisp_malloc (sizeof *float_block, | 2529 float_block = NULL; |
| 1931 MEM_TYPE_FLOAT); | 2530 float_block_index = FLOAT_BLOCK_SIZE; /* Force alloc of new float_block. */ |
| 1932 float_block->next = 0; | |
| 1933 bzero ((char *) float_block->floats, sizeof float_block->floats); | |
| 1934 float_block_index = 0; | |
| 1935 float_free_list = 0; | 2531 float_free_list = 0; |
| 1936 n_float_blocks = 1; | 2532 n_float_blocks = 0; |
| 1937 } | 2533 } |
| 1938 | 2534 |
| 1939 | 2535 |
| 1940 /* Explicitly free a float cell by putting it on the free-list. */ | 2536 /* Explicitly free a float cell by putting it on the free-list. */ |
| 1941 | 2537 |
| 1942 void | 2538 void |
| 1943 free_float (ptr) | 2539 free_float (ptr) |
| 1944 struct Lisp_Float *ptr; | 2540 struct Lisp_Float *ptr; |
| 1945 { | 2541 { |
| 1946 *(struct Lisp_Float **)&ptr->data = float_free_list; | 2542 ptr->u.chain = float_free_list; |
| 1947 #if GC_MARK_STACK | |
| 1948 ptr->type = Vdead; | |
| 1949 #endif | |
| 1950 float_free_list = ptr; | 2543 float_free_list = ptr; |
| 1951 } | 2544 } |
| 1952 | 2545 |
| 1953 | 2546 |
| 1954 /* Return a new float object with value FLOAT_VALUE. */ | 2547 /* Return a new float object with value FLOAT_VALUE. */ |
| 1962 if (float_free_list) | 2555 if (float_free_list) |
| 1963 { | 2556 { |
| 1964 /* We use the data field for chaining the free list | 2557 /* We use the data field for chaining the free list |
| 1965 so that we won't use the same field that has the mark bit. */ | 2558 so that we won't use the same field that has the mark bit. */ |
| 1966 XSETFLOAT (val, float_free_list); | 2559 XSETFLOAT (val, float_free_list); |
| 1967 float_free_list = *(struct Lisp_Float **)&float_free_list->data; | 2560 float_free_list = float_free_list->u.chain; |
| 1968 } | 2561 } |
| 1969 else | 2562 else |
| 1970 { | 2563 { |
| 1971 if (float_block_index == FLOAT_BLOCK_SIZE) | 2564 if (float_block_index == FLOAT_BLOCK_SIZE) |
| 1972 { | 2565 { |
| 1973 register struct float_block *new; | 2566 register struct float_block *new; |
| 1974 | 2567 |
| 1975 new = (struct float_block *) lisp_malloc (sizeof *new, | 2568 new = (struct float_block *) lisp_align_malloc (sizeof *new, |
| 1976 MEM_TYPE_FLOAT); | 2569 MEM_TYPE_FLOAT); |
| 1977 VALIDATE_LISP_STORAGE (new, sizeof *new); | |
| 1978 new->next = float_block; | 2570 new->next = float_block; |
| 2571 bzero ((char *) new->gcmarkbits, sizeof new->gcmarkbits); | |
| 1979 float_block = new; | 2572 float_block = new; |
| 1980 float_block_index = 0; | 2573 float_block_index = 0; |
| 1981 n_float_blocks++; | 2574 n_float_blocks++; |
| 1982 } | 2575 } |
| 1983 XSETFLOAT (val, &float_block->floats[float_block_index++]); | 2576 XSETFLOAT (val, &float_block->floats[float_block_index]); |
| 2577 float_block_index++; | |
| 1984 } | 2578 } |
| 1985 | 2579 |
| 1986 XFLOAT_DATA (val) = float_value; | 2580 XFLOAT_DATA (val) = float_value; |
| 1987 XSETFASTINT (XFLOAT (val)->type, 0); /* bug chasing -wsr */ | 2581 eassert (!FLOAT_MARKED_P (XFLOAT (val))); |
| 1988 consing_since_gc += sizeof (struct Lisp_Float); | 2582 consing_since_gc += sizeof (struct Lisp_Float); |
| 1989 floats_consed++; | 2583 floats_consed++; |
| 1990 return val; | 2584 return val; |
| 1991 } | 2585 } |
| 1992 | 2586 |
| 1997 ***********************************************************************/ | 2591 ***********************************************************************/ |
| 1998 | 2592 |
| 1999 /* We store cons cells inside of cons_blocks, allocating a new | 2593 /* We store cons cells inside of cons_blocks, allocating a new |
| 2000 cons_block with malloc whenever necessary. Cons cells reclaimed by | 2594 cons_block with malloc whenever necessary. Cons cells reclaimed by |
| 2001 GC are put on a free list to be reallocated before allocating | 2595 GC are put on a free list to be reallocated before allocating |
| 2002 any new cons cells from the latest cons_block. | 2596 any new cons cells from the latest cons_block. */ |
| 2003 | |
| 2004 Each cons_block is just under 1020 bytes long, | |
| 2005 since malloc really allocates in units of powers of two | |
| 2006 and uses 4 bytes for its own overhead. */ | |
| 2007 | 2597 |
| 2008 #define CONS_BLOCK_SIZE \ | 2598 #define CONS_BLOCK_SIZE \ |
| 2009 ((1020 - sizeof (struct cons_block *)) / sizeof (struct Lisp_Cons)) | 2599 (((BLOCK_BYTES - sizeof (struct cons_block *)) * CHAR_BIT) \ |
| 2600 / (sizeof (struct Lisp_Cons) * CHAR_BIT + 1)) | |
| 2601 | |
| 2602 #define CONS_BLOCK(fptr) \ | |
| 2603 ((struct cons_block *)(((EMACS_UINT)(fptr)) & ~(BLOCK_ALIGN - 1))) | |
| 2604 | |
| 2605 #define CONS_INDEX(fptr) \ | |
| 2606 ((((EMACS_UINT)(fptr)) & (BLOCK_ALIGN - 1)) / sizeof (struct Lisp_Cons)) | |
| 2010 | 2607 |
| 2011 struct cons_block | 2608 struct cons_block |
| 2012 { | 2609 { |
| 2610 /* Place `conses' at the beginning, to ease up CONS_INDEX's job. */ | |
| 2611 struct Lisp_Cons conses[CONS_BLOCK_SIZE]; | |
| 2612 int gcmarkbits[1 + CONS_BLOCK_SIZE / (sizeof(int) * CHAR_BIT)]; | |
| 2013 struct cons_block *next; | 2613 struct cons_block *next; |
| 2014 struct Lisp_Cons conses[CONS_BLOCK_SIZE]; | |
| 2015 }; | 2614 }; |
| 2615 | |
| 2616 #define CONS_MARKED_P(fptr) \ | |
| 2617 GETMARKBIT (CONS_BLOCK (fptr), CONS_INDEX ((fptr))) | |
| 2618 | |
| 2619 #define CONS_MARK(fptr) \ | |
| 2620 SETMARKBIT (CONS_BLOCK (fptr), CONS_INDEX ((fptr))) | |
| 2621 | |
| 2622 #define CONS_UNMARK(fptr) \ | |
| 2623 UNSETMARKBIT (CONS_BLOCK (fptr), CONS_INDEX ((fptr))) | |
| 2016 | 2624 |
| 2017 /* Current cons_block. */ | 2625 /* Current cons_block. */ |
| 2018 | 2626 |
| 2019 struct cons_block *cons_block; | 2627 struct cons_block *cons_block; |
| 2020 | 2628 |
| 2034 /* Initialize cons allocation. */ | 2642 /* Initialize cons allocation. */ |
| 2035 | 2643 |
| 2036 void | 2644 void |
| 2037 init_cons () | 2645 init_cons () |
| 2038 { | 2646 { |
| 2039 cons_block = (struct cons_block *) lisp_malloc (sizeof *cons_block, | 2647 cons_block = NULL; |
| 2040 MEM_TYPE_CONS); | 2648 cons_block_index = CONS_BLOCK_SIZE; /* Force alloc of new cons_block. */ |
| 2041 cons_block->next = 0; | |
| 2042 bzero ((char *) cons_block->conses, sizeof cons_block->conses); | |
| 2043 cons_block_index = 0; | |
| 2044 cons_free_list = 0; | 2649 cons_free_list = 0; |
| 2045 n_cons_blocks = 1; | 2650 n_cons_blocks = 0; |
| 2046 } | 2651 } |
| 2047 | 2652 |
| 2048 | 2653 |
| 2049 /* Explicitly free a cons cell by putting it on the free-list. */ | 2654 /* Explicitly free a cons cell by putting it on the free-list. */ |
| 2050 | 2655 |
| 2051 void | 2656 void |
| 2052 free_cons (ptr) | 2657 free_cons (ptr) |
| 2053 struct Lisp_Cons *ptr; | 2658 struct Lisp_Cons *ptr; |
| 2054 { | 2659 { |
| 2055 *(struct Lisp_Cons **)&ptr->cdr = cons_free_list; | 2660 ptr->u.chain = cons_free_list; |
| 2056 #if GC_MARK_STACK | 2661 #if GC_MARK_STACK |
| 2057 ptr->car = Vdead; | 2662 ptr->car = Vdead; |
| 2058 #endif | 2663 #endif |
| 2059 cons_free_list = ptr; | 2664 cons_free_list = ptr; |
| 2060 } | 2665 } |
| 2061 | |
| 2062 | 2666 |
| 2063 DEFUN ("cons", Fcons, Scons, 2, 2, 0, | 2667 DEFUN ("cons", Fcons, Scons, 2, 2, 0, |
| 2064 doc: /* Create a new cons, give it CAR and CDR as components, and return it. */) | 2668 doc: /* Create a new cons, give it CAR and CDR as components, and return it. */) |
| 2065 (car, cdr) | 2669 (car, cdr) |
| 2066 Lisp_Object car, cdr; | 2670 Lisp_Object car, cdr; |
| 2070 if (cons_free_list) | 2674 if (cons_free_list) |
| 2071 { | 2675 { |
| 2072 /* We use the cdr for chaining the free list | 2676 /* We use the cdr for chaining the free list |
| 2073 so that we won't use the same field that has the mark bit. */ | 2677 so that we won't use the same field that has the mark bit. */ |
| 2074 XSETCONS (val, cons_free_list); | 2678 XSETCONS (val, cons_free_list); |
| 2075 cons_free_list = *(struct Lisp_Cons **)&cons_free_list->cdr; | 2679 cons_free_list = cons_free_list->u.chain; |
| 2076 } | 2680 } |
| 2077 else | 2681 else |
| 2078 { | 2682 { |
| 2079 if (cons_block_index == CONS_BLOCK_SIZE) | 2683 if (cons_block_index == CONS_BLOCK_SIZE) |
| 2080 { | 2684 { |
| 2081 register struct cons_block *new; | 2685 register struct cons_block *new; |
| 2082 new = (struct cons_block *) lisp_malloc (sizeof *new, | 2686 new = (struct cons_block *) lisp_align_malloc (sizeof *new, |
| 2083 MEM_TYPE_CONS); | 2687 MEM_TYPE_CONS); |
| 2084 VALIDATE_LISP_STORAGE (new, sizeof *new); | 2688 bzero ((char *) new->gcmarkbits, sizeof new->gcmarkbits); |
| 2085 new->next = cons_block; | 2689 new->next = cons_block; |
| 2086 cons_block = new; | 2690 cons_block = new; |
| 2087 cons_block_index = 0; | 2691 cons_block_index = 0; |
| 2088 n_cons_blocks++; | 2692 n_cons_blocks++; |
| 2089 } | 2693 } |
| 2090 XSETCONS (val, &cons_block->conses[cons_block_index++]); | 2694 XSETCONS (val, &cons_block->conses[cons_block_index]); |
| 2695 cons_block_index++; | |
| 2091 } | 2696 } |
| 2092 | 2697 |
| 2093 XSETCAR (val, car); | 2698 XSETCAR (val, car); |
| 2094 XSETCDR (val, cdr); | 2699 XSETCDR (val, cdr); |
| 2700 eassert (!CONS_MARKED_P (XCONS (val))); | |
| 2095 consing_since_gc += sizeof (struct Lisp_Cons); | 2701 consing_since_gc += sizeof (struct Lisp_Cons); |
| 2096 cons_cells_consed++; | 2702 cons_cells_consed++; |
| 2097 return val; | 2703 return val; |
| 2098 } | 2704 } |
| 2099 | 2705 |
| 2706 /* Get an error now if there's any junk in the cons free list. */ | |
| 2707 void | |
| 2708 check_cons_list () | |
| 2709 { | |
| 2710 #ifdef GC_CHECK_CONS_LIST | |
| 2711 struct Lisp_Cons *tail = cons_free_list; | |
| 2712 | |
| 2713 while (tail) | |
| 2714 tail = tail->u.chain; | |
| 2715 #endif | |
| 2716 } | |
| 2100 | 2717 |
| 2101 /* Make a list of 2, 3, 4 or 5 specified objects. */ | 2718 /* Make a list of 2, 3, 4 or 5 specified objects. */ |
| 2102 | 2719 |
| 2103 Lisp_Object | 2720 Lisp_Object |
| 2104 list2 (arg1, arg2) | 2721 list2 (arg1, arg2) |
| 2228 | 2845 |
| 2229 #ifdef DOUG_LEA_MALLOC | 2846 #ifdef DOUG_LEA_MALLOC |
| 2230 /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed | 2847 /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed |
| 2231 because mapped region contents are not preserved in | 2848 because mapped region contents are not preserved in |
| 2232 a dumped Emacs. */ | 2849 a dumped Emacs. */ |
| 2850 BLOCK_INPUT; | |
| 2233 mallopt (M_MMAP_MAX, 0); | 2851 mallopt (M_MMAP_MAX, 0); |
| 2852 UNBLOCK_INPUT; | |
| 2234 #endif | 2853 #endif |
| 2235 | 2854 |
| 2236 nbytes = sizeof *p + (len - 1) * sizeof p->contents[0]; | 2855 nbytes = sizeof *p + (len - 1) * sizeof p->contents[0]; |
| 2237 p = (struct Lisp_Vector *) lisp_malloc (nbytes, type); | 2856 p = (struct Lisp_Vector *) lisp_malloc (nbytes, type); |
| 2238 | 2857 |
| 2239 #ifdef DOUG_LEA_MALLOC | 2858 #ifdef DOUG_LEA_MALLOC |
| 2240 /* Back to a reasonable maximum of mmap'ed areas. */ | 2859 /* Back to a reasonable maximum of mmap'ed areas. */ |
| 2860 BLOCK_INPUT; | |
| 2241 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); | 2861 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); |
| 2242 #endif | 2862 UNBLOCK_INPUT; |
| 2243 | 2863 #endif |
| 2244 VALIDATE_LISP_STORAGE (p, 0); | 2864 |
| 2245 consing_since_gc += nbytes; | 2865 consing_since_gc += nbytes; |
| 2246 vector_cells_consed += len; | 2866 vector_cells_consed += len; |
| 2247 | 2867 |
| 2248 p->next = all_vectors; | 2868 p->next = all_vectors; |
| 2249 all_vectors = p; | 2869 all_vectors = p; |
| 2387 XSETCHAR_TABLE (vector, XCHAR_TABLE (vector)); | 3007 XSETCHAR_TABLE (vector, XCHAR_TABLE (vector)); |
| 2388 return vector; | 3008 return vector; |
| 2389 } | 3009 } |
| 2390 | 3010 |
| 2391 | 3011 |
| 2392 /* Return a newly created sub char table with default value DEFALT. | 3012 /* Return a newly created sub char table with slots initialized by INIT. |
| 2393 Since a sub char table does not appear as a top level Emacs Lisp | 3013 Since a sub char table does not appear as a top level Emacs Lisp |
| 2394 object, we don't need a Lisp interface to make it. */ | 3014 object, we don't need a Lisp interface to make it. */ |
| 2395 | 3015 |
| 2396 Lisp_Object | 3016 Lisp_Object |
| 2397 make_sub_char_table (defalt) | 3017 make_sub_char_table (init) |
| 2398 Lisp_Object defalt; | 3018 Lisp_Object init; |
| 2399 { | 3019 { |
| 2400 Lisp_Object vector | 3020 Lisp_Object vector |
| 2401 = Fmake_vector (make_number (SUB_CHAR_TABLE_STANDARD_SLOTS), Qnil); | 3021 = Fmake_vector (make_number (SUB_CHAR_TABLE_STANDARD_SLOTS), init); |
| 2402 XCHAR_TABLE (vector)->top = Qnil; | 3022 XCHAR_TABLE (vector)->top = Qnil; |
| 2403 XCHAR_TABLE (vector)->defalt = defalt; | 3023 XCHAR_TABLE (vector)->defalt = Qnil; |
| 2404 XSETCHAR_TABLE (vector, XCHAR_TABLE (vector)); | 3024 XSETCHAR_TABLE (vector, XCHAR_TABLE (vector)); |
| 2405 return vector; | 3025 return vector; |
| 2406 } | 3026 } |
| 2407 | 3027 |
| 2408 | 3028 |
| 2431 doc: /* Create a byte-code object with specified arguments as elements. | 3051 doc: /* Create a byte-code object with specified arguments as elements. |
| 2432 The arguments should be the arglist, bytecode-string, constant vector, | 3052 The arguments should be the arglist, bytecode-string, constant vector, |
| 2433 stack size, (optional) doc string, and (optional) interactive spec. | 3053 stack size, (optional) doc string, and (optional) interactive spec. |
| 2434 The first four arguments are required; at most six have any | 3054 The first four arguments are required; at most six have any |
| 2435 significance. | 3055 significance. |
| 2436 usage: (make-byte-code &rest ELEMENTS) */) | 3056 usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INTERACTIVE-SPEC &rest ELEMENTS) */) |
| 2437 (nargs, args) | 3057 (nargs, args) |
| 2438 register int nargs; | 3058 register int nargs; |
| 2439 Lisp_Object *args; | 3059 Lisp_Object *args; |
| 2440 { | 3060 { |
| 2441 register Lisp_Object len, val; | 3061 register Lisp_Object len, val; |
| 2480 #define SYMBOL_BLOCK_SIZE \ | 3100 #define SYMBOL_BLOCK_SIZE \ |
| 2481 ((1020 - sizeof (struct symbol_block *)) / sizeof (struct Lisp_Symbol)) | 3101 ((1020 - sizeof (struct symbol_block *)) / sizeof (struct Lisp_Symbol)) |
| 2482 | 3102 |
| 2483 struct symbol_block | 3103 struct symbol_block |
| 2484 { | 3104 { |
| 3105 /* Place `symbols' first, to preserve alignment. */ | |
| 3106 struct Lisp_Symbol symbols[SYMBOL_BLOCK_SIZE]; | |
| 2485 struct symbol_block *next; | 3107 struct symbol_block *next; |
| 2486 struct Lisp_Symbol symbols[SYMBOL_BLOCK_SIZE]; | |
| 2487 }; | 3108 }; |
| 2488 | 3109 |
| 2489 /* Current symbol block and index of first unused Lisp_Symbol | 3110 /* Current symbol block and index of first unused Lisp_Symbol |
| 2490 structure in it. */ | 3111 structure in it. */ |
| 2491 | 3112 |
| 2504 /* Initialize symbol allocation. */ | 3125 /* Initialize symbol allocation. */ |
| 2505 | 3126 |
| 2506 void | 3127 void |
| 2507 init_symbol () | 3128 init_symbol () |
| 2508 { | 3129 { |
| 2509 symbol_block = (struct symbol_block *) lisp_malloc (sizeof *symbol_block, | 3130 symbol_block = NULL; |
| 2510 MEM_TYPE_SYMBOL); | 3131 symbol_block_index = SYMBOL_BLOCK_SIZE; |
| 2511 symbol_block->next = 0; | |
| 2512 bzero ((char *) symbol_block->symbols, sizeof symbol_block->symbols); | |
| 2513 symbol_block_index = 0; | |
| 2514 symbol_free_list = 0; | 3132 symbol_free_list = 0; |
| 2515 n_symbol_blocks = 1; | 3133 n_symbol_blocks = 0; |
| 2516 } | 3134 } |
| 2517 | 3135 |
| 2518 | 3136 |
| 2519 DEFUN ("make-symbol", Fmake_symbol, Smake_symbol, 1, 1, 0, | 3137 DEFUN ("make-symbol", Fmake_symbol, Smake_symbol, 1, 1, 0, |
| 2520 doc: /* Return a newly allocated uninterned symbol whose name is NAME. | 3138 doc: /* Return a newly allocated uninterned symbol whose name is NAME. |
| 2528 CHECK_STRING (name); | 3146 CHECK_STRING (name); |
| 2529 | 3147 |
| 2530 if (symbol_free_list) | 3148 if (symbol_free_list) |
| 2531 { | 3149 { |
| 2532 XSETSYMBOL (val, symbol_free_list); | 3150 XSETSYMBOL (val, symbol_free_list); |
| 2533 symbol_free_list = *(struct Lisp_Symbol **)&symbol_free_list->value; | 3151 symbol_free_list = symbol_free_list->next; |
| 2534 } | 3152 } |
| 2535 else | 3153 else |
| 2536 { | 3154 { |
| 2537 if (symbol_block_index == SYMBOL_BLOCK_SIZE) | 3155 if (symbol_block_index == SYMBOL_BLOCK_SIZE) |
| 2538 { | 3156 { |
| 2539 struct symbol_block *new; | 3157 struct symbol_block *new; |
| 2540 new = (struct symbol_block *) lisp_malloc (sizeof *new, | 3158 new = (struct symbol_block *) lisp_malloc (sizeof *new, |
| 2541 MEM_TYPE_SYMBOL); | 3159 MEM_TYPE_SYMBOL); |
| 2542 VALIDATE_LISP_STORAGE (new, sizeof *new); | |
| 2543 new->next = symbol_block; | 3160 new->next = symbol_block; |
| 2544 symbol_block = new; | 3161 symbol_block = new; |
| 2545 symbol_block_index = 0; | 3162 symbol_block_index = 0; |
| 2546 n_symbol_blocks++; | 3163 n_symbol_blocks++; |
| 2547 } | 3164 } |
| 2548 XSETSYMBOL (val, &symbol_block->symbols[symbol_block_index++]); | 3165 XSETSYMBOL (val, &symbol_block->symbols[symbol_block_index]); |
| 3166 symbol_block_index++; | |
| 2549 } | 3167 } |
| 2550 | 3168 |
| 2551 p = XSYMBOL (val); | 3169 p = XSYMBOL (val); |
| 2552 p->xname = name; | 3170 p->xname = name; |
| 2553 p->plist = Qnil; | 3171 p->plist = Qnil; |
| 2554 p->value = Qunbound; | 3172 p->value = Qunbound; |
| 2555 p->function = Qunbound; | 3173 p->function = Qunbound; |
| 2556 p->next = NULL; | 3174 p->next = NULL; |
| 3175 p->gcmarkbit = 0; | |
| 2557 p->interned = SYMBOL_UNINTERNED; | 3176 p->interned = SYMBOL_UNINTERNED; |
| 2558 p->constant = 0; | 3177 p->constant = 0; |
| 2559 p->indirect_variable = 0; | 3178 p->indirect_variable = 0; |
| 2560 consing_since_gc += sizeof (struct Lisp_Symbol); | 3179 consing_since_gc += sizeof (struct Lisp_Symbol); |
| 2561 symbols_consed++; | 3180 symbols_consed++; |
| 2574 #define MARKER_BLOCK_SIZE \ | 3193 #define MARKER_BLOCK_SIZE \ |
| 2575 ((1020 - sizeof (struct marker_block *)) / sizeof (union Lisp_Misc)) | 3194 ((1020 - sizeof (struct marker_block *)) / sizeof (union Lisp_Misc)) |
| 2576 | 3195 |
| 2577 struct marker_block | 3196 struct marker_block |
| 2578 { | 3197 { |
| 3198 /* Place `markers' first, to preserve alignment. */ | |
| 3199 union Lisp_Misc markers[MARKER_BLOCK_SIZE]; | |
| 2579 struct marker_block *next; | 3200 struct marker_block *next; |
| 2580 union Lisp_Misc markers[MARKER_BLOCK_SIZE]; | |
| 2581 }; | 3201 }; |
| 2582 | 3202 |
| 2583 struct marker_block *marker_block; | 3203 struct marker_block *marker_block; |
| 2584 int marker_block_index; | 3204 int marker_block_index; |
| 2585 | 3205 |
| 2590 int n_marker_blocks; | 3210 int n_marker_blocks; |
| 2591 | 3211 |
| 2592 void | 3212 void |
| 2593 init_marker () | 3213 init_marker () |
| 2594 { | 3214 { |
| 2595 marker_block = (struct marker_block *) lisp_malloc (sizeof *marker_block, | 3215 marker_block = NULL; |
| 2596 MEM_TYPE_MISC); | 3216 marker_block_index = MARKER_BLOCK_SIZE; |
| 2597 marker_block->next = 0; | |
| 2598 bzero ((char *) marker_block->markers, sizeof marker_block->markers); | |
| 2599 marker_block_index = 0; | |
| 2600 marker_free_list = 0; | 3217 marker_free_list = 0; |
| 2601 n_marker_blocks = 1; | 3218 n_marker_blocks = 0; |
| 2602 } | 3219 } |
| 2603 | 3220 |
| 2604 /* Return a newly allocated Lisp_Misc object, with no substructure. */ | 3221 /* Return a newly allocated Lisp_Misc object, with no substructure. */ |
| 2605 | 3222 |
| 2606 Lisp_Object | 3223 Lisp_Object |
| 2618 if (marker_block_index == MARKER_BLOCK_SIZE) | 3235 if (marker_block_index == MARKER_BLOCK_SIZE) |
| 2619 { | 3236 { |
| 2620 struct marker_block *new; | 3237 struct marker_block *new; |
| 2621 new = (struct marker_block *) lisp_malloc (sizeof *new, | 3238 new = (struct marker_block *) lisp_malloc (sizeof *new, |
| 2622 MEM_TYPE_MISC); | 3239 MEM_TYPE_MISC); |
| 2623 VALIDATE_LISP_STORAGE (new, sizeof *new); | |
| 2624 new->next = marker_block; | 3240 new->next = marker_block; |
| 2625 marker_block = new; | 3241 marker_block = new; |
| 2626 marker_block_index = 0; | 3242 marker_block_index = 0; |
| 2627 n_marker_blocks++; | 3243 n_marker_blocks++; |
| 3244 total_free_markers += MARKER_BLOCK_SIZE; | |
| 2628 } | 3245 } |
| 2629 XSETMISC (val, &marker_block->markers[marker_block_index++]); | 3246 XSETMISC (val, &marker_block->markers[marker_block_index]); |
| 2630 } | 3247 marker_block_index++; |
| 2631 | 3248 } |
| 3249 | |
| 3250 --total_free_markers; | |
| 2632 consing_since_gc += sizeof (union Lisp_Misc); | 3251 consing_since_gc += sizeof (union Lisp_Misc); |
| 2633 misc_objects_consed++; | 3252 misc_objects_consed++; |
| 3253 XMARKER (val)->gcmarkbit = 0; | |
| 2634 return val; | 3254 return val; |
| 3255 } | |
| 3256 | |
| 3257 /* Free a Lisp_Misc object */ | |
| 3258 | |
| 3259 void | |
| 3260 free_misc (misc) | |
| 3261 Lisp_Object misc; | |
| 3262 { | |
| 3263 XMISC (misc)->u_marker.type = Lisp_Misc_Free; | |
| 3264 XMISC (misc)->u_free.chain = marker_free_list; | |
| 3265 marker_free_list = XMISC (misc); | |
| 3266 | |
| 3267 total_free_markers++; | |
| 2635 } | 3268 } |
| 2636 | 3269 |
| 2637 /* Return a Lisp_Misc_Save_Value object containing POINTER and | 3270 /* Return a Lisp_Misc_Save_Value object containing POINTER and |
| 2638 INTEGER. This is used to package C values to call record_unwind_protect. | 3271 INTEGER. This is used to package C values to call record_unwind_protect. |
| 2639 The unwind function can get the C values back using XSAVE_VALUE. */ | 3272 The unwind function can get the C values back using XSAVE_VALUE. */ |
| 2649 val = allocate_misc (); | 3282 val = allocate_misc (); |
| 2650 XMISCTYPE (val) = Lisp_Misc_Save_Value; | 3283 XMISCTYPE (val) = Lisp_Misc_Save_Value; |
| 2651 p = XSAVE_VALUE (val); | 3284 p = XSAVE_VALUE (val); |
| 2652 p->pointer = pointer; | 3285 p->pointer = pointer; |
| 2653 p->integer = integer; | 3286 p->integer = integer; |
| 3287 p->dogc = 0; | |
| 2654 return val; | 3288 return val; |
| 2655 } | 3289 } |
| 2656 | 3290 |
| 2657 DEFUN ("make-marker", Fmake_marker, Smake_marker, 0, 0, 0, | 3291 DEFUN ("make-marker", Fmake_marker, Smake_marker, 0, 0, 0, |
| 2658 doc: /* Return a newly allocated marker which does not point at any place. */) | 3292 doc: /* Return a newly allocated marker which does not point at any place. */) |
| 2665 XMISCTYPE (val) = Lisp_Misc_Marker; | 3299 XMISCTYPE (val) = Lisp_Misc_Marker; |
| 2666 p = XMARKER (val); | 3300 p = XMARKER (val); |
| 2667 p->buffer = 0; | 3301 p->buffer = 0; |
| 2668 p->bytepos = 0; | 3302 p->bytepos = 0; |
| 2669 p->charpos = 0; | 3303 p->charpos = 0; |
| 2670 p->chain = Qnil; | 3304 p->next = NULL; |
| 2671 p->insertion_type = 0; | 3305 p->insertion_type = 0; |
| 2672 return val; | 3306 return val; |
| 2673 } | 3307 } |
| 2674 | 3308 |
| 2675 /* Put MARKER back on the free list after using it temporarily. */ | 3309 /* Put MARKER back on the free list after using it temporarily. */ |
| 2676 | 3310 |
| 2677 void | 3311 void |
| 2678 free_marker (marker) | 3312 free_marker (marker) |
| 2679 Lisp_Object marker; | 3313 Lisp_Object marker; |
| 2680 { | 3314 { |
| 2681 unchain_marker (marker); | 3315 unchain_marker (XMARKER (marker)); |
| 2682 | 3316 free_misc (marker); |
| 2683 XMISC (marker)->u_marker.type = Lisp_Misc_Free; | |
| 2684 XMISC (marker)->u_free.chain = marker_free_list; | |
| 2685 marker_free_list = XMISC (marker); | |
| 2686 | |
| 2687 total_free_markers++; | |
| 2688 } | 3317 } |
| 2689 | 3318 |
| 2690 | 3319 |
| 2691 /* Return a newly created vector or string with specified arguments as | 3320 /* Return a newly created vector or string with specified arguments as |
| 2692 elements. If all the arguments are characters that can fit | 3321 elements. If all the arguments are characters that can fit |
| 2726 return result; | 3355 return result; |
| 2727 } | 3356 } |
| 2728 } | 3357 } |
| 2729 | 3358 |
| 2730 | 3359 |
| 3360 | |
| 3361 /************************************************************************ | |
| 3362 Memory Full Handling | |
| 3363 ************************************************************************/ | |
| 3364 | |
| 3365 | |
| 3366 /* Called if malloc returns zero. */ | |
| 3367 | |
| 3368 void | |
| 3369 memory_full () | |
| 3370 { | |
| 3371 int i; | |
| 3372 | |
| 3373 Vmemory_full = Qt; | |
| 3374 | |
| 3375 memory_full_cons_threshold = sizeof (struct cons_block); | |
| 3376 | |
| 3377 /* The first time we get here, free the spare memory. */ | |
| 3378 for (i = 0; i < sizeof (spare_memory) / sizeof (char *); i++) | |
| 3379 if (spare_memory[i]) | |
| 3380 { | |
| 3381 if (i == 0) | |
| 3382 free (spare_memory[i]); | |
| 3383 else if (i >= 1 && i <= 4) | |
| 3384 lisp_align_free (spare_memory[i]); | |
| 3385 else | |
| 3386 lisp_free (spare_memory[i]); | |
| 3387 spare_memory[i] = 0; | |
| 3388 } | |
| 3389 | |
| 3390 /* Record the space now used. When it decreases substantially, | |
| 3391 we can refill the memory reserve. */ | |
| 3392 #ifndef SYSTEM_MALLOC | |
| 3393 bytes_used_when_full = BYTES_USED; | |
| 3394 #endif | |
| 3395 | |
| 3396 /* This used to call error, but if we've run out of memory, we could | |
| 3397 get infinite recursion trying to build the string. */ | |
| 3398 while (1) | |
| 3399 Fsignal (Qnil, Vmemory_signal_data); | |
| 3400 } | |
| 3401 | |
| 3402 /* If we released our reserve (due to running out of memory), | |
| 3403 and we have a fair amount free once again, | |
| 3404 try to set aside another reserve in case we run out once more. | |
| 3405 | |
| 3406 This is called when a relocatable block is freed in ralloc.c, | |
| 3407 and also directly from this file, in case we're not using ralloc.c. */ | |
| 3408 | |
| 3409 void | |
| 3410 refill_memory_reserve () | |
| 3411 { | |
| 3412 #ifndef SYSTEM_MALLOC | |
| 3413 if (spare_memory[0] == 0) | |
| 3414 spare_memory[0] = (char *) malloc ((size_t) SPARE_MEMORY); | |
| 3415 if (spare_memory[1] == 0) | |
| 3416 spare_memory[1] = (char *) lisp_align_malloc (sizeof (struct cons_block), | |
| 3417 MEM_TYPE_CONS); | |
| 3418 if (spare_memory[2] == 0) | |
| 3419 spare_memory[2] = (char *) lisp_align_malloc (sizeof (struct cons_block), | |
| 3420 MEM_TYPE_CONS); | |
| 3421 if (spare_memory[3] == 0) | |
| 3422 spare_memory[3] = (char *) lisp_align_malloc (sizeof (struct cons_block), | |
| 3423 MEM_TYPE_CONS); | |
| 3424 if (spare_memory[4] == 0) | |
| 3425 spare_memory[4] = (char *) lisp_align_malloc (sizeof (struct cons_block), | |
| 3426 MEM_TYPE_CONS); | |
| 3427 if (spare_memory[5] == 0) | |
| 3428 spare_memory[5] = (char *) lisp_malloc (sizeof (struct string_block), | |
| 3429 MEM_TYPE_STRING); | |
| 3430 if (spare_memory[6] == 0) | |
| 3431 spare_memory[6] = (char *) lisp_malloc (sizeof (struct string_block), | |
| 3432 MEM_TYPE_STRING); | |
| 3433 if (spare_memory[0] && spare_memory[1] && spare_memory[5]) | |
| 3434 Vmemory_full = Qnil; | |
| 3435 #endif | |
| 3436 } | |
| 2731 | 3437 |
| 2732 /************************************************************************ | 3438 /************************************************************************ |
| 2733 C Stack Marking | 3439 C Stack Marking |
| 2734 ************************************************************************/ | 3440 ************************************************************************/ |
| 2735 | 3441 |
| 3158 | 3864 |
| 3159 /* P must point to the start of a Lisp_String structure, and it | 3865 /* P must point to the start of a Lisp_String structure, and it |
| 3160 must not be on the free-list. */ | 3866 must not be on the free-list. */ |
| 3161 return (offset >= 0 | 3867 return (offset >= 0 |
| 3162 && offset % sizeof b->strings[0] == 0 | 3868 && offset % sizeof b->strings[0] == 0 |
| 3869 && offset < (STRING_BLOCK_SIZE * sizeof b->strings[0]) | |
| 3163 && ((struct Lisp_String *) p)->data != NULL); | 3870 && ((struct Lisp_String *) p)->data != NULL); |
| 3164 } | 3871 } |
| 3165 else | 3872 else |
| 3166 return 0; | 3873 return 0; |
| 3167 } | 3874 } |
| 3183 /* P must point to the start of a Lisp_Cons, not be | 3890 /* P must point to the start of a Lisp_Cons, not be |
| 3184 one of the unused cells in the current cons block, | 3891 one of the unused cells in the current cons block, |
| 3185 and not be on the free-list. */ | 3892 and not be on the free-list. */ |
| 3186 return (offset >= 0 | 3893 return (offset >= 0 |
| 3187 && offset % sizeof b->conses[0] == 0 | 3894 && offset % sizeof b->conses[0] == 0 |
| 3895 && offset < (CONS_BLOCK_SIZE * sizeof b->conses[0]) | |
| 3188 && (b != cons_block | 3896 && (b != cons_block |
| 3189 || offset / sizeof b->conses[0] < cons_block_index) | 3897 || offset / sizeof b->conses[0] < cons_block_index) |
| 3190 && !EQ (((struct Lisp_Cons *) p)->car, Vdead)); | 3898 && !EQ (((struct Lisp_Cons *) p)->car, Vdead)); |
| 3191 } | 3899 } |
| 3192 else | 3900 else |
| 3210 /* P must point to the start of a Lisp_Symbol, not be | 3918 /* P must point to the start of a Lisp_Symbol, not be |
| 3211 one of the unused cells in the current symbol block, | 3919 one of the unused cells in the current symbol block, |
| 3212 and not be on the free-list. */ | 3920 and not be on the free-list. */ |
| 3213 return (offset >= 0 | 3921 return (offset >= 0 |
| 3214 && offset % sizeof b->symbols[0] == 0 | 3922 && offset % sizeof b->symbols[0] == 0 |
| 3923 && offset < (SYMBOL_BLOCK_SIZE * sizeof b->symbols[0]) | |
| 3215 && (b != symbol_block | 3924 && (b != symbol_block |
| 3216 || offset / sizeof b->symbols[0] < symbol_block_index) | 3925 || offset / sizeof b->symbols[0] < symbol_block_index) |
| 3217 && !EQ (((struct Lisp_Symbol *) p)->function, Vdead)); | 3926 && !EQ (((struct Lisp_Symbol *) p)->function, Vdead)); |
| 3218 } | 3927 } |
| 3219 else | 3928 else |
| 3232 if (m->type == MEM_TYPE_FLOAT) | 3941 if (m->type == MEM_TYPE_FLOAT) |
| 3233 { | 3942 { |
| 3234 struct float_block *b = (struct float_block *) m->start; | 3943 struct float_block *b = (struct float_block *) m->start; |
| 3235 int offset = (char *) p - (char *) &b->floats[0]; | 3944 int offset = (char *) p - (char *) &b->floats[0]; |
| 3236 | 3945 |
| 3237 /* P must point to the start of a Lisp_Float, not be | 3946 /* P must point to the start of a Lisp_Float and not be |
| 3238 one of the unused cells in the current float block, | 3947 one of the unused cells in the current float block. */ |
| 3239 and not be on the free-list. */ | |
| 3240 return (offset >= 0 | 3948 return (offset >= 0 |
| 3241 && offset % sizeof b->floats[0] == 0 | 3949 && offset % sizeof b->floats[0] == 0 |
| 3950 && offset < (FLOAT_BLOCK_SIZE * sizeof b->floats[0]) | |
| 3242 && (b != float_block | 3951 && (b != float_block |
| 3243 || offset / sizeof b->floats[0] < float_block_index) | 3952 || offset / sizeof b->floats[0] < float_block_index)); |
| 3244 && !EQ (((struct Lisp_Float *) p)->type, Vdead)); | |
| 3245 } | 3953 } |
| 3246 else | 3954 else |
| 3247 return 0; | 3955 return 0; |
| 3248 } | 3956 } |
| 3249 | 3957 |
| 3264 /* P must point to the start of a Lisp_Misc, not be | 3972 /* P must point to the start of a Lisp_Misc, not be |
| 3265 one of the unused cells in the current misc block, | 3973 one of the unused cells in the current misc block, |
| 3266 and not be on the free-list. */ | 3974 and not be on the free-list. */ |
| 3267 return (offset >= 0 | 3975 return (offset >= 0 |
| 3268 && offset % sizeof b->markers[0] == 0 | 3976 && offset % sizeof b->markers[0] == 0 |
| 3977 && offset < (MARKER_BLOCK_SIZE * sizeof b->markers[0]) | |
| 3269 && (b != marker_block | 3978 && (b != marker_block |
| 3270 || offset / sizeof b->markers[0] < marker_block_index) | 3979 || offset / sizeof b->markers[0] < marker_block_index) |
| 3271 && ((union Lisp_Misc *) p)->u_marker.type != Lisp_Misc_Free); | 3980 && ((union Lisp_Misc *) p)->u_marker.type != Lisp_Misc_Free); |
| 3272 } | 3981 } |
| 3273 else | 3982 else |
| 3287 && m->type >= MEM_TYPE_VECTOR | 3996 && m->type >= MEM_TYPE_VECTOR |
| 3288 && m->type <= MEM_TYPE_WINDOW); | 3997 && m->type <= MEM_TYPE_WINDOW); |
| 3289 } | 3998 } |
| 3290 | 3999 |
| 3291 | 4000 |
| 3292 /* Value is non-zero of P is a pointer to a live buffer. M is a | 4001 /* Value is non-zero if P is a pointer to a live buffer. M is a |
| 3293 pointer to the mem_block for P. */ | 4002 pointer to the mem_block for P. */ |
| 3294 | 4003 |
| 3295 static INLINE int | 4004 static INLINE int |
| 3296 live_buffer_p (m, p) | 4005 live_buffer_p (m, p) |
| 3297 struct mem_node *m; | 4006 struct mem_node *m; |
| 3377 mark_p = (live_string_p (m, po) | 4086 mark_p = (live_string_p (m, po) |
| 3378 && !STRING_MARKED_P ((struct Lisp_String *) po)); | 4087 && !STRING_MARKED_P ((struct Lisp_String *) po)); |
| 3379 break; | 4088 break; |
| 3380 | 4089 |
| 3381 case Lisp_Cons: | 4090 case Lisp_Cons: |
| 3382 mark_p = (live_cons_p (m, po) | 4091 mark_p = (live_cons_p (m, po) && !CONS_MARKED_P (XCONS (obj))); |
| 3383 && !XMARKBIT (XCONS (obj)->car)); | |
| 3384 break; | 4092 break; |
| 3385 | 4093 |
| 3386 case Lisp_Symbol: | 4094 case Lisp_Symbol: |
| 3387 mark_p = (live_symbol_p (m, po) | 4095 mark_p = (live_symbol_p (m, po) && !XSYMBOL (obj)->gcmarkbit); |
| 3388 && !XMARKBIT (XSYMBOL (obj)->plist)); | |
| 3389 break; | 4096 break; |
| 3390 | 4097 |
| 3391 case Lisp_Float: | 4098 case Lisp_Float: |
| 3392 mark_p = (live_float_p (m, po) | 4099 mark_p = (live_float_p (m, po) && !FLOAT_MARKED_P (XFLOAT (obj))); |
| 3393 && !XMARKBIT (XFLOAT (obj)->type)); | |
| 3394 break; | 4100 break; |
| 3395 | 4101 |
| 3396 case Lisp_Vectorlike: | 4102 case Lisp_Vectorlike: |
| 3397 /* Note: can't check GC_BUFFERP before we know it's a | 4103 /* Note: can't check GC_BUFFERP before we know it's a |
| 3398 buffer because checking that dereferences the pointer | 4104 buffer because checking that dereferences the pointer |
| 3399 PO which might point anywhere. */ | 4105 PO which might point anywhere. */ |
| 3400 if (live_vector_p (m, po)) | 4106 if (live_vector_p (m, po)) |
| 3401 mark_p = (!GC_SUBRP (obj) | 4107 mark_p = !GC_SUBRP (obj) && !VECTOR_MARKED_P (XVECTOR (obj)); |
| 3402 && !(XVECTOR (obj)->size & ARRAY_MARK_FLAG)); | |
| 3403 else if (live_buffer_p (m, po)) | 4108 else if (live_buffer_p (m, po)) |
| 3404 mark_p = GC_BUFFERP (obj) && !XMARKBIT (XBUFFER (obj)->name); | 4109 mark_p = GC_BUFFERP (obj) && !VECTOR_MARKED_P (XBUFFER (obj)); |
| 3405 break; | 4110 break; |
| 3406 | 4111 |
| 3407 case Lisp_Misc: | 4112 case Lisp_Misc: |
| 3408 if (live_misc_p (m, po)) | 4113 mark_p = (live_misc_p (m, po) && !XMARKER (obj)->gcmarkbit); |
| 3409 { | |
| 3410 switch (XMISCTYPE (obj)) | |
| 3411 { | |
| 3412 case Lisp_Misc_Marker: | |
| 3413 mark_p = !XMARKBIT (XMARKER (obj)->chain); | |
| 3414 break; | |
| 3415 | |
| 3416 case Lisp_Misc_Buffer_Local_Value: | |
| 3417 case Lisp_Misc_Some_Buffer_Local_Value: | |
| 3418 mark_p = !XMARKBIT (XBUFFER_LOCAL_VALUE (obj)->realvalue); | |
| 3419 break; | |
| 3420 | |
| 3421 case Lisp_Misc_Overlay: | |
| 3422 mark_p = !XMARKBIT (XOVERLAY (obj)->plist); | |
| 3423 break; | |
| 3424 } | |
| 3425 } | |
| 3426 break; | 4114 break; |
| 3427 | 4115 |
| 3428 case Lisp_Int: | 4116 case Lisp_Int: |
| 3429 case Lisp_Type_Limit: | 4117 case Lisp_Type_Limit: |
| 3430 break; | 4118 break; |
| 3435 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES | 4123 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES |
| 3436 if (nzombies < MAX_ZOMBIES) | 4124 if (nzombies < MAX_ZOMBIES) |
| 3437 zombies[nzombies] = obj; | 4125 zombies[nzombies] = obj; |
| 3438 ++nzombies; | 4126 ++nzombies; |
| 3439 #endif | 4127 #endif |
| 3440 mark_object (&obj); | 4128 mark_object (obj); |
| 3441 } | 4129 } |
| 3442 } | 4130 } |
| 3443 } | 4131 } |
| 3444 | 4132 |
| 3445 | 4133 |
| 3467 case MEM_TYPE_NON_LISP: | 4155 case MEM_TYPE_NON_LISP: |
| 3468 /* Nothing to do; not a pointer to Lisp memory. */ | 4156 /* Nothing to do; not a pointer to Lisp memory. */ |
| 3469 break; | 4157 break; |
| 3470 | 4158 |
| 3471 case MEM_TYPE_BUFFER: | 4159 case MEM_TYPE_BUFFER: |
| 3472 if (live_buffer_p (m, p) | 4160 if (live_buffer_p (m, p) && !VECTOR_MARKED_P((struct buffer *)p)) |
| 3473 && !XMARKBIT (((struct buffer *) p)->name)) | |
| 3474 XSETVECTOR (obj, p); | 4161 XSETVECTOR (obj, p); |
| 3475 break; | 4162 break; |
| 3476 | 4163 |
| 3477 case MEM_TYPE_CONS: | 4164 case MEM_TYPE_CONS: |
| 3478 if (live_cons_p (m, p) | 4165 if (live_cons_p (m, p) && !CONS_MARKED_P ((struct Lisp_Cons *) p)) |
| 3479 && !XMARKBIT (((struct Lisp_Cons *) p)->car)) | |
| 3480 XSETCONS (obj, p); | 4166 XSETCONS (obj, p); |
| 3481 break; | 4167 break; |
| 3482 | 4168 |
| 3483 case MEM_TYPE_STRING: | 4169 case MEM_TYPE_STRING: |
| 3484 if (live_string_p (m, p) | 4170 if (live_string_p (m, p) |
| 3485 && !STRING_MARKED_P ((struct Lisp_String *) p)) | 4171 && !STRING_MARKED_P ((struct Lisp_String *) p)) |
| 3486 XSETSTRING (obj, p); | 4172 XSETSTRING (obj, p); |
| 3487 break; | 4173 break; |
| 3488 | 4174 |
| 3489 case MEM_TYPE_MISC: | 4175 case MEM_TYPE_MISC: |
| 3490 if (live_misc_p (m, p)) | 4176 if (live_misc_p (m, p) && !((struct Lisp_Free *) p)->gcmarkbit) |
| 3491 { | 4177 XSETMISC (obj, p); |
| 3492 Lisp_Object tem; | |
| 3493 XSETMISC (tem, p); | |
| 3494 | |
| 3495 switch (XMISCTYPE (tem)) | |
| 3496 { | |
| 3497 case Lisp_Misc_Marker: | |
| 3498 if (!XMARKBIT (XMARKER (tem)->chain)) | |
| 3499 obj = tem; | |
| 3500 break; | |
| 3501 | |
| 3502 case Lisp_Misc_Buffer_Local_Value: | |
| 3503 case Lisp_Misc_Some_Buffer_Local_Value: | |
| 3504 if (!XMARKBIT (XBUFFER_LOCAL_VALUE (tem)->realvalue)) | |
| 3505 obj = tem; | |
| 3506 break; | |
| 3507 | |
| 3508 case Lisp_Misc_Overlay: | |
| 3509 if (!XMARKBIT (XOVERLAY (tem)->plist)) | |
| 3510 obj = tem; | |
| 3511 break; | |
| 3512 } | |
| 3513 } | |
| 3514 break; | 4178 break; |
| 3515 | 4179 |
| 3516 case MEM_TYPE_SYMBOL: | 4180 case MEM_TYPE_SYMBOL: |
| 3517 if (live_symbol_p (m, p) | 4181 if (live_symbol_p (m, p) && !((struct Lisp_Symbol *) p)->gcmarkbit) |
| 3518 && !XMARKBIT (((struct Lisp_Symbol *) p)->plist)) | |
| 3519 XSETSYMBOL (obj, p); | 4182 XSETSYMBOL (obj, p); |
| 3520 break; | 4183 break; |
| 3521 | 4184 |
| 3522 case MEM_TYPE_FLOAT: | 4185 case MEM_TYPE_FLOAT: |
| 3523 if (live_float_p (m, p) | 4186 if (live_float_p (m, p) && !FLOAT_MARKED_P (p)) |
| 3524 && !XMARKBIT (((struct Lisp_Float *) p)->type)) | |
| 3525 XSETFLOAT (obj, p); | 4187 XSETFLOAT (obj, p); |
| 3526 break; | 4188 break; |
| 3527 | 4189 |
| 3528 case MEM_TYPE_VECTOR: | 4190 case MEM_TYPE_VECTOR: |
| 3529 case MEM_TYPE_PROCESS: | 4191 case MEM_TYPE_PROCESS: |
| 3532 case MEM_TYPE_WINDOW: | 4194 case MEM_TYPE_WINDOW: |
| 3533 if (live_vector_p (m, p)) | 4195 if (live_vector_p (m, p)) |
| 3534 { | 4196 { |
| 3535 Lisp_Object tem; | 4197 Lisp_Object tem; |
| 3536 XSETVECTOR (tem, p); | 4198 XSETVECTOR (tem, p); |
| 3537 if (!GC_SUBRP (tem) | 4199 if (!GC_SUBRP (tem) && !VECTOR_MARKED_P (XVECTOR (tem))) |
| 3538 && !(XVECTOR (tem)->size & ARRAY_MARK_FLAG)) | |
| 3539 obj = tem; | 4200 obj = tem; |
| 3540 } | 4201 } |
| 3541 break; | 4202 break; |
| 3542 | 4203 |
| 3543 default: | 4204 default: |
| 3544 abort (); | 4205 abort (); |
| 3545 } | 4206 } |
| 3546 | 4207 |
| 3547 if (!GC_NILP (obj)) | 4208 if (!GC_NILP (obj)) |
| 3548 mark_object (&obj); | 4209 mark_object (obj); |
| 3549 } | 4210 } |
| 3550 } | 4211 } |
| 3551 | 4212 |
| 3552 | 4213 |
| 3553 /* Mark Lisp objects referenced from the address range START..END. */ | 4214 /* Mark Lisp objects referenced from the address range START..END. */ |
| 3698 int i; | 4359 int i; |
| 3699 | 4360 |
| 3700 for (p = gcprolist; p; p = p->next) | 4361 for (p = gcprolist; p; p = p->next) |
| 3701 for (i = 0; i < p->nvars; ++i) | 4362 for (i = 0; i < p->nvars; ++i) |
| 3702 if (!survives_gc_p (p->var[i])) | 4363 if (!survives_gc_p (p->var[i])) |
| 4364 /* FIXME: It's not necessarily a bug. It might just be that the | |
| 4365 GCPRO is unnecessary or should release the object sooner. */ | |
| 3703 abort (); | 4366 abort (); |
| 3704 } | 4367 } |
| 3705 | 4368 |
| 3706 #elif GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES | 4369 #elif GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES |
| 3707 | 4370 |
| 3775 volatile int stack_grows_down_p = (char *) &j > (char *) stack_base; | 4438 volatile int stack_grows_down_p = (char *) &j > (char *) stack_base; |
| 3776 void *end; | 4439 void *end; |
| 3777 | 4440 |
| 3778 /* This trick flushes the register windows so that all the state of | 4441 /* This trick flushes the register windows so that all the state of |
| 3779 the process is contained in the stack. */ | 4442 the process is contained in the stack. */ |
| 3780 /* Fixme: Code in the Boehm GC sugests flushing (with `flushrs') is | 4443 /* Fixme: Code in the Boehm GC suggests flushing (with `flushrs') is |
| 3781 needed on ia64 too. See mach_dep.c, where it also says inline | 4444 needed on ia64 too. See mach_dep.c, where it also says inline |
| 3782 assembler doesn't work with relevant proprietary compilers. */ | 4445 assembler doesn't work with relevant proprietary compilers. */ |
| 3783 #ifdef sparc | 4446 #ifdef sparc |
| 3784 asm ("ta 3"); | 4447 asm ("ta 3"); |
| 3785 #endif | 4448 #endif |
| 3816 #define GC_LISP_OBJECT_ALIGNMENT sizeof (Lisp_Object) | 4479 #define GC_LISP_OBJECT_ALIGNMENT sizeof (Lisp_Object) |
| 3817 #endif | 4480 #endif |
| 3818 #endif | 4481 #endif |
| 3819 for (i = 0; i < sizeof (Lisp_Object); i += GC_LISP_OBJECT_ALIGNMENT) | 4482 for (i = 0; i < sizeof (Lisp_Object); i += GC_LISP_OBJECT_ALIGNMENT) |
| 3820 mark_memory ((char *) stack_base + i, end); | 4483 mark_memory ((char *) stack_base + i, end); |
| 4484 /* Allow for marking a secondary stack, like the register stack on the | |
| 4485 ia64. */ | |
| 4486 #ifdef GC_MARK_SECONDARY_STACK | |
| 4487 GC_MARK_SECONDARY_STACK (); | |
| 4488 #endif | |
| 3821 | 4489 |
| 3822 #if GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS | 4490 #if GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS |
| 3823 check_gcpros (); | 4491 check_gcpros (); |
| 3824 #endif | 4492 #endif |
| 3825 } | 4493 } |
| 3826 | 4494 |
| 3827 | |
| 3828 #endif /* GC_MARK_STACK != 0 */ | 4495 #endif /* GC_MARK_STACK != 0 */ |
| 4496 | |
| 4497 | |
| 4498 | |
| 4499 /* Return 1 if OBJ is a valid lisp object. | |
| 4500 Return 0 if OBJ is NOT a valid lisp object. | |
| 4501 Return -1 if we cannot validate OBJ. | |
| 4502 This function can be quite slow, | |
| 4503 so it should only be used in code for manual debugging. */ | |
| 4504 | |
| 4505 int | |
| 4506 valid_lisp_object_p (obj) | |
| 4507 Lisp_Object obj; | |
| 4508 { | |
| 4509 void *p; | |
| 4510 #if !GC_MARK_STACK | |
| 4511 int fd; | |
| 4512 #else | |
| 4513 struct mem_node *m; | |
| 4514 #endif | |
| 4515 | |
| 4516 if (INTEGERP (obj)) | |
| 4517 return 1; | |
| 4518 | |
| 4519 p = (void *) XPNTR (obj); | |
| 4520 if (PURE_POINTER_P (p)) | |
| 4521 return 1; | |
| 4522 | |
| 4523 #if !GC_MARK_STACK | |
| 4524 /* We need to determine whether it is safe to access memory at | |
| 4525 address P. Obviously, we cannot just access it (we would SEGV | |
| 4526 trying), so we trick the o/s to tell us whether p is a valid | |
| 4527 pointer. Unfortunately, we cannot use NULL_DEVICE here, as | |
| 4528 emacs_write may not validate p in that case. */ | |
| 4529 if ((fd = emacs_open ("__Valid__Lisp__Object__", O_CREAT | O_WRONLY | O_TRUNC, 0666)) >= 0) | |
| 4530 { | |
| 4531 int valid = (emacs_write (fd, (char *)p, 16) == 16); | |
| 4532 emacs_close (fd); | |
| 4533 unlink ("__Valid__Lisp__Object__"); | |
| 4534 return valid; | |
| 4535 } | |
| 4536 | |
| 4537 return -1; | |
| 4538 #else | |
| 4539 | |
| 4540 m = mem_find (p); | |
| 4541 | |
| 4542 if (m == MEM_NIL) | |
| 4543 return 0; | |
| 4544 | |
| 4545 switch (m->type) | |
| 4546 { | |
| 4547 case MEM_TYPE_NON_LISP: | |
| 4548 return 0; | |
| 4549 | |
| 4550 case MEM_TYPE_BUFFER: | |
| 4551 return live_buffer_p (m, p); | |
| 4552 | |
| 4553 case MEM_TYPE_CONS: | |
| 4554 return live_cons_p (m, p); | |
| 4555 | |
| 4556 case MEM_TYPE_STRING: | |
| 4557 return live_string_p (m, p); | |
| 4558 | |
| 4559 case MEM_TYPE_MISC: | |
| 4560 return live_misc_p (m, p); | |
| 4561 | |
| 4562 case MEM_TYPE_SYMBOL: | |
| 4563 return live_symbol_p (m, p); | |
| 4564 | |
| 4565 case MEM_TYPE_FLOAT: | |
| 4566 return live_float_p (m, p); | |
| 4567 | |
| 4568 case MEM_TYPE_VECTOR: | |
| 4569 case MEM_TYPE_PROCESS: | |
| 4570 case MEM_TYPE_HASH_TABLE: | |
| 4571 case MEM_TYPE_FRAME: | |
| 4572 case MEM_TYPE_WINDOW: | |
| 4573 return live_vector_p (m, p); | |
| 4574 | |
| 4575 default: | |
| 4576 break; | |
| 4577 } | |
| 4578 | |
| 4579 return 0; | |
| 4580 #endif | |
| 4581 } | |
| 4582 | |
| 3829 | 4583 |
| 3830 | 4584 |
| 3831 | 4585 |
| 3832 /*********************************************************************** | 4586 /*********************************************************************** |
| 3833 Pure Storage Management | 4587 Pure Storage Management |
| 3844 pure_alloc (size, type) | 4598 pure_alloc (size, type) |
| 3845 size_t size; | 4599 size_t size; |
| 3846 int type; | 4600 int type; |
| 3847 { | 4601 { |
| 3848 POINTER_TYPE *result; | 4602 POINTER_TYPE *result; |
| 4603 #ifdef USE_LSB_TAG | |
| 4604 size_t alignment = (1 << GCTYPEBITS); | |
| 4605 #else | |
| 3849 size_t alignment = sizeof (EMACS_INT); | 4606 size_t alignment = sizeof (EMACS_INT); |
| 3850 | 4607 |
| 3851 /* Give Lisp_Floats an extra alignment. */ | 4608 /* Give Lisp_Floats an extra alignment. */ |
| 3852 if (type == Lisp_Float) | 4609 if (type == Lisp_Float) |
| 3853 { | 4610 { |
| 3855 alignment = __alignof (struct Lisp_Float); | 4612 alignment = __alignof (struct Lisp_Float); |
| 3856 #else | 4613 #else |
| 3857 alignment = sizeof (struct Lisp_Float); | 4614 alignment = sizeof (struct Lisp_Float); |
| 3858 #endif | 4615 #endif |
| 3859 } | 4616 } |
| 4617 #endif | |
| 3860 | 4618 |
| 3861 again: | 4619 again: |
| 3862 result = (POINTER_TYPE *) ALIGN ((EMACS_UINT)purebeg + pure_bytes_used, alignment); | 4620 result = ALIGN (purebeg + pure_bytes_used, alignment); |
| 3863 pure_bytes_used = ((char *)result - (char *)purebeg) + size; | 4621 pure_bytes_used = ((char *)result - (char *)purebeg) + size; |
| 3864 | 4622 |
| 3865 if (pure_bytes_used <= pure_size) | 4623 if (pure_bytes_used <= pure_size) |
| 3866 return result; | 4624 return result; |
| 3867 | 4625 |
| 3990 SBYTES (obj), | 4748 SBYTES (obj), |
| 3991 STRING_MULTIBYTE (obj)); | 4749 STRING_MULTIBYTE (obj)); |
| 3992 else if (COMPILEDP (obj) || VECTORP (obj)) | 4750 else if (COMPILEDP (obj) || VECTORP (obj)) |
| 3993 { | 4751 { |
| 3994 register struct Lisp_Vector *vec; | 4752 register struct Lisp_Vector *vec; |
| 3995 register int i, size; | 4753 register int i; |
| 4754 EMACS_INT size; | |
| 3996 | 4755 |
| 3997 size = XVECTOR (obj)->size; | 4756 size = XVECTOR (obj)->size; |
| 3998 if (size & PSEUDOVECTOR_FLAG) | 4757 if (size & PSEUDOVECTOR_FLAG) |
| 3999 size &= PSEUDOVECTOR_SIZE_MASK; | 4758 size &= PSEUDOVECTOR_SIZE_MASK; |
| 4000 vec = XVECTOR (make_pure_vector ((EMACS_INT) size)); | 4759 vec = XVECTOR (make_pure_vector (size)); |
| 4001 for (i = 0; i < size; i++) | 4760 for (i = 0; i < size; i++) |
| 4002 vec->contents[i] = Fpurecopy (XVECTOR (obj)->contents[i]); | 4761 vec->contents[i] = Fpurecopy (XVECTOR (obj)->contents[i]); |
| 4003 if (COMPILEDP (obj)) | 4762 if (COMPILEDP (obj)) |
| 4004 XSETCOMPILED (obj, vec); | 4763 XSETCOMPILED (obj, vec); |
| 4005 else | 4764 else |
| 4035 Lisp_Object tag; | 4794 Lisp_Object tag; |
| 4036 Lisp_Object val; | 4795 Lisp_Object val; |
| 4037 struct catchtag *next; | 4796 struct catchtag *next; |
| 4038 }; | 4797 }; |
| 4039 | 4798 |
| 4040 struct backtrace | |
| 4041 { | |
| 4042 struct backtrace *next; | |
| 4043 Lisp_Object *function; | |
| 4044 Lisp_Object *args; /* Points to vector of args. */ | |
| 4045 int nargs; /* Length of vector. */ | |
| 4046 /* If nargs is UNEVALLED, args points to slot holding list of | |
| 4047 unevalled args. */ | |
| 4048 char evalargs; | |
| 4049 }; | |
| 4050 | |
| 4051 | |
| 4052 | 4799 |
| 4053 /*********************************************************************** | 4800 /*********************************************************************** |
| 4054 Protection from GC | 4801 Protection from GC |
| 4055 ***********************************************************************/ | 4802 ***********************************************************************/ |
| 4056 | 4803 |
| 4067 } | 4814 } |
| 4068 | 4815 |
| 4069 | 4816 |
| 4070 DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "", | 4817 DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "", |
| 4071 doc: /* Reclaim storage for Lisp objects no longer needed. | 4818 doc: /* Reclaim storage for Lisp objects no longer needed. |
| 4072 Returns info on amount of space in use: | 4819 Garbage collection happens automatically if you cons more than |
| 4820 `gc-cons-threshold' bytes of Lisp data since previous garbage collection. | |
| 4821 `garbage-collect' normally returns a list with info on amount of space in use: | |
| 4073 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS) | 4822 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS) |
| 4074 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS | 4823 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS |
| 4075 (USED-FLOATS . FREE-FLOATS) (USED-INTERVALS . FREE-INTERVALS) | 4824 (USED-FLOATS . FREE-FLOATS) (USED-INTERVALS . FREE-INTERVALS) |
| 4076 (USED-STRINGS . FREE-STRINGS)) | 4825 (USED-STRINGS . FREE-STRINGS)) |
| 4077 Garbage collection happens automatically if you cons more than | 4826 However, if there was overflow in pure space, `garbage-collect' |
| 4078 `gc-cons-threshold' bytes of Lisp data since previous garbage collection. */) | 4827 returns nil, because real GC can't be done. */) |
| 4079 () | 4828 () |
| 4080 { | 4829 { |
| 4081 register struct gcpro *tail; | |
| 4082 register struct specbinding *bind; | 4830 register struct specbinding *bind; |
| 4083 struct catchtag *catch; | 4831 struct catchtag *catch; |
| 4084 struct handler *handler; | 4832 struct handler *handler; |
| 4085 register struct backtrace *backlist; | |
| 4086 char stack_top_variable; | 4833 char stack_top_variable; |
| 4087 register int i; | 4834 register int i; |
| 4088 int message_p; | 4835 int message_p; |
| 4089 Lisp_Object total[8]; | 4836 Lisp_Object total[8]; |
| 4090 int count = SPECPDL_INDEX (); | 4837 int count = SPECPDL_INDEX (); |
| 4091 EMACS_TIME t1, t2, t3; | 4838 EMACS_TIME t1, t2, t3; |
| 4092 | 4839 |
| 4093 EMACS_GET_TIME (t1); | 4840 if (abort_on_gc) |
| 4841 abort (); | |
| 4094 | 4842 |
| 4095 /* Can't GC if pure storage overflowed because we can't determine | 4843 /* Can't GC if pure storage overflowed because we can't determine |
| 4096 if something is a pure object or not. */ | 4844 if something is a pure object or not. */ |
| 4097 if (pure_bytes_used_before_overflow) | 4845 if (pure_bytes_used_before_overflow) |
| 4098 return Qnil; | 4846 return Qnil; |
| 4847 | |
| 4848 CHECK_CONS_LIST (); | |
| 4849 | |
| 4850 /* Don't keep undo information around forever. | |
| 4851 Do this early on, so it is no problem if the user quits. */ | |
| 4852 { | |
| 4853 register struct buffer *nextb = all_buffers; | |
| 4854 | |
| 4855 while (nextb) | |
| 4856 { | |
| 4857 /* If a buffer's undo list is Qt, that means that undo is | |
| 4858 turned off in that buffer. Calling truncate_undo_list on | |
| 4859 Qt tends to return NULL, which effectively turns undo back on. | |
| 4860 So don't call truncate_undo_list if undo_list is Qt. */ | |
| 4861 if (! NILP (nextb->name) && ! EQ (nextb->undo_list, Qt)) | |
| 4862 truncate_undo_list (nextb); | |
| 4863 | |
| 4864 /* Shrink buffer gaps, but skip indirect and dead buffers. */ | |
| 4865 if (nextb->base_buffer == 0 && !NILP (nextb->name)) | |
| 4866 { | |
| 4867 /* If a buffer's gap size is more than 10% of the buffer | |
| 4868 size, or larger than 2000 bytes, then shrink it | |
| 4869 accordingly. Keep a minimum size of 20 bytes. */ | |
| 4870 int size = min (2000, max (20, (nextb->text->z_byte / 10))); | |
| 4871 | |
| 4872 if (nextb->text->gap_size > size) | |
| 4873 { | |
| 4874 struct buffer *save_current = current_buffer; | |
| 4875 current_buffer = nextb; | |
| 4876 make_gap (-(nextb->text->gap_size - size)); | |
| 4877 current_buffer = save_current; | |
| 4878 } | |
| 4879 } | |
| 4880 | |
| 4881 nextb = nextb->next; | |
| 4882 } | |
| 4883 } | |
| 4884 | |
| 4885 EMACS_GET_TIME (t1); | |
| 4099 | 4886 |
| 4100 /* In case user calls debug_print during GC, | 4887 /* In case user calls debug_print during GC, |
| 4101 don't let that cause a recursive GC. */ | 4888 don't let that cause a recursive GC. */ |
| 4102 consing_since_gc = 0; | 4889 consing_since_gc = 0; |
| 4103 | 4890 |
| 4133 | 4920 |
| 4134 BLOCK_INPUT; | 4921 BLOCK_INPUT; |
| 4135 | 4922 |
| 4136 shrink_regexp_cache (); | 4923 shrink_regexp_cache (); |
| 4137 | 4924 |
| 4138 /* Don't keep undo information around forever. */ | 4925 gc_in_progress = 1; |
| 4926 | |
| 4927 /* clear_marks (); */ | |
| 4928 | |
| 4929 /* Mark all the special slots that serve as the roots of accessibility. */ | |
| 4930 | |
| 4931 for (i = 0; i < staticidx; i++) | |
| 4932 mark_object (*staticvec[i]); | |
| 4933 | |
| 4934 for (bind = specpdl; bind != specpdl_ptr; bind++) | |
| 4935 { | |
| 4936 mark_object (bind->symbol); | |
| 4937 mark_object (bind->old_value); | |
| 4938 } | |
| 4939 mark_kboards (); | |
| 4940 | |
| 4941 #ifdef USE_GTK | |
| 4139 { | 4942 { |
| 4140 register struct buffer *nextb = all_buffers; | 4943 extern void xg_mark_data (); |
| 4141 | 4944 xg_mark_data (); |
| 4142 while (nextb) | |
| 4143 { | |
| 4144 /* If a buffer's undo list is Qt, that means that undo is | |
| 4145 turned off in that buffer. Calling truncate_undo_list on | |
| 4146 Qt tends to return NULL, which effectively turns undo back on. | |
| 4147 So don't call truncate_undo_list if undo_list is Qt. */ | |
| 4148 if (! EQ (nextb->undo_list, Qt)) | |
| 4149 nextb->undo_list | |
| 4150 = truncate_undo_list (nextb->undo_list, undo_limit, | |
| 4151 undo_strong_limit); | |
| 4152 | |
| 4153 /* Shrink buffer gaps, but skip indirect and dead buffers. */ | |
| 4154 if (nextb->base_buffer == 0 && !NILP (nextb->name)) | |
| 4155 { | |
| 4156 /* If a buffer's gap size is more than 10% of the buffer | |
| 4157 size, or larger than 2000 bytes, then shrink it | |
| 4158 accordingly. Keep a minimum size of 20 bytes. */ | |
| 4159 int size = min (2000, max (20, (nextb->text->z_byte / 10))); | |
| 4160 | |
| 4161 if (nextb->text->gap_size > size) | |
| 4162 { | |
| 4163 struct buffer *save_current = current_buffer; | |
| 4164 current_buffer = nextb; | |
| 4165 make_gap (-(nextb->text->gap_size - size)); | |
| 4166 current_buffer = save_current; | |
| 4167 } | |
| 4168 } | |
| 4169 | |
| 4170 nextb = nextb->next; | |
| 4171 } | |
| 4172 } | 4945 } |
| 4173 | 4946 #endif |
| 4174 gc_in_progress = 1; | |
| 4175 | |
| 4176 /* clear_marks (); */ | |
| 4177 | |
| 4178 /* Mark all the special slots that serve as the roots of accessibility. | |
| 4179 | |
| 4180 Usually the special slots to mark are contained in particular structures. | |
| 4181 Then we know no slot is marked twice because the structures don't overlap. | |
| 4182 In some cases, the structures point to the slots to be marked. | |
| 4183 For these, we use MARKBIT to avoid double marking of the slot. */ | |
| 4184 | |
| 4185 for (i = 0; i < staticidx; i++) | |
| 4186 mark_object (staticvec[i]); | |
| 4187 | 4947 |
| 4188 #if (GC_MARK_STACK == GC_MAKE_GCPROS_NOOPS \ | 4948 #if (GC_MARK_STACK == GC_MAKE_GCPROS_NOOPS \ |
| 4189 || GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS) | 4949 || GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS) |
| 4190 mark_stack (); | 4950 mark_stack (); |
| 4191 #else | 4951 #else |
| 4192 for (tail = gcprolist; tail; tail = tail->next) | 4952 { |
| 4193 for (i = 0; i < tail->nvars; i++) | 4953 register struct gcpro *tail; |
| 4194 if (!XMARKBIT (tail->var[i])) | 4954 for (tail = gcprolist; tail; tail = tail->next) |
| 4195 { | 4955 for (i = 0; i < tail->nvars; i++) |
| 4196 /* Explicit casting prevents compiler warning about | 4956 mark_object (tail->var[i]); |
| 4197 discarding the `volatile' qualifier. */ | 4957 } |
| 4198 mark_object ((Lisp_Object *)&tail->var[i]); | |
| 4199 XMARK (tail->var[i]); | |
| 4200 } | |
| 4201 #endif | 4958 #endif |
| 4202 | 4959 |
| 4203 mark_byte_stack (); | 4960 mark_byte_stack (); |
| 4204 for (bind = specpdl; bind != specpdl_ptr; bind++) | |
| 4205 { | |
| 4206 mark_object (&bind->symbol); | |
| 4207 mark_object (&bind->old_value); | |
| 4208 } | |
| 4209 for (catch = catchlist; catch; catch = catch->next) | 4961 for (catch = catchlist; catch; catch = catch->next) |
| 4210 { | 4962 { |
| 4211 mark_object (&catch->tag); | 4963 mark_object (catch->tag); |
| 4212 mark_object (&catch->val); | 4964 mark_object (catch->val); |
| 4213 } | 4965 } |
| 4214 for (handler = handlerlist; handler; handler = handler->next) | 4966 for (handler = handlerlist; handler; handler = handler->next) |
| 4215 { | 4967 { |
| 4216 mark_object (&handler->handler); | 4968 mark_object (handler->handler); |
| 4217 mark_object (&handler->var); | 4969 mark_object (handler->var); |
| 4218 } | 4970 } |
| 4219 for (backlist = backtrace_list; backlist; backlist = backlist->next) | 4971 mark_backtrace (); |
| 4220 { | 4972 |
| 4221 if (!XMARKBIT (*backlist->function)) | 4973 #ifdef HAVE_WINDOW_SYSTEM |
| 4222 { | 4974 mark_fringe_data (); |
| 4223 mark_object (backlist->function); | 4975 #endif |
| 4224 XMARK (*backlist->function); | 4976 |
| 4225 } | 4977 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES |
| 4226 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY) | 4978 mark_stack (); |
| 4227 i = 0; | 4979 #endif |
| 4228 else | 4980 |
| 4229 i = backlist->nargs - 1; | 4981 /* Everything is now marked, except for the things that require special |
| 4230 for (; i >= 0; i--) | 4982 finalization, i.e. the undo_list. |
| 4231 if (!XMARKBIT (backlist->args[i])) | 4983 Look thru every buffer's undo list |
| 4232 { | |
| 4233 mark_object (&backlist->args[i]); | |
| 4234 XMARK (backlist->args[i]); | |
| 4235 } | |
| 4236 } | |
| 4237 mark_kboards (); | |
| 4238 | |
| 4239 /* Look thru every buffer's undo list | |
| 4240 for elements that update markers that were not marked, | 4984 for elements that update markers that were not marked, |
| 4241 and delete them. */ | 4985 and delete them. */ |
| 4242 { | 4986 { |
| 4243 register struct buffer *nextb = all_buffers; | 4987 register struct buffer *nextb = all_buffers; |
| 4244 | 4988 |
| 4255 prev = Qnil; | 4999 prev = Qnil; |
| 4256 while (CONSP (tail)) | 5000 while (CONSP (tail)) |
| 4257 { | 5001 { |
| 4258 if (GC_CONSP (XCAR (tail)) | 5002 if (GC_CONSP (XCAR (tail)) |
| 4259 && GC_MARKERP (XCAR (XCAR (tail))) | 5003 && GC_MARKERP (XCAR (XCAR (tail))) |
| 4260 && ! XMARKBIT (XMARKER (XCAR (XCAR (tail)))->chain)) | 5004 && !XMARKER (XCAR (XCAR (tail)))->gcmarkbit) |
| 4261 { | 5005 { |
| 4262 if (NILP (prev)) | 5006 if (NILP (prev)) |
| 4263 nextb->undo_list = tail = XCDR (tail); | 5007 nextb->undo_list = tail = XCDR (tail); |
| 4264 else | 5008 else |
| 4265 { | 5009 { |
| 4272 prev = tail; | 5016 prev = tail; |
| 4273 tail = XCDR (tail); | 5017 tail = XCDR (tail); |
| 4274 } | 5018 } |
| 4275 } | 5019 } |
| 4276 } | 5020 } |
| 5021 /* Now that we have stripped the elements that need not be in the | |
| 5022 undo_list any more, we can finally mark the list. */ | |
| 5023 mark_object (nextb->undo_list); | |
| 4277 | 5024 |
| 4278 nextb = nextb->next; | 5025 nextb = nextb->next; |
| 4279 } | 5026 } |
| 4280 } | 5027 } |
| 4281 | 5028 |
| 4282 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES | |
| 4283 mark_stack (); | |
| 4284 #endif | |
| 4285 | |
| 4286 #ifdef USE_GTK | |
| 4287 { | |
| 4288 extern void xg_mark_data (); | |
| 4289 xg_mark_data (); | |
| 4290 } | |
| 4291 #endif | |
| 4292 | |
| 4293 gc_sweep (); | 5029 gc_sweep (); |
| 4294 | 5030 |
| 4295 /* Clear the mark bits that we set in certain root slots. */ | 5031 /* Clear the mark bits that we set in certain root slots. */ |
| 4296 | 5032 |
| 4297 #if (GC_MARK_STACK == GC_USE_GCPROS_AS_BEFORE \ | |
| 4298 || GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES) | |
| 4299 for (tail = gcprolist; tail; tail = tail->next) | |
| 4300 for (i = 0; i < tail->nvars; i++) | |
| 4301 XUNMARK (tail->var[i]); | |
| 4302 #endif | |
| 4303 | |
| 4304 unmark_byte_stack (); | 5033 unmark_byte_stack (); |
| 4305 for (backlist = backtrace_list; backlist; backlist = backlist->next) | 5034 VECTOR_UNMARK (&buffer_defaults); |
| 4306 { | 5035 VECTOR_UNMARK (&buffer_local_symbols); |
| 4307 XUNMARK (*backlist->function); | |
| 4308 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY) | |
| 4309 i = 0; | |
| 4310 else | |
| 4311 i = backlist->nargs - 1; | |
| 4312 for (; i >= 0; i--) | |
| 4313 XUNMARK (backlist->args[i]); | |
| 4314 } | |
| 4315 XUNMARK (buffer_defaults.name); | |
| 4316 XUNMARK (buffer_local_symbols.name); | |
| 4317 | 5036 |
| 4318 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES && 0 | 5037 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES && 0 |
| 4319 dump_zombies (); | 5038 dump_zombies (); |
| 4320 #endif | 5039 #endif |
| 4321 | 5040 |
| 4322 UNBLOCK_INPUT; | 5041 UNBLOCK_INPUT; |
| 5042 | |
| 5043 CHECK_CONS_LIST (); | |
| 4323 | 5044 |
| 4324 /* clear_marks (); */ | 5045 /* clear_marks (); */ |
| 4325 gc_in_progress = 0; | 5046 gc_in_progress = 0; |
| 4326 | 5047 |
| 4327 consing_since_gc = 0; | 5048 consing_since_gc = 0; |
| 4328 if (gc_cons_threshold < 10000) | 5049 if (gc_cons_threshold < 10000) |
| 4329 gc_cons_threshold = 10000; | 5050 gc_cons_threshold = 10000; |
| 5051 | |
| 5052 if (FLOATP (Vgc_cons_percentage)) | |
| 5053 { /* Set gc_cons_combined_threshold. */ | |
| 5054 EMACS_INT total = 0; | |
| 5055 | |
| 5056 total += total_conses * sizeof (struct Lisp_Cons); | |
| 5057 total += total_symbols * sizeof (struct Lisp_Symbol); | |
| 5058 total += total_markers * sizeof (union Lisp_Misc); | |
| 5059 total += total_string_size; | |
| 5060 total += total_vector_size * sizeof (Lisp_Object); | |
| 5061 total += total_floats * sizeof (struct Lisp_Float); | |
| 5062 total += total_intervals * sizeof (struct interval); | |
| 5063 total += total_strings * sizeof (struct Lisp_String); | |
| 5064 | |
| 5065 gc_relative_threshold = total * XFLOAT_DATA (Vgc_cons_percentage); | |
| 5066 } | |
| 5067 else | |
| 5068 gc_relative_threshold = 0; | |
| 4330 | 5069 |
| 4331 if (garbage_collection_messages) | 5070 if (garbage_collection_messages) |
| 4332 { | 5071 { |
| 4333 if (message_p || minibuf_level > 0) | 5072 if (message_p || minibuf_level > 0) |
| 4334 restore_message (); | 5073 restore_message (); |
| 4379 | 5118 |
| 4380 /* Accumulate statistics. */ | 5119 /* Accumulate statistics. */ |
| 4381 EMACS_GET_TIME (t2); | 5120 EMACS_GET_TIME (t2); |
| 4382 EMACS_SUB_TIME (t3, t2, t1); | 5121 EMACS_SUB_TIME (t3, t2, t1); |
| 4383 if (FLOATP (Vgc_elapsed)) | 5122 if (FLOATP (Vgc_elapsed)) |
| 4384 XSETFLOAT (Vgc_elapsed, make_float (XFLOAT_DATA (Vgc_elapsed) + | 5123 Vgc_elapsed = make_float (XFLOAT_DATA (Vgc_elapsed) + |
| 4385 EMACS_SECS (t3) + | 5124 EMACS_SECS (t3) + |
| 4386 EMACS_USECS (t3) * 1.0e-6)); | 5125 EMACS_USECS (t3) * 1.0e-6); |
| 4387 gcs_done++; | 5126 gcs_done++; |
| 4388 | 5127 |
| 4389 return Flist (sizeof total / sizeof *total, total); | 5128 return Flist (sizeof total / sizeof *total, total); |
| 4390 } | 5129 } |
| 4391 | 5130 |
| 4410 struct glyph *end_glyph = glyph + row->used[area]; | 5149 struct glyph *end_glyph = glyph + row->used[area]; |
| 4411 | 5150 |
| 4412 for (; glyph < end_glyph; ++glyph) | 5151 for (; glyph < end_glyph; ++glyph) |
| 4413 if (GC_STRINGP (glyph->object) | 5152 if (GC_STRINGP (glyph->object) |
| 4414 && !STRING_MARKED_P (XSTRING (glyph->object))) | 5153 && !STRING_MARKED_P (XSTRING (glyph->object))) |
| 4415 mark_object (&glyph->object); | 5154 mark_object (glyph->object); |
| 4416 } | 5155 } |
| 4417 } | 5156 } |
| 4418 } | 5157 } |
| 4419 | 5158 |
| 4420 | 5159 |
| 4432 struct face *face = FACE_FROM_ID (c->f, i); | 5171 struct face *face = FACE_FROM_ID (c->f, i); |
| 4433 | 5172 |
| 4434 if (face) | 5173 if (face) |
| 4435 { | 5174 { |
| 4436 for (j = 0; j < LFACE_VECTOR_SIZE; ++j) | 5175 for (j = 0; j < LFACE_VECTOR_SIZE; ++j) |
| 4437 mark_object (&face->lface[j]); | 5176 mark_object (face->lface[j]); |
| 4438 } | 5177 } |
| 4439 } | 5178 } |
| 4440 } | 5179 } |
| 4441 } | 5180 } |
| 4442 | 5181 |
| 4447 | 5186 |
| 4448 static void | 5187 static void |
| 4449 mark_image (img) | 5188 mark_image (img) |
| 4450 struct image *img; | 5189 struct image *img; |
| 4451 { | 5190 { |
| 4452 mark_object (&img->spec); | 5191 mark_object (img->spec); |
| 4453 | 5192 |
| 4454 if (!NILP (img->data.lisp_val)) | 5193 if (!NILP (img->data.lisp_val)) |
| 4455 mark_object (&img->data.lisp_val); | 5194 mark_object (img->data.lisp_val); |
| 4456 } | 5195 } |
| 4457 | 5196 |
| 4458 | 5197 |
| 4459 /* Mark Lisp objects in image cache of frame F. It's done this way so | 5198 /* Mark Lisp objects in image cache of frame F. It's done this way so |
| 4460 that we don't have to include xterm.h here. */ | 5199 that we don't have to include xterm.h here. */ |
| 4473 /* Mark reference to a Lisp_Object. | 5212 /* Mark reference to a Lisp_Object. |
| 4474 If the object referred to has not been seen yet, recursively mark | 5213 If the object referred to has not been seen yet, recursively mark |
| 4475 all the references contained in it. */ | 5214 all the references contained in it. */ |
| 4476 | 5215 |
| 4477 #define LAST_MARKED_SIZE 500 | 5216 #define LAST_MARKED_SIZE 500 |
| 4478 Lisp_Object *last_marked[LAST_MARKED_SIZE]; | 5217 Lisp_Object last_marked[LAST_MARKED_SIZE]; |
| 4479 int last_marked_index; | 5218 int last_marked_index; |
| 4480 | 5219 |
| 4481 /* For debugging--call abort when we cdr down this many | 5220 /* For debugging--call abort when we cdr down this many |
| 4482 links of a list, in mark_object. In debugging, | 5221 links of a list, in mark_object. In debugging, |
| 4483 the call to abort will hit a breakpoint. | 5222 the call to abort will hit a breakpoint. |
| 4484 Normally this is zero and the check never goes off. */ | 5223 Normally this is zero and the check never goes off. */ |
| 4485 int mark_object_loop_halt; | 5224 int mark_object_loop_halt; |
| 4486 | 5225 |
| 4487 void | 5226 void |
| 4488 mark_object (argptr) | 5227 mark_object (arg) |
| 4489 Lisp_Object *argptr; | 5228 Lisp_Object arg; |
| 4490 { | 5229 { |
| 4491 Lisp_Object *objptr = argptr; | 5230 register Lisp_Object obj = arg; |
| 4492 register Lisp_Object obj; | |
| 4493 #ifdef GC_CHECK_MARKED_OBJECTS | 5231 #ifdef GC_CHECK_MARKED_OBJECTS |
| 4494 void *po; | 5232 void *po; |
| 4495 struct mem_node *m; | 5233 struct mem_node *m; |
| 4496 #endif | 5234 #endif |
| 4497 int cdr_count = 0; | 5235 int cdr_count = 0; |
| 4498 | 5236 |
| 4499 loop: | 5237 loop: |
| 4500 obj = *objptr; | |
| 4501 loop2: | |
| 4502 XUNMARK (obj); | |
| 4503 | 5238 |
| 4504 if (PURE_POINTER_P (XPNTR (obj))) | 5239 if (PURE_POINTER_P (XPNTR (obj))) |
| 4505 return; | 5240 return; |
| 4506 | 5241 |
| 4507 last_marked[last_marked_index++] = objptr; | 5242 last_marked[last_marked_index++] = obj; |
| 4508 if (last_marked_index == LAST_MARKED_SIZE) | 5243 if (last_marked_index == LAST_MARKED_SIZE) |
| 4509 last_marked_index = 0; | 5244 last_marked_index = 0; |
| 4510 | 5245 |
| 4511 /* Perform some sanity checks on the objects marked here. Abort if | 5246 /* Perform some sanity checks on the objects marked here. Abort if |
| 4512 we encounter an object we know is bogus. This increases GC time | 5247 we encounter an object we know is bogus. This increases GC time |
| 4572 abort (); | 5307 abort (); |
| 4573 #endif /* GC_CHECK_MARKED_OBJECTS */ | 5308 #endif /* GC_CHECK_MARKED_OBJECTS */ |
| 4574 | 5309 |
| 4575 if (GC_BUFFERP (obj)) | 5310 if (GC_BUFFERP (obj)) |
| 4576 { | 5311 { |
| 4577 if (!XMARKBIT (XBUFFER (obj)->name)) | 5312 if (!VECTOR_MARKED_P (XBUFFER (obj))) |
| 4578 { | 5313 { |
| 4579 #ifdef GC_CHECK_MARKED_OBJECTS | 5314 #ifdef GC_CHECK_MARKED_OBJECTS |
| 4580 if (po != &buffer_defaults && po != &buffer_local_symbols) | 5315 if (po != &buffer_defaults && po != &buffer_local_symbols) |
| 4581 { | 5316 { |
| 4582 struct buffer *b; | 5317 struct buffer *b; |
| 4598 { | 5333 { |
| 4599 register struct Lisp_Vector *ptr = XVECTOR (obj); | 5334 register struct Lisp_Vector *ptr = XVECTOR (obj); |
| 4600 register EMACS_INT size = ptr->size; | 5335 register EMACS_INT size = ptr->size; |
| 4601 register int i; | 5336 register int i; |
| 4602 | 5337 |
| 4603 if (size & ARRAY_MARK_FLAG) | 5338 if (VECTOR_MARKED_P (ptr)) |
| 4604 break; /* Already marked */ | 5339 break; /* Already marked */ |
| 4605 | 5340 |
| 4606 CHECK_LIVE (live_vector_p); | 5341 CHECK_LIVE (live_vector_p); |
| 4607 ptr->size |= ARRAY_MARK_FLAG; /* Else mark it */ | 5342 VECTOR_MARK (ptr); /* Else mark it */ |
| 4608 size &= PSEUDOVECTOR_SIZE_MASK; | 5343 size &= PSEUDOVECTOR_SIZE_MASK; |
| 4609 for (i = 0; i < size; i++) /* and then mark its elements */ | 5344 for (i = 0; i < size; i++) /* and then mark its elements */ |
| 4610 { | 5345 { |
| 4611 if (i != COMPILED_CONSTANTS) | 5346 if (i != COMPILED_CONSTANTS) |
| 4612 mark_object (&ptr->contents[i]); | 5347 mark_object (ptr->contents[i]); |
| 4613 } | 5348 } |
| 4614 /* This cast should be unnecessary, but some Mips compiler complains | 5349 obj = ptr->contents[COMPILED_CONSTANTS]; |
| 4615 (MIPS-ABI + SysVR4, DC/OSx, etc). */ | |
| 4616 objptr = (Lisp_Object *) &ptr->contents[COMPILED_CONSTANTS]; | |
| 4617 goto loop; | 5350 goto loop; |
| 4618 } | 5351 } |
| 4619 else if (GC_FRAMEP (obj)) | 5352 else if (GC_FRAMEP (obj)) |
| 4620 { | 5353 { |
| 4621 register struct frame *ptr = XFRAME (obj); | 5354 register struct frame *ptr = XFRAME (obj); |
| 4622 register EMACS_INT size = ptr->size; | 5355 |
| 4623 | 5356 if (VECTOR_MARKED_P (ptr)) break; /* Already marked */ |
| 4624 if (size & ARRAY_MARK_FLAG) break; /* Already marked */ | 5357 VECTOR_MARK (ptr); /* Else mark it */ |
| 4625 ptr->size |= ARRAY_MARK_FLAG; /* Else mark it */ | |
| 4626 | 5358 |
| 4627 CHECK_LIVE (live_vector_p); | 5359 CHECK_LIVE (live_vector_p); |
| 4628 mark_object (&ptr->name); | 5360 mark_object (ptr->name); |
| 4629 mark_object (&ptr->icon_name); | 5361 mark_object (ptr->icon_name); |
| 4630 mark_object (&ptr->title); | 5362 mark_object (ptr->title); |
| 4631 mark_object (&ptr->focus_frame); | 5363 mark_object (ptr->focus_frame); |
| 4632 mark_object (&ptr->selected_window); | 5364 mark_object (ptr->selected_window); |
| 4633 mark_object (&ptr->minibuffer_window); | 5365 mark_object (ptr->minibuffer_window); |
| 4634 mark_object (&ptr->param_alist); | 5366 mark_object (ptr->param_alist); |
| 4635 mark_object (&ptr->scroll_bars); | 5367 mark_object (ptr->scroll_bars); |
| 4636 mark_object (&ptr->condemned_scroll_bars); | 5368 mark_object (ptr->condemned_scroll_bars); |
| 4637 mark_object (&ptr->menu_bar_items); | 5369 mark_object (ptr->menu_bar_items); |
| 4638 mark_object (&ptr->face_alist); | 5370 mark_object (ptr->face_alist); |
| 4639 mark_object (&ptr->menu_bar_vector); | 5371 mark_object (ptr->menu_bar_vector); |
| 4640 mark_object (&ptr->buffer_predicate); | 5372 mark_object (ptr->buffer_predicate); |
| 4641 mark_object (&ptr->buffer_list); | 5373 mark_object (ptr->buffer_list); |
| 4642 mark_object (&ptr->menu_bar_window); | 5374 mark_object (ptr->menu_bar_window); |
| 4643 mark_object (&ptr->tool_bar_window); | 5375 mark_object (ptr->tool_bar_window); |
| 4644 mark_face_cache (ptr->face_cache); | 5376 mark_face_cache (ptr->face_cache); |
| 4645 #ifdef HAVE_WINDOW_SYSTEM | 5377 #ifdef HAVE_WINDOW_SYSTEM |
| 4646 mark_image_cache (ptr); | 5378 mark_image_cache (ptr); |
| 4647 mark_object (&ptr->tool_bar_items); | 5379 mark_object (ptr->tool_bar_items); |
| 4648 mark_object (&ptr->desired_tool_bar_string); | 5380 mark_object (ptr->desired_tool_bar_string); |
| 4649 mark_object (&ptr->current_tool_bar_string); | 5381 mark_object (ptr->current_tool_bar_string); |
| 4650 #endif /* HAVE_WINDOW_SYSTEM */ | 5382 #endif /* HAVE_WINDOW_SYSTEM */ |
| 4651 } | 5383 } |
| 4652 else if (GC_BOOL_VECTOR_P (obj)) | 5384 else if (GC_BOOL_VECTOR_P (obj)) |
| 4653 { | 5385 { |
| 4654 register struct Lisp_Vector *ptr = XVECTOR (obj); | 5386 register struct Lisp_Vector *ptr = XVECTOR (obj); |
| 4655 | 5387 |
| 4656 if (ptr->size & ARRAY_MARK_FLAG) | 5388 if (VECTOR_MARKED_P (ptr)) |
| 4657 break; /* Already marked */ | 5389 break; /* Already marked */ |
| 4658 CHECK_LIVE (live_vector_p); | 5390 CHECK_LIVE (live_vector_p); |
| 4659 ptr->size |= ARRAY_MARK_FLAG; /* Else mark it */ | 5391 VECTOR_MARK (ptr); /* Else mark it */ |
| 4660 } | 5392 } |
| 4661 else if (GC_WINDOWP (obj)) | 5393 else if (GC_WINDOWP (obj)) |
| 4662 { | 5394 { |
| 4663 register struct Lisp_Vector *ptr = XVECTOR (obj); | 5395 register struct Lisp_Vector *ptr = XVECTOR (obj); |
| 4664 struct window *w = XWINDOW (obj); | 5396 struct window *w = XWINDOW (obj); |
| 4665 register EMACS_INT size = ptr->size; | |
| 4666 register int i; | 5397 register int i; |
| 4667 | 5398 |
| 4668 /* Stop if already marked. */ | 5399 /* Stop if already marked. */ |
| 4669 if (size & ARRAY_MARK_FLAG) | 5400 if (VECTOR_MARKED_P (ptr)) |
| 4670 break; | 5401 break; |
| 4671 | 5402 |
| 4672 /* Mark it. */ | 5403 /* Mark it. */ |
| 4673 CHECK_LIVE (live_vector_p); | 5404 CHECK_LIVE (live_vector_p); |
| 4674 ptr->size |= ARRAY_MARK_FLAG; | 5405 VECTOR_MARK (ptr); |
| 4675 | 5406 |
| 4676 /* There is no Lisp data above The member CURRENT_MATRIX in | 5407 /* There is no Lisp data above The member CURRENT_MATRIX in |
| 4677 struct WINDOW. Stop marking when that slot is reached. */ | 5408 struct WINDOW. Stop marking when that slot is reached. */ |
| 4678 for (i = 0; | 5409 for (i = 0; |
| 4679 (char *) &ptr->contents[i] < (char *) &w->current_matrix; | 5410 (char *) &ptr->contents[i] < (char *) &w->current_matrix; |
| 4680 i++) | 5411 i++) |
| 4681 mark_object (&ptr->contents[i]); | 5412 mark_object (ptr->contents[i]); |
| 4682 | 5413 |
| 4683 /* Mark glyphs for leaf windows. Marking window matrices is | 5414 /* Mark glyphs for leaf windows. Marking window matrices is |
| 4684 sufficient because frame matrices use the same glyph | 5415 sufficient because frame matrices use the same glyph |
| 4685 memory. */ | 5416 memory. */ |
| 4686 if (NILP (w->hchild) | 5417 if (NILP (w->hchild) |
| 4692 } | 5423 } |
| 4693 } | 5424 } |
| 4694 else if (GC_HASH_TABLE_P (obj)) | 5425 else if (GC_HASH_TABLE_P (obj)) |
| 4695 { | 5426 { |
| 4696 struct Lisp_Hash_Table *h = XHASH_TABLE (obj); | 5427 struct Lisp_Hash_Table *h = XHASH_TABLE (obj); |
| 4697 EMACS_INT size = h->size; | |
| 4698 | 5428 |
| 4699 /* Stop if already marked. */ | 5429 /* Stop if already marked. */ |
| 4700 if (size & ARRAY_MARK_FLAG) | 5430 if (VECTOR_MARKED_P (h)) |
| 4701 break; | 5431 break; |
| 4702 | 5432 |
| 4703 /* Mark it. */ | 5433 /* Mark it. */ |
| 4704 CHECK_LIVE (live_vector_p); | 5434 CHECK_LIVE (live_vector_p); |
| 4705 h->size |= ARRAY_MARK_FLAG; | 5435 VECTOR_MARK (h); |
| 4706 | 5436 |
| 4707 /* Mark contents. */ | 5437 /* Mark contents. */ |
| 4708 /* Do not mark next_free or next_weak. | 5438 /* Do not mark next_free or next_weak. |
| 4709 Being in the next_weak chain | 5439 Being in the next_weak chain |
| 4710 should not keep the hash table alive. | 5440 should not keep the hash table alive. |
| 4711 No need to mark `count' since it is an integer. */ | 5441 No need to mark `count' since it is an integer. */ |
| 4712 mark_object (&h->test); | 5442 mark_object (h->test); |
| 4713 mark_object (&h->weak); | 5443 mark_object (h->weak); |
| 4714 mark_object (&h->rehash_size); | 5444 mark_object (h->rehash_size); |
| 4715 mark_object (&h->rehash_threshold); | 5445 mark_object (h->rehash_threshold); |
| 4716 mark_object (&h->hash); | 5446 mark_object (h->hash); |
| 4717 mark_object (&h->next); | 5447 mark_object (h->next); |
| 4718 mark_object (&h->index); | 5448 mark_object (h->index); |
| 4719 mark_object (&h->user_hash_function); | 5449 mark_object (h->user_hash_function); |
| 4720 mark_object (&h->user_cmp_function); | 5450 mark_object (h->user_cmp_function); |
| 4721 | 5451 |
| 4722 /* If hash table is not weak, mark all keys and values. | 5452 /* If hash table is not weak, mark all keys and values. |
| 4723 For weak tables, mark only the vector. */ | 5453 For weak tables, mark only the vector. */ |
| 4724 if (GC_NILP (h->weak)) | 5454 if (GC_NILP (h->weak)) |
| 4725 mark_object (&h->key_and_value); | 5455 mark_object (h->key_and_value); |
| 4726 else | 5456 else |
| 4727 XVECTOR (h->key_and_value)->size |= ARRAY_MARK_FLAG; | 5457 VECTOR_MARK (XVECTOR (h->key_and_value)); |
| 4728 | |
| 4729 } | 5458 } |
| 4730 else | 5459 else |
| 4731 { | 5460 { |
| 4732 register struct Lisp_Vector *ptr = XVECTOR (obj); | 5461 register struct Lisp_Vector *ptr = XVECTOR (obj); |
| 4733 register EMACS_INT size = ptr->size; | 5462 register EMACS_INT size = ptr->size; |
| 4734 register int i; | 5463 register int i; |
| 4735 | 5464 |
| 4736 if (size & ARRAY_MARK_FLAG) break; /* Already marked */ | 5465 if (VECTOR_MARKED_P (ptr)) break; /* Already marked */ |
| 4737 CHECK_LIVE (live_vector_p); | 5466 CHECK_LIVE (live_vector_p); |
| 4738 ptr->size |= ARRAY_MARK_FLAG; /* Else mark it */ | 5467 VECTOR_MARK (ptr); /* Else mark it */ |
| 4739 if (size & PSEUDOVECTOR_FLAG) | 5468 if (size & PSEUDOVECTOR_FLAG) |
| 4740 size &= PSEUDOVECTOR_SIZE_MASK; | 5469 size &= PSEUDOVECTOR_SIZE_MASK; |
| 4741 | 5470 |
| 4742 for (i = 0; i < size; i++) /* and then mark its elements */ | 5471 for (i = 0; i < size; i++) /* and then mark its elements */ |
| 4743 mark_object (&ptr->contents[i]); | 5472 mark_object (ptr->contents[i]); |
| 4744 } | 5473 } |
| 4745 break; | 5474 break; |
| 4746 | 5475 |
| 4747 case Lisp_Symbol: | 5476 case Lisp_Symbol: |
| 4748 { | 5477 { |
| 4749 register struct Lisp_Symbol *ptr = XSYMBOL (obj); | 5478 register struct Lisp_Symbol *ptr = XSYMBOL (obj); |
| 4750 struct Lisp_Symbol *ptrx; | 5479 struct Lisp_Symbol *ptrx; |
| 4751 | 5480 |
| 4752 if (XMARKBIT (ptr->plist)) break; | 5481 if (ptr->gcmarkbit) break; |
| 4753 CHECK_ALLOCATED_AND_LIVE (live_symbol_p); | 5482 CHECK_ALLOCATED_AND_LIVE (live_symbol_p); |
| 4754 XMARK (ptr->plist); | 5483 ptr->gcmarkbit = 1; |
| 4755 mark_object ((Lisp_Object *) &ptr->value); | 5484 mark_object (ptr->value); |
| 4756 mark_object (&ptr->function); | 5485 mark_object (ptr->function); |
| 4757 mark_object (&ptr->plist); | 5486 mark_object (ptr->plist); |
| 4758 | 5487 |
| 4759 if (!PURE_POINTER_P (XSTRING (ptr->xname))) | 5488 if (!PURE_POINTER_P (XSTRING (ptr->xname))) |
| 4760 MARK_STRING (XSTRING (ptr->xname)); | 5489 MARK_STRING (XSTRING (ptr->xname)); |
| 4761 MARK_INTERVAL_TREE (STRING_INTERVALS (ptr->xname)); | 5490 MARK_INTERVAL_TREE (STRING_INTERVALS (ptr->xname)); |
| 4762 | 5491 |
| 4764 It is safe not to do so because nothing accesses that | 5493 It is safe not to do so because nothing accesses that |
| 4765 slot except to check whether it is nil. */ | 5494 slot except to check whether it is nil. */ |
| 4766 ptr = ptr->next; | 5495 ptr = ptr->next; |
| 4767 if (ptr) | 5496 if (ptr) |
| 4768 { | 5497 { |
| 4769 /* For the benefit of the last_marked log. */ | |
| 4770 objptr = (Lisp_Object *)&XSYMBOL (obj)->next; | |
| 4771 ptrx = ptr; /* Use of ptrx avoids compiler bug on Sun */ | 5498 ptrx = ptr; /* Use of ptrx avoids compiler bug on Sun */ |
| 4772 XSETSYMBOL (obj, ptrx); | 5499 XSETSYMBOL (obj, ptrx); |
| 4773 /* We can't goto loop here because *objptr doesn't contain an | 5500 goto loop; |
| 4774 actual Lisp_Object with valid datatype field. */ | |
| 4775 goto loop2; | |
| 4776 } | 5501 } |
| 4777 } | 5502 } |
| 4778 break; | 5503 break; |
| 4779 | 5504 |
| 4780 case Lisp_Misc: | 5505 case Lisp_Misc: |
| 4781 CHECK_ALLOCATED_AND_LIVE (live_misc_p); | 5506 CHECK_ALLOCATED_AND_LIVE (live_misc_p); |
| 5507 if (XMARKER (obj)->gcmarkbit) | |
| 5508 break; | |
| 5509 XMARKER (obj)->gcmarkbit = 1; | |
| 5510 | |
| 4782 switch (XMISCTYPE (obj)) | 5511 switch (XMISCTYPE (obj)) |
| 4783 { | 5512 { |
| 4784 case Lisp_Misc_Marker: | |
| 4785 XMARK (XMARKER (obj)->chain); | |
| 4786 /* DO NOT mark thru the marker's chain. | |
| 4787 The buffer's markers chain does not preserve markers from gc; | |
| 4788 instead, markers are removed from the chain when freed by gc. */ | |
| 4789 break; | |
| 4790 | |
| 4791 case Lisp_Misc_Buffer_Local_Value: | 5513 case Lisp_Misc_Buffer_Local_Value: |
| 4792 case Lisp_Misc_Some_Buffer_Local_Value: | 5514 case Lisp_Misc_Some_Buffer_Local_Value: |
| 4793 { | 5515 { |
| 4794 register struct Lisp_Buffer_Local_Value *ptr | 5516 register struct Lisp_Buffer_Local_Value *ptr |
| 4795 = XBUFFER_LOCAL_VALUE (obj); | 5517 = XBUFFER_LOCAL_VALUE (obj); |
| 4796 if (XMARKBIT (ptr->realvalue)) break; | |
| 4797 XMARK (ptr->realvalue); | |
| 4798 /* If the cdr is nil, avoid recursion for the car. */ | 5518 /* If the cdr is nil, avoid recursion for the car. */ |
| 4799 if (EQ (ptr->cdr, Qnil)) | 5519 if (EQ (ptr->cdr, Qnil)) |
| 4800 { | 5520 { |
| 4801 objptr = &ptr->realvalue; | 5521 obj = ptr->realvalue; |
| 4802 goto loop; | 5522 goto loop; |
| 4803 } | 5523 } |
| 4804 mark_object (&ptr->realvalue); | 5524 mark_object (ptr->realvalue); |
| 4805 mark_object (&ptr->buffer); | 5525 mark_object (ptr->buffer); |
| 4806 mark_object (&ptr->frame); | 5526 mark_object (ptr->frame); |
| 4807 objptr = &ptr->cdr; | 5527 obj = ptr->cdr; |
| 4808 goto loop; | 5528 goto loop; |
| 4809 } | 5529 } |
| 5530 | |
| 5531 case Lisp_Misc_Marker: | |
| 5532 /* DO NOT mark thru the marker's chain. | |
| 5533 The buffer's markers chain does not preserve markers from gc; | |
| 5534 instead, markers are removed from the chain when freed by gc. */ | |
| 5535 break; | |
| 4810 | 5536 |
| 4811 case Lisp_Misc_Intfwd: | 5537 case Lisp_Misc_Intfwd: |
| 4812 case Lisp_Misc_Boolfwd: | 5538 case Lisp_Misc_Boolfwd: |
| 4813 case Lisp_Misc_Objfwd: | 5539 case Lisp_Misc_Objfwd: |
| 4814 case Lisp_Misc_Buffer_Objfwd: | 5540 case Lisp_Misc_Buffer_Objfwd: |
| 4817 since all markable slots in current buffer marked anyway. */ | 5543 since all markable slots in current buffer marked anyway. */ |
| 4818 /* Don't need to do Lisp_Objfwd, since the places they point | 5544 /* Don't need to do Lisp_Objfwd, since the places they point |
| 4819 are protected with staticpro. */ | 5545 are protected with staticpro. */ |
| 4820 break; | 5546 break; |
| 4821 | 5547 |
| 5548 case Lisp_Misc_Save_Value: | |
| 5549 #if GC_MARK_STACK | |
| 5550 { | |
| 5551 register struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj); | |
| 5552 /* If DOGC is set, POINTER is the address of a memory | |
| 5553 area containing INTEGER potential Lisp_Objects. */ | |
| 5554 if (ptr->dogc) | |
| 5555 { | |
| 5556 Lisp_Object *p = (Lisp_Object *) ptr->pointer; | |
| 5557 int nelt; | |
| 5558 for (nelt = ptr->integer; nelt > 0; nelt--, p++) | |
| 5559 mark_maybe_object (*p); | |
| 5560 } | |
| 5561 } | |
| 5562 #endif | |
| 5563 break; | |
| 5564 | |
| 4822 case Lisp_Misc_Overlay: | 5565 case Lisp_Misc_Overlay: |
| 4823 { | 5566 { |
| 4824 struct Lisp_Overlay *ptr = XOVERLAY (obj); | 5567 struct Lisp_Overlay *ptr = XOVERLAY (obj); |
| 4825 if (!XMARKBIT (ptr->plist)) | 5568 mark_object (ptr->start); |
| 5569 mark_object (ptr->end); | |
| 5570 mark_object (ptr->plist); | |
| 5571 if (ptr->next) | |
| 4826 { | 5572 { |
| 4827 XMARK (ptr->plist); | 5573 XSETMISC (obj, ptr->next); |
| 4828 mark_object (&ptr->start); | |
| 4829 mark_object (&ptr->end); | |
| 4830 objptr = &ptr->plist; | |
| 4831 goto loop; | 5574 goto loop; |
| 4832 } | 5575 } |
| 4833 } | 5576 } |
| 4834 break; | 5577 break; |
| 4835 | 5578 |
| 4839 break; | 5582 break; |
| 4840 | 5583 |
| 4841 case Lisp_Cons: | 5584 case Lisp_Cons: |
| 4842 { | 5585 { |
| 4843 register struct Lisp_Cons *ptr = XCONS (obj); | 5586 register struct Lisp_Cons *ptr = XCONS (obj); |
| 4844 if (XMARKBIT (ptr->car)) break; | 5587 if (CONS_MARKED_P (ptr)) break; |
| 4845 CHECK_ALLOCATED_AND_LIVE (live_cons_p); | 5588 CHECK_ALLOCATED_AND_LIVE (live_cons_p); |
| 4846 XMARK (ptr->car); | 5589 CONS_MARK (ptr); |
| 4847 /* If the cdr is nil, avoid recursion for the car. */ | 5590 /* If the cdr is nil, avoid recursion for the car. */ |
| 4848 if (EQ (ptr->cdr, Qnil)) | 5591 if (EQ (ptr->u.cdr, Qnil)) |
| 4849 { | 5592 { |
| 4850 objptr = &ptr->car; | 5593 obj = ptr->car; |
| 4851 cdr_count = 0; | 5594 cdr_count = 0; |
| 4852 goto loop; | 5595 goto loop; |
| 4853 } | 5596 } |
| 4854 mark_object (&ptr->car); | 5597 mark_object (ptr->car); |
| 4855 objptr = &ptr->cdr; | 5598 obj = ptr->u.cdr; |
| 4856 cdr_count++; | 5599 cdr_count++; |
| 4857 if (cdr_count == mark_object_loop_halt) | 5600 if (cdr_count == mark_object_loop_halt) |
| 4858 abort (); | 5601 abort (); |
| 4859 goto loop; | 5602 goto loop; |
| 4860 } | 5603 } |
| 4861 | 5604 |
| 4862 case Lisp_Float: | 5605 case Lisp_Float: |
| 4863 CHECK_ALLOCATED_AND_LIVE (live_float_p); | 5606 CHECK_ALLOCATED_AND_LIVE (live_float_p); |
| 4864 XMARK (XFLOAT (obj)->type); | 5607 FLOAT_MARK (XFLOAT (obj)); |
| 4865 break; | 5608 break; |
| 4866 | 5609 |
| 4867 case Lisp_Int: | 5610 case Lisp_Int: |
| 4868 break; | 5611 break; |
| 4869 | 5612 |
| 4881 static void | 5624 static void |
| 4882 mark_buffer (buf) | 5625 mark_buffer (buf) |
| 4883 Lisp_Object buf; | 5626 Lisp_Object buf; |
| 4884 { | 5627 { |
| 4885 register struct buffer *buffer = XBUFFER (buf); | 5628 register struct buffer *buffer = XBUFFER (buf); |
| 4886 register Lisp_Object *ptr; | 5629 register Lisp_Object *ptr, tmp; |
| 4887 Lisp_Object base_buffer; | 5630 Lisp_Object base_buffer; |
| 4888 | 5631 |
| 4889 /* This is the buffer's markbit */ | 5632 VECTOR_MARK (buffer); |
| 4890 mark_object (&buffer->name); | |
| 4891 XMARK (buffer->name); | |
| 4892 | 5633 |
| 4893 MARK_INTERVAL_TREE (BUF_INTERVALS (buffer)); | 5634 MARK_INTERVAL_TREE (BUF_INTERVALS (buffer)); |
| 4894 | 5635 |
| 4895 if (CONSP (buffer->undo_list)) | 5636 /* For now, we just don't mark the undo_list. It's done later in |
| 4896 { | 5637 a special way just before the sweep phase, and after stripping |
| 4897 Lisp_Object tail; | 5638 some of its elements that are not needed any more. */ |
| 4898 tail = buffer->undo_list; | 5639 |
| 4899 | 5640 if (buffer->overlays_before) |
| 4900 while (CONSP (tail)) | 5641 { |
| 4901 { | 5642 XSETMISC (tmp, buffer->overlays_before); |
| 4902 register struct Lisp_Cons *ptr = XCONS (tail); | 5643 mark_object (tmp); |
| 4903 | 5644 } |
| 4904 if (XMARKBIT (ptr->car)) | 5645 if (buffer->overlays_after) |
| 4905 break; | 5646 { |
| 4906 XMARK (ptr->car); | 5647 XSETMISC (tmp, buffer->overlays_after); |
| 4907 if (GC_CONSP (ptr->car) | 5648 mark_object (tmp); |
| 4908 && ! XMARKBIT (XCAR (ptr->car)) | 5649 } |
| 4909 && GC_MARKERP (XCAR (ptr->car))) | 5650 |
| 4910 { | 5651 for (ptr = &buffer->name; |
| 4911 XMARK (XCAR_AS_LVALUE (ptr->car)); | |
| 4912 mark_object (&XCDR_AS_LVALUE (ptr->car)); | |
| 4913 } | |
| 4914 else | |
| 4915 mark_object (&ptr->car); | |
| 4916 | |
| 4917 if (CONSP (ptr->cdr)) | |
| 4918 tail = ptr->cdr; | |
| 4919 else | |
| 4920 break; | |
| 4921 } | |
| 4922 | |
| 4923 mark_object (&XCDR_AS_LVALUE (tail)); | |
| 4924 } | |
| 4925 else | |
| 4926 mark_object (&buffer->undo_list); | |
| 4927 | |
| 4928 for (ptr = &buffer->name + 1; | |
| 4929 (char *)ptr < (char *)buffer + sizeof (struct buffer); | 5652 (char *)ptr < (char *)buffer + sizeof (struct buffer); |
| 4930 ptr++) | 5653 ptr++) |
| 4931 mark_object (ptr); | 5654 mark_object (*ptr); |
| 4932 | 5655 |
| 4933 /* If this is an indirect buffer, mark its base buffer. */ | 5656 /* If this is an indirect buffer, mark its base buffer. */ |
| 4934 if (buffer->base_buffer && !XMARKBIT (buffer->base_buffer->name)) | 5657 if (buffer->base_buffer && !VECTOR_MARKED_P (buffer->base_buffer)) |
| 4935 { | 5658 { |
| 4936 XSETBUFFER (base_buffer, buffer->base_buffer); | 5659 XSETBUFFER (base_buffer, buffer->base_buffer); |
| 4937 mark_buffer (base_buffer); | 5660 mark_buffer (base_buffer); |
| 4938 } | |
| 4939 } | |
| 4940 | |
| 4941 | |
| 4942 /* Mark the pointers in the kboard objects. */ | |
| 4943 | |
| 4944 static void | |
| 4945 mark_kboards () | |
| 4946 { | |
| 4947 KBOARD *kb; | |
| 4948 Lisp_Object *p; | |
| 4949 for (kb = all_kboards; kb; kb = kb->next_kboard) | |
| 4950 { | |
| 4951 if (kb->kbd_macro_buffer) | |
| 4952 for (p = kb->kbd_macro_buffer; p < kb->kbd_macro_ptr; p++) | |
| 4953 mark_object (p); | |
| 4954 mark_object (&kb->Voverriding_terminal_local_map); | |
| 4955 mark_object (&kb->Vlast_command); | |
| 4956 mark_object (&kb->Vreal_last_command); | |
| 4957 mark_object (&kb->Vprefix_arg); | |
| 4958 mark_object (&kb->Vlast_prefix_arg); | |
| 4959 mark_object (&kb->kbd_queue); | |
| 4960 mark_object (&kb->defining_kbd_macro); | |
| 4961 mark_object (&kb->Vlast_kbd_macro); | |
| 4962 mark_object (&kb->Vsystem_key_alist); | |
| 4963 mark_object (&kb->system_key_syms); | |
| 4964 mark_object (&kb->Vdefault_minibuffer_frame); | |
| 4965 mark_object (&kb->echo_string); | |
| 4966 } | 5661 } |
| 4967 } | 5662 } |
| 4968 | 5663 |
| 4969 | 5664 |
| 4970 /* Value is non-zero if OBJ will survive the current GC because it's | 5665 /* Value is non-zero if OBJ will survive the current GC because it's |
| 4981 case Lisp_Int: | 5676 case Lisp_Int: |
| 4982 survives_p = 1; | 5677 survives_p = 1; |
| 4983 break; | 5678 break; |
| 4984 | 5679 |
| 4985 case Lisp_Symbol: | 5680 case Lisp_Symbol: |
| 4986 survives_p = XMARKBIT (XSYMBOL (obj)->plist); | 5681 survives_p = XSYMBOL (obj)->gcmarkbit; |
| 4987 break; | 5682 break; |
| 4988 | 5683 |
| 4989 case Lisp_Misc: | 5684 case Lisp_Misc: |
| 4990 switch (XMISCTYPE (obj)) | 5685 survives_p = XMARKER (obj)->gcmarkbit; |
| 4991 { | |
| 4992 case Lisp_Misc_Marker: | |
| 4993 survives_p = XMARKBIT (obj); | |
| 4994 break; | |
| 4995 | |
| 4996 case Lisp_Misc_Buffer_Local_Value: | |
| 4997 case Lisp_Misc_Some_Buffer_Local_Value: | |
| 4998 survives_p = XMARKBIT (XBUFFER_LOCAL_VALUE (obj)->realvalue); | |
| 4999 break; | |
| 5000 | |
| 5001 case Lisp_Misc_Intfwd: | |
| 5002 case Lisp_Misc_Boolfwd: | |
| 5003 case Lisp_Misc_Objfwd: | |
| 5004 case Lisp_Misc_Buffer_Objfwd: | |
| 5005 case Lisp_Misc_Kboard_Objfwd: | |
| 5006 survives_p = 1; | |
| 5007 break; | |
| 5008 | |
| 5009 case Lisp_Misc_Overlay: | |
| 5010 survives_p = XMARKBIT (XOVERLAY (obj)->plist); | |
| 5011 break; | |
| 5012 | |
| 5013 default: | |
| 5014 abort (); | |
| 5015 } | |
| 5016 break; | 5686 break; |
| 5017 | 5687 |
| 5018 case Lisp_String: | 5688 case Lisp_String: |
| 5019 { | 5689 survives_p = STRING_MARKED_P (XSTRING (obj)); |
| 5020 struct Lisp_String *s = XSTRING (obj); | |
| 5021 survives_p = STRING_MARKED_P (s); | |
| 5022 } | |
| 5023 break; | 5690 break; |
| 5024 | 5691 |
| 5025 case Lisp_Vectorlike: | 5692 case Lisp_Vectorlike: |
| 5026 if (GC_BUFFERP (obj)) | 5693 survives_p = GC_SUBRP (obj) || VECTOR_MARKED_P (XVECTOR (obj)); |
| 5027 survives_p = XMARKBIT (XBUFFER (obj)->name); | |
| 5028 else if (GC_SUBRP (obj)) | |
| 5029 survives_p = 1; | |
| 5030 else | |
| 5031 survives_p = XVECTOR (obj)->size & ARRAY_MARK_FLAG; | |
| 5032 break; | 5694 break; |
| 5033 | 5695 |
| 5034 case Lisp_Cons: | 5696 case Lisp_Cons: |
| 5035 survives_p = XMARKBIT (XCAR (obj)); | 5697 survives_p = CONS_MARKED_P (XCONS (obj)); |
| 5036 break; | 5698 break; |
| 5037 | 5699 |
| 5038 case Lisp_Float: | 5700 case Lisp_Float: |
| 5039 survives_p = XMARKBIT (XFLOAT (obj)->type); | 5701 survives_p = FLOAT_MARKED_P (XFLOAT (obj)); |
| 5040 break; | 5702 break; |
| 5041 | 5703 |
| 5042 default: | 5704 default: |
| 5043 abort (); | 5705 abort (); |
| 5044 } | 5706 } |
| 5075 for (cblk = cons_block; cblk; cblk = *cprev) | 5737 for (cblk = cons_block; cblk; cblk = *cprev) |
| 5076 { | 5738 { |
| 5077 register int i; | 5739 register int i; |
| 5078 int this_free = 0; | 5740 int this_free = 0; |
| 5079 for (i = 0; i < lim; i++) | 5741 for (i = 0; i < lim; i++) |
| 5080 if (!XMARKBIT (cblk->conses[i].car)) | 5742 if (!CONS_MARKED_P (&cblk->conses[i])) |
| 5081 { | 5743 { |
| 5082 this_free++; | 5744 this_free++; |
| 5083 *(struct Lisp_Cons **)&cblk->conses[i].cdr = cons_free_list; | 5745 cblk->conses[i].u.chain = cons_free_list; |
| 5084 cons_free_list = &cblk->conses[i]; | 5746 cons_free_list = &cblk->conses[i]; |
| 5085 #if GC_MARK_STACK | 5747 #if GC_MARK_STACK |
| 5086 cons_free_list->car = Vdead; | 5748 cons_free_list->car = Vdead; |
| 5087 #endif | 5749 #endif |
| 5088 } | 5750 } |
| 5089 else | 5751 else |
| 5090 { | 5752 { |
| 5091 num_used++; | 5753 num_used++; |
| 5092 XUNMARK (cblk->conses[i].car); | 5754 CONS_UNMARK (&cblk->conses[i]); |
| 5093 } | 5755 } |
| 5094 lim = CONS_BLOCK_SIZE; | 5756 lim = CONS_BLOCK_SIZE; |
| 5095 /* If this block contains only free conses and we have already | 5757 /* If this block contains only free conses and we have already |
| 5096 seen more than two blocks worth of free conses then deallocate | 5758 seen more than two blocks worth of free conses then deallocate |
| 5097 this block. */ | 5759 this block. */ |
| 5098 if (this_free == CONS_BLOCK_SIZE && num_free > CONS_BLOCK_SIZE) | 5760 if (this_free == CONS_BLOCK_SIZE && num_free > CONS_BLOCK_SIZE) |
| 5099 { | 5761 { |
| 5100 *cprev = cblk->next; | 5762 *cprev = cblk->next; |
| 5101 /* Unhook from the free list. */ | 5763 /* Unhook from the free list. */ |
| 5102 cons_free_list = *(struct Lisp_Cons **) &cblk->conses[0].cdr; | 5764 cons_free_list = cblk->conses[0].u.chain; |
| 5103 lisp_free (cblk); | 5765 lisp_align_free (cblk); |
| 5104 n_cons_blocks--; | 5766 n_cons_blocks--; |
| 5105 } | 5767 } |
| 5106 else | 5768 else |
| 5107 { | 5769 { |
| 5108 num_free += this_free; | 5770 num_free += this_free; |
| 5125 for (fblk = float_block; fblk; fblk = *fprev) | 5787 for (fblk = float_block; fblk; fblk = *fprev) |
| 5126 { | 5788 { |
| 5127 register int i; | 5789 register int i; |
| 5128 int this_free = 0; | 5790 int this_free = 0; |
| 5129 for (i = 0; i < lim; i++) | 5791 for (i = 0; i < lim; i++) |
| 5130 if (!XMARKBIT (fblk->floats[i].type)) | 5792 if (!FLOAT_MARKED_P (&fblk->floats[i])) |
| 5131 { | 5793 { |
| 5132 this_free++; | 5794 this_free++; |
| 5133 *(struct Lisp_Float **)&fblk->floats[i].data = float_free_list; | 5795 fblk->floats[i].u.chain = float_free_list; |
| 5134 float_free_list = &fblk->floats[i]; | 5796 float_free_list = &fblk->floats[i]; |
| 5135 #if GC_MARK_STACK | |
| 5136 float_free_list->type = Vdead; | |
| 5137 #endif | |
| 5138 } | 5797 } |
| 5139 else | 5798 else |
| 5140 { | 5799 { |
| 5141 num_used++; | 5800 num_used++; |
| 5142 XUNMARK (fblk->floats[i].type); | 5801 FLOAT_UNMARK (&fblk->floats[i]); |
| 5143 } | 5802 } |
| 5144 lim = FLOAT_BLOCK_SIZE; | 5803 lim = FLOAT_BLOCK_SIZE; |
| 5145 /* If this block contains only free floats and we have already | 5804 /* If this block contains only free floats and we have already |
| 5146 seen more than two blocks worth of free floats then deallocate | 5805 seen more than two blocks worth of free floats then deallocate |
| 5147 this block. */ | 5806 this block. */ |
| 5148 if (this_free == FLOAT_BLOCK_SIZE && num_free > FLOAT_BLOCK_SIZE) | 5807 if (this_free == FLOAT_BLOCK_SIZE && num_free > FLOAT_BLOCK_SIZE) |
| 5149 { | 5808 { |
| 5150 *fprev = fblk->next; | 5809 *fprev = fblk->next; |
| 5151 /* Unhook from the free list. */ | 5810 /* Unhook from the free list. */ |
| 5152 float_free_list = *(struct Lisp_Float **) &fblk->floats[0].data; | 5811 float_free_list = fblk->floats[0].u.chain; |
| 5153 lisp_free (fblk); | 5812 lisp_align_free (fblk); |
| 5154 n_float_blocks--; | 5813 n_float_blocks--; |
| 5155 } | 5814 } |
| 5156 else | 5815 else |
| 5157 { | 5816 { |
| 5158 num_free += this_free; | 5817 num_free += this_free; |
| 5177 register int i; | 5836 register int i; |
| 5178 int this_free = 0; | 5837 int this_free = 0; |
| 5179 | 5838 |
| 5180 for (i = 0; i < lim; i++) | 5839 for (i = 0; i < lim; i++) |
| 5181 { | 5840 { |
| 5182 if (! XMARKBIT (iblk->intervals[i].plist)) | 5841 if (!iblk->intervals[i].gcmarkbit) |
| 5183 { | 5842 { |
| 5184 SET_INTERVAL_PARENT (&iblk->intervals[i], interval_free_list); | 5843 SET_INTERVAL_PARENT (&iblk->intervals[i], interval_free_list); |
| 5185 interval_free_list = &iblk->intervals[i]; | 5844 interval_free_list = &iblk->intervals[i]; |
| 5186 this_free++; | 5845 this_free++; |
| 5187 } | 5846 } |
| 5188 else | 5847 else |
| 5189 { | 5848 { |
| 5190 num_used++; | 5849 num_used++; |
| 5191 XUNMARK (iblk->intervals[i].plist); | 5850 iblk->intervals[i].gcmarkbit = 0; |
| 5192 } | 5851 } |
| 5193 } | 5852 } |
| 5194 lim = INTERVAL_BLOCK_SIZE; | 5853 lim = INTERVAL_BLOCK_SIZE; |
| 5195 /* If this block contains only free intervals and we have already | 5854 /* If this block contains only free intervals and we have already |
| 5196 seen more than two blocks worth of free intervals then | 5855 seen more than two blocks worth of free intervals then |
| 5233 /* Check if the symbol was created during loadup. In such a case | 5892 /* Check if the symbol was created during loadup. In such a case |
| 5234 it might be pointed to by pure bytecode which we don't trace, | 5893 it might be pointed to by pure bytecode which we don't trace, |
| 5235 so we conservatively assume that it is live. */ | 5894 so we conservatively assume that it is live. */ |
| 5236 int pure_p = PURE_POINTER_P (XSTRING (sym->xname)); | 5895 int pure_p = PURE_POINTER_P (XSTRING (sym->xname)); |
| 5237 | 5896 |
| 5238 if (!XMARKBIT (sym->plist) && !pure_p) | 5897 if (!sym->gcmarkbit && !pure_p) |
| 5239 { | 5898 { |
| 5240 *(struct Lisp_Symbol **) &sym->value = symbol_free_list; | 5899 sym->next = symbol_free_list; |
| 5241 symbol_free_list = sym; | 5900 symbol_free_list = sym; |
| 5242 #if GC_MARK_STACK | 5901 #if GC_MARK_STACK |
| 5243 symbol_free_list->function = Vdead; | 5902 symbol_free_list->function = Vdead; |
| 5244 #endif | 5903 #endif |
| 5245 ++this_free; | 5904 ++this_free; |
| 5247 else | 5906 else |
| 5248 { | 5907 { |
| 5249 ++num_used; | 5908 ++num_used; |
| 5250 if (!pure_p) | 5909 if (!pure_p) |
| 5251 UNMARK_STRING (XSTRING (sym->xname)); | 5910 UNMARK_STRING (XSTRING (sym->xname)); |
| 5252 XUNMARK (sym->plist); | 5911 sym->gcmarkbit = 0; |
| 5253 } | 5912 } |
| 5254 } | 5913 } |
| 5255 | 5914 |
| 5256 lim = SYMBOL_BLOCK_SIZE; | 5915 lim = SYMBOL_BLOCK_SIZE; |
| 5257 /* If this block contains only free symbols and we have already | 5916 /* If this block contains only free symbols and we have already |
| 5259 this block. */ | 5918 this block. */ |
| 5260 if (this_free == SYMBOL_BLOCK_SIZE && num_free > SYMBOL_BLOCK_SIZE) | 5919 if (this_free == SYMBOL_BLOCK_SIZE && num_free > SYMBOL_BLOCK_SIZE) |
| 5261 { | 5920 { |
| 5262 *sprev = sblk->next; | 5921 *sprev = sblk->next; |
| 5263 /* Unhook from the free list. */ | 5922 /* Unhook from the free list. */ |
| 5264 symbol_free_list = *(struct Lisp_Symbol **)&sblk->symbols[0].value; | 5923 symbol_free_list = sblk->symbols[0].next; |
| 5265 lisp_free (sblk); | 5924 lisp_free (sblk); |
| 5266 n_symbol_blocks--; | 5925 n_symbol_blocks--; |
| 5267 } | 5926 } |
| 5268 else | 5927 else |
| 5269 { | 5928 { |
| 5287 | 5946 |
| 5288 for (mblk = marker_block; mblk; mblk = *mprev) | 5947 for (mblk = marker_block; mblk; mblk = *mprev) |
| 5289 { | 5948 { |
| 5290 register int i; | 5949 register int i; |
| 5291 int this_free = 0; | 5950 int this_free = 0; |
| 5292 EMACS_INT already_free = -1; | |
| 5293 | 5951 |
| 5294 for (i = 0; i < lim; i++) | 5952 for (i = 0; i < lim; i++) |
| 5295 { | 5953 { |
| 5296 Lisp_Object *markword; | 5954 if (!mblk->markers[i].u_marker.gcmarkbit) |
| 5297 switch (mblk->markers[i].u_marker.type) | |
| 5298 { | 5955 { |
| 5299 case Lisp_Misc_Marker: | |
| 5300 markword = &mblk->markers[i].u_marker.chain; | |
| 5301 break; | |
| 5302 case Lisp_Misc_Buffer_Local_Value: | |
| 5303 case Lisp_Misc_Some_Buffer_Local_Value: | |
| 5304 markword = &mblk->markers[i].u_buffer_local_value.realvalue; | |
| 5305 break; | |
| 5306 case Lisp_Misc_Overlay: | |
| 5307 markword = &mblk->markers[i].u_overlay.plist; | |
| 5308 break; | |
| 5309 case Lisp_Misc_Free: | |
| 5310 /* If the object was already free, keep it | |
| 5311 on the free list. */ | |
| 5312 markword = (Lisp_Object *) &already_free; | |
| 5313 break; | |
| 5314 default: | |
| 5315 markword = 0; | |
| 5316 break; | |
| 5317 } | |
| 5318 if (markword && !XMARKBIT (*markword)) | |
| 5319 { | |
| 5320 Lisp_Object tem; | |
| 5321 if (mblk->markers[i].u_marker.type == Lisp_Misc_Marker) | 5956 if (mblk->markers[i].u_marker.type == Lisp_Misc_Marker) |
| 5322 { | 5957 unchain_marker (&mblk->markers[i].u_marker); |
| 5323 /* tem1 avoids Sun compiler bug */ | |
| 5324 struct Lisp_Marker *tem1 = &mblk->markers[i].u_marker; | |
| 5325 XSETMARKER (tem, tem1); | |
| 5326 unchain_marker (tem); | |
| 5327 } | |
| 5328 /* Set the type of the freed object to Lisp_Misc_Free. | 5958 /* Set the type of the freed object to Lisp_Misc_Free. |
| 5329 We could leave the type alone, since nobody checks it, | 5959 We could leave the type alone, since nobody checks it, |
| 5330 but this might catch bugs faster. */ | 5960 but this might catch bugs faster. */ |
| 5331 mblk->markers[i].u_marker.type = Lisp_Misc_Free; | 5961 mblk->markers[i].u_marker.type = Lisp_Misc_Free; |
| 5332 mblk->markers[i].u_free.chain = marker_free_list; | 5962 mblk->markers[i].u_free.chain = marker_free_list; |
| 5334 this_free++; | 5964 this_free++; |
| 5335 } | 5965 } |
| 5336 else | 5966 else |
| 5337 { | 5967 { |
| 5338 num_used++; | 5968 num_used++; |
| 5339 if (markword) | 5969 mblk->markers[i].u_marker.gcmarkbit = 0; |
| 5340 XUNMARK (*markword); | |
| 5341 } | 5970 } |
| 5342 } | 5971 } |
| 5343 lim = MARKER_BLOCK_SIZE; | 5972 lim = MARKER_BLOCK_SIZE; |
| 5344 /* If this block contains only free markers and we have already | 5973 /* If this block contains only free markers and we have already |
| 5345 seen more than two blocks worth of free markers then deallocate | 5974 seen more than two blocks worth of free markers then deallocate |
| 5366 /* Free all unmarked buffers */ | 5995 /* Free all unmarked buffers */ |
| 5367 { | 5996 { |
| 5368 register struct buffer *buffer = all_buffers, *prev = 0, *next; | 5997 register struct buffer *buffer = all_buffers, *prev = 0, *next; |
| 5369 | 5998 |
| 5370 while (buffer) | 5999 while (buffer) |
| 5371 if (!XMARKBIT (buffer->name)) | 6000 if (!VECTOR_MARKED_P (buffer)) |
| 5372 { | 6001 { |
| 5373 if (prev) | 6002 if (prev) |
| 5374 prev->next = buffer->next; | 6003 prev->next = buffer->next; |
| 5375 else | 6004 else |
| 5376 all_buffers = buffer->next; | 6005 all_buffers = buffer->next; |
| 5378 lisp_free (buffer); | 6007 lisp_free (buffer); |
| 5379 buffer = next; | 6008 buffer = next; |
| 5380 } | 6009 } |
| 5381 else | 6010 else |
| 5382 { | 6011 { |
| 5383 XUNMARK (buffer->name); | 6012 VECTOR_UNMARK (buffer); |
| 5384 UNMARK_BALANCE_INTERVALS (BUF_INTERVALS (buffer)); | 6013 UNMARK_BALANCE_INTERVALS (BUF_INTERVALS (buffer)); |
| 5385 prev = buffer, buffer = buffer->next; | 6014 prev = buffer, buffer = buffer->next; |
| 5386 } | 6015 } |
| 5387 } | 6016 } |
| 5388 | 6017 |
| 5390 { | 6019 { |
| 5391 register struct Lisp_Vector *vector = all_vectors, *prev = 0, *next; | 6020 register struct Lisp_Vector *vector = all_vectors, *prev = 0, *next; |
| 5392 total_vector_size = 0; | 6021 total_vector_size = 0; |
| 5393 | 6022 |
| 5394 while (vector) | 6023 while (vector) |
| 5395 if (!(vector->size & ARRAY_MARK_FLAG)) | 6024 if (!VECTOR_MARKED_P (vector)) |
| 5396 { | 6025 { |
| 5397 if (prev) | 6026 if (prev) |
| 5398 prev->next = vector->next; | 6027 prev->next = vector->next; |
| 5399 else | 6028 else |
| 5400 all_vectors = vector->next; | 6029 all_vectors = vector->next; |
| 5404 vector = next; | 6033 vector = next; |
| 5405 | 6034 |
| 5406 } | 6035 } |
| 5407 else | 6036 else |
| 5408 { | 6037 { |
| 5409 vector->size &= ~ARRAY_MARK_FLAG; | 6038 VECTOR_UNMARK (vector); |
| 5410 if (vector->size & PSEUDOVECTOR_FLAG) | 6039 if (vector->size & PSEUDOVECTOR_FLAG) |
| 5411 total_vector_size += (PSEUDOVECTOR_SIZE_MASK & vector->size); | 6040 total_vector_size += (PSEUDOVECTOR_SIZE_MASK & vector->size); |
| 5412 else | 6041 else |
| 5413 total_vector_size += vector->size; | 6042 total_vector_size += vector->size; |
| 5414 prev = vector, vector = vector->next; | 6043 prev = vector, vector = vector->next; |
| 5489 purebeg = PUREBEG; | 6118 purebeg = PUREBEG; |
| 5490 pure_size = PURESIZE; | 6119 pure_size = PURESIZE; |
| 5491 pure_bytes_used = 0; | 6120 pure_bytes_used = 0; |
| 5492 pure_bytes_used_before_overflow = 0; | 6121 pure_bytes_used_before_overflow = 0; |
| 5493 | 6122 |
| 6123 /* Initialize the list of free aligned blocks. */ | |
| 6124 free_ablock = NULL; | |
| 6125 | |
| 5494 #if GC_MARK_STACK || defined GC_MALLOC_CHECK | 6126 #if GC_MARK_STACK || defined GC_MALLOC_CHECK |
| 5495 mem_init (); | 6127 mem_init (); |
| 5496 Vdead = make_pure_string ("DEAD", 4, 4, 0); | 6128 Vdead = make_pure_string ("DEAD", 4, 4, 0); |
| 5497 #endif | 6129 #endif |
| 5498 | 6130 |
| 5514 malloc_hysteresis = 32; | 6146 malloc_hysteresis = 32; |
| 5515 #else | 6147 #else |
| 5516 malloc_hysteresis = 0; | 6148 malloc_hysteresis = 0; |
| 5517 #endif | 6149 #endif |
| 5518 | 6150 |
| 5519 spare_memory = (char *) malloc (SPARE_MEMORY); | 6151 refill_memory_reserve (); |
| 5520 | 6152 |
| 5521 ignore_warnings = 0; | 6153 ignore_warnings = 0; |
| 5522 gcprolist = 0; | 6154 gcprolist = 0; |
| 5523 byte_stack_list = 0; | 6155 byte_stack_list = 0; |
| 5524 staticidx = 0; | 6156 staticidx = 0; |
| 5525 consing_since_gc = 0; | 6157 consing_since_gc = 0; |
| 5526 gc_cons_threshold = 100000 * sizeof (Lisp_Object); | 6158 gc_cons_threshold = 100000 * sizeof (Lisp_Object); |
| 6159 gc_relative_threshold = 0; | |
| 6160 | |
| 5527 #ifdef VIRT_ADDR_VARIES | 6161 #ifdef VIRT_ADDR_VARIES |
| 5528 malloc_sbrk_unused = 1<<22; /* A large number */ | 6162 malloc_sbrk_unused = 1<<22; /* A large number */ |
| 5529 malloc_sbrk_used = 100000; /* as reasonable as any number */ | 6163 malloc_sbrk_used = 100000; /* as reasonable as any number */ |
| 5530 #endif /* VIRT_ADDR_VARIES */ | 6164 #endif /* VIRT_ADDR_VARIES */ |
| 5531 } | 6165 } |
| 5553 allocated since the last garbage collection. All data types count. | 6187 allocated since the last garbage collection. All data types count. |
| 5554 | 6188 |
| 5555 Garbage collection happens automatically only when `eval' is called. | 6189 Garbage collection happens automatically only when `eval' is called. |
| 5556 | 6190 |
| 5557 By binding this temporarily to a large number, you can effectively | 6191 By binding this temporarily to a large number, you can effectively |
| 5558 prevent garbage collection during a part of the program. */); | 6192 prevent garbage collection during a part of the program. |
| 6193 See also `gc-cons-percentage'. */); | |
| 6194 | |
| 6195 DEFVAR_LISP ("gc-cons-percentage", &Vgc_cons_percentage, | |
| 6196 doc: /* *Portion of the heap used for allocation. | |
| 6197 Garbage collection can happen automatically once this portion of the heap | |
| 6198 has been allocated since the last garbage collection. | |
| 6199 If this portion is smaller than `gc-cons-threshold', this is ignored. */); | |
| 6200 Vgc_cons_percentage = make_float (0.1); | |
| 5559 | 6201 |
| 5560 DEFVAR_INT ("pure-bytes-used", &pure_bytes_used, | 6202 DEFVAR_INT ("pure-bytes-used", &pure_bytes_used, |
| 5561 doc: /* Number of bytes of sharable Lisp data allocated so far. */); | 6203 doc: /* Number of bytes of sharable Lisp data allocated so far. */); |
| 5562 | 6204 |
| 5563 DEFVAR_INT ("cons-cells-consed", &cons_cells_consed, | 6205 DEFVAR_INT ("cons-cells-consed", &cons_cells_consed, |
| 5585 doc: /* Number of strings that have been consed so far. */); | 6227 doc: /* Number of strings that have been consed so far. */); |
| 5586 | 6228 |
| 5587 DEFVAR_LISP ("purify-flag", &Vpurify_flag, | 6229 DEFVAR_LISP ("purify-flag", &Vpurify_flag, |
| 5588 doc: /* Non-nil means loading Lisp code in order to dump an executable. | 6230 doc: /* Non-nil means loading Lisp code in order to dump an executable. |
| 5589 This means that certain objects should be allocated in shared (pure) space. */); | 6231 This means that certain objects should be allocated in shared (pure) space. */); |
| 5590 | |
| 5591 DEFVAR_INT ("undo-limit", &undo_limit, | |
| 5592 doc: /* Keep no more undo information once it exceeds this size. | |
| 5593 This limit is applied when garbage collection happens. | |
| 5594 The size is counted as the number of bytes occupied, | |
| 5595 which includes both saved text and other data. */); | |
| 5596 undo_limit = 20000; | |
| 5597 | |
| 5598 DEFVAR_INT ("undo-strong-limit", &undo_strong_limit, | |
| 5599 doc: /* Don't keep more than this much size of undo information. | |
| 5600 A command which pushes past this size is itself forgotten. | |
| 5601 This limit is applied when garbage collection happens. | |
| 5602 The size is counted as the number of bytes occupied, | |
| 5603 which includes both saved text and other data. */); | |
| 5604 undo_strong_limit = 30000; | |
| 5605 | 6232 |
| 5606 DEFVAR_BOOL ("garbage-collection-messages", &garbage_collection_messages, | 6233 DEFVAR_BOOL ("garbage-collection-messages", &garbage_collection_messages, |
| 5607 doc: /* Non-nil means display messages at start and end of garbage collection. */); | 6234 doc: /* Non-nil means display messages at start and end of garbage collection. */); |
| 5608 garbage_collection_messages = 0; | 6235 garbage_collection_messages = 0; |
| 5609 | 6236 |
| 5620 Vmemory_signal_data | 6247 Vmemory_signal_data |
| 5621 = list2 (Qerror, | 6248 = list2 (Qerror, |
| 5622 build_string ("Memory exhausted--use M-x save-some-buffers then exit and restart Emacs")); | 6249 build_string ("Memory exhausted--use M-x save-some-buffers then exit and restart Emacs")); |
| 5623 | 6250 |
| 5624 DEFVAR_LISP ("memory-full", &Vmemory_full, | 6251 DEFVAR_LISP ("memory-full", &Vmemory_full, |
| 5625 doc: /* Non-nil means we are handling a memory-full error. */); | 6252 doc: /* Non-nil means Emacs cannot get much more Lisp memory. */); |
| 5626 Vmemory_full = Qnil; | 6253 Vmemory_full = Qnil; |
| 5627 | 6254 |
| 5628 staticpro (&Qgc_cons_threshold); | 6255 staticpro (&Qgc_cons_threshold); |
| 5629 Qgc_cons_threshold = intern ("gc-cons-threshold"); | 6256 Qgc_cons_threshold = intern ("gc-cons-threshold"); |
| 5630 | 6257 |
| 5631 staticpro (&Qchar_table_extra_slots); | 6258 staticpro (&Qchar_table_extra_slots); |
| 5632 Qchar_table_extra_slots = intern ("char-table-extra-slots"); | 6259 Qchar_table_extra_slots = intern ("char-table-extra-slots"); |
| 5633 | 6260 |
| 5634 DEFVAR_LISP ("gc-elapsed", &Vgc_elapsed, | 6261 DEFVAR_LISP ("gc-elapsed", &Vgc_elapsed, |
| 5635 doc: /* Accumulated time elapsed in garbage collections. | 6262 doc: /* Accumulated time elapsed in garbage collections. |
| 5636 The time is in seconds as a floating point value. | 6263 The time is in seconds as a floating point value. */); |
| 5637 Programs may reset this to get statistics in a specific period. */); | |
| 5638 DEFVAR_INT ("gcs-done", &gcs_done, | 6264 DEFVAR_INT ("gcs-done", &gcs_done, |
| 5639 doc: /* Accumulated number of garbage collections done. | 6265 doc: /* Accumulated number of garbage collections done. */); |
| 5640 Programs may reset this to get statistics in a specific period. */); | |
| 5641 | 6266 |
| 5642 defsubr (&Scons); | 6267 defsubr (&Scons); |
| 5643 defsubr (&Slist); | 6268 defsubr (&Slist); |
| 5644 defsubr (&Svector); | 6269 defsubr (&Svector); |
| 5645 defsubr (&Smake_byte_code); | 6270 defsubr (&Smake_byte_code); |
| 5657 | 6282 |
| 5658 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES | 6283 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES |
| 5659 defsubr (&Sgc_status); | 6284 defsubr (&Sgc_status); |
| 5660 #endif | 6285 #endif |
| 5661 } | 6286 } |
| 6287 | |
| 6288 /* arch-tag: 6695ca10-e3c5-4c2c-8bc3-ed26a7dda857 | |
| 6289 (do not change this comment) */ |
