aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorStefan Monnier2011-02-01 12:09:25 -0500
committerStefan Monnier2011-02-01 12:09:25 -0500
commit8f1d2ef658f95549eb33fe5265f8f11c5129bece (patch)
treeb7cd852a1adb423384532cfe22c31547160b22bc /src/alloc.c
parent590130fb19e1f433965c421d98fedeb2d7c33310 (diff)
parent1dc4075fa8809805aed5092e93e225e889725c94 (diff)
downloademacs-8f1d2ef658f95549eb33fe5265f8f11c5129bece.tar.gz
emacs-8f1d2ef658f95549eb33fe5265f8f11c5129bece.zip
Merge from trunk
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c117
1 files changed, 44 insertions, 73 deletions
diff --git a/src/alloc.c b/src/alloc.c
index b18fd6feb3d..990622a30f6 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1,6 +1,5 @@
1/* Storage allocation and gc for GNU Emacs Lisp interpreter. 1/* Storage allocation and gc for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 1986, 1988, 1993, 1994, 1995, 1997, 1998, 1999, 2 Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2011
3 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
5 4
6This file is part of GNU Emacs. 5This file is part of GNU Emacs.
@@ -59,9 +58,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
59#undef GC_MALLOC_CHECK 58#undef GC_MALLOC_CHECK
60#endif 59#endif
61 60
62#ifdef HAVE_UNISTD_H
63#include <unistd.h> 61#include <unistd.h>
64#else 62#ifndef HAVE_UNISTD_H
65extern POINTER_TYPE *sbrk (); 63extern POINTER_TYPE *sbrk ();
66#endif 64#endif
67 65
@@ -143,8 +141,6 @@ static pthread_mutex_t alloc_mutex;
143 141
144static __malloc_size_t bytes_used_when_full; 142static __malloc_size_t bytes_used_when_full;
145 143
146static __malloc_size_t bytes_used_when_reconsidered;
147
148/* Mark, unmark, query mark bit of a Lisp string. S must be a pointer 144/* Mark, unmark, query mark bit of a Lisp string. S must be a pointer
149 to a struct Lisp_String. */ 145 to a struct Lisp_String. */
150 146
@@ -164,31 +160,17 @@ static __malloc_size_t bytes_used_when_reconsidered;
164#define GC_STRING_BYTES(S) (STRING_BYTES (S)) 160#define GC_STRING_BYTES(S) (STRING_BYTES (S))
165#define GC_STRING_CHARS(S) ((S)->size & ~ARRAY_MARK_FLAG) 161#define GC_STRING_CHARS(S) ((S)->size & ~ARRAY_MARK_FLAG)
166 162
163/* Global variables. */
164struct emacs_globals globals;
165
167/* Number of bytes of consing done since the last gc. */ 166/* Number of bytes of consing done since the last gc. */
168 167
169int consing_since_gc; 168int consing_since_gc;
170 169
171/* Count the amount of consing of various sorts of space. */
172
173EMACS_INT cons_cells_consed;
174EMACS_INT floats_consed;
175EMACS_INT vector_cells_consed;
176EMACS_INT symbols_consed;
177EMACS_INT string_chars_consed;
178EMACS_INT misc_objects_consed;
179EMACS_INT intervals_consed;
180EMACS_INT strings_consed;
181
182/* Minimum number of bytes of consing since GC before next GC. */
183
184EMACS_INT gc_cons_threshold;
185
186/* Similar minimum, computed from Vgc_cons_percentage. */ 170/* Similar minimum, computed from Vgc_cons_percentage. */
187 171
188EMACS_INT gc_relative_threshold; 172EMACS_INT gc_relative_threshold;
189 173
190static Lisp_Object Vgc_cons_percentage;
191
192/* Minimum number of bytes of consing since GC before next GC, 174/* Minimum number of bytes of consing since GC before next GC,
193 when memory is full. */ 175 when memory is full. */
194 176
@@ -204,10 +186,6 @@ int gc_in_progress;
204 186
205int abort_on_gc; 187int abort_on_gc;
206 188
207/* Nonzero means display messages at beginning and end of GC. */
208
209int garbage_collection_messages;
210
211/* Number of live and free conses etc. */ 189/* Number of live and free conses etc. */
212 190
213static int total_conses, total_markers, total_symbols, total_vector_size; 191static int total_conses, total_markers, total_symbols, total_vector_size;
@@ -228,14 +206,6 @@ static char *spare_memory[7];
228 206
229static int malloc_hysteresis; 207static int malloc_hysteresis;
230 208
231/* Non-nil means defun should do purecopy on the function definition. */
232
233Lisp_Object Vpurify_flag;
234
235/* Non-nil means we are handling a memory-full error. */
236
237Lisp_Object Vmemory_full;
238
239/* Initialize it to a nonzero value to force it into data space 209/* Initialize it to a nonzero value to force it into data space
240 (rather than bss space). That way unexec will remap it into text 210 (rather than bss space). That way unexec will remap it into text
241 space (pure), on some systems. We have not implemented the 211 space (pure), on some systems. We have not implemented the
@@ -263,10 +233,6 @@ static size_t pure_bytes_used_before_overflow;
263 && ((PNTR_COMPARISON_TYPE) (P) \ 233 && ((PNTR_COMPARISON_TYPE) (P) \
264 >= (PNTR_COMPARISON_TYPE) purebeg)) 234 >= (PNTR_COMPARISON_TYPE) purebeg))
265 235
266/* Total number of bytes allocated in pure storage. */
267
268EMACS_INT pure_bytes_used;
269
270/* Index in pure at which next pure Lisp object will be allocated.. */ 236/* Index in pure at which next pure Lisp object will be allocated.. */
271 237
272static EMACS_INT pure_bytes_used_lisp; 238static EMACS_INT pure_bytes_used_lisp;
@@ -280,10 +246,6 @@ static EMACS_INT pure_bytes_used_non_lisp;
280 246
281const char *pending_malloc_warning; 247const char *pending_malloc_warning;
282 248
283/* Pre-computed signal argument for use when memory is exhausted. */
284
285Lisp_Object Vmemory_signal_data;
286
287/* Maximum amount of C stack to save when a GC happens. */ 249/* Maximum amount of C stack to save when a GC happens. */
288 250
289#ifndef MAX_SAVE_STACK 251#ifndef MAX_SAVE_STACK
@@ -304,10 +266,7 @@ Lisp_Object Qgc_cons_threshold, Qchar_table_extra_slots;
304 266
305/* Hook run after GC has finished. */ 267/* Hook run after GC has finished. */
306 268
307Lisp_Object Vpost_gc_hook, Qpost_gc_hook; 269Lisp_Object Qpost_gc_hook;
308
309Lisp_Object Vgc_elapsed; /* accumulated elapsed time in GC */
310EMACS_INT gcs_done; /* accumulated GCs */
311 270
312static void mark_buffer (Lisp_Object); 271static void mark_buffer (Lisp_Object);
313static void mark_terminals (void); 272static void mark_terminals (void);
@@ -1140,6 +1099,8 @@ static void * (*old_malloc_hook) (size_t, const void *);
1140static void * (*old_realloc_hook) (void *, size_t, const void*); 1099static void * (*old_realloc_hook) (void *, size_t, const void*);
1141static void (*old_free_hook) (void*, const void*); 1100static void (*old_free_hook) (void*, const void*);
1142 1101
1102static __malloc_size_t bytes_used_when_reconsidered;
1103
1143/* This function is used as the hook for free to call. */ 1104/* This function is used as the hook for free to call. */
1144 1105
1145static void 1106static void
@@ -4279,7 +4240,7 @@ Please mail the result to <emacs-devel@gnu.org>.\n\
4279 can prove that. */ 4240 can prove that. */
4280 4241
4281static void 4242static void
4282test_setjmp () 4243test_setjmp (void)
4283{ 4244{
4284 char buf[10]; 4245 char buf[10];
4285 register int x; 4246 register int x;
@@ -4327,7 +4288,7 @@ test_setjmp ()
4327/* Abort if anything GCPRO'd doesn't survive the GC. */ 4288/* Abort if anything GCPRO'd doesn't survive the GC. */
4328 4289
4329static void 4290static void
4330check_gcpros () 4291check_gcpros (void)
4331{ 4292{
4332 struct gcpro *p; 4293 struct gcpro *p;
4333 int i; 4294 int i;
@@ -4343,7 +4304,7 @@ check_gcpros ()
4343#elif GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES 4304#elif GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES
4344 4305
4345static void 4306static void
4346dump_zombies () 4307dump_zombies (void)
4347{ 4308{
4348 int i; 4309 int i;
4349 4310
@@ -4378,6 +4339,11 @@ dump_zombies ()
4378 have to be true! It must be verified for each system, possibly 4339 have to be true! It must be verified for each system, possibly
4379 by taking a look at the source code of setjmp. 4340 by taking a look at the source code of setjmp.
4380 4341
4342 If __builtin_unwind_init is available (defined by GCC >= 2.8) we
4343 can use it as a machine independent method to store all registers
4344 to the stack. In this case the macros described in the previous
4345 two paragraphs are not used.
4346
4381 Stack Layout 4347 Stack Layout
4382 4348
4383 Architectures differ in the way their processor stack is organized. 4349 Architectures differ in the way their processor stack is organized.
@@ -4416,6 +4382,13 @@ mark_stack (void)
4416 volatile int stack_grows_down_p = (char *) &j > (char *) stack_base; 4382 volatile int stack_grows_down_p = (char *) &j > (char *) stack_base;
4417 void *end; 4383 void *end;
4418 4384
4385#ifdef HAVE___BUILTIN_UNWIND_INIT
4386 /* Force callee-saved registers and register windows onto the stack.
4387 This is the preferred method if available, obviating the need for
4388 machine dependent methods. */
4389 __builtin_unwind_init ();
4390 end = &end;
4391#else /* not HAVE___BUILTIN_UNWIND_INIT */
4419 /* This trick flushes the register windows so that all the state of 4392 /* This trick flushes the register windows so that all the state of
4420 the process is contained in the stack. */ 4393 the process is contained in the stack. */
4421 /* Fixme: Code in the Boehm GC suggests flushing (with `flushrs') is 4394 /* Fixme: Code in the Boehm GC suggests flushing (with `flushrs') is
@@ -4451,6 +4424,7 @@ mark_stack (void)
4451 setjmp (j.j); 4424 setjmp (j.j);
4452 end = stack_grows_down_p ? (char *) &j + sizeof j : (char *) &j; 4425 end = stack_grows_down_p ? (char *) &j + sizeof j : (char *) &j;
4453#endif /* not GC_SAVE_REGISTERS_ON_STACK */ 4426#endif /* not GC_SAVE_REGISTERS_ON_STACK */
4427#endif /* not HAVE___BUILTIN_UNWIND_INIT */
4454 4428
4455 /* This assumes that the stack is a contiguous region in memory. If 4429 /* This assumes that the stack is a contiguous region in memory. If
4456 that's not the case, something has to be done here to iterate 4430 that's not the case, something has to be done here to iterate
@@ -4839,7 +4813,7 @@ Does not copy symbols. Copies strings without text properties. */)
4839 else if (FLOATP (obj)) 4813 else if (FLOATP (obj))
4840 obj = make_pure_float (XFLOAT_DATA (obj)); 4814 obj = make_pure_float (XFLOAT_DATA (obj));
4841 else if (STRINGP (obj)) 4815 else if (STRINGP (obj))
4842 obj = make_pure_string (SDATA (obj), SCHARS (obj), 4816 obj = make_pure_string (SSDATA (obj), SCHARS (obj),
4843 SBYTES (obj), 4817 SBYTES (obj),
4844 STRING_MULTIBYTE (obj)); 4818 STRING_MULTIBYTE (obj));
4845 else if (FUNVECP (obj) || VECTORP (obj)) 4819 else if (FUNVECP (obj) || VECTORP (obj))
@@ -5326,7 +5300,7 @@ mark_char_table (struct Lisp_Vector *ptr)
5326 { 5300 {
5327 Lisp_Object val = ptr->contents[i]; 5301 Lisp_Object val = ptr->contents[i];
5328 5302
5329 if (INTEGERP (val) || SYMBOLP (val) && XSYMBOL (val)->gcmarkbit) 5303 if (INTEGERP (val) || (SYMBOLP (val) && XSYMBOL (val)->gcmarkbit))
5330 continue; 5304 continue;
5331 if (SUB_CHAR_TABLE_P (val)) 5305 if (SUB_CHAR_TABLE_P (val))
5332 { 5306 {
@@ -6255,7 +6229,7 @@ init_alloc (void)
6255void 6229void
6256syms_of_alloc (void) 6230syms_of_alloc (void)
6257{ 6231{
6258 DEFVAR_INT ("gc-cons-threshold", &gc_cons_threshold, 6232 DEFVAR_INT ("gc-cons-threshold", gc_cons_threshold,
6259 doc: /* *Number of bytes of consing between garbage collections. 6233 doc: /* *Number of bytes of consing between garbage collections.
6260Garbage collection can happen automatically once this many bytes have been 6234Garbage collection can happen automatically once this many bytes have been
6261allocated since the last garbage collection. All data types count. 6235allocated since the last garbage collection. All data types count.
@@ -6266,57 +6240,57 @@ By binding this temporarily to a large number, you can effectively
6266prevent garbage collection during a part of the program. 6240prevent garbage collection during a part of the program.
6267See also `gc-cons-percentage'. */); 6241See also `gc-cons-percentage'. */);
6268 6242
6269 DEFVAR_LISP ("gc-cons-percentage", &Vgc_cons_percentage, 6243 DEFVAR_LISP ("gc-cons-percentage", Vgc_cons_percentage,
6270 doc: /* *Portion of the heap used for allocation. 6244 doc: /* *Portion of the heap used for allocation.
6271Garbage collection can happen automatically once this portion of the heap 6245Garbage collection can happen automatically once this portion of the heap
6272has been allocated since the last garbage collection. 6246has been allocated since the last garbage collection.
6273If this portion is smaller than `gc-cons-threshold', this is ignored. */); 6247If this portion is smaller than `gc-cons-threshold', this is ignored. */);
6274 Vgc_cons_percentage = make_float (0.1); 6248 Vgc_cons_percentage = make_float (0.1);
6275 6249
6276 DEFVAR_INT ("pure-bytes-used", &pure_bytes_used, 6250 DEFVAR_INT ("pure-bytes-used", pure_bytes_used,
6277 doc: /* Number of bytes of sharable Lisp data allocated so far. */); 6251 doc: /* Number of bytes of sharable Lisp data allocated so far. */);
6278 6252
6279 DEFVAR_INT ("cons-cells-consed", &cons_cells_consed, 6253 DEFVAR_INT ("cons-cells-consed", cons_cells_consed,
6280 doc: /* Number of cons cells that have been consed so far. */); 6254 doc: /* Number of cons cells that have been consed so far. */);
6281 6255
6282 DEFVAR_INT ("floats-consed", &floats_consed, 6256 DEFVAR_INT ("floats-consed", floats_consed,
6283 doc: /* Number of floats that have been consed so far. */); 6257 doc: /* Number of floats that have been consed so far. */);
6284 6258
6285 DEFVAR_INT ("vector-cells-consed", &vector_cells_consed, 6259 DEFVAR_INT ("vector-cells-consed", vector_cells_consed,
6286 doc: /* Number of vector cells that have been consed so far. */); 6260 doc: /* Number of vector cells that have been consed so far. */);
6287 6261
6288 DEFVAR_INT ("symbols-consed", &symbols_consed, 6262 DEFVAR_INT ("symbols-consed", symbols_consed,
6289 doc: /* Number of symbols that have been consed so far. */); 6263 doc: /* Number of symbols that have been consed so far. */);
6290 6264
6291 DEFVAR_INT ("string-chars-consed", &string_chars_consed, 6265 DEFVAR_INT ("string-chars-consed", string_chars_consed,
6292 doc: /* Number of string characters that have been consed so far. */); 6266 doc: /* Number of string characters that have been consed so far. */);
6293 6267
6294 DEFVAR_INT ("misc-objects-consed", &misc_objects_consed, 6268 DEFVAR_INT ("misc-objects-consed", misc_objects_consed,
6295 doc: /* Number of miscellaneous objects that have been consed so far. */); 6269 doc: /* Number of miscellaneous objects that have been consed so far. */);
6296 6270
6297 DEFVAR_INT ("intervals-consed", &intervals_consed, 6271 DEFVAR_INT ("intervals-consed", intervals_consed,
6298 doc: /* Number of intervals that have been consed so far. */); 6272 doc: /* Number of intervals that have been consed so far. */);
6299 6273
6300 DEFVAR_INT ("strings-consed", &strings_consed, 6274 DEFVAR_INT ("strings-consed", strings_consed,
6301 doc: /* Number of strings that have been consed so far. */); 6275 doc: /* Number of strings that have been consed so far. */);
6302 6276
6303 DEFVAR_LISP ("purify-flag", &Vpurify_flag, 6277 DEFVAR_LISP ("purify-flag", Vpurify_flag,
6304 doc: /* Non-nil means loading Lisp code in order to dump an executable. 6278 doc: /* Non-nil means loading Lisp code in order to dump an executable.
6305This means that certain objects should be allocated in shared (pure) space. 6279This means that certain objects should be allocated in shared (pure) space.
6306It can also be set to a hash-table, in which case this table is used to 6280It can also be set to a hash-table, in which case this table is used to
6307do hash-consing of the objects allocated to pure space. */); 6281do hash-consing of the objects allocated to pure space. */);
6308 6282
6309 DEFVAR_BOOL ("garbage-collection-messages", &garbage_collection_messages, 6283 DEFVAR_BOOL ("garbage-collection-messages", garbage_collection_messages,
6310 doc: /* Non-nil means display messages at start and end of garbage collection. */); 6284 doc: /* Non-nil means display messages at start and end of garbage collection. */);
6311 garbage_collection_messages = 0; 6285 garbage_collection_messages = 0;
6312 6286
6313 DEFVAR_LISP ("post-gc-hook", &Vpost_gc_hook, 6287 DEFVAR_LISP ("post-gc-hook", Vpost_gc_hook,
6314 doc: /* Hook run after garbage collection has finished. */); 6288 doc: /* Hook run after garbage collection has finished. */);
6315 Vpost_gc_hook = Qnil; 6289 Vpost_gc_hook = Qnil;
6316 Qpost_gc_hook = intern_c_string ("post-gc-hook"); 6290 Qpost_gc_hook = intern_c_string ("post-gc-hook");
6317 staticpro (&Qpost_gc_hook); 6291 staticpro (&Qpost_gc_hook);
6318 6292
6319 DEFVAR_LISP ("memory-signal-data", &Vmemory_signal_data, 6293 DEFVAR_LISP ("memory-signal-data", Vmemory_signal_data,
6320 doc: /* Precomputed `signal' argument for memory-full error. */); 6294 doc: /* Precomputed `signal' argument for memory-full error. */);
6321 /* We build this in advance because if we wait until we need it, we might 6295 /* We build this in advance because if we wait until we need it, we might
6322 not be able to allocate the memory to hold it. */ 6296 not be able to allocate the memory to hold it. */
@@ -6324,7 +6298,7 @@ do hash-consing of the objects allocated to pure space. */);
6324 = pure_cons (Qerror, 6298 = pure_cons (Qerror,
6325 pure_cons (make_pure_c_string ("Memory exhausted--use M-x save-some-buffers then exit and restart Emacs"), Qnil)); 6299 pure_cons (make_pure_c_string ("Memory exhausted--use M-x save-some-buffers then exit and restart Emacs"), Qnil));
6326 6300
6327 DEFVAR_LISP ("memory-full", &Vmemory_full, 6301 DEFVAR_LISP ("memory-full", Vmemory_full,
6328 doc: /* Non-nil means Emacs cannot get much more Lisp memory. */); 6302 doc: /* Non-nil means Emacs cannot get much more Lisp memory. */);
6329 Vmemory_full = Qnil; 6303 Vmemory_full = Qnil;
6330 6304
@@ -6334,10 +6308,10 @@ do hash-consing of the objects allocated to pure space. */);
6334 staticpro (&Qchar_table_extra_slots); 6308 staticpro (&Qchar_table_extra_slots);
6335 Qchar_table_extra_slots = intern_c_string ("char-table-extra-slots"); 6309 Qchar_table_extra_slots = intern_c_string ("char-table-extra-slots");
6336 6310
6337 DEFVAR_LISP ("gc-elapsed", &Vgc_elapsed, 6311 DEFVAR_LISP ("gc-elapsed", Vgc_elapsed,
6338 doc: /* Accumulated time elapsed in garbage collections. 6312 doc: /* Accumulated time elapsed in garbage collections.
6339The time is in seconds as a floating point value. */); 6313The time is in seconds as a floating point value. */);
6340 DEFVAR_INT ("gcs-done", &gcs_done, 6314 DEFVAR_INT ("gcs-done", gcs_done,
6341 doc: /* Accumulated number of garbage collections done. */); 6315 doc: /* Accumulated number of garbage collections done. */);
6342 6316
6343 defsubr (&Scons); 6317 defsubr (&Scons);
@@ -6360,6 +6334,3 @@ The time is in seconds as a floating point value. */);
6360 defsubr (&Sgc_status); 6334 defsubr (&Sgc_status);
6361#endif 6335#endif
6362} 6336}
6363
6364/* arch-tag: 6695ca10-e3c5-4c2c-8bc3-ed26a7dda857
6365 (do not change this comment) */