Commit | Line | Data |
---|---|---|
94d7c01a | 1 | /* Functions for memory limit warnings. |
e231fd42 | 2 | Copyright (C) 1990, 1992 Free Software Foundation, Inc. |
94d7c01a JA |
3 | |
4 | This file is part of GNU Emacs. | |
5 | ||
6 | GNU Emacs is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
e231fd42 | 8 | the Free Software Foundation; either version 2, or (at your option) |
94d7c01a JA |
9 | any later version. |
10 | ||
11 | GNU Emacs is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU Emacs; see the file COPYING. If not, write to | |
3b7ad313 EN |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. */ | |
94d7c01a | 20 | |
3b672b8f | 21 | #ifdef emacs |
18160b98 | 22 | #include <config.h> |
94d7c01a | 23 | #include "lisp.h" |
3b672b8f RS |
24 | #endif |
25 | ||
26 | #ifndef emacs | |
27 | #include <stddef.h> | |
28 | typedef size_t SIZE; | |
29 | typedef void *POINTER; | |
30 | #define EXCEEDS_LISP_PTR(x) 0 | |
31 | #endif | |
32 | ||
e231fd42 | 33 | #include "mem-limits.h" |
94d7c01a JA |
34 | |
35 | /* | |
36 | Level number of warnings already issued. | |
37 | 0 -- no warnings issued. | |
38 | 1 -- 75% warning already issued. | |
39 | 2 -- 85% warning already issued. | |
3b672b8f | 40 | 3 -- 95% warning issued; keep warning frequently. |
94d7c01a JA |
41 | */ |
42 | static int warnlevel; | |
43 | ||
44 | /* Function to call to issue a warning; | |
45 | 0 means don't issue them. */ | |
da396c5e | 46 | static void (*warn_function) (); |
94d7c01a | 47 | |
94d7c01a JA |
48 | /* Get more memory space, complaining if we're near the end. */ |
49 | ||
fd065466 RM |
50 | static void |
51 | check_memory_limits () | |
94d7c01a | 52 | { |
968e9c04 AI |
53 | #ifdef REL_ALLOC |
54 | extern POINTER (*real_morecore) (); | |
55 | #endif | |
134994ae RM |
56 | extern POINTER (*__morecore) (); |
57 | ||
968e9c04 | 58 | |
94d7c01a | 59 | register POINTER cp; |
46b3623d RS |
60 | unsigned long five_percent; |
61 | unsigned long data_size; | |
94d7c01a JA |
62 | |
63 | if (lim_data == 0) | |
64 | get_lim_data (); | |
3b672b8f | 65 | five_percent = lim_data / 20; |
94d7c01a JA |
66 | |
67 | /* Find current end of memory and issue warning if getting near max */ | |
968e9c04 AI |
68 | #ifdef REL_ALLOC |
69 | if (real_morecore) | |
70 | cp = (char *) (*real_morecore) (0); | |
71 | else | |
72 | #endif | |
fd065466 | 73 | cp = (char *) (*__morecore) (0); |
da396c5e | 74 | data_size = (char *) cp - (char *) data_space_start; |
94d7c01a | 75 | |
da396c5e | 76 | if (warn_function) |
94d7c01a JA |
77 | switch (warnlevel) |
78 | { | |
177c0ea7 | 79 | case 0: |
3b672b8f | 80 | if (data_size > five_percent * 15) |
94d7c01a JA |
81 | { |
82 | warnlevel++; | |
3b672b8f | 83 | (*warn_function) ("Warning: past 75% of memory limit"); |
94d7c01a JA |
84 | } |
85 | break; | |
86 | ||
177c0ea7 | 87 | case 1: |
3b672b8f | 88 | if (data_size > five_percent * 17) |
94d7c01a JA |
89 | { |
90 | warnlevel++; | |
3b672b8f | 91 | (*warn_function) ("Warning: past 85% of memory limit"); |
94d7c01a JA |
92 | } |
93 | break; | |
94 | ||
177c0ea7 | 95 | case 2: |
3b672b8f | 96 | if (data_size > five_percent * 19) |
94d7c01a JA |
97 | { |
98 | warnlevel++; | |
3b672b8f | 99 | (*warn_function) ("Warning: past 95% of memory limit"); |
94d7c01a JA |
100 | } |
101 | break; | |
102 | ||
103 | default: | |
3b672b8f | 104 | (*warn_function) ("Warning: past acceptable memory limits"); |
94d7c01a JA |
105 | break; |
106 | } | |
107 | ||
3b672b8f RS |
108 | /* If we go down below 70% full, issue another 75% warning |
109 | when we go up again. */ | |
110 | if (data_size < five_percent * 14) | |
111 | warnlevel = 0; | |
112 | /* If we go down below 80% full, issue another 85% warning | |
113 | when we go up again. */ | |
114 | else if (warnlevel > 1 && data_size < five_percent * 16) | |
115 | warnlevel = 1; | |
116 | /* If we go down below 90% full, issue another 95% warning | |
117 | when we go up again. */ | |
118 | else if (warnlevel > 2 && data_size < five_percent * 18) | |
119 | warnlevel = 2; | |
120 | ||
121 | if (EXCEEDS_LISP_PTR (cp)) | |
da396c5e | 122 | (*warn_function) ("Warning: memory in use exceeds lisp pointer size"); |
94d7c01a JA |
123 | } |
124 | ||
125 | /* Cause reinitialization based on job parameters; | |
126 | also declare where the end of pure storage is. */ | |
127 | ||
128 | void | |
3b672b8f | 129 | memory_warnings (start, warnfun) |
94d7c01a JA |
130 | POINTER start; |
131 | void (*warnfun) (); | |
132 | { | |
fd065466 | 133 | extern void (* __after_morecore_hook) (); /* From gmalloc.c */ |
94d7c01a JA |
134 | |
135 | if (start) | |
136 | data_space_start = start; | |
3b672b8f RS |
137 | else |
138 | data_space_start = start_of_data (); | |
139 | ||
da396c5e | 140 | warn_function = warnfun; |
fd065466 | 141 | __after_morecore_hook = check_memory_limits; |
b78e8d0a AI |
142 | |
143 | #ifdef WINDOWSNT | |
144 | /* Force data limit to be recalculated on each run. */ | |
145 | lim_data = 0; | |
146 | #endif | |
94d7c01a | 147 | } |
6b61353c KH |
148 | |
149 | /* arch-tag: eab04eda-1f69-447a-8d9f-95f0a3983ca5 | |
150 | (do not change this comment) */ |