Mercurial > emacs
annotate src/ralloc.c @ 110237:b02c6c7716e4
Merge changes from emacs-23 branch.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Mon, 06 Sep 2010 12:40:56 -0400 |
parents | 68ca98ae70fb |
children | 417b1e4d63cd 7df2e30d72ec |
rev | line source |
---|---|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1 /* Block-relocating memory allocator. |
75227
e90d04cd455a
Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents:
73539
diff
changeset
|
2 Copyright (C) 1993, 1995, 2000, 2001, 2002, 2003, 2004, |
106815 | 3 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
118 | 4 |
5 This file is part of GNU Emacs. | |
6 | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79759
diff
changeset
|
7 GNU Emacs is free software: you can redistribute it and/or modify |
118 | 8 it under the terms of the GNU General Public License as published by |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79759
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79759
diff
changeset
|
10 (at your option) any later version. |
118 | 11 |
12 GNU Emacs is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79759
diff
changeset
|
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
118 | 19 |
20 /* NOTES: | |
21 | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3136
diff
changeset
|
22 Only relocate the blocs necessary for SIZE in r_alloc_sbrk, |
118 | 23 rather than all of them. This means allowing for a possible |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
24 hole between the first bloc and the end of malloc storage. */ |
118 | 25 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
26 #ifdef emacs |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
27 |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
4230
diff
changeset
|
28 #include <config.h> |
105669
68dd71358159
* alloc.c: Do not define struct catchtag.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100951
diff
changeset
|
29 #include <setjmp.h> |
577 | 30 #include "lisp.h" /* Needed for VALBITS. */ |
61226 | 31 #include "blockinput.h" |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
32 |
29917 | 33 #ifdef HAVE_UNISTD_H |
34 #include <unistd.h> | |
35 #endif | |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
36 |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
37 typedef POINTER_TYPE *POINTER; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
38 typedef size_t SIZE; |
1451
107c9b227e7f
[emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents:
1403
diff
changeset
|
39 |
17845
ac6367122ee2
(mallopt): Declare, if appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
14953
diff
changeset
|
40 #ifdef DOUG_LEA_MALLOC |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
41 #define M_TOP_PAD -2 |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
42 extern int mallopt (int, int); |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
43 #else /* not DOUG_LEA_MALLOC */ |
31498
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
44 #ifndef SYSTEM_MALLOC |
31891
d8d68cbd1113
(__malloc_extra_blocks): Declare as __malloc_size_t.
Dave Love <fx@gnu.org>
parents:
31606
diff
changeset
|
45 extern size_t __malloc_extra_blocks; |
31498
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
46 #endif /* SYSTEM_MALLOC */ |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
47 #endif /* not DOUG_LEA_MALLOC */ |
10785
f3a45c2e57c2
(r_alloc_init): Set __malloc_extra_blocks.
Richard M. Stallman <rms@gnu.org>
parents:
10767
diff
changeset
|
48 |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
49 #else /* not emacs */ |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
50 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
51 #include <stddef.h> |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
52 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
53 typedef size_t SIZE; |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
54 typedef void *POINTER; |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
55 |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
56 #include <unistd.h> |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
57 #include <malloc.h> |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
58 |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
59 #endif /* not emacs */ |
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
60 |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
61 |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
62 #include "getpagesize.h" |
118 | 63 |
64 #define NIL ((POINTER) 0) | |
65 | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
66 /* A flag to indicate whether we have initialized ralloc yet. For |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
67 Emacs's sake, please do not make this local to malloc_init; on some |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
68 machines, the dumping procedure makes all static variables |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
69 read-only. On these machines, the word static is #defined to be |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
70 the empty string, meaning that r_alloc_initialized becomes an |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
71 automatic variable, and loses its value each time Emacs is started |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
72 up. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
73 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
74 static int r_alloc_initialized = 0; |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
75 |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
76 static void r_alloc_init (void); |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
77 |
118 | 78 |
577 | 79 /* Declarations for working with the malloc, ralloc, and system breaks. */ |
80 | |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
81 /* Function to set the real break value. */ |
109516
68ca98ae70fb
Make building under stricter warning flags somewhat cleaner.
Juanma Barranquero <lekktu@gmail.com>
parents:
109501
diff
changeset
|
82 POINTER (*real_morecore) (long int); |
118 | 83 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
84 /* The break value, as seen by malloc. */ |
118 | 85 static POINTER virtual_break_value; |
86 | |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
87 /* The address of the end of the last data in use by ralloc, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
88 including relocatable blocs as well as malloc data. */ |
118 | 89 static POINTER break_value; |
90 | |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
91 /* This is the size of a page. We round memory requests to this boundary. */ |
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
92 static int page_size; |
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
93 |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
94 /* Whenever we get memory from the system, get this many extra bytes. This |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
95 must be a multiple of page_size. */ |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
96 static int extra_bytes; |
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
97 |
118 | 98 /* Macros for rounding. Note that rounding to any value is possible |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
99 by changing the definition of PAGE. */ |
118 | 100 #define PAGE (getpagesize ()) |
4230
df4d091e603e
(ALIGNED, ROUNDUP): Use `unsigned long int' instead of `unsigned int' for
Roland McGrath <roland@gnu.org>
parents:
3591
diff
changeset
|
101 #define ALIGNED(addr) (((unsigned long int) (addr) & (page_size - 1)) == 0) |
df4d091e603e
(ALIGNED, ROUNDUP): Use `unsigned long int' instead of `unsigned int' for
Roland McGrath <roland@gnu.org>
parents:
3591
diff
changeset
|
102 #define ROUNDUP(size) (((unsigned long int) (size) + page_size - 1) \ |
df4d091e603e
(ALIGNED, ROUNDUP): Use `unsigned long int' instead of `unsigned int' for
Roland McGrath <roland@gnu.org>
parents:
3591
diff
changeset
|
103 & ~(page_size - 1)) |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
104 #define ROUND_TO_PAGE(addr) (addr & (~(page_size - 1))) |
118 | 105 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
106 #define MEM_ALIGN sizeof(double) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
107 #define MEM_ROUNDUP(addr) (((unsigned long int)(addr) + MEM_ALIGN - 1) \ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
108 & ~(MEM_ALIGN - 1)) |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
109 |
36187
72f30168f26c
(__morecore) [!SYSTEM_MALLOC]: Move declaration
Gerd Moellmann <gerd@gnu.org>
parents:
31891
diff
changeset
|
110 /* The hook `malloc' uses for the function which gets more space |
72f30168f26c
(__morecore) [!SYSTEM_MALLOC]: Move declaration
Gerd Moellmann <gerd@gnu.org>
parents:
31891
diff
changeset
|
111 from the system. */ |
72f30168f26c
(__morecore) [!SYSTEM_MALLOC]: Move declaration
Gerd Moellmann <gerd@gnu.org>
parents:
31891
diff
changeset
|
112 |
72f30168f26c
(__morecore) [!SYSTEM_MALLOC]: Move declaration
Gerd Moellmann <gerd@gnu.org>
parents:
31891
diff
changeset
|
113 #ifndef SYSTEM_MALLOC |
109516
68ca98ae70fb
Make building under stricter warning flags somewhat cleaner.
Juanma Barranquero <lekktu@gmail.com>
parents:
109501
diff
changeset
|
114 extern POINTER (*__morecore) (long int); |
36187
72f30168f26c
(__morecore) [!SYSTEM_MALLOC]: Move declaration
Gerd Moellmann <gerd@gnu.org>
parents:
31891
diff
changeset
|
115 #endif |
72f30168f26c
(__morecore) [!SYSTEM_MALLOC]: Move declaration
Gerd Moellmann <gerd@gnu.org>
parents:
31891
diff
changeset
|
116 |
72f30168f26c
(__morecore) [!SYSTEM_MALLOC]: Move declaration
Gerd Moellmann <gerd@gnu.org>
parents:
31891
diff
changeset
|
117 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
118 |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
119 /*********************************************************************** |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
120 Implementation using sbrk |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
121 ***********************************************************************/ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
122 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
123 /* Data structures of heaps and blocs. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
124 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
125 /* The relocatable objects, or blocs, and the malloc data |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
126 both reside within one or more heaps. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
127 Each heap contains malloc data, running from `start' to `bloc_start', |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
128 and relocatable objects, running from `bloc_start' to `free'. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
129 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
130 Relocatable objects may relocate within the same heap |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
131 or may move into another heap; the heaps themselves may grow |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
132 but they never move. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
133 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
134 We try to make just one heap and make it larger as necessary. |
14036 | 135 But sometimes we can't do that, because we can't get contiguous |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
136 space to add onto the heap. When that happens, we start a new heap. */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
137 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
138 typedef struct heap |
118 | 139 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
140 struct heap *next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
141 struct heap *prev; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
142 /* Start of memory range of this heap. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
143 POINTER start; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
144 /* End of memory range of this heap. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
145 POINTER end; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
146 /* Start of relocatable data in this heap. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
147 POINTER bloc_start; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
148 /* Start of unused space in this heap. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
149 POINTER free; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
150 /* First bloc in this heap. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
151 struct bp *first_bloc; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
152 /* Last bloc in this heap. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
153 struct bp *last_bloc; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
154 } *heap_ptr; |
118 | 155 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
156 #define NIL_HEAP ((heap_ptr) 0) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
157 #define HEAP_PTR_SIZE (sizeof (struct heap)) |
118 | 158 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
159 /* This is the first heap object. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
160 If we need additional heap objects, each one resides at the beginning of |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
161 the space it covers. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
162 static struct heap heap_base; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
163 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
164 /* Head and tail of the list of heaps. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
165 static heap_ptr first_heap, last_heap; |
577 | 166 |
167 /* These structures are allocated in the malloc arena. | |
168 The linked list is kept in order of increasing '.data' members. | |
169 The data blocks abut each other; if b->next is non-nil, then | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
170 b->data + b->size == b->next->data. |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
171 |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
172 An element with variable==NIL denotes a freed block, which has not yet |
99767
0d5b71c55b3c
Fix typos in comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
95479
diff
changeset
|
173 been collected. They may only appear while r_alloc_freeze_level > 0, |
0d5b71c55b3c
Fix typos in comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
95479
diff
changeset
|
174 and will be freed when the arena is thawed. Currently, these blocs are |
0d5b71c55b3c
Fix typos in comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
95479
diff
changeset
|
175 not reusable, while the arena is frozen. Very inefficient. */ |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
176 |
118 | 177 typedef struct bp |
178 { | |
179 struct bp *next; | |
180 struct bp *prev; | |
181 POINTER *variable; | |
182 POINTER data; | |
183 SIZE size; | |
14036 | 184 POINTER new_data; /* temporarily used for relocation */ |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
185 struct heap *heap; /* Heap this bloc is in. */ |
118 | 186 } *bloc_ptr; |
187 | |
188 #define NIL_BLOC ((bloc_ptr) 0) | |
189 #define BLOC_PTR_SIZE (sizeof (struct bp)) | |
190 | |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
191 /* Head and tail of the list of relocatable blocs. */ |
118 | 192 static bloc_ptr first_bloc, last_bloc; |
193 | |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
194 static int use_relocatable_buffers; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
195 |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
196 /* If >0, no relocation whatsoever takes place. */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
197 static int r_alloc_freeze_level; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
198 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
199 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
200 /* Functions to get and return memory from the system. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
201 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
202 /* Find the heap that ADDRESS falls within. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
203 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
204 static heap_ptr |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
205 find_heap (POINTER address) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
206 { |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
207 heap_ptr heap; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
208 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
209 for (heap = last_heap; heap; heap = heap->prev) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
210 { |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
211 if (heap->start <= address && address <= heap->end) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
212 return heap; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
213 } |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
214 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
215 return NIL_HEAP; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
216 } |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
217 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
218 /* Find SIZE bytes of space in a heap. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
219 Try to get them at ADDRESS (which must fall within some heap's range) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
220 if we can get that many within one heap. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
221 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
222 If enough space is not presently available in our reserve, this means |
14036 | 223 getting more page-aligned space from the system. If the returned space |
224 is not contiguous to the last heap, allocate a new heap, and append it | |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
225 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
226 obtain does not try to keep track of whether space is in use |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
227 or not in use. It just returns the address of SIZE bytes that |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
228 fall within a single heap. If you call obtain twice in a row |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
229 with the same arguments, you typically get the same value. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
230 to the heap list. It's the caller's responsibility to keep |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
231 track of what space is in use. |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
232 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
233 Return the address of the space if all went well, or zero if we couldn't |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
234 allocate the memory. */ |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
235 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
236 static POINTER |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
237 obtain (POINTER address, SIZE size) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
238 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
239 heap_ptr heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
240 SIZE already_available; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
241 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
242 /* Find the heap that ADDRESS falls within. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
243 for (heap = last_heap; heap; heap = heap->prev) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
244 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
245 if (heap->start <= address && address <= heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
246 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
247 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
248 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
249 if (! heap) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
250 abort (); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
251 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
252 /* If we can't fit SIZE bytes in that heap, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
253 try successive later heaps. */ |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
254 while (heap && (char *) address + size > (char *) heap->end) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
255 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
256 heap = heap->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
257 if (heap == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
258 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
259 address = heap->bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
260 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
261 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
262 /* If we can't fit them within any existing heap, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
263 get more space. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
264 if (heap == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
265 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
266 POINTER new = (*real_morecore)(0); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
267 SIZE get; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
268 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
269 already_available = (char *)last_heap->end - (char *)address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
270 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
271 if (new != last_heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
272 { |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
273 /* Someone else called sbrk. Make a new heap. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
274 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
275 heap_ptr new_heap = (heap_ptr) MEM_ROUNDUP (new); |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
276 POINTER bloc_start = (POINTER) MEM_ROUNDUP ((POINTER)(new_heap + 1)); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
277 |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
278 if ((*real_morecore) ((char *) bloc_start - (char *) new) != new) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
279 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
280 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
281 new_heap->start = new; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
282 new_heap->end = bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
283 new_heap->bloc_start = bloc_start; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
284 new_heap->free = bloc_start; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
285 new_heap->next = NIL_HEAP; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
286 new_heap->prev = last_heap; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
287 new_heap->first_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
288 new_heap->last_bloc = NIL_BLOC; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
289 last_heap->next = new_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
290 last_heap = new_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
291 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
292 address = bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
293 already_available = 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
294 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
295 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
296 /* Add space to the last heap (which we may have just created). |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
297 Get some extra, so we can come here less often. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
298 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
299 get = size + extra_bytes - already_available; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
300 get = (char *) ROUNDUP ((char *)last_heap->end + get) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
301 - (char *) last_heap->end; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
302 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
303 if ((*real_morecore) (get) != last_heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
304 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
305 |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
306 last_heap->end = (char *) last_heap->end + get; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
307 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
308 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
309 return address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
310 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
311 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
312 /* Return unused heap space to the system |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
313 if there is a lot of unused space now. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
314 This can make the last heap smaller; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
315 it can also eliminate the last heap entirely. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
316 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
317 static void |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
318 relinquish (void) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
319 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
320 register heap_ptr h; |
73539
db045c86d29b
* ralloc.c (relinquish): Use a long for excess space counter to
Chong Yidong <cyd@stupidchicken.com>
parents:
68651
diff
changeset
|
321 long excess = 0; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
322 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
323 /* Add the amount of space beyond break_value |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
324 in all heaps which have extend beyond break_value at all. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
325 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
326 for (h = last_heap; h && break_value < h->end; h = h->prev) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
327 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
328 excess += (char *) h->end - (char *) ((break_value < h->bloc_start) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
329 ? h->bloc_start : break_value); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
330 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
331 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
332 if (excess > extra_bytes * 2 && (*real_morecore) (0) == last_heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
333 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
334 /* Keep extra_bytes worth of empty space. |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
335 And don't free anything unless we can free at least extra_bytes. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
336 excess -= extra_bytes; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
337 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
338 if ((char *)last_heap->end - (char *)last_heap->bloc_start <= excess) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
339 { |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
340 /* This heap should have no blocs in it. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
341 if (last_heap->first_bloc != NIL_BLOC |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
342 || last_heap->last_bloc != NIL_BLOC) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
343 abort (); |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
344 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
345 /* Return the last heap, with its header, to the system. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
346 excess = (char *)last_heap->end - (char *)last_heap->start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
347 last_heap = last_heap->prev; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
348 last_heap->next = NIL_HEAP; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
349 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
350 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
351 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
352 excess = (char *) last_heap->end |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
353 - (char *) ROUNDUP ((char *)last_heap->end - excess); |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
354 last_heap->end = (char *) last_heap->end - excess; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
355 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
356 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
357 if ((*real_morecore) (- excess) == 0) |
19999
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
358 { |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
359 /* If the system didn't want that much memory back, adjust |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
360 the end of the last heap to reflect that. This can occur |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
361 if break_value is still within the original data segment. */ |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
362 last_heap->end = (char *) last_heap->end + excess; |
19999
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
363 /* Make sure that the result of the adjustment is accurate. |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
364 It should be, for the else clause above; the other case, |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
365 which returns the entire last heap to the system, seems |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
366 unlikely to trigger this mode of failure. */ |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
367 if (last_heap->end != (*real_morecore) (0)) |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
368 abort (); |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
369 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
370 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
371 } |
10682
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
372 |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
373 /* Return the total size in use by relocating allocator, |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
374 above where malloc gets space. */ |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
375 |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
376 long |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
377 r_alloc_size_in_use (void) |
10682
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
378 { |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
379 return (char *) break_value - (char *) virtual_break_value; |
10682
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
380 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
381 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
382 /* The meat - allocating, freeing, and relocating blocs. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
383 |
577 | 384 /* Find the bloc referenced by the address in PTR. Returns a pointer |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
385 to that block. */ |
118 | 386 |
387 static bloc_ptr | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
388 find_bloc (POINTER *ptr) |
118 | 389 { |
390 register bloc_ptr p = first_bloc; | |
391 | |
392 while (p != NIL_BLOC) | |
393 { | |
100674
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
394 /* Consistency check. Don't return inconsistent blocs. |
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
395 Don't abort here, as callers might be expecting this, but |
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
396 callers that always expect a bloc to be returned should abort |
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
397 if one isn't to avoid a memory corruption bug that is |
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
398 difficult to track down. */ |
118 | 399 if (p->variable == ptr && p->data == *ptr) |
400 return p; | |
401 | |
402 p = p->next; | |
403 } | |
404 | |
405 return p; | |
406 } | |
407 | |
408 /* Allocate a bloc of SIZE bytes and append it to the chain of blocs. | |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
409 Returns a pointer to the new bloc, or zero if we couldn't allocate |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
410 memory for the new block. */ |
118 | 411 |
412 static bloc_ptr | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
413 get_bloc (SIZE size) |
118 | 414 { |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
415 register bloc_ptr new_bloc; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
416 register heap_ptr heap; |
118 | 417 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
418 if (! (new_bloc = (bloc_ptr) malloc (BLOC_PTR_SIZE)) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
419 || ! (new_bloc->data = obtain (break_value, size))) |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
420 { |
95479
9588c3703f38
remove useless if-before-free tests
Jim Meyering <jim@meyering.net>
parents:
94963
diff
changeset
|
421 free (new_bloc); |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
422 |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
423 return 0; |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
424 } |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
425 |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
426 break_value = (char *) new_bloc->data + size; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
427 |
118 | 428 new_bloc->size = size; |
429 new_bloc->next = NIL_BLOC; | |
1013
6bf2c4766d4c
* ralloc.c (get_bloc): When initializing new_bloc->variable, cast
Jim Blandy <jimb@redhat.com>
parents:
734
diff
changeset
|
430 new_bloc->variable = (POINTER *) NIL; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
431 new_bloc->new_data = 0; |
118 | 432 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
433 /* Record in the heap that this space is in use. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
434 heap = find_heap (new_bloc->data); |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
435 heap->free = break_value; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
436 |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
437 /* Maintain the correspondence between heaps and blocs. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
438 new_bloc->heap = heap; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
439 heap->last_bloc = new_bloc; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
440 if (heap->first_bloc == NIL_BLOC) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
441 heap->first_bloc = new_bloc; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
442 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
443 /* Put this bloc on the doubly-linked list of blocs. */ |
118 | 444 if (first_bloc) |
445 { | |
446 new_bloc->prev = last_bloc; | |
447 last_bloc->next = new_bloc; | |
448 last_bloc = new_bloc; | |
449 } | |
450 else | |
451 { | |
452 first_bloc = last_bloc = new_bloc; | |
453 new_bloc->prev = NIL_BLOC; | |
454 } | |
455 | |
456 return new_bloc; | |
457 } | |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
458 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
459 /* Calculate new locations of blocs in the list beginning with BLOC, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
460 relocating it to start at ADDRESS, in heap HEAP. If enough space is |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
461 not presently available in our reserve, call obtain for |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
462 more space. |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
463 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
464 Store the new location of each bloc in its new_data field. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
465 Do not touch the contents of blocs or break_value. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
466 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
467 static int |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
468 relocate_blocs (bloc_ptr bloc, heap_ptr heap, POINTER address) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
469 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
470 register bloc_ptr b = bloc; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
471 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
472 /* No need to ever call this if arena is frozen, bug somewhere! */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
473 if (r_alloc_freeze_level) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
474 abort(); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
475 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
476 while (b) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
477 { |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
478 /* If bloc B won't fit within HEAP, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
479 move to the next heap and try again. */ |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
480 while (heap && (char *) address + b->size > (char *) heap->end) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
481 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
482 heap = heap->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
483 if (heap == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
484 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
485 address = heap->bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
486 } |
118 | 487 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
488 /* If BLOC won't fit in any heap, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
489 get enough new space to hold BLOC and all following blocs. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
490 if (heap == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
491 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
492 register bloc_ptr tb = b; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
493 register SIZE s = 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
494 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
495 /* Add up the size of all the following blocs. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
496 while (tb != NIL_BLOC) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
497 { |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
498 if (tb->variable) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
499 s += tb->size; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
500 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
501 tb = tb->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
502 } |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
503 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
504 /* Get that space. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
505 address = obtain (address, s); |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
506 if (address == 0) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
507 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
508 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
509 heap = last_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
510 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
511 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
512 /* Record the new address of this bloc |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
513 and update where the next bloc can start. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
514 b->new_data = address; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
515 if (b->variable) |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
516 address = (char *) address + b->size; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
517 b = b->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
518 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
519 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
520 return 1; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
521 } |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
522 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
523 /* Update the records of which heaps contain which blocs, starting |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
524 with heap HEAP and bloc BLOC. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
525 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
526 static void |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
527 update_heap_bloc_correspondence (bloc_ptr bloc, heap_ptr heap) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
528 { |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
529 register bloc_ptr b; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
530 |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
531 /* Initialize HEAP's status to reflect blocs before BLOC. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
532 if (bloc != NIL_BLOC && bloc->prev != NIL_BLOC && bloc->prev->heap == heap) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
533 { |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
534 /* The previous bloc is in HEAP. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
535 heap->last_bloc = bloc->prev; |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
536 heap->free = (char *) bloc->prev->data + bloc->prev->size; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
537 } |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
538 else |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
539 { |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
540 /* HEAP contains no blocs before BLOC. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
541 heap->first_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
542 heap->last_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
543 heap->free = heap->bloc_start; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
544 } |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
545 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
546 /* Advance through blocs one by one. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
547 for (b = bloc; b != NIL_BLOC; b = b->next) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
548 { |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
549 /* Advance through heaps, marking them empty, |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
550 till we get to the one that B is in. */ |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
551 while (heap) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
552 { |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
553 if (heap->bloc_start <= b->data && b->data <= heap->end) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
554 break; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
555 heap = heap->next; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
556 /* We know HEAP is not null now, |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
557 because there has to be space for bloc B. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
558 heap->first_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
559 heap->last_bloc = NIL_BLOC; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
560 heap->free = heap->bloc_start; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
561 } |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
562 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
563 /* Update HEAP's status for bloc B. */ |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
564 heap->free = (char *) b->data + b->size; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
565 heap->last_bloc = b; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
566 if (heap->first_bloc == NIL_BLOC) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
567 heap->first_bloc = b; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
568 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
569 /* Record that B is in HEAP. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
570 b->heap = heap; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
571 } |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
572 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
573 /* If there are any remaining heaps and no blocs left, |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
574 mark those heaps as empty. */ |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
575 heap = heap->next; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
576 while (heap) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
577 { |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
578 heap->first_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
579 heap->last_bloc = NIL_BLOC; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
580 heap->free = heap->bloc_start; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
581 heap = heap->next; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
582 } |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
583 } |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
584 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
585 /* Resize BLOC to SIZE bytes. This relocates the blocs |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
586 that come after BLOC in memory. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
587 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
588 static int |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
589 resize_bloc (bloc_ptr bloc, SIZE size) |
118 | 590 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
591 register bloc_ptr b; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
592 heap_ptr heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
593 POINTER address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
594 SIZE old_size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
595 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
596 /* No need to ever call this if arena is frozen, bug somewhere! */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
597 if (r_alloc_freeze_level) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
598 abort(); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
599 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
600 if (bloc == NIL_BLOC || size == bloc->size) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
601 return 1; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
602 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
603 for (heap = first_heap; heap != NIL_HEAP; heap = heap->next) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
604 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
605 if (heap->bloc_start <= bloc->data && bloc->data <= heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
606 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
607 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
608 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
609 if (heap == NIL_HEAP) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
610 abort (); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
611 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
612 old_size = bloc->size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
613 bloc->size = size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
614 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
615 /* Note that bloc could be moved into the previous heap. */ |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
616 address = (bloc->prev ? (char *) bloc->prev->data + bloc->prev->size |
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
617 : (char *) first_heap->bloc_start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
618 while (heap) |
118 | 619 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
620 if (heap->bloc_start <= address && address <= heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
621 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
622 heap = heap->prev; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
623 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
624 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
625 if (! relocate_blocs (bloc, heap, address)) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
626 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
627 bloc->size = old_size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
628 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
629 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
630 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
631 if (size > old_size) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
632 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
633 for (b = last_bloc; b != bloc; b = b->prev) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
634 { |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
635 if (!b->variable) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
636 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
637 b->size = 0; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
638 b->data = b->new_data; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
639 } |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
640 else |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
641 { |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
642 memmove (b->new_data, b->data, b->size); |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
643 *b->variable = b->data = b->new_data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
644 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
645 } |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
646 if (!bloc->variable) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
647 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
648 bloc->size = 0; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
649 bloc->data = bloc->new_data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
650 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
651 else |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
652 { |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
653 memmove (bloc->new_data, bloc->data, old_size); |
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
654 memset (bloc->new_data + old_size, 0, size - old_size); |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
655 *bloc->variable = bloc->data = bloc->new_data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
656 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
657 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
658 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
659 { |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
660 for (b = bloc; b != NIL_BLOC; b = b->next) |
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
661 { |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
662 if (!b->variable) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
663 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
664 b->size = 0; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
665 b->data = b->new_data; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
666 } |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
667 else |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
668 { |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
669 memmove (b->new_data, b->data, b->size); |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
670 *b->variable = b->data = b->new_data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
671 } |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
672 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
673 } |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
674 |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
675 update_heap_bloc_correspondence (bloc, heap); |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
676 |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
677 break_value = (last_bloc ? (char *) last_bloc->data + last_bloc->size |
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
678 : (char *) first_heap->bloc_start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
679 return 1; |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
680 } |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
681 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
682 /* Free BLOC from the chain of blocs, relocating any blocs above it. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
683 This may return space to the system. */ |
118 | 684 |
685 static void | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
686 free_bloc (bloc_ptr bloc) |
118 | 687 { |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
688 heap_ptr heap = bloc->heap; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
689 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
690 if (r_alloc_freeze_level) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
691 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
692 bloc->variable = (POINTER *) NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
693 return; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
694 } |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
695 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
696 resize_bloc (bloc, 0); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
697 |
118 | 698 if (bloc == first_bloc && bloc == last_bloc) |
699 { | |
700 first_bloc = last_bloc = NIL_BLOC; | |
701 } | |
702 else if (bloc == last_bloc) | |
703 { | |
704 last_bloc = bloc->prev; | |
705 last_bloc->next = NIL_BLOC; | |
706 } | |
707 else if (bloc == first_bloc) | |
708 { | |
709 first_bloc = bloc->next; | |
710 first_bloc->prev = NIL_BLOC; | |
711 } | |
712 else | |
713 { | |
714 bloc->next->prev = bloc->prev; | |
715 bloc->prev->next = bloc->next; | |
716 } | |
717 | |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
718 /* Update the records of which blocs are in HEAP. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
719 if (heap->first_bloc == bloc) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
720 { |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
721 if (bloc->next != 0 && bloc->next->heap == heap) |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
722 heap->first_bloc = bloc->next; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
723 else |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
724 heap->first_bloc = heap->last_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
725 } |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
726 if (heap->last_bloc == bloc) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
727 { |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
728 if (bloc->prev != 0 && bloc->prev->heap == heap) |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
729 heap->last_bloc = bloc->prev; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
730 else |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
731 heap->first_bloc = heap->last_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
732 } |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
733 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
734 relinquish (); |
118 | 735 free (bloc); |
736 } | |
737 | |
577 | 738 /* Interface routines. */ |
739 | |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
740 /* Obtain SIZE bytes of storage from the free pool, or the system, as |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
741 necessary. If relocatable blocs are in use, this means relocating |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
742 them. This function gets plugged into the GNU malloc's __morecore |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
743 hook. |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
744 |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
745 We provide hysteresis, never relocating by less than extra_bytes. |
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
746 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
747 If we're out of memory, we should return zero, to imitate the other |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
748 __morecore hook values - in particular, __default_morecore in the |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
749 GNU malloc package. */ |
118 | 750 |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
751 POINTER |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
752 r_alloc_sbrk (long int size) |
118 | 753 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
754 register bloc_ptr b; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
755 POINTER address; |
118 | 756 |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
757 if (! r_alloc_initialized) |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
758 r_alloc_init (); |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
759 |
118 | 760 if (! use_relocatable_buffers) |
1401 | 761 return (*real_morecore) (size); |
118 | 762 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
763 if (size == 0) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
764 return virtual_break_value; |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
765 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
766 if (size > 0) |
118 | 767 { |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
768 /* Allocate a page-aligned space. GNU malloc would reclaim an |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
769 extra space if we passed an unaligned one. But we could |
14036 | 770 not always find a space which is contiguous to the previous. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
771 POINTER new_bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
772 heap_ptr h = first_heap; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
773 SIZE get = ROUNDUP (size); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
774 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
775 address = (POINTER) ROUNDUP (virtual_break_value); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
776 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
777 /* Search the list upward for a heap which is large enough. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
778 while ((char *) h->end < (char *) MEM_ROUNDUP ((char *)address + get)) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
779 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
780 h = h->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
781 if (h == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
782 break; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
783 address = (POINTER) ROUNDUP (h->start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
784 } |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
785 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
786 /* If not found, obtain more space. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
787 if (h == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
788 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
789 get += extra_bytes + page_size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
790 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
791 if (! obtain (address, get)) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
792 return 0; |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
793 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
794 if (first_heap == last_heap) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
795 address = (POINTER) ROUNDUP (virtual_break_value); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
796 else |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
797 address = (POINTER) ROUNDUP (last_heap->start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
798 h = last_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
799 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
800 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
801 new_bloc_start = (POINTER) MEM_ROUNDUP ((char *)address + get); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
802 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
803 if (first_heap->bloc_start < new_bloc_start) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
804 { |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
805 /* This is no clean solution - no idea how to do it better. */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
806 if (r_alloc_freeze_level) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
807 return NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
808 |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
809 /* There is a bug here: if the above obtain call succeeded, but the |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
810 relocate_blocs call below does not succeed, we need to free |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
811 the memory that we got with obtain. */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
812 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
813 /* Move all blocs upward. */ |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
814 if (! relocate_blocs (first_bloc, h, new_bloc_start)) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
815 return 0; |
577 | 816 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
817 /* Note that (POINTER)(h+1) <= new_bloc_start since |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
818 get >= page_size, so the following does not destroy the heap |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
819 header. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
820 for (b = last_bloc; b != NIL_BLOC; b = b->prev) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
821 { |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
822 memmove (b->new_data, b->data, b->size); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
823 *b->variable = b->data = b->new_data; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
824 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
825 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
826 h->bloc_start = new_bloc_start; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
827 |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
828 update_heap_bloc_correspondence (first_bloc, h); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
829 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
830 if (h != first_heap) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
831 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
832 /* Give up managing heaps below the one the new |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
833 virtual_break_value points to. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
834 first_heap->prev = NIL_HEAP; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
835 first_heap->next = h->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
836 first_heap->start = h->start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
837 first_heap->end = h->end; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
838 first_heap->free = h->free; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
839 first_heap->first_bloc = h->first_bloc; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
840 first_heap->last_bloc = h->last_bloc; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
841 first_heap->bloc_start = h->bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
842 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
843 if (first_heap->next) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
844 first_heap->next->prev = first_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
845 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
846 last_heap = first_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
847 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
848 |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
849 memset (address, 0, size); |
118 | 850 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
851 else /* size < 0 */ |
118 | 852 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
853 SIZE excess = (char *)first_heap->bloc_start |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
854 - ((char *)virtual_break_value + size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
855 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
856 address = virtual_break_value; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
857 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
858 if (r_alloc_freeze_level == 0 && excess > 2 * extra_bytes) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
859 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
860 excess -= extra_bytes; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
861 first_heap->bloc_start |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
862 = (POINTER) MEM_ROUNDUP ((char *)first_heap->bloc_start - excess); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
863 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
864 relocate_blocs (first_bloc, first_heap, first_heap->bloc_start); |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
865 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
866 for (b = first_bloc; b != NIL_BLOC; b = b->next) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
867 { |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
868 memmove (b->new_data, b->data, b->size); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
869 *b->variable = b->data = b->new_data; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
870 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
871 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
872 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
873 if ((char *)virtual_break_value + size < (char *)first_heap->start) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
874 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
875 /* We found an additional space below the first heap */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
876 first_heap->start = (POINTER) ((char *)virtual_break_value + size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
877 } |
118 | 878 } |
879 | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
880 virtual_break_value = (POINTER) ((char *)address + size); |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
881 break_value = (last_bloc |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
882 ? (char *) last_bloc->data + last_bloc->size |
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
883 : (char *) first_heap->bloc_start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
884 if (size < 0) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
885 relinquish (); |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
886 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
887 return address; |
118 | 888 } |
889 | |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
890 |
118 | 891 /* Allocate a relocatable bloc of storage of size SIZE. A pointer to |
892 the data is returned in *PTR. PTR is thus the address of some variable | |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
893 which will use the data area. |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
894 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
895 The allocation of 0 bytes is valid. |
99767
0d5b71c55b3c
Fix typos in comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
95479
diff
changeset
|
896 In case r_alloc_freeze_level is set, a best fit of unused blocs could be |
0d5b71c55b3c
Fix typos in comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
95479
diff
changeset
|
897 done before allocating a new area. Not yet done. |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
898 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
899 If we can't allocate the necessary memory, set *PTR to zero, and |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
900 return zero. */ |
118 | 901 |
902 POINTER | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
903 r_alloc (POINTER *ptr, SIZE size) |
118 | 904 { |
905 register bloc_ptr new_bloc; | |
906 | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
907 if (! r_alloc_initialized) |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
908 r_alloc_init (); |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
909 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
910 new_bloc = get_bloc (MEM_ROUNDUP (size)); |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
911 if (new_bloc) |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
912 { |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
913 new_bloc->variable = ptr; |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
914 *ptr = new_bloc->data; |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
915 } |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
916 else |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
917 *ptr = 0; |
118 | 918 |
919 return *ptr; | |
920 } | |
921 | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
922 /* Free a bloc of relocatable storage whose data is pointed to by PTR. |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
923 Store 0 in *PTR to show there's no block allocated. */ |
118 | 924 |
925 void | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
926 r_alloc_free (register POINTER *ptr) |
118 | 927 { |
928 register bloc_ptr dead_bloc; | |
929 | |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
930 if (! r_alloc_initialized) |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
931 r_alloc_init (); |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
932 |
118 | 933 dead_bloc = find_bloc (ptr); |
934 if (dead_bloc == NIL_BLOC) | |
100674
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
935 abort (); /* Double free? PTR not originally used to allocate? */ |
118 | 936 |
937 free_bloc (dead_bloc); | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
938 *ptr = 0; |
10682
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
939 |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
940 #ifdef emacs |
10682
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
941 refill_memory_reserve (); |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
942 #endif |
118 | 943 } |
944 | |
1087
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
945 /* Given a pointer at address PTR to relocatable data, resize it to SIZE. |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
946 Do this by shifting all blocks above this one up in memory, unless |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
947 SIZE is less than or equal to the current bloc size, in which case |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
948 do nothing. |
118 | 949 |
99767
0d5b71c55b3c
Fix typos in comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
95479
diff
changeset
|
950 In case r_alloc_freeze_level is set, a new bloc is allocated, and the |
14036 | 951 memory copied to it. Not very efficient. We could traverse the |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
952 bloc_list for a best fit of free blocs first. |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
953 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
954 Change *PTR to reflect the new bloc, and return this value. |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
955 |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
956 If more memory cannot be allocated, then leave *PTR unchanged, and |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
957 return zero. */ |
118 | 958 |
959 POINTER | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
960 r_re_alloc (POINTER *ptr, SIZE size) |
118 | 961 { |
1087
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
962 register bloc_ptr bloc; |
118 | 963 |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
964 if (! r_alloc_initialized) |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
965 r_alloc_init (); |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
966 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
967 if (!*ptr) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
968 return r_alloc (ptr, size); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
969 if (!size) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
970 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
971 r_alloc_free (ptr); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
972 return r_alloc (ptr, 0); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
973 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
974 |
1087
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
975 bloc = find_bloc (ptr); |
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
976 if (bloc == NIL_BLOC) |
100674
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
977 abort (); /* Already freed? PTR not originally used to allocate? */ |
118 | 978 |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
979 if (size < bloc->size) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
980 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
981 /* Wouldn't it be useful to actually resize the bloc here? */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
982 /* I think so too, but not if it's too expensive... */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
983 if ((bloc->size - MEM_ROUNDUP (size) >= page_size) |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
984 && r_alloc_freeze_level == 0) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
985 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
986 resize_bloc (bloc, MEM_ROUNDUP (size)); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
987 /* Never mind if this fails, just do nothing... */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
988 /* It *should* be infallible! */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
989 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
990 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
991 else if (size > bloc->size) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
992 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
993 if (r_alloc_freeze_level) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
994 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
995 bloc_ptr new_bloc; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
996 new_bloc = get_bloc (MEM_ROUNDUP (size)); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
997 if (new_bloc) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
998 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
999 new_bloc->variable = ptr; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1000 *ptr = new_bloc->data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1001 bloc->variable = (POINTER *) NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1002 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1003 else |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1004 return NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1005 } |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1006 else |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1007 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1008 if (! resize_bloc (bloc, MEM_ROUNDUP (size))) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1009 return NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1010 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1011 } |
118 | 1012 return *ptr; |
1013 } | |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1014 |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1015 /* Disable relocations, after making room for at least SIZE bytes |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1016 of non-relocatable heap if possible. The relocatable blocs are |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1017 guaranteed to hold still until thawed, even if this means that |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1018 malloc must return a null pointer. */ |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
1019 |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1020 void |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
1021 r_alloc_freeze (long int size) |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1022 { |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1023 if (! r_alloc_initialized) |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1024 r_alloc_init (); |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1025 |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1026 /* If already frozen, we can't make any more room, so don't try. */ |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1027 if (r_alloc_freeze_level > 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1028 size = 0; |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1029 /* If we can't get the amount requested, half is better than nothing. */ |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1030 while (size > 0 && r_alloc_sbrk (size) == 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1031 size /= 2; |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1032 ++r_alloc_freeze_level; |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1033 if (size > 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1034 r_alloc_sbrk (-size); |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1035 } |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1036 |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1037 void |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
1038 r_alloc_thaw (void) |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1039 { |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1040 |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1041 if (! r_alloc_initialized) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1042 r_alloc_init (); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1043 |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1044 if (--r_alloc_freeze_level < 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1045 abort (); |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1046 |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1047 /* This frees all unused blocs. It is not too inefficient, as the resize |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
1048 and memcpy is done only once. Afterwards, all unreferenced blocs are |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1049 already shrunk to zero size. */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1050 if (!r_alloc_freeze_level) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1051 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1052 bloc_ptr *b = &first_bloc; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1053 while (*b) |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1054 if (!(*b)->variable) |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1055 free_bloc (*b); |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1056 else |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1057 b = &(*b)->next; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1058 } |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1059 } |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1060 |
18757
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1061 |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1062 #if defined (emacs) && defined (DOUG_LEA_MALLOC) |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1063 |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1064 /* Reinitialize the morecore hook variables after restarting a dumped |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1065 Emacs. This is needed when using Doug Lea's malloc from GNU libc. */ |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1066 void |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
1067 r_alloc_reinit (void) |
18757
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1068 { |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1069 /* Only do this if the hook has been reset, so that we don't get an |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1070 infinite loop, in case Emacs was linked statically. */ |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1071 if (__morecore != r_alloc_sbrk) |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1072 { |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1073 real_morecore = __morecore; |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1074 __morecore = r_alloc_sbrk; |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1075 } |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1076 } |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1077 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1078 #endif /* emacs && DOUG_LEA_MALLOC */ |
18757
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1079 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1080 #ifdef DEBUG |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1081 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1082 #include <assert.h> |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1083 |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1084 void |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1085 r_alloc_check () |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1086 { |
10766 | 1087 int found = 0; |
1088 heap_ptr h, ph = 0; | |
1089 bloc_ptr b, pb = 0; | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1090 |
10766 | 1091 if (!r_alloc_initialized) |
1092 return; | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1093 |
10766 | 1094 assert (first_heap); |
1095 assert (last_heap->end <= (POINTER) sbrk (0)); | |
1096 assert ((POINTER) first_heap < first_heap->start); | |
1097 assert (first_heap->start <= virtual_break_value); | |
1098 assert (virtual_break_value <= first_heap->end); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1099 |
10766 | 1100 for (h = first_heap; h; h = h->next) |
1101 { | |
1102 assert (h->prev == ph); | |
1103 assert ((POINTER) ROUNDUP (h->end) == h->end); | |
14953
36e4b3043730
(r_alloc_check): Don't check alignment of h->start.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
1104 #if 0 /* ??? The code in ralloc.c does not really try to ensure |
36e4b3043730
(r_alloc_check): Don't check alignment of h->start.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
1105 the heap start has any sort of alignment. |
36e4b3043730
(r_alloc_check): Don't check alignment of h->start.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
1106 Perhaps it should. */ |
10766 | 1107 assert ((POINTER) MEM_ROUNDUP (h->start) == h->start); |
14953
36e4b3043730
(r_alloc_check): Don't check alignment of h->start.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
1108 #endif |
10766 | 1109 assert ((POINTER) MEM_ROUNDUP (h->bloc_start) == h->bloc_start); |
1110 assert (h->start <= h->bloc_start && h->bloc_start <= h->end); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1111 |
10766 | 1112 if (ph) |
1113 { | |
1114 assert (ph->end < h->start); | |
1115 assert (h->start <= (POINTER)h && (POINTER)(h+1) <= h->bloc_start); | |
1116 } | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1117 |
10766 | 1118 if (h->bloc_start <= break_value && break_value <= h->end) |
1119 found = 1; | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1120 |
10766 | 1121 ph = h; |
1122 } | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1123 |
10766 | 1124 assert (found); |
1125 assert (last_heap == ph); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1126 |
10766 | 1127 for (b = first_bloc; b; b = b->next) |
1128 { | |
1129 assert (b->prev == pb); | |
1130 assert ((POINTER) MEM_ROUNDUP (b->data) == b->data); | |
1131 assert ((SIZE) MEM_ROUNDUP (b->size) == b->size); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1132 |
10766 | 1133 ph = 0; |
1134 for (h = first_heap; h; h = h->next) | |
1135 { | |
1136 if (h->bloc_start <= b->data && b->data + b->size <= h->end) | |
1137 break; | |
1138 ph = h; | |
1139 } | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1140 |
10766 | 1141 assert (h); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1142 |
10766 | 1143 if (pb && pb->data + pb->size != b->data) |
1144 { | |
1145 assert (ph && b->data == h->bloc_start); | |
1146 while (ph) | |
1147 { | |
1148 if (ph->bloc_start <= pb->data | |
1149 && pb->data + pb->size <= ph->end) | |
1150 { | |
1151 assert (pb->data + pb->size + b->size > ph->end); | |
1152 break; | |
1153 } | |
1154 else | |
1155 { | |
1156 assert (ph->bloc_start + b->size > ph->end); | |
1157 } | |
1158 ph = ph->prev; | |
1159 } | |
1160 } | |
1161 pb = b; | |
1162 } | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1163 |
10766 | 1164 assert (last_bloc == pb); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1165 |
10766 | 1166 if (last_bloc) |
1167 assert (last_bloc->data + last_bloc->size == break_value); | |
1168 else | |
1169 assert (first_heap->bloc_start == break_value); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1170 } |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1171 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1172 #endif /* DEBUG */ |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1173 |
100673
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1174 /* Update the internal record of which variable points to some data to NEW. |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1175 Used by buffer-swap-text in Emacs to restore consistency after it |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1176 swaps the buffer text between two buffer objects. The OLD pointer |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1177 is checked to ensure that memory corruption does not occur due to |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1178 misuse. */ |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1179 void |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
1180 r_alloc_reset_variable (POINTER *old, POINTER *new) |
100673
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1181 { |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1182 bloc_ptr bloc = first_bloc; |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1183 |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1184 /* Find the bloc that corresponds to the data pointed to by pointer. |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1185 find_bloc cannot be used, as it has internal consistency checks |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1186 which fail when the variable needs reseting. */ |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1187 while (bloc != NIL_BLOC) |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1188 { |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1189 if (bloc->data == *new) |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1190 break; |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1191 |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1192 bloc = bloc->next; |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1193 } |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1194 |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1195 if (bloc == NIL_BLOC || bloc->variable != old) |
100674
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
1196 abort (); /* Already freed? OLD not originally used to allocate? */ |
100673
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1197 |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1198 /* Update variable to point to the new location. */ |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1199 bloc->variable = new; |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1200 } |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1201 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1202 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1203 /*********************************************************************** |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1204 Initialization |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1205 ***********************************************************************/ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1206 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1207 /* Initialize various things for memory allocation. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1208 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1209 static void |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
1210 r_alloc_init (void) |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1211 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1212 if (r_alloc_initialized) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1213 return; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1214 r_alloc_initialized = 1; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1215 |
31498
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
1216 page_size = PAGE; |
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
1217 #ifndef SYSTEM_MALLOC |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1218 real_morecore = __morecore; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1219 __morecore = r_alloc_sbrk; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1220 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1221 first_heap = last_heap = &heap_base; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1222 first_heap->next = first_heap->prev = NIL_HEAP; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1223 first_heap->start = first_heap->bloc_start |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1224 = virtual_break_value = break_value = (*real_morecore) (0); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1225 if (break_value == NIL) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1226 abort (); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1227 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1228 extra_bytes = ROUNDUP (50000); |
31498
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
1229 #endif |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1230 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1231 #ifdef DOUG_LEA_MALLOC |
61225
1e515cc6ca0c
* alloc.c (allocate_string_data): Call BLOCK_INPUT before calling
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1232 BLOCK_INPUT; |
1e515cc6ca0c
* alloc.c (allocate_string_data): Call BLOCK_INPUT before calling
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1233 mallopt (M_TOP_PAD, 64 * 4096); |
1e515cc6ca0c
* alloc.c (allocate_string_data): Call BLOCK_INPUT before calling
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1234 UNBLOCK_INPUT; |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1235 #else |
31498
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
1236 #ifndef SYSTEM_MALLOC |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1237 /* Give GNU malloc's morecore some hysteresis |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1238 so that we move all the relocatable blocks much less often. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1239 __malloc_extra_blocks = 64; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1240 #endif |
31498
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
1241 #endif |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1242 |
31509
6bc82db7d305
(r_alloc_init): Conditionalize on SYSTEM_MALLOC, not REL_ALLOC_MMAP.
Dave Love <fx@gnu.org>
parents:
31504
diff
changeset
|
1243 #ifndef SYSTEM_MALLOC |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1244 first_heap->end = (POINTER) ROUNDUP (first_heap->start); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1245 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1246 /* The extra call to real_morecore guarantees that the end of the |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1247 address space is a multiple of page_size, even if page_size is |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1248 not really the page size of the system running the binary in |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1249 which page_size is stored. This allows a binary to be built on a |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1250 system with one page size and run on a system with a smaller page |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1251 size. */ |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
1252 (*real_morecore) ((char *) first_heap->end - (char *) first_heap->start); |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1253 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1254 /* Clear the rest of the last page; this memory is in our address space |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1255 even though it is after the sbrk value. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1256 /* Doubly true, with the additional call that explicitly adds the |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1257 rest of that page to the address space. */ |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
1258 memset (first_heap->start, 0, |
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
1259 (char *) first_heap->end - (char *) first_heap->start); |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1260 virtual_break_value = break_value = first_heap->bloc_start = first_heap->end; |
31498
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
1261 #endif |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1262 |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1263 use_relocatable_buffers = 1; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1264 } |
52401 | 1265 |
1266 /* arch-tag: 6a524a15-faff-44c8-95d4-a5da6f55110f | |
1267 (do not change this comment) */ |