annotate src/vm-limit.c @ 1053:a411429c4140

* xselect.c: Use the FRAME_X_WINDOW macro, for readability.
author Jim Blandy <jimb@redhat.com>
date Sat, 29 Aug 1992 03:33:12 +0000
parents 64e152d639af
children ad64a94cd81c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
1 /* Functions for memory limit warnings.
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
2 Copyright (C) 1990 Free Software Foundation, Inc.
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
3
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
4 This file is part of GNU Emacs.
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
5
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8 the Free Software Foundation; either version 1, or (at your option)
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
9 any later version.
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
10
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14 GNU General Public License for more details.
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
20 #include "config.h"
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
21 #include "lisp.h"
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
22 #include "mem_limits.h"
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
23
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
24 /*
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
25 Level number of warnings already issued.
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
26 0 -- no warnings issued.
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
27 1 -- 75% warning already issued.
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
28 2 -- 85% warning already issued.
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
29 */
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
30 static int warnlevel;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
31
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
32 /* Function to call to issue a warning;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
33 0 means don't issue them. */
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
34 static void (*warnfunction) ();
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
35
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
36 extern POINTER sbrk ();
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
37
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
38 /* Get more memory space, complaining if we're near the end. */
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
39
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
40 static POINTER
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
41 morecore_with_warning (size)
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
42 register int size;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
43 {
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
44 POINTER result;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
45 register POINTER cp;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
46 register unsigned int siz;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
47
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
48 if (!data_space_start)
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
49 {
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
50 data_space_start = start_of_data ();
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
51 }
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
52
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
53 if (lim_data == 0)
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
54 get_lim_data ();
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
55
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
56 /* Find current end of memory and issue warning if getting near max */
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
57 cp = sbrk (0);
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
58 siz = cp - data_space_start;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
59
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
60 if (warnfunction)
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
61 switch (warnlevel)
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
62 {
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
63 case 0:
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
64 if (siz > (lim_data / 4) * 3)
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
65 {
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
66 warnlevel++;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
67 (*warnfunction) ("Warning: past 75% of memory limit");
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
68 }
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
69 break;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
70
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
71 case 1:
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
72 if (siz > (lim_data / 20) * 17)
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
73 {
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
74 warnlevel++;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
75 (*warnfunction) ("Warning: past 85% of memory limit");
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
76 }
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
77 break;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
78
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
79 case 2:
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
80 if (siz > (lim_data / 20) * 19)
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
81 {
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
82 warnlevel++;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
83 (*warnfunction) ("Warning: past 95% of memory limit");
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
84 }
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
85 break;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
86
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
87 default:
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
88 (*warnfunction) ("Warning: past acceptable memory limits");
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
89 break;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
90 }
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
91
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
92 if (EXCEEDS_ELISP_PTR (cp))
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
93 (*warnfunction) ("Warning: memory in use exceeds lisp pointer size");
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
94
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
95 result = sbrk (size);
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
96 if (result == (POINTER) -1)
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
97 return NULL;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
98 return result;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
99 }
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
100
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
101 /* Cause reinitialization based on job parameters;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
102 also declare where the end of pure storage is. */
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
103
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
104 void
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
105 malloc_init (start, warnfun)
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
106 POINTER start;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
107 void (*warnfun) ();
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
108 {
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
109 extern POINTER (* __morecore) (); /* From gmalloc.c */
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
110
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
111 if (start)
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
112 data_space_start = start;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
113 lim_data = 0;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
114 warnlevel = 0;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
115 warnfunction = warnfun;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
116 __morecore = &morecore_with_warning;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
117 }