annotate src/vm-limit.c @ 383:6a50c6a581a5

Added tag r21-2-6 for changeset 064ab7fed2e0
author cvs
date Mon, 13 Aug 2007 11:07:40 +0200
parents 3d6bfa290dbd
children 74fd4e045ea6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Functions for memory limit warnings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1990, 1992 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Synched up with: FSF 19.30. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
28 #include <stddef.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #ifndef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 typedef size_t SIZE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 typedef void *POINTER;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #define EXCEEDS_LISP_PTR(x) 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include "mem-limits.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 Level number of warnings already issued.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 0 -- no warnings issued.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 1 -- 75% warning already issued.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 2 -- 85% warning already issued.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 3 -- 95% warning issued; keep warning frequently.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 static int warnlevel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 /* Function to call to issue a warning;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 0 means don't issue them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 static void (*warn_function) (CONST char *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 /* Get more memory space, complaining if we're near the end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 static void
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
53 check_memory_limits (void)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
55 extern POINTER (*__morecore) (ptrdiff_t size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 POINTER cp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 unsigned long five_percent;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 unsigned long data_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 if (lim_data == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 get_lim_data ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 five_percent = lim_data / 20;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 /* Find current end of memory and issue warning if getting near max */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 cp = (char *) (*__morecore) (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 data_size = (char *) cp - (char *) data_space_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 if (warn_function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 switch (warnlevel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
72 case 0:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 if (data_size > five_percent * 15)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 warnlevel++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (*warn_function) ("Warning: past 75% of memory limit");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
80 case 1:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 if (data_size > five_percent * 17)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 warnlevel++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (*warn_function) ("Warning: past 85% of memory limit");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
88 case 2:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 if (data_size > five_percent * 19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 warnlevel++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (*warn_function) ("Warning: past 95% of memory limit");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (*warn_function) ("Warning: past acceptable memory limits");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 /* If we go down below 70% full, issue another 75% warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 when we go up again. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 if (data_size < five_percent * 14)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 warnlevel = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 /* If we go down below 80% full, issue another 85% warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 when we go up again. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 else if (warnlevel > 1 && data_size < five_percent * 16)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 warnlevel = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 /* If we go down below 90% full, issue another 95% warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 when we go up again. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 else if (warnlevel > 2 && data_size < five_percent * 18)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 warnlevel = 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 if (EXCEEDS_LISP_PTR (cp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (*warn_function) ("Warning: memory in use exceeds lisp pointer size");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 /* Cause reinitialization based on job parameters;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 also declare where the end of pure storage is. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 memory_warnings (void *start, void (*warnfun) (CONST char *))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
124 extern void (* __after_morecore_hook) (void); /* From gmalloc.c */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 if (start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 data_space_start = start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 data_space_start = start_of_data ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 #ifndef _NO_MALLOC_WARNING_
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 warn_function = warnfun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 __after_morecore_hook = check_memory_limits;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 }