comparison src/sheap.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 57709be46d1b
children de805c49cfc1
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
19 02111-1307, USA.*/ 19 02111-1307, USA.*/
20 20
21 #include <config.h> 21 #include <config.h>
22 #include <stdio.h> 22 #include <stdio.h>
23 #include "lisp.h" 23 #include "lisp.h"
24 #include <stddef.h>
25 #include <unistd.h> 24 #include <unistd.h>
26 #include <sheap-adjust.h> 25 #include <sheap-adjust.h>
27 26
28 #define STATIC_HEAP_BASE 0x600000 27 #define STATIC_HEAP_BASE 0x800000
29 #define STATIC_HEAP_SLOP 0x40000 28 #define STATIC_HEAP_SLOP 0x40000
30 #define STATIC_HEAP_SIZE \ 29 #define STATIC_HEAP_SIZE \
31 (STATIC_HEAP_BASE + SHEAP_ADJUSTMENT + STATIC_HEAP_SLOP) 30 (STATIC_HEAP_BASE + SHEAP_ADJUSTMENT + STATIC_HEAP_SLOP)
32 #define BLOCKSIZE (1<<12) 31 #define BLOCKSIZE (1<<12)
33 #define ALLOC_UNIT (BLOCKSIZE-1) 32 #define ALLOC_UNIT (BLOCKSIZE-1)
83 printf( 82 printf(
84 83
85 "\nRequested %d bytes, static heap exhausted! base is %p, current ptr 84 "\nRequested %d bytes, static heap exhausted! base is %p, current ptr
86 is %p. You have exhausted the static heap. 85 is %p. You have exhausted the static heap.
87 86
88 If you are simply trying to compile, remove sheap-adjust.h and 87 If you are simply trying to compile, remove sheap-adjust.h
89 puresize-adjust.h and recompile from the top level. If this doesn't 88 and recompile from the top level. If this doesn't
90 work then STATIC_HEAP_SLOP (defined in this file) is too small. 89 work then STATIC_HEAP_SLOP (defined in this file) is too small.
91 90
92 If you want to run temacs, change SHEAP_ADJUSTMENT in sheap-adjust.h 91 If you want to run temacs, change SHEAP_ADJUSTMENT in sheap-adjust.h
93 to 0 or a +ve number. Generally you should *not* try to run temacs 92 to 0 or a +ve number. Generally you should *not* try to run temacs
94 with a static heap, you should dump first.\n", size, 93 with a static heap, you should dump first.\n", size,
101 static_heap_ptr += size; 100 static_heap_ptr += size;
102 101
103 return result; 102 return result;
104 } 103 }
105 104
106 void 105 static void
107 sheap_adjust_h () 106 sheap_adjust_h ()
108 { 107 {
109 FILE *stream = fopen ("sheap-adjust.h", "w"); 108 FILE *stream = fopen ("sheap-adjust.h", "w");
110 109
111 if (stream == NULL) 110 if (stream == NULL)
118 "# define SHEAP_ADJUSTMENT (%d)\n", 117 "# define SHEAP_ADJUSTMENT (%d)\n",
119 ((static_heap_ptr - static_heap_buffer) - STATIC_HEAP_BASE)); 118 ((static_heap_ptr - static_heap_buffer) - STATIC_HEAP_BASE));
120 fclose (stream); 119 fclose (stream);
121 } 120 }
122 121
122 void
123 report_sheap_usage (int die_if_pure_storage_exceeded)
124 {
125 int rc = 0;
126
127 size_t lost = (STATIC_HEAP_BASE + STATIC_HEAP_SLOP + SHEAP_ADJUSTMENT)
128 - (static_heap_ptr - static_heap_buffer);
129 char buf[200];
130 sprintf (buf, "Static heap usage: %ld of %ld",
131 (long) (static_heap_ptr - static_heap_buffer),
132 (long) (STATIC_HEAP_BASE + STATIC_HEAP_SLOP + SHEAP_ADJUSTMENT));
133
134 if (lost > STATIC_HEAP_SLOP) {
135 sprintf (buf + strlen (buf), " -- %ldk wasted", (long)(lost/1024));
136 if (die_if_pure_storage_exceeded) {
137 sheap_adjust_h();
138 rc = -1;
139 }
140 message ("%s", buf);
141 }
142
143 if (rc < 0) {
144 unlink("SATISFIED");
145 fatal ("Static heap size adjusted, Don't Panic! I will restart the `make'");
146 }
147 }
148
149