annotate src/ralloc.c @ 10705:3d356714b662

Initial revision
author Richard M. Stallman <rms@gnu.org>
date Thu, 09 Feb 1995 00:01:34 +0000
parents 5659c0885145
children c6a68e4ee53a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 /* NOTES:
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3136
diff changeset
22 Only relocate the blocs necessary for SIZE in r_alloc_sbrk,
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 rather than all of them. This means allowing for a possible
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
24 hole between the first bloc and the end of malloc storage. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
26 #ifdef emacs
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
27
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 4230
diff changeset
28 #include <config.h>
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
29 #include "lisp.h" /* Needed for VALBITS. */
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
30
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
31 #undef NULL
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
32
1451
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
33 /* The important properties of this type are that 1) it's a pointer, and
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
34 2) arithmetic on it should work as if the size of the object pointed
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
35 to has a size of 1. */
3109
cd1bbe721cb5 (POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
36 #if 0 /* Arithmetic on void* is a GCC extension. */
1451
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
37 #ifdef __STDC__
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
38 typedef void *POINTER;
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
39 #else
1729
5c3898c5aa2d [! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents: 1595
diff changeset
40
5c3898c5aa2d [! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents: 1595
diff changeset
41 #ifdef HAVE_CONFIG_H
5c3898c5aa2d [! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents: 1595
diff changeset
42 #include "config.h"
5c3898c5aa2d [! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents: 1595
diff changeset
43 #endif
5c3898c5aa2d [! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents: 1595
diff changeset
44
1451
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
45 typedef char *POINTER;
1729
5c3898c5aa2d [! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents: 1595
diff changeset
46
1451
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
47 #endif
3109
cd1bbe721cb5 (POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
48 #endif /* 0 */
cd1bbe721cb5 (POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
49
cd1bbe721cb5 (POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
50 /* Unconditionally use char * for this. */
cd1bbe721cb5 (POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
51 typedef char *POINTER;
1451
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
52
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
53 typedef unsigned long SIZE;
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
54
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
55 /* Declared in dispnew.c, this version doesn't screw up if regions
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
56 overlap. */
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
57 extern void safe_bcopy ();
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
58
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
59 #include "getpagesize.h"
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
60
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
61 #else /* Not emacs. */
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
62
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
63 #include <stddef.h>
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
64
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
65 typedef size_t SIZE;
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
66 typedef void *POINTER;
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
67
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
68 #include <unistd.h>
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
69 #include <malloc.h>
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
70 #include <string.h>
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
71
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
72 #define safe_bcopy(x, y, z) memmove (y, x, z)
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
73
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
74 #endif /* emacs. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 #define NIL ((POINTER) 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
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 /* A flag to indicate whether we have initialized ralloc yet. For
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
79 Emacs's sake, please do not make this local to malloc_init; on some
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
80 machines, the dumping procedure makes all static variables
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
81 read-only. On these machines, the word static is #defined to be
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
82 the empty string, meaning that r_alloc_initialized becomes an
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
83 automatic variable, and loses its value each time Emacs is started up. */
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
84 static int r_alloc_initialized = 0;
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
85
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
86 static void r_alloc_init ();
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
88 /* Declarations for working with the malloc, ralloc, and system breaks. */
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
89
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
90 /* Function to set the real break value. */
1401
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
91 static POINTER (*real_morecore) ();
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
93 /* The break value, as seen by malloc. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 static POINTER virtual_break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
96 /* 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
97 including relocatable blocs as well as malloc data. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 static POINTER break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
100 /* 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
101 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
102
1595
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
103 /* 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
104 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
105 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
106
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 /* 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
108 by changing the definition of PAGE. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 #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
110 #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
111 #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
112 & ~(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
113 #define ROUND_TO_PAGE(addr) (addr & (~(page_size - 1)))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
115 #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
116 #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
117 & ~(MEM_ALIGN - 1))
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
118
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
119 /* 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
120
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
121 /* 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
122 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
123 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
124 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
125
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
126 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
127 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
128 but they never move.
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 We try to make just one heap and make it larger as necessary.
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
131 But sometimes we can't do that, because we can't get continguous
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
132 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
133
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
134 typedef struct heap
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 {
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
136 struct heap *next;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
137 struct heap *prev;
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
138 /* 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
139 POINTER start;
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
140 /* 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
141 POINTER end;
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
142 /* 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
143 POINTER bloc_start;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
144 /* 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
145 POINTER free;
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
146 /* First bloc in this heap. */
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
147 struct bp *first_bloc;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
148 /* Last bloc in this heap. */
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
149 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
150 } *heap_ptr;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
152 #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
153 #define HEAP_PTR_SIZE (sizeof (struct heap))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
155 /* 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
156 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
157 the space it covers. */
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
158 static struct heap heap_base;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
159
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
160 /* 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
161 static heap_ptr first_heap, last_heap;
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
162
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
163 /* These structures are allocated in the malloc arena.
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
164 The linked list is kept in order of increasing '.data' members.
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
165 The data blocks abut each other; if b->next is non-nil, then
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
166 b->data + b->size == b->next->data. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 typedef struct bp
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 struct bp *next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 struct bp *prev;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 POINTER *variable;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 POINTER data;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 SIZE size;
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
174 POINTER new_data; /* tmporarily used for relocation */
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
175 /* Heap this bloc is in. */
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
176 struct heap *heap;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 } *bloc_ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 #define NIL_BLOC ((bloc_ptr) 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 #define BLOC_PTR_SIZE (sizeof (struct bp))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
182 /* Head and tail of the list of relocatable blocs. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 static bloc_ptr first_bloc, last_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
185
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
186 /* 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
187
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
188 /* 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
189
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
190 static heap_ptr
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
191 find_heap (address)
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
192 POINTER address;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
193 {
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
194 heap_ptr heap;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
195
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
196 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
197 {
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
198 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
199 return heap;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
200 }
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
201
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
202 return NIL_HEAP;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
203 }
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
204
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
205 /* 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
206 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
207 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
208
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
209 If enough space is not presently available in our reserve, this means
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
210 getting more page-aligned space from the system. If the retuned space
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
211 is not contiguos 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
212
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
213 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
214 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
215 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
216 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
217 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
218 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
219
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
220 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
221 allocate the memory. */
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
222
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
223 static POINTER
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
224 obtain (address, size)
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
225 POINTER address;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
226 SIZE size;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
227 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
228 heap_ptr heap;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
229 SIZE already_available;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
230
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
231 /* 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
232 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
233 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
234 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
235 break;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
236 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
237
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
238 if (! heap)
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
239 abort ();
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
240
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
241 /* 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
242 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
243 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
244 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
245 heap = heap->next;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
246 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
247 break;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
248 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
249 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
250
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
251 /* 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
252 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
253 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
254 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
255 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
256 SIZE get;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
257
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
258 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
259
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
260 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
261 {
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
262 /* 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
263
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
264 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
265 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
266
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
267 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
268 return 0;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
269
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
270 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
271 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
272 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
273 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
274 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
275 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
276 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
277 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
278 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
279 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
280
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
281 address = bloc_start;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
282 already_available = 0;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
283 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
284
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
285 /* 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
286 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
287
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
288 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
289 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
290 - (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
291
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
292 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
293 return 0;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
294
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
295 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
296 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
297
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
298 return address;
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
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
301 /* 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
302 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
303 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
304 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
305
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
306 static void
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
307 relinquish ()
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
308 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
309 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
310 int excess = 0;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
311
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
312 /* 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
313 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
314
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
315 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
316 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
317 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
318 ? 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
319 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
320
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
321 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
322 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
323 /* 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
324 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
325 excess -= extra_bytes;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
326
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
327 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
328 {
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
329 /* 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
330 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
331 || 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
332 abort ();
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
333
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
334 /* 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
335 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
336 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
337 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
338 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
339 else
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
340 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
341 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
342 - (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
343 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
344 }
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 ((*real_morecore) (- excess) == 0)
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
347 abort ();
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
348 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
349 }
10682
5659c0885145 (r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10432
diff changeset
350
5659c0885145 (r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10432
diff changeset
351 /* 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
352 above where malloc gets space. */
5659c0885145 (r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10432
diff changeset
353
5659c0885145 (r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10432
diff changeset
354 long
5659c0885145 (r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10432
diff changeset
355 r_alloc_size_in_use ()
5659c0885145 (r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10432
diff changeset
356 {
5659c0885145 (r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10432
diff changeset
357 return break_value - virtual_break_value;
5659c0885145 (r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10432
diff changeset
358 }
9459
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 /* 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
361
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
362 /* 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
363 to that block. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 static bloc_ptr
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 find_bloc (ptr)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 register bloc_ptr p = first_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 while (p != NIL_BLOC)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 if (p->variable == ptr && p->data == *ptr)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 return p;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 p = p->next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 return p;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 /* 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
383 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
384 memory for the new block. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 static bloc_ptr
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 get_bloc (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 {
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
390 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
391 register heap_ptr heap;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
393 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
394 || ! (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
395 {
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
396 if (new_bloc)
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
397 free (new_bloc);
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
398
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
399 return 0;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
400 }
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
401
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
402 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
403
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 new_bloc->size = size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 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
406 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
407 new_bloc->new_data = 0;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
409 /* 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
410 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
411 heap->free = break_value;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
412
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
413 /* 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
414 new_bloc->heap = heap;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
415 heap->last_bloc = new_bloc;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
416 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
417 heap->first_bloc = new_bloc;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
418
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
419 /* Put this bloc on the doubly-linked list of blocs. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 if (first_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 new_bloc->prev = last_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 last_bloc->next = new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 last_bloc = new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 first_bloc = last_bloc = new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 new_bloc->prev = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 return new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 }
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
434
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
435 /* 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
436 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
437 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
438 more space.
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
439
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
440 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
441 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
442
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
443 static int
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
444 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
445 bloc_ptr bloc;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
446 heap_ptr heap;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
447 POINTER address;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
448 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
449 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
450
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
451 while (b)
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
452 {
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
453 /* 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
454 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
455 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
456 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
457 heap = heap->next;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
458 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
459 break;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
460 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
461 }
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
463 /* 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
464 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
465 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
466 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
467 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
468 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
469
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
470 /* 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
471 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
472 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
473 s += tb->size;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
474 tb = tb->next;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
475 }
1595
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
476
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
477 /* Get that space. */
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
478 address = obtain (address, s);
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
479 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
480 return 0;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
481
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
482 heap = last_heap;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
483 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
484
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
485 /* 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
486 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
487 b->new_data = address;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
488 address += b->size;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
489 b = b->next;
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
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
492 return 1;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
493 }
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
495 /* 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
496 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
497 before that of BEFORE. */
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
498
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
499 static void
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
500 reorder_bloc (bloc, before)
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
501 bloc_ptr bloc, before;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
502 {
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
503 bloc_ptr prev, next;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
504
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
505 /* 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
506 prev = bloc->prev;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
507 next = bloc->next;
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
508
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
509 if (prev)
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
510 prev->next = next;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
511 if (next)
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
512 next->prev = prev;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
513
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
514 /* Splice it in before BEFORE. */
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
515 prev = before->prev;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
516
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
517 if (prev)
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
518 prev->next = bloc;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
519 bloc->prev = prev;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
520
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
521 before->prev = bloc;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
522 bloc->next = before;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
523 }
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
524
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
525 /* 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
526 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
527
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
528 static void
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
529 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
530 bloc_ptr bloc;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
531 heap_ptr heap;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
532 {
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
533 register bloc_ptr b;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
534
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
535 /* 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
536 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
537 {
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
538 /* 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
539 heap->last_bloc = bloc->prev;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
540 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
541 }
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
542 else
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
543 {
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
544 /* 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
545 heap->first_bloc = NIL_BLOC;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
546 heap->last_bloc = NIL_BLOC;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
547 heap->free = heap->bloc_start;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
548 }
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
549
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
550 /* 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
551 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
552 {
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
553 /* 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
554 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
555 while (heap)
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
556 {
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
557 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
558 break;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
559 heap = heap->next;
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
560 /* 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
561 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
562 heap->first_bloc = NIL_BLOC;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
563 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
564 heap->free = heap->bloc_start;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
565 }
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
566
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
567 /* 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
568 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
569 heap->last_bloc = b;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
570 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
571 heap->first_bloc = b;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
572
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
573 /* 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
574 b->heap = heap;
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
575 }
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
576
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
577 /* 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
578 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
579 heap = heap->next;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
580 while (heap)
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
581 {
9666
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;
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
584 heap->free = heap->bloc_start;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
585 heap = heap->next;
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
586 }
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
587 }
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
588
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
589 /* 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
590 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
591
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
592 static int
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
593 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
594 bloc_ptr bloc;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
595 SIZE size;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
596 {
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
597 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
598 heap_ptr heap;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
599 POINTER address;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
600 SIZE old_size;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
601
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
602 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
603 return 1;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
604
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
605 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
606 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
607 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
608 break;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
609 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
610
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
611 if (heap == NIL_HEAP)
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
612 abort ();
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
613
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
614 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
615 bloc->size = size;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
616
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
617 /* 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
618 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
619 : 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
620 while (heap)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
621 {
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
622 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
623 break;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
624 heap = heap->prev;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
625 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
626
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
627 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
628 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
629 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
630 return 0;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
631 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
632
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
633 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
634 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
635 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
636 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
637 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
638 *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
639 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
640 safe_bcopy (bloc->data, bloc->new_data, old_size);
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
641 bzero (bloc->new_data + old_size, size - old_size);
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
642 *bloc->variable = bloc->data = bloc->new_data;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
643 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
644 else
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
645 {
1595
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
646 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
647 {
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
648 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
649 *b->variable = b->data = b->new_data;
1595
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
650 }
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
651 }
1595
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
652
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
653 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
654
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
655 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
656 : 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
657 return 1;
1595
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
658 }
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
659
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
660 /* 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
661 This may return space to the system. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
662
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
663 static void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
664 free_bloc (bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
665 bloc_ptr bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
666 {
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
667 heap_ptr heap = bloc->heap;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
668
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
669 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
670
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
671 if (bloc == first_bloc && bloc == last_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
672 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
673 first_bloc = last_bloc = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
674 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
675 else if (bloc == last_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
676 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
677 last_bloc = bloc->prev;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
678 last_bloc->next = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
679 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
680 else if (bloc == first_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
681 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
682 first_bloc = bloc->next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
683 first_bloc->prev = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
684 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
685 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
686 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
687 bloc->next->prev = bloc->prev;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
688 bloc->prev->next = bloc->next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
689 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
690
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
691 /* 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
692 if (heap->first_bloc == bloc)
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
693 {
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
694 if (bloc->next->heap == heap)
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
695 heap->first_bloc = bloc->next;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
696 else
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
697 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
698 }
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
699 if (heap->last_bloc == bloc)
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
700 {
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
701 if (bloc->prev->heap == heap)
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
702 heap->last_bloc = bloc->prev;
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
703 else
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
704 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
705 }
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
706
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
707 relinquish ();
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
708 free (bloc);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
709 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
710
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
711 /* Interface routines. */
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
712
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
713 static int use_relocatable_buffers;
8951
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
714 static int r_alloc_freeze_level;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
715
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
716 /* 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
717 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
718 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
719 hook.
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
720
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
721 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
722
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
723 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
724 __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
725 GNU malloc package. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
726
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
727 POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
728 r_alloc_sbrk (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
729 long size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
730 {
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
731 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
732 POINTER address;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
733
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
734 if (! use_relocatable_buffers)
1401
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
735 return (*real_morecore) (size);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
736
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
737 if (size == 0)
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
738 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
739
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
740 if (size > 0)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
741 {
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
742 /* 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
743 extra space if we passed an unaligned one. But we could
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
744 not always find a space which is contiguos 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
745 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
746 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
747 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
748
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
749 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
750
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
751 /* 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
752 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
753 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
754 h = h->next;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
755 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
756 break;
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
757 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
758 }
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
759
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
760 /* 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
761 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
762 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
763 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
764
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
765 if (r_alloc_freeze_level > 0 || ! 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
766 return 0;
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
767
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
768 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
769 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
770 else
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
771 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
772 h = last_heap;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
773 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
774
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
775 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
776
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
777 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
778 {
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
779 /* Move all blocs upward. */
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
780 if (r_alloc_freeze_level > 0
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
781 || ! relocate_blocs (first_bloc, h, new_bloc_start))
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
782 return 0;
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
783
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
784 /* 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
785 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
786 header. */
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
787 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
788 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
789 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
790 *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
791 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
792
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
793 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
794
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
795 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
796 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
797
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
798 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
799 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
800 /* 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
801 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
802 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
803 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
804 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
805 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
806 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
807 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
808 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
809 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
810
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
811 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
812 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
813 else
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
814 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
815 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
816
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
817 bzero (address, size);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
818 }
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
819 else /* size < 0 */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
820 {
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
821 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
822 - ((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
823
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
824 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
825
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
826 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
827 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
828 excess -= extra_bytes;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
829 first_heap->bloc_start
9666
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
830 = (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
831
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
832 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
833
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
834 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
835 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
836 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
837 *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
838 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
839 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
840
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
841 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
842 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
843 /* 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
844 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
845 }
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
846 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
847
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
848 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
849 break_value = (last_bloc
d50850d0c8f8 (struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents: 9596
diff changeset
850 ? 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
851 : 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
852 if (size < 0)
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
853 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
854
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
855 return address;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
856 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
857
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
858 /* Allocate a relocatable bloc of storage of size SIZE. A pointer to
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
859 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
860 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
861
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
862 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
863 return zero. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
864
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
865 POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
866 r_alloc (ptr, size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
867 POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
868 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
869 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
870 register bloc_ptr new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
871
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
872 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
873 r_alloc_init ();
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
874
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
875 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
876 if (new_bloc)
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
877 {
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
878 new_bloc->variable = ptr;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
879 *ptr = new_bloc->data;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
880 }
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
881 else
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
882 *ptr = 0;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
883
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
884 return *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
885 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
886
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
887 /* 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
888 Store 0 in *PTR to show there's no block allocated. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
889
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
890 void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
891 r_alloc_free (ptr)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
892 register POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
893 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
894 register bloc_ptr dead_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
895
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
896 dead_bloc = find_bloc (ptr);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
897 if (dead_bloc == NIL_BLOC)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
898 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
899
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
900 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
901 *ptr = 0;
10682
5659c0885145 (r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10432
diff changeset
902
5659c0885145 (r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10432
diff changeset
903 refill_memory_reserve ();
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
904 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
905
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
906 /* 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
907 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
908 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
909 do nothing.
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
910
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
911 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
912
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
913 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
914 return zero. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
915
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
916 POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
917 r_re_alloc (ptr, size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
918 POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
919 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
920 {
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
921 register bloc_ptr bloc;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
922
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
923 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
924 if (bloc == NIL_BLOC)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
925 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
926
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
927 if (size <= bloc->size)
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
928 /* Wouldn't it be useful to actually resize the bloc here? */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
929 return *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
930
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
931 if (! resize_bloc (bloc, MEM_ROUNDUP (size)))
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
932 return 0;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
933
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
934 return *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
935 }
8951
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
936
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
937 /* 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
938 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
939 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
940 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
941
8951
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
942 void
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
943 r_alloc_freeze (size)
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
944 long size;
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
945 {
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
946 /* 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
947 if (r_alloc_freeze_level > 0)
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
948 size = 0;
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
949 /* 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
950 while (size > 0 && r_alloc_sbrk (size) == 0)
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
951 size /= 2;
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
952 ++r_alloc_freeze_level;
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
953 if (size > 0)
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
954 r_alloc_sbrk (-size);
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
955 }
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
956
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
957 void
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
958 r_alloc_thaw ()
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
959 {
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
960 if (--r_alloc_freeze_level < 0)
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
961 abort ();
b628561b185b (r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 5063
diff changeset
962 }
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
963
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
964 /* The hook `malloc' uses for the function which gets more space
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
965 from the system. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
966 extern POINTER (*__morecore) ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
967
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
968 /* Initialize various things for memory allocation. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
969
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
970 static void
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
971 r_alloc_init ()
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
972 {
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
973 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
974 return;
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
975
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
976 r_alloc_initialized = 1;
1401
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
977 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
978 __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
979
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
980 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
981 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
982 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
983 = virtual_break_value = break_value = (*real_morecore) (0);
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
984 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
985 abort ();
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
986
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
987 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
988 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
989
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
990 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
991
9ab921a16318 (r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
992 /* 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
993 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
994 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
995 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
996 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
997 size. */
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
998 (*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
999
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
1000 /* 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
1001 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
1002 /* 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
1003 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
1004 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
1005 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
1006 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
1007 }
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1008 #ifdef DEBUG
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1009 #include <assert.h>
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1010
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1011 int
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1012 r_alloc_check ()
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1013 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1014 int found = 0;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1015 heap_ptr h, ph = 0;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1016 bloc_ptr b, pb = 0;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1017
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1018 if (!r_alloc_initialized)
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1019 return;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1020
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1021 assert (first_heap);
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1022 assert (last_heap->end <= (POINTER) sbrk (0));
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1023 assert ((POINTER) first_heap < first_heap->start);
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1024 assert (first_heap->start <= virtual_break_value);
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1025 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
1026
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1027 for (h = first_heap; h; h = h->next)
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1028 {
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1029 assert (h->prev == ph);
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1030 assert ((POINTER) ROUNDUP (h->end) == h->end);
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1031 assert ((POINTER) MEM_ROUNDUP (h->start) == h->start);
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1032 assert ((POINTER) MEM_ROUNDUP (h->bloc_start) == h->bloc_start);
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1033 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
1034
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1035 if (ph)
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1036 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1037 assert (ph->end < h->start);
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1038 assert (h->start <= (POINTER)h && (POINTER)(h+1) <= h->bloc_start);
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1039 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1040
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1041 if (h->bloc_start <= break_value && break_value <= h->end)
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1042 found = 1;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1043
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1044 ph = h;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1045 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1046
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1047 assert (found);
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1048 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
1049
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1050 for (b = first_bloc; b; b = b->next)
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1051 {
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1052 assert (b->prev == pb);
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1053 assert ((POINTER) MEM_ROUNDUP (b->data) == b->data);
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1054 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
1055
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1056 ph = 0;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1057 for (h = first_heap; h; h = h->next)
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1058 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1059 if (h->bloc_start <= b->data && b->data + b->size <= h->end)
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1060 break;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1061 ph = h;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1062 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1063
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1064 assert (h);
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1065
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1066 if (pb && pb->data + pb->size != b->data)
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1067 {
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1068 assert (ph && b->data == h->bloc_start);
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1069 while (ph)
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1070 {
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1071 if (ph->bloc_start <= pb->data
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1072 && pb->data + pb->size <= ph->end)
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1073 {
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1074 assert (pb->data + pb->size + b->size > ph->end);
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1075 break;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1076 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1077 else
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1078 {
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1079 assert (ph->bloc_start + b->size > ph->end);
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1080 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1081 ph = ph->prev;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1082 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1083 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1084 pb = b;
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1085 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1086
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1087 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
1088
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1089 if (last_bloc)
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1090 assert (last_bloc->data + last_bloc->size == break_value);
9459
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1091 else
9596
134f7085c56b (heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents: 9459
diff changeset
1092 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
1093 }
a1569f00a6a6 Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents: 8951
diff changeset
1094 #endif /* DEBUG */