aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorBill Wohler2013-02-18 10:11:43 -0800
committerBill Wohler2013-02-18 10:11:43 -0800
commit21733e4f154f8830fa568a347a0d6dbd59793c2b (patch)
tree3170dbbcdfafeb42f6c381d6b80b251e9f31b788 /src/alloc.c
parent6d14beddb06b5ae86f9dd770a1661ebd24846f28 (diff)
parent587feed443522f738b65b57b22a31cc8a25525c5 (diff)
downloademacs-21733e4f154f8830fa568a347a0d6dbd59793c2b.tar.gz
emacs-21733e4f154f8830fa568a347a0d6dbd59793c2b.zip
Merge from trunk; up to 2013-02-18T01:30:27Z!monnier@iro.umontreal.ca.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c168
1 files changed, 108 insertions, 60 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 5a3ba465d81..80086433e65 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1,7 +1,7 @@
1/* Storage allocation and gc for GNU Emacs Lisp interpreter. 1/* Storage allocation and gc for GNU Emacs Lisp interpreter.
2 2
3Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2012 3Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2013 Free Software
4 Free Software Foundation, Inc. 4Foundation, Inc.
5 5
6This file is part of GNU Emacs. 6This file is part of GNU Emacs.
7 7
@@ -26,7 +26,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26#include <limits.h> /* For CHAR_BIT. */ 26#include <limits.h> /* For CHAR_BIT. */
27 27
28#ifdef ENABLE_CHECKING 28#ifdef ENABLE_CHECKING
29#include <signal.h> /* For SIGABRT. */ 29#include <signal.h> /* For SIGABRT. */
30#endif 30#endif
31 31
32#ifdef HAVE_PTHREAD 32#ifdef HAVE_PTHREAD
@@ -209,6 +209,7 @@ Lisp_Object Qchar_table_extra_slots;
209 209
210static Lisp_Object Qpost_gc_hook; 210static Lisp_Object Qpost_gc_hook;
211 211
212static void free_save_value (Lisp_Object);
212static void mark_terminals (void); 213static void mark_terminals (void);
213static void gc_sweep (void); 214static void gc_sweep (void);
214static Lisp_Object make_pure_vector (ptrdiff_t); 215static Lisp_Object make_pure_vector (ptrdiff_t);
@@ -219,7 +220,6 @@ static void refill_memory_reserve (void);
219#endif 220#endif
220static void compact_small_strings (void); 221static void compact_small_strings (void);
221static void free_large_strings (void); 222static void free_large_strings (void);
222static void free_misc (Lisp_Object);
223extern Lisp_Object which_symbols (Lisp_Object, EMACS_INT) EXTERNALLY_VISIBLE; 223extern Lisp_Object which_symbols (Lisp_Object, EMACS_INT) EXTERNALLY_VISIBLE;
224 224
225/* When scanning the C stack for live Lisp objects, Emacs keeps track of 225/* When scanning the C stack for live Lisp objects, Emacs keeps track of
@@ -845,7 +845,7 @@ void *
845record_xmalloc (size_t size) 845record_xmalloc (size_t size)
846{ 846{
847 void *p = xmalloc (size); 847 void *p = xmalloc (size);
848 record_unwind_protect (safe_alloca_unwind, make_save_value (p, 0)); 848 record_unwind_protect (safe_alloca_unwind, make_save_pointer (p));
849 return p; 849 return p;
850} 850}
851 851
@@ -1684,7 +1684,7 @@ allocate_string_data (struct Lisp_String *s,
1684 b = lisp_malloc (size + GC_STRING_EXTRA, MEM_TYPE_NON_LISP); 1684 b = lisp_malloc (size + GC_STRING_EXTRA, MEM_TYPE_NON_LISP);
1685 1685
1686#ifdef DOUG_LEA_MALLOC 1686#ifdef DOUG_LEA_MALLOC
1687 /* Back to a reasonable maximum of mmap'ed areas. */ 1687 /* Back to a reasonable maximum of mmap'ed areas. */
1688 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); 1688 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS);
1689#endif 1689#endif
1690 1690
@@ -1901,7 +1901,7 @@ compact_small_strings (void)
1901 1901
1902#ifdef GC_CHECK_STRING_BYTES 1902#ifdef GC_CHECK_STRING_BYTES
1903 /* Check that the string size recorded in the string is the 1903 /* Check that the string size recorded in the string is the
1904 same as the one recorded in the sdata structure. */ 1904 same as the one recorded in the sdata structure. */
1905 if (s && string_bytes (s) != SDATA_NBYTES (from)) 1905 if (s && string_bytes (s) != SDATA_NBYTES (from))
1906 emacs_abort (); 1906 emacs_abort ();
1907#endif /* GC_CHECK_STRING_BYTES */ 1907#endif /* GC_CHECK_STRING_BYTES */
@@ -3105,13 +3105,10 @@ Any number of arguments, even zero arguments, are allowed.
3105usage: (vector &rest OBJECTS) */) 3105usage: (vector &rest OBJECTS) */)
3106 (ptrdiff_t nargs, Lisp_Object *args) 3106 (ptrdiff_t nargs, Lisp_Object *args)
3107{ 3107{
3108 register Lisp_Object len, val;
3109 ptrdiff_t i; 3108 ptrdiff_t i;
3110 register struct Lisp_Vector *p; 3109 register Lisp_Object val = make_uninit_vector (nargs);
3110 register struct Lisp_Vector *p = XVECTOR (val);
3111 3111
3112 XSETFASTINT (len, nargs);
3113 val = Fmake_vector (len, Qnil);
3114 p = XVECTOR (val);
3115 for (i = 0; i < nargs; i++) 3112 for (i = 0; i < nargs; i++)
3116 p->contents[i] = args[i]; 3113 p->contents[i] = args[i];
3117 return val; 3114 return val;
@@ -3149,9 +3146,9 @@ stack before executing the byte-code.
3149usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INTERACTIVE-SPEC &rest ELEMENTS) */) 3146usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INTERACTIVE-SPEC &rest ELEMENTS) */)
3150 (ptrdiff_t nargs, Lisp_Object *args) 3147 (ptrdiff_t nargs, Lisp_Object *args)
3151{ 3148{
3152 register Lisp_Object len, val;
3153 ptrdiff_t i; 3149 ptrdiff_t i;
3154 register struct Lisp_Vector *p; 3150 register Lisp_Object val = make_uninit_vector (nargs);
3151 register struct Lisp_Vector *p = XVECTOR (val);
3155 3152
3156 /* We used to purecopy everything here, if purify-flag was set. This worked 3153 /* We used to purecopy everything here, if purify-flag was set. This worked
3157 OK for Emacs-23, but with Emacs-24's lexical binding code, it can be 3154 OK for Emacs-23, but with Emacs-24's lexical binding code, it can be
@@ -3161,10 +3158,6 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INT
3161 just wasteful and other times plainly wrong (e.g. those free vars may want 3158 just wasteful and other times plainly wrong (e.g. those free vars may want
3162 to be setcar'd). */ 3159 to be setcar'd). */
3163 3160
3164 XSETFASTINT (len, nargs);
3165 val = Fmake_vector (len, Qnil);
3166
3167 p = XVECTOR (val);
3168 for (i = 0; i < nargs; i++) 3161 for (i = 0; i < nargs; i++)
3169 p->contents[i] = args[i]; 3162 p->contents[i] = args[i];
3170 make_byte_code (p); 3163 make_byte_code (p);
@@ -3339,9 +3332,9 @@ allocate_misc (enum Lisp_Misc_Type type)
3339 return val; 3332 return val;
3340} 3333}
3341 3334
3342/* Free a Lisp_Misc object */ 3335/* Free a Lisp_Misc object. */
3343 3336
3344static void 3337void
3345free_misc (Lisp_Object misc) 3338free_misc (Lisp_Object misc)
3346{ 3339{
3347 XMISCTYPE (misc) = Lisp_Misc_Free; 3340 XMISCTYPE (misc) = Lisp_Misc_Free;
@@ -3351,34 +3344,81 @@ free_misc (Lisp_Object misc)
3351 total_free_markers++; 3344 total_free_markers++;
3352} 3345}
3353 3346
3354/* Return a Lisp_Misc_Save_Value object containing POINTER and 3347/* Return a Lisp_Save_Value object with the data saved according to
3355 INTEGER. This is used to package C values to call record_unwind_protect. 3348 FMT. Format specifiers are `i' for an integer, `p' for a pointer
3356 The unwind function can get the C values back using XSAVE_VALUE. */ 3349 and `o' for Lisp_Object. Up to 4 objects can be specified. */
3357 3350
3358Lisp_Object 3351Lisp_Object
3359make_save_value (void *pointer, ptrdiff_t integer) 3352make_save_value (const char *fmt, ...)
3360{ 3353{
3361 register Lisp_Object val; 3354 va_list ap;
3362 register struct Lisp_Save_Value *p; 3355 int len = strlen (fmt);
3356 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value);
3357 struct Lisp_Save_Value *p = XSAVE_VALUE (val);
3358
3359 eassert (0 < len && len < 5);
3360 va_start (ap, fmt);
3361
3362#define INITX(index) \
3363 do { \
3364 if (len <= index) \
3365 p->type ## index = SAVE_UNUSED; \
3366 else \
3367 { \
3368 if (fmt[index] == 'i') \
3369 { \
3370 p->type ## index = SAVE_INTEGER; \
3371 p->data[index].integer = va_arg (ap, ptrdiff_t); \
3372 } \
3373 else if (fmt[index] == 'p') \
3374 { \
3375 p->type ## index = SAVE_POINTER; \
3376 p->data[index].pointer = va_arg (ap, void *); \
3377 } \
3378 else if (fmt[index] == 'o') \
3379 { \
3380 p->type ## index = SAVE_OBJECT; \
3381 p->data[index].object = va_arg (ap, Lisp_Object); \
3382 } \
3383 else \
3384 emacs_abort (); \
3385 } \
3386 } while (0)
3387
3388 INITX (0);
3389 INITX (1);
3390 INITX (2);
3391 INITX (3);
3363 3392
3364 val = allocate_misc (Lisp_Misc_Save_Value); 3393#undef INITX
3365 p = XSAVE_VALUE (val); 3394
3366 p->pointer = pointer; 3395 va_end (ap);
3367 p->integer = integer; 3396 p->area = 0;
3368 p->dogc = 0;
3369 return val; 3397 return val;
3370} 3398}
3371 3399
3372/* Free a Lisp_Misc_Save_Value object. */ 3400/* The most common task it to save just one C pointer. */
3373 3401
3374void 3402Lisp_Object
3375free_save_value (Lisp_Object save) 3403make_save_pointer (void *pointer)
3376{ 3404{
3377 register struct Lisp_Save_Value *p = XSAVE_VALUE (save); 3405 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value);
3406 struct Lisp_Save_Value *p = XSAVE_VALUE (val);
3378 3407
3379 p->dogc = 0; 3408 p->area = 0;
3380 xfree (p->pointer); 3409 p->type0 = SAVE_POINTER;
3381 p->pointer = NULL; 3410 p->data[0].pointer = pointer;
3411 p->type1 = p->type2 = p->type3 = SAVE_UNUSED;
3412 return val;
3413}
3414
3415/* Free a Lisp_Save_Value object. Do not use this function
3416 if SAVE contains pointer other than returned by xmalloc. */
3417
3418static void
3419free_save_value (Lisp_Object save)
3420{
3421 xfree (XSAVE_POINTER (save, 0));
3382 free_misc (save); 3422 free_misc (save);
3383} 3423}
3384 3424
@@ -4446,11 +4486,6 @@ mark_memory (void *start, void *end)
4446 } 4486 }
4447} 4487}
4448 4488
4449/* setjmp will work with GCC unless NON_SAVING_SETJMP is defined in
4450 the GCC system configuration. In gcc 3.2, the only systems for
4451 which this is so are i386-sco5 non-ELF, i386-sysv3 (maybe included
4452 by others?) and ns32k-pc532-min. */
4453
4454#if !defined GC_SAVE_REGISTERS_ON_STACK && !defined GC_SETJMP_WORKS 4489#if !defined GC_SAVE_REGISTERS_ON_STACK && !defined GC_SETJMP_WORKS
4455 4490
4456static bool setjmp_tested_p; 4491static bool setjmp_tested_p;
@@ -4721,12 +4756,12 @@ valid_pointer_p (void *p)
4721#endif 4756#endif
4722} 4757}
4723 4758
4724/* Return 2 if OBJ is a killed or special buffer object. 4759/* Return 2 if OBJ is a killed or special buffer object, 1 if OBJ is a
4725 Return 1 if OBJ is a valid lisp object. 4760 valid lisp object, 0 if OBJ is NOT a valid lisp object, or -1 if we
4726 Return 0 if OBJ is NOT a valid lisp object. 4761 cannot validate OBJ. This function can be quite slow, so its primary
4727 Return -1 if we cannot validate OBJ. 4762 use is the manual debugging. The only exception is print_object, where
4728 This function can be quite slow, 4763 we use it to check whether the memory referenced by the pointer of
4729 so it should only be used in code for manual debugging. */ 4764 Lisp_Save_Value object contains valid objects. */
4730 4765
4731int 4766int
4732valid_lisp_object_p (Lisp_Object obj) 4767valid_lisp_object_p (Lisp_Object obj)
@@ -5940,20 +5975,33 @@ mark_object (Lisp_Object arg)
5940 5975
5941 case Lisp_Misc_Save_Value: 5976 case Lisp_Misc_Save_Value:
5942 XMISCANY (obj)->gcmarkbit = 1; 5977 XMISCANY (obj)->gcmarkbit = 1;
5943#if GC_MARK_STACK
5944 { 5978 {
5945 register struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj); 5979 register struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj);
5946 /* If DOGC is set, POINTER is the address of a memory 5980 /* If `area' is nonzero, `data[0].pointer' is the address
5947 area containing INTEGER potential Lisp_Objects. */ 5981 of a memory area containing `data[1].integer' potential
5948 if (ptr->dogc) 5982 Lisp_Objects. */
5983#if GC_MARK_STACK
5984 if (ptr->area)
5949 { 5985 {
5950 Lisp_Object *p = (Lisp_Object *) ptr->pointer; 5986 Lisp_Object *p = ptr->data[0].pointer;
5951 ptrdiff_t nelt; 5987 ptrdiff_t nelt;
5952 for (nelt = ptr->integer; nelt > 0; nelt--, p++) 5988 for (nelt = ptr->data[1].integer; nelt > 0; nelt--, p++)
5953 mark_maybe_object (*p); 5989 mark_maybe_object (*p);
5954 } 5990 }
5991 else
5992#endif /* GC_MARK_STACK */
5993 {
5994 /* Find Lisp_Objects in `data[N]' slots and mark them. */
5995 if (ptr->type0 == SAVE_OBJECT)
5996 mark_object (ptr->data[0].object);
5997 if (ptr->type1 == SAVE_OBJECT)
5998 mark_object (ptr->data[1].object);
5999 if (ptr->type2 == SAVE_OBJECT)
6000 mark_object (ptr->data[2].object);
6001 if (ptr->type3 == SAVE_OBJECT)
6002 mark_object (ptr->data[3].object);
6003 }
5955 } 6004 }
5956#endif
5957 break; 6005 break;
5958 6006
5959 case Lisp_Misc_Overlay: 6007 case Lisp_Misc_Overlay:
@@ -6509,7 +6557,7 @@ die (const char *msg, const char *file, int line)
6509} 6557}
6510#endif 6558#endif
6511 6559
6512/* Initialization */ 6560/* Initialization. */
6513 6561
6514void 6562void
6515init_alloc_once (void) 6563init_alloc_once (void)
@@ -6524,9 +6572,9 @@ init_alloc_once (void)
6524#endif 6572#endif
6525 6573
6526#ifdef DOUG_LEA_MALLOC 6574#ifdef DOUG_LEA_MALLOC
6527 mallopt (M_TRIM_THRESHOLD, 128*1024); /* trim threshold */ 6575 mallopt (M_TRIM_THRESHOLD, 128 * 1024); /* Trim threshold. */
6528 mallopt (M_MMAP_THRESHOLD, 64*1024); /* mmap threshold */ 6576 mallopt (M_MMAP_THRESHOLD, 64 * 1024); /* Mmap threshold. */
6529 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); /* max. number of mmap'ed areas */ 6577 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); /* Max. number of mmap'ed areas. */
6530#endif 6578#endif
6531 init_strings (); 6579 init_strings ();
6532 init_vectors (); 6580 init_vectors ();