Mercurial > emacs
annotate src/ralloc.c @ 9459:a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
where the C library makes calls to sbrk directly.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Wed, 12 Oct 1994 00:48:03 +0000 |
parents | b628561b185b |
children | 134f7085c56b |
rev | line source |
---|---|
118 | 1 /* Block-relocating memory allocator. |
2961 | 2 Copyright (C) 1993 Free Software Foundation, Inc. |
118 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 1, or (at your option) | |
9 any later version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
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 |
24 hole between the first bloc and the end of malloc storage. */ | |
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> |
577 | 29 #include "lisp.h" /* Needed for VALBITS. */ |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
30 |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
31 #undef NULL |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
32 |
1451
107c9b227e7f
[emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents:
1403
diff
changeset
|
33 /* The important properties of this type are that 1) it's a pointer, and |
107c9b227e7f
[emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents:
1403
diff
changeset
|
34 2) arithmetic on it should work as if the size of the object pointed |
107c9b227e7f
[emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents:
1403
diff
changeset
|
35 to has a size of 1. */ |
3109
cd1bbe721cb5
(POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
36 #if 0 /* Arithmetic on void* is a GCC extension. */ |
1451
107c9b227e7f
[emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents:
1403
diff
changeset
|
37 #ifdef __STDC__ |
107c9b227e7f
[emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents:
1403
diff
changeset
|
38 typedef void *POINTER; |
107c9b227e7f
[emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents:
1403
diff
changeset
|
39 #else |
1729
5c3898c5aa2d
[! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents:
1595
diff
changeset
|
40 |
5c3898c5aa2d
[! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents:
1595
diff
changeset
|
41 #ifdef HAVE_CONFIG_H |
5c3898c5aa2d
[! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents:
1595
diff
changeset
|
42 #include "config.h" |
5c3898c5aa2d
[! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents:
1595
diff
changeset
|
43 #endif |
5c3898c5aa2d
[! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents:
1595
diff
changeset
|
44 |
1451
107c9b227e7f
[emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents:
1403
diff
changeset
|
45 typedef char *POINTER; |
1729
5c3898c5aa2d
[! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents:
1595
diff
changeset
|
46 |
1451
107c9b227e7f
[emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents:
1403
diff
changeset
|
47 #endif |
3109
cd1bbe721cb5
(POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
48 #endif /* 0 */ |
cd1bbe721cb5
(POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
49 |
cd1bbe721cb5
(POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
50 /* Unconditionally use char * for this. */ |
cd1bbe721cb5
(POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
51 typedef char *POINTER; |
1451
107c9b227e7f
[emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents:
1403
diff
changeset
|
52 |
107c9b227e7f
[emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents:
1403
diff
changeset
|
53 typedef unsigned long SIZE; |
107c9b227e7f
[emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents:
1403
diff
changeset
|
54 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
55 /* Declared in dispnew.c, this version doesn't screw up if regions |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
56 overlap. */ |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
57 extern void safe_bcopy (); |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
58 |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
59 #include "getpagesize.h" |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
60 |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
61 #else /* Not emacs. */ |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
62 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
63 #include <stddef.h> |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
64 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
65 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
|
66 typedef void *POINTER; |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
67 |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
68 #include <unistd.h> |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
69 #include <malloc.h> |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
70 #include <string.h> |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
71 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
72 #define safe_bcopy(x, y, z) memmove (y, x, z) |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
73 |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
74 #endif /* emacs. */ |
118 | 75 |
76 #define NIL ((POINTER) 0) | |
77 | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
78 /* 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
|
79 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
|
80 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
|
81 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
|
82 the empty string, meaning that r_alloc_initialized becomes an |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
83 automatic variable, and loses its value each time Emacs is started up. */ |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
84 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
|
85 |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
86 static void r_alloc_init (); |
118 | 87 |
577 | 88 /* Declarations for working with the malloc, ralloc, and system breaks. */ |
89 | |
1401 | 90 /* Function to set the real break value. */ |
91 static POINTER (*real_morecore) (); | |
118 | 92 |
93 /* The break value, as seen by malloc (). */ | |
94 static POINTER virtual_break_value; | |
95 | |
96 /* The break value, viewed by the relocatable blocs. */ | |
97 static POINTER break_value; | |
98 | |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
99 /* 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
|
100 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
|
101 |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
102 /* Whenever we get memory from the system, get this many extra bytes. This |
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
103 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
|
104 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
|
105 |
118 | 106 /* Macros for rounding. Note that rounding to any value is possible |
107 by changing the definition of PAGE. */ | |
108 #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
|
109 #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
|
110 #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
|
111 & ~(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
|
112 #define ROUND_TO_PAGE(addr) (addr & (~(page_size - 1))) |
118 | 113 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
114 #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
|
115 #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
|
116 & ~(MEM_ALIGN - 1)) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
117 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
118 /* Data structures of heaps and blocs */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
119 typedef struct heap |
118 | 120 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
121 struct heap *next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
122 struct heap *prev; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
123 POINTER start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
124 POINTER end; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
125 POINTER bloc_start; /* start of relocatable blocs */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
126 } *heap_ptr; |
118 | 127 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
128 #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
|
129 #define HEAP_PTR_SIZE (sizeof (struct heap)) |
118 | 130 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
131 /* Head and tail of the list of heaps. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
132 static heap_ptr first_heap, last_heap; |
577 | 133 |
134 /* These structures are allocated in the malloc arena. | |
135 The linked list is kept in order of increasing '.data' members. | |
136 The data blocks abut each other; if b->next is non-nil, then | |
137 b->data + b->size == b->next->data. */ | |
118 | 138 typedef struct bp |
139 { | |
140 struct bp *next; | |
141 struct bp *prev; | |
142 POINTER *variable; | |
143 POINTER data; | |
144 SIZE size; | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
145 POINTER new_data; /* tmporarily used for relocation */ |
118 | 146 } *bloc_ptr; |
147 | |
148 #define NIL_BLOC ((bloc_ptr) 0) | |
149 #define BLOC_PTR_SIZE (sizeof (struct bp)) | |
150 | |
151 /* Head and tail of the list of relocatable blocs. */ | |
152 static bloc_ptr first_bloc, last_bloc; | |
153 | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
154 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
155 /* 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
|
156 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
157 /* Obtain SIZE bytes of space starting at ADDRESS in a heap. |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
158 If enough space is not presently available in our reserve, this means |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
159 getting more page-aligned space from the system. If the retuned space |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
160 is not contiguos to the last heap, allocate a new heap, and append it |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
161 to the heap list. |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
162 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
163 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
|
164 allocate the memory. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
165 static POINTER |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
166 obtain (address, size) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
167 POINTER address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
168 SIZE size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
169 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
170 heap_ptr heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
171 SIZE already_available; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
172 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
173 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
|
174 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
175 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
|
176 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
177 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
178 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
179 if (! heap) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
180 abort(); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
181 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
182 while (heap && address + size > heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
183 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
184 heap = heap->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
185 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
|
186 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
187 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
|
188 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
189 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
190 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
|
191 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
192 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
|
193 SIZE get; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
194 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
195 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
|
196 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
197 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
|
198 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
199 /* Someone else called sbrk(). */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
200 heap_ptr new_heap = (heap_ptr) MEM_ROUNDUP(new); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
201 POINTER bloc_start = (POINTER) MEM_ROUNDUP((POINTER)(new_heap + 1)); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
202 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
203 if ((*real_morecore) (bloc_start - new) != new) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
204 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
205 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
206 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
|
207 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
|
208 new_heap->bloc_start = bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
209 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
|
210 new_heap->prev = last_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
211 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
|
212 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
|
213 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
214 address = bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
215 already_available = 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
216 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
217 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
218 /* Get some extra, so we can come here less often. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
219 get = size + extra_bytes - already_available; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
220 get = (char *) ROUNDUP((char *)last_heap->end + get) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
221 - (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
|
222 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
223 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
|
224 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
225 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
226 last_heap->end += get; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
227 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
228 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
229 return address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
230 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
231 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
232 /* If the last heap has a excessive space, return it to the system. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
233 static void |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
234 relinquish () |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
235 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
236 register heap_ptr h; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
237 int excess = 0; |
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 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
|
240 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
241 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
|
242 ? 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
|
243 } |
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 (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
|
246 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
247 /* 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
|
248 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
|
249 excess -= extra_bytes; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
250 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
251 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
|
252 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
253 /* Return the last heap with its header to the system */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
258 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
259 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
260 excess = (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
|
261 - (char *) ROUNDUP((char *)last_heap->end - excess); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
262 last_heap->end -= excess; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
263 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
264 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
265 if ((*real_morecore) (- excess) == 0) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
266 abort (); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
267 } |
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 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
270 /* 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
|
271 |
577 | 272 /* Find the bloc referenced by the address in PTR. Returns a pointer |
118 | 273 to that block. */ |
274 | |
275 static bloc_ptr | |
276 find_bloc (ptr) | |
277 POINTER *ptr; | |
278 { | |
279 register bloc_ptr p = first_bloc; | |
280 | |
281 while (p != NIL_BLOC) | |
282 { | |
283 if (p->variable == ptr && p->data == *ptr) | |
284 return p; | |
285 | |
286 p = p->next; | |
287 } | |
288 | |
289 return p; | |
290 } | |
291 | |
292 /* 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
|
293 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
|
294 memory for the new block. */ |
118 | 295 |
296 static bloc_ptr | |
297 get_bloc (size) | |
298 SIZE size; | |
299 { | |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
300 register bloc_ptr new_bloc; |
118 | 301 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
302 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
|
303 || ! (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
|
304 { |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
305 if (new_bloc) |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
306 free (new_bloc); |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
307 |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
308 return 0; |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
309 } |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
310 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
311 break_value = new_bloc->data + size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
312 |
118 | 313 new_bloc->size = size; |
314 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
|
315 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
|
316 new_bloc->new_data = 0; |
118 | 317 |
318 if (first_bloc) | |
319 { | |
320 new_bloc->prev = last_bloc; | |
321 last_bloc->next = new_bloc; | |
322 last_bloc = new_bloc; | |
323 } | |
324 else | |
325 { | |
326 first_bloc = last_bloc = new_bloc; | |
327 new_bloc->prev = NIL_BLOC; | |
328 } | |
329 | |
330 return new_bloc; | |
331 } | |
332 | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
333 /* Calculate new locations of blocs in the list begining with BLOC, |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
334 whose spaces is started at ADDRESS in HEAP. If enough space is |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
335 not presently available in our reserve, obtain() is called for |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
336 more space. |
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 Do not touch the contents of blocs or break_value. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
339 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
340 static int |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
341 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
|
342 bloc_ptr bloc; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
343 heap_ptr heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
344 POINTER address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
345 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
346 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
|
347 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
348 while (b) |
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 while (heap && address + b->size > heap->end) |
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 heap = heap->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
353 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
|
354 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
355 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
|
356 } |
118 | 357 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
358 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
|
359 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
360 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
|
361 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
|
362 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
363 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
|
364 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
365 s += tb->size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
366 tb = tb->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
367 } |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
368 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
369 if (! (address = obtain(address, s))) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
370 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
371 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
372 heap = last_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
373 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
374 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
375 b->new_data = address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
376 address += b->size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
377 b = b->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
378 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
379 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
380 return 1; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
381 } |
118 | 382 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
383 /* Resize BLOC to SIZE bytes. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
384 static int |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
385 resize_bloc (bloc, size) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
386 bloc_ptr bloc; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
387 SIZE size; |
118 | 388 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
389 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
|
390 heap_ptr heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
391 POINTER address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
392 SIZE old_size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
393 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
394 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
|
395 return 1; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
396 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
397 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
|
398 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
399 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
|
400 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
401 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
402 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
403 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
|
404 abort(); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
405 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
406 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
|
407 bloc->size = size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
408 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
409 /* Note that bloc could be moved into the previous heap. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
410 address = bloc->prev ? bloc->prev->data + bloc->prev->size |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
411 : 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
|
412 while (heap) |
118 | 413 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
414 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
|
415 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
416 heap = heap->prev; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
417 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
418 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
419 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
|
420 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
421 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
|
422 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
423 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
424 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
425 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
|
426 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
427 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
|
428 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
429 safe_bcopy (b->data, b->new_data, b->size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
430 *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
|
431 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
432 safe_bcopy (bloc->data, bloc->new_data, old_size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
433 bzero (bloc->new_data + old_size, size - old_size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
434 *bloc->variable = bloc->data = bloc->new_data; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
435 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
436 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
437 { |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
438 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
|
439 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
440 safe_bcopy (b->data, b->new_data, b->size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
441 *b->variable = b->data = b->new_data; |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
442 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
443 } |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
444 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
445 break_value = last_bloc ? last_bloc->data + last_bloc->size |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
446 : 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
|
447 return 1; |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
448 } |
118 | 449 |
450 /* Free BLOC from the chain of blocs, relocating any blocs above it | |
451 and returning BLOC->size bytes to the free area. */ | |
452 | |
453 static void | |
454 free_bloc (bloc) | |
455 bloc_ptr bloc; | |
456 { | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
457 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
|
458 |
118 | 459 if (bloc == first_bloc && bloc == last_bloc) |
460 { | |
461 first_bloc = last_bloc = NIL_BLOC; | |
462 } | |
463 else if (bloc == last_bloc) | |
464 { | |
465 last_bloc = bloc->prev; | |
466 last_bloc->next = NIL_BLOC; | |
467 } | |
468 else if (bloc == first_bloc) | |
469 { | |
470 first_bloc = bloc->next; | |
471 first_bloc->prev = NIL_BLOC; | |
472 } | |
473 else | |
474 { | |
475 bloc->next->prev = bloc->prev; | |
476 bloc->prev->next = bloc->next; | |
477 } | |
478 | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
479 relinquish (); |
118 | 480 free (bloc); |
481 } | |
482 | |
577 | 483 /* Interface routines. */ |
484 | |
118 | 485 static int use_relocatable_buffers; |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
486 static int r_alloc_freeze_level; |
118 | 487 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
488 /* 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
|
489 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
|
490 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
|
491 hook. |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
492 |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
493 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
|
494 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
495 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
|
496 __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
|
497 GNU malloc package. */ |
118 | 498 |
499 POINTER | |
500 r_alloc_sbrk (size) | |
501 long size; | |
502 { | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
503 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
|
504 POINTER address; |
118 | 505 |
506 if (! use_relocatable_buffers) | |
1401 | 507 return (*real_morecore) (size); |
118 | 508 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
509 if (size == 0) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
510 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
|
511 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
512 if (size > 0) |
118 | 513 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
514 /* Allocate a page-aligned space. GNU malloc would reclaim an |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
515 extra space if we passed an unaligned one. But we could |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
516 not always find a space which is contiguos to the previous. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
517 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
|
518 heap_ptr h = first_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
519 SIZE get = ROUNDUP(size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
520 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
521 address = (POINTER) ROUNDUP(virtual_break_value); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
522 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
523 /* Search the list upward for a heap which is large enough. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
524 while ((char *) h->end < (char *) MEM_ROUNDUP((char *)address + get)) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
525 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
526 h = h->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
527 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
|
528 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
529 address = (POINTER) ROUNDUP(h->start); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
530 } |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
531 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
532 /* If not found, obatin more space. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
533 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
|
534 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
535 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
|
536 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
537 if (r_alloc_freeze_level > 0 || ! obtain(address, get)) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
538 return 0; |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
539 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
540 if (first_heap == last_heap) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
541 address = (POINTER) ROUNDUP(virtual_break_value); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
542 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
543 address = (POINTER) ROUNDUP(last_heap->start); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
544 h = last_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
545 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
546 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
547 new_bloc_start = (POINTER) MEM_ROUNDUP((char *)address + get); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
548 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
549 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
|
550 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
551 /* Move all blocs upward. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
552 if (r_alloc_freeze_level > 0 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
553 || ! relocate_blocs (first_bloc, h, new_bloc_start)) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
554 return 0; |
577 | 555 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
556 /* 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
|
557 get >= page_size, so the following does not destroy the heap |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
558 header. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
559 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
|
560 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
561 safe_bcopy (b->data, b->new_data, b->size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
562 *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
|
563 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
564 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
565 h->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
|
566 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
567 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
568 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
|
569 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
570 /* Give up managing heaps below the one the new |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
571 virtual_break_value points to. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
572 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
|
573 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
|
574 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
|
575 first_heap->end = h->end; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
576 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
|
577 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
578 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
|
579 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
|
580 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
581 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
|
582 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
583 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
584 bzero (address, size); |
118 | 585 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
586 else /* size < 0 */ |
118 | 587 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
588 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
|
589 - ((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
|
590 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
591 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
|
592 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
593 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
|
594 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
595 excess -= extra_bytes; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
596 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
|
597 = (POINTER) MEM_ROUNDUP((char *)first_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
|
598 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
599 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
|
600 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
601 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
|
602 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
603 safe_bcopy (b->data, b->new_data, b->size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
604 *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
|
605 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
606 } |
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 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
|
609 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
610 /* 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
|
611 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
|
612 } |
118 | 613 } |
614 | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
615 virtual_break_value = (POINTER) ((char *)address + size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
616 break_value = last_bloc ? last_bloc->data + last_bloc->size |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
617 : 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
|
618 if (size < 0) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
619 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
|
620 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
621 return address; |
118 | 622 } |
623 | |
624 /* Allocate a relocatable bloc of storage of size SIZE. A pointer to | |
625 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
|
626 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
|
627 |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
628 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
|
629 return zero. */ |
118 | 630 |
631 POINTER | |
632 r_alloc (ptr, size) | |
633 POINTER *ptr; | |
634 SIZE size; | |
635 { | |
636 register bloc_ptr new_bloc; | |
637 | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
638 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
|
639 r_alloc_init (); |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
640 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
641 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
|
642 if (new_bloc) |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
643 { |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
644 new_bloc->variable = ptr; |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
645 *ptr = new_bloc->data; |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
646 } |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
647 else |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
648 *ptr = 0; |
118 | 649 |
650 return *ptr; | |
651 } | |
652 | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
653 /* 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
|
654 Store 0 in *PTR to show there's no block allocated. */ |
118 | 655 |
656 void | |
657 r_alloc_free (ptr) | |
658 register POINTER *ptr; | |
659 { | |
660 register bloc_ptr dead_bloc; | |
661 | |
662 dead_bloc = find_bloc (ptr); | |
663 if (dead_bloc == NIL_BLOC) | |
664 abort (); | |
665 | |
666 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
|
667 *ptr = 0; |
118 | 668 } |
669 | |
1087
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
670 /* 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
|
671 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
|
672 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
|
673 do nothing. |
118 | 674 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
675 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
|
676 |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
677 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
|
678 return zero. */ |
118 | 679 |
680 POINTER | |
681 r_re_alloc (ptr, size) | |
682 POINTER *ptr; | |
683 SIZE size; | |
684 { | |
1087
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
685 register bloc_ptr bloc; |
118 | 686 |
1087
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
687 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
|
688 if (bloc == NIL_BLOC) |
118 | 689 abort (); |
690 | |
1087
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
691 if (size <= bloc->size) |
577 | 692 /* Wouldn't it be useful to actually resize the bloc here? */ |
118 | 693 return *ptr; |
694 | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
695 if (! resize_bloc (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
|
696 return 0; |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
697 |
118 | 698 return *ptr; |
699 } | |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
700 |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
701 /* 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
|
702 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
|
703 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
|
704 malloc must return a null pointer. */ |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
705 void |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
706 r_alloc_freeze (size) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
707 long size; |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
708 { |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
709 /* 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
|
710 if (r_alloc_freeze_level > 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
711 size = 0; |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
712 /* 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
|
713 while (size > 0 && r_alloc_sbrk (size) == 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
714 size /= 2; |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
715 ++r_alloc_freeze_level; |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
716 if (size > 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
717 r_alloc_sbrk (-size); |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
718 } |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
719 |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
720 void |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
721 r_alloc_thaw () |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
722 { |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
723 if (--r_alloc_freeze_level < 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
724 abort (); |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
725 } |
118 | 726 |
727 /* The hook `malloc' uses for the function which gets more space | |
728 from the system. */ | |
729 extern POINTER (*__morecore) (); | |
730 | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3136
diff
changeset
|
731 /* Initialize various things for memory allocation. */ |
118 | 732 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
733 static void |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
734 r_alloc_init () |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
735 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
736 static struct heap heap_base; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
737 POINTER end; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
738 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
739 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
|
740 return; |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
741 |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
742 r_alloc_initialized = 1; |
1401 | 743 real_morecore = __morecore; |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
744 __morecore = r_alloc_sbrk; |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
745 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
746 first_heap = last_heap = &heap_base; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
747 first_heap->next = 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
|
748 first_heap->start = 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
|
749 = virtual_break_value = break_value = (*real_morecore) (0); |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
750 if (break_value == NIL) |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
751 abort (); |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
752 |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
753 page_size = PAGE; |
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
754 extra_bytes = ROUNDUP (50000); |
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
755 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
756 first_heap->end = (POINTER) ROUNDUP (first_heap->start); |
5063
9ab921a16318
(r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
757 |
9ab921a16318
(r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
758 /* The extra call to real_morecore guarantees that the end of the |
9ab921a16318
(r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
759 address space is a multiple of page_size, even if page_size is |
9ab921a16318
(r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
760 not really the page size of the system running the binary in |
9ab921a16318
(r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
761 which page_size is stored. This allows a binary to be built on a |
9ab921a16318
(r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
762 system with one page size and run on a system with a smaller page |
9ab921a16318
(r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
763 size. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
764 (*real_morecore) (first_heap->end - first_heap->start); |
5063
9ab921a16318
(r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
765 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
766 /* Clear the rest of the last page; this memory is in our address space |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
767 even though it is after the sbrk value. */ |
5063
9ab921a16318
(r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
768 /* Doubly true, with the additional call that explicitly adds the |
9ab921a16318
(r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
769 rest of that page to the address space. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
770 bzero (first_heap->start, first_heap->end - first_heap->start); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
771 virtual_break_value = break_value = first_heap->bloc_start = first_heap->end; |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
772 use_relocatable_buffers = 1; |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
773 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
774 #ifdef DEBUG |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
775 #include <assert.h> |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
776 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
777 int |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
778 r_alloc_check () |
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 int found = 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
781 heap_ptr h, ph = 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
782 bloc_ptr b, pb = 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
783 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
784 if (!r_alloc_initialized) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
785 return; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
786 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
787 assert(first_heap); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
788 assert(last_heap->end <= (POINTER) sbrk(0)); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
789 assert((POINTER) first_heap < first_heap->start); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
790 assert(first_heap->start <= virtual_break_value); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
791 assert(virtual_break_value <= first_heap->end); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
792 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
793 for (h = first_heap; h; h = h->next) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
794 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
795 assert(h->prev == ph); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
796 assert((POINTER) ROUNDUP(h->end) == h->end); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
797 assert((POINTER) MEM_ROUNDUP(h->start) == h->start); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
798 assert((POINTER) MEM_ROUNDUP(h->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
|
799 assert(h->start <= h->bloc_start && h->bloc_start <= h->end); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
800 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
801 if (ph) |
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 assert (ph->end < h->start); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
804 assert (h->start <= (POINTER)h && (POINTER)(h+1) <= h->bloc_start); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
805 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
806 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
807 if (h->bloc_start <= break_value && break_value <= h->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
808 found = 1; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
809 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
810 ph = h; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
811 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
812 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
813 assert(found); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
814 assert(last_heap == ph); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
815 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
816 for (b = first_bloc; b; b = b->next) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
817 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
818 assert(b->prev == pb); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
819 assert((POINTER) MEM_ROUNDUP(b->data) == b->data); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
820 assert((SIZE) MEM_ROUNDUP(b->size) == b->size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
821 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
822 ph = 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
823 for (h = first_heap; h; h = h->next) |
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 if (h->bloc_start <= b->data && b->data + b->size <= h->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
826 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
827 ph = h; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
828 } |
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 assert(h); |
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 if (pb && pb->data + pb->size != b->data) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
833 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
834 assert(ph && b->data == h->bloc_start); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
835 while (ph) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
836 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
837 if (ph->bloc_start <= pb->data |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
838 && pb->data + pb->size <= ph->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
839 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
840 assert(pb->data + pb->size + b->size > ph->end); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
841 break; |
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 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
844 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
845 assert(ph->bloc_start + b->size > ph->end); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
846 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
847 ph = ph->prev; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
848 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
849 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
850 pb = b; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
851 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
852 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
853 assert(last_bloc == pb); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
854 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
855 if (last_bloc) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
856 assert(last_bloc->data + last_bloc->size == break_value); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
857 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
858 assert(first_heap->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
|
859 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
860 #endif /* DEBUG */ |