aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorStefan Monnier2011-03-21 12:42:16 -0400
committerStefan Monnier2011-03-21 12:42:16 -0400
commitcafdcef32d55cbb44389d7e322e7f973cbb72dfd (patch)
tree7ee0c41ea8a589650ce6f4311fb10e61a63807b9 /src/alloc.c
parenta08a25d7aaf251aa18f2ef747be53734bc55cae9 (diff)
parent4e05e67e4cd0bc1b0a4ef3176a4d0d91c6b3738e (diff)
downloademacs-cafdcef32d55cbb44389d7e322e7f973cbb72dfd.tar.gz
emacs-cafdcef32d55cbb44389d7e322e7f973cbb72dfd.zip
Merge from trunk
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c90
1 files changed, 42 insertions, 48 deletions
diff --git a/src/alloc.c b/src/alloc.c
index c7fd8747f74..0ca702fe0cd 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -92,7 +92,8 @@ extern __malloc_size_t __malloc_extra_blocks;
92 92
93#endif /* not DOUG_LEA_MALLOC */ 93#endif /* not DOUG_LEA_MALLOC */
94 94
95#if ! defined (SYSTEM_MALLOC) && defined (HAVE_GTK_AND_PTHREAD) 95#if ! defined SYSTEM_MALLOC && ! defined SYNC_INPUT
96#ifdef HAVE_GTK_AND_PTHREAD
96 97
97/* When GTK uses the file chooser dialog, different backends can be loaded 98/* When GTK uses the file chooser dialog, different backends can be loaded
98 dynamically. One such a backend is the Gnome VFS backend that gets loaded 99 dynamically. One such a backend is the Gnome VFS backend that gets loaded
@@ -130,12 +131,13 @@ static pthread_mutex_t alloc_mutex;
130 } \ 131 } \
131 while (0) 132 while (0)
132 133
133#else /* SYSTEM_MALLOC || not HAVE_GTK_AND_PTHREAD */ 134#else /* ! defined HAVE_GTK_AND_PTHREAD */
134 135
135#define BLOCK_INPUT_ALLOC BLOCK_INPUT 136#define BLOCK_INPUT_ALLOC BLOCK_INPUT
136#define UNBLOCK_INPUT_ALLOC UNBLOCK_INPUT 137#define UNBLOCK_INPUT_ALLOC UNBLOCK_INPUT
137 138
138#endif /* SYSTEM_MALLOC || not HAVE_GTK_AND_PTHREAD */ 139#endif /* ! defined HAVE_GTK_AND_PTHREAD */
140#endif /* ! defined SYSTEM_MALLOC && ! defined SYNC_INPUT */
139 141
140/* Value of _bytes_used, when spare_memory was freed. */ 142/* Value of _bytes_used, when spare_memory was freed. */
141 143
@@ -152,13 +154,11 @@ static __malloc_size_t bytes_used_when_full;
152#define VECTOR_UNMARK(V) ((V)->size &= ~ARRAY_MARK_FLAG) 154#define VECTOR_UNMARK(V) ((V)->size &= ~ARRAY_MARK_FLAG)
153#define VECTOR_MARKED_P(V) (((V)->size & ARRAY_MARK_FLAG) != 0) 155#define VECTOR_MARKED_P(V) (((V)->size & ARRAY_MARK_FLAG) != 0)
154 156
155/* Value is the number of bytes/chars of S, a pointer to a struct 157/* Value is the number of bytes of S, a pointer to a struct Lisp_String.
156 Lisp_String. This must be used instead of STRING_BYTES (S) or 158 Be careful during GC, because S->size contains the mark bit for
157 S->size during GC, because S->size contains the mark bit for
158 strings. */ 159 strings. */
159 160
160#define GC_STRING_BYTES(S) (STRING_BYTES (S)) 161#define GC_STRING_BYTES(S) (STRING_BYTES (S))
161#define GC_STRING_CHARS(S) ((S)->size & ~ARRAY_MARK_FLAG)
162 162
163/* Global variables. */ 163/* Global variables. */
164struct emacs_globals globals; 164struct emacs_globals globals;
@@ -270,17 +270,10 @@ Lisp_Object Qpost_gc_hook;
270 270
271static void mark_buffer (Lisp_Object); 271static void mark_buffer (Lisp_Object);
272static void mark_terminals (void); 272static void mark_terminals (void);
273extern void mark_kboards (void);
274extern void mark_ttys (void);
275extern void mark_backtrace (void);
276static void gc_sweep (void); 273static void gc_sweep (void);
277static void mark_glyph_matrix (struct glyph_matrix *); 274static void mark_glyph_matrix (struct glyph_matrix *);
278static void mark_face_cache (struct face_cache *); 275static void mark_face_cache (struct face_cache *);
279 276
280#ifdef HAVE_WINDOW_SYSTEM
281extern void mark_fringe_data (void);
282#endif /* HAVE_WINDOW_SYSTEM */
283
284static struct Lisp_String *allocate_string (void); 277static struct Lisp_String *allocate_string (void);
285static void compact_small_strings (void); 278static void compact_small_strings (void);
286static void free_large_strings (void); 279static void free_large_strings (void);
@@ -2659,17 +2652,17 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0,
2659 return val; 2652 return val;
2660} 2653}
2661 2654
2655#ifdef GC_CHECK_CONS_LIST
2662/* Get an error now if there's any junk in the cons free list. */ 2656/* Get an error now if there's any junk in the cons free list. */
2663void 2657void
2664check_cons_list (void) 2658check_cons_list (void)
2665{ 2659{
2666#ifdef GC_CHECK_CONS_LIST
2667 struct Lisp_Cons *tail = cons_free_list; 2660 struct Lisp_Cons *tail = cons_free_list;
2668 2661
2669 while (tail) 2662 while (tail)
2670 tail = tail->u.chain; 2663 tail = tail->u.chain;
2671#endif
2672} 2664}
2665#endif
2673 2666
2674/* Make a list of 1, 2, 3, 4 or 5 specified objects. */ 2667/* Make a list of 1, 2, 3, 4 or 5 specified objects. */
2675 2668
@@ -2909,15 +2902,15 @@ See also the function `vector'. */)
2909{ 2902{
2910 Lisp_Object vector; 2903 Lisp_Object vector;
2911 register EMACS_INT sizei; 2904 register EMACS_INT sizei;
2912 register EMACS_INT index; 2905 register EMACS_INT i;
2913 register struct Lisp_Vector *p; 2906 register struct Lisp_Vector *p;
2914 2907
2915 CHECK_NATNUM (length); 2908 CHECK_NATNUM (length);
2916 sizei = XFASTINT (length); 2909 sizei = XFASTINT (length);
2917 2910
2918 p = allocate_vector (sizei); 2911 p = allocate_vector (sizei);
2919 for (index = 0; index < sizei; index++) 2912 for (i = 0; i < sizei; i++)
2920 p->contents[index] = init; 2913 p->contents[i] = init;
2921 2914
2922 XSETVECTOR (vector, p); 2915 XSETVECTOR (vector, p);
2923 return vector; 2916 return vector;
@@ -2931,14 +2924,14 @@ usage: (vector &rest OBJECTS) */)
2931 (register int nargs, Lisp_Object *args) 2924 (register int nargs, Lisp_Object *args)
2932{ 2925{
2933 register Lisp_Object len, val; 2926 register Lisp_Object len, val;
2934 register int index; 2927 register int i;
2935 register struct Lisp_Vector *p; 2928 register struct Lisp_Vector *p;
2936 2929
2937 XSETFASTINT (len, nargs); 2930 XSETFASTINT (len, nargs);
2938 val = Fmake_vector (len, Qnil); 2931 val = Fmake_vector (len, Qnil);
2939 p = XVECTOR (val); 2932 p = XVECTOR (val);
2940 for (index = 0; index < nargs; index++) 2933 for (i = 0; i < nargs; i++)
2941 p->contents[index] = args[index]; 2934 p->contents[i] = args[i];
2942 return val; 2935 return val;
2943} 2936}
2944 2937
@@ -2962,7 +2955,7 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INT
2962 (register int nargs, Lisp_Object *args) 2955 (register int nargs, Lisp_Object *args)
2963{ 2956{
2964 register Lisp_Object len, val; 2957 register Lisp_Object len, val;
2965 register int index; 2958 register int i;
2966 register struct Lisp_Vector *p; 2959 register struct Lisp_Vector *p;
2967 2960
2968 XSETFASTINT (len, nargs); 2961 XSETFASTINT (len, nargs);
@@ -2980,11 +2973,11 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INT
2980 args[1] = Fstring_as_unibyte (args[1]); 2973 args[1] = Fstring_as_unibyte (args[1]);
2981 2974
2982 p = XVECTOR (val); 2975 p = XVECTOR (val);
2983 for (index = 0; index < nargs; index++) 2976 for (i = 0; i < nargs; i++)
2984 { 2977 {
2985 if (!NILP (Vpurify_flag)) 2978 if (!NILP (Vpurify_flag))
2986 args[index] = Fpurecopy (args[index]); 2979 args[i] = Fpurecopy (args[i]);
2987 p->contents[index] = args[index]; 2980 p->contents[i] = args[i];
2988 } 2981 }
2989 XSETPVECTYPE (p, PVEC_COMPILED); 2982 XSETPVECTYPE (p, PVEC_COMPILED);
2990 XSETCOMPILED (val, p); 2983 XSETCOMPILED (val, p);
@@ -4328,12 +4321,6 @@ static void
4328mark_stack (void) 4321mark_stack (void)
4329{ 4322{
4330 int i; 4323 int i;
4331 /* jmp_buf may not be aligned enough on darwin-ppc64 */
4332 union aligned_jmpbuf {
4333 Lisp_Object o;
4334 jmp_buf j;
4335 } j;
4336 volatile int stack_grows_down_p = (char *) &j > (char *) stack_base;
4337 void *end; 4324 void *end;
4338 4325
4339#ifdef HAVE___BUILTIN_UNWIND_INIT 4326#ifdef HAVE___BUILTIN_UNWIND_INIT
@@ -4343,6 +4330,14 @@ mark_stack (void)
4343 __builtin_unwind_init (); 4330 __builtin_unwind_init ();
4344 end = &end; 4331 end = &end;
4345#else /* not HAVE___BUILTIN_UNWIND_INIT */ 4332#else /* not HAVE___BUILTIN_UNWIND_INIT */
4333#ifndef GC_SAVE_REGISTERS_ON_STACK
4334 /* jmp_buf may not be aligned enough on darwin-ppc64 */
4335 union aligned_jmpbuf {
4336 Lisp_Object o;
4337 jmp_buf j;
4338 } j;
4339 volatile int stack_grows_down_p = (char *) &j > (char *) stack_base;
4340#endif
4346 /* This trick flushes the register windows so that all the state of 4341 /* This trick flushes the register windows so that all the state of
4347 the process is contained in the stack. */ 4342 the process is contained in the stack. */
4348 /* Fixme: Code in the Boehm GC suggests flushing (with `flushrs') is 4343 /* Fixme: Code in the Boehm GC suggests flushing (with `flushrs') is
@@ -5079,18 +5074,18 @@ returns nil, because real GC can't be done. */)
5079 5074
5080 if (FLOATP (Vgc_cons_percentage)) 5075 if (FLOATP (Vgc_cons_percentage))
5081 { /* Set gc_cons_combined_threshold. */ 5076 { /* Set gc_cons_combined_threshold. */
5082 EMACS_INT total = 0; 5077 EMACS_INT tot = 0;
5083 5078
5084 total += total_conses * sizeof (struct Lisp_Cons); 5079 tot += total_conses * sizeof (struct Lisp_Cons);
5085 total += total_symbols * sizeof (struct Lisp_Symbol); 5080 tot += total_symbols * sizeof (struct Lisp_Symbol);
5086 total += total_markers * sizeof (union Lisp_Misc); 5081 tot += total_markers * sizeof (union Lisp_Misc);
5087 total += total_string_size; 5082 tot += total_string_size;
5088 total += total_vector_size * sizeof (Lisp_Object); 5083 tot += total_vector_size * sizeof (Lisp_Object);
5089 total += total_floats * sizeof (struct Lisp_Float); 5084 tot += total_floats * sizeof (struct Lisp_Float);
5090 total += total_intervals * sizeof (struct interval); 5085 tot += total_intervals * sizeof (struct interval);
5091 total += total_strings * sizeof (struct Lisp_String); 5086 tot += total_strings * sizeof (struct Lisp_String);
5092 5087
5093 gc_relative_threshold = total * XFLOAT_DATA (Vgc_cons_percentage); 5088 gc_relative_threshold = tot * XFLOAT_DATA (Vgc_cons_percentage);
5094 } 5089 }
5095 else 5090 else
5096 gc_relative_threshold = 0; 5091 gc_relative_threshold = 0;
@@ -5139,9 +5134,9 @@ returns nil, because real GC can't be done. */)
5139 5134
5140 if (!NILP (Vpost_gc_hook)) 5135 if (!NILP (Vpost_gc_hook))
5141 { 5136 {
5142 int count = inhibit_garbage_collection (); 5137 int gc_count = inhibit_garbage_collection ();
5143 safe_run_hooks (Qpost_gc_hook); 5138 safe_run_hooks (Qpost_gc_hook);
5144 unbind_to (count, Qnil); 5139 unbind_to (gc_count, Qnil);
5145 } 5140 }
5146 5141
5147 /* Accumulate statistics. */ 5142 /* Accumulate statistics. */
@@ -5320,7 +5315,6 @@ mark_object (Lisp_Object arg)
5320 5315
5321#else /* not GC_CHECK_MARKED_OBJECTS */ 5316#else /* not GC_CHECK_MARKED_OBJECTS */
5322 5317
5323#define CHECK_ALLOCATED() (void) 0
5324#define CHECK_LIVE(LIVEP) (void) 0 5318#define CHECK_LIVE(LIVEP) (void) 0
5325#define CHECK_ALLOCATED_AND_LIVE(LIVEP) (void) 0 5319#define CHECK_ALLOCATED_AND_LIVE(LIVEP) (void) 0
5326 5320
@@ -6072,7 +6066,7 @@ We divide the value by 1024 to make sure it fits in a Lisp integer. */)
6072{ 6066{
6073 Lisp_Object end; 6067 Lisp_Object end;
6074 6068
6075 XSETINT (end, (EMACS_INT) sbrk (0) / 1024); 6069 XSETINT (end, (EMACS_INT) (char *) sbrk (0) / 1024);
6076 6070
6077 return end; 6071 return end;
6078} 6072}