aboutsummaryrefslogtreecommitdiffstats
path: root/src/ralloc.c
diff options
context:
space:
mode:
authorTom Tromey2012-12-17 07:56:22 -0700
committerTom Tromey2012-12-17 07:56:22 -0700
commit3d6eced1ae51ffd0a782130e7c334052277e2724 (patch)
tree5d1d2ad7cd3374f922886c4a72062511a035c168 /src/ralloc.c
parentbf69f522a9e135f9aa483cedd53e71e915f2bf75 (diff)
parent7c3d167f48d6262ee4e5512aa50a07ee96bc1509 (diff)
downloademacs-3d6eced1ae51ffd0a782130e7c334052277e2724.tar.gz
emacs-3d6eced1ae51ffd0a782130e7c334052277e2724.zip
merge from trunk
Diffstat (limited to 'src/ralloc.c')
-rw-r--r--src/ralloc.c89
1 files changed, 48 insertions, 41 deletions
diff --git a/src/ralloc.c b/src/ralloc.c
index 3877e21d4f6..e5bf76b0e6d 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -25,7 +25,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
25#ifdef emacs 25#ifdef emacs
26 26
27#include <config.h> 27#include <config.h>
28#include <setjmp.h> 28
29#include "lisp.h" /* Needed for VALBITS. */ 29#include "lisp.h" /* Needed for VALBITS. */
30#include "blockinput.h" 30#include "blockinput.h"
31 31
@@ -72,7 +72,7 @@ static void r_alloc_init (void);
72/* Declarations for working with the malloc, ralloc, and system breaks. */ 72/* Declarations for working with the malloc, ralloc, and system breaks. */
73 73
74/* Function to set the real break value. */ 74/* Function to set the real break value. */
75POINTER (*real_morecore) (long int); 75POINTER (*real_morecore) (ptrdiff_t);
76 76
77/* The break value, as seen by malloc. */ 77/* The break value, as seen by malloc. */
78static POINTER virtual_break_value; 78static POINTER virtual_break_value;
@@ -91,18 +91,18 @@ static int extra_bytes;
91/* Macros for rounding. Note that rounding to any value is possible 91/* Macros for rounding. Note that rounding to any value is possible
92 by changing the definition of PAGE. */ 92 by changing the definition of PAGE. */
93#define PAGE (getpagesize ()) 93#define PAGE (getpagesize ())
94#define ROUNDUP(size) (((unsigned long int) (size) + page_size - 1) \ 94#define ROUNDUP(size) (((size_t) (size) + page_size - 1) \
95 & ~(page_size - 1)) 95 & ~((size_t)(page_size - 1)))
96 96
97#define MEM_ALIGN sizeof (double) 97#define MEM_ALIGN sizeof (double)
98#define MEM_ROUNDUP(addr) (((unsigned long int)(addr) + MEM_ALIGN - 1) \ 98#define MEM_ROUNDUP(addr) (((size_t)(addr) + MEM_ALIGN - 1) \
99 & ~(MEM_ALIGN - 1)) 99 & ~(MEM_ALIGN - 1))
100 100
101/* The hook `malloc' uses for the function which gets more space 101/* The hook `malloc' uses for the function which gets more space
102 from the system. */ 102 from the system. */
103 103
104#ifndef SYSTEM_MALLOC 104#ifndef SYSTEM_MALLOC
105extern POINTER (*__morecore) (long int); 105extern POINTER (*__morecore) (ptrdiff_t);
106#endif 106#endif
107 107
108 108
@@ -237,7 +237,7 @@ obtain (POINTER address, SIZE size)
237 } 237 }
238 238
239 if (! heap) 239 if (! heap)
240 abort (); 240 emacs_abort ();
241 241
242 /* If we can't fit SIZE bytes in that heap, 242 /* If we can't fit SIZE bytes in that heap,
243 try successive later heaps. */ 243 try successive later heaps. */
@@ -308,7 +308,7 @@ static void
308relinquish (void) 308relinquish (void)
309{ 309{
310 register heap_ptr h; 310 register heap_ptr h;
311 long excess = 0; 311 ptrdiff_t excess = 0;
312 312
313 /* Add the amount of space beyond break_value 313 /* Add the amount of space beyond break_value
314 in all heaps which have extend beyond break_value at all. */ 314 in all heaps which have extend beyond break_value at all. */
@@ -327,35 +327,36 @@ relinquish (void)
327 327
328 if ((char *)last_heap->end - (char *)last_heap->bloc_start <= excess) 328 if ((char *)last_heap->end - (char *)last_heap->bloc_start <= excess)
329 { 329 {
330 /* This heap should have no blocs in it. */ 330 heap_ptr lh_prev;
331
332 /* This heap should have no blocs in it. If it does, we
333 cannot return it to the system. */
331 if (last_heap->first_bloc != NIL_BLOC 334 if (last_heap->first_bloc != NIL_BLOC
332 || last_heap->last_bloc != NIL_BLOC) 335 || last_heap->last_bloc != NIL_BLOC)
333 abort (); 336 return;
334 337
335 /* Return the last heap, with its header, to the system. */ 338 /* Return the last heap, with its header, to the system. */
336 excess = (char *)last_heap->end - (char *)last_heap->start; 339 excess = (char *)last_heap->end - (char *)last_heap->start;
337 last_heap = last_heap->prev; 340 lh_prev = last_heap->prev;
338 last_heap->next = NIL_HEAP; 341 /* If the system doesn't want that much memory back, leave
342 last_heap unaltered to reflect that. This can occur if
343 break_value is still within the original data segment. */
344 if ((*real_morecore) (- excess) != 0)
345 {
346 last_heap = lh_prev;
347 last_heap->next = NIL_HEAP;
348 }
339 } 349 }
340 else 350 else
341 { 351 {
342 excess = (char *) last_heap->end 352 excess = (char *) last_heap->end
343 - (char *) ROUNDUP ((char *)last_heap->end - excess); 353 - (char *) ROUNDUP ((char *)last_heap->end - excess);
344 last_heap->end = (char *) last_heap->end - excess; 354 /* If the system doesn't want that much memory back, leave
345 } 355 the end of the last heap unchanged to reflect that. This
346 356 can occur if break_value is still within the original
347 if ((*real_morecore) (- excess) == 0) 357 data segment. */
348 { 358 if ((*real_morecore) (- excess) != 0)
349 /* If the system didn't want that much memory back, adjust 359 last_heap->end = (char *) last_heap->end - excess;
350 the end of the last heap to reflect that. This can occur
351 if break_value is still within the original data segment. */
352 last_heap->end = (char *) last_heap->end + excess;
353 /* Make sure that the result of the adjustment is accurate.
354 It should be, for the else clause above; the other case,
355 which returns the entire last heap to the system, seems
356 unlikely to trigger this mode of failure. */
357 if (last_heap->end != (*real_morecore) (0))
358 abort ();
359 } 360 }
360 } 361 }
361} 362}
@@ -452,7 +453,7 @@ relocate_blocs (bloc_ptr bloc, heap_ptr heap, POINTER address)
452 453
453 /* No need to ever call this if arena is frozen, bug somewhere! */ 454 /* No need to ever call this if arena is frozen, bug somewhere! */
454 if (r_alloc_freeze_level) 455 if (r_alloc_freeze_level)
455 abort (); 456 emacs_abort ();
456 457
457 while (b) 458 while (b)
458 { 459 {
@@ -576,7 +577,7 @@ resize_bloc (bloc_ptr bloc, SIZE size)
576 577
577 /* No need to ever call this if arena is frozen, bug somewhere! */ 578 /* No need to ever call this if arena is frozen, bug somewhere! */
578 if (r_alloc_freeze_level) 579 if (r_alloc_freeze_level)
579 abort (); 580 emacs_abort ();
580 581
581 if (bloc == NIL_BLOC || size == bloc->size) 582 if (bloc == NIL_BLOC || size == bloc->size)
582 return 1; 583 return 1;
@@ -588,7 +589,7 @@ resize_bloc (bloc_ptr bloc, SIZE size)
588 } 589 }
589 590
590 if (heap == NIL_HEAP) 591 if (heap == NIL_HEAP)
591 abort (); 592 emacs_abort ();
592 593
593 old_size = bloc->size; 594 old_size = bloc->size;
594 bloc->size = size; 595 bloc->size = size;
@@ -752,7 +753,7 @@ free_bloc (bloc_ptr bloc)
752 GNU malloc package. */ 753 GNU malloc package. */
753 754
754static POINTER 755static POINTER
755r_alloc_sbrk (long int size) 756r_alloc_sbrk (ptrdiff_t size)
756{ 757{
757 register bloc_ptr b; 758 register bloc_ptr b;
758 POINTER address; 759 POINTER address;
@@ -937,7 +938,7 @@ r_alloc_free (register POINTER *ptr)
937 938
938 dead_bloc = find_bloc (ptr); 939 dead_bloc = find_bloc (ptr);
939 if (dead_bloc == NIL_BLOC) 940 if (dead_bloc == NIL_BLOC)
940 abort (); /* Double free? PTR not originally used to allocate? */ 941 emacs_abort (); /* Double free? PTR not originally used to allocate? */
941 942
942 free_bloc (dead_bloc); 943 free_bloc (dead_bloc);
943 *ptr = 0; 944 *ptr = 0;
@@ -979,7 +980,7 @@ r_re_alloc (POINTER *ptr, SIZE size)
979 980
980 bloc = find_bloc (ptr); 981 bloc = find_bloc (ptr);
981 if (bloc == NIL_BLOC) 982 if (bloc == NIL_BLOC)
982 abort (); /* Already freed? PTR not originally used to allocate? */ 983 emacs_abort (); /* Already freed? PTR not originally used to allocate? */
983 984
984 if (size < bloc->size) 985 if (size < bloc->size)
985 { 986 {
@@ -1152,7 +1153,7 @@ r_alloc_reset_variable (POINTER *old, POINTER *new)
1152 } 1153 }
1153 1154
1154 if (bloc == NIL_BLOC || bloc->variable != old) 1155 if (bloc == NIL_BLOC || bloc->variable != old)
1155 abort (); /* Already freed? OLD not originally used to allocate? */ 1156 emacs_abort (); /* Already freed? OLD not originally used to allocate? */
1156 1157
1157 /* Update variable to point to the new location. */ 1158 /* Update variable to point to the new location. */
1158 bloc->variable = new; 1159 bloc->variable = new;
@@ -1193,20 +1194,26 @@ r_alloc_init (void)
1193 first_heap->start = first_heap->bloc_start 1194 first_heap->start = first_heap->bloc_start
1194 = virtual_break_value = break_value = (*real_morecore) (0); 1195 = virtual_break_value = break_value = (*real_morecore) (0);
1195 if (break_value == NIL) 1196 if (break_value == NIL)
1196 abort (); 1197 emacs_abort ();
1197 1198
1198 extra_bytes = ROUNDUP (50000); 1199 extra_bytes = ROUNDUP (50000);
1199#endif 1200#endif
1200 1201
1201#ifdef DOUG_LEA_MALLOC 1202#ifdef DOUG_LEA_MALLOC
1202 BLOCK_INPUT; 1203 block_input ();
1203 mallopt (M_TOP_PAD, 64 * 4096); 1204 mallopt (M_TOP_PAD, 64 * 4096);
1204 UNBLOCK_INPUT; 1205 unblock_input ();
1205#else 1206#else
1206#ifndef SYSTEM_MALLOC 1207#ifndef SYSTEM_MALLOC
1207 /* Give GNU malloc's morecore some hysteresis 1208 /* Give GNU malloc's morecore some hysteresis so that we move all
1208 so that we move all the relocatable blocks much less often. */ 1209 the relocatable blocks much less often. The number used to be
1209 __malloc_extra_blocks = 64; 1210 64, but alloc.c would override that with 32 in code that was
1211 removed when SYNC_INPUT became the only input handling mode.
1212 That code was conditioned on !DOUG_LEA_MALLOC, so the call to
1213 mallopt above is left unchanged. (Actually, I think there's no
1214 system nowadays that uses DOUG_LEA_MALLOC and also uses
1215 REL_ALLOC.) */
1216 __malloc_extra_blocks = 32;
1210#endif 1217#endif
1211#endif 1218#endif
1212 1219