comparison src/vm-limit.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 3ecd8885ac67
children e38acbeb1cae
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
43 */ 43 */
44 static int warnlevel; 44 static int warnlevel;
45 45
46 /* Function to call to issue a warning; 46 /* Function to call to issue a warning;
47 0 means don't issue them. */ 47 0 means don't issue them. */
48 static void (*warn_function) (CONST char *); 48 static void (*warn_function) (const char *);
49 49
50 /* Get more memory space, complaining if we're near the end. */ 50 /* Get more memory space, complaining if we're near the end. */
51 51
52 static void 52 static void
53 check_memory_limits (void) 53 check_memory_limits (void)
55 extern POINTER (*__morecore) (ptrdiff_t size); 55 extern POINTER (*__morecore) (ptrdiff_t size);
56 56
57 POINTER cp; 57 POINTER cp;
58 unsigned long five_percent; 58 unsigned long five_percent;
59 unsigned long data_size; 59 unsigned long data_size;
60 void (*save_warn_fun) (const char *);
60 61
61 if (lim_data == 0) 62 if (lim_data == 0)
62 get_lim_data (); 63 get_lim_data ();
63 five_percent = lim_data / 20; 64 five_percent = lim_data / 20;
64 65
65 /* Find current end of memory and issue warning if getting near max */ 66 /* Find current end of memory and issue warning if getting near max */
66 cp = (char *) (*__morecore) (0); 67 cp = (char *) (*__morecore) (0);
67 data_size = (char *) cp - (char *) data_space_start; 68 data_size = (char *) cp - (char *) data_space_start;
68 69
69 if (warn_function) 70 if (warn_function)
70 switch (warnlevel) 71 {
71 { 72 /* temporarily reset the warn_function to 0 or we will get infinite
72 case 0: 73 looping. */
73 if (data_size > five_percent * 15) 74 save_warn_fun = warn_function;
74 { 75 warn_function = 0;
75 warnlevel++; 76 switch (warnlevel)
76 (*warn_function) ("Warning: past 75% of memory limit"); 77 {
77 } 78 case 0:
78 break; 79 if (data_size > five_percent * 15)
80 {
81 warnlevel++;
82 (*save_warn_fun) ("Warning: past 75% of memory limit");
83 }
84 break;
79 85
80 case 1: 86 case 1:
81 if (data_size > five_percent * 17) 87 if (data_size > five_percent * 17)
82 { 88 {
83 warnlevel++; 89 warnlevel++;
84 (*warn_function) ("Warning: past 85% of memory limit"); 90 (*save_warn_fun) ("Warning: past 85% of memory limit");
85 } 91 }
86 break; 92 break;
87 93
88 case 2: 94 case 2:
89 if (data_size > five_percent * 19) 95 if (data_size > five_percent * 19)
90 { 96 {
91 warnlevel++; 97 warnlevel++;
92 (*warn_function) ("Warning: past 95% of memory limit"); 98 (*save_warn_fun) ("Warning: past 95% of memory limit");
93 } 99 }
94 break; 100 break;
95 101
96 default: 102 default:
97 (*warn_function) ("Warning: past acceptable memory limits"); 103 (*save_warn_fun) ("Warning: past acceptable memory limits");
98 break; 104 break;
99 } 105 }
106 warn_function = save_warn_fun;
107 }
100 108
101 /* If we go down below 70% full, issue another 75% warning 109 /* If we go down below 70% full, issue another 75% warning
102 when we go up again. */ 110 when we go up again. */
103 if (data_size < five_percent * 14) 111 if (data_size < five_percent * 14)
104 warnlevel = 0; 112 warnlevel = 0;
110 when we go up again. */ 118 when we go up again. */
111 else if (warnlevel > 2 && data_size < five_percent * 18) 119 else if (warnlevel > 2 && data_size < five_percent * 18)
112 warnlevel = 2; 120 warnlevel = 2;
113 121
114 if (EXCEEDS_LISP_PTR (cp)) 122 if (EXCEEDS_LISP_PTR (cp))
115 (*warn_function) ("Warning: memory in use exceeds lisp pointer size"); 123 {
124 if (warn_function)
125 {
126 /* temporarily reset the warn_function to 0 or we will get infinite
127 looping. */
128 save_warn_fun = warn_function;
129 warn_function = 0;
130 (*save_warn_fun)
131 ("Warning: memory in use exceeds lisp pointer size");
132 warn_function = save_warn_fun;
133 }
134 }
116 } 135 }
117 136
118 /* Cause reinitialization based on job parameters; 137 /* Cause reinitialization based on job parameters;
119 also declare where the end of pure storage is. */ 138 also declare where the end of pure storage is. */
120 139
121 void 140 void
122 memory_warnings (void *start, void (*warnfun) (CONST char *)) 141 memory_warnings (void *start, void (*warnfun) (const char *))
123 { 142 {
124 extern void (* __after_morecore_hook) (void); /* From gmalloc.c */ 143 extern void (* __after_morecore_hook) (void); /* From gmalloc.c */
125 144
126 if (start) 145 if (start)
127 data_space_start = start; 146 data_space_start = (char*) start;
128 else 147 else
129 data_space_start = start_of_data (); 148 data_space_start = start_of_data ();
130 149
131 #ifndef _NO_MALLOC_WARNING_ 150 #ifndef _NO_MALLOC_WARNING_
132 warn_function = warnfun; 151 warn_function = warnfun;