comparison src/sheap.c @ 414:da8ed4261e83 r21-2-15

Import from CVS: tag r21-2-15
author cvs
date Mon, 13 Aug 2007 11:21:38 +0200
parents 697ef44129c6
children 41dbb7a9d5f2
comparison
equal deleted inserted replaced
413:901169e5ca31 414:da8ed4261e83
23 #include "lisp.h" 23 #include "lisp.h"
24 #include <stddef.h> 24 #include <stddef.h>
25 #include <unistd.h> 25 #include <unistd.h>
26 #include <sheap-adjust.h> 26 #include <sheap-adjust.h>
27 27
28 #define STATIC_HEAP_BASE 0x600000 28 #define STATIC_HEAP_BASE 0x800000
29 #define STATIC_HEAP_SLOP 0x40000 29 #define STATIC_HEAP_SLOP 0x40000
30 #define STATIC_HEAP_SIZE \ 30 #define STATIC_HEAP_SIZE \
31 (STATIC_HEAP_BASE + SHEAP_ADJUSTMENT + STATIC_HEAP_SLOP) 31 (STATIC_HEAP_BASE + SHEAP_ADJUSTMENT + STATIC_HEAP_SLOP)
32 #define BLOCKSIZE (1<<12) 32 #define BLOCKSIZE (1<<12)
33 #define ALLOC_UNIT (BLOCKSIZE-1) 33 #define ALLOC_UNIT (BLOCKSIZE-1)
101 static_heap_ptr += size; 101 static_heap_ptr += size;
102 102
103 return result; 103 return result;
104 } 104 }
105 105
106 void 106 static 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
124 report_sheap_usage (int die_if_pure_storage_exceeded)
125 {
126 int rc = 0;
127
128 size_t lost = (STATIC_HEAP_BASE + STATIC_HEAP_SLOP + SHEAP_ADJUSTMENT)
129 - (static_heap_ptr - static_heap_buffer);
130 char buf[200];
131 sprintf (buf, "Static heap usage: %ld of %ld",
132 (long) (static_heap_ptr - static_heap_buffer),
133 (long) (STATIC_HEAP_BASE + STATIC_HEAP_SLOP + SHEAP_ADJUSTMENT));
134
135 if (lost > STATIC_HEAP_SLOP) {
136 sprintf (buf + strlen (buf), " -- %ldk wasted", (long)(lost/1024));
137 if (die_if_pure_storage_exceeded) {
138 sheap_adjust_h();
139 rc = -1;
140 }
141 message ("%s", buf);
142 }
143
144 if (rc < 0) {
145 unlink("SATISFIED");
146 fatal ("Static heap size adjusted, Don't Panic! I will restart the `make'");
147 }
148 }
149
150