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