comparison src/sheap.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children da8ed4261e83
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
17 along with XEmacs; see the file COPYING. If not, write to the Free 17 along with XEmacs; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.*/ 19 02111-1307, USA.*/
20 20
21 #include <config.h> 21 #include <config.h>
22 #include <stdio.h>
22 #include "lisp.h" 23 #include "lisp.h"
23 24 #include <stddef.h>
24 #include <unistd.h> 25 #include <unistd.h>
25 #include <sheap-adjust.h> 26 #include <sheap-adjust.h>
26 27
27 #define STATIC_HEAP_BASE 0x800000 28 #define STATIC_HEAP_BASE 0x600000
28 #define STATIC_HEAP_SLOP 0x40000 29 #define STATIC_HEAP_SLOP 0x40000
29 #define STATIC_HEAP_SIZE \ 30 #define STATIC_HEAP_SIZE \
30 (STATIC_HEAP_BASE + SHEAP_ADJUSTMENT + STATIC_HEAP_SLOP) 31 (STATIC_HEAP_BASE + SHEAP_ADJUSTMENT + STATIC_HEAP_SLOP)
31 #define BLOCKSIZE (1<<12) 32 #define BLOCKSIZE (1<<12)
32 #define ALLOC_UNIT (BLOCKSIZE-1) 33 #define ALLOC_UNIT (BLOCKSIZE-1)
38 char* static_heap_ptr=static_heap_buffer; 39 char* static_heap_ptr=static_heap_buffer;
39 unsigned long static_heap_size=STATIC_HEAP_SIZE; 40 unsigned long static_heap_size=STATIC_HEAP_SIZE;
40 int static_heap_initialized=0; 41 int static_heap_initialized=0;
41 int static_heap_dumped=0; 42 int static_heap_dumped=0;
42 43
43 void* more_static_core ( ptrdiff_t increment );
44 void* more_static_core ( ptrdiff_t increment ) 44 void* more_static_core ( ptrdiff_t increment )
45 { 45 {
46 int size = (int) increment; 46 int size = (int) increment;
47 void *result; 47 void *result;
48 48
57 #endif 57 #endif
58 static_heap_base=(char*)ALIGN_ALLOC(static_heap_buffer); 58 static_heap_base=(char*)ALIGN_ALLOC(static_heap_buffer);
59 static_heap_ptr=static_heap_base; 59 static_heap_ptr=static_heap_base;
60 static_heap_size=STATIC_HEAP_SIZE - 60 static_heap_size=STATIC_HEAP_SIZE -
61 (static_heap_base-static_heap_buffer); 61 (static_heap_base-static_heap_buffer);
62 #ifdef CYGWIN 62 #ifdef __CYGWIN32__
63 sbrk(BLOCKSIZE); /* force space for fork to work */ 63 sbrk(BLOCKSIZE); /* force space for fork to work */
64 #endif 64 #endif
65 static_heap_initialized=1; 65 static_heap_initialized=1;
66 } 66 }
67 67
101 static_heap_ptr += size; 101 static_heap_ptr += size;
102 102
103 return result; 103 return result;
104 } 104 }
105 105
106 static void 106 void
107 sheap_adjust_h () 107 sheap_adjust_h ()
108 { 108 {
109 FILE *stream = fopen ("sheap-adjust.h", "w"); 109 FILE *stream = fopen ("sheap-adjust.h", "w");
110 110
111 if (stream == NULL) 111 if (stream == NULL)
118 "# define SHEAP_ADJUSTMENT (%d)\n", 118 "# define SHEAP_ADJUSTMENT (%d)\n",
119 ((static_heap_ptr - static_heap_buffer) - STATIC_HEAP_BASE)); 119 ((static_heap_ptr - static_heap_buffer) - STATIC_HEAP_BASE));
120 fclose (stream); 120 fclose (stream);
121 } 121 }
122 122
123 void report_sheap_usage (int die_if_pure_storage_exceeded);
124 void
125 report_sheap_usage (int die_if_pure_storage_exceeded)
126 {
127 int rc = 0;
128
129 size_t lost = (STATIC_HEAP_BASE + STATIC_HEAP_SLOP + SHEAP_ADJUSTMENT)
130 - (static_heap_ptr - static_heap_buffer);
131 char buf[200];
132 sprintf (buf, "Static heap usage: %ld of %ld",
133 (long) (static_heap_ptr - static_heap_buffer),
134 (long) (STATIC_HEAP_BASE + STATIC_HEAP_SLOP + SHEAP_ADJUSTMENT));
135
136 if (lost > STATIC_HEAP_SLOP) {
137 sprintf (buf + strlen (buf), " -- %ldk wasted", (long)(lost/1024));
138 if (die_if_pure_storage_exceeded) {
139 sheap_adjust_h();
140 rc = -1;
141 }
142 message ("%s", buf);
143 }
144
145 if (rc < 0) {
146 unlink("SATISFIED");
147 fatal ("Static heap size adjusted, Don't Panic! I will restart the `make'");
148 }
149 }
150
151