Mercurial > hg > xemacs-beta
annotate src/alloc.c @ 5402:308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
author | Mats Lidell <matsl@xemacs.org> |
---|---|
date | Thu, 14 Oct 2010 17:15:20 +0200 |
parents | 7d06a8bf47d2 |
children | 8d29f1c4bb98 |
rev | line source |
---|---|
428 | 1 /* Storage allocation and gc for XEmacs Lisp interpreter. |
2 Copyright (C) 1985-1998 Free Software Foundation, Inc. | |
3 Copyright (C) 1995 Sun Microsystems, Inc. | |
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
4 Copyright (C) 1995, 1996, 2001, 2002, 2003, 2004, 2005, 2010 Ben Wing. |
428 | 5 |
6 This file is part of XEmacs. | |
7 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5229
diff
changeset
|
8 XEmacs is free software: you can redistribute it and/or modify it |
428 | 9 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5229
diff
changeset
|
10 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5229
diff
changeset
|
11 option) any later version. |
428 | 12 |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5229
diff
changeset
|
19 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 20 |
21 /* Synched up with: FSF 19.28, Mule 2.0. Substantially different from | |
22 FSF. */ | |
23 | |
24 /* Authorship: | |
25 | |
26 FSF: Original version; a long time ago. | |
27 Mly: Significantly rewritten to use new 3-bit tags and | |
28 nicely abstracted object definitions, for 19.8. | |
29 JWZ: Improved code to keep track of purespace usage and | |
30 issue nice purespace and GC stats. | |
31 Ben Wing: Cleaned up frob-block lrecord code, added error-checking | |
32 and various changes for Mule, for 19.12. | |
33 Added bit vectors for 19.13. | |
34 Added lcrecord lists for 19.14. | |
35 slb: Lots of work on the purification and dump time code. | |
36 Synched Doug Lea malloc support from Emacs 20.2. | |
442 | 37 og: Killed the purespace. Portable dumper (moved to dumper.c) |
428 | 38 */ |
39 | |
40 #include <config.h> | |
41 #include "lisp.h" | |
42 | |
43 #include "backtrace.h" | |
44 #include "buffer.h" | |
45 #include "bytecode.h" | |
46 #include "chartab.h" | |
47 #include "device.h" | |
48 #include "elhash.h" | |
49 #include "events.h" | |
872 | 50 #include "extents-impl.h" |
1204 | 51 #include "file-coding.h" |
872 | 52 #include "frame-impl.h" |
3092 | 53 #include "gc.h" |
428 | 54 #include "glyphs.h" |
55 #include "opaque.h" | |
1204 | 56 #include "lstream.h" |
872 | 57 #include "process.h" |
1292 | 58 #include "profile.h" |
428 | 59 #include "redisplay.h" |
60 #include "specifier.h" | |
61 #include "sysfile.h" | |
442 | 62 #include "sysdep.h" |
428 | 63 #include "window.h" |
3092 | 64 #ifdef NEW_GC |
65 #include "vdb.h" | |
66 #endif /* NEW_GC */ | |
428 | 67 #include "console-stream.h" |
68 | |
69 #ifdef DOUG_LEA_MALLOC | |
70 #include <malloc.h> | |
71 #endif | |
4803
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
72 #ifdef USE_VALGRIND |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
73 #include <valgrind/memcheck.h> |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
74 #endif |
428 | 75 |
76 EXFUN (Fgarbage_collect, 0); | |
77 | |
78 #if 0 /* this is _way_ too slow to be part of the standard debug options */ | |
79 #if defined(DEBUG_XEMACS) && defined(MULE) | |
80 #define VERIFY_STRING_CHARS_INTEGRITY | |
81 #endif | |
82 #endif | |
83 | |
84 /* Define this to use malloc/free with no freelist for all datatypes, | |
85 the hope being that some debugging tools may help detect | |
86 freed memory references */ | |
87 #ifdef USE_DEBUG_MALLOC /* Taking the above comment at face value -slb */ | |
88 #include <dmalloc.h> | |
89 #define ALLOC_NO_POOLS | |
90 #endif | |
91 | |
92 #ifdef DEBUG_XEMACS | |
458 | 93 static Fixnum debug_allocation; |
94 static Fixnum debug_allocation_backtrace_length; | |
428 | 95 #endif |
96 | |
851 | 97 int need_to_check_c_alloca; |
887 | 98 int need_to_signal_post_gc; |
851 | 99 int funcall_allocation_flag; |
100 Bytecount __temp_alloca_size__; | |
101 Bytecount funcall_alloca_count; | |
814 | 102 |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
103 /* All the built-in lisp object types are enumerated in `enum lrecord_type'. |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
104 Additional ones may be defined by a module (none yet). We leave some |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
105 room in `lrecord_implementations_table' for such new lisp object types. */ |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
106 struct lrecord_implementation *lrecord_implementations_table[(int)lrecord_type_last_built_in_type + MODULE_DEFINABLE_TYPE_COUNT]; |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
107 int lrecord_type_count = lrecord_type_last_built_in_type; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
108 |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
109 /* This is just for use by the printer, to allow things to print uniquely. |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
110 We have a separate UID space for each object. (Important because the |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
111 UID is only 20 bits in old-GC, and 22 in NEW_GC.) */ |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
112 int lrecord_uid_counter[countof (lrecord_implementations_table)]; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
113 |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
114 #ifndef USE_KKCC |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
115 /* Object marker functions are in the lrecord_implementation structure. |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
116 But copying them to a parallel array is much more cache-friendly. |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
117 This hack speeds up (garbage-collect) by about 5%. */ |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
118 Lisp_Object (*lrecord_markers[countof (lrecord_implementations_table)]) (Lisp_Object); |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
119 #endif /* not USE_KKCC */ |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
120 |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
121 struct gcpro *gcprolist; |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
122 |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
123 /* Non-zero means we're in the process of doing the dump */ |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
124 int purify_flag; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
125 |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
126 /* Non-zero means we're pdumping out or in */ |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
127 #ifdef PDUMP |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
128 int in_pdump; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
129 #endif |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
130 |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
131 #ifdef ERROR_CHECK_TYPES |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
132 |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
133 Error_Behavior ERROR_ME, ERROR_ME_NOT, ERROR_ME_WARN, ERROR_ME_DEBUG_WARN; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
134 |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
135 #endif |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
136 |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
137 #ifdef MEMORY_USAGE_STATS |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
138 Lisp_Object Qobject_actually_requested, Qobject_malloc_overhead; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
139 Lisp_Object Qother_memory_actually_requested, Qother_memory_malloc_overhead; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
140 Lisp_Object Qother_memory_dynarr_overhead, Qother_memory_gap_overhead; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
141 #endif /* MEMORY_USAGE_STATS */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
142 |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
143 #ifndef NEW_GC |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
144 static int gc_count_num_short_string_in_use; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
145 static Bytecount gc_count_string_total_size; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
146 static Bytecount gc_count_short_string_total_size; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
147 static Bytecount gc_count_long_string_storage_including_overhead; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
148 #endif /* not NEW_GC */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
149 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
150 /* static int gc_count_total_records_used, gc_count_records_total_size; */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
151 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
152 /* stats on objects in use */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
153 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
154 #ifdef NEW_GC |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
155 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
156 static struct |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
157 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
158 int instances_in_use; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
159 int bytes_in_use; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
160 int bytes_in_use_including_overhead; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
161 } lrecord_stats [countof (lrecord_implementations_table)]; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
162 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
163 #else /* not NEW_GC */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
164 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
165 static struct |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
166 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
167 Elemcount instances_in_use; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
168 Bytecount bytes_in_use; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
169 Bytecount bytes_in_use_overhead; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
170 Elemcount instances_freed; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
171 Bytecount bytes_freed; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
172 Bytecount bytes_freed_overhead; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
173 Elemcount instances_on_free_list; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
174 Bytecount bytes_on_free_list; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
175 Bytecount bytes_on_free_list_overhead; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
176 #ifdef MEMORY_USAGE_STATS |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
177 Bytecount nonlisp_bytes_in_use; |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
178 Bytecount lisp_ancillary_bytes_in_use; |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
179 struct generic_usage_stats stats; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
180 #endif |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
181 } lrecord_stats [countof (lrecord_implementations_table)]; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
182 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
183 #endif /* (not) NEW_GC */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
184 |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
185 /* Very cheesy ways of figuring out how much memory is being used for |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
186 data. #### Need better (system-dependent) ways. */ |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
187 void *minimum_address_seen; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
188 void *maximum_address_seen; |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
189 |
428 | 190 |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
191 /************************************************************************/ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
192 /* Low-level allocation */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
193 /************************************************************************/ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
194 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
195 void |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
196 recompute_funcall_allocation_flag (void) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
197 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
198 funcall_allocation_flag = |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
199 need_to_garbage_collect || |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
200 need_to_check_c_alloca || |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
201 need_to_signal_post_gc; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
202 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
203 |
428 | 204 /* Maximum amount of C stack to save when a GC happens. */ |
205 | |
206 #ifndef MAX_SAVE_STACK | |
207 #define MAX_SAVE_STACK 0 /* 16000 */ | |
208 #endif | |
209 | |
210 /* Non-zero means ignore malloc warnings. Set during initialization. */ | |
211 int ignore_malloc_warnings; | |
212 | |
213 | |
3263 | 214 #ifndef NEW_GC |
3092 | 215 void *breathing_space; |
428 | 216 |
217 void | |
218 release_breathing_space (void) | |
219 { | |
220 if (breathing_space) | |
221 { | |
222 void *tmp = breathing_space; | |
223 breathing_space = 0; | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
224 xfree (tmp); |
428 | 225 } |
226 } | |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
227 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
228 #if !defined(HAVE_MMAP) || defined(DOUG_LEA_MALLOC) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
229 /* If we released our reserve (due to running out of memory), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
230 and we have a fair amount free once again, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
231 try to set aside another reserve in case we run out once more. |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
232 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
233 This is called when a relocatable block is freed in ralloc.c. */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
234 void refill_memory_reserve (void); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
235 void |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
236 refill_memory_reserve (void) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
237 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
238 if (breathing_space == 0) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
239 breathing_space = (char *) malloc (4096 - MALLOC_OVERHEAD); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
240 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
241 #endif /* !defined(HAVE_MMAP) || defined(DOUG_LEA_MALLOC) */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
242 |
3263 | 243 #endif /* not NEW_GC */ |
428 | 244 |
801 | 245 static void |
246 set_alloc_mins_and_maxes (void *val, Bytecount size) | |
247 { | |
248 if (!val) | |
249 return; | |
250 if ((char *) val + size > (char *) maximum_address_seen) | |
251 maximum_address_seen = (char *) val + size; | |
252 if (!minimum_address_seen) | |
253 minimum_address_seen = | |
254 #if SIZEOF_VOID_P == 8 | |
255 (void *) 0xFFFFFFFFFFFFFFFF; | |
256 #else | |
257 (void *) 0xFFFFFFFF; | |
258 #endif | |
259 if ((char *) val < (char *) minimum_address_seen) | |
260 minimum_address_seen = (char *) val; | |
261 } | |
262 | |
1315 | 263 #ifdef ERROR_CHECK_MALLOC |
3176 | 264 static int in_malloc; |
1333 | 265 extern int regex_malloc_disallowed; |
2367 | 266 |
267 #define MALLOC_BEGIN() \ | |
268 do \ | |
269 { \ | |
3176 | 270 assert (!in_malloc); \ |
2367 | 271 assert (!regex_malloc_disallowed); \ |
272 in_malloc = 1; \ | |
273 } \ | |
274 while (0) | |
275 | |
3263 | 276 #ifdef NEW_GC |
2720 | 277 #define FREE_OR_REALLOC_BEGIN(block) \ |
278 do \ | |
279 { \ | |
280 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an \ | |
281 error until much later on for many system mallocs, such as \ | |
282 the one that comes with Solaris 2.3. FMH!! */ \ | |
4938
299dce99bdad
(for main branch) when freeing check against DEADBEEF_CONSTANT since that's what we use elsewhere
Ben Wing <ben@xemacs.org>
parents:
4934
diff
changeset
|
283 assert (block != (void *) DEADBEEF_CONSTANT); \ |
2720 | 284 MALLOC_BEGIN (); \ |
285 } \ | |
286 while (0) | |
3263 | 287 #else /* not NEW_GC */ |
2367 | 288 #define FREE_OR_REALLOC_BEGIN(block) \ |
289 do \ | |
290 { \ | |
291 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an \ | |
292 error until much later on for many system mallocs, such as \ | |
293 the one that comes with Solaris 2.3. FMH!! */ \ | |
4938
299dce99bdad
(for main branch) when freeing check against DEADBEEF_CONSTANT since that's what we use elsewhere
Ben Wing <ben@xemacs.org>
parents:
4934
diff
changeset
|
294 assert (block != (void *) DEADBEEF_CONSTANT); \ |
2367 | 295 /* You cannot free something within dumped space, because there is \ |
296 no longer any sort of malloc structure associated with the block. \ | |
297 If you are tripping this, you may need to conditionalize on \ | |
298 DUMPEDP. */ \ | |
299 assert (!DUMPEDP (block)); \ | |
300 MALLOC_BEGIN (); \ | |
301 } \ | |
302 while (0) | |
3263 | 303 #endif /* not NEW_GC */ |
2367 | 304 |
305 #define MALLOC_END() \ | |
306 do \ | |
307 { \ | |
308 in_malloc = 0; \ | |
309 } \ | |
310 while (0) | |
311 | |
312 #else /* ERROR_CHECK_MALLOC */ | |
313 | |
2658 | 314 #define MALLOC_BEGIN() |
2367 | 315 #define FREE_OR_REALLOC_BEGIN(block) |
316 #define MALLOC_END() | |
317 | |
318 #endif /* ERROR_CHECK_MALLOC */ | |
319 | |
320 static void | |
321 malloc_after (void *val, Bytecount size) | |
322 { | |
323 if (!val && size != 0) | |
324 memory_full (); | |
325 set_alloc_mins_and_maxes (val, size); | |
326 } | |
327 | |
3305 | 328 /* malloc calls this if it finds we are near exhausting storage */ |
329 void | |
330 malloc_warning (const char *str) | |
331 { | |
332 if (ignore_malloc_warnings) | |
333 return; | |
334 | |
335 /* Remove the malloc lock here, because warn_when_safe may allocate | |
336 again. It is safe to remove the malloc lock here, because malloc | |
337 is already finished (malloc_warning is called via | |
338 after_morecore_hook -> check_memory_limits -> save_warn_fun -> | |
339 malloc_warning). */ | |
340 MALLOC_END (); | |
341 | |
342 warn_when_safe | |
343 (Qmemory, Qemergency, | |
344 "%s\n" | |
345 "Killing some buffers may delay running out of memory.\n" | |
346 "However, certainly by the time you receive the 95%% warning,\n" | |
347 "you should clean up, kill this Emacs, and start a new one.", | |
348 str); | |
349 } | |
350 | |
351 /* Called if malloc returns zero */ | |
352 DOESNT_RETURN | |
353 memory_full (void) | |
354 { | |
355 /* Force a GC next time eval is called. | |
356 It's better to loop garbage-collecting (we might reclaim enough | |
357 to win) than to loop beeping and barfing "Memory exhausted" | |
358 */ | |
359 consing_since_gc = gc_cons_threshold + 1; | |
360 recompute_need_to_garbage_collect (); | |
361 #ifdef NEW_GC | |
362 /* Put mc-alloc into memory shortage mode. This may keep XEmacs | |
363 alive until the garbage collector can free enough memory to get | |
364 us out of the memory exhaustion. If already in memory shortage | |
365 mode, we are in a loop and hopelessly lost. */ | |
366 if (memory_shortage) | |
367 { | |
368 fprintf (stderr, "Memory full, cannot recover.\n"); | |
369 ABORT (); | |
370 } | |
371 fprintf (stderr, | |
372 "Memory full, try to recover.\n" | |
373 "You should clean up, kill this Emacs, and start a new one.\n"); | |
374 memory_shortage++; | |
375 #else /* not NEW_GC */ | |
376 release_breathing_space (); | |
377 #endif /* not NEW_GC */ | |
378 | |
379 /* Flush some histories which might conceivably contain garbalogical | |
380 inhibitors. */ | |
381 if (!NILP (Fboundp (Qvalues))) | |
382 Fset (Qvalues, Qnil); | |
383 Vcommand_history = Qnil; | |
384 | |
385 out_of_memory ("Memory exhausted", Qunbound); | |
386 } | |
387 | |
2367 | 388 /* like malloc, calloc, realloc, free but: |
389 | |
390 -- check for no memory left | |
391 -- set internal mins and maxes | |
392 -- with error-checking on, check for reentrancy, invalid freeing, etc. | |
393 */ | |
1292 | 394 |
428 | 395 #undef xmalloc |
396 void * | |
665 | 397 xmalloc (Bytecount size) |
428 | 398 { |
1292 | 399 void *val; |
2367 | 400 MALLOC_BEGIN (); |
1292 | 401 val = malloc (size); |
2367 | 402 MALLOC_END (); |
403 malloc_after (val, size); | |
428 | 404 return val; |
405 } | |
406 | |
407 #undef xcalloc | |
408 static void * | |
665 | 409 xcalloc (Elemcount nelem, Bytecount elsize) |
428 | 410 { |
1292 | 411 void *val; |
2367 | 412 MALLOC_BEGIN (); |
1292 | 413 val= calloc (nelem, elsize); |
2367 | 414 MALLOC_END (); |
415 malloc_after (val, nelem * elsize); | |
428 | 416 return val; |
417 } | |
418 | |
419 void * | |
665 | 420 xmalloc_and_zero (Bytecount size) |
428 | 421 { |
422 return xcalloc (size, sizeof (char)); | |
423 } | |
424 | |
425 #undef xrealloc | |
426 void * | |
665 | 427 xrealloc (void *block, Bytecount size) |
428 | 428 { |
2367 | 429 FREE_OR_REALLOC_BEGIN (block); |
551 | 430 block = realloc (block, size); |
2367 | 431 MALLOC_END (); |
432 malloc_after (block, size); | |
551 | 433 return block; |
428 | 434 } |
435 | |
436 void | |
437 xfree_1 (void *block) | |
438 { | |
439 #ifdef ERROR_CHECK_MALLOC | |
440 assert (block); | |
441 #endif /* ERROR_CHECK_MALLOC */ | |
2367 | 442 FREE_OR_REALLOC_BEGIN (block); |
428 | 443 free (block); |
2367 | 444 MALLOC_END (); |
428 | 445 } |
446 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
447 void |
665 | 448 deadbeef_memory (void *ptr, Bytecount size) |
428 | 449 { |
826 | 450 UINT_32_BIT *ptr4 = (UINT_32_BIT *) ptr; |
665 | 451 Bytecount beefs = size >> 2; |
428 | 452 |
453 /* In practice, size will always be a multiple of four. */ | |
454 while (beefs--) | |
1204 | 455 (*ptr4++) = 0xDEADBEEF; /* -559038737 base 10 */ |
428 | 456 } |
457 | |
458 #undef xstrdup | |
459 char * | |
442 | 460 xstrdup (const char *str) |
428 | 461 { |
462 int len = strlen (str) + 1; /* for stupid terminating 0 */ | |
463 void *val = xmalloc (len); | |
771 | 464 |
428 | 465 if (val == 0) return 0; |
466 return (char *) memcpy (val, str, len); | |
467 } | |
468 | |
469 #ifdef NEED_STRDUP | |
470 char * | |
442 | 471 strdup (const char *s) |
428 | 472 { |
473 return xstrdup (s); | |
474 } | |
475 #endif /* NEED_STRDUP */ | |
476 | |
477 | |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
478 /************************************************************************/ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
479 /* Lisp object allocation */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
480 /************************************************************************/ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
481 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
482 /* Determine now whether we need to garbage collect or not, to make |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
483 Ffuncall() faster */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
484 #define INCREMENT_CONS_COUNTER_1(size) \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
485 do \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
486 { \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
487 consing_since_gc += (size); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
488 total_consing += (size); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
489 if (profiling_active) \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
490 profile_record_consing (size); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
491 recompute_need_to_garbage_collect (); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
492 } while (0) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
493 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
494 #define debug_allocation_backtrace() \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
495 do { \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
496 if (debug_allocation_backtrace_length > 0) \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
497 debug_short_backtrace (debug_allocation_backtrace_length); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
498 } while (0) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
499 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
500 #ifdef DEBUG_XEMACS |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
501 #define INCREMENT_CONS_COUNTER(foosize, type) \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
502 do { \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
503 if (debug_allocation) \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
504 { \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
505 stderr_out ("allocating %s (size %ld)\n", type, \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
506 (long) foosize); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
507 debug_allocation_backtrace (); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
508 } \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
509 INCREMENT_CONS_COUNTER_1 (foosize); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
510 } while (0) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
511 #define NOSEEUM_INCREMENT_CONS_COUNTER(foosize, type) \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
512 do { \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
513 if (debug_allocation > 1) \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
514 { \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
515 stderr_out ("allocating noseeum %s (size %ld)\n", type, \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
516 (long) foosize); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
517 debug_allocation_backtrace (); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
518 } \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
519 INCREMENT_CONS_COUNTER_1 (foosize); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
520 } while (0) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
521 #else |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
522 #define INCREMENT_CONS_COUNTER(size, type) INCREMENT_CONS_COUNTER_1 (size) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
523 #define NOSEEUM_INCREMENT_CONS_COUNTER(size, type) \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
524 INCREMENT_CONS_COUNTER_1 (size) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
525 #endif |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
526 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
527 #ifdef NEW_GC |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
528 /* [[ The call to recompute_need_to_garbage_collect is moved to |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
529 free_normal_lisp_object, since DECREMENT_CONS_COUNTER is extensively called |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
530 during sweep and recomputing need_to_garbage_collect all the time |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
531 is not needed. ]] -- not accurate! */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
532 #define DECREMENT_CONS_COUNTER(size) do { \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
533 consing_since_gc -= (size); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
534 total_consing -= (size); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
535 if (profiling_active) \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
536 profile_record_unconsing (size); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
537 if (consing_since_gc < 0) \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
538 consing_since_gc = 0; \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
539 } while (0) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
540 #else /* not NEW_GC */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
541 #define DECREMENT_CONS_COUNTER(size) do { \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
542 consing_since_gc -= (size); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
543 total_consing -= (size); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
544 if (profiling_active) \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
545 profile_record_unconsing (size); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
546 if (consing_since_gc < 0) \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
547 consing_since_gc = 0; \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
548 recompute_need_to_garbage_collect (); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
549 } while (0) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
550 #endif /*not NEW_GC */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
551 |
3263 | 552 #ifndef NEW_GC |
428 | 553 static void * |
665 | 554 allocate_lisp_storage (Bytecount size) |
428 | 555 { |
793 | 556 void *val = xmalloc (size); |
557 /* We don't increment the cons counter anymore. Calling functions do | |
558 that now because we have two different kinds of cons counters -- one | |
559 for normal objects, and one for no-see-um conses (and possibly others | |
560 similar) where the conses are used totally internally, never escape, | |
561 and are created and then freed and shouldn't logically increment the | |
562 cons counting. #### (Or perhaps, we should decrement it when an object | |
563 get freed?) */ | |
564 | |
565 /* But we do now (as of 3-27-02) go and zero out the memory. This is a | |
566 good thing, as it will guarantee we won't get any intermittent bugs | |
1204 | 567 coming from an uninitiated field. The speed loss is unnoticeable, |
568 esp. as the objects are not large -- large stuff like buffer text and | |
569 redisplay structures are allocated separately. */ | |
793 | 570 memset (val, 0, size); |
851 | 571 |
572 if (need_to_check_c_alloca) | |
573 xemacs_c_alloca (0); | |
574 | |
793 | 575 return val; |
428 | 576 } |
3263 | 577 #endif /* not NEW_GC */ |
578 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
579 #define assert_proper_sizing(size) \ |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
580 type_checking_assert \ |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
581 (implementation->static_size == 0 ? \ |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
582 implementation->size_in_bytes_method != NULL : \ |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
583 implementation->size_in_bytes_method == NULL && \ |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
584 implementation->static_size == size) |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
585 |
3263 | 586 #ifndef NEW_GC |
442 | 587 /* lcrecords are chained together through their "next" field. |
588 After doing the mark phase, GC will walk this linked list | |
589 and free any lcrecord which hasn't been marked. */ | |
3024 | 590 static struct old_lcrecord_header *all_lcrecords; |
3263 | 591 #endif /* not NEW_GC */ |
592 | |
593 #ifdef NEW_GC | |
2720 | 594 /* The basic lrecord allocation functions. See lrecord.h for details. */ |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
595 static Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
596 alloc_sized_lrecord_1 (Bytecount size, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
597 const struct lrecord_implementation *implementation, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
598 int noseeum) |
2720 | 599 { |
600 struct lrecord_header *lheader; | |
601 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
602 assert_proper_sizing (size); |
2720 | 603 |
604 lheader = (struct lrecord_header *) mc_alloc (size); | |
605 gc_checking_assert (LRECORD_FREE_P (lheader)); | |
606 set_lheader_implementation (lheader, implementation); | |
2994 | 607 #ifdef ALLOC_TYPE_STATS |
2720 | 608 inc_lrecord_stats (size, lheader); |
2994 | 609 #endif /* ALLOC_TYPE_STATS */ |
3263 | 610 if (implementation->finalizer) |
611 add_finalizable_obj (wrap_pointer_1 (lheader)); | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
612 if (noseeum) |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
613 NOSEEUM_INCREMENT_CONS_COUNTER (size, implementation->name); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
614 else |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
615 INCREMENT_CONS_COUNTER (size, implementation->name); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
616 return wrap_pointer_1 (lheader); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
617 } |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
618 |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
619 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
620 alloc_sized_lrecord (Bytecount size, |
3092 | 621 const struct lrecord_implementation *implementation) |
622 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
623 return alloc_sized_lrecord_1 (size, implementation, 0); |
2720 | 624 } |
625 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
626 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
627 noseeum_alloc_sized_lrecord (Bytecount size, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
628 const struct lrecord_implementation * |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
629 implementation) |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
630 { |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
631 return alloc_sized_lrecord_1 (size, implementation, 1); |
2720 | 632 } |
633 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
634 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
635 alloc_lrecord (const struct lrecord_implementation *implementation) |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
636 { |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
637 type_checking_assert (implementation->static_size > 0); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
638 return alloc_sized_lrecord (implementation->static_size, implementation); |
2720 | 639 } |
640 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
641 Lisp_Object |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
642 noseeum_alloc_lrecord (const struct lrecord_implementation *implementation) |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
643 { |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
644 type_checking_assert (implementation->static_size > 0); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
645 return noseeum_alloc_sized_lrecord (implementation->static_size, implementation); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
646 } |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
647 |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
648 Lisp_Object |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
649 alloc_sized_lrecord_array (Bytecount size, int elemcount, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
650 const struct lrecord_implementation *implementation) |
3092 | 651 { |
652 struct lrecord_header *lheader; | |
653 Rawbyte *start, *stop; | |
654 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
655 assert_proper_sizing (size); |
3092 | 656 |
657 lheader = (struct lrecord_header *) mc_alloc_array (size, elemcount); | |
658 gc_checking_assert (LRECORD_FREE_P (lheader)); | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
659 |
3092 | 660 for (start = (Rawbyte *) lheader, |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
661 /* #### FIXME: why is this -1 present? */ |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
662 stop = ((Rawbyte *) lheader) + (size * elemcount -1); |
3092 | 663 start < stop; start += size) |
664 { | |
665 struct lrecord_header *lh = (struct lrecord_header *) start; | |
666 set_lheader_implementation (lh, implementation); | |
667 #ifdef ALLOC_TYPE_STATS | |
668 inc_lrecord_stats (size, lh); | |
669 #endif /* not ALLOC_TYPE_STATS */ | |
3263 | 670 if (implementation->finalizer) |
671 add_finalizable_obj (wrap_pointer_1 (lh)); | |
3092 | 672 } |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
673 |
3092 | 674 INCREMENT_CONS_COUNTER (size * elemcount, implementation->name); |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
675 return wrap_pointer_1 (lheader); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
676 } |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
677 |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
678 Lisp_Object |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
679 alloc_lrecord_array (int elemcount, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
680 const struct lrecord_implementation *implementation) |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
681 { |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
682 type_checking_assert (implementation->static_size > 0); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
683 return alloc_sized_lrecord_array (implementation->static_size, elemcount, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
684 implementation); |
3092 | 685 } |
686 | |
3263 | 687 #else /* not NEW_GC */ |
428 | 688 |
1204 | 689 /* The most basic of the lcrecord allocation functions. Not usually called |
690 directly. Allocates an lrecord not managed by any lcrecord-list, of a | |
691 specified size. See lrecord.h. */ | |
692 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
693 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
694 old_alloc_sized_lcrecord (Bytecount size, |
3024 | 695 const struct lrecord_implementation *implementation) |
696 { | |
697 struct old_lcrecord_header *lcheader; | |
428 | 698 |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
699 assert_proper_sizing (size); |
442 | 700 type_checking_assert |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
701 (!implementation->frob_block_p |
442 | 702 && |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
703 !(implementation->hash == NULL && implementation->equal != NULL)); |
428 | 704 |
3024 | 705 lcheader = (struct old_lcrecord_header *) allocate_lisp_storage (size); |
442 | 706 set_lheader_implementation (&lcheader->lheader, implementation); |
428 | 707 lcheader->next = all_lcrecords; |
708 all_lcrecords = lcheader; | |
709 INCREMENT_CONS_COUNTER (size, implementation->name); | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
710 return wrap_pointer_1 (lcheader); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
711 } |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
712 |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
713 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
714 old_alloc_lcrecord (const struct lrecord_implementation *implementation) |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
715 { |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
716 type_checking_assert (implementation->static_size > 0); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
717 return old_alloc_sized_lcrecord (implementation->static_size, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
718 implementation); |
428 | 719 } |
720 | |
721 #if 0 /* Presently unused */ | |
722 /* Very, very poor man's EGC? | |
723 * This may be slow and thrash pages all over the place. | |
724 * Only call it if you really feel you must (and if the | |
725 * lrecord was fairly recently allocated). | |
726 * Otherwise, just let the GC do its job -- that's what it's there for | |
727 */ | |
728 void | |
3024 | 729 very_old_free_lcrecord (struct old_lcrecord_header *lcrecord) |
428 | 730 { |
731 if (all_lcrecords == lcrecord) | |
732 { | |
733 all_lcrecords = lcrecord->next; | |
734 } | |
735 else | |
736 { | |
3024 | 737 struct old_lcrecord_header *header = all_lcrecords; |
428 | 738 for (;;) |
739 { | |
3024 | 740 struct old_lcrecord_header *next = header->next; |
428 | 741 if (next == lcrecord) |
742 { | |
743 header->next = lrecord->next; | |
744 break; | |
745 } | |
746 else if (next == 0) | |
2500 | 747 ABORT (); |
428 | 748 else |
749 header = next; | |
750 } | |
751 } | |
752 if (lrecord->implementation->finalizer) | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
753 lrecord->implementation->finalizer (wrap_pointer_1 (lrecord)); |
428 | 754 xfree (lrecord); |
755 return; | |
756 } | |
757 #endif /* Unused */ | |
3263 | 758 #endif /* not NEW_GC */ |
428 | 759 |
1204 | 760 /* Bitwise copy all parts of a Lisp object other than the header */ |
761 | |
762 void | |
763 copy_lisp_object (Lisp_Object dst, Lisp_Object src) | |
764 { | |
765 const struct lrecord_implementation *imp = | |
766 XRECORD_LHEADER_IMPLEMENTATION (src); | |
767 Bytecount size = lisp_object_size (src); | |
768 | |
769 assert (imp == XRECORD_LHEADER_IMPLEMENTATION (dst)); | |
770 assert (size == lisp_object_size (dst)); | |
771 | |
3263 | 772 #ifdef NEW_GC |
2720 | 773 memcpy ((char *) XRECORD_LHEADER (dst) + sizeof (struct lrecord_header), |
774 (char *) XRECORD_LHEADER (src) + sizeof (struct lrecord_header), | |
775 size - sizeof (struct lrecord_header)); | |
3263 | 776 #else /* not NEW_GC */ |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
777 if (imp->frob_block_p) |
1204 | 778 memcpy ((char *) XRECORD_LHEADER (dst) + sizeof (struct lrecord_header), |
779 (char *) XRECORD_LHEADER (src) + sizeof (struct lrecord_header), | |
780 size - sizeof (struct lrecord_header)); | |
781 else | |
3024 | 782 memcpy ((char *) XRECORD_LHEADER (dst) + |
783 sizeof (struct old_lcrecord_header), | |
784 (char *) XRECORD_LHEADER (src) + | |
785 sizeof (struct old_lcrecord_header), | |
786 size - sizeof (struct old_lcrecord_header)); | |
3263 | 787 #endif /* not NEW_GC */ |
1204 | 788 } |
789 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
790 /* Zero out all parts of a Lisp object other than the header, for a |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
791 variable-sized object. The size needs to be given explicitly because |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
792 at the time this is called, the contents of the object may not be |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
793 defined, or may not be set up in such a way that we can reliably |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
794 retrieve the size, since it may depend on settings inside of the object. */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
795 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
796 void |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
797 zero_sized_lisp_object (Lisp_Object obj, Bytecount size) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
798 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
799 #ifndef NEW_GC |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
800 const struct lrecord_implementation *imp = |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
801 XRECORD_LHEADER_IMPLEMENTATION (obj); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
802 #endif /* not NEW_GC */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
803 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
804 #ifdef NEW_GC |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
805 memset ((char *) XRECORD_LHEADER (obj) + sizeof (struct lrecord_header), 0, |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
806 size - sizeof (struct lrecord_header)); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
807 #else /* not NEW_GC */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
808 if (imp->frob_block_p) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
809 memset ((char *) XRECORD_LHEADER (obj) + sizeof (struct lrecord_header), 0, |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
810 size - sizeof (struct lrecord_header)); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
811 else |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
812 memset ((char *) XRECORD_LHEADER (obj) + |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
813 sizeof (struct old_lcrecord_header), 0, |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
814 size - sizeof (struct old_lcrecord_header)); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
815 #endif /* not NEW_GC */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
816 } |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
817 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
818 /* Zero out all parts of a Lisp object other than the header, for an object |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
819 that isn't variable-size. Objects that are variable-size need to use |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
820 zero_sized_lisp_object(). |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
821 */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
822 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
823 void |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
824 zero_nonsized_lisp_object (Lisp_Object obj) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
825 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
826 const struct lrecord_implementation *imp = |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
827 XRECORD_LHEADER_IMPLEMENTATION (obj); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
828 assert (!imp->size_in_bytes_method); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
829 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
830 zero_sized_lisp_object (obj, lisp_object_size (obj)); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
831 } |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
832 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
833 void |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
834 free_normal_lisp_object (Lisp_Object obj) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
835 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
836 #ifndef NEW_GC |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
837 const struct lrecord_implementation *imp = |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
838 XRECORD_LHEADER_IMPLEMENTATION (obj); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
839 #endif /* not NEW_GC */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
840 |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
841 #ifdef NEW_GC |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
842 /* Manual frees are not allowed with asynchronous finalization */ |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
843 return; |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
844 #else |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
845 assert (!imp->frob_block_p); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
846 assert (!imp->size_in_bytes_method); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
847 old_free_lcrecord (obj); |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
848 #endif |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
849 } |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
850 |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
851 #ifndef NEW_GC |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
852 int |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
853 c_readonly (Lisp_Object obj) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
854 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
855 return POINTER_TYPE_P (XTYPE (obj)) && C_READONLY (obj); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
856 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
857 #endif /* not NEW_GC */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
858 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
859 int |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
860 lisp_readonly (Lisp_Object obj) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
861 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
862 return POINTER_TYPE_P (XTYPE (obj)) && LISP_READONLY (obj); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
863 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
864 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
865 /* #### Should be made into an object method */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
866 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
867 int |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
868 object_dead_p (Lisp_Object obj) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
869 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
870 return ((BUFFERP (obj) && !BUFFER_LIVE_P (XBUFFER (obj))) || |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
871 (FRAMEP (obj) && !FRAME_LIVE_P (XFRAME (obj))) || |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
872 (WINDOWP (obj) && !WINDOW_LIVE_P (XWINDOW (obj))) || |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
873 (DEVICEP (obj) && !DEVICE_LIVE_P (XDEVICE (obj))) || |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
874 (CONSOLEP (obj) && !CONSOLE_LIVE_P (XCONSOLE (obj))) || |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
875 (EVENTP (obj) && !EVENT_LIVE_P (XEVENT (obj))) || |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
876 (EXTENTP (obj) && !EXTENT_LIVE_P (XEXTENT (obj)))); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
877 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
878 |
428 | 879 |
880 /************************************************************************/ | |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
881 /* Debugger support */ |
428 | 882 /************************************************************************/ |
883 /* Give gdb/dbx enough information to decode Lisp Objects. We make | |
884 sure certain symbols are always defined, so gdb doesn't complain | |
438 | 885 about expressions in src/.gdbinit. See src/.gdbinit or src/.dbxrc |
886 to see how this is used. */ | |
428 | 887 |
458 | 888 EMACS_UINT dbg_valmask = ((1UL << VALBITS) - 1) << GCBITS; |
889 EMACS_UINT dbg_typemask = (1UL << GCTYPEBITS) - 1; | |
428 | 890 |
891 #ifdef USE_UNION_TYPE | |
458 | 892 unsigned char dbg_USE_UNION_TYPE = 1; |
428 | 893 #else |
458 | 894 unsigned char dbg_USE_UNION_TYPE = 0; |
428 | 895 #endif |
896 | |
458 | 897 unsigned char dbg_valbits = VALBITS; |
898 unsigned char dbg_gctypebits = GCTYPEBITS; | |
899 | |
900 /* On some systems, the above definitions will be optimized away by | |
901 the compiler or linker unless they are referenced in some function. */ | |
902 long dbg_inhibit_dbg_symbol_deletion (void); | |
903 long | |
904 dbg_inhibit_dbg_symbol_deletion (void) | |
905 { | |
906 return | |
907 (dbg_valmask + | |
908 dbg_typemask + | |
909 dbg_USE_UNION_TYPE + | |
910 dbg_valbits + | |
911 dbg_gctypebits); | |
912 } | |
428 | 913 |
914 /* Macros turned into functions for ease of debugging. | |
915 Debuggers don't know about macros! */ | |
916 int dbg_eq (Lisp_Object obj1, Lisp_Object obj2); | |
917 int | |
918 dbg_eq (Lisp_Object obj1, Lisp_Object obj2) | |
919 { | |
920 return EQ (obj1, obj2); | |
921 } | |
922 | |
923 | |
3263 | 924 #ifdef NEW_GC |
3017 | 925 #define DECLARE_FIXED_TYPE_ALLOC(type, structture) struct __foo__ |
926 #else | |
428 | 927 /************************************************************************/ |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
928 /* Fixed-size type macros */ |
428 | 929 /************************************************************************/ |
930 | |
931 /* For fixed-size types that are commonly used, we malloc() large blocks | |
932 of memory at a time and subdivide them into chunks of the correct | |
933 size for an object of that type. This is more efficient than | |
934 malloc()ing each object separately because we save on malloc() time | |
935 and overhead due to the fewer number of malloc()ed blocks, and | |
936 also because we don't need any extra pointers within each object | |
937 to keep them threaded together for GC purposes. For less common | |
938 (and frequently large-size) types, we use lcrecords, which are | |
939 malloc()ed individually and chained together through a pointer | |
940 in the lcrecord header. lcrecords do not need to be fixed-size | |
941 (i.e. two objects of the same type need not have the same size; | |
942 however, the size of a particular object cannot vary dynamically). | |
943 It is also much easier to create a new lcrecord type because no | |
944 additional code needs to be added to alloc.c. Finally, lcrecords | |
945 may be more efficient when there are only a small number of them. | |
946 | |
947 The types that are stored in these large blocks (or "frob blocks") | |
1983 | 948 are cons, all number types except fixnum, compiled-function, symbol, |
949 marker, extent, event, and string. | |
428 | 950 |
951 Note that strings are special in that they are actually stored in | |
952 two parts: a structure containing information about the string, and | |
953 the actual data associated with the string. The former structure | |
954 (a struct Lisp_String) is a fixed-size structure and is managed the | |
955 same way as all the other such types. This structure contains a | |
956 pointer to the actual string data, which is stored in structures of | |
957 type struct string_chars_block. Each string_chars_block consists | |
958 of a pointer to a struct Lisp_String, followed by the data for that | |
440 | 959 string, followed by another pointer to a Lisp_String, followed by |
960 the data for that string, etc. At GC time, the data in these | |
961 blocks is compacted by searching sequentially through all the | |
428 | 962 blocks and compressing out any holes created by unmarked strings. |
963 Strings that are more than a certain size (bigger than the size of | |
964 a string_chars_block, although something like half as big might | |
965 make more sense) are malloc()ed separately and not stored in | |
966 string_chars_blocks. Furthermore, no one string stretches across | |
967 two string_chars_blocks. | |
968 | |
1204 | 969 Vectors are each malloc()ed separately as lcrecords. |
428 | 970 |
971 In the following discussion, we use conses, but it applies equally | |
972 well to the other fixed-size types. | |
973 | |
974 We store cons cells inside of cons_blocks, allocating a new | |
975 cons_block with malloc() whenever necessary. Cons cells reclaimed | |
976 by GC are put on a free list to be reallocated before allocating | |
977 any new cons cells from the latest cons_block. Each cons_block is | |
978 just under 2^n - MALLOC_OVERHEAD bytes long, since malloc (at least | |
979 the versions in malloc.c and gmalloc.c) really allocates in units | |
980 of powers of two and uses 4 bytes for its own overhead. | |
981 | |
982 What GC actually does is to search through all the cons_blocks, | |
983 from the most recently allocated to the oldest, and put all | |
984 cons cells that are not marked (whether or not they're already | |
985 free) on a cons_free_list. The cons_free_list is a stack, and | |
986 so the cons cells in the oldest-allocated cons_block end up | |
987 at the head of the stack and are the first to be reallocated. | |
988 If any cons_block is entirely free, it is freed with free() | |
989 and its cons cells removed from the cons_free_list. Because | |
990 the cons_free_list ends up basically in memory order, we have | |
991 a high locality of reference (assuming a reasonable turnover | |
992 of allocating and freeing) and have a reasonable probability | |
993 of entirely freeing up cons_blocks that have been more recently | |
994 allocated. This stage is called the "sweep stage" of GC, and | |
995 is executed after the "mark stage", which involves starting | |
996 from all places that are known to point to in-use Lisp objects | |
997 (e.g. the obarray, where are all symbols are stored; the | |
998 current catches and condition-cases; the backtrace list of | |
999 currently executing functions; the gcpro list; etc.) and | |
1000 recursively marking all objects that are accessible. | |
1001 | |
454 | 1002 At the beginning of the sweep stage, the conses in the cons blocks |
1003 are in one of three states: in use and marked, in use but not | |
1004 marked, and not in use (already freed). Any conses that are marked | |
1005 have been marked in the mark stage just executed, because as part | |
1006 of the sweep stage we unmark any marked objects. The way we tell | |
1007 whether or not a cons cell is in use is through the LRECORD_FREE_P | |
1008 macro. This uses a special lrecord type `lrecord_type_free', | |
1009 which is never associated with any valid object. | |
1010 | |
1011 Conses on the free_cons_list are threaded through a pointer stored | |
1012 in the conses themselves. Because the cons is still in a | |
1013 cons_block and needs to remain marked as not in use for the next | |
1014 time that GC happens, we need room to store both the "free" | |
1015 indicator and the chaining pointer. So this pointer is stored | |
1016 after the lrecord header (actually where C places a pointer after | |
1017 the lrecord header; they are not necessarily contiguous). This | |
1018 implies that all fixed-size types must be big enough to contain at | |
1019 least one pointer. This is true for all current fixed-size types, | |
1020 with the possible exception of Lisp_Floats, for which we define the | |
1021 meat of the struct using a union of a pointer and a double to | |
1022 ensure adequate space for the free list chain pointer. | |
428 | 1023 |
1024 Some types of objects need additional "finalization" done | |
1025 when an object is converted from in use to not in use; | |
1026 this is the purpose of the ADDITIONAL_FREE_type macro. | |
1027 For example, markers need to be removed from the chain | |
1028 of markers that is kept in each buffer. This is because | |
1029 markers in a buffer automatically disappear if the marker | |
1030 is no longer referenced anywhere (the same does not | |
1031 apply to extents, however). | |
1032 | |
1033 WARNING: Things are in an extremely bizarre state when | |
1034 the ADDITIONAL_FREE_type macros are called, so beware! | |
1035 | |
454 | 1036 When ERROR_CHECK_GC is defined, we do things differently so as to |
1037 maximize our chances of catching places where there is insufficient | |
1038 GCPROing. The thing we want to avoid is having an object that | |
1039 we're using but didn't GCPRO get freed by GC and then reallocated | |
1040 while we're in the process of using it -- this will result in | |
1041 something seemingly unrelated getting trashed, and is extremely | |
1042 difficult to track down. If the object gets freed but not | |
1043 reallocated, we can usually catch this because we set most of the | |
1044 bytes of a freed object to 0xDEADBEEF. (The lisp object type is set | |
1045 to the invalid type `lrecord_type_free', however, and a pointer | |
1046 used to chain freed objects together is stored after the lrecord | |
1047 header; we play some tricks with this pointer to make it more | |
428 | 1048 bogus, so crashes are more likely to occur right away.) |
1049 | |
1050 We want freed objects to stay free as long as possible, | |
1051 so instead of doing what we do above, we maintain the | |
1052 free objects in a first-in first-out queue. We also | |
1053 don't recompute the free list each GC, unlike above; | |
1054 this ensures that the queue ordering is preserved. | |
1055 [This means that we are likely to have worse locality | |
1056 of reference, and that we can never free a frob block | |
1057 once it's allocated. (Even if we know that all cells | |
1058 in it are free, there's no easy way to remove all those | |
1059 cells from the free list because the objects on the | |
1060 free list are unlikely to be in memory order.)] | |
1061 Furthermore, we never take objects off the free list | |
1062 unless there's a large number (usually 1000, but | |
1063 varies depending on type) of them already on the list. | |
1064 This way, we ensure that an object that gets freed will | |
1065 remain free for the next 1000 (or whatever) times that | |
440 | 1066 an object of that type is allocated. */ |
428 | 1067 |
1068 #ifdef ALLOC_NO_POOLS | |
1069 # define TYPE_ALLOC_SIZE(type, structtype) 1 | |
1070 #else | |
1071 # define TYPE_ALLOC_SIZE(type, structtype) \ | |
1072 ((2048 - MALLOC_OVERHEAD - sizeof (struct type##_block *)) \ | |
1073 / sizeof (structtype)) | |
1074 #endif /* ALLOC_NO_POOLS */ | |
1075 | |
1076 #define DECLARE_FIXED_TYPE_ALLOC(type, structtype) \ | |
1077 \ | |
1078 struct type##_block \ | |
1079 { \ | |
1080 struct type##_block *prev; \ | |
1081 structtype block[TYPE_ALLOC_SIZE (type, structtype)]; \ | |
1082 }; \ | |
1083 \ | |
1084 static struct type##_block *current_##type##_block; \ | |
1085 static int current_##type##_block_index; \ | |
1086 \ | |
454 | 1087 static Lisp_Free *type##_free_list; \ |
1088 static Lisp_Free *type##_free_list_tail; \ | |
428 | 1089 \ |
1090 static void \ | |
1091 init_##type##_alloc (void) \ | |
1092 { \ | |
1093 current_##type##_block = 0; \ | |
1094 current_##type##_block_index = \ | |
1095 countof (current_##type##_block->block); \ | |
1096 type##_free_list = 0; \ | |
1097 type##_free_list_tail = 0; \ | |
1098 } \ | |
1099 \ | |
1100 static int gc_count_num_##type##_in_use; \ | |
1101 static int gc_count_num_##type##_freelist | |
1102 | |
1103 #define ALLOCATE_FIXED_TYPE_FROM_BLOCK(type, result) do { \ | |
1104 if (current_##type##_block_index \ | |
1105 == countof (current_##type##_block->block)) \ | |
1106 { \ | |
1107 struct type##_block *AFTFB_new = (struct type##_block *) \ | |
1108 allocate_lisp_storage (sizeof (struct type##_block)); \ | |
1109 AFTFB_new->prev = current_##type##_block; \ | |
1110 current_##type##_block = AFTFB_new; \ | |
1111 current_##type##_block_index = 0; \ | |
1112 } \ | |
1113 (result) = \ | |
1114 &(current_##type##_block->block[current_##type##_block_index++]); \ | |
1115 } while (0) | |
1116 | |
1117 /* Allocate an instance of a type that is stored in blocks. | |
1118 TYPE is the "name" of the type, STRUCTTYPE is the corresponding | |
1119 structure type. */ | |
1120 | |
1121 #ifdef ERROR_CHECK_GC | |
1122 | |
1123 /* Note: if you get crashes in this function, suspect incorrect calls | |
1124 to free_cons() and friends. This happened once because the cons | |
1125 cell was not GC-protected and was getting collected before | |
1126 free_cons() was called. */ | |
1127 | |
454 | 1128 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) do { \ |
1129 if (gc_count_num_##type##_freelist > \ | |
1130 MINIMUM_ALLOWED_FIXED_TYPE_CELLS_##type) \ | |
1131 { \ | |
1132 result = (structtype *) type##_free_list; \ | |
1204 | 1133 assert (LRECORD_FREE_P (result)); \ |
1134 /* Before actually using the chain pointer, we complement \ | |
1135 all its bits; see PUT_FIXED_TYPE_ON_FREE_LIST(). */ \ | |
454 | 1136 type##_free_list = (Lisp_Free *) \ |
1137 (~ (EMACS_UINT) (type##_free_list->chain)); \ | |
1138 gc_count_num_##type##_freelist--; \ | |
1139 } \ | |
1140 else \ | |
1141 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \ | |
1142 MARK_LRECORD_AS_NOT_FREE (result); \ | |
428 | 1143 } while (0) |
1144 | |
1145 #else /* !ERROR_CHECK_GC */ | |
1146 | |
454 | 1147 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) do { \ |
428 | 1148 if (type##_free_list) \ |
1149 { \ | |
454 | 1150 result = (structtype *) type##_free_list; \ |
1151 type##_free_list = type##_free_list->chain; \ | |
428 | 1152 } \ |
1153 else \ | |
1154 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \ | |
454 | 1155 MARK_LRECORD_AS_NOT_FREE (result); \ |
428 | 1156 } while (0) |
1157 | |
1158 #endif /* !ERROR_CHECK_GC */ | |
1159 | |
454 | 1160 |
428 | 1161 #define ALLOCATE_FIXED_TYPE(type, structtype, result) \ |
1162 do \ | |
1163 { \ | |
1164 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \ | |
1165 INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \ | |
1166 } while (0) | |
1167 | |
1168 #define NOSEEUM_ALLOCATE_FIXED_TYPE(type, structtype, result) \ | |
1169 do \ | |
1170 { \ | |
1171 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \ | |
1172 NOSEEUM_INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \ | |
1173 } while (0) | |
1174 | |
454 | 1175 /* Lisp_Free is the type to represent a free list member inside a frob |
1176 block of any lisp object type. */ | |
1177 typedef struct Lisp_Free | |
1178 { | |
1179 struct lrecord_header lheader; | |
1180 struct Lisp_Free *chain; | |
1181 } Lisp_Free; | |
1182 | |
1183 #define LRECORD_FREE_P(ptr) \ | |
771 | 1184 (((struct lrecord_header *) ptr)->type == lrecord_type_free) |
454 | 1185 |
1186 #define MARK_LRECORD_AS_FREE(ptr) \ | |
771 | 1187 ((void) (((struct lrecord_header *) ptr)->type = lrecord_type_free)) |
454 | 1188 |
1189 #ifdef ERROR_CHECK_GC | |
1190 #define MARK_LRECORD_AS_NOT_FREE(ptr) \ | |
771 | 1191 ((void) (((struct lrecord_header *) ptr)->type = lrecord_type_undefined)) |
428 | 1192 #else |
454 | 1193 #define MARK_LRECORD_AS_NOT_FREE(ptr) DO_NOTHING |
428 | 1194 #endif |
1195 | |
1196 #ifdef ERROR_CHECK_GC | |
1197 | |
454 | 1198 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) do { \ |
1199 if (type##_free_list_tail) \ | |
1200 { \ | |
1201 /* When we store the chain pointer, we complement all \ | |
1202 its bits; this should significantly increase its \ | |
1203 bogosity in case someone tries to use the value, and \ | |
1204 should make us crash faster if someone overwrites the \ | |
1205 pointer because when it gets un-complemented in \ | |
1206 ALLOCATED_FIXED_TYPE(), the resulting pointer will be \ | |
1207 extremely bogus. */ \ | |
1208 type##_free_list_tail->chain = \ | |
1209 (Lisp_Free *) ~ (EMACS_UINT) (ptr); \ | |
1210 } \ | |
1211 else \ | |
1212 type##_free_list = (Lisp_Free *) (ptr); \ | |
1213 type##_free_list_tail = (Lisp_Free *) (ptr); \ | |
1214 } while (0) | |
428 | 1215 |
1216 #else /* !ERROR_CHECK_GC */ | |
1217 | |
454 | 1218 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) do { \ |
1219 ((Lisp_Free *) (ptr))->chain = type##_free_list; \ | |
1220 type##_free_list = (Lisp_Free *) (ptr); \ | |
1221 } while (0) \ | |
428 | 1222 |
1223 #endif /* !ERROR_CHECK_GC */ | |
1224 | |
1225 /* TYPE and STRUCTTYPE are the same as in ALLOCATE_FIXED_TYPE(). */ | |
1226 | |
1227 #define FREE_FIXED_TYPE(type, structtype, ptr) do { \ | |
1228 structtype *FFT_ptr = (ptr); \ | |
1204 | 1229 gc_checking_assert (!LRECORD_FREE_P (FFT_ptr)); \ |
2367 | 1230 gc_checking_assert (!DUMPEDP (FFT_ptr)); \ |
428 | 1231 ADDITIONAL_FREE_##type (FFT_ptr); \ |
1232 deadbeef_memory (FFT_ptr, sizeof (structtype)); \ | |
1233 PUT_FIXED_TYPE_ON_FREE_LIST (type, structtype, FFT_ptr); \ | |
454 | 1234 MARK_LRECORD_AS_FREE (FFT_ptr); \ |
428 | 1235 } while (0) |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1236 #endif /* NEW_GC */ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1237 |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1238 #ifdef NEW_GC |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1239 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(lo, type, structtype, ptr) \ |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1240 free_normal_lisp_object (lo) |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1241 #else /* not NEW_GC */ |
428 | 1242 /* Like FREE_FIXED_TYPE() but used when we are explicitly |
1243 freeing a structure through free_cons(), free_marker(), etc. | |
1244 rather than through the normal process of sweeping. | |
1245 We attempt to undo the changes made to the allocation counters | |
1246 as a result of this structure being allocated. This is not | |
1247 completely necessary but helps keep things saner: e.g. this way, | |
1248 repeatedly allocating and freeing a cons will not result in | |
1249 the consing-since-gc counter advancing, which would cause a GC | |
1204 | 1250 and somewhat defeat the purpose of explicitly freeing. |
1251 | |
1252 We also disable this mechanism entirely when ALLOC_NO_POOLS is | |
1253 set, which is used for Purify and the like. */ | |
1254 | |
1255 #ifndef ALLOC_NO_POOLS | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1256 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(lo, type, structtype, ptr) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1257 do { FREE_FIXED_TYPE (type, structtype, ptr); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1258 DECREMENT_CONS_COUNTER (sizeof (structtype)); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1259 gc_count_num_##type##_freelist++; \ |
428 | 1260 } while (0) |
1204 | 1261 #else |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1262 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(lo, type, structtype, ptr) |
1204 | 1263 #endif |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1264 #endif /* (not) NEW_GC */ |
3263 | 1265 |
1266 #ifdef NEW_GC | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1267 #define ALLOC_FROB_BLOCK_LISP_OBJECT(type, lisp_type, var, lrec_ptr)\ |
3017 | 1268 do { \ |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1269 (var) = (lisp_type *) XPNTR (ALLOC_NORMAL_LISP_OBJECT (type)); \ |
3017 | 1270 } while (0) |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1271 #define NOSEEUM_ALLOC_FROB_BLOCK_LISP_OBJECT(type, lisp_type, var, \ |
3017 | 1272 lrec_ptr) \ |
1273 do { \ | |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1274 (var) = (lisp_type *) XPNTR (noseeum_alloc_lrecord (lrec_ptr)); \ |
3017 | 1275 } while (0) |
3263 | 1276 #else /* not NEW_GC */ |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1277 #define ALLOC_FROB_BLOCK_LISP_OBJECT(type, lisp_type, var, lrec_ptr) \ |
3017 | 1278 do \ |
1279 { \ | |
1280 ALLOCATE_FIXED_TYPE (type, lisp_type, var); \ | |
1281 set_lheader_implementation (&(var)->lheader, lrec_ptr); \ | |
1282 } while (0) | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1283 #define NOSEEUM_ALLOC_FROB_BLOCK_LISP_OBJECT(type, lisp_type, var, \ |
3017 | 1284 lrec_ptr) \ |
1285 do \ | |
1286 { \ | |
1287 NOSEEUM_ALLOCATE_FIXED_TYPE (type, lisp_type, var); \ | |
1288 set_lheader_implementation (&(var)->lheader, lrec_ptr); \ | |
1289 } while (0) | |
3263 | 1290 #endif /* not NEW_GC */ |
3017 | 1291 |
428 | 1292 |
1293 | |
1294 /************************************************************************/ | |
1295 /* Cons allocation */ | |
1296 /************************************************************************/ | |
1297 | |
440 | 1298 DECLARE_FIXED_TYPE_ALLOC (cons, Lisp_Cons); |
428 | 1299 /* conses are used and freed so often that we set this really high */ |
1300 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 20000 */ | |
1301 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 2000 | |
1302 | |
1303 static Lisp_Object | |
1304 mark_cons (Lisp_Object obj) | |
1305 { | |
1306 if (NILP (XCDR (obj))) | |
1307 return XCAR (obj); | |
1308 | |
1309 mark_object (XCAR (obj)); | |
1310 return XCDR (obj); | |
1311 } | |
1312 | |
1313 static int | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1314 cons_equal (Lisp_Object ob1, Lisp_Object ob2, int depth, int foldcase) |
428 | 1315 { |
442 | 1316 depth++; |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1317 while (internal_equal_0 (XCAR (ob1), XCAR (ob2), depth, foldcase)) |
428 | 1318 { |
1319 ob1 = XCDR (ob1); | |
1320 ob2 = XCDR (ob2); | |
1321 if (! CONSP (ob1) || ! CONSP (ob2)) | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1322 return internal_equal_0 (ob1, ob2, depth, foldcase); |
428 | 1323 } |
1324 return 0; | |
1325 } | |
1326 | |
1204 | 1327 static const struct memory_description cons_description[] = { |
853 | 1328 { XD_LISP_OBJECT, offsetof (Lisp_Cons, car_) }, |
1329 { XD_LISP_OBJECT, offsetof (Lisp_Cons, cdr_) }, | |
428 | 1330 { XD_END } |
1331 }; | |
1332 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1333 DEFINE_DUMPABLE_FROB_BLOCK_LISP_OBJECT ("cons", cons, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1334 mark_cons, print_cons, 0, cons_equal, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1335 /* |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1336 * No `hash' method needed. |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1337 * internal_hash knows how to |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1338 * handle conses. |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1339 */ |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1340 0, cons_description, Lisp_Cons); |
428 | 1341 |
1342 DEFUN ("cons", Fcons, 2, 2, 0, /* | |
3355 | 1343 Create a new cons cell, give it CAR and CDR as components, and return it. |
1344 | |
1345 A cons cell is a Lisp object (an area in memory) made up of two pointers | |
1346 called the CAR and the CDR. Each of these pointers can point to any other | |
1347 Lisp object. The common Lisp data type, the list, is a specially-structured | |
1348 series of cons cells. | |
1349 | |
1350 The pointers are accessed from Lisp with `car' and `cdr', and mutated with | |
1351 `setcar' and `setcdr' respectively. For historical reasons, the aliases | |
1352 `rplaca' and `rplacd' (for `setcar' and `setcdr') are supported. | |
428 | 1353 */ |
1354 (car, cdr)) | |
1355 { | |
1356 /* This cannot GC. */ | |
1357 Lisp_Object val; | |
440 | 1358 Lisp_Cons *c; |
1359 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1360 ALLOC_FROB_BLOCK_LISP_OBJECT (cons, Lisp_Cons, c, &lrecord_cons); |
793 | 1361 val = wrap_cons (c); |
853 | 1362 XSETCAR (val, car); |
1363 XSETCDR (val, cdr); | |
428 | 1364 return val; |
1365 } | |
1366 | |
1367 /* This is identical to Fcons() but it used for conses that we're | |
1368 going to free later, and is useful when trying to track down | |
1369 "real" consing. */ | |
1370 Lisp_Object | |
1371 noseeum_cons (Lisp_Object car, Lisp_Object cdr) | |
1372 { | |
1373 Lisp_Object val; | |
440 | 1374 Lisp_Cons *c; |
1375 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1376 NOSEEUM_ALLOC_FROB_BLOCK_LISP_OBJECT (cons, Lisp_Cons, c, &lrecord_cons); |
793 | 1377 val = wrap_cons (c); |
428 | 1378 XCAR (val) = car; |
1379 XCDR (val) = cdr; | |
1380 return val; | |
1381 } | |
1382 | |
1383 DEFUN ("list", Flist, 0, MANY, 0, /* | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1384 Return a newly created list with specified ARGS as elements. |
428 | 1385 Any number of arguments, even zero arguments, are allowed. |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1386 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1387 arguments: (&rest ARGS) |
428 | 1388 */ |
1389 (int nargs, Lisp_Object *args)) | |
1390 { | |
1391 Lisp_Object val = Qnil; | |
1392 Lisp_Object *argp = args + nargs; | |
1393 | |
1394 while (argp > args) | |
1395 val = Fcons (*--argp, val); | |
1396 return val; | |
1397 } | |
1398 | |
1399 Lisp_Object | |
1400 list1 (Lisp_Object obj0) | |
1401 { | |
1402 /* This cannot GC. */ | |
1403 return Fcons (obj0, Qnil); | |
1404 } | |
1405 | |
1406 Lisp_Object | |
1407 list2 (Lisp_Object obj0, Lisp_Object obj1) | |
1408 { | |
1409 /* This cannot GC. */ | |
1410 return Fcons (obj0, Fcons (obj1, Qnil)); | |
1411 } | |
1412 | |
1413 Lisp_Object | |
1414 list3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2) | |
1415 { | |
1416 /* This cannot GC. */ | |
1417 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Qnil))); | |
1418 } | |
1419 | |
1420 Lisp_Object | |
1421 cons3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2) | |
1422 { | |
1423 /* This cannot GC. */ | |
1424 return Fcons (obj0, Fcons (obj1, obj2)); | |
1425 } | |
1426 | |
1427 Lisp_Object | |
1428 acons (Lisp_Object key, Lisp_Object value, Lisp_Object alist) | |
1429 { | |
1430 return Fcons (Fcons (key, value), alist); | |
1431 } | |
1432 | |
1433 Lisp_Object | |
1434 list4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3) | |
1435 { | |
1436 /* This cannot GC. */ | |
1437 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Qnil)))); | |
1438 } | |
1439 | |
1440 Lisp_Object | |
1441 list5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3, | |
1442 Lisp_Object obj4) | |
1443 { | |
1444 /* This cannot GC. */ | |
1445 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Fcons (obj4, Qnil))))); | |
1446 } | |
1447 | |
1448 Lisp_Object | |
1449 list6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3, | |
1450 Lisp_Object obj4, Lisp_Object obj5) | |
1451 { | |
1452 /* This cannot GC. */ | |
1453 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Fcons (obj4, Fcons (obj5, Qnil)))))); | |
1454 } | |
1455 | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1456 /* Return a list of arbitrary length, terminated by Qunbound. */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1457 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1458 Lisp_Object |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1459 listu (Lisp_Object first, ...) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1460 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1461 Lisp_Object obj = Qnil; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1462 Lisp_Object val; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1463 va_list va; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1464 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1465 va_start (va, first); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1466 val = first; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1467 while (!UNBOUNDP (val)) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1468 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1469 obj = Fcons (val, obj); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1470 val = va_arg (va, Lisp_Object); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1471 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1472 va_end (va); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1473 return Fnreverse (obj); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1474 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1475 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1476 /* Return a list of arbitrary length, with length specified and remaining |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1477 args making up the list. */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1478 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1479 Lisp_Object |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1480 listn (int num_args, ...) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1481 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1482 int i; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1483 Lisp_Object obj = Qnil; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1484 va_list va; |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1485 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1486 va_start (va, num_args); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1487 for (i = 0; i < num_args; i++) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1488 obj = Fcons (va_arg (va, Lisp_Object), obj); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1489 va_end (va); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1490 return Fnreverse (obj); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1491 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1492 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1493 /* Return a list of arbitrary length, with length specified and an array |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1494 of elements. */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1495 |
428 | 1496 DEFUN ("make-list", Fmake_list, 2, 2, 0, /* |
444 | 1497 Return a new list of length LENGTH, with each element being OBJECT. |
428 | 1498 */ |
444 | 1499 (length, object)) |
428 | 1500 { |
1501 CHECK_NATNUM (length); | |
1502 | |
1503 { | |
1504 Lisp_Object val = Qnil; | |
647 | 1505 EMACS_INT size = XINT (length); |
428 | 1506 |
1507 while (size--) | |
444 | 1508 val = Fcons (object, val); |
428 | 1509 return val; |
1510 } | |
1511 } | |
1512 | |
1513 | |
1514 /************************************************************************/ | |
1515 /* Float allocation */ | |
1516 /************************************************************************/ | |
1517 | |
1983 | 1518 /*** With enhanced number support, these are short floats */ |
1519 | |
440 | 1520 DECLARE_FIXED_TYPE_ALLOC (float, Lisp_Float); |
428 | 1521 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_float 1000 |
1522 | |
1523 Lisp_Object | |
1524 make_float (double float_value) | |
1525 { | |
440 | 1526 Lisp_Float *f; |
1527 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1528 ALLOC_FROB_BLOCK_LISP_OBJECT (float, Lisp_Float, f, &lrecord_float); |
440 | 1529 |
1530 /* Avoid dump-time `uninitialized memory read' purify warnings. */ | |
1531 if (sizeof (struct lrecord_header) + sizeof (double) != sizeof (*f)) | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1532 zero_nonsized_lisp_object (wrap_float (f)); |
3017 | 1533 |
428 | 1534 float_data (f) = float_value; |
793 | 1535 return wrap_float (f); |
428 | 1536 } |
1537 | |
1538 | |
1539 /************************************************************************/ | |
1983 | 1540 /* Enhanced number allocation */ |
1541 /************************************************************************/ | |
1542 | |
1543 /*** Bignum ***/ | |
1544 #ifdef HAVE_BIGNUM | |
1545 DECLARE_FIXED_TYPE_ALLOC (bignum, Lisp_Bignum); | |
1546 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bignum 250 | |
1547 | |
1548 /* WARNING: This function returns a bignum even if its argument fits into a | |
1549 fixnum. See Fcanonicalize_number(). */ | |
1550 Lisp_Object | |
1551 make_bignum (long bignum_value) | |
1552 { | |
1553 Lisp_Bignum *b; | |
1554 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1555 ALLOC_FROB_BLOCK_LISP_OBJECT (bignum, Lisp_Bignum, b, &lrecord_bignum); |
1983 | 1556 bignum_init (bignum_data (b)); |
1557 bignum_set_long (bignum_data (b), bignum_value); | |
1558 return wrap_bignum (b); | |
1559 } | |
1560 | |
1561 /* WARNING: This function returns a bignum even if its argument fits into a | |
1562 fixnum. See Fcanonicalize_number(). */ | |
1563 Lisp_Object | |
1564 make_bignum_bg (bignum bg) | |
1565 { | |
1566 Lisp_Bignum *b; | |
1567 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1568 ALLOC_FROB_BLOCK_LISP_OBJECT (bignum, Lisp_Bignum, b, &lrecord_bignum); |
1983 | 1569 bignum_init (bignum_data (b)); |
1570 bignum_set (bignum_data (b), bg); | |
1571 return wrap_bignum (b); | |
1572 } | |
1573 #endif /* HAVE_BIGNUM */ | |
1574 | |
1575 /*** Ratio ***/ | |
1576 #ifdef HAVE_RATIO | |
1577 DECLARE_FIXED_TYPE_ALLOC (ratio, Lisp_Ratio); | |
1578 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_ratio 250 | |
1579 | |
1580 Lisp_Object | |
1581 make_ratio (long numerator, unsigned long denominator) | |
1582 { | |
1583 Lisp_Ratio *r; | |
1584 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1585 ALLOC_FROB_BLOCK_LISP_OBJECT (ratio, Lisp_Ratio, r, &lrecord_ratio); |
1983 | 1586 ratio_init (ratio_data (r)); |
1587 ratio_set_long_ulong (ratio_data (r), numerator, denominator); | |
1588 ratio_canonicalize (ratio_data (r)); | |
1589 return wrap_ratio (r); | |
1590 } | |
1591 | |
1592 Lisp_Object | |
1593 make_ratio_bg (bignum numerator, bignum denominator) | |
1594 { | |
1595 Lisp_Ratio *r; | |
1596 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1597 ALLOC_FROB_BLOCK_LISP_OBJECT (ratio, Lisp_Ratio, r, &lrecord_ratio); |
1983 | 1598 ratio_init (ratio_data (r)); |
1599 ratio_set_bignum_bignum (ratio_data (r), numerator, denominator); | |
1600 ratio_canonicalize (ratio_data (r)); | |
1601 return wrap_ratio (r); | |
1602 } | |
1603 | |
1604 Lisp_Object | |
1605 make_ratio_rt (ratio rat) | |
1606 { | |
1607 Lisp_Ratio *r; | |
1608 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1609 ALLOC_FROB_BLOCK_LISP_OBJECT (ratio, Lisp_Ratio, r, &lrecord_ratio); |
1983 | 1610 ratio_init (ratio_data (r)); |
1611 ratio_set (ratio_data (r), rat); | |
1612 return wrap_ratio (r); | |
1613 } | |
1614 #endif /* HAVE_RATIO */ | |
1615 | |
1616 /*** Bigfloat ***/ | |
1617 #ifdef HAVE_BIGFLOAT | |
1618 DECLARE_FIXED_TYPE_ALLOC (bigfloat, Lisp_Bigfloat); | |
1619 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bigfloat 250 | |
1620 | |
1621 /* This function creates a bigfloat with the default precision if the | |
1622 PRECISION argument is zero. */ | |
1623 Lisp_Object | |
1624 make_bigfloat (double float_value, unsigned long precision) | |
1625 { | |
1626 Lisp_Bigfloat *f; | |
1627 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1628 ALLOC_FROB_BLOCK_LISP_OBJECT (bigfloat, Lisp_Bigfloat, f, &lrecord_bigfloat); |
1983 | 1629 if (precision == 0UL) |
1630 bigfloat_init (bigfloat_data (f)); | |
1631 else | |
1632 bigfloat_init_prec (bigfloat_data (f), precision); | |
1633 bigfloat_set_double (bigfloat_data (f), float_value); | |
1634 return wrap_bigfloat (f); | |
1635 } | |
1636 | |
1637 /* This function creates a bigfloat with the precision of its argument */ | |
1638 Lisp_Object | |
1639 make_bigfloat_bf (bigfloat float_value) | |
1640 { | |
1641 Lisp_Bigfloat *f; | |
1642 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1643 ALLOC_FROB_BLOCK_LISP_OBJECT (bigfloat, Lisp_Bigfloat, f, &lrecord_bigfloat); |
1983 | 1644 bigfloat_init_prec (bigfloat_data (f), bigfloat_get_prec (float_value)); |
1645 bigfloat_set (bigfloat_data (f), float_value); | |
1646 return wrap_bigfloat (f); | |
1647 } | |
1648 #endif /* HAVE_BIGFLOAT */ | |
1649 | |
1650 /************************************************************************/ | |
428 | 1651 /* Vector allocation */ |
1652 /************************************************************************/ | |
1653 | |
1654 static Lisp_Object | |
1655 mark_vector (Lisp_Object obj) | |
1656 { | |
1657 Lisp_Vector *ptr = XVECTOR (obj); | |
1658 int len = vector_length (ptr); | |
1659 int i; | |
1660 | |
1661 for (i = 0; i < len - 1; i++) | |
1662 mark_object (ptr->contents[i]); | |
1663 return (len > 0) ? ptr->contents[len - 1] : Qnil; | |
1664 } | |
1665 | |
665 | 1666 static Bytecount |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1667 size_vector (Lisp_Object obj) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1668 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1669 |
456 | 1670 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object, contents, |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1671 XVECTOR (obj)->size); |
428 | 1672 } |
1673 | |
1674 static int | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1675 vector_equal (Lisp_Object obj1, Lisp_Object obj2, int depth, int foldcase) |
428 | 1676 { |
1677 int len = XVECTOR_LENGTH (obj1); | |
1678 if (len != XVECTOR_LENGTH (obj2)) | |
1679 return 0; | |
1680 | |
1681 { | |
1682 Lisp_Object *ptr1 = XVECTOR_DATA (obj1); | |
1683 Lisp_Object *ptr2 = XVECTOR_DATA (obj2); | |
1684 while (len--) | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1685 if (!internal_equal_0 (*ptr1++, *ptr2++, depth + 1, foldcase)) |
428 | 1686 return 0; |
1687 } | |
1688 return 1; | |
1689 } | |
1690 | |
665 | 1691 static Hashcode |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5179
diff
changeset
|
1692 vector_hash (Lisp_Object obj, int depth, Boolint equalp) |
442 | 1693 { |
1694 return HASH2 (XVECTOR_LENGTH (obj), | |
1695 internal_array_hash (XVECTOR_DATA (obj), | |
1696 XVECTOR_LENGTH (obj), | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5179
diff
changeset
|
1697 depth + 1, equalp)); |
442 | 1698 } |
1699 | |
1204 | 1700 static const struct memory_description vector_description[] = { |
440 | 1701 { XD_LONG, offsetof (Lisp_Vector, size) }, |
1702 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Vector, contents), XD_INDIRECT(0, 0) }, | |
428 | 1703 { XD_END } |
1704 }; | |
1705 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1706 DEFINE_DUMPABLE_SIZABLE_LISP_OBJECT ("vector", vector, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1707 mark_vector, print_vector, 0, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1708 vector_equal, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1709 vector_hash, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1710 vector_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1711 size_vector, Lisp_Vector); |
428 | 1712 /* #### should allocate `small' vectors from a frob-block */ |
1713 static Lisp_Vector * | |
665 | 1714 make_vector_internal (Elemcount sizei) |
428 | 1715 { |
1204 | 1716 /* no `next' field; we use lcrecords */ |
665 | 1717 Bytecount sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object, |
1204 | 1718 contents, sizei); |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1719 Lisp_Object obj = ALLOC_SIZED_LISP_OBJECT (sizem, vector); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1720 Lisp_Vector *p = XVECTOR (obj); |
428 | 1721 |
1722 p->size = sizei; | |
1723 return p; | |
1724 } | |
1725 | |
1726 Lisp_Object | |
665 | 1727 make_vector (Elemcount length, Lisp_Object object) |
428 | 1728 { |
1729 Lisp_Vector *vecp = make_vector_internal (length); | |
1730 Lisp_Object *p = vector_data (vecp); | |
1731 | |
1732 while (length--) | |
444 | 1733 *p++ = object; |
428 | 1734 |
793 | 1735 return wrap_vector (vecp); |
428 | 1736 } |
1737 | |
1738 DEFUN ("make-vector", Fmake_vector, 2, 2, 0, /* | |
444 | 1739 Return a new vector of length LENGTH, with each element being OBJECT. |
428 | 1740 See also the function `vector'. |
1741 */ | |
444 | 1742 (length, object)) |
428 | 1743 { |
1744 CONCHECK_NATNUM (length); | |
444 | 1745 return make_vector (XINT (length), object); |
428 | 1746 } |
1747 | |
1748 DEFUN ("vector", Fvector, 0, MANY, 0, /* | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1749 Return a newly created vector with specified ARGS as elements. |
428 | 1750 Any number of arguments, even zero arguments, are allowed. |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1751 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1752 arguments: (&rest ARGS) |
428 | 1753 */ |
1754 (int nargs, Lisp_Object *args)) | |
1755 { | |
1756 Lisp_Vector *vecp = make_vector_internal (nargs); | |
1757 Lisp_Object *p = vector_data (vecp); | |
1758 | |
1759 while (nargs--) | |
1760 *p++ = *args++; | |
1761 | |
793 | 1762 return wrap_vector (vecp); |
428 | 1763 } |
1764 | |
1765 Lisp_Object | |
1766 vector1 (Lisp_Object obj0) | |
1767 { | |
1768 return Fvector (1, &obj0); | |
1769 } | |
1770 | |
1771 Lisp_Object | |
1772 vector2 (Lisp_Object obj0, Lisp_Object obj1) | |
1773 { | |
1774 Lisp_Object args[2]; | |
1775 args[0] = obj0; | |
1776 args[1] = obj1; | |
1777 return Fvector (2, args); | |
1778 } | |
1779 | |
1780 Lisp_Object | |
1781 vector3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2) | |
1782 { | |
1783 Lisp_Object args[3]; | |
1784 args[0] = obj0; | |
1785 args[1] = obj1; | |
1786 args[2] = obj2; | |
1787 return Fvector (3, args); | |
1788 } | |
1789 | |
1790 #if 0 /* currently unused */ | |
1791 | |
1792 Lisp_Object | |
1793 vector4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1794 Lisp_Object obj3) | |
1795 { | |
1796 Lisp_Object args[4]; | |
1797 args[0] = obj0; | |
1798 args[1] = obj1; | |
1799 args[2] = obj2; | |
1800 args[3] = obj3; | |
1801 return Fvector (4, args); | |
1802 } | |
1803 | |
1804 Lisp_Object | |
1805 vector5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1806 Lisp_Object obj3, Lisp_Object obj4) | |
1807 { | |
1808 Lisp_Object args[5]; | |
1809 args[0] = obj0; | |
1810 args[1] = obj1; | |
1811 args[2] = obj2; | |
1812 args[3] = obj3; | |
1813 args[4] = obj4; | |
1814 return Fvector (5, args); | |
1815 } | |
1816 | |
1817 Lisp_Object | |
1818 vector6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1819 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5) | |
1820 { | |
1821 Lisp_Object args[6]; | |
1822 args[0] = obj0; | |
1823 args[1] = obj1; | |
1824 args[2] = obj2; | |
1825 args[3] = obj3; | |
1826 args[4] = obj4; | |
1827 args[5] = obj5; | |
1828 return Fvector (6, args); | |
1829 } | |
1830 | |
1831 Lisp_Object | |
1832 vector7 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1833 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5, | |
1834 Lisp_Object obj6) | |
1835 { | |
1836 Lisp_Object args[7]; | |
1837 args[0] = obj0; | |
1838 args[1] = obj1; | |
1839 args[2] = obj2; | |
1840 args[3] = obj3; | |
1841 args[4] = obj4; | |
1842 args[5] = obj5; | |
1843 args[6] = obj6; | |
1844 return Fvector (7, args); | |
1845 } | |
1846 | |
1847 Lisp_Object | |
1848 vector8 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1849 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5, | |
1850 Lisp_Object obj6, Lisp_Object obj7) | |
1851 { | |
1852 Lisp_Object args[8]; | |
1853 args[0] = obj0; | |
1854 args[1] = obj1; | |
1855 args[2] = obj2; | |
1856 args[3] = obj3; | |
1857 args[4] = obj4; | |
1858 args[5] = obj5; | |
1859 args[6] = obj6; | |
1860 args[7] = obj7; | |
1861 return Fvector (8, args); | |
1862 } | |
1863 #endif /* unused */ | |
1864 | |
1865 /************************************************************************/ | |
1866 /* Bit Vector allocation */ | |
1867 /************************************************************************/ | |
1868 | |
1869 /* #### should allocate `small' bit vectors from a frob-block */ | |
440 | 1870 static Lisp_Bit_Vector * |
665 | 1871 make_bit_vector_internal (Elemcount sizei) |
428 | 1872 { |
1204 | 1873 /* no `next' field; we use lcrecords */ |
665 | 1874 Elemcount num_longs = BIT_VECTOR_LONG_STORAGE (sizei); |
1875 Bytecount sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Bit_Vector, | |
1204 | 1876 unsigned long, |
1877 bits, num_longs); | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1878 Lisp_Object obj = ALLOC_SIZED_LISP_OBJECT (sizem, bit_vector); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1879 Lisp_Bit_Vector *p = XBIT_VECTOR (obj); |
428 | 1880 |
1881 bit_vector_length (p) = sizei; | |
1882 return p; | |
1883 } | |
1884 | |
1885 Lisp_Object | |
665 | 1886 make_bit_vector (Elemcount length, Lisp_Object bit) |
428 | 1887 { |
440 | 1888 Lisp_Bit_Vector *p = make_bit_vector_internal (length); |
665 | 1889 Elemcount num_longs = BIT_VECTOR_LONG_STORAGE (length); |
428 | 1890 |
444 | 1891 CHECK_BIT (bit); |
1892 | |
1893 if (ZEROP (bit)) | |
428 | 1894 memset (p->bits, 0, num_longs * sizeof (long)); |
1895 else | |
1896 { | |
665 | 1897 Elemcount bits_in_last = length & (LONGBITS_POWER_OF_2 - 1); |
428 | 1898 memset (p->bits, ~0, num_longs * sizeof (long)); |
1899 /* But we have to make sure that the unused bits in the | |
1900 last long are 0, so that equal/hash is easy. */ | |
1901 if (bits_in_last) | |
1902 p->bits[num_longs - 1] &= (1 << bits_in_last) - 1; | |
1903 } | |
1904 | |
793 | 1905 return wrap_bit_vector (p); |
428 | 1906 } |
1907 | |
1908 Lisp_Object | |
665 | 1909 make_bit_vector_from_byte_vector (unsigned char *bytevec, Elemcount length) |
428 | 1910 { |
665 | 1911 Elemcount i; |
428 | 1912 Lisp_Bit_Vector *p = make_bit_vector_internal (length); |
1913 | |
1914 for (i = 0; i < length; i++) | |
1915 set_bit_vector_bit (p, i, bytevec[i]); | |
1916 | |
793 | 1917 return wrap_bit_vector (p); |
428 | 1918 } |
1919 | |
1920 DEFUN ("make-bit-vector", Fmake_bit_vector, 2, 2, 0, /* | |
444 | 1921 Return a new bit vector of length LENGTH. with each bit set to BIT. |
1922 BIT must be one of the integers 0 or 1. See also the function `bit-vector'. | |
428 | 1923 */ |
444 | 1924 (length, bit)) |
428 | 1925 { |
1926 CONCHECK_NATNUM (length); | |
1927 | |
444 | 1928 return make_bit_vector (XINT (length), bit); |
428 | 1929 } |
1930 | |
1931 DEFUN ("bit-vector", Fbit_vector, 0, MANY, 0, /* | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1932 Return a newly created bit vector with specified ARGS as elements. |
428 | 1933 Any number of arguments, even zero arguments, are allowed. |
444 | 1934 Each argument must be one of the integers 0 or 1. |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1935 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1936 arguments: (&rest ARGS) |
428 | 1937 */ |
1938 (int nargs, Lisp_Object *args)) | |
1939 { | |
1940 int i; | |
1941 Lisp_Bit_Vector *p = make_bit_vector_internal (nargs); | |
1942 | |
1943 for (i = 0; i < nargs; i++) | |
1944 { | |
1945 CHECK_BIT (args[i]); | |
1946 set_bit_vector_bit (p, i, !ZEROP (args[i])); | |
1947 } | |
1948 | |
793 | 1949 return wrap_bit_vector (p); |
428 | 1950 } |
1951 | |
1952 | |
1953 /************************************************************************/ | |
1954 /* Compiled-function allocation */ | |
1955 /************************************************************************/ | |
1956 | |
1957 DECLARE_FIXED_TYPE_ALLOC (compiled_function, Lisp_Compiled_Function); | |
1958 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_compiled_function 1000 | |
1959 | |
1960 static Lisp_Object | |
1961 make_compiled_function (void) | |
1962 { | |
1963 Lisp_Compiled_Function *f; | |
1964 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1965 ALLOC_FROB_BLOCK_LISP_OBJECT (compiled_function, Lisp_Compiled_Function, |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1966 f, &lrecord_compiled_function); |
428 | 1967 |
1968 f->stack_depth = 0; | |
1969 f->specpdl_depth = 0; | |
1970 f->flags.documentationp = 0; | |
1971 f->flags.interactivep = 0; | |
1972 f->flags.domainp = 0; /* I18N3 */ | |
1973 f->instructions = Qzero; | |
1974 f->constants = Qzero; | |
1975 f->arglist = Qnil; | |
3092 | 1976 #ifdef NEW_GC |
1977 f->arguments = Qnil; | |
1978 #else /* not NEW_GC */ | |
1739 | 1979 f->args = NULL; |
3092 | 1980 #endif /* not NEW_GC */ |
1739 | 1981 f->max_args = f->min_args = f->args_in_array = 0; |
428 | 1982 f->doc_and_interactive = Qnil; |
1983 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
1984 f->annotated = Qnil; | |
1985 #endif | |
793 | 1986 return wrap_compiled_function (f); |
428 | 1987 } |
1988 | |
1989 DEFUN ("make-byte-code", Fmake_byte_code, 4, MANY, 0, /* | |
1990 Return a new compiled-function object. | |
1991 Note that, unlike all other emacs-lisp functions, calling this with five | |
1992 arguments is NOT the same as calling it with six arguments, the last of | |
1993 which is nil. If the INTERACTIVE arg is specified as nil, then that means | |
1994 that this function was defined with `(interactive)'. If the arg is not | |
1995 specified, then that means the function is not interactive. | |
1996 This is terrible behavior which is retained for compatibility with old | |
1997 `.elc' files which expect these semantics. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1998 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1999 arguments: (ARGLIST INSTRUCTIONS CONSTANTS STACK-DEPTH &optional DOC-STRING INTERACTIVE) |
428 | 2000 */ |
2001 (int nargs, Lisp_Object *args)) | |
2002 { | |
2003 /* In a non-insane world this function would have this arglist... | |
2004 (arglist instructions constants stack_depth &optional doc_string interactive) | |
2005 */ | |
2006 Lisp_Object fun = make_compiled_function (); | |
2007 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (fun); | |
2008 | |
2009 Lisp_Object arglist = args[0]; | |
2010 Lisp_Object instructions = args[1]; | |
2011 Lisp_Object constants = args[2]; | |
2012 Lisp_Object stack_depth = args[3]; | |
2013 Lisp_Object doc_string = (nargs > 4) ? args[4] : Qnil; | |
2014 Lisp_Object interactive = (nargs > 5) ? args[5] : Qunbound; | |
2015 | |
2016 if (nargs < 4 || nargs > 6) | |
2017 return Fsignal (Qwrong_number_of_arguments, | |
2018 list2 (intern ("make-byte-code"), make_int (nargs))); | |
2019 | |
2020 /* Check for valid formal parameter list now, to allow us to use | |
2021 SPECBIND_FAST_UNSAFE() later in funcall_compiled_function(). */ | |
2022 { | |
814 | 2023 EXTERNAL_LIST_LOOP_2 (symbol, arglist) |
428 | 2024 { |
2025 CHECK_SYMBOL (symbol); | |
2026 if (EQ (symbol, Qt) || | |
2027 EQ (symbol, Qnil) || | |
2028 SYMBOL_IS_KEYWORD (symbol)) | |
563 | 2029 invalid_constant_2 |
428 | 2030 ("Invalid constant symbol in formal parameter list", |
2031 symbol, arglist); | |
2032 } | |
2033 } | |
2034 f->arglist = arglist; | |
2035 | |
2036 /* `instructions' is a string or a cons (string . int) for a | |
2037 lazy-loaded function. */ | |
2038 if (CONSP (instructions)) | |
2039 { | |
2040 CHECK_STRING (XCAR (instructions)); | |
2041 CHECK_INT (XCDR (instructions)); | |
2042 } | |
2043 else | |
2044 { | |
2045 CHECK_STRING (instructions); | |
2046 } | |
2047 f->instructions = instructions; | |
2048 | |
2049 if (!NILP (constants)) | |
2050 CHECK_VECTOR (constants); | |
2051 f->constants = constants; | |
2052 | |
2053 CHECK_NATNUM (stack_depth); | |
442 | 2054 f->stack_depth = (unsigned short) XINT (stack_depth); |
428 | 2055 |
2056 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
4923
8ee3c10d1ed5
remove old no-longer-useful kludgy compiled-fun annotations hack
Ben Wing <ben@xemacs.org>
parents:
4921
diff
changeset
|
2057 f->annotated = Vload_file_name_internal; |
428 | 2058 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */ |
2059 | |
2060 /* doc_string may be nil, string, int, or a cons (string . int). | |
2061 interactive may be list or string (or unbound). */ | |
2062 f->doc_and_interactive = Qunbound; | |
2063 #ifdef I18N3 | |
2064 if ((f->flags.domainp = !NILP (Vfile_domain)) != 0) | |
2065 f->doc_and_interactive = Vfile_domain; | |
2066 #endif | |
2067 if ((f->flags.interactivep = !UNBOUNDP (interactive)) != 0) | |
2068 { | |
2069 f->doc_and_interactive | |
2070 = (UNBOUNDP (f->doc_and_interactive) ? interactive : | |
2071 Fcons (interactive, f->doc_and_interactive)); | |
2072 } | |
2073 if ((f->flags.documentationp = !NILP (doc_string)) != 0) | |
2074 { | |
2075 f->doc_and_interactive | |
2076 = (UNBOUNDP (f->doc_and_interactive) ? doc_string : | |
2077 Fcons (doc_string, f->doc_and_interactive)); | |
2078 } | |
2079 if (UNBOUNDP (f->doc_and_interactive)) | |
2080 f->doc_and_interactive = Qnil; | |
2081 | |
2082 return fun; | |
2083 } | |
2084 | |
2085 | |
2086 /************************************************************************/ | |
2087 /* Symbol allocation */ | |
2088 /************************************************************************/ | |
2089 | |
440 | 2090 DECLARE_FIXED_TYPE_ALLOC (symbol, Lisp_Symbol); |
428 | 2091 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_symbol 1000 |
2092 | |
2093 DEFUN ("make-symbol", Fmake_symbol, 1, 1, 0, /* | |
2094 Return a newly allocated uninterned symbol whose name is NAME. | |
2095 Its value and function definition are void, and its property list is nil. | |
2096 */ | |
2097 (name)) | |
2098 { | |
440 | 2099 Lisp_Symbol *p; |
428 | 2100 |
2101 CHECK_STRING (name); | |
2102 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2103 ALLOC_FROB_BLOCK_LISP_OBJECT (symbol, Lisp_Symbol, p, &lrecord_symbol); |
793 | 2104 p->name = name; |
428 | 2105 p->plist = Qnil; |
2106 p->value = Qunbound; | |
2107 p->function = Qunbound; | |
2108 symbol_next (p) = 0; | |
793 | 2109 return wrap_symbol (p); |
428 | 2110 } |
2111 | |
2112 | |
2113 /************************************************************************/ | |
2114 /* Extent allocation */ | |
2115 /************************************************************************/ | |
2116 | |
2117 DECLARE_FIXED_TYPE_ALLOC (extent, struct extent); | |
2118 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_extent 1000 | |
2119 | |
2120 struct extent * | |
2121 allocate_extent (void) | |
2122 { | |
2123 struct extent *e; | |
2124 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2125 ALLOC_FROB_BLOCK_LISP_OBJECT (extent, struct extent, e, &lrecord_extent); |
428 | 2126 extent_object (e) = Qnil; |
2127 set_extent_start (e, -1); | |
2128 set_extent_end (e, -1); | |
2129 e->plist = Qnil; | |
2130 | |
2131 xzero (e->flags); | |
2132 | |
2133 extent_face (e) = Qnil; | |
2134 e->flags.end_open = 1; /* default is for endpoints to behave like markers */ | |
2135 e->flags.detachable = 1; | |
2136 | |
2137 return e; | |
2138 } | |
2139 | |
2140 | |
2141 /************************************************************************/ | |
2142 /* Event allocation */ | |
2143 /************************************************************************/ | |
2144 | |
440 | 2145 DECLARE_FIXED_TYPE_ALLOC (event, Lisp_Event); |
428 | 2146 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_event 1000 |
2147 | |
2148 Lisp_Object | |
2149 allocate_event (void) | |
2150 { | |
440 | 2151 Lisp_Event *e; |
2152 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2153 ALLOC_FROB_BLOCK_LISP_OBJECT (event, Lisp_Event, e, &lrecord_event); |
428 | 2154 |
793 | 2155 return wrap_event (e); |
428 | 2156 } |
2157 | |
1204 | 2158 #ifdef EVENT_DATA_AS_OBJECTS |
934 | 2159 DECLARE_FIXED_TYPE_ALLOC (key_data, Lisp_Key_Data); |
2160 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_key_data 1000 | |
2161 | |
2162 Lisp_Object | |
1204 | 2163 make_key_data (void) |
934 | 2164 { |
2165 Lisp_Key_Data *d; | |
2166 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2167 ALLOC_FROB_BLOCK_LISP_OBJECT (key_data, Lisp_Key_Data, d, |
3017 | 2168 &lrecord_key_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2169 zero_nonsized_lisp_object (wrap_key_data (d)); |
1204 | 2170 d->keysym = Qnil; |
2171 | |
2172 return wrap_key_data (d); | |
934 | 2173 } |
2174 | |
2175 DECLARE_FIXED_TYPE_ALLOC (button_data, Lisp_Button_Data); | |
2176 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_button_data 1000 | |
2177 | |
2178 Lisp_Object | |
1204 | 2179 make_button_data (void) |
934 | 2180 { |
2181 Lisp_Button_Data *d; | |
2182 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2183 ALLOC_FROB_BLOCK_LISP_OBJECT (button_data, Lisp_Button_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2184 &lrecord_button_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2185 zero_nonsized_lisp_object (wrap_button_data (d)); |
1204 | 2186 return wrap_button_data (d); |
934 | 2187 } |
2188 | |
2189 DECLARE_FIXED_TYPE_ALLOC (motion_data, Lisp_Motion_Data); | |
2190 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_motion_data 1000 | |
2191 | |
2192 Lisp_Object | |
1204 | 2193 make_motion_data (void) |
934 | 2194 { |
2195 Lisp_Motion_Data *d; | |
2196 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2197 ALLOC_FROB_BLOCK_LISP_OBJECT (motion_data, Lisp_Motion_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2198 &lrecord_motion_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2199 zero_nonsized_lisp_object (wrap_motion_data (d)); |
934 | 2200 |
1204 | 2201 return wrap_motion_data (d); |
934 | 2202 } |
2203 | |
2204 DECLARE_FIXED_TYPE_ALLOC (process_data, Lisp_Process_Data); | |
2205 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_process_data 1000 | |
2206 | |
2207 Lisp_Object | |
1204 | 2208 make_process_data (void) |
934 | 2209 { |
2210 Lisp_Process_Data *d; | |
2211 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2212 ALLOC_FROB_BLOCK_LISP_OBJECT (process_data, Lisp_Process_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2213 &lrecord_process_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2214 zero_nonsized_lisp_object (wrap_process_data (d)); |
1204 | 2215 d->process = Qnil; |
2216 | |
2217 return wrap_process_data (d); | |
934 | 2218 } |
2219 | |
2220 DECLARE_FIXED_TYPE_ALLOC (timeout_data, Lisp_Timeout_Data); | |
2221 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_timeout_data 1000 | |
2222 | |
2223 Lisp_Object | |
1204 | 2224 make_timeout_data (void) |
934 | 2225 { |
2226 Lisp_Timeout_Data *d; | |
2227 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2228 ALLOC_FROB_BLOCK_LISP_OBJECT (timeout_data, Lisp_Timeout_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2229 &lrecord_timeout_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2230 zero_nonsized_lisp_object (wrap_timeout_data (d)); |
1204 | 2231 d->function = Qnil; |
2232 d->object = Qnil; | |
2233 | |
2234 return wrap_timeout_data (d); | |
934 | 2235 } |
2236 | |
2237 DECLARE_FIXED_TYPE_ALLOC (magic_data, Lisp_Magic_Data); | |
2238 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_magic_data 1000 | |
2239 | |
2240 Lisp_Object | |
1204 | 2241 make_magic_data (void) |
934 | 2242 { |
2243 Lisp_Magic_Data *d; | |
2244 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2245 ALLOC_FROB_BLOCK_LISP_OBJECT (magic_data, Lisp_Magic_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2246 &lrecord_magic_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2247 zero_nonsized_lisp_object (wrap_magic_data (d)); |
934 | 2248 |
1204 | 2249 return wrap_magic_data (d); |
934 | 2250 } |
2251 | |
2252 DECLARE_FIXED_TYPE_ALLOC (magic_eval_data, Lisp_Magic_Eval_Data); | |
2253 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_magic_eval_data 1000 | |
2254 | |
2255 Lisp_Object | |
1204 | 2256 make_magic_eval_data (void) |
934 | 2257 { |
2258 Lisp_Magic_Eval_Data *d; | |
2259 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2260 ALLOC_FROB_BLOCK_LISP_OBJECT (magic_eval_data, Lisp_Magic_Eval_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2261 &lrecord_magic_eval_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2262 zero_nonsized_lisp_object (wrap_magic_eval_data (d)); |
1204 | 2263 d->object = Qnil; |
2264 | |
2265 return wrap_magic_eval_data (d); | |
934 | 2266 } |
2267 | |
2268 DECLARE_FIXED_TYPE_ALLOC (eval_data, Lisp_Eval_Data); | |
2269 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_eval_data 1000 | |
2270 | |
2271 Lisp_Object | |
1204 | 2272 make_eval_data (void) |
934 | 2273 { |
2274 Lisp_Eval_Data *d; | |
2275 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2276 ALLOC_FROB_BLOCK_LISP_OBJECT (eval_data, Lisp_Eval_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2277 &lrecord_eval_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2278 zero_nonsized_lisp_object (wrap_eval_data (d)); |
1204 | 2279 d->function = Qnil; |
2280 d->object = Qnil; | |
2281 | |
2282 return wrap_eval_data (d); | |
934 | 2283 } |
2284 | |
2285 DECLARE_FIXED_TYPE_ALLOC (misc_user_data, Lisp_Misc_User_Data); | |
2286 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_misc_user_data 1000 | |
2287 | |
2288 Lisp_Object | |
1204 | 2289 make_misc_user_data (void) |
934 | 2290 { |
2291 Lisp_Misc_User_Data *d; | |
2292 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2293 ALLOC_FROB_BLOCK_LISP_OBJECT (misc_user_data, Lisp_Misc_User_Data, d, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2294 &lrecord_misc_user_data); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2295 zero_nonsized_lisp_object (wrap_misc_user_data (d)); |
1204 | 2296 d->function = Qnil; |
2297 d->object = Qnil; | |
2298 | |
2299 return wrap_misc_user_data (d); | |
934 | 2300 } |
1204 | 2301 |
2302 #endif /* EVENT_DATA_AS_OBJECTS */ | |
428 | 2303 |
2304 /************************************************************************/ | |
2305 /* Marker allocation */ | |
2306 /************************************************************************/ | |
2307 | |
440 | 2308 DECLARE_FIXED_TYPE_ALLOC (marker, Lisp_Marker); |
428 | 2309 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_marker 1000 |
2310 | |
2311 DEFUN ("make-marker", Fmake_marker, 0, 0, 0, /* | |
2312 Return a new marker which does not point at any place. | |
2313 */ | |
2314 ()) | |
2315 { | |
440 | 2316 Lisp_Marker *p; |
2317 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2318 ALLOC_FROB_BLOCK_LISP_OBJECT (marker, Lisp_Marker, p, &lrecord_marker); |
428 | 2319 p->buffer = 0; |
665 | 2320 p->membpos = 0; |
428 | 2321 marker_next (p) = 0; |
2322 marker_prev (p) = 0; | |
2323 p->insertion_type = 0; | |
793 | 2324 return wrap_marker (p); |
428 | 2325 } |
2326 | |
2327 Lisp_Object | |
2328 noseeum_make_marker (void) | |
2329 { | |
440 | 2330 Lisp_Marker *p; |
2331 | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2332 NOSEEUM_ALLOC_FROB_BLOCK_LISP_OBJECT (marker, Lisp_Marker, p, |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
2333 &lrecord_marker); |
428 | 2334 p->buffer = 0; |
665 | 2335 p->membpos = 0; |
428 | 2336 marker_next (p) = 0; |
2337 marker_prev (p) = 0; | |
2338 p->insertion_type = 0; | |
793 | 2339 return wrap_marker (p); |
428 | 2340 } |
2341 | |
2342 | |
2343 /************************************************************************/ | |
2344 /* String allocation */ | |
2345 /************************************************************************/ | |
2346 | |
2347 /* The data for "short" strings generally resides inside of structs of type | |
2348 string_chars_block. The Lisp_String structure is allocated just like any | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2349 other frob-block lrecord, and these are freelisted when they get garbage |
1204 | 2350 collected. The data for short strings get compacted, but the data for |
2351 large strings do not. | |
428 | 2352 |
2353 Previously Lisp_String structures were relocated, but this caused a lot | |
2354 of bus-errors because the C code didn't include enough GCPRO's for | |
2355 strings (since EVERY REFERENCE to a short string needed to be GCPRO'd so | |
2356 that the reference would get relocated). | |
2357 | |
2358 This new method makes things somewhat bigger, but it is MUCH safer. */ | |
2359 | |
438 | 2360 DECLARE_FIXED_TYPE_ALLOC (string, Lisp_String); |
428 | 2361 /* strings are used and freed quite often */ |
2362 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 10000 */ | |
2363 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 1000 | |
2364 | |
2365 static Lisp_Object | |
2366 mark_string (Lisp_Object obj) | |
2367 { | |
793 | 2368 if (CONSP (XSTRING_PLIST (obj)) && EXTENT_INFOP (XCAR (XSTRING_PLIST (obj)))) |
2369 flush_cached_extent_info (XCAR (XSTRING_PLIST (obj))); | |
2370 return XSTRING_PLIST (obj); | |
428 | 2371 } |
2372 | |
2373 static int | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2374 string_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth), |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2375 int foldcase) |
428 | 2376 { |
2377 Bytecount len; | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2378 if (foldcase) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2379 return !lisp_strcasecmp_i18n (obj1, obj2); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2380 else |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2381 return (((len = XSTRING_LENGTH (obj1)) == XSTRING_LENGTH (obj2)) && |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2382 !memcmp (XSTRING_DATA (obj1), XSTRING_DATA (obj2), len)); |
428 | 2383 } |
2384 | |
1204 | 2385 static const struct memory_description string_description[] = { |
3092 | 2386 #ifdef NEW_GC |
2387 { XD_LISP_OBJECT, offsetof (Lisp_String, data_object) }, | |
2388 #else /* not NEW_GC */ | |
793 | 2389 { XD_BYTECOUNT, offsetof (Lisp_String, size_) }, |
2390 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String, data_), XD_INDIRECT(0, 1) }, | |
3092 | 2391 #endif /* not NEW_GC */ |
440 | 2392 { XD_LISP_OBJECT, offsetof (Lisp_String, plist) }, |
428 | 2393 { XD_END } |
2394 }; | |
2395 | |
442 | 2396 /* We store the string's extent info as the first element of the string's |
2397 property list; and the string's MODIFF as the first or second element | |
2398 of the string's property list (depending on whether the extent info | |
2399 is present), but only if the string has been modified. This is ugly | |
2400 but it reduces the memory allocated for the string in the vast | |
2401 majority of cases, where the string is never modified and has no | |
2402 extent info. | |
2403 | |
2404 #### This means you can't use an int as a key in a string's plist. */ | |
2405 | |
2406 static Lisp_Object * | |
2407 string_plist_ptr (Lisp_Object string) | |
2408 { | |
793 | 2409 Lisp_Object *ptr = &XSTRING_PLIST (string); |
442 | 2410 |
2411 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr))) | |
2412 ptr = &XCDR (*ptr); | |
2413 if (CONSP (*ptr) && INTP (XCAR (*ptr))) | |
2414 ptr = &XCDR (*ptr); | |
2415 return ptr; | |
2416 } | |
2417 | |
2418 static Lisp_Object | |
2419 string_getprop (Lisp_Object string, Lisp_Object property) | |
2420 { | |
2421 return external_plist_get (string_plist_ptr (string), property, 0, ERROR_ME); | |
2422 } | |
2423 | |
2424 static int | |
2425 string_putprop (Lisp_Object string, Lisp_Object property, Lisp_Object value) | |
2426 { | |
2427 external_plist_put (string_plist_ptr (string), property, value, 0, ERROR_ME); | |
2428 return 1; | |
2429 } | |
2430 | |
2431 static int | |
2432 string_remprop (Lisp_Object string, Lisp_Object property) | |
2433 { | |
2434 return external_remprop (string_plist_ptr (string), property, 0, ERROR_ME); | |
2435 } | |
2436 | |
2437 static Lisp_Object | |
2438 string_plist (Lisp_Object string) | |
2439 { | |
2440 return *string_plist_ptr (string); | |
2441 } | |
2442 | |
3263 | 2443 #ifndef NEW_GC |
442 | 2444 /* No `finalize', or `hash' methods. |
2445 internal_hash() already knows how to hash strings and finalization | |
2446 is done with the ADDITIONAL_FREE_string macro, which is the | |
2447 standard way to do finalization when using | |
2448 SWEEP_FIXED_TYPE_BLOCK(). */ | |
2720 | 2449 |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2450 DEFINE_DUMPABLE_FROB_BLOCK_LISP_OBJECT ("string", string, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2451 mark_string, print_string, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2452 0, string_equal, 0, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2453 string_description, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2454 Lisp_String); |
3263 | 2455 #endif /* not NEW_GC */ |
2720 | 2456 |
3092 | 2457 #ifdef NEW_GC |
2458 #define STRING_FULLSIZE(size) \ | |
2459 ALIGN_SIZE (FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_String_Direct_Data, Lisp_Object, data, (size) + 1), sizeof (Lisp_Object *)); | |
2460 #else /* not NEW_GC */ | |
428 | 2461 /* String blocks contain this many useful bytes. */ |
2462 #define STRING_CHARS_BLOCK_SIZE \ | |
814 | 2463 ((Bytecount) (8192 - MALLOC_OVERHEAD - \ |
2464 ((2 * sizeof (struct string_chars_block *)) \ | |
2465 + sizeof (EMACS_INT)))) | |
428 | 2466 /* Block header for small strings. */ |
2467 struct string_chars_block | |
2468 { | |
2469 EMACS_INT pos; | |
2470 struct string_chars_block *next; | |
2471 struct string_chars_block *prev; | |
2472 /* Contents of string_chars_block->string_chars are interleaved | |
2473 string_chars structures (see below) and the actual string data */ | |
2474 unsigned char string_chars[STRING_CHARS_BLOCK_SIZE]; | |
2475 }; | |
2476 | |
2477 static struct string_chars_block *first_string_chars_block; | |
2478 static struct string_chars_block *current_string_chars_block; | |
2479 | |
2480 /* If SIZE is the length of a string, this returns how many bytes | |
2481 * the string occupies in string_chars_block->string_chars | |
2482 * (including alignment padding). | |
2483 */ | |
438 | 2484 #define STRING_FULLSIZE(size) \ |
826 | 2485 ALIGN_FOR_TYPE (((size) + 1 + sizeof (Lisp_String *)), Lisp_String *) |
428 | 2486 |
2487 #define BIG_STRING_FULLSIZE_P(fullsize) ((fullsize) >= STRING_CHARS_BLOCK_SIZE) | |
2488 #define BIG_STRING_SIZE_P(size) (BIG_STRING_FULLSIZE_P (STRING_FULLSIZE(size))) | |
2489 | |
454 | 2490 #define STRING_CHARS_FREE_P(ptr) ((ptr)->string == NULL) |
2491 #define MARK_STRING_CHARS_AS_FREE(ptr) ((void) ((ptr)->string = NULL)) | |
3092 | 2492 #endif /* not NEW_GC */ |
454 | 2493 |
3263 | 2494 #ifdef NEW_GC |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2495 DEFINE_DUMPABLE_LISP_OBJECT ("string", string, mark_string, print_string, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2496 0, string_equal, 0, |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2497 string_description, Lisp_String); |
3092 | 2498 |
2499 | |
2500 static const struct memory_description string_direct_data_description[] = { | |
3514 | 2501 { XD_BYTECOUNT, offsetof (Lisp_String_Direct_Data, size) }, |
3092 | 2502 { XD_END } |
2503 }; | |
2504 | |
2505 static Bytecount | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2506 size_string_direct_data (Lisp_Object obj) |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2507 { |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2508 return STRING_FULLSIZE (XSTRING_DIRECT_DATA (obj)->size); |
3092 | 2509 } |
2510 | |
2511 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2512 DEFINE_DUMPABLE_SIZABLE_INTERNAL_LISP_OBJECT ("string-direct-data", |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2513 string_direct_data, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2514 0, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2515 string_direct_data_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2516 size_string_direct_data, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2517 Lisp_String_Direct_Data); |
3092 | 2518 |
2519 | |
2520 static const struct memory_description string_indirect_data_description[] = { | |
2521 { XD_BYTECOUNT, offsetof (Lisp_String_Indirect_Data, size) }, | |
2522 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String_Indirect_Data, data), | |
2523 XD_INDIRECT(0, 1) }, | |
2524 { XD_END } | |
2525 }; | |
2526 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2527 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("string-indirect-data", |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2528 string_indirect_data, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2529 0, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2530 string_indirect_data_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2531 Lisp_String_Indirect_Data); |
3092 | 2532 #endif /* NEW_GC */ |
2720 | 2533 |
3092 | 2534 #ifndef NEW_GC |
428 | 2535 struct string_chars |
2536 { | |
438 | 2537 Lisp_String *string; |
428 | 2538 unsigned char chars[1]; |
2539 }; | |
2540 | |
2541 struct unused_string_chars | |
2542 { | |
438 | 2543 Lisp_String *string; |
428 | 2544 EMACS_INT fullsize; |
2545 }; | |
2546 | |
2547 static void | |
2548 init_string_chars_alloc (void) | |
2549 { | |
2550 first_string_chars_block = xnew (struct string_chars_block); | |
2551 first_string_chars_block->prev = 0; | |
2552 first_string_chars_block->next = 0; | |
2553 first_string_chars_block->pos = 0; | |
2554 current_string_chars_block = first_string_chars_block; | |
2555 } | |
2556 | |
1550 | 2557 static Ibyte * |
2558 allocate_big_string_chars (Bytecount length) | |
2559 { | |
2560 Ibyte *p = xnew_array (Ibyte, length); | |
2561 INCREMENT_CONS_COUNTER (length, "string chars"); | |
2562 return p; | |
2563 } | |
2564 | |
428 | 2565 static struct string_chars * |
793 | 2566 allocate_string_chars_struct (Lisp_Object string_it_goes_with, |
814 | 2567 Bytecount fullsize) |
428 | 2568 { |
2569 struct string_chars *s_chars; | |
2570 | |
438 | 2571 if (fullsize <= |
2572 (countof (current_string_chars_block->string_chars) | |
2573 - current_string_chars_block->pos)) | |
428 | 2574 { |
2575 /* This string can fit in the current string chars block */ | |
2576 s_chars = (struct string_chars *) | |
2577 (current_string_chars_block->string_chars | |
2578 + current_string_chars_block->pos); | |
2579 current_string_chars_block->pos += fullsize; | |
2580 } | |
2581 else | |
2582 { | |
2583 /* Make a new current string chars block */ | |
2584 struct string_chars_block *new_scb = xnew (struct string_chars_block); | |
2585 | |
2586 current_string_chars_block->next = new_scb; | |
2587 new_scb->prev = current_string_chars_block; | |
2588 new_scb->next = 0; | |
2589 current_string_chars_block = new_scb; | |
2590 new_scb->pos = fullsize; | |
2591 s_chars = (struct string_chars *) | |
2592 current_string_chars_block->string_chars; | |
2593 } | |
2594 | |
793 | 2595 s_chars->string = XSTRING (string_it_goes_with); |
428 | 2596 |
2597 INCREMENT_CONS_COUNTER (fullsize, "string chars"); | |
2598 | |
2599 return s_chars; | |
2600 } | |
3092 | 2601 #endif /* not NEW_GC */ |
428 | 2602 |
771 | 2603 #ifdef SLEDGEHAMMER_CHECK_ASCII_BEGIN |
2604 void | |
2605 sledgehammer_check_ascii_begin (Lisp_Object str) | |
2606 { | |
2607 Bytecount i; | |
2608 | |
2609 for (i = 0; i < XSTRING_LENGTH (str); i++) | |
2610 { | |
826 | 2611 if (!byte_ascii_p (string_byte (str, i))) |
771 | 2612 break; |
2613 } | |
2614 | |
2615 assert (i == (Bytecount) XSTRING_ASCII_BEGIN (str) || | |
2616 (i > MAX_STRING_ASCII_BEGIN && | |
2617 (Bytecount) XSTRING_ASCII_BEGIN (str) == | |
2618 (Bytecount) MAX_STRING_ASCII_BEGIN)); | |
2619 } | |
2620 #endif | |
2621 | |
2622 /* You do NOT want to be calling this! (And if you do, you must call | |
851 | 2623 XSET_STRING_ASCII_BEGIN() after modifying the string.) Use ALLOCA () |
771 | 2624 instead and then call make_string() like the rest of the world. */ |
2625 | |
428 | 2626 Lisp_Object |
2627 make_uninit_string (Bytecount length) | |
2628 { | |
438 | 2629 Lisp_String *s; |
814 | 2630 Bytecount fullsize = STRING_FULLSIZE (length); |
428 | 2631 |
438 | 2632 assert (length >= 0 && fullsize > 0); |
428 | 2633 |
3263 | 2634 #ifdef NEW_GC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2635 s = XSTRING (ALLOC_NORMAL_LISP_OBJECT (string)); |
3263 | 2636 #else /* not NEW_GC */ |
428 | 2637 /* Allocate the string header */ |
438 | 2638 ALLOCATE_FIXED_TYPE (string, Lisp_String, s); |
793 | 2639 xzero (*s); |
771 | 2640 set_lheader_implementation (&s->u.lheader, &lrecord_string); |
3263 | 2641 #endif /* not NEW_GC */ |
2720 | 2642 |
3063 | 2643 /* The above allocations set the UID field, which overlaps with the |
2644 ascii-length field, to some non-zero value. We need to zero it. */ | |
2645 XSET_STRING_ASCII_BEGIN (wrap_string (s), 0); | |
2646 | |
3092 | 2647 #ifdef NEW_GC |
3304 | 2648 set_lispstringp_direct (s); |
3092 | 2649 STRING_DATA_OBJECT (s) = |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2650 alloc_sized_lrecord (fullsize, &lrecord_string_direct_data); |
3092 | 2651 #else /* not NEW_GC */ |
826 | 2652 set_lispstringp_data (s, BIG_STRING_FULLSIZE_P (fullsize) |
2720 | 2653 ? allocate_big_string_chars (length + 1) |
2654 : allocate_string_chars_struct (wrap_string (s), | |
2655 fullsize)->chars); | |
3092 | 2656 #endif /* not NEW_GC */ |
438 | 2657 |
826 | 2658 set_lispstringp_length (s, length); |
428 | 2659 s->plist = Qnil; |
793 | 2660 set_string_byte (wrap_string (s), length, 0); |
2661 | |
2662 return wrap_string (s); | |
428 | 2663 } |
2664 | |
2665 #ifdef VERIFY_STRING_CHARS_INTEGRITY | |
2666 static void verify_string_chars_integrity (void); | |
2667 #endif | |
2668 | |
2669 /* Resize the string S so that DELTA bytes can be inserted starting | |
2670 at POS. If DELTA < 0, it means deletion starting at POS. If | |
2671 POS < 0, resize the string but don't copy any characters. Use | |
2672 this if you're planning on completely overwriting the string. | |
2673 */ | |
2674 | |
2675 void | |
793 | 2676 resize_string (Lisp_Object s, Bytecount pos, Bytecount delta) |
428 | 2677 { |
3092 | 2678 #ifdef NEW_GC |
2679 Bytecount newfullsize, len; | |
2680 #else /* not NEW_GC */ | |
438 | 2681 Bytecount oldfullsize, newfullsize; |
3092 | 2682 #endif /* not NEW_GC */ |
428 | 2683 #ifdef VERIFY_STRING_CHARS_INTEGRITY |
2684 verify_string_chars_integrity (); | |
2685 #endif | |
800 | 2686 #ifdef ERROR_CHECK_TEXT |
428 | 2687 if (pos >= 0) |
2688 { | |
793 | 2689 assert (pos <= XSTRING_LENGTH (s)); |
428 | 2690 if (delta < 0) |
793 | 2691 assert (pos + (-delta) <= XSTRING_LENGTH (s)); |
428 | 2692 } |
2693 else | |
2694 { | |
2695 if (delta < 0) | |
793 | 2696 assert ((-delta) <= XSTRING_LENGTH (s)); |
428 | 2697 } |
800 | 2698 #endif /* ERROR_CHECK_TEXT */ |
428 | 2699 |
2700 if (delta == 0) | |
2701 /* simplest case: no size change. */ | |
2702 return; | |
438 | 2703 |
2704 if (pos >= 0 && delta < 0) | |
2705 /* If DELTA < 0, the functions below will delete the characters | |
2706 before POS. We want to delete characters *after* POS, however, | |
2707 so convert this to the appropriate form. */ | |
2708 pos += -delta; | |
2709 | |
3092 | 2710 #ifdef NEW_GC |
2711 newfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s) + delta); | |
2712 | |
2713 len = XSTRING_LENGTH (s) + 1 - pos; | |
2714 | |
2715 if (delta < 0 && pos >= 0) | |
2716 memmove (XSTRING_DATA (s) + pos + delta, | |
2717 XSTRING_DATA (s) + pos, len); | |
2718 | |
2719 XSTRING_DATA_OBJECT (s) = | |
2720 wrap_string_direct_data (mc_realloc (XPNTR (XSTRING_DATA_OBJECT (s)), | |
2721 newfullsize)); | |
2722 if (delta > 0 && pos >= 0) | |
2723 memmove (XSTRING_DATA (s) + pos + delta, XSTRING_DATA (s) + pos, | |
2724 len); | |
2725 | |
3263 | 2726 #else /* not NEW_GC */ |
793 | 2727 oldfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s)); |
2728 newfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s) + delta); | |
438 | 2729 |
2730 if (BIG_STRING_FULLSIZE_P (oldfullsize)) | |
428 | 2731 { |
438 | 2732 if (BIG_STRING_FULLSIZE_P (newfullsize)) |
428 | 2733 { |
440 | 2734 /* Both strings are big. We can just realloc(). |
2735 But careful! If the string is shrinking, we have to | |
2736 memmove() _before_ realloc(), and if growing, we have to | |
2737 memmove() _after_ realloc() - otherwise the access is | |
2738 illegal, and we might crash. */ | |
793 | 2739 Bytecount len = XSTRING_LENGTH (s) + 1 - pos; |
440 | 2740 |
2741 if (delta < 0 && pos >= 0) | |
793 | 2742 memmove (XSTRING_DATA (s) + pos + delta, |
2743 XSTRING_DATA (s) + pos, len); | |
2744 XSET_STRING_DATA | |
867 | 2745 (s, (Ibyte *) xrealloc (XSTRING_DATA (s), |
793 | 2746 XSTRING_LENGTH (s) + delta + 1)); |
440 | 2747 if (delta > 0 && pos >= 0) |
793 | 2748 memmove (XSTRING_DATA (s) + pos + delta, XSTRING_DATA (s) + pos, |
2749 len); | |
1550 | 2750 /* Bump the cons counter. |
2751 Conservative; Martin let the increment be delta. */ | |
2752 INCREMENT_CONS_COUNTER (newfullsize, "string chars"); | |
428 | 2753 } |
438 | 2754 else /* String has been demoted from BIG_STRING. */ |
428 | 2755 { |
867 | 2756 Ibyte *new_data = |
438 | 2757 allocate_string_chars_struct (s, newfullsize)->chars; |
867 | 2758 Ibyte *old_data = XSTRING_DATA (s); |
438 | 2759 |
2760 if (pos >= 0) | |
2761 { | |
2762 memcpy (new_data, old_data, pos); | |
2763 memcpy (new_data + pos + delta, old_data + pos, | |
793 | 2764 XSTRING_LENGTH (s) + 1 - pos); |
438 | 2765 } |
793 | 2766 XSET_STRING_DATA (s, new_data); |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
2767 xfree (old_data); |
438 | 2768 } |
2769 } | |
2770 else /* old string is small */ | |
2771 { | |
2772 if (oldfullsize == newfullsize) | |
2773 { | |
2774 /* special case; size change but the necessary | |
2775 allocation size won't change (up or down; code | |
2776 somewhere depends on there not being any unused | |
2777 allocation space, modulo any alignment | |
2778 constraints). */ | |
428 | 2779 if (pos >= 0) |
2780 { | |
867 | 2781 Ibyte *addroff = pos + XSTRING_DATA (s); |
428 | 2782 |
2783 memmove (addroff + delta, addroff, | |
2784 /* +1 due to zero-termination. */ | |
793 | 2785 XSTRING_LENGTH (s) + 1 - pos); |
428 | 2786 } |
2787 } | |
2788 else | |
2789 { | |
867 | 2790 Ibyte *old_data = XSTRING_DATA (s); |
2791 Ibyte *new_data = | |
438 | 2792 BIG_STRING_FULLSIZE_P (newfullsize) |
1550 | 2793 ? allocate_big_string_chars (XSTRING_LENGTH (s) + delta + 1) |
438 | 2794 : allocate_string_chars_struct (s, newfullsize)->chars; |
2795 | |
428 | 2796 if (pos >= 0) |
2797 { | |
438 | 2798 memcpy (new_data, old_data, pos); |
2799 memcpy (new_data + pos + delta, old_data + pos, | |
793 | 2800 XSTRING_LENGTH (s) + 1 - pos); |
428 | 2801 } |
793 | 2802 XSET_STRING_DATA (s, new_data); |
438 | 2803 |
4776
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2804 if (!DUMPEDP (old_data)) /* Can't free dumped data. */ |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2805 { |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2806 /* We need to mark this chunk of the string_chars_block |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2807 as unused so that compact_string_chars() doesn't |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2808 freak. */ |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2809 struct string_chars *old_s_chars = (struct string_chars *) |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2810 ((char *) old_data - offsetof (struct string_chars, chars)); |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2811 /* Sanity check to make sure we aren't hosed by strange |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2812 alignment/padding. */ |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2813 assert (old_s_chars->string == XSTRING (s)); |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2814 MARK_STRING_CHARS_AS_FREE (old_s_chars); |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2815 ((struct unused_string_chars *) old_s_chars)->fullsize = |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2816 oldfullsize; |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2817 } |
428 | 2818 } |
438 | 2819 } |
3092 | 2820 #endif /* not NEW_GC */ |
438 | 2821 |
793 | 2822 XSET_STRING_LENGTH (s, XSTRING_LENGTH (s) + delta); |
438 | 2823 /* If pos < 0, the string won't be zero-terminated. |
2824 Terminate now just to make sure. */ | |
793 | 2825 XSTRING_DATA (s)[XSTRING_LENGTH (s)] = '\0'; |
438 | 2826 |
2827 if (pos >= 0) | |
793 | 2828 /* We also have to adjust all of the extent indices after the |
2829 place we did the change. We say "pos - 1" because | |
2830 adjust_extents() is exclusive of the starting position | |
2831 passed to it. */ | |
2832 adjust_extents (s, pos - 1, XSTRING_LENGTH (s), delta); | |
428 | 2833 |
2834 #ifdef VERIFY_STRING_CHARS_INTEGRITY | |
2835 verify_string_chars_integrity (); | |
2836 #endif | |
2837 } | |
2838 | |
2839 #ifdef MULE | |
2840 | |
771 | 2841 /* WARNING: If you modify an existing string, you must call |
2842 CHECK_LISP_WRITEABLE() before and bump_string_modiff() afterwards. */ | |
428 | 2843 void |
867 | 2844 set_string_char (Lisp_Object s, Charcount i, Ichar c) |
428 | 2845 { |
867 | 2846 Ibyte newstr[MAX_ICHAR_LEN]; |
771 | 2847 Bytecount bytoff = string_index_char_to_byte (s, i); |
867 | 2848 Bytecount oldlen = itext_ichar_len (XSTRING_DATA (s) + bytoff); |
2849 Bytecount newlen = set_itext_ichar (newstr, c); | |
428 | 2850 |
793 | 2851 sledgehammer_check_ascii_begin (s); |
428 | 2852 if (oldlen != newlen) |
2853 resize_string (s, bytoff, newlen - oldlen); | |
793 | 2854 /* Remember, XSTRING_DATA (s) might have changed so we can't cache it. */ |
2855 memcpy (XSTRING_DATA (s) + bytoff, newstr, newlen); | |
771 | 2856 if (oldlen != newlen) |
2857 { | |
793 | 2858 if (newlen > 1 && i <= (Charcount) XSTRING_ASCII_BEGIN (s)) |
771 | 2859 /* Everything starting with the new char is no longer part of |
2860 ascii_begin */ | |
793 | 2861 XSET_STRING_ASCII_BEGIN (s, i); |
2862 else if (newlen == 1 && i == (Charcount) XSTRING_ASCII_BEGIN (s)) | |
771 | 2863 /* We've extended ascii_begin, and we have to figure out how much by */ |
2864 { | |
2865 Bytecount j; | |
814 | 2866 for (j = (Bytecount) i + 1; j < XSTRING_LENGTH (s); j++) |
771 | 2867 { |
826 | 2868 if (!byte_ascii_p (XSTRING_DATA (s)[j])) |
771 | 2869 break; |
2870 } | |
814 | 2871 XSET_STRING_ASCII_BEGIN (s, min (j, (Bytecount) MAX_STRING_ASCII_BEGIN)); |
771 | 2872 } |
2873 } | |
793 | 2874 sledgehammer_check_ascii_begin (s); |
428 | 2875 } |
2876 | |
2877 #endif /* MULE */ | |
2878 | |
2879 DEFUN ("make-string", Fmake_string, 2, 2, 0, /* | |
444 | 2880 Return a new string consisting of LENGTH copies of CHARACTER. |
2881 LENGTH must be a non-negative integer. | |
428 | 2882 */ |
444 | 2883 (length, character)) |
428 | 2884 { |
2885 CHECK_NATNUM (length); | |
444 | 2886 CHECK_CHAR_COERCE_INT (character); |
428 | 2887 { |
867 | 2888 Ibyte init_str[MAX_ICHAR_LEN]; |
2889 int len = set_itext_ichar (init_str, XCHAR (character)); | |
428 | 2890 Lisp_Object val = make_uninit_string (len * XINT (length)); |
2891 | |
2892 if (len == 1) | |
771 | 2893 { |
2894 /* Optimize the single-byte case */ | |
2895 memset (XSTRING_DATA (val), XCHAR (character), XSTRING_LENGTH (val)); | |
793 | 2896 XSET_STRING_ASCII_BEGIN (val, min (MAX_STRING_ASCII_BEGIN, |
2897 len * XINT (length))); | |
771 | 2898 } |
428 | 2899 else |
2900 { | |
647 | 2901 EMACS_INT i; |
867 | 2902 Ibyte *ptr = XSTRING_DATA (val); |
428 | 2903 |
2904 for (i = XINT (length); i; i--) | |
2905 { | |
867 | 2906 Ibyte *init_ptr = init_str; |
428 | 2907 switch (len) |
2908 { | |
2909 case 4: *ptr++ = *init_ptr++; | |
2910 case 3: *ptr++ = *init_ptr++; | |
2911 case 2: *ptr++ = *init_ptr++; | |
2912 case 1: *ptr++ = *init_ptr++; | |
2913 } | |
2914 } | |
2915 } | |
771 | 2916 sledgehammer_check_ascii_begin (val); |
428 | 2917 return val; |
2918 } | |
2919 } | |
2920 | |
2921 DEFUN ("string", Fstring, 0, MANY, 0, /* | |
2922 Concatenate all the argument characters and make the result a string. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
2923 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
2924 arguments: (&rest ARGS) |
428 | 2925 */ |
2926 (int nargs, Lisp_Object *args)) | |
2927 { | |
2367 | 2928 Ibyte *storage = alloca_ibytes (nargs * MAX_ICHAR_LEN); |
867 | 2929 Ibyte *p = storage; |
428 | 2930 |
2931 for (; nargs; nargs--, args++) | |
2932 { | |
2933 Lisp_Object lisp_char = *args; | |
2934 CHECK_CHAR_COERCE_INT (lisp_char); | |
867 | 2935 p += set_itext_ichar (p, XCHAR (lisp_char)); |
428 | 2936 } |
2937 return make_string (storage, p - storage); | |
2938 } | |
2939 | |
771 | 2940 /* Initialize the ascii_begin member of a string to the correct value. */ |
2941 | |
2942 void | |
2943 init_string_ascii_begin (Lisp_Object string) | |
2944 { | |
2945 #ifdef MULE | |
2946 int i; | |
2947 Bytecount length = XSTRING_LENGTH (string); | |
867 | 2948 Ibyte *contents = XSTRING_DATA (string); |
771 | 2949 |
2950 for (i = 0; i < length; i++) | |
2951 { | |
826 | 2952 if (!byte_ascii_p (contents[i])) |
771 | 2953 break; |
2954 } | |
793 | 2955 XSET_STRING_ASCII_BEGIN (string, min (i, MAX_STRING_ASCII_BEGIN)); |
771 | 2956 #else |
793 | 2957 XSET_STRING_ASCII_BEGIN (string, min (XSTRING_LENGTH (string), |
2958 MAX_STRING_ASCII_BEGIN)); | |
771 | 2959 #endif |
2960 sledgehammer_check_ascii_begin (string); | |
2961 } | |
428 | 2962 |
2963 /* Take some raw memory, which MUST already be in internal format, | |
2964 and package it up into a Lisp string. */ | |
2965 Lisp_Object | |
867 | 2966 make_string (const Ibyte *contents, Bytecount length) |
428 | 2967 { |
2968 Lisp_Object val; | |
2969 | |
2970 /* Make sure we find out about bad make_string's when they happen */ | |
800 | 2971 #if defined (ERROR_CHECK_TEXT) && defined (MULE) |
428 | 2972 bytecount_to_charcount (contents, length); /* Just for the assertions */ |
2973 #endif | |
2974 | |
2975 val = make_uninit_string (length); | |
2976 memcpy (XSTRING_DATA (val), contents, length); | |
771 | 2977 init_string_ascii_begin (val); |
2978 sledgehammer_check_ascii_begin (val); | |
428 | 2979 return val; |
2980 } | |
2981 | |
2982 /* Take some raw memory, encoded in some external data format, | |
2983 and convert it into a Lisp string. */ | |
2984 Lisp_Object | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2985 make_extstring (const Extbyte *contents, EMACS_INT length, |
440 | 2986 Lisp_Object coding_system) |
428 | 2987 { |
440 | 2988 Lisp_Object string; |
2989 TO_INTERNAL_FORMAT (DATA, (contents, length), | |
2990 LISP_STRING, string, | |
2991 coding_system); | |
2992 return string; | |
428 | 2993 } |
2994 | |
2995 Lisp_Object | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2996 build_istring (const Ibyte *str) |
771 | 2997 { |
2998 /* Some strlen's crash and burn if passed null. */ | |
814 | 2999 return make_string (str, (str ? qxestrlen (str) : (Bytecount) 0)); |
771 | 3000 } |
3001 | |
3002 Lisp_Object | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3003 build_cistring (const CIbyte *str) |
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3004 { |
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3005 return build_istring ((const Ibyte *) str); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3006 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3007 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3008 Lisp_Object |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3009 build_ascstring (const Ascbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3010 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3011 ASSERT_ASCTEXT_ASCII (str); |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3012 return build_istring ((const Ibyte *) str); |
428 | 3013 } |
3014 | |
3015 Lisp_Object | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3016 build_extstring (const Extbyte *str, Lisp_Object coding_system) |
428 | 3017 { |
3018 /* Some strlen's crash and burn if passed null. */ | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3019 return make_extstring ((const Extbyte *) str, |
2367 | 3020 (str ? dfc_external_data_len (str, coding_system) : |
3021 0), | |
440 | 3022 coding_system); |
428 | 3023 } |
3024 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3025 /* Build a string whose content is a translatable message, and translate |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3026 the message according to the current language environment. */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3027 |
428 | 3028 Lisp_Object |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3029 build_msg_istring (const Ibyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3030 { |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3031 return build_istring (IGETTEXT (str)); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3032 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3033 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3034 /* Build a string whose content is a translatable message, and translate |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3035 the message according to the current language environment. */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3036 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3037 Lisp_Object |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3038 build_msg_cistring (const CIbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3039 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3040 return build_msg_istring ((const Ibyte *) str); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3041 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3042 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3043 /* Build a string whose content is a translatable message, and translate |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3044 the message according to the current language environment. |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3045 String must be pure-ASCII, and when compiled with error-checking, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3046 an abort will have if not pure-ASCII. */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3047 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3048 Lisp_Object |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3049 build_msg_ascstring (const Ascbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3050 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3051 ASSERT_ASCTEXT_ASCII (str); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3052 return build_msg_istring ((const Ibyte *) str); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3053 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3054 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3055 /* Build a string whose content is a translatable message, but don't |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3056 translate the message immediately. Perhaps do something else instead, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3057 such as put a property on the string indicating that it needs to be |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3058 translated. |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3059 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3060 This is useful for strings that are built at dump time or init time, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3061 rather than on-the-fly when the current language environment is set |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3062 properly. */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3063 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3064 Lisp_Object |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3065 build_defer_istring (const Ibyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3066 { |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3067 Lisp_Object retval = build_istring ((Ibyte *) str); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3068 /* Possibly do something to the return value */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3069 return retval; |
771 | 3070 } |
3071 | |
428 | 3072 Lisp_Object |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3073 build_defer_cistring (const CIbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3074 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3075 return build_defer_istring ((Ibyte *) str); |
771 | 3076 } |
3077 | |
3078 Lisp_Object | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3079 build_defer_ascstring (const Ascbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3080 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3081 ASSERT_ASCTEXT_ASCII (str); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3082 return build_defer_istring ((Ibyte *) str); |
428 | 3083 } |
3084 | |
3085 Lisp_Object | |
867 | 3086 make_string_nocopy (const Ibyte *contents, Bytecount length) |
428 | 3087 { |
438 | 3088 Lisp_String *s; |
428 | 3089 Lisp_Object val; |
3090 | |
3091 /* Make sure we find out about bad make_string_nocopy's when they happen */ | |
800 | 3092 #if defined (ERROR_CHECK_TEXT) && defined (MULE) |
428 | 3093 bytecount_to_charcount (contents, length); /* Just for the assertions */ |
3094 #endif | |
3095 | |
3263 | 3096 #ifdef NEW_GC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3097 s = XSTRING (ALLOC_NORMAL_LISP_OBJECT (string)); |
2720 | 3098 mcpro (wrap_pointer_1 (s)); /* otherwise nocopy_strings get |
3099 collected and static data is tried to | |
3100 be freed. */ | |
3263 | 3101 #else /* not NEW_GC */ |
428 | 3102 /* Allocate the string header */ |
438 | 3103 ALLOCATE_FIXED_TYPE (string, Lisp_String, s); |
771 | 3104 set_lheader_implementation (&s->u.lheader, &lrecord_string); |
3105 SET_C_READONLY_RECORD_HEADER (&s->u.lheader); | |
3263 | 3106 #endif /* not NEW_GC */ |
3063 | 3107 /* Don't need to XSET_STRING_ASCII_BEGIN() here because it happens in |
3108 init_string_ascii_begin(). */ | |
428 | 3109 s->plist = Qnil; |
3092 | 3110 #ifdef NEW_GC |
3111 set_lispstringp_indirect (s); | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3112 STRING_DATA_OBJECT (s) = ALLOC_NORMAL_LISP_OBJECT (string_indirect_data); |
3092 | 3113 XSTRING_INDIRECT_DATA_DATA (STRING_DATA_OBJECT (s)) = (Ibyte *) contents; |
3114 XSTRING_INDIRECT_DATA_SIZE (STRING_DATA_OBJECT (s)) = length; | |
3115 #else /* not NEW_GC */ | |
867 | 3116 set_lispstringp_data (s, (Ibyte *) contents); |
826 | 3117 set_lispstringp_length (s, length); |
3092 | 3118 #endif /* not NEW_GC */ |
793 | 3119 val = wrap_string (s); |
771 | 3120 init_string_ascii_begin (val); |
3121 sledgehammer_check_ascii_begin (val); | |
3122 | |
428 | 3123 return val; |
3124 } | |
3125 | |
3126 | |
3263 | 3127 #ifndef NEW_GC |
428 | 3128 /************************************************************************/ |
3129 /* lcrecord lists */ | |
3130 /************************************************************************/ | |
3131 | |
3132 /* Lcrecord lists are used to manage the allocation of particular | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3133 sorts of lcrecords, to avoid calling ALLOC_NORMAL_LISP_OBJECT() (and thus |
428 | 3134 malloc() and garbage-collection junk) as much as possible. |
3135 It is similar to the Blocktype class. | |
3136 | |
1204 | 3137 See detailed comment in lcrecord.h. |
3138 */ | |
3139 | |
3140 const struct memory_description free_description[] = { | |
2551 | 3141 { XD_LISP_OBJECT, offsetof (struct free_lcrecord_header, chain), 0, { 0 }, |
1204 | 3142 XD_FLAG_FREE_LISP_OBJECT }, |
3143 { XD_END } | |
3144 }; | |
3145 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3146 DEFINE_NODUMP_INTERNAL_LISP_OBJECT ("free", free, 0, free_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3147 struct free_lcrecord_header); |
1204 | 3148 |
3149 const struct memory_description lcrecord_list_description[] = { | |
2551 | 3150 { XD_LISP_OBJECT, offsetof (struct lcrecord_list, free), 0, { 0 }, |
1204 | 3151 XD_FLAG_FREE_LISP_OBJECT }, |
3152 { XD_END } | |
3153 }; | |
428 | 3154 |
3155 static Lisp_Object | |
3156 mark_lcrecord_list (Lisp_Object obj) | |
3157 { | |
3158 struct lcrecord_list *list = XLCRECORD_LIST (obj); | |
3159 Lisp_Object chain = list->free; | |
3160 | |
3161 while (!NILP (chain)) | |
3162 { | |
3163 struct lrecord_header *lheader = XRECORD_LHEADER (chain); | |
3164 struct free_lcrecord_header *free_header = | |
3165 (struct free_lcrecord_header *) lheader; | |
3166 | |
442 | 3167 gc_checking_assert |
3168 (/* There should be no other pointers to the free list. */ | |
3169 ! MARKED_RECORD_HEADER_P (lheader) | |
3170 && | |
3171 /* Only lcrecords should be here. */ | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3172 ! list->implementation->frob_block_p |
442 | 3173 && |
3174 /* Only free lcrecords should be here. */ | |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
3175 lheader->free |
442 | 3176 && |
3177 /* The type of the lcrecord must be right. */ | |
1204 | 3178 lheader->type == lrecord_type_free |
442 | 3179 && |
3180 /* So must the size. */ | |
1204 | 3181 (list->implementation->static_size == 0 || |
3182 list->implementation->static_size == list->size) | |
442 | 3183 ); |
428 | 3184 |
3185 MARK_RECORD_HEADER (lheader); | |
3186 chain = free_header->chain; | |
3187 } | |
3188 | |
3189 return Qnil; | |
3190 } | |
3191 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3192 DEFINE_NODUMP_INTERNAL_LISP_OBJECT ("lcrecord-list", lcrecord_list, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3193 mark_lcrecord_list, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3194 lcrecord_list_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3195 struct lcrecord_list); |
934 | 3196 |
428 | 3197 Lisp_Object |
665 | 3198 make_lcrecord_list (Elemcount size, |
442 | 3199 const struct lrecord_implementation *implementation) |
428 | 3200 { |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
3201 /* Don't use alloc_automanaged_lcrecord() avoid infinite recursion |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
3202 allocating this. */ |
5151
641d0cdd1d00
fix compilation problems identified by Robert Delius Royar
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3203 struct lcrecord_list *p = |
641d0cdd1d00
fix compilation problems identified by Robert Delius Royar
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3204 XLCRECORD_LIST (old_alloc_lcrecord (&lrecord_lcrecord_list)); |
428 | 3205 |
3206 p->implementation = implementation; | |
3207 p->size = size; | |
3208 p->free = Qnil; | |
793 | 3209 return wrap_lcrecord_list (p); |
428 | 3210 } |
3211 | |
3212 Lisp_Object | |
1204 | 3213 alloc_managed_lcrecord (Lisp_Object lcrecord_list) |
428 | 3214 { |
3215 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list); | |
3216 if (!NILP (list->free)) | |
3217 { | |
3218 Lisp_Object val = list->free; | |
3219 struct free_lcrecord_header *free_header = | |
3220 (struct free_lcrecord_header *) XPNTR (val); | |
1204 | 3221 struct lrecord_header *lheader = &free_header->lcheader.lheader; |
428 | 3222 |
3223 #ifdef ERROR_CHECK_GC | |
1204 | 3224 /* Major overkill here. */ |
428 | 3225 /* There should be no other pointers to the free list. */ |
442 | 3226 assert (! MARKED_RECORD_HEADER_P (lheader)); |
428 | 3227 /* Only free lcrecords should be here. */ |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
3228 assert (lheader->free); |
1204 | 3229 assert (lheader->type == lrecord_type_free); |
3230 /* Only lcrecords should be here. */ | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3231 assert (! (list->implementation->frob_block_p)); |
1204 | 3232 #if 0 /* Not used anymore, now that we set the type of the header to |
3233 lrecord_type_free. */ | |
428 | 3234 /* The type of the lcrecord must be right. */ |
442 | 3235 assert (LHEADER_IMPLEMENTATION (lheader) == list->implementation); |
1204 | 3236 #endif /* 0 */ |
428 | 3237 /* So must the size. */ |
1204 | 3238 assert (list->implementation->static_size == 0 || |
3239 list->implementation->static_size == list->size); | |
428 | 3240 #endif /* ERROR_CHECK_GC */ |
442 | 3241 |
428 | 3242 list->free = free_header->chain; |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
3243 lheader->free = 0; |
1204 | 3244 /* Put back the correct type, as we set it to lrecord_type_free. */ |
3245 lheader->type = list->implementation->lrecord_type_index; | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3246 zero_sized_lisp_object (val, list->size); |
428 | 3247 return val; |
3248 } | |
3249 else | |
5151
641d0cdd1d00
fix compilation problems identified by Robert Delius Royar
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3250 return old_alloc_sized_lcrecord (list->size, list->implementation); |
428 | 3251 } |
3252 | |
771 | 3253 /* "Free" a Lisp object LCRECORD by placing it on its associated free list |
1204 | 3254 LCRECORD_LIST; next time alloc_managed_lcrecord() is called with the |
771 | 3255 same LCRECORD_LIST as its parameter, it will return an object from the |
3256 free list, which may be this one. Be VERY VERY SURE there are no | |
3257 pointers to this object hanging around anywhere where they might be | |
3258 used! | |
3259 | |
3260 The first thing this does before making any global state change is to | |
3261 call the finalize method of the object, if it exists. */ | |
3262 | |
428 | 3263 void |
3264 free_managed_lcrecord (Lisp_Object lcrecord_list, Lisp_Object lcrecord) | |
3265 { | |
3266 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list); | |
3267 struct free_lcrecord_header *free_header = | |
3268 (struct free_lcrecord_header *) XPNTR (lcrecord); | |
442 | 3269 struct lrecord_header *lheader = &free_header->lcheader.lheader; |
3270 const struct lrecord_implementation *implementation | |
428 | 3271 = LHEADER_IMPLEMENTATION (lheader); |
3272 | |
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3273 /* If we try to debug-print during GC, we'll likely get a crash on the |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3274 following assert (called from Lstream_delete(), from prin1_to_string()). |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3275 Instead, just don't do anything. Worst comes to worst, we have a |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3276 small memory leak -- and programs being debugged usually won't be |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3277 super long-lived afterwards, anyway. */ |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3278 if (gc_in_progress && in_debug_print) |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3279 return; |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3280 |
771 | 3281 /* Finalizer methods may try to free objects within them, which typically |
3282 won't be marked and thus are scheduled for demolition. Putting them | |
3283 on the free list would be very bad, as we'd have xfree()d memory in | |
3284 the list. Even if for some reason the objects are still live | |
3285 (generally a logic error!), we still will have problems putting such | |
3286 an object on the free list right now (e.g. we'd have to avoid calling | |
3287 the finalizer twice, etc.). So basically, those finalizers should not | |
3288 be freeing any objects if during GC. Abort now to catch those | |
3289 problems. */ | |
3290 gc_checking_assert (!gc_in_progress); | |
3291 | |
428 | 3292 /* Make sure the size is correct. This will catch, for example, |
3293 putting a window configuration on the wrong free list. */ | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3294 gc_checking_assert (lisp_object_size (lcrecord) == list->size); |
771 | 3295 /* Make sure the object isn't already freed. */ |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
3296 gc_checking_assert (!lheader->free); |
2367 | 3297 /* Freeing stuff in dumped memory is bad. If you trip this, you |
3298 may need to check for this before freeing. */ | |
3299 gc_checking_assert (!OBJECT_DUMPED_P (lcrecord)); | |
771 | 3300 |
428 | 3301 if (implementation->finalizer) |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3302 implementation->finalizer (lcrecord); |
1204 | 3303 /* Yes, there are two ways to indicate freeness -- the type is |
3304 lrecord_type_free or the ->free flag is set. We used to do only the | |
3305 latter; now we do the former as well for KKCC purposes. Probably | |
3306 safer in any case, as we will lose quicker this way than keeping | |
3307 around an lrecord of apparently correct type but bogus junk in it. */ | |
3308 MARK_LRECORD_AS_FREE (lheader); | |
428 | 3309 free_header->chain = list->free; |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
3310 lheader->free = 1; |
428 | 3311 list->free = lcrecord; |
3312 } | |
3313 | |
771 | 3314 static Lisp_Object all_lcrecord_lists[countof (lrecord_implementations_table)]; |
3315 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3316 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3317 alloc_automanaged_sized_lcrecord (Bytecount size, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3318 const struct lrecord_implementation *imp) |
771 | 3319 { |
3320 if (EQ (all_lcrecord_lists[imp->lrecord_type_index], Qzero)) | |
3321 all_lcrecord_lists[imp->lrecord_type_index] = | |
3322 make_lcrecord_list (size, imp); | |
3323 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3324 return alloc_managed_lcrecord (all_lcrecord_lists[imp->lrecord_type_index]); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3325 } |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3326 |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3327 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3328 alloc_automanaged_lcrecord (const struct lrecord_implementation *imp) |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3329 { |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3330 type_checking_assert (imp->static_size > 0); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3331 return alloc_automanaged_sized_lcrecord (imp->static_size, imp); |
771 | 3332 } |
3333 | |
3334 void | |
3024 | 3335 old_free_lcrecord (Lisp_Object rec) |
771 | 3336 { |
3337 int type = XRECORD_LHEADER (rec)->type; | |
3338 | |
3339 assert (!EQ (all_lcrecord_lists[type], Qzero)); | |
3340 | |
3341 free_managed_lcrecord (all_lcrecord_lists[type], rec); | |
3342 } | |
3263 | 3343 #endif /* not NEW_GC */ |
428 | 3344 |
3345 | |
3346 /************************************************************************/ | |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3347 /* Staticpro, MCpro */ |
428 | 3348 /************************************************************************/ |
3349 | |
771 | 3350 /* We want the staticpro list relocated, but not the pointers found |
3351 therein, because they refer to locations in the global data segment, not | |
3352 in the heap; we only dump heap objects. Hence we use a trivial | |
3353 description, as for pointerless objects. (Note that the data segment | |
3354 objects, which are global variables like Qfoo or Vbar, themselves are | |
3355 pointers to heap objects. Each needs to be described to pdump as a | |
3356 "root pointer"; this happens in the call to staticpro(). */ | |
1204 | 3357 static const struct memory_description staticpro_description_1[] = { |
452 | 3358 { XD_END } |
3359 }; | |
3360 | |
1204 | 3361 static const struct sized_memory_description staticpro_description = { |
452 | 3362 sizeof (Lisp_Object *), |
3363 staticpro_description_1 | |
3364 }; | |
3365 | |
1204 | 3366 static const struct memory_description staticpros_description_1[] = { |
452 | 3367 XD_DYNARR_DESC (Lisp_Object_ptr_dynarr, &staticpro_description), |
3368 { XD_END } | |
3369 }; | |
3370 | |
1204 | 3371 static const struct sized_memory_description staticpros_description = { |
452 | 3372 sizeof (Lisp_Object_ptr_dynarr), |
3373 staticpros_description_1 | |
3374 }; | |
3375 | |
771 | 3376 #ifdef DEBUG_XEMACS |
3377 | |
3378 /* Help debug crashes gc-marking a staticpro'ed object. */ | |
3379 | |
3380 Lisp_Object_ptr_dynarr *staticpros; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3381 const_Ascbyte_ptr_dynarr *staticpro_names; |
771 | 3382 |
3383 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3384 garbage collection, and for dumping. */ | |
3385 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3386 staticpro_1 (Lisp_Object *varaddress, const Ascbyte *varname) |
771 | 3387 { |
3388 Dynarr_add (staticpros, varaddress); | |
3389 Dynarr_add (staticpro_names, varname); | |
1204 | 3390 dump_add_root_lisp_object (varaddress); |
771 | 3391 } |
3392 | |
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3393 const Ascbyte *staticpro_name (int count); |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3394 |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3395 /* External debugging function: Return the name of the variable at offset |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3396 COUNT. */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3397 const Ascbyte * |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3398 staticpro_name (int count) |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3399 { |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3400 return Dynarr_at (staticpro_names, count); |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3401 } |
771 | 3402 |
3403 Lisp_Object_ptr_dynarr *staticpros_nodump; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3404 const_Ascbyte_ptr_dynarr *staticpro_nodump_names; |
771 | 3405 |
3406 /* Mark the Lisp_Object at heap VARADDRESS as a root object for | |
3407 garbage collection, but not for dumping. (See below.) */ | |
3408 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3409 staticpro_nodump_1 (Lisp_Object *varaddress, const Ascbyte *varname) |
771 | 3410 { |
3411 Dynarr_add (staticpros_nodump, varaddress); | |
3412 Dynarr_add (staticpro_nodump_names, varname); | |
3413 } | |
3414 | |
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3415 const Ascbyte *staticpro_nodump_name (int count); |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3416 |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3417 /* External debugging function: Return the name of the variable at offset |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3418 COUNT. */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3419 const Ascbyte * |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3420 staticpro_nodump_name (int count) |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3421 { |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3422 return Dynarr_at (staticpro_nodump_names, count); |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3423 } |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3424 |
996 | 3425 #ifdef HAVE_SHLIB |
3426 /* Stop treating the Lisp_Object at non-heap VARADDRESS as a root object | |
3427 for garbage collection, but not for dumping. */ | |
3428 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3429 unstaticpro_nodump_1 (Lisp_Object *varaddress, const Ascbyte *varname) |
996 | 3430 { |
3431 Dynarr_delete_object (staticpros, varaddress); | |
3432 Dynarr_delete_object (staticpro_names, varname); | |
3433 } | |
3434 #endif | |
3435 | |
771 | 3436 #else /* not DEBUG_XEMACS */ |
3437 | |
452 | 3438 Lisp_Object_ptr_dynarr *staticpros; |
3439 | |
3440 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3441 garbage collection, and for dumping. */ | |
428 | 3442 void |
3443 staticpro (Lisp_Object *varaddress) | |
3444 { | |
452 | 3445 Dynarr_add (staticpros, varaddress); |
1204 | 3446 dump_add_root_lisp_object (varaddress); |
428 | 3447 } |
3448 | |
442 | 3449 |
452 | 3450 Lisp_Object_ptr_dynarr *staticpros_nodump; |
3451 | |
771 | 3452 /* Mark the Lisp_Object at heap VARADDRESS as a root object for garbage |
3453 collection, but not for dumping. This is used for objects where the | |
3454 only sure pointer is in the heap (rather than in the global data | |
3455 segment, as must be the case for pdump root pointers), but not inside of | |
3456 another Lisp object (where it will be marked as a result of that Lisp | |
3457 object's mark method). The call to staticpro_nodump() must occur *BOTH* | |
3458 at initialization time and at "reinitialization" time (startup, after | |
3459 pdump load.) (For example, this is the case with the predicate symbols | |
3460 for specifier and coding system types. The pointer to this symbol is | |
3461 inside of a methods structure, which is allocated on the heap. The | |
3462 methods structure will be written out to the pdump data file, and may be | |
3463 reloaded at a different address.) | |
3464 | |
3465 #### The necessity for reinitialization is a bug in pdump. Pdump should | |
3466 automatically regenerate the staticpro()s for these symbols when it | |
3467 loads the data in. */ | |
3468 | |
428 | 3469 void |
3470 staticpro_nodump (Lisp_Object *varaddress) | |
3471 { | |
452 | 3472 Dynarr_add (staticpros_nodump, varaddress); |
428 | 3473 } |
3474 | |
996 | 3475 #ifdef HAVE_SHLIB |
3476 /* Unmark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3477 garbage collection, but not for dumping. */ | |
3478 void | |
3479 unstaticpro_nodump (Lisp_Object *varaddress) | |
3480 { | |
3481 Dynarr_delete_object (staticpros, varaddress); | |
3482 } | |
3483 #endif | |
3484 | |
771 | 3485 #endif /* not DEBUG_XEMACS */ |
3486 | |
3263 | 3487 #ifdef NEW_GC |
2720 | 3488 static const struct memory_description mcpro_description_1[] = { |
3489 { XD_END } | |
3490 }; | |
3491 | |
3492 static const struct sized_memory_description mcpro_description = { | |
3493 sizeof (Lisp_Object *), | |
3494 mcpro_description_1 | |
3495 }; | |
3496 | |
3497 static const struct memory_description mcpros_description_1[] = { | |
3498 XD_DYNARR_DESC (Lisp_Object_dynarr, &mcpro_description), | |
3499 { XD_END } | |
3500 }; | |
3501 | |
3502 static const struct sized_memory_description mcpros_description = { | |
3503 sizeof (Lisp_Object_dynarr), | |
3504 mcpros_description_1 | |
3505 }; | |
3506 | |
3507 #ifdef DEBUG_XEMACS | |
3508 | |
3509 /* Help debug crashes gc-marking a mcpro'ed object. */ | |
3510 | |
3511 Lisp_Object_dynarr *mcpros; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3512 const_Ascbyte_ptr_dynarr *mcpro_names; |
2720 | 3513 |
3514 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3515 garbage collection, and for dumping. */ | |
3516 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3517 mcpro_1 (Lisp_Object varaddress, const Ascbyte *varname) |
2720 | 3518 { |
3519 Dynarr_add (mcpros, varaddress); | |
3520 Dynarr_add (mcpro_names, varname); | |
3521 } | |
3522 | |
5046 | 3523 const Ascbyte *mcpro_name (int count); |
3524 | |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3525 /* External debugging function: Return the name of the variable at offset |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3526 COUNT. */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3527 const Ascbyte * |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3528 mcpro_name (int count) |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3529 { |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3530 return Dynarr_at (mcpro_names, count); |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3531 } |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3532 |
2720 | 3533 #else /* not DEBUG_XEMACS */ |
3534 | |
3535 Lisp_Object_dynarr *mcpros; | |
3536 | |
3537 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3538 garbage collection, and for dumping. */ | |
3539 void | |
3540 mcpro (Lisp_Object varaddress) | |
3541 { | |
3542 Dynarr_add (mcpros, varaddress); | |
3543 } | |
3544 | |
3545 #endif /* not DEBUG_XEMACS */ | |
3263 | 3546 #endif /* NEW_GC */ |
3547 | |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3548 #ifdef ALLOC_TYPE_STATS |
428 | 3549 |
3550 | |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3551 /************************************************************************/ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3552 /* Determining allocation overhead */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3553 /************************************************************************/ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3554 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3555 /* Attempt to determine the actual amount of space that is used for |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3556 the block allocated starting at PTR, supposedly of size "CLAIMED_SIZE". |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3557 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3558 It seems that the following holds: |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3559 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3560 1. When using the old allocator (malloc.c): |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3561 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3562 -- blocks are always allocated in chunks of powers of two. For |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3563 each block, there is an overhead of 8 bytes if rcheck is not |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3564 defined, 20 bytes if it is defined. In other words, a |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3565 one-byte allocation needs 8 bytes of overhead for a total of |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3566 9 bytes, and needs to have 16 bytes of memory chunked out for |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3567 it. |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3568 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3569 2. When using the new allocator (gmalloc.c): |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3570 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3571 -- blocks are always allocated in chunks of powers of two up |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3572 to 4096 bytes. Larger blocks are allocated in chunks of |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3573 an integral multiple of 4096 bytes. The minimum block |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3574 size is 2*sizeof (void *), or 16 bytes if SUNOS_LOCALTIME_BUG |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3575 is defined. There is no per-block overhead, but there |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3576 is an overhead of 3*sizeof (size_t) for each 4096 bytes |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3577 allocated. |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3578 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3579 3. When using the system malloc, anything goes, but they are |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3580 generally slower and more space-efficient than the GNU |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3581 allocators. One possibly reasonable assumption to make |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3582 for want of better data is that sizeof (void *), or maybe |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3583 2 * sizeof (void *), is required as overhead and that |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3584 blocks are allocated in the minimum required size except |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3585 that some minimum block size is imposed (e.g. 16 bytes). */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3586 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3587 Bytecount |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3588 malloced_storage_size (void * UNUSED (ptr), Bytecount claimed_size, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3589 struct usage_stats *stats) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3590 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3591 Bytecount orig_claimed_size = claimed_size; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3592 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3593 #ifndef SYSTEM_MALLOC |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3594 if (claimed_size < (Bytecount) (2 * sizeof (void *))) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3595 claimed_size = 2 * sizeof (void *); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3596 # ifdef SUNOS_LOCALTIME_BUG |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3597 if (claimed_size < 16) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3598 claimed_size = 16; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3599 # endif |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3600 if (claimed_size < 4096) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3601 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3602 /* fxg: rename log->log2 to supress gcc3 shadow warning */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3603 int log2 = 1; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3604 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3605 /* compute the log base two, more or less, then use it to compute |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3606 the block size needed. */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3607 claimed_size--; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3608 /* It's big, it's heavy, it's wood! */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3609 while ((claimed_size /= 2) != 0) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3610 ++log2; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3611 claimed_size = 1; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3612 /* It's better than bad, it's good! */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3613 while (log2 > 0) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3614 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3615 claimed_size *= 2; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3616 log2--; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3617 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3618 /* We have to come up with some average about the amount of |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3619 blocks used. */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3620 if ((Bytecount) (rand () & 4095) < claimed_size) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3621 claimed_size += 3 * sizeof (void *); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3622 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3623 else |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3624 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3625 claimed_size += 4095; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3626 claimed_size &= ~4095; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3627 claimed_size += (claimed_size / 4096) * 3 * sizeof (size_t); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3628 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3629 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3630 #else |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3631 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3632 if (claimed_size < 16) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3633 claimed_size = 16; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3634 claimed_size += 2 * sizeof (void *); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3635 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3636 #endif /* system allocator */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3637 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3638 if (stats) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3639 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3640 stats->was_requested += orig_claimed_size; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3641 stats->malloc_overhead += claimed_size - orig_claimed_size; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3642 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3643 return claimed_size; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3644 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3645 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3646 #ifndef NEW_GC |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3647 static Bytecount |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3648 fixed_type_block_overhead (Bytecount size, Bytecount per_block) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3649 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3650 Bytecount overhead = 0; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3651 Bytecount storage_size = malloced_storage_size (0, per_block, 0); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3652 while (size >= per_block) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3653 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3654 size -= per_block; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3655 overhead += storage_size - per_block; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3656 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3657 if (rand () % per_block < size) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3658 overhead += storage_size - per_block; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3659 return overhead; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3660 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3661 #endif /* not NEW_GC */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3662 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3663 Bytecount |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3664 lisp_object_storage_size (Lisp_Object obj, struct usage_stats *ustats) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3665 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3666 #ifndef NEW_GC |
5179
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3667 const struct lrecord_implementation *imp; |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3668 #endif /* not NEW_GC */ |
5179
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3669 Bytecount size; |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3670 |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3671 if (!LRECORDP (obj)) |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3672 return 0; |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3673 |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3674 size = lisp_object_size (obj); |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3675 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3676 #ifdef NEW_GC |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3677 return mc_alloced_storage_size (size, ustats); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3678 #else |
5179
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3679 imp = XRECORD_LHEADER_IMPLEMENTATION (obj); |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3680 if (imp->frob_block_p) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3681 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3682 Bytecount overhead = |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3683 /* #### Always using cons_block is incorrect but close; only |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3684 string_chars_block is significantly different in size, and |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3685 it won't ever be seen in this function */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3686 fixed_type_block_overhead (size, sizeof (struct cons_block)); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3687 if (ustats) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3688 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3689 ustats->was_requested += size; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3690 ustats->malloc_overhead += overhead; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3691 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3692 return size + overhead; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3693 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3694 else |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3695 return malloced_storage_size (XPNTR (obj), size, ustats); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3696 #endif |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3697 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3698 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3699 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3700 /************************************************************************/ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3701 /* Allocation Statistics: Accumulate */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3702 /************************************************************************/ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3703 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3704 #ifdef NEW_GC |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3705 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3706 void |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3707 init_lrecord_stats (void) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3708 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3709 xzero (lrecord_stats); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3710 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3711 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3712 void |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3713 inc_lrecord_stats (Bytecount size, const struct lrecord_header *h) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3714 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3715 int type_index = h->type; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3716 if (!size) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3717 size = detagged_lisp_object_size (h); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3718 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3719 lrecord_stats[type_index].instances_in_use++; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3720 lrecord_stats[type_index].bytes_in_use += size; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3721 lrecord_stats[type_index].bytes_in_use_including_overhead |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3722 #ifdef MEMORY_USAGE_STATS |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3723 += mc_alloced_storage_size (size, 0); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3724 #else /* not MEMORY_USAGE_STATS */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3725 += size; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3726 #endif /* not MEMORY_USAGE_STATS */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3727 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3728 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3729 void |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3730 dec_lrecord_stats (Bytecount size_including_overhead, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3731 const struct lrecord_header *h) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3732 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3733 int type_index = h->type; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3734 int size = detagged_lisp_object_size (h); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3735 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3736 lrecord_stats[type_index].instances_in_use--; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3737 lrecord_stats[type_index].bytes_in_use -= size; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3738 lrecord_stats[type_index].bytes_in_use_including_overhead |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3739 -= size_including_overhead; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3740 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3741 DECREMENT_CONS_COUNTER (size); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3742 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3743 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3744 int |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3745 lrecord_stats_heap_size (void) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3746 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3747 int i; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3748 int size = 0; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3749 for (i = 0; i < countof (lrecord_implementations_table); i++) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3750 size += lrecord_stats[i].bytes_in_use; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3751 return size; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3752 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3753 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3754 #else /* not NEW_GC */ |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3755 |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3756 static void |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3757 clear_lrecord_stats (void) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3758 { |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3759 xzero (lrecord_stats); |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3760 gc_count_num_short_string_in_use = 0; |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3761 gc_count_string_total_size = 0; |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3762 gc_count_short_string_total_size = 0; |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3763 gc_count_long_string_storage_including_overhead = 0; |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3764 } |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3765 |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3766 /* Keep track of extra statistics for strings -- length of the string |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3767 characters for short and long strings, number of short and long strings. */ |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3768 static void |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3769 tick_string_stats (Lisp_String *p, int from_sweep) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3770 { |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3771 Bytecount size = p->size_; |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3772 gc_count_string_total_size += size; |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3773 if (!BIG_STRING_SIZE_P (size)) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3774 { |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3775 gc_count_short_string_total_size += size; |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3776 gc_count_num_short_string_in_use++; |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3777 } |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3778 else |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3779 gc_count_long_string_storage_including_overhead += |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3780 malloced_storage_size (p->data_, p->size_, NULL); |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3781 /* During the sweep stage, we count the total number of strings in use. |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3782 This gets those not stored in pdump storage. For pdump storage, we |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3783 need to bump the number of strings in use so as to get an accurate |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3784 count of all strings in use (pdump or not). But don't do this when |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3785 called from the sweep stage, or we will double-count. */ |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3786 if (!from_sweep) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3787 gc_count_num_string_in_use++; |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3788 } |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3789 |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3790 /* As objects are sweeped, we record statistics about their memory usage. |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3791 Currently, all lcrecords are processed this way as well as any frob-block |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3792 objects that were saved and restored as a result of the pdump process. |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3793 (See pdump_objects_unmark().) Other frob-block objects do NOT get their |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3794 statistics noted this way -- instead, as the frob blocks are swept, |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3795 COPY_INTO_LRECORD_STATS() is called, and notes statistics about the |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3796 frob blocks. */ |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3797 |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3798 void |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3799 tick_lrecord_stats (const struct lrecord_header *h, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3800 enum lrecord_alloc_status status) |
428 | 3801 { |
647 | 3802 int type_index = h->type; |
5163
57f4dcb14ad5
Don't assume a Lisp_Object will fit in a Bytecount, src/alloc.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5160
diff
changeset
|
3803 Lisp_Object obj = wrap_pointer_1 (h); |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3804 Bytecount sz = lisp_object_size (obj); |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3805 Bytecount sz_with_overhead = lisp_object_storage_size (obj, NULL); |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3806 Bytecount overhead = sz_with_overhead - sz; |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3807 |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3808 switch (status) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3809 { |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3810 case ALLOC_IN_USE: |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3811 lrecord_stats[type_index].instances_in_use++; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3812 lrecord_stats[type_index].bytes_in_use += sz; |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3813 lrecord_stats[type_index].bytes_in_use_overhead += overhead; |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3814 if (STRINGP (obj)) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3815 tick_string_stats (XSTRING (obj), 0); |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3816 #ifdef MEMORY_USAGE_STATS |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3817 { |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3818 struct generic_usage_stats stats; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3819 if (HAS_OBJECT_METH_P (obj, memory_usage)) |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3820 { |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3821 int i; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3822 int total_stats = OBJECT_PROPERTY (obj, num_extra_memusage_stats); |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3823 xzero (stats); |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3824 OBJECT_METH (obj, memory_usage, (obj, &stats)); |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3825 for (i = 0; i < total_stats; i++) |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3826 lrecord_stats[type_index].stats.othervals[i] += |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3827 stats.othervals[i]; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3828 } |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3829 } |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3830 #endif |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3831 break; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3832 case ALLOC_FREE: |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3833 lrecord_stats[type_index].instances_freed++; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3834 lrecord_stats[type_index].bytes_freed += sz; |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3835 lrecord_stats[type_index].bytes_freed_overhead += overhead; |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3836 break; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3837 case ALLOC_ON_FREE_LIST: |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3838 lrecord_stats[type_index].instances_on_free_list++; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3839 lrecord_stats[type_index].bytes_on_free_list += sz; |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3840 lrecord_stats[type_index].bytes_on_free_list_overhead += overhead; |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3841 break; |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3842 default: |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3843 ABORT (); |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3844 } |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3845 } |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3846 |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3847 inline static void |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3848 tick_lcrecord_stats (const struct lrecord_header *h, int free_p) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3849 { |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
3850 if (h->free) |
428 | 3851 { |
442 | 3852 gc_checking_assert (!free_p); |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3853 tick_lrecord_stats (h, ALLOC_ON_FREE_LIST); |
428 | 3854 } |
3855 else | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3856 tick_lrecord_stats (h, free_p ? ALLOC_FREE : ALLOC_IN_USE); |
428 | 3857 } |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3858 |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3859 #endif /* (not) NEW_GC */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3860 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3861 void |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3862 finish_object_memory_usage_stats (void) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3863 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3864 /* Here we add up the aggregate values for each statistic, previously |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3865 computed during tick_lrecord_stats(), to get a single combined value |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3866 of non-Lisp memory usage for all objects of each type. We can't |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3867 do this if NEW_GC because nothing like tick_lrecord_stats() gets |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3868 called -- instead, statistics are computed when objects are allocated, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3869 which is too early to be calling the memory_usage() method. */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3870 #if defined (MEMORY_USAGE_STATS) && !defined (NEW_GC) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3871 int i; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3872 for (i = 0; i < countof (lrecord_implementations_table); i++) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3873 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3874 struct lrecord_implementation *imp = lrecord_implementations_table[i]; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3875 if (imp && imp->num_extra_nonlisp_memusage_stats) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3876 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3877 int j; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3878 for (j = 0; j < imp->num_extra_nonlisp_memusage_stats; j++) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3879 lrecord_stats[i].nonlisp_bytes_in_use += |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3880 lrecord_stats[i].stats.othervals[j]; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3881 } |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
3882 if (imp && imp->num_extra_lisp_ancillary_memusage_stats) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
3883 { |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
3884 int j; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
3885 for (j = 0; j < imp->num_extra_lisp_ancillary_memusage_stats; j++) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
3886 lrecord_stats[i].lisp_ancillary_bytes_in_use += |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
3887 lrecord_stats[i].stats.othervals |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
3888 [j + imp->offset_lisp_ancillary_memusage_stats]; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
3889 } |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3890 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3891 #endif /* defined (MEMORY_USAGE_STATS) && !defined (NEW_GC) */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3892 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3893 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3894 #define COUNT_FROB_BLOCK_USAGE(type) \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3895 EMACS_INT s = 0; \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3896 EMACS_INT s_overhead = 0; \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3897 struct type##_block *x = current_##type##_block; \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3898 while (x) { s += sizeof (*x) + MALLOC_OVERHEAD; x = x->prev; } \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3899 s_overhead = fixed_type_block_overhead (s, sizeof (struct type##_block)); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3900 DO_NOTHING |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3901 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3902 #define COPY_INTO_LRECORD_STATS(type) \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3903 do { \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3904 COUNT_FROB_BLOCK_USAGE (type); \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3905 lrecord_stats[lrecord_type_##type].bytes_in_use += s; \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3906 lrecord_stats[lrecord_type_##type].bytes_in_use_overhead += \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3907 s_overhead; \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3908 lrecord_stats[lrecord_type_##type].instances_on_free_list += \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3909 gc_count_num_##type##_freelist; \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3910 lrecord_stats[lrecord_type_##type].instances_in_use += \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3911 gc_count_num_##type##_in_use; \ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3912 } while (0) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3913 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3914 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3915 /************************************************************************/ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3916 /* Allocation statistics: format nicely */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3917 /************************************************************************/ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3918 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3919 static Lisp_Object |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3920 gc_plist_hack (const Ascbyte *name, EMACS_INT value, Lisp_Object tail) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3921 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3922 /* C doesn't have local functions (or closures, or GC, or readable syntax, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3923 or portable numeric datatypes, or bit-vectors, or characters, or |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3924 arrays, or exceptions, or ...) */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3925 return cons3 (intern (name), make_int (value), tail); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3926 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3927 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3928 /* Pluralize a lowercase English word stored in BUF, assuming BUF has |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3929 enough space to hold the extra letters (at most 2). */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3930 static void |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3931 pluralize_word (Ascbyte *buf) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3932 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3933 Bytecount len = strlen (buf); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3934 int upper = 0; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3935 Ascbyte d, e; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3936 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3937 if (len == 0 || len == 1) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3938 goto pluralize_apostrophe_s; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3939 e = buf[len - 1]; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3940 d = buf[len - 2]; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3941 upper = isupper (e); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3942 e = tolower (e); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3943 d = tolower (d); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3944 if (e == 'y') |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3945 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3946 switch (d) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3947 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3948 case 'a': |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3949 case 'e': |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3950 case 'i': |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3951 case 'o': |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3952 case 'u': |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3953 goto pluralize_s; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3954 default: |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3955 buf[len - 1] = (upper ? 'I' : 'i'); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3956 goto pluralize_es; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3957 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3958 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3959 else if (e == 's' || e == 'x' || (e == 'h' && (d == 's' || d == 'c'))) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3960 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3961 pluralize_es: |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3962 buf[len++] = (upper ? 'E' : 'e'); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3963 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3964 pluralize_s: |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3965 buf[len++] = (upper ? 'S' : 's'); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3966 buf[len] = '\0'; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3967 return; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3968 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3969 pluralize_apostrophe_s: |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3970 buf[len++] = '\''; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3971 goto pluralize_s; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3972 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3973 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3974 static void |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3975 pluralize_and_append (Ascbyte *buf, const Ascbyte *name, const Ascbyte *suffix) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3976 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3977 strcpy (buf, name); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3978 pluralize_word (buf); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3979 strcat (buf, suffix); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3980 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3981 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3982 static Lisp_Object |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3983 object_memory_usage_stats (int set_total_gc_usage) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3984 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3985 Lisp_Object pl = Qnil; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3986 int i; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3987 EMACS_INT tgu_val = 0; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3988 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3989 #ifdef NEW_GC |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3990 for (i = 0; i < countof (lrecord_implementations_table); i++) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3991 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3992 if (lrecord_stats[i].instances_in_use != 0) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3993 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3994 Ascbyte buf[255]; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3995 const Ascbyte *name = lrecord_implementations_table[i]->name; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3996 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3997 if (lrecord_stats[i].bytes_in_use_including_overhead != |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3998 lrecord_stats[i].bytes_in_use) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3999 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4000 sprintf (buf, "%s-storage-including-overhead", name); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4001 pl = gc_plist_hack (buf, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4002 lrecord_stats[i] |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4003 .bytes_in_use_including_overhead, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4004 pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4005 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4006 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4007 sprintf (buf, "%s-storage", name); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4008 pl = gc_plist_hack (buf, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4009 lrecord_stats[i].bytes_in_use, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4010 pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4011 tgu_val += lrecord_stats[i].bytes_in_use_including_overhead; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4012 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4013 pluralize_and_append (buf, name, "-used"); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4014 pl = gc_plist_hack (buf, lrecord_stats[i].instances_in_use, pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4015 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4016 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4017 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4018 #else /* not NEW_GC */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4019 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4020 for (i = 0; i < lrecord_type_count; i++) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4021 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4022 if (lrecord_stats[i].bytes_in_use != 0 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4023 || lrecord_stats[i].bytes_freed != 0 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4024 || lrecord_stats[i].instances_on_free_list != 0) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4025 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4026 Ascbyte buf[255]; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4027 const Ascbyte *name = lrecord_implementations_table[i]->name; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4028 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4029 sprintf (buf, "%s-storage-overhead", name); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4030 pl = gc_plist_hack (buf, lrecord_stats[i].bytes_in_use_overhead, pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4031 tgu_val += lrecord_stats[i].bytes_in_use_overhead; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4032 sprintf (buf, "%s-storage", name); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4033 pl = gc_plist_hack (buf, lrecord_stats[i].bytes_in_use, pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4034 tgu_val += lrecord_stats[i].bytes_in_use; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4035 #ifdef MEMORY_USAGE_STATS |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4036 if (lrecord_stats[i].nonlisp_bytes_in_use) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4037 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4038 sprintf (buf, "%s-non-lisp-storage", name); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4039 pl = gc_plist_hack (buf, lrecord_stats[i].nonlisp_bytes_in_use, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4040 pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4041 tgu_val += lrecord_stats[i].nonlisp_bytes_in_use; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4042 } |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4043 if (lrecord_stats[i].lisp_ancillary_bytes_in_use) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4044 { |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4045 sprintf (buf, "%s-lisp-ancillary-storage", name); |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4046 pl = gc_plist_hack (buf, lrecord_stats[i]. |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4047 lisp_ancillary_bytes_in_use, |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4048 pl); |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4049 tgu_val += lrecord_stats[i].lisp_ancillary_bytes_in_use; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4050 } |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4051 #endif /* MEMORY_USAGE_STATS */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4052 pluralize_and_append (buf, name, "-freed"); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4053 if (lrecord_stats[i].instances_freed != 0) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4054 pl = gc_plist_hack (buf, lrecord_stats[i].instances_freed, pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4055 pluralize_and_append (buf, name, "-on-free-list"); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4056 if (lrecord_stats[i].instances_on_free_list != 0) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4057 pl = gc_plist_hack (buf, lrecord_stats[i].instances_on_free_list, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4058 pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4059 pluralize_and_append (buf, name, "-used"); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4060 pl = gc_plist_hack (buf, lrecord_stats[i].instances_in_use, pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4061 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4062 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4063 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4064 pl = gc_plist_hack ("long-string-chars-storage-overhead", |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4065 gc_count_long_string_storage_including_overhead - |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4066 (gc_count_string_total_size |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4067 - gc_count_short_string_total_size), pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4068 pl = gc_plist_hack ("long-string-chars-storage", |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4069 gc_count_string_total_size |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4070 - gc_count_short_string_total_size, pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4071 do |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4072 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4073 COUNT_FROB_BLOCK_USAGE (string_chars); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4074 tgu_val += s + s_overhead; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4075 pl = gc_plist_hack ("short-string-chars-storage-overhead", s_overhead, pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4076 pl = gc_plist_hack ("short-string-chars-storage", s, pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4077 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4078 while (0); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4079 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4080 pl = gc_plist_hack ("long-strings-total-length", |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4081 gc_count_string_total_size |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4082 - gc_count_short_string_total_size, pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4083 pl = gc_plist_hack ("short-strings-total-length", |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4084 gc_count_short_string_total_size, pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4085 pl = gc_plist_hack ("long-strings-used", |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4086 gc_count_num_string_in_use |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4087 - gc_count_num_short_string_in_use, pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4088 pl = gc_plist_hack ("short-strings-used", |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4089 gc_count_num_short_string_in_use, pl); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4090 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4091 #endif /* NEW_GC */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4092 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4093 if (set_total_gc_usage) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4094 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4095 total_gc_usage = tgu_val; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4096 total_gc_usage_set = 1; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4097 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4098 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4099 return pl; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4100 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4101 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4102 static Lisp_Object |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4103 garbage_collection_statistics (void) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4104 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4105 /* The things we do for backwards-compatibility */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4106 #ifdef NEW_GC |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4107 return |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4108 list6 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4109 (Fcons (make_int (lrecord_stats[lrecord_type_cons].instances_in_use), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4110 make_int (lrecord_stats[lrecord_type_cons] |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4111 .bytes_in_use_including_overhead)), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4112 Fcons (make_int (lrecord_stats[lrecord_type_symbol].instances_in_use), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4113 make_int (lrecord_stats[lrecord_type_symbol] |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4114 .bytes_in_use_including_overhead)), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4115 Fcons (make_int (lrecord_stats[lrecord_type_marker].instances_in_use), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4116 make_int (lrecord_stats[lrecord_type_marker] |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4117 .bytes_in_use_including_overhead)), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4118 make_int (lrecord_stats[lrecord_type_string] |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4119 .bytes_in_use_including_overhead), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4120 make_int (lrecord_stats[lrecord_type_vector] |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4121 .bytes_in_use_including_overhead), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4122 object_memory_usage_stats (1)); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4123 #else /* not NEW_GC */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4124 return |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4125 list6 (Fcons (make_int (gc_count_num_cons_in_use), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4126 make_int (gc_count_num_cons_freelist)), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4127 Fcons (make_int (gc_count_num_symbol_in_use), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4128 make_int (gc_count_num_symbol_freelist)), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4129 Fcons (make_int (gc_count_num_marker_in_use), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4130 make_int (gc_count_num_marker_freelist)), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4131 make_int (gc_count_string_total_size), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4132 make_int (lrecord_stats[lrecord_type_vector].bytes_in_use + |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4133 lrecord_stats[lrecord_type_vector].bytes_freed + |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4134 lrecord_stats[lrecord_type_vector].bytes_on_free_list), |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4135 object_memory_usage_stats (1)); |
3263 | 4136 #endif /* not NEW_GC */ |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4137 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4138 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4139 DEFUN ("object-memory-usage-stats", Fobject_memory_usage_stats, 0, 0, 0, /* |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4140 Return statistics about memory usage of Lisp objects. |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4141 */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4142 ()) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4143 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4144 return object_memory_usage_stats (0); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4145 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4146 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4147 #endif /* ALLOC_TYPE_STATS */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4148 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4149 #ifdef MEMORY_USAGE_STATS |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4150 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4151 DEFUN ("object-memory-usage", Fobject_memory_usage, 1, 1, 0, /* |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4152 Return stats about the memory usage of OBJECT. |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4153 The values returned are in the form of an alist of usage types and byte |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4154 counts. The byte counts attempt to encompass all the memory used |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4155 by the object (separate from the memory logically associated with any |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4156 other object), including internal structures and any malloc() |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4157 overhead associated with them. In practice, the byte counts are |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4158 underestimated because certain memory usage is very hard to determine |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4159 \(e.g. the amount of memory used inside the Xt library or inside the |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4160 X server). |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4161 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4162 Multiple slices of the total memory usage may be returned, separated |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4163 by a nil. Each slice represents a particular view of the memory, a |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4164 particular way of partitioning it into groups. Within a slice, there |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4165 is no overlap between the groups of memory, and each slice collectively |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4166 represents all the memory concerned. The rightmost slice typically |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4167 represents the total memory used plus malloc and dynarr overhead. |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4168 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4169 Slices describing other Lisp objects logically associated with the |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4170 object may be included, separated from other slices by `t' and from |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4171 each other by nil if there is more than one. |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4172 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4173 #### We have to figure out how to handle the memory used by the object |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4174 itself vs. the memory used by substructures. Probably the memory_usage |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4175 method should return info only about substructures and related Lisp |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4176 objects, since the caller can always find and all info about the object |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4177 itself. |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4178 */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4179 (object)) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4180 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4181 struct generic_usage_stats gustats; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4182 struct usage_stats object_stats; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4183 int i; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4184 Lisp_Object val = Qnil; |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4185 Lisp_Object stats_list; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4186 |
5179
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4187 if (!LRECORDP (object)) |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4188 invalid_argument |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4189 ("No memory associated with immediate objects (int or char)", object); |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4190 |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4191 stats_list = OBJECT_PROPERTY (object, memusage_stats_list); |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4192 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4193 xzero (object_stats); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4194 lisp_object_storage_size (object, &object_stats); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4195 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4196 val = acons (Qobject_actually_requested, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4197 make_int (object_stats.was_requested), val); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4198 val = acons (Qobject_malloc_overhead, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4199 make_int (object_stats.malloc_overhead), val); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4200 assert (!object_stats.dynarr_overhead); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4201 assert (!object_stats.gap_overhead); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4202 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4203 if (!NILP (stats_list)) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4204 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4205 xzero (gustats); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4206 MAYBE_OBJECT_METH (object, memory_usage, (object, &gustats)); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4207 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4208 val = Fcons (Qt, val); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4209 val = acons (Qother_memory_actually_requested, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4210 make_int (gustats.u.was_requested), val); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4211 val = acons (Qother_memory_malloc_overhead, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4212 make_int (gustats.u.malloc_overhead), val); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4213 if (gustats.u.dynarr_overhead) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4214 val = acons (Qother_memory_dynarr_overhead, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4215 make_int (gustats.u.dynarr_overhead), val); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4216 if (gustats.u.gap_overhead) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4217 val = acons (Qother_memory_gap_overhead, |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4218 make_int (gustats.u.gap_overhead), val); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4219 val = Fcons (Qnil, val); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4220 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4221 i = 0; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4222 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4223 LIST_LOOP_2 (item, stats_list) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4224 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4225 if (NILP (item) || EQ (item, Qt)) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4226 val = Fcons (item, val); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4227 else |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4228 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4229 val = acons (item, make_int (gustats.othervals[i]), val); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4230 i++; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4231 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4232 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4233 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4234 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4235 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4236 return Fnreverse (val); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4237 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4238 |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4239 /* Compute total memory usage associated with an object, including |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4240 |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4241 (a) Storage (including overhead) allocated to the object itself |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4242 (b) Storage (including overhead) for ancillary non-Lisp structures attached |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4243 to the object |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4244 (c) Storage (including overhead) for ancillary Lisp objects attached |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4245 to the object |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4246 |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4247 Store the three types of memory into the return values provided they |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4248 aren't NULL, and return a sum of the three values. Also store the |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4249 structure of individual statistics into STATS if non-zero. |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4250 |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4251 Note that the value for type (c) is the sum of all three types of |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4252 memory associated with the ancillary Lisp objects. |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4253 */ |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4254 |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4255 Bytecount |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4256 lisp_object_memory_usage_full (Lisp_Object object, Bytecount *storage_size, |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4257 Bytecount *extra_nonlisp_storage, |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4258 Bytecount *extra_lisp_ancillary_storage, |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4259 struct generic_usage_stats *stats) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4260 { |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4261 Bytecount total; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4262 |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4263 total = lisp_object_storage_size (object, NULL); |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4264 if (storage_size) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4265 *storage_size = total; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4266 |
5179
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4267 if (LRECORDP (object) && HAS_OBJECT_METH_P (object, memory_usage)) |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4268 { |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4269 int i; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4270 struct generic_usage_stats gustats; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4271 Bytecount sum; |
5179
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4272 struct lrecord_implementation *imp = |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4273 XRECORD_LHEADER_IMPLEMENTATION (object); |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4274 |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4275 xzero (gustats); |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4276 OBJECT_METH (object, memory_usage, (object, &gustats)); |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4277 |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4278 if (stats) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4279 *stats = gustats; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4280 |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4281 sum = 0; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4282 for (i = 0; i < imp->num_extra_nonlisp_memusage_stats; i++) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4283 sum += gustats.othervals[i]; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4284 total += sum; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4285 if (extra_nonlisp_storage) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4286 *extra_nonlisp_storage = sum; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4287 |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4288 sum = 0; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4289 for (i = 0; i < imp->num_extra_lisp_ancillary_memusage_stats; i++) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4290 sum += gustats.othervals[imp->offset_lisp_ancillary_memusage_stats + |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4291 i]; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4292 total += sum; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4293 if (extra_lisp_ancillary_storage) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4294 *extra_lisp_ancillary_storage = sum; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4295 } |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4296 else |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4297 { |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4298 if (extra_nonlisp_storage) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4299 *extra_nonlisp_storage = 0; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4300 if (extra_lisp_ancillary_storage) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4301 *extra_lisp_ancillary_storage = 0; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4302 } |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4303 |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4304 return total; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4305 } |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4306 |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4307 |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4308 Bytecount |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4309 lisp_object_memory_usage (Lisp_Object object) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4310 { |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4311 return lisp_object_memory_usage_full (object, NULL, NULL, NULL, NULL); |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4312 } |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4313 |
5179
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4314 static Bytecount |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4315 tree_memory_usage_1 (Lisp_Object arg, int vectorp, int depth) |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4316 { |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4317 Bytecount total = 0; |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4318 |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4319 if (depth > 200) |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4320 return total; |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4321 |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4322 if (CONSP (arg)) |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4323 { |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4324 SAFE_LIST_LOOP_3 (elt, arg, tail) |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4325 { |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4326 total += lisp_object_memory_usage (tail); |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4327 if (CONSP (elt) || VECTORP (elt)) |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4328 total += tree_memory_usage_1 (elt, vectorp, depth + 1); |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4329 if (VECTORP (XCDR (tail))) /* hack for (a b . [c d]) */ |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4330 total += tree_memory_usage_1 (XCDR (tail), vectorp, depth +1); |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4331 } |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4332 } |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4333 else if (VECTORP (arg) && vectorp) |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4334 { |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4335 int i = XVECTOR_LENGTH (arg); |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4336 int j; |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4337 total += lisp_object_memory_usage (arg); |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4338 for (j = 0; j < i; j++) |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4339 { |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4340 Lisp_Object elt = XVECTOR_DATA (arg) [j]; |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4341 if (CONSP (elt) || VECTORP (elt)) |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4342 total += tree_memory_usage_1 (elt, vectorp, depth + 1); |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4343 } |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4344 } |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4345 return total; |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4346 } |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4347 |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4348 Bytecount |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4349 tree_memory_usage (Lisp_Object arg, int vectorp) |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4350 { |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4351 return tree_memory_usage_1 (arg, vectorp, 0); |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4352 } |
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4353 |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4354 #endif /* MEMORY_USAGE_STATS */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4355 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4356 #ifdef ALLOC_TYPE_STATS |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4357 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4358 DEFUN ("total-object-memory-usage", Ftotal_object_memory_usage, 0, 0, 0, /* |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4359 Return total number of bytes used for object storage in XEmacs. |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4360 This may be helpful in debugging XEmacs's memory usage. |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4361 See also `consing-since-gc' and `object-memory-usage-stats'. |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4362 */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4363 ()) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4364 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4365 return make_int (total_gc_usage + consing_since_gc); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4366 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4367 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4368 #endif /* ALLOC_TYPE_STATS */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4369 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4370 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4371 /************************************************************************/ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4372 /* Allocation statistics: Initialization */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4373 /************************************************************************/ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4374 #ifdef MEMORY_USAGE_STATS |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4375 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4376 /* Compute the number of extra memory-usage statistics associated with an |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4377 object. We can't compute this at the time INIT_LISP_OBJECT() is called |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4378 because the value of the `memusage_stats_list' property is generally |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4379 set afterwards. So we compute the values for all types of objects |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4380 after all objects have been initialized. */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4381 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4382 static void |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4383 compute_memusage_stats_length (void) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4384 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4385 int i; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4386 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4387 for (i = 0; i < countof (lrecord_implementations_table); i++) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4388 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4389 struct lrecord_implementation *imp = lrecord_implementations_table[i]; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4390 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4391 if (!imp) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4392 continue; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4393 /* For some of the early objects, Qnil was not yet initialized at |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4394 the time of object initialization, so it came up as Qnull_pointer. |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4395 Fix that now. */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4396 if (EQ (imp->memusage_stats_list, Qnull_pointer)) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4397 imp->memusage_stats_list = Qnil; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4398 { |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4399 Elemcount len = 0; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4400 Elemcount nonlisp_len = 0; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4401 Elemcount lisp_len = 0; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4402 Elemcount lisp_offset = 0; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4403 int group_num = 0; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4404 int slice_num = 0; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4405 |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4406 LIST_LOOP_2 (item, imp->memusage_stats_list) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4407 { |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4408 if (EQ (item, Qt)) |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4409 { |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4410 group_num++; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4411 if (group_num == 1) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4412 lisp_offset = len; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4413 slice_num = 0; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4414 } |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4415 else if (EQ (item, Qnil)) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4416 { |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4417 slice_num++; |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4418 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4419 else |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4420 { |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4421 if (slice_num == 0) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4422 { |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4423 if (group_num == 0) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4424 nonlisp_len++; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4425 else if (group_num == 1) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4426 lisp_len++; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4427 } |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4428 len++; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4429 } |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4430 } |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4431 |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4432 imp->num_extra_memusage_stats = len; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4433 imp->num_extra_nonlisp_memusage_stats = nonlisp_len; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4434 imp->num_extra_lisp_ancillary_memusage_stats = lisp_len; |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4435 imp->offset_lisp_ancillary_memusage_stats = lisp_offset; |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4436 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4437 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4438 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4439 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4440 #endif /* MEMORY_USAGE_STATS */ |
428 | 4441 |
4442 | |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
4443 /************************************************************************/ |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
4444 /* Garbage Collection -- Sweep/Compact */ |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
4445 /************************************************************************/ |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
4446 |
3263 | 4447 #ifndef NEW_GC |
428 | 4448 /* Free all unmarked records */ |
4449 static void | |
3024 | 4450 sweep_lcrecords_1 (struct old_lcrecord_header **prev, int *used) |
4451 { | |
4452 struct old_lcrecord_header *header; | |
428 | 4453 int num_used = 0; |
4454 /* int total_size = 0; */ | |
4455 | |
4456 /* First go through and call all the finalize methods. | |
4457 Then go through and free the objects. There used to | |
4458 be only one loop here, with the call to the finalizer | |
4459 occurring directly before the xfree() below. That | |
4460 is marginally faster but much less safe -- if the | |
4461 finalize method for an object needs to reference any | |
4462 other objects contained within it (and many do), | |
4463 we could easily be screwed by having already freed that | |
4464 other object. */ | |
4465 | |
4466 for (header = *prev; header; header = header->next) | |
4467 { | |
4468 struct lrecord_header *h = &(header->lheader); | |
442 | 4469 |
4470 GC_CHECK_LHEADER_INVARIANTS (h); | |
4471 | |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
4472 if (! MARKED_RECORD_HEADER_P (h) && !h->free) |
428 | 4473 { |
4474 if (LHEADER_IMPLEMENTATION (h)->finalizer) | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
4475 LHEADER_IMPLEMENTATION (h)->finalizer (wrap_pointer_1 (h)); |
428 | 4476 } |
4477 } | |
4478 | |
4479 for (header = *prev; header; ) | |
4480 { | |
4481 struct lrecord_header *h = &(header->lheader); | |
442 | 4482 if (MARKED_RECORD_HEADER_P (h)) |
428 | 4483 { |
442 | 4484 if (! C_READONLY_RECORD_HEADER_P (h)) |
428 | 4485 UNMARK_RECORD_HEADER (h); |
4486 num_used++; | |
4487 /* total_size += n->implementation->size_in_bytes (h);*/ | |
440 | 4488 /* #### May modify header->next on a C_READONLY lcrecord */ |
428 | 4489 prev = &(header->next); |
4490 header = *prev; | |
4491 tick_lcrecord_stats (h, 0); | |
4492 } | |
4493 else | |
4494 { | |
3024 | 4495 struct old_lcrecord_header *next = header->next; |
428 | 4496 *prev = next; |
4497 tick_lcrecord_stats (h, 1); | |
4498 /* used to call finalizer right here. */ | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
4499 xfree (header); |
428 | 4500 header = next; |
4501 } | |
4502 } | |
4503 *used = num_used; | |
4504 /* *total = total_size; */ | |
4505 } | |
4506 | |
4507 /* And the Lord said: Thou shalt use the `c-backslash-region' command | |
4508 to make macros prettier. */ | |
4509 | |
4510 #ifdef ERROR_CHECK_GC | |
4511 | |
771 | 4512 #define SWEEP_FIXED_TYPE_BLOCK_1(typename, obj_type, lheader) \ |
428 | 4513 do { \ |
4514 struct typename##_block *SFTB_current; \ | |
4515 int SFTB_limit; \ | |
4516 int num_free = 0, num_used = 0; \ | |
4517 \ | |
444 | 4518 for (SFTB_current = current_##typename##_block, \ |
428 | 4519 SFTB_limit = current_##typename##_block_index; \ |
4520 SFTB_current; \ | |
4521 ) \ | |
4522 { \ | |
4523 int SFTB_iii; \ | |
4524 \ | |
4525 for (SFTB_iii = 0; SFTB_iii < SFTB_limit; SFTB_iii++) \ | |
4526 { \ | |
4527 obj_type *SFTB_victim = &(SFTB_current->block[SFTB_iii]); \ | |
4528 \ | |
454 | 4529 if (LRECORD_FREE_P (SFTB_victim)) \ |
428 | 4530 { \ |
4531 num_free++; \ | |
4532 } \ | |
4533 else if (C_READONLY_RECORD_HEADER_P (&SFTB_victim->lheader)) \ | |
4534 { \ | |
4535 num_used++; \ | |
4536 } \ | |
442 | 4537 else if (! MARKED_RECORD_HEADER_P (&SFTB_victim->lheader)) \ |
428 | 4538 { \ |
4539 num_free++; \ | |
4540 FREE_FIXED_TYPE (typename, obj_type, SFTB_victim); \ | |
4541 } \ | |
4542 else \ | |
4543 { \ | |
4544 num_used++; \ | |
4545 UNMARK_##typename (SFTB_victim); \ | |
4546 } \ | |
4547 } \ | |
4548 SFTB_current = SFTB_current->prev; \ | |
4549 SFTB_limit = countof (current_##typename##_block->block); \ | |
4550 } \ | |
4551 \ | |
4552 gc_count_num_##typename##_in_use = num_used; \ | |
4553 gc_count_num_##typename##_freelist = num_free; \ | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4554 COPY_INTO_LRECORD_STATS (typename); \ |
428 | 4555 } while (0) |
4556 | |
4557 #else /* !ERROR_CHECK_GC */ | |
4558 | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4559 #define SWEEP_FIXED_TYPE_BLOCK_1(typename, obj_type, lheader) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4560 do { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4561 struct typename##_block *SFTB_current; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4562 struct typename##_block **SFTB_prev; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4563 int SFTB_limit; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4564 int num_free = 0, num_used = 0; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4565 \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4566 typename##_free_list = 0; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4567 \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4568 for (SFTB_prev = ¤t_##typename##_block, \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4569 SFTB_current = current_##typename##_block, \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4570 SFTB_limit = current_##typename##_block_index; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4571 SFTB_current; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4572 ) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4573 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4574 int SFTB_iii; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4575 int SFTB_empty = 1; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4576 Lisp_Free *SFTB_old_free_list = typename##_free_list; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4577 \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4578 for (SFTB_iii = 0; SFTB_iii < SFTB_limit; SFTB_iii++) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4579 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4580 obj_type *SFTB_victim = &(SFTB_current->block[SFTB_iii]); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4581 \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4582 if (LRECORD_FREE_P (SFTB_victim)) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4583 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4584 num_free++; \ |
771 | 4585 PUT_FIXED_TYPE_ON_FREE_LIST (typename, obj_type, SFTB_victim); \ |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4586 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4587 else if (C_READONLY_RECORD_HEADER_P (&SFTB_victim->lheader)) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4588 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4589 SFTB_empty = 0; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4590 num_used++; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4591 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4592 else if (! MARKED_RECORD_HEADER_P (&SFTB_victim->lheader)) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4593 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4594 num_free++; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4595 FREE_FIXED_TYPE (typename, obj_type, SFTB_victim); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4596 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4597 else \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4598 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4599 SFTB_empty = 0; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4600 num_used++; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4601 UNMARK_##typename (SFTB_victim); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4602 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4603 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4604 if (!SFTB_empty) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4605 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4606 SFTB_prev = &(SFTB_current->prev); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4607 SFTB_current = SFTB_current->prev; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4608 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4609 else if (SFTB_current == current_##typename##_block \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4610 && !SFTB_current->prev) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4611 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4612 /* No real point in freeing sole allocation block */ \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4613 break; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4614 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4615 else \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4616 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4617 struct typename##_block *SFTB_victim_block = SFTB_current; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4618 if (SFTB_victim_block == current_##typename##_block) \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4619 current_##typename##_block_index \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4620 = countof (current_##typename##_block->block); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4621 SFTB_current = SFTB_current->prev; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4622 { \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4623 *SFTB_prev = SFTB_current; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4624 xfree (SFTB_victim_block); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4625 /* Restore free list to what it was before victim was swept */ \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4626 typename##_free_list = SFTB_old_free_list; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4627 num_free -= SFTB_limit; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4628 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4629 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4630 SFTB_limit = countof (current_##typename##_block->block); \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4631 } \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4632 \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4633 gc_count_num_##typename##_in_use = num_used; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4634 gc_count_num_##typename##_freelist = num_free; \ |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4635 COPY_INTO_LRECORD_STATS (typename); \ |
428 | 4636 } while (0) |
4637 | |
4638 #endif /* !ERROR_CHECK_GC */ | |
4639 | |
771 | 4640 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \ |
4641 SWEEP_FIXED_TYPE_BLOCK_1 (typename, obj_type, lheader) | |
4642 | |
3263 | 4643 #endif /* not NEW_GC */ |
2720 | 4644 |
428 | 4645 |
3263 | 4646 #ifndef NEW_GC |
428 | 4647 static void |
4648 sweep_conses (void) | |
4649 { | |
4650 #define UNMARK_cons(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4651 #define ADDITIONAL_FREE_cons(ptr) | |
4652 | |
440 | 4653 SWEEP_FIXED_TYPE_BLOCK (cons, Lisp_Cons); |
428 | 4654 } |
3263 | 4655 #endif /* not NEW_GC */ |
428 | 4656 |
4657 /* Explicitly free a cons cell. */ | |
4658 void | |
853 | 4659 free_cons (Lisp_Object cons) |
428 | 4660 { |
3263 | 4661 #ifndef NEW_GC /* to avoid compiler warning */ |
853 | 4662 Lisp_Cons *ptr = XCONS (cons); |
3263 | 4663 #endif /* not NEW_GC */ |
853 | 4664 |
428 | 4665 #ifdef ERROR_CHECK_GC |
3263 | 4666 #ifdef NEW_GC |
2720 | 4667 Lisp_Cons *ptr = XCONS (cons); |
3263 | 4668 #endif /* NEW_GC */ |
428 | 4669 /* If the CAR is not an int, then it will be a pointer, which will |
4670 always be four-byte aligned. If this cons cell has already been | |
4671 placed on the free list, however, its car will probably contain | |
4672 a chain pointer to the next cons on the list, which has cleverly | |
4673 had all its 0's and 1's inverted. This allows for a quick | |
1204 | 4674 check to make sure we're not freeing something already freed. |
4675 | |
4676 NOTE: This check may not be necessary. Freeing an object sets its | |
4677 type to lrecord_type_free, which will trip up the XCONS() above -- as | |
4678 well as a check in FREE_FIXED_TYPE(). */ | |
853 | 4679 if (POINTER_TYPE_P (XTYPE (cons_car (ptr)))) |
4680 ASSERT_VALID_POINTER (XPNTR (cons_car (ptr))); | |
428 | 4681 #endif /* ERROR_CHECK_GC */ |
4682 | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4683 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (cons, cons, Lisp_Cons, ptr); |
428 | 4684 } |
4685 | |
4686 /* explicitly free a list. You **must make sure** that you have | |
4687 created all the cons cells that make up this list and that there | |
4688 are no pointers to any of these cons cells anywhere else. If there | |
4689 are, you will lose. */ | |
4690 | |
4691 void | |
4692 free_list (Lisp_Object list) | |
4693 { | |
4694 Lisp_Object rest, next; | |
4695 | |
4696 for (rest = list; !NILP (rest); rest = next) | |
4697 { | |
4698 next = XCDR (rest); | |
853 | 4699 free_cons (rest); |
428 | 4700 } |
4701 } | |
4702 | |
4703 /* explicitly free an alist. You **must make sure** that you have | |
4704 created all the cons cells that make up this alist and that there | |
4705 are no pointers to any of these cons cells anywhere else. If there | |
4706 are, you will lose. */ | |
4707 | |
4708 void | |
4709 free_alist (Lisp_Object alist) | |
4710 { | |
4711 Lisp_Object rest, next; | |
4712 | |
4713 for (rest = alist; !NILP (rest); rest = next) | |
4714 { | |
4715 next = XCDR (rest); | |
853 | 4716 free_cons (XCAR (rest)); |
4717 free_cons (rest); | |
428 | 4718 } |
4719 } | |
4720 | |
3263 | 4721 #ifndef NEW_GC |
428 | 4722 static void |
4723 sweep_compiled_functions (void) | |
4724 { | |
4725 #define UNMARK_compiled_function(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
945 | 4726 #define ADDITIONAL_FREE_compiled_function(ptr) \ |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
4727 if (ptr->args_in_array) xfree (ptr->args) |
428 | 4728 |
4729 SWEEP_FIXED_TYPE_BLOCK (compiled_function, Lisp_Compiled_Function); | |
4730 } | |
4731 | |
4732 static void | |
4733 sweep_floats (void) | |
4734 { | |
4735 #define UNMARK_float(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4736 #define ADDITIONAL_FREE_float(ptr) | |
4737 | |
440 | 4738 SWEEP_FIXED_TYPE_BLOCK (float, Lisp_Float); |
428 | 4739 } |
4740 | |
1983 | 4741 #ifdef HAVE_BIGNUM |
4742 static void | |
4743 sweep_bignums (void) | |
4744 { | |
4745 #define UNMARK_bignum(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4746 #define ADDITIONAL_FREE_bignum(ptr) bignum_fini (ptr->data) | |
4747 | |
4748 SWEEP_FIXED_TYPE_BLOCK (bignum, Lisp_Bignum); | |
4749 } | |
4750 #endif /* HAVE_BIGNUM */ | |
4751 | |
4752 #ifdef HAVE_RATIO | |
4753 static void | |
4754 sweep_ratios (void) | |
4755 { | |
4756 #define UNMARK_ratio(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4757 #define ADDITIONAL_FREE_ratio(ptr) ratio_fini (ptr->data) | |
4758 | |
4759 SWEEP_FIXED_TYPE_BLOCK (ratio, Lisp_Ratio); | |
4760 } | |
4761 #endif /* HAVE_RATIO */ | |
4762 | |
4763 #ifdef HAVE_BIGFLOAT | |
4764 static void | |
4765 sweep_bigfloats (void) | |
4766 { | |
4767 #define UNMARK_bigfloat(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4768 #define ADDITIONAL_FREE_bigfloat(ptr) bigfloat_fini (ptr->bf) | |
4769 | |
4770 SWEEP_FIXED_TYPE_BLOCK (bigfloat, Lisp_Bigfloat); | |
4771 } | |
4772 #endif | |
4773 | |
428 | 4774 static void |
4775 sweep_symbols (void) | |
4776 { | |
4777 #define UNMARK_symbol(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4778 #define ADDITIONAL_FREE_symbol(ptr) | |
4779 | |
440 | 4780 SWEEP_FIXED_TYPE_BLOCK (symbol, Lisp_Symbol); |
428 | 4781 } |
4782 | |
4783 static void | |
4784 sweep_extents (void) | |
4785 { | |
4786 #define UNMARK_extent(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4787 #define ADDITIONAL_FREE_extent(ptr) | |
4788 | |
4789 SWEEP_FIXED_TYPE_BLOCK (extent, struct extent); | |
4790 } | |
4791 | |
4792 static void | |
4793 sweep_events (void) | |
4794 { | |
4795 #define UNMARK_event(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4796 #define ADDITIONAL_FREE_event(ptr) | |
4797 | |
440 | 4798 SWEEP_FIXED_TYPE_BLOCK (event, Lisp_Event); |
428 | 4799 } |
3263 | 4800 #endif /* not NEW_GC */ |
428 | 4801 |
1204 | 4802 #ifdef EVENT_DATA_AS_OBJECTS |
934 | 4803 |
3263 | 4804 #ifndef NEW_GC |
934 | 4805 static void |
4806 sweep_key_data (void) | |
4807 { | |
4808 #define UNMARK_key_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4809 #define ADDITIONAL_FREE_key_data(ptr) | |
4810 | |
4811 SWEEP_FIXED_TYPE_BLOCK (key_data, Lisp_Key_Data); | |
4812 } | |
3263 | 4813 #endif /* not NEW_GC */ |
934 | 4814 |
1204 | 4815 void |
4816 free_key_data (Lisp_Object ptr) | |
4817 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4818 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, key_data, Lisp_Key_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4819 XKEY_DATA (ptr)); |
2720 | 4820 } |
4821 | |
3263 | 4822 #ifndef NEW_GC |
934 | 4823 static void |
4824 sweep_button_data (void) | |
4825 { | |
4826 #define UNMARK_button_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4827 #define ADDITIONAL_FREE_button_data(ptr) | |
4828 | |
4829 SWEEP_FIXED_TYPE_BLOCK (button_data, Lisp_Button_Data); | |
4830 } | |
3263 | 4831 #endif /* not NEW_GC */ |
934 | 4832 |
1204 | 4833 void |
4834 free_button_data (Lisp_Object ptr) | |
4835 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4836 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, button_data, Lisp_Button_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4837 XBUTTON_DATA (ptr)); |
2720 | 4838 } |
4839 | |
3263 | 4840 #ifndef NEW_GC |
934 | 4841 static void |
4842 sweep_motion_data (void) | |
4843 { | |
4844 #define UNMARK_motion_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4845 #define ADDITIONAL_FREE_motion_data(ptr) | |
4846 | |
4847 SWEEP_FIXED_TYPE_BLOCK (motion_data, Lisp_Motion_Data); | |
4848 } | |
3263 | 4849 #endif /* not NEW_GC */ |
934 | 4850 |
1204 | 4851 void |
4852 free_motion_data (Lisp_Object ptr) | |
4853 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4854 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, motion_data, Lisp_Motion_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4855 XMOTION_DATA (ptr)); |
2720 | 4856 } |
4857 | |
3263 | 4858 #ifndef NEW_GC |
934 | 4859 static void |
4860 sweep_process_data (void) | |
4861 { | |
4862 #define UNMARK_process_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4863 #define ADDITIONAL_FREE_process_data(ptr) | |
4864 | |
4865 SWEEP_FIXED_TYPE_BLOCK (process_data, Lisp_Process_Data); | |
4866 } | |
3263 | 4867 #endif /* not NEW_GC */ |
934 | 4868 |
1204 | 4869 void |
4870 free_process_data (Lisp_Object ptr) | |
4871 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4872 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, process_data, Lisp_Process_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4873 XPROCESS_DATA (ptr)); |
2720 | 4874 } |
4875 | |
3263 | 4876 #ifndef NEW_GC |
934 | 4877 static void |
4878 sweep_timeout_data (void) | |
4879 { | |
4880 #define UNMARK_timeout_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4881 #define ADDITIONAL_FREE_timeout_data(ptr) | |
4882 | |
4883 SWEEP_FIXED_TYPE_BLOCK (timeout_data, Lisp_Timeout_Data); | |
4884 } | |
3263 | 4885 #endif /* not NEW_GC */ |
934 | 4886 |
1204 | 4887 void |
4888 free_timeout_data (Lisp_Object ptr) | |
4889 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4890 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, timeout_data, Lisp_Timeout_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4891 XTIMEOUT_DATA (ptr)); |
2720 | 4892 } |
4893 | |
3263 | 4894 #ifndef NEW_GC |
934 | 4895 static void |
4896 sweep_magic_data (void) | |
4897 { | |
4898 #define UNMARK_magic_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4899 #define ADDITIONAL_FREE_magic_data(ptr) | |
4900 | |
4901 SWEEP_FIXED_TYPE_BLOCK (magic_data, Lisp_Magic_Data); | |
4902 } | |
3263 | 4903 #endif /* not NEW_GC */ |
934 | 4904 |
1204 | 4905 void |
4906 free_magic_data (Lisp_Object ptr) | |
4907 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4908 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, magic_data, Lisp_Magic_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4909 XMAGIC_DATA (ptr)); |
2720 | 4910 } |
4911 | |
3263 | 4912 #ifndef NEW_GC |
934 | 4913 static void |
4914 sweep_magic_eval_data (void) | |
4915 { | |
4916 #define UNMARK_magic_eval_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4917 #define ADDITIONAL_FREE_magic_eval_data(ptr) | |
4918 | |
4919 SWEEP_FIXED_TYPE_BLOCK (magic_eval_data, Lisp_Magic_Eval_Data); | |
4920 } | |
3263 | 4921 #endif /* not NEW_GC */ |
934 | 4922 |
1204 | 4923 void |
4924 free_magic_eval_data (Lisp_Object ptr) | |
4925 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4926 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, magic_eval_data, Lisp_Magic_Eval_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4927 XMAGIC_EVAL_DATA (ptr)); |
2720 | 4928 } |
4929 | |
3263 | 4930 #ifndef NEW_GC |
934 | 4931 static void |
4932 sweep_eval_data (void) | |
4933 { | |
4934 #define UNMARK_eval_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4935 #define ADDITIONAL_FREE_eval_data(ptr) | |
4936 | |
4937 SWEEP_FIXED_TYPE_BLOCK (eval_data, Lisp_Eval_Data); | |
4938 } | |
3263 | 4939 #endif /* not NEW_GC */ |
934 | 4940 |
1204 | 4941 void |
4942 free_eval_data (Lisp_Object ptr) | |
4943 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4944 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, eval_data, Lisp_Eval_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4945 XEVAL_DATA (ptr)); |
2720 | 4946 } |
4947 | |
3263 | 4948 #ifndef NEW_GC |
934 | 4949 static void |
4950 sweep_misc_user_data (void) | |
4951 { | |
4952 #define UNMARK_misc_user_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4953 #define ADDITIONAL_FREE_misc_user_data(ptr) | |
4954 | |
4955 SWEEP_FIXED_TYPE_BLOCK (misc_user_data, Lisp_Misc_User_Data); | |
4956 } | |
3263 | 4957 #endif /* not NEW_GC */ |
934 | 4958 |
1204 | 4959 void |
4960 free_misc_user_data (Lisp_Object ptr) | |
4961 { | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4962 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, misc_user_data, Lisp_Misc_User_Data, |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4963 XMISC_USER_DATA (ptr)); |
1204 | 4964 } |
4965 | |
4966 #endif /* EVENT_DATA_AS_OBJECTS */ | |
934 | 4967 |
3263 | 4968 #ifndef NEW_GC |
428 | 4969 static void |
4970 sweep_markers (void) | |
4971 { | |
4972 #define UNMARK_marker(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4973 #define ADDITIONAL_FREE_marker(ptr) \ | |
4974 do { Lisp_Object tem; \ | |
793 | 4975 tem = wrap_marker (ptr); \ |
428 | 4976 unchain_marker (tem); \ |
4977 } while (0) | |
4978 | |
440 | 4979 SWEEP_FIXED_TYPE_BLOCK (marker, Lisp_Marker); |
428 | 4980 } |
3263 | 4981 #endif /* not NEW_GC */ |
428 | 4982 |
4983 /* Explicitly free a marker. */ | |
4984 void | |
1204 | 4985 free_marker (Lisp_Object ptr) |
428 | 4986 { |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4987 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, marker, Lisp_Marker, XMARKER (ptr)); |
428 | 4988 } |
4989 | |
4990 | |
4991 #if defined (MULE) && defined (VERIFY_STRING_CHARS_INTEGRITY) | |
4992 | |
4993 static void | |
4994 verify_string_chars_integrity (void) | |
4995 { | |
4996 struct string_chars_block *sb; | |
4997 | |
4998 /* Scan each existing string block sequentially, string by string. */ | |
4999 for (sb = first_string_chars_block; sb; sb = sb->next) | |
5000 { | |
5001 int pos = 0; | |
5002 /* POS is the index of the next string in the block. */ | |
5003 while (pos < sb->pos) | |
5004 { | |
5005 struct string_chars *s_chars = | |
5006 (struct string_chars *) &(sb->string_chars[pos]); | |
438 | 5007 Lisp_String *string; |
428 | 5008 int size; |
5009 int fullsize; | |
5010 | |
454 | 5011 /* If the string_chars struct is marked as free (i.e. the |
5012 STRING pointer is NULL) then this is an unused chunk of | |
5013 string storage. (See below.) */ | |
5014 | |
5015 if (STRING_CHARS_FREE_P (s_chars)) | |
428 | 5016 { |
5017 fullsize = ((struct unused_string_chars *) s_chars)->fullsize; | |
5018 pos += fullsize; | |
5019 continue; | |
5020 } | |
5021 | |
5022 string = s_chars->string; | |
5023 /* Must be 32-bit aligned. */ | |
5024 assert ((((int) string) & 3) == 0); | |
5025 | |
793 | 5026 size = string->size_; |
428 | 5027 fullsize = STRING_FULLSIZE (size); |
5028 | |
5029 assert (!BIG_STRING_FULLSIZE_P (fullsize)); | |
2720 | 5030 assert (XSTRING_DATA (string) == s_chars->chars); |
428 | 5031 pos += fullsize; |
5032 } | |
5033 assert (pos == sb->pos); | |
5034 } | |
5035 } | |
5036 | |
1204 | 5037 #endif /* defined (MULE) && defined (VERIFY_STRING_CHARS_INTEGRITY) */ |
428 | 5038 |
3092 | 5039 #ifndef NEW_GC |
428 | 5040 /* Compactify string chars, relocating the reference to each -- |
5041 free any empty string_chars_block we see. */ | |
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
5042 static void |
428 | 5043 compact_string_chars (void) |
5044 { | |
5045 struct string_chars_block *to_sb = first_string_chars_block; | |
5046 int to_pos = 0; | |
5047 struct string_chars_block *from_sb; | |
5048 | |
5049 /* Scan each existing string block sequentially, string by string. */ | |
5050 for (from_sb = first_string_chars_block; from_sb; from_sb = from_sb->next) | |
5051 { | |
5052 int from_pos = 0; | |
5053 /* FROM_POS is the index of the next string in the block. */ | |
5054 while (from_pos < from_sb->pos) | |
5055 { | |
5056 struct string_chars *from_s_chars = | |
5057 (struct string_chars *) &(from_sb->string_chars[from_pos]); | |
5058 struct string_chars *to_s_chars; | |
438 | 5059 Lisp_String *string; |
428 | 5060 int size; |
5061 int fullsize; | |
5062 | |
454 | 5063 /* If the string_chars struct is marked as free (i.e. the |
5064 STRING pointer is NULL) then this is an unused chunk of | |
5065 string storage. This happens under Mule when a string's | |
5066 size changes in such a way that its fullsize changes. | |
5067 (Strings can change size because a different-length | |
5068 character can be substituted for another character.) | |
5069 In this case, after the bogus string pointer is the | |
5070 "fullsize" of this entry, i.e. how many bytes to skip. */ | |
5071 | |
5072 if (STRING_CHARS_FREE_P (from_s_chars)) | |
428 | 5073 { |
5074 fullsize = ((struct unused_string_chars *) from_s_chars)->fullsize; | |
5075 from_pos += fullsize; | |
5076 continue; | |
5077 } | |
5078 | |
5079 string = from_s_chars->string; | |
1204 | 5080 gc_checking_assert (!(LRECORD_FREE_P (string))); |
428 | 5081 |
793 | 5082 size = string->size_; |
428 | 5083 fullsize = STRING_FULLSIZE (size); |
5084 | |
442 | 5085 gc_checking_assert (! BIG_STRING_FULLSIZE_P (fullsize)); |
428 | 5086 |
5087 /* Just skip it if it isn't marked. */ | |
771 | 5088 if (! MARKED_RECORD_HEADER_P (&(string->u.lheader))) |
428 | 5089 { |
5090 from_pos += fullsize; | |
5091 continue; | |
5092 } | |
5093 | |
5094 /* If it won't fit in what's left of TO_SB, close TO_SB out | |
5095 and go on to the next string_chars_block. We know that TO_SB | |
5096 cannot advance past FROM_SB here since FROM_SB is large enough | |
5097 to currently contain this string. */ | |
5098 if ((to_pos + fullsize) > countof (to_sb->string_chars)) | |
5099 { | |
5100 to_sb->pos = to_pos; | |
5101 to_sb = to_sb->next; | |
5102 to_pos = 0; | |
5103 } | |
5104 | |
5105 /* Compute new address of this string | |
5106 and update TO_POS for the space being used. */ | |
5107 to_s_chars = (struct string_chars *) &(to_sb->string_chars[to_pos]); | |
5108 | |
5109 /* Copy the string_chars to the new place. */ | |
5110 if (from_s_chars != to_s_chars) | |
5111 memmove (to_s_chars, from_s_chars, fullsize); | |
5112 | |
5113 /* Relocate FROM_S_CHARS's reference */ | |
826 | 5114 set_lispstringp_data (string, &(to_s_chars->chars[0])); |
428 | 5115 |
5116 from_pos += fullsize; | |
5117 to_pos += fullsize; | |
5118 } | |
5119 } | |
5120 | |
5121 /* Set current to the last string chars block still used and | |
5122 free any that follow. */ | |
5123 { | |
5124 struct string_chars_block *victim; | |
5125 | |
5126 for (victim = to_sb->next; victim; ) | |
5127 { | |
5128 struct string_chars_block *next = victim->next; | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
5129 xfree (victim); |
428 | 5130 victim = next; |
5131 } | |
5132 | |
5133 current_string_chars_block = to_sb; | |
5134 current_string_chars_block->pos = to_pos; | |
5135 current_string_chars_block->next = 0; | |
5136 } | |
5137 } | |
3092 | 5138 #endif /* not NEW_GC */ |
428 | 5139 |
3263 | 5140 #ifndef NEW_GC |
428 | 5141 #if 1 /* Hack to debug missing purecopy's */ |
5142 static int debug_string_purity; | |
5143 | |
5144 static void | |
793 | 5145 debug_string_purity_print (Lisp_Object p) |
428 | 5146 { |
5147 Charcount i; | |
826 | 5148 Charcount s = string_char_length (p); |
442 | 5149 stderr_out ("\""); |
428 | 5150 for (i = 0; i < s; i++) |
5151 { | |
867 | 5152 Ichar ch = string_ichar (p, i); |
428 | 5153 if (ch < 32 || ch >= 126) |
5154 stderr_out ("\\%03o", ch); | |
5155 else if (ch == '\\' || ch == '\"') | |
5156 stderr_out ("\\%c", ch); | |
5157 else | |
5158 stderr_out ("%c", ch); | |
5159 } | |
5160 stderr_out ("\"\n"); | |
5161 } | |
5162 #endif /* 1 */ | |
3263 | 5163 #endif /* not NEW_GC */ |
5164 | |
5165 #ifndef NEW_GC | |
428 | 5166 static void |
5167 sweep_strings (void) | |
5168 { | |
5169 int debug = debug_string_purity; | |
5170 | |
793 | 5171 #define UNMARK_string(ptr) do { \ |
5172 Lisp_String *p = (ptr); \ | |
5173 UNMARK_RECORD_HEADER (&(p->u.lheader)); \ | |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5174 tick_string_stats (p, 1); \ |
793 | 5175 if (debug) \ |
5176 debug_string_purity_print (wrap_string (p)); \ | |
438 | 5177 } while (0) |
5178 #define ADDITIONAL_FREE_string(ptr) do { \ | |
793 | 5179 Bytecount size = ptr->size_; \ |
438 | 5180 if (BIG_STRING_SIZE_P (size)) \ |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
5181 xfree (ptr->data_); \ |
438 | 5182 } while (0) |
5183 | |
771 | 5184 SWEEP_FIXED_TYPE_BLOCK_1 (string, Lisp_String, u.lheader); |
428 | 5185 } |
3263 | 5186 #endif /* not NEW_GC */ |
428 | 5187 |
3092 | 5188 #ifndef NEW_GC |
5189 void | |
5190 gc_sweep_1 (void) | |
428 | 5191 { |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
5192 /* Reset all statistics to 0. They will be incremented when |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
5193 sweeping lcrecords, frob-block lrecords and dumped objects. */ |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5194 clear_lrecord_stats (); |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
5195 |
428 | 5196 /* Free all unmarked records. Do this at the very beginning, |
5197 before anything else, so that the finalize methods can safely | |
5198 examine items in the objects. sweep_lcrecords_1() makes | |
5199 sure to call all the finalize methods *before* freeing anything, | |
5200 to complete the safety. */ | |
5201 { | |
5202 int ignored; | |
5203 sweep_lcrecords_1 (&all_lcrecords, &ignored); | |
5204 } | |
5205 | |
5206 compact_string_chars (); | |
5207 | |
5208 /* Finalize methods below (called through the ADDITIONAL_FREE_foo | |
5209 macros) must be *extremely* careful to make sure they're not | |
5210 referencing freed objects. The only two existing finalize | |
5211 methods (for strings and markers) pass muster -- the string | |
5212 finalizer doesn't look at anything but its own specially- | |
5213 created block, and the marker finalizer only looks at live | |
5214 buffers (which will never be freed) and at the markers before | |
5215 and after it in the chain (which, by induction, will never be | |
5216 freed because if so, they would have already removed themselves | |
5217 from the chain). */ | |
5218 | |
5219 /* Put all unmarked strings on free list, free'ing the string chars | |
5220 of large unmarked strings */ | |
5221 sweep_strings (); | |
5222 | |
5223 /* Put all unmarked conses on free list */ | |
5224 sweep_conses (); | |
5225 | |
5226 /* Free all unmarked compiled-function objects */ | |
5227 sweep_compiled_functions (); | |
5228 | |
5229 /* Put all unmarked floats on free list */ | |
5230 sweep_floats (); | |
5231 | |
1983 | 5232 #ifdef HAVE_BIGNUM |
5233 /* Put all unmarked bignums on free list */ | |
5234 sweep_bignums (); | |
5235 #endif | |
5236 | |
5237 #ifdef HAVE_RATIO | |
5238 /* Put all unmarked ratios on free list */ | |
5239 sweep_ratios (); | |
5240 #endif | |
5241 | |
5242 #ifdef HAVE_BIGFLOAT | |
5243 /* Put all unmarked bigfloats on free list */ | |
5244 sweep_bigfloats (); | |
5245 #endif | |
5246 | |
428 | 5247 /* Put all unmarked symbols on free list */ |
5248 sweep_symbols (); | |
5249 | |
5250 /* Put all unmarked extents on free list */ | |
5251 sweep_extents (); | |
5252 | |
5253 /* Put all unmarked markers on free list. | |
5254 Dechain each one first from the buffer into which it points. */ | |
5255 sweep_markers (); | |
5256 | |
5257 sweep_events (); | |
5258 | |
1204 | 5259 #ifdef EVENT_DATA_AS_OBJECTS |
934 | 5260 sweep_key_data (); |
5261 sweep_button_data (); | |
5262 sweep_motion_data (); | |
5263 sweep_process_data (); | |
5264 sweep_timeout_data (); | |
5265 sweep_magic_data (); | |
5266 sweep_magic_eval_data (); | |
5267 sweep_eval_data (); | |
5268 sweep_misc_user_data (); | |
1204 | 5269 #endif /* EVENT_DATA_AS_OBJECTS */ |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
5270 |
428 | 5271 #ifdef PDUMP |
442 | 5272 pdump_objects_unmark (); |
428 | 5273 #endif |
5274 } | |
3092 | 5275 #endif /* not NEW_GC */ |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5276 |
428 | 5277 |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5278 /************************************************************************/ |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5279 /* "Disksave Finalization" -- Preparing for Dumping */ |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5280 /************************************************************************/ |
428 | 5281 |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5282 static void |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5283 disksave_object_finalization_1 (void) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5284 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5285 #ifdef NEW_GC |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5286 mc_finalize_for_disksave (); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5287 #else /* not NEW_GC */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5288 struct old_lcrecord_header *header; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5289 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5290 for (header = all_lcrecords; header; header = header->next) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5291 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5292 struct lrecord_header *objh = &header->lheader; |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5293 const struct lrecord_implementation *imp = LHEADER_IMPLEMENTATION (objh); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5294 #if 0 /* possibly useful for debugging */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5295 if (!RECORD_DUMPABLE (objh) && !objh->free) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5296 { |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5297 stderr_out ("Disksaving a non-dumpable object: "); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5298 debug_print (wrap_pointer_1 (header)); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5299 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5300 #endif |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5301 if (imp->disksave && !objh->free) |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5302 (imp->disksave) (wrap_pointer_1 (header)); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5303 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5304 #endif /* not NEW_GC */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5305 } |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5306 |
428 | 5307 void |
5308 disksave_object_finalization (void) | |
5309 { | |
5310 /* It's important that certain information from the environment not get | |
5311 dumped with the executable (pathnames, environment variables, etc.). | |
5312 To make it easier to tell when this has happened with strings(1) we | |
5313 clear some known-to-be-garbage blocks of memory, so that leftover | |
5314 results of old evaluation don't look like potential problems. | |
5315 But first we set some notable variables to nil and do one more GC, | |
5316 to turn those strings into garbage. | |
440 | 5317 */ |
428 | 5318 |
5319 /* Yeah, this list is pretty ad-hoc... */ | |
5320 Vprocess_environment = Qnil; | |
771 | 5321 env_initted = 0; |
428 | 5322 Vexec_directory = Qnil; |
5323 Vdata_directory = Qnil; | |
5324 Vsite_directory = Qnil; | |
5325 Vdoc_directory = Qnil; | |
5326 Vexec_path = Qnil; | |
5327 Vload_path = Qnil; | |
5328 /* Vdump_load_path = Qnil; */ | |
5329 /* Release hash tables for locate_file */ | |
5330 Flocate_file_clear_hashing (Qt); | |
771 | 5331 uncache_home_directory (); |
776 | 5332 zero_out_command_line_status_vars (); |
872 | 5333 clear_default_devices (); |
428 | 5334 |
5335 #if defined(LOADHIST) && !(defined(LOADHIST_DUMPED) || \ | |
5336 defined(LOADHIST_BUILTIN)) | |
5337 Vload_history = Qnil; | |
5338 #endif | |
5339 Vshell_file_name = Qnil; | |
5340 | |
3092 | 5341 #ifdef NEW_GC |
5342 gc_full (); | |
5343 #else /* not NEW_GC */ | |
428 | 5344 garbage_collect_1 (); |
3092 | 5345 #endif /* not NEW_GC */ |
428 | 5346 |
5347 /* Run the disksave finalization methods of all live objects. */ | |
5348 disksave_object_finalization_1 (); | |
5349 | |
3092 | 5350 #ifndef NEW_GC |
428 | 5351 /* Zero out the uninitialized (really, unused) part of the containers |
5352 for the live strings. */ | |
5353 { | |
5354 struct string_chars_block *scb; | |
5355 for (scb = first_string_chars_block; scb; scb = scb->next) | |
5356 { | |
5357 int count = sizeof (scb->string_chars) - scb->pos; | |
5358 | |
5359 assert (count >= 0 && count < STRING_CHARS_BLOCK_SIZE); | |
440 | 5360 if (count != 0) |
5361 { | |
5362 /* from the block's fill ptr to the end */ | |
5363 memset ((scb->string_chars + scb->pos), 0, count); | |
5364 } | |
428 | 5365 } |
5366 } | |
3092 | 5367 #endif /* not NEW_GC */ |
428 | 5368 |
5369 /* There, that ought to be enough... */ | |
5370 | |
5371 } | |
5372 | |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5373 |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5374 /************************************************************************/ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5375 /* Lisp interface onto garbage collection */ |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5376 /************************************************************************/ |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5377 |
2994 | 5378 /* Debugging aids. */ |
5379 | |
5380 DEFUN ("garbage-collect", Fgarbage_collect, 0, 0, "", /* | |
5381 Reclaim storage for Lisp objects no longer needed. | |
5382 Return info on amount of space in use: | |
5383 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS) | |
5384 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS | |
5385 PLIST) | |
5386 where `PLIST' is a list of alternating keyword/value pairs providing | |
5387 more detailed information. | |
5388 Garbage collection happens automatically if you cons more than | |
5389 `gc-cons-threshold' bytes of Lisp data since previous garbage collection. | |
5390 */ | |
5391 ()) | |
5392 { | |
5393 /* Record total usage for purposes of determining next GC */ | |
3092 | 5394 #ifdef NEW_GC |
5395 gc_full (); | |
5396 #else /* not NEW_GC */ | |
2994 | 5397 garbage_collect_1 (); |
3092 | 5398 #endif /* not NEW_GC */ |
2994 | 5399 |
5400 /* This will get set to 1, and total_gc_usage computed, as part of the | |
5401 call to object_memory_usage_stats() -- if ALLOC_TYPE_STATS is enabled. */ | |
5402 total_gc_usage_set = 0; | |
5403 #ifdef ALLOC_TYPE_STATS | |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5404 return garbage_collection_statistics (); |
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5405 #else |
2994 | 5406 return Qnil; |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5407 #endif |
2994 | 5408 } |
428 | 5409 |
5410 DEFUN ("consing-since-gc", Fconsing_since_gc, 0, 0, "", /* | |
5411 Return the number of bytes consed since the last garbage collection. | |
5412 \"Consed\" is a misnomer in that this actually counts allocation | |
5413 of all different kinds of objects, not just conses. | |
5414 | |
5415 If this value exceeds `gc-cons-threshold', a garbage collection happens. | |
5416 */ | |
5417 ()) | |
5418 { | |
5419 return make_int (consing_since_gc); | |
5420 } | |
5421 | |
440 | 5422 #if 0 |
444 | 5423 DEFUN ("memory-limit", Fmemory_limit, 0, 0, 0, /* |
801 | 5424 Return the address of the last byte XEmacs has allocated, divided by 1024. |
5425 This may be helpful in debugging XEmacs's memory usage. | |
428 | 5426 The value is divided by 1024 to make sure it will fit in a lisp integer. |
5427 */ | |
5428 ()) | |
5429 { | |
5430 return make_int ((EMACS_INT) sbrk (0) / 1024); | |
5431 } | |
440 | 5432 #endif |
428 | 5433 |
2994 | 5434 DEFUN ("total-memory-usage", Ftotal_memory_usage, 0, 0, 0, /* |
801 | 5435 Return the total number of bytes used by the data segment in XEmacs. |
5436 This may be helpful in debugging XEmacs's memory usage. | |
2994 | 5437 NOTE: This may or may not be accurate! It is hard to determine this |
5438 value in a system-independent fashion. On Windows, for example, the | |
5439 returned number tends to be much greater than reality. | |
801 | 5440 */ |
5441 ()) | |
5442 { | |
5443 return make_int (total_data_usage ()); | |
5444 } | |
5445 | |
4803
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5446 #ifdef USE_VALGRIND |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5447 DEFUN ("valgrind-leak-check", Fvalgrind_leak_check, 0, 0, "", /* |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5448 Ask valgrind to perform a memory leak check. |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5449 The results of the leak check are sent to stderr. |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5450 */ |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5451 ()) |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5452 { |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5453 VALGRIND_DO_LEAK_CHECK; |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5454 return Qnil; |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5455 } |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5456 |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5457 DEFUN ("valgrind-quick-leak-check", Fvalgrind_quick_leak_check, 0, 0, "", /* |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5458 Ask valgrind to perform a quick memory leak check. |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5459 This just prints a summary of leaked memory, rather than all the details. |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5460 The results of the leak check are sent to stderr. |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5461 */ |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5462 ()) |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5463 { |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5464 VALGRIND_DO_QUICK_LEAK_CHECK; |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5465 return Qnil; |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5466 } |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5467 #endif /* USE_VALGRIND */ |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5468 |
428 | 5469 |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5470 /************************************************************************/ |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5471 /* Initialization */ |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5472 /************************************************************************/ |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5473 |
428 | 5474 /* Initialization */ |
771 | 5475 static void |
1204 | 5476 common_init_alloc_early (void) |
428 | 5477 { |
771 | 5478 #ifndef Qzero |
5479 Qzero = make_int (0); /* Only used if Lisp_Object is a union type */ | |
5480 #endif | |
5481 | |
5482 #ifndef Qnull_pointer | |
5483 /* C guarantees that Qnull_pointer will be initialized to all 0 bits, | |
5484 so the following is actually a no-op. */ | |
793 | 5485 Qnull_pointer = wrap_pointer_1 (0); |
771 | 5486 #endif |
5487 | |
3263 | 5488 #ifndef NEW_GC |
428 | 5489 breathing_space = 0; |
5490 all_lcrecords = 0; | |
3263 | 5491 #endif /* not NEW_GC */ |
428 | 5492 ignore_malloc_warnings = 1; |
5493 #ifdef DOUG_LEA_MALLOC | |
5494 mallopt (M_TRIM_THRESHOLD, 128*1024); /* trim threshold */ | |
5495 mallopt (M_MMAP_THRESHOLD, 64*1024); /* mmap threshold */ | |
5496 #if 0 /* Moved to emacs.c */ | |
5497 mallopt (M_MMAP_MAX, 64); /* max. number of mmap'ed areas */ | |
5498 #endif | |
5499 #endif | |
3092 | 5500 #ifndef NEW_GC |
2720 | 5501 init_string_chars_alloc (); |
428 | 5502 init_string_alloc (); |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5503 /* #### Is it intentional that this is called twice? --ben */ |
428 | 5504 init_string_chars_alloc (); |
5505 init_cons_alloc (); | |
5506 init_symbol_alloc (); | |
5507 init_compiled_function_alloc (); | |
5508 init_float_alloc (); | |
1983 | 5509 #ifdef HAVE_BIGNUM |
5510 init_bignum_alloc (); | |
5511 #endif | |
5512 #ifdef HAVE_RATIO | |
5513 init_ratio_alloc (); | |
5514 #endif | |
5515 #ifdef HAVE_BIGFLOAT | |
5516 init_bigfloat_alloc (); | |
5517 #endif | |
428 | 5518 init_marker_alloc (); |
5519 init_extent_alloc (); | |
5520 init_event_alloc (); | |
1204 | 5521 #ifdef EVENT_DATA_AS_OBJECTS |
934 | 5522 init_key_data_alloc (); |
5523 init_button_data_alloc (); | |
5524 init_motion_data_alloc (); | |
5525 init_process_data_alloc (); | |
5526 init_timeout_data_alloc (); | |
5527 init_magic_data_alloc (); | |
5528 init_magic_eval_data_alloc (); | |
5529 init_eval_data_alloc (); | |
5530 init_misc_user_data_alloc (); | |
1204 | 5531 #endif /* EVENT_DATA_AS_OBJECTS */ |
3263 | 5532 #endif /* not NEW_GC */ |
428 | 5533 |
5534 ignore_malloc_warnings = 0; | |
5535 | |
452 | 5536 if (staticpros_nodump) |
5537 Dynarr_free (staticpros_nodump); | |
5538 staticpros_nodump = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *); | |
5539 Dynarr_resize (staticpros_nodump, 100); /* merely a small optimization */ | |
771 | 5540 #ifdef DEBUG_XEMACS |
5541 if (staticpro_nodump_names) | |
5542 Dynarr_free (staticpro_nodump_names); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5543 staticpro_nodump_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5544 const Ascbyte *); |
771 | 5545 Dynarr_resize (staticpro_nodump_names, 100); /* ditto */ |
5546 #endif | |
428 | 5547 |
3263 | 5548 #ifdef NEW_GC |
2720 | 5549 mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object); |
5550 Dynarr_resize (mcpros, 1410); /* merely a small optimization */ | |
5551 dump_add_root_block_ptr (&mcpros, &mcpros_description); | |
5552 #ifdef DEBUG_XEMACS | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5553 mcpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *); |
2720 | 5554 Dynarr_resize (mcpro_names, 1410); /* merely a small optimization */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5555 dump_add_root_block_ptr (&mcpro_names, |
4964 | 5556 &const_Ascbyte_ptr_dynarr_description); |
2720 | 5557 #endif |
3263 | 5558 #endif /* NEW_GC */ |
2720 | 5559 |
428 | 5560 consing_since_gc = 0; |
851 | 5561 need_to_check_c_alloca = 0; |
5562 funcall_allocation_flag = 0; | |
5563 funcall_alloca_count = 0; | |
814 | 5564 |
3263 | 5565 #ifndef NEW_GC |
428 | 5566 debug_string_purity = 0; |
3263 | 5567 #endif /* not NEW_GC */ |
428 | 5568 |
800 | 5569 #ifdef ERROR_CHECK_TYPES |
428 | 5570 ERROR_ME.really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = |
5571 666; | |
5572 ERROR_ME_NOT. | |
5573 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = 42; | |
5574 ERROR_ME_WARN. | |
5575 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = | |
5576 3333632; | |
793 | 5577 ERROR_ME_DEBUG_WARN. |
5578 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = | |
5579 8675309; | |
800 | 5580 #endif /* ERROR_CHECK_TYPES */ |
428 | 5581 } |
5582 | |
3263 | 5583 #ifndef NEW_GC |
771 | 5584 static void |
5585 init_lcrecord_lists (void) | |
5586 { | |
5587 int i; | |
5588 | |
5589 for (i = 0; i < countof (lrecord_implementations_table); i++) | |
5590 { | |
5591 all_lcrecord_lists[i] = Qzero; /* Qnil not yet set */ | |
5592 staticpro_nodump (&all_lcrecord_lists[i]); | |
5593 } | |
5594 } | |
3263 | 5595 #endif /* not NEW_GC */ |
771 | 5596 |
5597 void | |
1204 | 5598 init_alloc_early (void) |
771 | 5599 { |
1204 | 5600 #if defined (__cplusplus) && defined (ERROR_CHECK_GC) |
5601 static struct gcpro initial_gcpro; | |
5602 | |
5603 initial_gcpro.next = 0; | |
5604 initial_gcpro.var = &Qnil; | |
5605 initial_gcpro.nvars = 1; | |
5606 gcprolist = &initial_gcpro; | |
5607 #else | |
5608 gcprolist = 0; | |
5609 #endif /* defined (__cplusplus) && defined (ERROR_CHECK_GC) */ | |
5610 } | |
5611 | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5612 static void |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5613 reinit_alloc_objects_early (void) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5614 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5615 OBJECT_HAS_METHOD (string, getprop); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5616 OBJECT_HAS_METHOD (string, putprop); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5617 OBJECT_HAS_METHOD (string, remprop); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5618 OBJECT_HAS_METHOD (string, plist); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5619 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5620 |
1204 | 5621 void |
5622 reinit_alloc_early (void) | |
5623 { | |
5624 common_init_alloc_early (); | |
3263 | 5625 #ifndef NEW_GC |
771 | 5626 init_lcrecord_lists (); |
3263 | 5627 #endif /* not NEW_GC */ |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5628 reinit_alloc_objects_early (); |
771 | 5629 } |
5630 | |
428 | 5631 void |
5632 init_alloc_once_early (void) | |
5633 { | |
1204 | 5634 common_init_alloc_early (); |
428 | 5635 |
442 | 5636 { |
5637 int i; | |
5638 for (i = 0; i < countof (lrecord_implementations_table); i++) | |
5639 lrecord_implementations_table[i] = 0; | |
5640 } | |
5641 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
5642 dump_add_opaque (lrecord_uid_counter, sizeof (lrecord_uid_counter)); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
5643 |
452 | 5644 staticpros = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *); |
5645 Dynarr_resize (staticpros, 1410); /* merely a small optimization */ | |
2367 | 5646 dump_add_root_block_ptr (&staticpros, &staticpros_description); |
771 | 5647 #ifdef DEBUG_XEMACS |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5648 staticpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *); |
771 | 5649 Dynarr_resize (staticpro_names, 1410); /* merely a small optimization */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5650 dump_add_root_block_ptr (&staticpro_names, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5651 &const_Ascbyte_ptr_dynarr_description); |
771 | 5652 #endif |
5653 | |
3263 | 5654 #ifdef NEW_GC |
2720 | 5655 mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object); |
5656 Dynarr_resize (mcpros, 1410); /* merely a small optimization */ | |
5657 dump_add_root_block_ptr (&mcpros, &mcpros_description); | |
5658 #ifdef DEBUG_XEMACS | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5659 mcpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *); |
2720 | 5660 Dynarr_resize (mcpro_names, 1410); /* merely a small optimization */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5661 dump_add_root_block_ptr (&mcpro_names, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5662 &const_Ascbyte_ptr_dynarr_description); |
2720 | 5663 #endif |
3263 | 5664 #else /* not NEW_GC */ |
771 | 5665 init_lcrecord_lists (); |
3263 | 5666 #endif /* not NEW_GC */ |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5667 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5668 INIT_LISP_OBJECT (cons); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5669 INIT_LISP_OBJECT (vector); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5670 INIT_LISP_OBJECT (string); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5671 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5672 #ifdef NEW_GC |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5673 INIT_LISP_OBJECT (string_indirect_data); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5674 INIT_LISP_OBJECT (string_direct_data); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5675 #endif /* NEW_GC */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5676 #ifndef NEW_GC |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5677 INIT_LISP_OBJECT (lcrecord_list); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5678 INIT_LISP_OBJECT (free); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5679 #endif /* not NEW_GC */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5680 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5681 reinit_alloc_objects_early (); |
428 | 5682 } |
5683 | |
5684 void | |
5685 syms_of_alloc (void) | |
5686 { | |
442 | 5687 DEFSYMBOL (Qgarbage_collecting); |
428 | 5688 |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5689 #ifdef MEMORY_USAGE_STATS |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5690 DEFSYMBOL (Qobject_actually_requested); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5691 DEFSYMBOL (Qobject_malloc_overhead); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5692 DEFSYMBOL (Qother_memory_actually_requested); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5693 DEFSYMBOL (Qother_memory_malloc_overhead); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5694 DEFSYMBOL (Qother_memory_dynarr_overhead); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5695 DEFSYMBOL (Qother_memory_gap_overhead); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5696 #endif /* MEMORY_USAGE_STATS */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5697 |
428 | 5698 DEFSUBR (Fcons); |
5699 DEFSUBR (Flist); | |
5700 DEFSUBR (Fvector); | |
5701 DEFSUBR (Fbit_vector); | |
5702 DEFSUBR (Fmake_byte_code); | |
5703 DEFSUBR (Fmake_list); | |
5704 DEFSUBR (Fmake_vector); | |
5705 DEFSUBR (Fmake_bit_vector); | |
5706 DEFSUBR (Fmake_string); | |
5707 DEFSUBR (Fstring); | |
5708 DEFSUBR (Fmake_symbol); | |
5709 DEFSUBR (Fmake_marker); | |
2994 | 5710 #ifdef ALLOC_TYPE_STATS |
5711 DEFSUBR (Fobject_memory_usage_stats); | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5712 DEFSUBR (Ftotal_object_memory_usage); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5713 #endif /* ALLOC_TYPE_STATS */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5714 #ifdef MEMORY_USAGE_STATS |
2994 | 5715 DEFSUBR (Fobject_memory_usage); |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5716 #endif /* MEMORY_USAGE_STATS */ |
428 | 5717 DEFSUBR (Fgarbage_collect); |
440 | 5718 #if 0 |
428 | 5719 DEFSUBR (Fmemory_limit); |
440 | 5720 #endif |
2994 | 5721 DEFSUBR (Ftotal_memory_usage); |
428 | 5722 DEFSUBR (Fconsing_since_gc); |
4803
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5723 #ifdef USE_VALGRIND |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5724 DEFSUBR (Fvalgrind_leak_check); |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5725 DEFSUBR (Fvalgrind_quick_leak_check); |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5726 #endif |
428 | 5727 } |
5728 | |
5729 void | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5730 reinit_vars_of_alloc (void) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5731 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5732 #ifdef MEMORY_USAGE_STATS |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5733 compute_memusage_stats_length (); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5734 #endif /* MEMORY_USAGE_STATS */ |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5735 } |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5736 |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5737 void |
428 | 5738 vars_of_alloc (void) |
5739 { | |
5740 #ifdef DEBUG_XEMACS | |
5741 DEFVAR_INT ("debug-allocation", &debug_allocation /* | |
5742 If non-zero, print out information to stderr about all objects allocated. | |
5743 See also `debug-allocation-backtrace-length'. | |
5744 */ ); | |
5745 debug_allocation = 0; | |
5746 | |
5747 DEFVAR_INT ("debug-allocation-backtrace-length", | |
5748 &debug_allocation_backtrace_length /* | |
5749 Length (in stack frames) of short backtrace printed out by `debug-allocation'. | |
5750 */ ); | |
5751 debug_allocation_backtrace_length = 2; | |
5752 #endif | |
5753 | |
5754 DEFVAR_BOOL ("purify-flag", &purify_flag /* | |
5755 Non-nil means loading Lisp code in order to dump an executable. | |
5756 This means that certain objects should be allocated in readonly space. | |
5757 */ ); | |
5758 } |