Mercurial > hg > xemacs-beta
annotate src/alloc.c @ 5465:1c87bdc11d65 last-gplv2
Added tag r21-5-30 for changeset e79916901603
| author | Stephen J. Turnbull <stephen@xemacs.org> |
|---|---|
| date | Wed, 27 Apr 2011 01:24:28 +0900 |
| parents | af961911bcb2 |
| children | 248176c74e6b |
| 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 | |
| 8 XEmacs is free software; you can redistribute it and/or modify it | |
| 9 under the terms of the GNU General Public License as published by the | |
| 10 Free Software Foundation; either version 2, or (at your option) any | |
| 11 later version. | |
| 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 | |
| 19 along with XEmacs; see the file COPYING. If not, write to | |
| 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 21 Boston, MA 02111-1307, USA. */ | |
| 22 | |
| 23 /* Synched up with: FSF 19.28, Mule 2.0. Substantially different from | |
| 24 FSF. */ | |
| 25 | |
| 26 /* Authorship: | |
| 27 | |
| 28 FSF: Original version; a long time ago. | |
| 29 Mly: Significantly rewritten to use new 3-bit tags and | |
| 30 nicely abstracted object definitions, for 19.8. | |
| 31 JWZ: Improved code to keep track of purespace usage and | |
| 32 issue nice purespace and GC stats. | |
| 33 Ben Wing: Cleaned up frob-block lrecord code, added error-checking | |
| 34 and various changes for Mule, for 19.12. | |
| 35 Added bit vectors for 19.13. | |
| 36 Added lcrecord lists for 19.14. | |
| 37 slb: Lots of work on the purification and dump time code. | |
| 38 Synched Doug Lea malloc support from Emacs 20.2. | |
| 442 | 39 og: Killed the purespace. Portable dumper (moved to dumper.c) |
| 428 | 40 */ |
| 41 | |
| 42 #include <config.h> | |
| 43 #include "lisp.h" | |
| 44 | |
| 45 #include "backtrace.h" | |
| 46 #include "buffer.h" | |
| 47 #include "bytecode.h" | |
| 48 #include "chartab.h" | |
| 49 #include "device.h" | |
| 50 #include "elhash.h" | |
| 51 #include "events.h" | |
| 872 | 52 #include "extents-impl.h" |
| 1204 | 53 #include "file-coding.h" |
| 872 | 54 #include "frame-impl.h" |
| 3092 | 55 #include "gc.h" |
| 428 | 56 #include "glyphs.h" |
| 57 #include "opaque.h" | |
| 1204 | 58 #include "lstream.h" |
| 872 | 59 #include "process.h" |
| 1292 | 60 #include "profile.h" |
| 428 | 61 #include "redisplay.h" |
| 62 #include "specifier.h" | |
| 63 #include "sysfile.h" | |
| 442 | 64 #include "sysdep.h" |
| 428 | 65 #include "window.h" |
| 3092 | 66 #ifdef NEW_GC |
| 67 #include "vdb.h" | |
| 68 #endif /* NEW_GC */ | |
| 428 | 69 #include "console-stream.h" |
| 70 | |
| 71 #ifdef DOUG_LEA_MALLOC | |
| 72 #include <malloc.h> | |
| 73 #endif | |
|
4803
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
74 #ifdef USE_VALGRIND |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
75 #include <valgrind/memcheck.h> |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
76 #endif |
| 428 | 77 |
| 78 EXFUN (Fgarbage_collect, 0); | |
| 79 | |
| 80 #if 0 /* this is _way_ too slow to be part of the standard debug options */ | |
| 81 #if defined(DEBUG_XEMACS) && defined(MULE) | |
| 82 #define VERIFY_STRING_CHARS_INTEGRITY | |
| 83 #endif | |
| 84 #endif | |
| 85 | |
| 86 /* Define this to use malloc/free with no freelist for all datatypes, | |
| 87 the hope being that some debugging tools may help detect | |
| 88 freed memory references */ | |
| 89 #ifdef USE_DEBUG_MALLOC /* Taking the above comment at face value -slb */ | |
| 90 #include <dmalloc.h> | |
| 91 #define ALLOC_NO_POOLS | |
| 92 #endif | |
| 93 | |
| 94 #ifdef DEBUG_XEMACS | |
| 458 | 95 static Fixnum debug_allocation; |
| 96 static Fixnum debug_allocation_backtrace_length; | |
| 428 | 97 #endif |
| 98 | |
|
5307
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
99 Fixnum Varray_dimension_limit, Varray_total_size_limit, Varray_rank_limit; |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
100 |
| 851 | 101 int need_to_check_c_alloca; |
| 887 | 102 int need_to_signal_post_gc; |
| 851 | 103 int funcall_allocation_flag; |
| 104 Bytecount __temp_alloca_size__; | |
| 105 Bytecount funcall_alloca_count; | |
| 814 | 106 |
|
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 /* 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 |
|
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 /* 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
|
114 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
|
115 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
|
116 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
|
117 |
|
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
118 #ifndef USE_KKCC |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
119 /* 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
|
120 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
|
121 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
|
122 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
|
123 #endif /* not USE_KKCC */ |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
124 |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
125 struct gcpro *gcprolist; |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
126 |
|
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
|
127 /* 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
|
128 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
|
129 |
|
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 /* 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
|
131 #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
|
132 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
|
133 #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
|
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 #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
|
136 |
|
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
|
137 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
|
138 |
|
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
|
139 #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
|
140 |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
141 #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
|
142 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
|
143 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
|
144 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
|
145 #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
|
146 |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
147 #ifndef NEW_GC |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
148 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
|
149 static Bytecount gc_count_string_total_size; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
150 static Bytecount gc_count_short_string_total_size; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
151 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
|
152 #endif /* not NEW_GC */ |
|
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 /* 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
|
155 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
156 /* stats on objects in use */ |
|
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 #ifdef NEW_GC |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
159 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
160 static struct |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
161 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
162 int instances_in_use; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
163 int bytes_in_use; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
164 int bytes_in_use_including_overhead; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
165 } lrecord_stats [countof (lrecord_implementations_table)]; |
|
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 #else /* not NEW_GC */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
168 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
169 static struct |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
170 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
171 Elemcount instances_in_use; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
172 Bytecount bytes_in_use; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
173 Bytecount bytes_in_use_overhead; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
174 Elemcount instances_freed; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
175 Bytecount bytes_freed; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
176 Bytecount bytes_freed_overhead; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
177 Elemcount instances_on_free_list; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
178 Bytecount bytes_on_free_list; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
179 Bytecount bytes_on_free_list_overhead; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
180 #ifdef MEMORY_USAGE_STATS |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
181 Bytecount nonlisp_bytes_in_use; |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
182 Bytecount lisp_ancillary_bytes_in_use; |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
183 struct generic_usage_stats stats; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
184 #endif |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
185 } lrecord_stats [countof (lrecord_implementations_table)]; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
186 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
187 #endif /* (not) NEW_GC */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
188 |
|
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
|
189 /* 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
|
190 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
|
191 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
|
192 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
|
193 |
| 428 | 194 |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
195 /************************************************************************/ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
196 /* Low-level allocation */ |
|
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 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
199 void |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
200 recompute_funcall_allocation_flag (void) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
201 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
202 funcall_allocation_flag = |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
203 need_to_garbage_collect || |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
204 need_to_check_c_alloca || |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
205 need_to_signal_post_gc; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
206 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
207 |
| 428 | 208 /* Maximum amount of C stack to save when a GC happens. */ |
| 209 | |
| 210 #ifndef MAX_SAVE_STACK | |
| 211 #define MAX_SAVE_STACK 0 /* 16000 */ | |
| 212 #endif | |
| 213 | |
| 214 /* Non-zero means ignore malloc warnings. Set during initialization. */ | |
| 215 int ignore_malloc_warnings; | |
| 216 | |
| 217 | |
| 3263 | 218 #ifndef NEW_GC |
| 3092 | 219 void *breathing_space; |
| 428 | 220 |
| 221 void | |
| 222 release_breathing_space (void) | |
| 223 { | |
| 224 if (breathing_space) | |
| 225 { | |
| 226 void *tmp = breathing_space; | |
| 227 breathing_space = 0; | |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
228 xfree (tmp); |
| 428 | 229 } |
| 230 } | |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
231 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
232 #if !defined(HAVE_MMAP) || defined(DOUG_LEA_MALLOC) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
233 /* 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
|
234 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
|
235 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
|
236 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
237 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
|
238 void refill_memory_reserve (void); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
239 void |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
240 refill_memory_reserve (void) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
241 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
242 if (breathing_space == 0) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
243 breathing_space = (char *) malloc (4096 - MALLOC_OVERHEAD); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
244 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
245 #endif /* !defined(HAVE_MMAP) || defined(DOUG_LEA_MALLOC) */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
246 |
| 3263 | 247 #endif /* not NEW_GC */ |
| 428 | 248 |
| 801 | 249 static void |
| 250 set_alloc_mins_and_maxes (void *val, Bytecount size) | |
| 251 { | |
| 252 if (!val) | |
| 253 return; | |
| 254 if ((char *) val + size > (char *) maximum_address_seen) | |
| 255 maximum_address_seen = (char *) val + size; | |
| 256 if (!minimum_address_seen) | |
| 257 minimum_address_seen = | |
| 258 #if SIZEOF_VOID_P == 8 | |
| 259 (void *) 0xFFFFFFFFFFFFFFFF; | |
| 260 #else | |
| 261 (void *) 0xFFFFFFFF; | |
| 262 #endif | |
| 263 if ((char *) val < (char *) minimum_address_seen) | |
| 264 minimum_address_seen = (char *) val; | |
| 265 } | |
| 266 | |
| 1315 | 267 #ifdef ERROR_CHECK_MALLOC |
| 3176 | 268 static int in_malloc; |
| 1333 | 269 extern int regex_malloc_disallowed; |
| 2367 | 270 |
| 271 #define MALLOC_BEGIN() \ | |
| 272 do \ | |
| 273 { \ | |
| 3176 | 274 assert (!in_malloc); \ |
| 2367 | 275 assert (!regex_malloc_disallowed); \ |
| 276 in_malloc = 1; \ | |
| 277 } \ | |
| 278 while (0) | |
| 279 | |
| 3263 | 280 #ifdef NEW_GC |
| 2720 | 281 #define FREE_OR_REALLOC_BEGIN(block) \ |
| 282 do \ | |
| 283 { \ | |
| 284 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an \ | |
| 285 error until much later on for many system mallocs, such as \ | |
| 286 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
|
287 assert (block != (void *) DEADBEEF_CONSTANT); \ |
| 2720 | 288 MALLOC_BEGIN (); \ |
| 289 } \ | |
| 290 while (0) | |
| 3263 | 291 #else /* not NEW_GC */ |
| 2367 | 292 #define FREE_OR_REALLOC_BEGIN(block) \ |
| 293 do \ | |
| 294 { \ | |
| 295 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an \ | |
| 296 error until much later on for many system mallocs, such as \ | |
| 297 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
|
298 assert (block != (void *) DEADBEEF_CONSTANT); \ |
| 2367 | 299 /* You cannot free something within dumped space, because there is \ |
| 300 no longer any sort of malloc structure associated with the block. \ | |
| 301 If you are tripping this, you may need to conditionalize on \ | |
| 302 DUMPEDP. */ \ | |
| 303 assert (!DUMPEDP (block)); \ | |
| 304 MALLOC_BEGIN (); \ | |
| 305 } \ | |
| 306 while (0) | |
| 3263 | 307 #endif /* not NEW_GC */ |
| 2367 | 308 |
| 309 #define MALLOC_END() \ | |
| 310 do \ | |
| 311 { \ | |
| 312 in_malloc = 0; \ | |
| 313 } \ | |
| 314 while (0) | |
| 315 | |
| 316 #else /* ERROR_CHECK_MALLOC */ | |
| 317 | |
| 2658 | 318 #define MALLOC_BEGIN() |
| 2367 | 319 #define FREE_OR_REALLOC_BEGIN(block) |
| 320 #define MALLOC_END() | |
| 321 | |
| 322 #endif /* ERROR_CHECK_MALLOC */ | |
| 323 | |
| 324 static void | |
| 325 malloc_after (void *val, Bytecount size) | |
| 326 { | |
| 327 if (!val && size != 0) | |
| 328 memory_full (); | |
| 329 set_alloc_mins_and_maxes (val, size); | |
| 330 } | |
| 331 | |
| 3305 | 332 /* malloc calls this if it finds we are near exhausting storage */ |
| 333 void | |
| 334 malloc_warning (const char *str) | |
| 335 { | |
| 336 if (ignore_malloc_warnings) | |
| 337 return; | |
| 338 | |
| 339 /* Remove the malloc lock here, because warn_when_safe may allocate | |
| 340 again. It is safe to remove the malloc lock here, because malloc | |
| 341 is already finished (malloc_warning is called via | |
| 342 after_morecore_hook -> check_memory_limits -> save_warn_fun -> | |
| 343 malloc_warning). */ | |
| 344 MALLOC_END (); | |
| 345 | |
| 346 warn_when_safe | |
| 347 (Qmemory, Qemergency, | |
| 348 "%s\n" | |
| 349 "Killing some buffers may delay running out of memory.\n" | |
| 350 "However, certainly by the time you receive the 95%% warning,\n" | |
| 351 "you should clean up, kill this Emacs, and start a new one.", | |
| 352 str); | |
| 353 } | |
| 354 | |
| 355 /* Called if malloc returns zero */ | |
| 356 DOESNT_RETURN | |
| 357 memory_full (void) | |
| 358 { | |
| 359 /* Force a GC next time eval is called. | |
| 360 It's better to loop garbage-collecting (we might reclaim enough | |
| 361 to win) than to loop beeping and barfing "Memory exhausted" | |
| 362 */ | |
| 363 consing_since_gc = gc_cons_threshold + 1; | |
| 364 recompute_need_to_garbage_collect (); | |
| 365 #ifdef NEW_GC | |
| 366 /* Put mc-alloc into memory shortage mode. This may keep XEmacs | |
| 367 alive until the garbage collector can free enough memory to get | |
| 368 us out of the memory exhaustion. If already in memory shortage | |
| 369 mode, we are in a loop and hopelessly lost. */ | |
| 370 if (memory_shortage) | |
| 371 { | |
| 372 fprintf (stderr, "Memory full, cannot recover.\n"); | |
| 373 ABORT (); | |
| 374 } | |
| 375 fprintf (stderr, | |
| 376 "Memory full, try to recover.\n" | |
| 377 "You should clean up, kill this Emacs, and start a new one.\n"); | |
| 378 memory_shortage++; | |
| 379 #else /* not NEW_GC */ | |
| 380 release_breathing_space (); | |
| 381 #endif /* not NEW_GC */ | |
| 382 | |
| 383 /* Flush some histories which might conceivably contain garbalogical | |
| 384 inhibitors. */ | |
| 385 if (!NILP (Fboundp (Qvalues))) | |
| 386 Fset (Qvalues, Qnil); | |
| 387 Vcommand_history = Qnil; | |
| 388 | |
| 389 out_of_memory ("Memory exhausted", Qunbound); | |
| 390 } | |
| 391 | |
| 2367 | 392 /* like malloc, calloc, realloc, free but: |
| 393 | |
| 394 -- check for no memory left | |
| 395 -- set internal mins and maxes | |
| 396 -- with error-checking on, check for reentrancy, invalid freeing, etc. | |
| 397 */ | |
| 1292 | 398 |
| 428 | 399 #undef xmalloc |
| 400 void * | |
| 665 | 401 xmalloc (Bytecount size) |
| 428 | 402 { |
| 1292 | 403 void *val; |
| 2367 | 404 MALLOC_BEGIN (); |
| 1292 | 405 val = malloc (size); |
| 2367 | 406 MALLOC_END (); |
| 407 malloc_after (val, size); | |
| 428 | 408 return val; |
| 409 } | |
| 410 | |
| 411 #undef xcalloc | |
| 412 static void * | |
| 665 | 413 xcalloc (Elemcount nelem, Bytecount elsize) |
| 428 | 414 { |
| 1292 | 415 void *val; |
| 2367 | 416 MALLOC_BEGIN (); |
| 1292 | 417 val= calloc (nelem, elsize); |
| 2367 | 418 MALLOC_END (); |
| 419 malloc_after (val, nelem * elsize); | |
| 428 | 420 return val; |
| 421 } | |
| 422 | |
| 423 void * | |
| 665 | 424 xmalloc_and_zero (Bytecount size) |
| 428 | 425 { |
| 426 return xcalloc (size, sizeof (char)); | |
| 427 } | |
| 428 | |
| 429 #undef xrealloc | |
| 430 void * | |
| 665 | 431 xrealloc (void *block, Bytecount size) |
| 428 | 432 { |
| 2367 | 433 FREE_OR_REALLOC_BEGIN (block); |
| 551 | 434 block = realloc (block, size); |
| 2367 | 435 MALLOC_END (); |
| 436 malloc_after (block, size); | |
| 551 | 437 return block; |
| 428 | 438 } |
| 439 | |
| 440 void | |
| 441 xfree_1 (void *block) | |
| 442 { | |
| 443 #ifdef ERROR_CHECK_MALLOC | |
| 444 assert (block); | |
| 445 #endif /* ERROR_CHECK_MALLOC */ | |
| 2367 | 446 FREE_OR_REALLOC_BEGIN (block); |
| 428 | 447 free (block); |
| 2367 | 448 MALLOC_END (); |
| 428 | 449 } |
| 450 | |
|
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
|
451 void |
| 665 | 452 deadbeef_memory (void *ptr, Bytecount size) |
| 428 | 453 { |
| 826 | 454 UINT_32_BIT *ptr4 = (UINT_32_BIT *) ptr; |
| 665 | 455 Bytecount beefs = size >> 2; |
| 428 | 456 |
| 457 /* In practice, size will always be a multiple of four. */ | |
| 458 while (beefs--) | |
| 1204 | 459 (*ptr4++) = 0xDEADBEEF; /* -559038737 base 10 */ |
| 428 | 460 } |
| 461 | |
| 462 #undef xstrdup | |
| 463 char * | |
| 442 | 464 xstrdup (const char *str) |
| 428 | 465 { |
| 466 int len = strlen (str) + 1; /* for stupid terminating 0 */ | |
| 467 void *val = xmalloc (len); | |
| 771 | 468 |
| 428 | 469 if (val == 0) return 0; |
| 470 return (char *) memcpy (val, str, len); | |
| 471 } | |
| 472 | |
| 473 #ifdef NEED_STRDUP | |
| 474 char * | |
| 442 | 475 strdup (const char *s) |
| 428 | 476 { |
| 477 return xstrdup (s); | |
| 478 } | |
| 479 #endif /* NEED_STRDUP */ | |
| 480 | |
| 481 | |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
482 /************************************************************************/ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
483 /* Lisp object allocation */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
484 /************************************************************************/ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
485 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
486 /* 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
|
487 Ffuncall() faster */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
488 #define INCREMENT_CONS_COUNTER_1(size) \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
489 do \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
490 { \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
491 consing_since_gc += (size); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
492 total_consing += (size); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
493 if (profiling_active) \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
494 profile_record_consing (size); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
495 recompute_need_to_garbage_collect (); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
496 } while (0) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
497 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
498 #define debug_allocation_backtrace() \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
499 do { \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
500 if (debug_allocation_backtrace_length > 0) \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
501 debug_short_backtrace (debug_allocation_backtrace_length); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
502 } while (0) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
503 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
504 #ifdef DEBUG_XEMACS |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
505 #define INCREMENT_CONS_COUNTER(foosize, type) \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
506 do { \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
507 if (debug_allocation) \ |
|
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 stderr_out ("allocating %s (size %ld)\n", type, \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
510 (long) foosize); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
511 debug_allocation_backtrace (); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
512 } \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
513 INCREMENT_CONS_COUNTER_1 (foosize); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
514 } while (0) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
515 #define NOSEEUM_INCREMENT_CONS_COUNTER(foosize, type) \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
516 do { \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
517 if (debug_allocation > 1) \ |
|
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 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
|
520 (long) foosize); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
521 debug_allocation_backtrace (); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
522 } \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
523 INCREMENT_CONS_COUNTER_1 (foosize); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
524 } while (0) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
525 #else |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
526 #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
|
527 #define NOSEEUM_INCREMENT_CONS_COUNTER(size, type) \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
528 INCREMENT_CONS_COUNTER_1 (size) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
529 #endif |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
530 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
531 #ifdef NEW_GC |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
532 /* [[ 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
|
533 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
|
534 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
|
535 is not needed. ]] -- not accurate! */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
536 #define DECREMENT_CONS_COUNTER(size) do { \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
537 consing_since_gc -= (size); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
538 total_consing -= (size); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
539 if (profiling_active) \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
540 profile_record_unconsing (size); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
541 if (consing_since_gc < 0) \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
542 consing_since_gc = 0; \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
543 } while (0) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
544 #else /* not NEW_GC */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
545 #define DECREMENT_CONS_COUNTER(size) do { \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
546 consing_since_gc -= (size); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
547 total_consing -= (size); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
548 if (profiling_active) \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
549 profile_record_unconsing (size); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
550 if (consing_since_gc < 0) \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
551 consing_since_gc = 0; \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
552 recompute_need_to_garbage_collect (); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
553 } while (0) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
554 #endif /*not NEW_GC */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
555 |
| 3263 | 556 #ifndef NEW_GC |
| 428 | 557 static void * |
| 665 | 558 allocate_lisp_storage (Bytecount size) |
| 428 | 559 { |
| 793 | 560 void *val = xmalloc (size); |
| 561 /* We don't increment the cons counter anymore. Calling functions do | |
| 562 that now because we have two different kinds of cons counters -- one | |
| 563 for normal objects, and one for no-see-um conses (and possibly others | |
| 564 similar) where the conses are used totally internally, never escape, | |
| 565 and are created and then freed and shouldn't logically increment the | |
| 566 cons counting. #### (Or perhaps, we should decrement it when an object | |
| 567 get freed?) */ | |
| 568 | |
| 569 /* But we do now (as of 3-27-02) go and zero out the memory. This is a | |
| 570 good thing, as it will guarantee we won't get any intermittent bugs | |
| 1204 | 571 coming from an uninitiated field. The speed loss is unnoticeable, |
| 572 esp. as the objects are not large -- large stuff like buffer text and | |
| 573 redisplay structures are allocated separately. */ | |
| 793 | 574 memset (val, 0, size); |
| 851 | 575 |
| 576 if (need_to_check_c_alloca) | |
| 577 xemacs_c_alloca (0); | |
| 578 | |
| 793 | 579 return val; |
| 428 | 580 } |
| 3263 | 581 #endif /* not NEW_GC */ |
| 582 | |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
583 #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
|
584 type_checking_assert \ |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
585 (implementation->static_size == 0 ? \ |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
586 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
|
587 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
|
588 implementation->static_size == size) |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
589 |
| 3263 | 590 #ifndef NEW_GC |
| 442 | 591 /* lcrecords are chained together through their "next" field. |
| 592 After doing the mark phase, GC will walk this linked list | |
| 593 and free any lcrecord which hasn't been marked. */ | |
| 3024 | 594 static struct old_lcrecord_header *all_lcrecords; |
| 3263 | 595 #endif /* not NEW_GC */ |
| 596 | |
| 597 #ifdef NEW_GC | |
| 2720 | 598 /* 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
|
599 static Lisp_Object |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
600 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
|
601 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
|
602 int noseeum) |
| 2720 | 603 { |
| 604 struct lrecord_header *lheader; | |
| 605 | |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
606 assert_proper_sizing (size); |
| 2720 | 607 |
| 608 lheader = (struct lrecord_header *) mc_alloc (size); | |
| 609 gc_checking_assert (LRECORD_FREE_P (lheader)); | |
| 610 set_lheader_implementation (lheader, implementation); | |
| 2994 | 611 #ifdef ALLOC_TYPE_STATS |
| 2720 | 612 inc_lrecord_stats (size, lheader); |
| 2994 | 613 #endif /* ALLOC_TYPE_STATS */ |
| 3263 | 614 if (implementation->finalizer) |
| 615 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
|
616 if (noseeum) |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
617 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
|
618 else |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
619 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
|
620 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
|
621 } |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
622 |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
623 Lisp_Object |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
624 alloc_sized_lrecord (Bytecount size, |
| 3092 | 625 const struct lrecord_implementation *implementation) |
| 626 { | |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
627 return alloc_sized_lrecord_1 (size, implementation, 0); |
| 2720 | 628 } |
| 629 | |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
630 Lisp_Object |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
631 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
|
632 const struct lrecord_implementation * |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
633 implementation) |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
634 { |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
635 return alloc_sized_lrecord_1 (size, implementation, 1); |
| 2720 | 636 } |
| 637 | |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
638 Lisp_Object |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
639 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
|
640 { |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
641 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
|
642 return alloc_sized_lrecord (implementation->static_size, implementation); |
| 2720 | 643 } |
| 644 | |
|
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
645 Lisp_Object |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
646 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
|
647 { |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
648 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
|
649 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
|
650 } |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
651 |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
652 Lisp_Object |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
653 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
|
654 const struct lrecord_implementation *implementation) |
| 3092 | 655 { |
| 656 struct lrecord_header *lheader; | |
| 657 Rawbyte *start, *stop; | |
| 658 | |
|
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
659 assert_proper_sizing (size); |
| 3092 | 660 |
| 661 lheader = (struct lrecord_header *) mc_alloc_array (size, elemcount); | |
| 662 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
|
663 |
| 3092 | 664 for (start = (Rawbyte *) lheader, |
|
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
665 /* #### FIXME: why is this -1 present? */ |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
666 stop = ((Rawbyte *) lheader) + (size * elemcount -1); |
| 3092 | 667 start < stop; start += size) |
| 668 { | |
| 669 struct lrecord_header *lh = (struct lrecord_header *) start; | |
| 670 set_lheader_implementation (lh, implementation); | |
| 671 #ifdef ALLOC_TYPE_STATS | |
| 672 inc_lrecord_stats (size, lh); | |
| 673 #endif /* not ALLOC_TYPE_STATS */ | |
| 3263 | 674 if (implementation->finalizer) |
| 675 add_finalizable_obj (wrap_pointer_1 (lh)); | |
| 3092 | 676 } |
|
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
677 |
| 3092 | 678 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
|
679 return wrap_pointer_1 (lheader); |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
680 } |
|
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 Lisp_Object |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
683 alloc_lrecord_array (int elemcount, |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
684 const struct lrecord_implementation *implementation) |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
685 { |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
686 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
|
687 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
|
688 implementation); |
| 3092 | 689 } |
| 690 | |
| 3263 | 691 #else /* not NEW_GC */ |
| 428 | 692 |
| 1204 | 693 /* The most basic of the lcrecord allocation functions. Not usually called |
| 694 directly. Allocates an lrecord not managed by any lcrecord-list, of a | |
| 695 specified size. See lrecord.h. */ | |
| 696 | |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
697 Lisp_Object |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
698 old_alloc_sized_lcrecord (Bytecount size, |
| 3024 | 699 const struct lrecord_implementation *implementation) |
| 700 { | |
| 701 struct old_lcrecord_header *lcheader; | |
| 428 | 702 |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
703 assert_proper_sizing (size); |
| 442 | 704 type_checking_assert |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
705 (!implementation->frob_block_p |
| 442 | 706 && |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
707 !(implementation->hash == NULL && implementation->equal != NULL)); |
| 428 | 708 |
| 3024 | 709 lcheader = (struct old_lcrecord_header *) allocate_lisp_storage (size); |
| 442 | 710 set_lheader_implementation (&lcheader->lheader, implementation); |
| 428 | 711 lcheader->next = all_lcrecords; |
| 712 all_lcrecords = lcheader; | |
| 713 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
|
714 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
|
715 } |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
716 |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
717 Lisp_Object |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
718 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
|
719 { |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
720 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
|
721 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
|
722 implementation); |
| 428 | 723 } |
| 724 | |
| 725 #if 0 /* Presently unused */ | |
| 726 /* Very, very poor man's EGC? | |
| 727 * This may be slow and thrash pages all over the place. | |
| 728 * Only call it if you really feel you must (and if the | |
| 729 * lrecord was fairly recently allocated). | |
| 730 * Otherwise, just let the GC do its job -- that's what it's there for | |
| 731 */ | |
| 732 void | |
| 3024 | 733 very_old_free_lcrecord (struct old_lcrecord_header *lcrecord) |
| 428 | 734 { |
| 735 if (all_lcrecords == lcrecord) | |
| 736 { | |
| 737 all_lcrecords = lcrecord->next; | |
| 738 } | |
| 739 else | |
| 740 { | |
| 3024 | 741 struct old_lcrecord_header *header = all_lcrecords; |
| 428 | 742 for (;;) |
| 743 { | |
| 3024 | 744 struct old_lcrecord_header *next = header->next; |
| 428 | 745 if (next == lcrecord) |
| 746 { | |
| 747 header->next = lrecord->next; | |
| 748 break; | |
| 749 } | |
| 750 else if (next == 0) | |
| 2500 | 751 ABORT (); |
| 428 | 752 else |
| 753 header = next; | |
| 754 } | |
| 755 } | |
| 756 if (lrecord->implementation->finalizer) | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
757 lrecord->implementation->finalizer (wrap_pointer_1 (lrecord)); |
| 428 | 758 xfree (lrecord); |
| 759 return; | |
| 760 } | |
| 761 #endif /* Unused */ | |
| 3263 | 762 #endif /* not NEW_GC */ |
| 428 | 763 |
| 1204 | 764 /* Bitwise copy all parts of a Lisp object other than the header */ |
| 765 | |
| 766 void | |
| 767 copy_lisp_object (Lisp_Object dst, Lisp_Object src) | |
| 768 { | |
| 769 const struct lrecord_implementation *imp = | |
| 770 XRECORD_LHEADER_IMPLEMENTATION (src); | |
| 771 Bytecount size = lisp_object_size (src); | |
| 772 | |
| 773 assert (imp == XRECORD_LHEADER_IMPLEMENTATION (dst)); | |
| 774 assert (size == lisp_object_size (dst)); | |
| 775 | |
| 3263 | 776 #ifdef NEW_GC |
| 2720 | 777 memcpy ((char *) XRECORD_LHEADER (dst) + sizeof (struct lrecord_header), |
| 778 (char *) XRECORD_LHEADER (src) + sizeof (struct lrecord_header), | |
| 779 size - sizeof (struct lrecord_header)); | |
| 3263 | 780 #else /* not NEW_GC */ |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
781 if (imp->frob_block_p) |
| 1204 | 782 memcpy ((char *) XRECORD_LHEADER (dst) + sizeof (struct lrecord_header), |
| 783 (char *) XRECORD_LHEADER (src) + sizeof (struct lrecord_header), | |
| 784 size - sizeof (struct lrecord_header)); | |
| 785 else | |
| 3024 | 786 memcpy ((char *) XRECORD_LHEADER (dst) + |
| 787 sizeof (struct old_lcrecord_header), | |
| 788 (char *) XRECORD_LHEADER (src) + | |
| 789 sizeof (struct old_lcrecord_header), | |
| 790 size - sizeof (struct old_lcrecord_header)); | |
| 3263 | 791 #endif /* not NEW_GC */ |
| 1204 | 792 } |
| 793 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
794 /* 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
|
795 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
|
796 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
|
797 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
|
798 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
|
799 |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
800 void |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
801 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
|
802 { |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
803 #ifndef NEW_GC |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
804 const struct lrecord_implementation *imp = |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
805 XRECORD_LHEADER_IMPLEMENTATION (obj); |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
806 #endif /* not NEW_GC */ |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
807 |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
808 #ifdef NEW_GC |
|
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 /* not NEW_GC */ |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
812 if (imp->frob_block_p) |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
813 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
|
814 size - sizeof (struct lrecord_header)); |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
815 else |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
816 memset ((char *) XRECORD_LHEADER (obj) + |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
817 sizeof (struct old_lcrecord_header), 0, |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
818 size - sizeof (struct old_lcrecord_header)); |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
819 #endif /* not NEW_GC */ |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
820 } |
|
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 /* 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
|
823 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
|
824 zero_sized_lisp_object(). |
|
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 |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
827 void |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
828 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
|
829 { |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
830 const struct lrecord_implementation *imp = |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
831 XRECORD_LHEADER_IMPLEMENTATION (obj); |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
832 assert (!imp->size_in_bytes_method); |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
833 |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
834 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
|
835 } |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
836 |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
837 void |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
838 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
|
839 { |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
840 #ifndef NEW_GC |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
841 const struct lrecord_implementation *imp = |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
842 XRECORD_LHEADER_IMPLEMENTATION (obj); |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
843 #endif /* not NEW_GC */ |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
844 |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
845 #ifdef NEW_GC |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
846 /* 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
|
847 return; |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
848 #else |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
849 assert (!imp->frob_block_p); |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
850 assert (!imp->size_in_bytes_method); |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
851 old_free_lcrecord (obj); |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
852 #endif |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
853 } |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
854 |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
855 #ifndef NEW_GC |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
856 int |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
857 c_readonly (Lisp_Object obj) |
|
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 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
|
860 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
861 #endif /* not NEW_GC */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
862 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
863 int |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
864 lisp_readonly (Lisp_Object obj) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
865 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
866 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
|
867 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
868 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
869 /* #### Should be made into an object method */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
870 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
871 int |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
872 object_dead_p (Lisp_Object obj) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
873 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
874 return ((BUFFERP (obj) && !BUFFER_LIVE_P (XBUFFER (obj))) || |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
875 (FRAMEP (obj) && !FRAME_LIVE_P (XFRAME (obj))) || |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
876 (WINDOWP (obj) && !WINDOW_LIVE_P (XWINDOW (obj))) || |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
877 (DEVICEP (obj) && !DEVICE_LIVE_P (XDEVICE (obj))) || |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
878 (CONSOLEP (obj) && !CONSOLE_LIVE_P (XCONSOLE (obj))) || |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
879 (EVENTP (obj) && !EVENT_LIVE_P (XEVENT (obj))) || |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
880 (EXTENTP (obj) && !EXTENT_LIVE_P (XEXTENT (obj)))); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
881 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
882 |
| 428 | 883 |
| 884 /************************************************************************/ | |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
885 /* Debugger support */ |
| 428 | 886 /************************************************************************/ |
| 887 /* Give gdb/dbx enough information to decode Lisp Objects. We make | |
| 888 sure certain symbols are always defined, so gdb doesn't complain | |
| 438 | 889 about expressions in src/.gdbinit. See src/.gdbinit or src/.dbxrc |
| 890 to see how this is used. */ | |
| 428 | 891 |
| 458 | 892 EMACS_UINT dbg_valmask = ((1UL << VALBITS) - 1) << GCBITS; |
| 893 EMACS_UINT dbg_typemask = (1UL << GCTYPEBITS) - 1; | |
| 428 | 894 |
| 895 #ifdef USE_UNION_TYPE | |
| 458 | 896 unsigned char dbg_USE_UNION_TYPE = 1; |
| 428 | 897 #else |
| 458 | 898 unsigned char dbg_USE_UNION_TYPE = 0; |
| 428 | 899 #endif |
| 900 | |
| 458 | 901 unsigned char dbg_valbits = VALBITS; |
| 902 unsigned char dbg_gctypebits = GCTYPEBITS; | |
| 903 | |
| 904 /* On some systems, the above definitions will be optimized away by | |
| 905 the compiler or linker unless they are referenced in some function. */ | |
| 906 long dbg_inhibit_dbg_symbol_deletion (void); | |
| 907 long | |
| 908 dbg_inhibit_dbg_symbol_deletion (void) | |
| 909 { | |
| 910 return | |
| 911 (dbg_valmask + | |
| 912 dbg_typemask + | |
| 913 dbg_USE_UNION_TYPE + | |
| 914 dbg_valbits + | |
| 915 dbg_gctypebits); | |
| 916 } | |
| 428 | 917 |
| 918 /* Macros turned into functions for ease of debugging. | |
| 919 Debuggers don't know about macros! */ | |
| 920 int dbg_eq (Lisp_Object obj1, Lisp_Object obj2); | |
| 921 int | |
| 922 dbg_eq (Lisp_Object obj1, Lisp_Object obj2) | |
| 923 { | |
| 924 return EQ (obj1, obj2); | |
| 925 } | |
| 926 | |
| 927 | |
| 3263 | 928 #ifdef NEW_GC |
| 3017 | 929 #define DECLARE_FIXED_TYPE_ALLOC(type, structture) struct __foo__ |
| 930 #else | |
| 428 | 931 /************************************************************************/ |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
932 /* Fixed-size type macros */ |
| 428 | 933 /************************************************************************/ |
| 934 | |
| 935 /* For fixed-size types that are commonly used, we malloc() large blocks | |
| 936 of memory at a time and subdivide them into chunks of the correct | |
| 937 size for an object of that type. This is more efficient than | |
| 938 malloc()ing each object separately because we save on malloc() time | |
| 939 and overhead due to the fewer number of malloc()ed blocks, and | |
| 940 also because we don't need any extra pointers within each object | |
| 941 to keep them threaded together for GC purposes. For less common | |
| 942 (and frequently large-size) types, we use lcrecords, which are | |
| 943 malloc()ed individually and chained together through a pointer | |
| 944 in the lcrecord header. lcrecords do not need to be fixed-size | |
| 945 (i.e. two objects of the same type need not have the same size; | |
| 946 however, the size of a particular object cannot vary dynamically). | |
| 947 It is also much easier to create a new lcrecord type because no | |
| 948 additional code needs to be added to alloc.c. Finally, lcrecords | |
| 949 may be more efficient when there are only a small number of them. | |
| 950 | |
| 951 The types that are stored in these large blocks (or "frob blocks") | |
| 1983 | 952 are cons, all number types except fixnum, compiled-function, symbol, |
| 953 marker, extent, event, and string. | |
| 428 | 954 |
| 955 Note that strings are special in that they are actually stored in | |
| 956 two parts: a structure containing information about the string, and | |
| 957 the actual data associated with the string. The former structure | |
| 958 (a struct Lisp_String) is a fixed-size structure and is managed the | |
| 959 same way as all the other such types. This structure contains a | |
| 960 pointer to the actual string data, which is stored in structures of | |
| 961 type struct string_chars_block. Each string_chars_block consists | |
| 962 of a pointer to a struct Lisp_String, followed by the data for that | |
| 440 | 963 string, followed by another pointer to a Lisp_String, followed by |
| 964 the data for that string, etc. At GC time, the data in these | |
| 965 blocks is compacted by searching sequentially through all the | |
| 428 | 966 blocks and compressing out any holes created by unmarked strings. |
| 967 Strings that are more than a certain size (bigger than the size of | |
| 968 a string_chars_block, although something like half as big might | |
| 969 make more sense) are malloc()ed separately and not stored in | |
| 970 string_chars_blocks. Furthermore, no one string stretches across | |
| 971 two string_chars_blocks. | |
| 972 | |
| 1204 | 973 Vectors are each malloc()ed separately as lcrecords. |
| 428 | 974 |
| 975 In the following discussion, we use conses, but it applies equally | |
| 976 well to the other fixed-size types. | |
| 977 | |
| 978 We store cons cells inside of cons_blocks, allocating a new | |
| 979 cons_block with malloc() whenever necessary. Cons cells reclaimed | |
| 980 by GC are put on a free list to be reallocated before allocating | |
| 981 any new cons cells from the latest cons_block. Each cons_block is | |
| 982 just under 2^n - MALLOC_OVERHEAD bytes long, since malloc (at least | |
| 983 the versions in malloc.c and gmalloc.c) really allocates in units | |
| 984 of powers of two and uses 4 bytes for its own overhead. | |
| 985 | |
| 986 What GC actually does is to search through all the cons_blocks, | |
| 987 from the most recently allocated to the oldest, and put all | |
| 988 cons cells that are not marked (whether or not they're already | |
| 989 free) on a cons_free_list. The cons_free_list is a stack, and | |
| 990 so the cons cells in the oldest-allocated cons_block end up | |
| 991 at the head of the stack and are the first to be reallocated. | |
| 992 If any cons_block is entirely free, it is freed with free() | |
| 993 and its cons cells removed from the cons_free_list. Because | |
| 994 the cons_free_list ends up basically in memory order, we have | |
| 995 a high locality of reference (assuming a reasonable turnover | |
| 996 of allocating and freeing) and have a reasonable probability | |
| 997 of entirely freeing up cons_blocks that have been more recently | |
| 998 allocated. This stage is called the "sweep stage" of GC, and | |
| 999 is executed after the "mark stage", which involves starting | |
| 1000 from all places that are known to point to in-use Lisp objects | |
| 1001 (e.g. the obarray, where are all symbols are stored; the | |
| 1002 current catches and condition-cases; the backtrace list of | |
| 1003 currently executing functions; the gcpro list; etc.) and | |
| 1004 recursively marking all objects that are accessible. | |
| 1005 | |
| 454 | 1006 At the beginning of the sweep stage, the conses in the cons blocks |
| 1007 are in one of three states: in use and marked, in use but not | |
| 1008 marked, and not in use (already freed). Any conses that are marked | |
| 1009 have been marked in the mark stage just executed, because as part | |
| 1010 of the sweep stage we unmark any marked objects. The way we tell | |
| 1011 whether or not a cons cell is in use is through the LRECORD_FREE_P | |
| 1012 macro. This uses a special lrecord type `lrecord_type_free', | |
| 1013 which is never associated with any valid object. | |
| 1014 | |
| 1015 Conses on the free_cons_list are threaded through a pointer stored | |
| 1016 in the conses themselves. Because the cons is still in a | |
| 1017 cons_block and needs to remain marked as not in use for the next | |
| 1018 time that GC happens, we need room to store both the "free" | |
| 1019 indicator and the chaining pointer. So this pointer is stored | |
| 1020 after the lrecord header (actually where C places a pointer after | |
| 1021 the lrecord header; they are not necessarily contiguous). This | |
| 1022 implies that all fixed-size types must be big enough to contain at | |
| 1023 least one pointer. This is true for all current fixed-size types, | |
| 1024 with the possible exception of Lisp_Floats, for which we define the | |
| 1025 meat of the struct using a union of a pointer and a double to | |
| 1026 ensure adequate space for the free list chain pointer. | |
| 428 | 1027 |
| 1028 Some types of objects need additional "finalization" done | |
| 1029 when an object is converted from in use to not in use; | |
| 1030 this is the purpose of the ADDITIONAL_FREE_type macro. | |
| 1031 For example, markers need to be removed from the chain | |
| 1032 of markers that is kept in each buffer. This is because | |
| 1033 markers in a buffer automatically disappear if the marker | |
| 1034 is no longer referenced anywhere (the same does not | |
| 1035 apply to extents, however). | |
| 1036 | |
| 1037 WARNING: Things are in an extremely bizarre state when | |
| 1038 the ADDITIONAL_FREE_type macros are called, so beware! | |
| 1039 | |
| 454 | 1040 When ERROR_CHECK_GC is defined, we do things differently so as to |
| 1041 maximize our chances of catching places where there is insufficient | |
| 1042 GCPROing. The thing we want to avoid is having an object that | |
| 1043 we're using but didn't GCPRO get freed by GC and then reallocated | |
| 1044 while we're in the process of using it -- this will result in | |
| 1045 something seemingly unrelated getting trashed, and is extremely | |
| 1046 difficult to track down. If the object gets freed but not | |
| 1047 reallocated, we can usually catch this because we set most of the | |
| 1048 bytes of a freed object to 0xDEADBEEF. (The lisp object type is set | |
| 1049 to the invalid type `lrecord_type_free', however, and a pointer | |
| 1050 used to chain freed objects together is stored after the lrecord | |
| 1051 header; we play some tricks with this pointer to make it more | |
| 428 | 1052 bogus, so crashes are more likely to occur right away.) |
| 1053 | |
| 1054 We want freed objects to stay free as long as possible, | |
| 1055 so instead of doing what we do above, we maintain the | |
| 1056 free objects in a first-in first-out queue. We also | |
| 1057 don't recompute the free list each GC, unlike above; | |
| 1058 this ensures that the queue ordering is preserved. | |
| 1059 [This means that we are likely to have worse locality | |
| 1060 of reference, and that we can never free a frob block | |
| 1061 once it's allocated. (Even if we know that all cells | |
| 1062 in it are free, there's no easy way to remove all those | |
| 1063 cells from the free list because the objects on the | |
| 1064 free list are unlikely to be in memory order.)] | |
| 1065 Furthermore, we never take objects off the free list | |
| 1066 unless there's a large number (usually 1000, but | |
| 1067 varies depending on type) of them already on the list. | |
| 1068 This way, we ensure that an object that gets freed will | |
| 1069 remain free for the next 1000 (or whatever) times that | |
| 440 | 1070 an object of that type is allocated. */ |
| 428 | 1071 |
| 1072 #ifdef ALLOC_NO_POOLS | |
| 1073 # define TYPE_ALLOC_SIZE(type, structtype) 1 | |
| 1074 #else | |
| 1075 # define TYPE_ALLOC_SIZE(type, structtype) \ | |
| 1076 ((2048 - MALLOC_OVERHEAD - sizeof (struct type##_block *)) \ | |
| 1077 / sizeof (structtype)) | |
| 1078 #endif /* ALLOC_NO_POOLS */ | |
| 1079 | |
| 1080 #define DECLARE_FIXED_TYPE_ALLOC(type, structtype) \ | |
| 1081 \ | |
| 1082 struct type##_block \ | |
| 1083 { \ | |
| 1084 struct type##_block *prev; \ | |
| 1085 structtype block[TYPE_ALLOC_SIZE (type, structtype)]; \ | |
| 1086 }; \ | |
| 1087 \ | |
| 1088 static struct type##_block *current_##type##_block; \ | |
| 1089 static int current_##type##_block_index; \ | |
| 1090 \ | |
| 454 | 1091 static Lisp_Free *type##_free_list; \ |
| 1092 static Lisp_Free *type##_free_list_tail; \ | |
| 428 | 1093 \ |
| 1094 static void \ | |
| 1095 init_##type##_alloc (void) \ | |
| 1096 { \ | |
| 1097 current_##type##_block = 0; \ | |
| 1098 current_##type##_block_index = \ | |
| 1099 countof (current_##type##_block->block); \ | |
| 1100 type##_free_list = 0; \ | |
| 1101 type##_free_list_tail = 0; \ | |
| 1102 } \ | |
| 1103 \ | |
| 1104 static int gc_count_num_##type##_in_use; \ | |
| 1105 static int gc_count_num_##type##_freelist | |
| 1106 | |
| 1107 #define ALLOCATE_FIXED_TYPE_FROM_BLOCK(type, result) do { \ | |
| 1108 if (current_##type##_block_index \ | |
| 1109 == countof (current_##type##_block->block)) \ | |
| 1110 { \ | |
| 1111 struct type##_block *AFTFB_new = (struct type##_block *) \ | |
| 1112 allocate_lisp_storage (sizeof (struct type##_block)); \ | |
| 1113 AFTFB_new->prev = current_##type##_block; \ | |
| 1114 current_##type##_block = AFTFB_new; \ | |
| 1115 current_##type##_block_index = 0; \ | |
| 1116 } \ | |
| 1117 (result) = \ | |
| 1118 &(current_##type##_block->block[current_##type##_block_index++]); \ | |
| 1119 } while (0) | |
| 1120 | |
| 1121 /* Allocate an instance of a type that is stored in blocks. | |
| 1122 TYPE is the "name" of the type, STRUCTTYPE is the corresponding | |
| 1123 structure type. */ | |
| 1124 | |
| 1125 #ifdef ERROR_CHECK_GC | |
| 1126 | |
| 1127 /* Note: if you get crashes in this function, suspect incorrect calls | |
| 1128 to free_cons() and friends. This happened once because the cons | |
| 1129 cell was not GC-protected and was getting collected before | |
| 1130 free_cons() was called. */ | |
| 1131 | |
| 454 | 1132 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) do { \ |
| 1133 if (gc_count_num_##type##_freelist > \ | |
| 1134 MINIMUM_ALLOWED_FIXED_TYPE_CELLS_##type) \ | |
| 1135 { \ | |
| 1136 result = (structtype *) type##_free_list; \ | |
| 1204 | 1137 assert (LRECORD_FREE_P (result)); \ |
| 1138 /* Before actually using the chain pointer, we complement \ | |
| 1139 all its bits; see PUT_FIXED_TYPE_ON_FREE_LIST(). */ \ | |
| 454 | 1140 type##_free_list = (Lisp_Free *) \ |
| 1141 (~ (EMACS_UINT) (type##_free_list->chain)); \ | |
| 1142 gc_count_num_##type##_freelist--; \ | |
| 1143 } \ | |
| 1144 else \ | |
| 1145 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \ | |
| 1146 MARK_LRECORD_AS_NOT_FREE (result); \ | |
| 428 | 1147 } while (0) |
| 1148 | |
| 1149 #else /* !ERROR_CHECK_GC */ | |
| 1150 | |
| 454 | 1151 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) do { \ |
| 428 | 1152 if (type##_free_list) \ |
| 1153 { \ | |
| 454 | 1154 result = (structtype *) type##_free_list; \ |
| 1155 type##_free_list = type##_free_list->chain; \ | |
| 428 | 1156 } \ |
| 1157 else \ | |
| 1158 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \ | |
| 454 | 1159 MARK_LRECORD_AS_NOT_FREE (result); \ |
| 428 | 1160 } while (0) |
| 1161 | |
| 1162 #endif /* !ERROR_CHECK_GC */ | |
| 1163 | |
| 454 | 1164 |
| 428 | 1165 #define ALLOCATE_FIXED_TYPE(type, structtype, result) \ |
| 1166 do \ | |
| 1167 { \ | |
| 1168 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \ | |
| 1169 INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \ | |
| 1170 } while (0) | |
| 1171 | |
| 1172 #define NOSEEUM_ALLOCATE_FIXED_TYPE(type, structtype, result) \ | |
| 1173 do \ | |
| 1174 { \ | |
| 1175 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \ | |
| 1176 NOSEEUM_INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \ | |
| 1177 } while (0) | |
| 1178 | |
| 454 | 1179 /* Lisp_Free is the type to represent a free list member inside a frob |
| 1180 block of any lisp object type. */ | |
| 1181 typedef struct Lisp_Free | |
| 1182 { | |
| 1183 struct lrecord_header lheader; | |
| 1184 struct Lisp_Free *chain; | |
| 1185 } Lisp_Free; | |
| 1186 | |
| 1187 #define LRECORD_FREE_P(ptr) \ | |
| 771 | 1188 (((struct lrecord_header *) ptr)->type == lrecord_type_free) |
| 454 | 1189 |
| 1190 #define MARK_LRECORD_AS_FREE(ptr) \ | |
| 771 | 1191 ((void) (((struct lrecord_header *) ptr)->type = lrecord_type_free)) |
| 454 | 1192 |
| 1193 #ifdef ERROR_CHECK_GC | |
| 1194 #define MARK_LRECORD_AS_NOT_FREE(ptr) \ | |
| 771 | 1195 ((void) (((struct lrecord_header *) ptr)->type = lrecord_type_undefined)) |
| 428 | 1196 #else |
| 454 | 1197 #define MARK_LRECORD_AS_NOT_FREE(ptr) DO_NOTHING |
| 428 | 1198 #endif |
| 1199 | |
| 1200 #ifdef ERROR_CHECK_GC | |
| 1201 | |
| 454 | 1202 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) do { \ |
| 1203 if (type##_free_list_tail) \ | |
| 1204 { \ | |
| 1205 /* When we store the chain pointer, we complement all \ | |
| 1206 its bits; this should significantly increase its \ | |
| 1207 bogosity in case someone tries to use the value, and \ | |
| 1208 should make us crash faster if someone overwrites the \ | |
| 1209 pointer because when it gets un-complemented in \ | |
| 1210 ALLOCATED_FIXED_TYPE(), the resulting pointer will be \ | |
| 1211 extremely bogus. */ \ | |
| 1212 type##_free_list_tail->chain = \ | |
| 1213 (Lisp_Free *) ~ (EMACS_UINT) (ptr); \ | |
| 1214 } \ | |
| 1215 else \ | |
| 1216 type##_free_list = (Lisp_Free *) (ptr); \ | |
| 1217 type##_free_list_tail = (Lisp_Free *) (ptr); \ | |
| 1218 } while (0) | |
| 428 | 1219 |
| 1220 #else /* !ERROR_CHECK_GC */ | |
| 1221 | |
| 454 | 1222 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) do { \ |
| 1223 ((Lisp_Free *) (ptr))->chain = type##_free_list; \ | |
| 1224 type##_free_list = (Lisp_Free *) (ptr); \ | |
| 1225 } while (0) \ | |
| 428 | 1226 |
| 1227 #endif /* !ERROR_CHECK_GC */ | |
| 1228 | |
| 1229 /* TYPE and STRUCTTYPE are the same as in ALLOCATE_FIXED_TYPE(). */ | |
| 1230 | |
| 1231 #define FREE_FIXED_TYPE(type, structtype, ptr) do { \ | |
| 1232 structtype *FFT_ptr = (ptr); \ | |
| 1204 | 1233 gc_checking_assert (!LRECORD_FREE_P (FFT_ptr)); \ |
| 2367 | 1234 gc_checking_assert (!DUMPEDP (FFT_ptr)); \ |
| 428 | 1235 ADDITIONAL_FREE_##type (FFT_ptr); \ |
| 1236 deadbeef_memory (FFT_ptr, sizeof (structtype)); \ | |
| 1237 PUT_FIXED_TYPE_ON_FREE_LIST (type, structtype, FFT_ptr); \ | |
| 454 | 1238 MARK_LRECORD_AS_FREE (FFT_ptr); \ |
| 428 | 1239 } while (0) |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1240 #endif /* NEW_GC */ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1241 |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1242 #ifdef NEW_GC |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1243 #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
|
1244 free_normal_lisp_object (lo) |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1245 #else /* not NEW_GC */ |
| 428 | 1246 /* Like FREE_FIXED_TYPE() but used when we are explicitly |
| 1247 freeing a structure through free_cons(), free_marker(), etc. | |
| 1248 rather than through the normal process of sweeping. | |
| 1249 We attempt to undo the changes made to the allocation counters | |
| 1250 as a result of this structure being allocated. This is not | |
| 1251 completely necessary but helps keep things saner: e.g. this way, | |
| 1252 repeatedly allocating and freeing a cons will not result in | |
| 1253 the consing-since-gc counter advancing, which would cause a GC | |
| 1204 | 1254 and somewhat defeat the purpose of explicitly freeing. |
| 1255 | |
| 1256 We also disable this mechanism entirely when ALLOC_NO_POOLS is | |
| 1257 set, which is used for Purify and the like. */ | |
| 1258 | |
| 1259 #ifndef ALLOC_NO_POOLS | |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1260 #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
|
1261 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
|
1262 DECREMENT_CONS_COUNTER (sizeof (structtype)); \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1263 gc_count_num_##type##_freelist++; \ |
| 428 | 1264 } while (0) |
| 1204 | 1265 #else |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1266 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(lo, type, structtype, ptr) |
| 1204 | 1267 #endif |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
1268 #endif /* (not) NEW_GC */ |
| 3263 | 1269 |
| 1270 #ifdef NEW_GC | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1271 #define ALLOC_FROB_BLOCK_LISP_OBJECT(type, lisp_type, var, lrec_ptr)\ |
| 3017 | 1272 do { \ |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1273 (var) = (lisp_type *) XPNTR (ALLOC_NORMAL_LISP_OBJECT (type)); \ |
| 3017 | 1274 } while (0) |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1275 #define NOSEEUM_ALLOC_FROB_BLOCK_LISP_OBJECT(type, lisp_type, var, \ |
| 3017 | 1276 lrec_ptr) \ |
| 1277 do { \ | |
|
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1278 (var) = (lisp_type *) XPNTR (noseeum_alloc_lrecord (lrec_ptr)); \ |
| 3017 | 1279 } while (0) |
| 3263 | 1280 #else /* not NEW_GC */ |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1281 #define ALLOC_FROB_BLOCK_LISP_OBJECT(type, lisp_type, var, lrec_ptr) \ |
| 3017 | 1282 do \ |
| 1283 { \ | |
| 1284 ALLOCATE_FIXED_TYPE (type, lisp_type, var); \ | |
| 1285 set_lheader_implementation (&(var)->lheader, lrec_ptr); \ | |
| 1286 } while (0) | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1287 #define NOSEEUM_ALLOC_FROB_BLOCK_LISP_OBJECT(type, lisp_type, var, \ |
| 3017 | 1288 lrec_ptr) \ |
| 1289 do \ | |
| 1290 { \ | |
| 1291 NOSEEUM_ALLOCATE_FIXED_TYPE (type, lisp_type, var); \ | |
| 1292 set_lheader_implementation (&(var)->lheader, lrec_ptr); \ | |
| 1293 } while (0) | |
| 3263 | 1294 #endif /* not NEW_GC */ |
| 3017 | 1295 |
| 428 | 1296 |
| 1297 | |
| 1298 /************************************************************************/ | |
| 1299 /* Cons allocation */ | |
| 1300 /************************************************************************/ | |
| 1301 | |
| 440 | 1302 DECLARE_FIXED_TYPE_ALLOC (cons, Lisp_Cons); |
| 428 | 1303 /* conses are used and freed so often that we set this really high */ |
| 1304 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 20000 */ | |
| 1305 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 2000 | |
| 1306 | |
| 1307 static Lisp_Object | |
| 1308 mark_cons (Lisp_Object obj) | |
| 1309 { | |
| 1310 if (NILP (XCDR (obj))) | |
| 1311 return XCAR (obj); | |
| 1312 | |
| 1313 mark_object (XCAR (obj)); | |
| 1314 return XCDR (obj); | |
| 1315 } | |
| 1316 | |
| 1317 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
|
1318 cons_equal (Lisp_Object ob1, Lisp_Object ob2, int depth, int foldcase) |
| 428 | 1319 { |
| 442 | 1320 depth++; |
|
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1321 while (internal_equal_0 (XCAR (ob1), XCAR (ob2), depth, foldcase)) |
| 428 | 1322 { |
| 1323 ob1 = XCDR (ob1); | |
| 1324 ob2 = XCDR (ob2); | |
| 1325 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
|
1326 return internal_equal_0 (ob1, ob2, depth, foldcase); |
| 428 | 1327 } |
| 1328 return 0; | |
| 1329 } | |
| 1330 | |
| 1204 | 1331 static const struct memory_description cons_description[] = { |
| 853 | 1332 { XD_LISP_OBJECT, offsetof (Lisp_Cons, car_) }, |
| 1333 { XD_LISP_OBJECT, offsetof (Lisp_Cons, cdr_) }, | |
| 428 | 1334 { XD_END } |
| 1335 }; | |
| 1336 | |
|
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1337 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
|
1338 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
|
1339 /* |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1340 * No `hash' method needed. |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1341 * internal_hash knows how to |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1342 * handle conses. |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1343 */ |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1344 0, cons_description, Lisp_Cons); |
| 428 | 1345 |
| 1346 DEFUN ("cons", Fcons, 2, 2, 0, /* | |
| 3355 | 1347 Create a new cons cell, give it CAR and CDR as components, and return it. |
| 1348 | |
| 1349 A cons cell is a Lisp object (an area in memory) made up of two pointers | |
| 1350 called the CAR and the CDR. Each of these pointers can point to any other | |
| 1351 Lisp object. The common Lisp data type, the list, is a specially-structured | |
| 1352 series of cons cells. | |
| 1353 | |
| 1354 The pointers are accessed from Lisp with `car' and `cdr', and mutated with | |
| 1355 `setcar' and `setcdr' respectively. For historical reasons, the aliases | |
| 1356 `rplaca' and `rplacd' (for `setcar' and `setcdr') are supported. | |
| 428 | 1357 */ |
| 1358 (car, cdr)) | |
| 1359 { | |
| 1360 /* This cannot GC. */ | |
| 1361 Lisp_Object val; | |
| 440 | 1362 Lisp_Cons *c; |
| 1363 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1364 ALLOC_FROB_BLOCK_LISP_OBJECT (cons, Lisp_Cons, c, &lrecord_cons); |
| 793 | 1365 val = wrap_cons (c); |
| 853 | 1366 XSETCAR (val, car); |
| 1367 XSETCDR (val, cdr); | |
| 428 | 1368 return val; |
| 1369 } | |
| 1370 | |
| 1371 /* This is identical to Fcons() but it used for conses that we're | |
| 1372 going to free later, and is useful when trying to track down | |
| 1373 "real" consing. */ | |
| 1374 Lisp_Object | |
| 1375 noseeum_cons (Lisp_Object car, Lisp_Object cdr) | |
| 1376 { | |
| 1377 Lisp_Object val; | |
| 440 | 1378 Lisp_Cons *c; |
| 1379 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1380 NOSEEUM_ALLOC_FROB_BLOCK_LISP_OBJECT (cons, Lisp_Cons, c, &lrecord_cons); |
| 793 | 1381 val = wrap_cons (c); |
| 428 | 1382 XCAR (val) = car; |
| 1383 XCDR (val) = cdr; | |
| 1384 return val; | |
| 1385 } | |
| 1386 | |
| 1387 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
|
1388 Return a newly created list with specified ARGS as elements. |
| 428 | 1389 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
|
1390 |
|
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1391 arguments: (&rest ARGS) |
| 428 | 1392 */ |
| 1393 (int nargs, Lisp_Object *args)) | |
| 1394 { | |
| 1395 Lisp_Object val = Qnil; | |
| 1396 Lisp_Object *argp = args + nargs; | |
| 1397 | |
| 1398 while (argp > args) | |
| 1399 val = Fcons (*--argp, val); | |
| 1400 return val; | |
| 1401 } | |
| 1402 | |
| 1403 Lisp_Object | |
| 1404 list1 (Lisp_Object obj0) | |
| 1405 { | |
| 1406 /* This cannot GC. */ | |
| 1407 return Fcons (obj0, Qnil); | |
| 1408 } | |
| 1409 | |
| 1410 Lisp_Object | |
| 1411 list2 (Lisp_Object obj0, Lisp_Object obj1) | |
| 1412 { | |
| 1413 /* This cannot GC. */ | |
| 1414 return Fcons (obj0, Fcons (obj1, Qnil)); | |
| 1415 } | |
| 1416 | |
| 1417 Lisp_Object | |
| 1418 list3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2) | |
| 1419 { | |
| 1420 /* This cannot GC. */ | |
| 1421 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Qnil))); | |
| 1422 } | |
| 1423 | |
| 1424 Lisp_Object | |
| 1425 cons3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2) | |
| 1426 { | |
| 1427 /* This cannot GC. */ | |
| 1428 return Fcons (obj0, Fcons (obj1, obj2)); | |
| 1429 } | |
| 1430 | |
|
5354
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
1431 DEFUN ("acons", Facons, 3, 3, 0, /* |
|
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
1432 Return a new alist created by prepending (KEY . VALUE) to ALIST. |
|
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
1433 */ |
|
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
1434 (key, value, alist)) |
| 428 | 1435 { |
| 1436 return Fcons (Fcons (key, value), alist); | |
| 1437 } | |
| 1438 | |
| 1439 Lisp_Object | |
| 1440 list4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3) | |
| 1441 { | |
| 1442 /* This cannot GC. */ | |
| 1443 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Qnil)))); | |
| 1444 } | |
| 1445 | |
| 1446 Lisp_Object | |
| 1447 list5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3, | |
| 1448 Lisp_Object obj4) | |
| 1449 { | |
| 1450 /* This cannot GC. */ | |
| 1451 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Fcons (obj4, Qnil))))); | |
| 1452 } | |
| 1453 | |
| 1454 Lisp_Object | |
| 1455 list6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3, | |
| 1456 Lisp_Object obj4, Lisp_Object obj5) | |
| 1457 { | |
| 1458 /* This cannot GC. */ | |
| 1459 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Fcons (obj4, Fcons (obj5, Qnil)))))); | |
| 1460 } | |
| 1461 | |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1462 /* 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
|
1463 |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1464 Lisp_Object |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1465 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
|
1466 { |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1467 Lisp_Object obj = Qnil; |
|
5386
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1468 |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1469 if (!UNBOUNDP (first)) |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1470 { |
|
5386
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1471 va_list va; |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1472 Lisp_Object last, val; |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1473 |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1474 last = obj = Fcons (first, Qnil); |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1475 va_start (va, first); |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1476 val = va_arg (va, Lisp_Object); |
|
5386
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1477 while (!UNBOUNDP (val)) |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1478 { |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1479 last = XCDR (last) = Fcons (val, Qnil); |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1480 val = va_arg (va, Lisp_Object); |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1481 } |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1482 va_end (va); |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1483 } |
|
5386
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1484 return obj; |
|
5157
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 |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1487 /* 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
|
1488 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
|
1489 |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1490 Lisp_Object |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1491 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
|
1492 { |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1493 Lisp_Object obj = Qnil; |
|
5386
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1494 |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1495 if (num_args > 0) |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1496 { |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1497 va_list va; |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1498 Lisp_Object last; |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1499 int i; |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1500 |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1501 va_start (va, num_args); |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1502 last = obj = Fcons (va_arg (va, Lisp_Object), Qnil); |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1503 for (i = 1; i < num_args; i++) |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1504 last = XCDR (last) = Fcons (va_arg (va, Lisp_Object), Qnil); |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1505 va_end (va); |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1506 } |
|
af961911bcb2
Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents:
5384
diff
changeset
|
1507 return obj; |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1508 } |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1509 |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1510 /* 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
|
1511 of elements. */ |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
1512 |
| 428 | 1513 DEFUN ("make-list", Fmake_list, 2, 2, 0, /* |
| 444 | 1514 Return a new list of length LENGTH, with each element being OBJECT. |
| 428 | 1515 */ |
| 444 | 1516 (length, object)) |
| 428 | 1517 { |
|
5307
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1518 Lisp_Object val = Qnil; |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1519 Elemcount size; |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1520 |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1521 check_integer_range (length, Qzero, make_integer (EMACS_INT_MAX)); |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1522 |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1523 size = XINT (length); |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1524 |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1525 while (size--) |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1526 val = Fcons (object, val); |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1527 |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1528 return val; |
| 428 | 1529 } |
| 1530 | |
| 1531 | |
| 1532 /************************************************************************/ | |
| 1533 /* Float allocation */ | |
| 1534 /************************************************************************/ | |
| 1535 | |
| 1983 | 1536 /*** With enhanced number support, these are short floats */ |
| 1537 | |
| 440 | 1538 DECLARE_FIXED_TYPE_ALLOC (float, Lisp_Float); |
| 428 | 1539 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_float 1000 |
| 1540 | |
| 1541 Lisp_Object | |
| 1542 make_float (double float_value) | |
| 1543 { | |
| 440 | 1544 Lisp_Float *f; |
| 1545 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1546 ALLOC_FROB_BLOCK_LISP_OBJECT (float, Lisp_Float, f, &lrecord_float); |
| 440 | 1547 |
| 1548 /* Avoid dump-time `uninitialized memory read' purify warnings. */ | |
| 1549 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
|
1550 zero_nonsized_lisp_object (wrap_float (f)); |
| 3017 | 1551 |
| 428 | 1552 float_data (f) = float_value; |
| 793 | 1553 return wrap_float (f); |
| 428 | 1554 } |
| 1555 | |
| 1556 | |
| 1557 /************************************************************************/ | |
| 1983 | 1558 /* Enhanced number allocation */ |
| 1559 /************************************************************************/ | |
| 1560 | |
| 1561 /*** Bignum ***/ | |
| 1562 #ifdef HAVE_BIGNUM | |
| 1563 DECLARE_FIXED_TYPE_ALLOC (bignum, Lisp_Bignum); | |
| 1564 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bignum 250 | |
| 1565 | |
| 1566 /* WARNING: This function returns a bignum even if its argument fits into a | |
| 1567 fixnum. See Fcanonicalize_number(). */ | |
| 1568 Lisp_Object | |
| 1569 make_bignum (long bignum_value) | |
| 1570 { | |
| 1571 Lisp_Bignum *b; | |
| 1572 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1573 ALLOC_FROB_BLOCK_LISP_OBJECT (bignum, Lisp_Bignum, b, &lrecord_bignum); |
| 1983 | 1574 bignum_init (bignum_data (b)); |
| 1575 bignum_set_long (bignum_data (b), bignum_value); | |
| 1576 return wrap_bignum (b); | |
| 1577 } | |
| 1578 | |
| 1579 /* WARNING: This function returns a bignum even if its argument fits into a | |
| 1580 fixnum. See Fcanonicalize_number(). */ | |
| 1581 Lisp_Object | |
| 1582 make_bignum_bg (bignum bg) | |
| 1583 { | |
| 1584 Lisp_Bignum *b; | |
| 1585 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1586 ALLOC_FROB_BLOCK_LISP_OBJECT (bignum, Lisp_Bignum, b, &lrecord_bignum); |
| 1983 | 1587 bignum_init (bignum_data (b)); |
| 1588 bignum_set (bignum_data (b), bg); | |
| 1589 return wrap_bignum (b); | |
| 1590 } | |
| 1591 #endif /* HAVE_BIGNUM */ | |
| 1592 | |
| 1593 /*** Ratio ***/ | |
| 1594 #ifdef HAVE_RATIO | |
| 1595 DECLARE_FIXED_TYPE_ALLOC (ratio, Lisp_Ratio); | |
| 1596 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_ratio 250 | |
| 1597 | |
| 1598 Lisp_Object | |
| 1599 make_ratio (long numerator, unsigned long denominator) | |
| 1600 { | |
| 1601 Lisp_Ratio *r; | |
| 1602 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1603 ALLOC_FROB_BLOCK_LISP_OBJECT (ratio, Lisp_Ratio, r, &lrecord_ratio); |
| 1983 | 1604 ratio_init (ratio_data (r)); |
| 1605 ratio_set_long_ulong (ratio_data (r), numerator, denominator); | |
| 1606 ratio_canonicalize (ratio_data (r)); | |
| 1607 return wrap_ratio (r); | |
| 1608 } | |
| 1609 | |
| 1610 Lisp_Object | |
| 1611 make_ratio_bg (bignum numerator, bignum denominator) | |
| 1612 { | |
| 1613 Lisp_Ratio *r; | |
| 1614 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1615 ALLOC_FROB_BLOCK_LISP_OBJECT (ratio, Lisp_Ratio, r, &lrecord_ratio); |
| 1983 | 1616 ratio_init (ratio_data (r)); |
| 1617 ratio_set_bignum_bignum (ratio_data (r), numerator, denominator); | |
| 1618 ratio_canonicalize (ratio_data (r)); | |
| 1619 return wrap_ratio (r); | |
| 1620 } | |
| 1621 | |
| 1622 Lisp_Object | |
| 1623 make_ratio_rt (ratio rat) | |
| 1624 { | |
| 1625 Lisp_Ratio *r; | |
| 1626 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1627 ALLOC_FROB_BLOCK_LISP_OBJECT (ratio, Lisp_Ratio, r, &lrecord_ratio); |
| 1983 | 1628 ratio_init (ratio_data (r)); |
| 1629 ratio_set (ratio_data (r), rat); | |
| 1630 return wrap_ratio (r); | |
| 1631 } | |
| 1632 #endif /* HAVE_RATIO */ | |
| 1633 | |
| 1634 /*** Bigfloat ***/ | |
| 1635 #ifdef HAVE_BIGFLOAT | |
| 1636 DECLARE_FIXED_TYPE_ALLOC (bigfloat, Lisp_Bigfloat); | |
| 1637 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bigfloat 250 | |
| 1638 | |
| 1639 /* This function creates a bigfloat with the default precision if the | |
| 1640 PRECISION argument is zero. */ | |
| 1641 Lisp_Object | |
| 1642 make_bigfloat (double float_value, unsigned long precision) | |
| 1643 { | |
| 1644 Lisp_Bigfloat *f; | |
| 1645 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1646 ALLOC_FROB_BLOCK_LISP_OBJECT (bigfloat, Lisp_Bigfloat, f, &lrecord_bigfloat); |
| 1983 | 1647 if (precision == 0UL) |
| 1648 bigfloat_init (bigfloat_data (f)); | |
| 1649 else | |
| 1650 bigfloat_init_prec (bigfloat_data (f), precision); | |
| 1651 bigfloat_set_double (bigfloat_data (f), float_value); | |
| 1652 return wrap_bigfloat (f); | |
| 1653 } | |
| 1654 | |
| 1655 /* This function creates a bigfloat with the precision of its argument */ | |
| 1656 Lisp_Object | |
| 1657 make_bigfloat_bf (bigfloat float_value) | |
| 1658 { | |
| 1659 Lisp_Bigfloat *f; | |
| 1660 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1661 ALLOC_FROB_BLOCK_LISP_OBJECT (bigfloat, Lisp_Bigfloat, f, &lrecord_bigfloat); |
| 1983 | 1662 bigfloat_init_prec (bigfloat_data (f), bigfloat_get_prec (float_value)); |
| 1663 bigfloat_set (bigfloat_data (f), float_value); | |
| 1664 return wrap_bigfloat (f); | |
| 1665 } | |
| 1666 #endif /* HAVE_BIGFLOAT */ | |
| 1667 | |
| 1668 /************************************************************************/ | |
| 428 | 1669 /* Vector allocation */ |
| 1670 /************************************************************************/ | |
| 1671 | |
| 1672 static Lisp_Object | |
| 1673 mark_vector (Lisp_Object obj) | |
| 1674 { | |
| 1675 Lisp_Vector *ptr = XVECTOR (obj); | |
| 1676 int len = vector_length (ptr); | |
| 1677 int i; | |
| 1678 | |
| 1679 for (i = 0; i < len - 1; i++) | |
| 1680 mark_object (ptr->contents[i]); | |
| 1681 return (len > 0) ? ptr->contents[len - 1] : Qnil; | |
| 1682 } | |
| 1683 | |
| 665 | 1684 static Bytecount |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1685 size_vector (Lisp_Object obj) |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1686 { |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1687 |
| 456 | 1688 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
|
1689 XVECTOR (obj)->size); |
| 428 | 1690 } |
| 1691 | |
| 1692 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
|
1693 vector_equal (Lisp_Object obj1, Lisp_Object obj2, int depth, int foldcase) |
| 428 | 1694 { |
| 1695 int len = XVECTOR_LENGTH (obj1); | |
| 1696 if (len != XVECTOR_LENGTH (obj2)) | |
| 1697 return 0; | |
| 1698 | |
| 1699 { | |
| 1700 Lisp_Object *ptr1 = XVECTOR_DATA (obj1); | |
| 1701 Lisp_Object *ptr2 = XVECTOR_DATA (obj2); | |
| 1702 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
|
1703 if (!internal_equal_0 (*ptr1++, *ptr2++, depth + 1, foldcase)) |
| 428 | 1704 return 0; |
| 1705 } | |
| 1706 return 1; | |
| 1707 } | |
| 1708 | |
| 665 | 1709 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
|
1710 vector_hash (Lisp_Object obj, int depth, Boolint equalp) |
| 442 | 1711 { |
| 1712 return HASH2 (XVECTOR_LENGTH (obj), | |
| 1713 internal_array_hash (XVECTOR_DATA (obj), | |
| 1714 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
|
1715 depth + 1, equalp)); |
| 442 | 1716 } |
| 1717 | |
| 1204 | 1718 static const struct memory_description vector_description[] = { |
| 440 | 1719 { XD_LONG, offsetof (Lisp_Vector, size) }, |
| 1720 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Vector, contents), XD_INDIRECT(0, 0) }, | |
| 428 | 1721 { XD_END } |
| 1722 }; | |
| 1723 | |
|
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1724 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
|
1725 mark_vector, print_vector, 0, |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1726 vector_equal, |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1727 vector_hash, |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1728 vector_description, |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1729 size_vector, Lisp_Vector); |
| 428 | 1730 /* #### should allocate `small' vectors from a frob-block */ |
| 1731 static Lisp_Vector * | |
| 665 | 1732 make_vector_internal (Elemcount sizei) |
| 428 | 1733 { |
| 1204 | 1734 /* no `next' field; we use lcrecords */ |
| 665 | 1735 Bytecount sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object, |
| 1204 | 1736 contents, sizei); |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1737 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
|
1738 Lisp_Vector *p = XVECTOR (obj); |
| 428 | 1739 |
| 1740 p->size = sizei; | |
| 1741 return p; | |
| 1742 } | |
| 1743 | |
| 1744 Lisp_Object | |
| 665 | 1745 make_vector (Elemcount length, Lisp_Object object) |
| 428 | 1746 { |
| 1747 Lisp_Vector *vecp = make_vector_internal (length); | |
| 1748 Lisp_Object *p = vector_data (vecp); | |
| 1749 | |
| 1750 while (length--) | |
| 444 | 1751 *p++ = object; |
| 428 | 1752 |
| 793 | 1753 return wrap_vector (vecp); |
| 428 | 1754 } |
| 1755 | |
| 1756 DEFUN ("make-vector", Fmake_vector, 2, 2, 0, /* | |
| 444 | 1757 Return a new vector of length LENGTH, with each element being OBJECT. |
| 428 | 1758 See also the function `vector'. |
| 1759 */ | |
| 444 | 1760 (length, object)) |
| 428 | 1761 { |
|
5307
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1762 check_integer_range (length, Qzero, make_int (ARRAY_DIMENSION_LIMIT)); |
| 444 | 1763 return make_vector (XINT (length), object); |
| 428 | 1764 } |
| 1765 | |
| 1766 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
|
1767 Return a newly created vector with specified ARGS as elements. |
| 428 | 1768 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
|
1769 |
|
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1770 arguments: (&rest ARGS) |
| 428 | 1771 */ |
| 1772 (int nargs, Lisp_Object *args)) | |
| 1773 { | |
| 1774 Lisp_Vector *vecp = make_vector_internal (nargs); | |
| 1775 Lisp_Object *p = vector_data (vecp); | |
| 1776 | |
| 1777 while (nargs--) | |
| 1778 *p++ = *args++; | |
| 1779 | |
| 793 | 1780 return wrap_vector (vecp); |
| 428 | 1781 } |
| 1782 | |
| 1783 Lisp_Object | |
| 1784 vector1 (Lisp_Object obj0) | |
| 1785 { | |
| 1786 return Fvector (1, &obj0); | |
| 1787 } | |
| 1788 | |
| 1789 Lisp_Object | |
| 1790 vector2 (Lisp_Object obj0, Lisp_Object obj1) | |
| 1791 { | |
| 1792 Lisp_Object args[2]; | |
| 1793 args[0] = obj0; | |
| 1794 args[1] = obj1; | |
| 1795 return Fvector (2, args); | |
| 1796 } | |
| 1797 | |
| 1798 Lisp_Object | |
| 1799 vector3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2) | |
| 1800 { | |
| 1801 Lisp_Object args[3]; | |
| 1802 args[0] = obj0; | |
| 1803 args[1] = obj1; | |
| 1804 args[2] = obj2; | |
| 1805 return Fvector (3, args); | |
| 1806 } | |
| 1807 | |
| 1808 #if 0 /* currently unused */ | |
| 1809 | |
| 1810 Lisp_Object | |
| 1811 vector4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
| 1812 Lisp_Object obj3) | |
| 1813 { | |
| 1814 Lisp_Object args[4]; | |
| 1815 args[0] = obj0; | |
| 1816 args[1] = obj1; | |
| 1817 args[2] = obj2; | |
| 1818 args[3] = obj3; | |
| 1819 return Fvector (4, args); | |
| 1820 } | |
| 1821 | |
| 1822 Lisp_Object | |
| 1823 vector5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
| 1824 Lisp_Object obj3, Lisp_Object obj4) | |
| 1825 { | |
| 1826 Lisp_Object args[5]; | |
| 1827 args[0] = obj0; | |
| 1828 args[1] = obj1; | |
| 1829 args[2] = obj2; | |
| 1830 args[3] = obj3; | |
| 1831 args[4] = obj4; | |
| 1832 return Fvector (5, args); | |
| 1833 } | |
| 1834 | |
| 1835 Lisp_Object | |
| 1836 vector6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
| 1837 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5) | |
| 1838 { | |
| 1839 Lisp_Object args[6]; | |
| 1840 args[0] = obj0; | |
| 1841 args[1] = obj1; | |
| 1842 args[2] = obj2; | |
| 1843 args[3] = obj3; | |
| 1844 args[4] = obj4; | |
| 1845 args[5] = obj5; | |
| 1846 return Fvector (6, args); | |
| 1847 } | |
| 1848 | |
| 1849 Lisp_Object | |
| 1850 vector7 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
| 1851 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5, | |
| 1852 Lisp_Object obj6) | |
| 1853 { | |
| 1854 Lisp_Object args[7]; | |
| 1855 args[0] = obj0; | |
| 1856 args[1] = obj1; | |
| 1857 args[2] = obj2; | |
| 1858 args[3] = obj3; | |
| 1859 args[4] = obj4; | |
| 1860 args[5] = obj5; | |
| 1861 args[6] = obj6; | |
| 1862 return Fvector (7, args); | |
| 1863 } | |
| 1864 | |
| 1865 Lisp_Object | |
| 1866 vector8 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
| 1867 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5, | |
| 1868 Lisp_Object obj6, Lisp_Object obj7) | |
| 1869 { | |
| 1870 Lisp_Object args[8]; | |
| 1871 args[0] = obj0; | |
| 1872 args[1] = obj1; | |
| 1873 args[2] = obj2; | |
| 1874 args[3] = obj3; | |
| 1875 args[4] = obj4; | |
| 1876 args[5] = obj5; | |
| 1877 args[6] = obj6; | |
| 1878 args[7] = obj7; | |
| 1879 return Fvector (8, args); | |
| 1880 } | |
| 1881 #endif /* unused */ | |
| 1882 | |
| 1883 /************************************************************************/ | |
| 1884 /* Bit Vector allocation */ | |
| 1885 /************************************************************************/ | |
| 1886 | |
| 1887 /* #### should allocate `small' bit vectors from a frob-block */ | |
| 440 | 1888 static Lisp_Bit_Vector * |
| 665 | 1889 make_bit_vector_internal (Elemcount sizei) |
| 428 | 1890 { |
| 1204 | 1891 /* no `next' field; we use lcrecords */ |
| 665 | 1892 Elemcount num_longs = BIT_VECTOR_LONG_STORAGE (sizei); |
| 1893 Bytecount sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Bit_Vector, | |
| 1204 | 1894 unsigned long, |
| 1895 bits, num_longs); | |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1896 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
|
1897 Lisp_Bit_Vector *p = XBIT_VECTOR (obj); |
| 428 | 1898 |
| 1899 bit_vector_length (p) = sizei; | |
| 1900 return p; | |
| 1901 } | |
| 1902 | |
| 1903 Lisp_Object | |
| 665 | 1904 make_bit_vector (Elemcount length, Lisp_Object bit) |
| 428 | 1905 { |
| 440 | 1906 Lisp_Bit_Vector *p = make_bit_vector_internal (length); |
| 665 | 1907 Elemcount num_longs = BIT_VECTOR_LONG_STORAGE (length); |
| 428 | 1908 |
| 444 | 1909 CHECK_BIT (bit); |
| 1910 | |
| 1911 if (ZEROP (bit)) | |
| 428 | 1912 memset (p->bits, 0, num_longs * sizeof (long)); |
| 1913 else | |
| 1914 { | |
| 665 | 1915 Elemcount bits_in_last = length & (LONGBITS_POWER_OF_2 - 1); |
| 428 | 1916 memset (p->bits, ~0, num_longs * sizeof (long)); |
| 1917 /* But we have to make sure that the unused bits in the | |
| 1918 last long are 0, so that equal/hash is easy. */ | |
| 1919 if (bits_in_last) | |
| 1920 p->bits[num_longs - 1] &= (1 << bits_in_last) - 1; | |
| 1921 } | |
| 1922 | |
| 793 | 1923 return wrap_bit_vector (p); |
| 428 | 1924 } |
| 1925 | |
| 1926 Lisp_Object | |
| 665 | 1927 make_bit_vector_from_byte_vector (unsigned char *bytevec, Elemcount length) |
| 428 | 1928 { |
| 665 | 1929 Elemcount i; |
| 428 | 1930 Lisp_Bit_Vector *p = make_bit_vector_internal (length); |
| 1931 | |
| 1932 for (i = 0; i < length; i++) | |
| 1933 set_bit_vector_bit (p, i, bytevec[i]); | |
| 1934 | |
| 793 | 1935 return wrap_bit_vector (p); |
| 428 | 1936 } |
| 1937 | |
| 1938 DEFUN ("make-bit-vector", Fmake_bit_vector, 2, 2, 0, /* | |
| 444 | 1939 Return a new bit vector of length LENGTH. with each bit set to BIT. |
| 1940 BIT must be one of the integers 0 or 1. See also the function `bit-vector'. | |
| 428 | 1941 */ |
| 444 | 1942 (length, bit)) |
| 428 | 1943 { |
|
5307
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
1944 check_integer_range (length, Qzero, make_int (ARRAY_DIMENSION_LIMIT)); |
| 444 | 1945 return make_bit_vector (XINT (length), bit); |
| 428 | 1946 } |
| 1947 | |
| 1948 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
|
1949 Return a newly created bit vector with specified ARGS as elements. |
| 428 | 1950 Any number of arguments, even zero arguments, are allowed. |
| 444 | 1951 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
|
1952 |
|
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1953 arguments: (&rest ARGS) |
| 428 | 1954 */ |
| 1955 (int nargs, Lisp_Object *args)) | |
| 1956 { | |
| 1957 int i; | |
| 1958 Lisp_Bit_Vector *p = make_bit_vector_internal (nargs); | |
| 1959 | |
| 1960 for (i = 0; i < nargs; i++) | |
| 1961 { | |
| 1962 CHECK_BIT (args[i]); | |
| 1963 set_bit_vector_bit (p, i, !ZEROP (args[i])); | |
| 1964 } | |
| 1965 | |
| 793 | 1966 return wrap_bit_vector (p); |
| 428 | 1967 } |
| 1968 | |
| 1969 | |
| 1970 /************************************************************************/ | |
| 1971 /* Compiled-function allocation */ | |
| 1972 /************************************************************************/ | |
| 1973 | |
| 1974 DECLARE_FIXED_TYPE_ALLOC (compiled_function, Lisp_Compiled_Function); | |
| 1975 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_compiled_function 1000 | |
| 1976 | |
| 1977 static Lisp_Object | |
| 1978 make_compiled_function (void) | |
| 1979 { | |
| 1980 Lisp_Compiled_Function *f; | |
| 1981 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
1982 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
|
1983 f, &lrecord_compiled_function); |
| 428 | 1984 |
| 1985 f->stack_depth = 0; | |
| 1986 f->specpdl_depth = 0; | |
| 1987 f->flags.documentationp = 0; | |
| 1988 f->flags.interactivep = 0; | |
| 1989 f->flags.domainp = 0; /* I18N3 */ | |
| 1990 f->instructions = Qzero; | |
| 1991 f->constants = Qzero; | |
| 1992 f->arglist = Qnil; | |
| 3092 | 1993 #ifdef NEW_GC |
| 1994 f->arguments = Qnil; | |
| 1995 #else /* not NEW_GC */ | |
| 1739 | 1996 f->args = NULL; |
| 3092 | 1997 #endif /* not NEW_GC */ |
| 1739 | 1998 f->max_args = f->min_args = f->args_in_array = 0; |
| 428 | 1999 f->doc_and_interactive = Qnil; |
| 2000 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
| 2001 f->annotated = Qnil; | |
| 2002 #endif | |
| 793 | 2003 return wrap_compiled_function (f); |
| 428 | 2004 } |
| 2005 | |
| 2006 DEFUN ("make-byte-code", Fmake_byte_code, 4, MANY, 0, /* | |
| 2007 Return a new compiled-function object. | |
| 2008 Note that, unlike all other emacs-lisp functions, calling this with five | |
| 2009 arguments is NOT the same as calling it with six arguments, the last of | |
| 2010 which is nil. If the INTERACTIVE arg is specified as nil, then that means | |
| 2011 that this function was defined with `(interactive)'. If the arg is not | |
| 2012 specified, then that means the function is not interactive. | |
| 2013 This is terrible behavior which is retained for compatibility with old | |
| 2014 `.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
|
2015 |
|
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
2016 arguments: (ARGLIST INSTRUCTIONS CONSTANTS STACK-DEPTH &optional DOC-STRING INTERACTIVE) |
| 428 | 2017 */ |
| 2018 (int nargs, Lisp_Object *args)) | |
| 2019 { | |
| 2020 /* In a non-insane world this function would have this arglist... | |
| 2021 (arglist instructions constants stack_depth &optional doc_string interactive) | |
| 2022 */ | |
| 2023 Lisp_Object fun = make_compiled_function (); | |
| 2024 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (fun); | |
| 2025 | |
| 2026 Lisp_Object arglist = args[0]; | |
| 2027 Lisp_Object instructions = args[1]; | |
| 2028 Lisp_Object constants = args[2]; | |
| 2029 Lisp_Object stack_depth = args[3]; | |
| 2030 Lisp_Object doc_string = (nargs > 4) ? args[4] : Qnil; | |
| 2031 Lisp_Object interactive = (nargs > 5) ? args[5] : Qunbound; | |
| 2032 | |
| 2033 if (nargs < 4 || nargs > 6) | |
| 2034 return Fsignal (Qwrong_number_of_arguments, | |
| 2035 list2 (intern ("make-byte-code"), make_int (nargs))); | |
| 2036 | |
| 2037 /* Check for valid formal parameter list now, to allow us to use | |
| 2038 SPECBIND_FAST_UNSAFE() later in funcall_compiled_function(). */ | |
| 2039 { | |
| 814 | 2040 EXTERNAL_LIST_LOOP_2 (symbol, arglist) |
| 428 | 2041 { |
| 2042 CHECK_SYMBOL (symbol); | |
| 2043 if (EQ (symbol, Qt) || | |
| 2044 EQ (symbol, Qnil) || | |
| 2045 SYMBOL_IS_KEYWORD (symbol)) | |
| 563 | 2046 invalid_constant_2 |
| 428 | 2047 ("Invalid constant symbol in formal parameter list", |
| 2048 symbol, arglist); | |
| 2049 } | |
| 2050 } | |
| 2051 f->arglist = arglist; | |
| 2052 | |
| 2053 /* `instructions' is a string or a cons (string . int) for a | |
| 2054 lazy-loaded function. */ | |
| 2055 if (CONSP (instructions)) | |
| 2056 { | |
| 2057 CHECK_STRING (XCAR (instructions)); | |
| 2058 CHECK_INT (XCDR (instructions)); | |
| 2059 } | |
| 2060 else | |
| 2061 { | |
| 2062 CHECK_STRING (instructions); | |
| 2063 } | |
| 2064 f->instructions = instructions; | |
| 2065 | |
| 2066 if (!NILP (constants)) | |
| 2067 CHECK_VECTOR (constants); | |
| 2068 f->constants = constants; | |
| 2069 | |
|
5307
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
2070 check_integer_range (stack_depth, Qzero, make_int (USHRT_MAX)); |
| 442 | 2071 f->stack_depth = (unsigned short) XINT (stack_depth); |
| 428 | 2072 |
| 2073 #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
|
2074 f->annotated = Vload_file_name_internal; |
| 428 | 2075 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */ |
| 2076 | |
| 2077 /* doc_string may be nil, string, int, or a cons (string . int). | |
| 2078 interactive may be list or string (or unbound). */ | |
| 2079 f->doc_and_interactive = Qunbound; | |
| 2080 #ifdef I18N3 | |
| 2081 if ((f->flags.domainp = !NILP (Vfile_domain)) != 0) | |
| 2082 f->doc_and_interactive = Vfile_domain; | |
| 2083 #endif | |
| 2084 if ((f->flags.interactivep = !UNBOUNDP (interactive)) != 0) | |
| 2085 { | |
| 2086 f->doc_and_interactive | |
| 2087 = (UNBOUNDP (f->doc_and_interactive) ? interactive : | |
| 2088 Fcons (interactive, f->doc_and_interactive)); | |
| 2089 } | |
| 2090 if ((f->flags.documentationp = !NILP (doc_string)) != 0) | |
| 2091 { | |
| 2092 f->doc_and_interactive | |
| 2093 = (UNBOUNDP (f->doc_and_interactive) ? doc_string : | |
| 2094 Fcons (doc_string, f->doc_and_interactive)); | |
| 2095 } | |
| 2096 if (UNBOUNDP (f->doc_and_interactive)) | |
| 2097 f->doc_and_interactive = Qnil; | |
| 2098 | |
| 2099 return fun; | |
| 2100 } | |
| 2101 | |
| 2102 | |
| 2103 /************************************************************************/ | |
| 2104 /* Symbol allocation */ | |
| 2105 /************************************************************************/ | |
| 2106 | |
| 440 | 2107 DECLARE_FIXED_TYPE_ALLOC (symbol, Lisp_Symbol); |
| 428 | 2108 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_symbol 1000 |
| 2109 | |
| 2110 DEFUN ("make-symbol", Fmake_symbol, 1, 1, 0, /* | |
| 2111 Return a newly allocated uninterned symbol whose name is NAME. | |
| 2112 Its value and function definition are void, and its property list is nil. | |
| 2113 */ | |
| 2114 (name)) | |
| 2115 { | |
| 440 | 2116 Lisp_Symbol *p; |
| 428 | 2117 |
| 2118 CHECK_STRING (name); | |
| 2119 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2120 ALLOC_FROB_BLOCK_LISP_OBJECT (symbol, Lisp_Symbol, p, &lrecord_symbol); |
| 793 | 2121 p->name = name; |
| 428 | 2122 p->plist = Qnil; |
| 2123 p->value = Qunbound; | |
| 2124 p->function = Qunbound; | |
| 2125 symbol_next (p) = 0; | |
| 793 | 2126 return wrap_symbol (p); |
| 428 | 2127 } |
| 2128 | |
| 2129 | |
| 2130 /************************************************************************/ | |
| 2131 /* Extent allocation */ | |
| 2132 /************************************************************************/ | |
| 2133 | |
| 2134 DECLARE_FIXED_TYPE_ALLOC (extent, struct extent); | |
| 2135 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_extent 1000 | |
| 2136 | |
| 2137 struct extent * | |
| 2138 allocate_extent (void) | |
| 2139 { | |
| 2140 struct extent *e; | |
| 2141 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2142 ALLOC_FROB_BLOCK_LISP_OBJECT (extent, struct extent, e, &lrecord_extent); |
| 428 | 2143 extent_object (e) = Qnil; |
| 2144 set_extent_start (e, -1); | |
| 2145 set_extent_end (e, -1); | |
| 2146 e->plist = Qnil; | |
| 2147 | |
| 2148 xzero (e->flags); | |
| 2149 | |
| 2150 extent_face (e) = Qnil; | |
| 2151 e->flags.end_open = 1; /* default is for endpoints to behave like markers */ | |
| 2152 e->flags.detachable = 1; | |
| 2153 | |
| 2154 return e; | |
| 2155 } | |
| 2156 | |
| 2157 | |
| 2158 /************************************************************************/ | |
| 2159 /* Event allocation */ | |
| 2160 /************************************************************************/ | |
| 2161 | |
| 440 | 2162 DECLARE_FIXED_TYPE_ALLOC (event, Lisp_Event); |
| 428 | 2163 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_event 1000 |
| 2164 | |
| 2165 Lisp_Object | |
| 2166 allocate_event (void) | |
| 2167 { | |
| 440 | 2168 Lisp_Event *e; |
| 2169 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2170 ALLOC_FROB_BLOCK_LISP_OBJECT (event, Lisp_Event, e, &lrecord_event); |
| 428 | 2171 |
| 793 | 2172 return wrap_event (e); |
| 428 | 2173 } |
| 2174 | |
| 1204 | 2175 #ifdef EVENT_DATA_AS_OBJECTS |
| 934 | 2176 DECLARE_FIXED_TYPE_ALLOC (key_data, Lisp_Key_Data); |
| 2177 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_key_data 1000 | |
| 2178 | |
| 2179 Lisp_Object | |
| 1204 | 2180 make_key_data (void) |
| 934 | 2181 { |
| 2182 Lisp_Key_Data *d; | |
| 2183 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2184 ALLOC_FROB_BLOCK_LISP_OBJECT (key_data, Lisp_Key_Data, d, |
| 3017 | 2185 &lrecord_key_data); |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2186 zero_nonsized_lisp_object (wrap_key_data (d)); |
| 1204 | 2187 d->keysym = Qnil; |
| 2188 | |
| 2189 return wrap_key_data (d); | |
| 934 | 2190 } |
| 2191 | |
| 2192 DECLARE_FIXED_TYPE_ALLOC (button_data, Lisp_Button_Data); | |
| 2193 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_button_data 1000 | |
| 2194 | |
| 2195 Lisp_Object | |
| 1204 | 2196 make_button_data (void) |
| 934 | 2197 { |
| 2198 Lisp_Button_Data *d; | |
| 2199 | |
|
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
|
2200 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
|
2201 &lrecord_button_data); |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2202 zero_nonsized_lisp_object (wrap_button_data (d)); |
| 1204 | 2203 return wrap_button_data (d); |
| 934 | 2204 } |
| 2205 | |
| 2206 DECLARE_FIXED_TYPE_ALLOC (motion_data, Lisp_Motion_Data); | |
| 2207 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_motion_data 1000 | |
| 2208 | |
| 2209 Lisp_Object | |
| 1204 | 2210 make_motion_data (void) |
| 934 | 2211 { |
| 2212 Lisp_Motion_Data *d; | |
| 2213 | |
|
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
|
2214 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
|
2215 &lrecord_motion_data); |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2216 zero_nonsized_lisp_object (wrap_motion_data (d)); |
| 934 | 2217 |
| 1204 | 2218 return wrap_motion_data (d); |
| 934 | 2219 } |
| 2220 | |
| 2221 DECLARE_FIXED_TYPE_ALLOC (process_data, Lisp_Process_Data); | |
| 2222 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_process_data 1000 | |
| 2223 | |
| 2224 Lisp_Object | |
| 1204 | 2225 make_process_data (void) |
| 934 | 2226 { |
| 2227 Lisp_Process_Data *d; | |
| 2228 | |
|
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
|
2229 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
|
2230 &lrecord_process_data); |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2231 zero_nonsized_lisp_object (wrap_process_data (d)); |
| 1204 | 2232 d->process = Qnil; |
| 2233 | |
| 2234 return wrap_process_data (d); | |
| 934 | 2235 } |
| 2236 | |
| 2237 DECLARE_FIXED_TYPE_ALLOC (timeout_data, Lisp_Timeout_Data); | |
| 2238 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_timeout_data 1000 | |
| 2239 | |
| 2240 Lisp_Object | |
| 1204 | 2241 make_timeout_data (void) |
| 934 | 2242 { |
| 2243 Lisp_Timeout_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 (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
|
2246 &lrecord_timeout_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_timeout_data (d)); |
| 1204 | 2248 d->function = Qnil; |
| 2249 d->object = Qnil; | |
| 2250 | |
| 2251 return wrap_timeout_data (d); | |
| 934 | 2252 } |
| 2253 | |
| 2254 DECLARE_FIXED_TYPE_ALLOC (magic_data, Lisp_Magic_Data); | |
| 2255 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_magic_data 1000 | |
| 2256 | |
| 2257 Lisp_Object | |
| 1204 | 2258 make_magic_data (void) |
| 934 | 2259 { |
| 2260 Lisp_Magic_Data *d; | |
| 2261 | |
|
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
|
2262 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
|
2263 &lrecord_magic_data); |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2264 zero_nonsized_lisp_object (wrap_magic_data (d)); |
| 934 | 2265 |
| 1204 | 2266 return wrap_magic_data (d); |
| 934 | 2267 } |
| 2268 | |
| 2269 DECLARE_FIXED_TYPE_ALLOC (magic_eval_data, Lisp_Magic_Eval_Data); | |
| 2270 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_magic_eval_data 1000 | |
| 2271 | |
| 2272 Lisp_Object | |
| 1204 | 2273 make_magic_eval_data (void) |
| 934 | 2274 { |
| 2275 Lisp_Magic_Eval_Data *d; | |
| 2276 | |
|
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
|
2277 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
|
2278 &lrecord_magic_eval_data); |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2279 zero_nonsized_lisp_object (wrap_magic_eval_data (d)); |
| 1204 | 2280 d->object = Qnil; |
| 2281 | |
| 2282 return wrap_magic_eval_data (d); | |
| 934 | 2283 } |
| 2284 | |
| 2285 DECLARE_FIXED_TYPE_ALLOC (eval_data, Lisp_Eval_Data); | |
| 2286 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_eval_data 1000 | |
| 2287 | |
| 2288 Lisp_Object | |
| 1204 | 2289 make_eval_data (void) |
| 934 | 2290 { |
| 2291 Lisp_Eval_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 (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
|
2294 &lrecord_eval_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_eval_data (d)); |
| 1204 | 2296 d->function = Qnil; |
| 2297 d->object = Qnil; | |
| 2298 | |
| 2299 return wrap_eval_data (d); | |
| 934 | 2300 } |
| 2301 | |
| 2302 DECLARE_FIXED_TYPE_ALLOC (misc_user_data, Lisp_Misc_User_Data); | |
| 2303 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_misc_user_data 1000 | |
| 2304 | |
| 2305 Lisp_Object | |
| 1204 | 2306 make_misc_user_data (void) |
| 934 | 2307 { |
| 2308 Lisp_Misc_User_Data *d; | |
| 2309 | |
|
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
|
2310 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
|
2311 &lrecord_misc_user_data); |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2312 zero_nonsized_lisp_object (wrap_misc_user_data (d)); |
| 1204 | 2313 d->function = Qnil; |
| 2314 d->object = Qnil; | |
| 2315 | |
| 2316 return wrap_misc_user_data (d); | |
| 934 | 2317 } |
| 1204 | 2318 |
| 2319 #endif /* EVENT_DATA_AS_OBJECTS */ | |
| 428 | 2320 |
| 2321 /************************************************************************/ | |
| 2322 /* Marker allocation */ | |
| 2323 /************************************************************************/ | |
| 2324 | |
| 440 | 2325 DECLARE_FIXED_TYPE_ALLOC (marker, Lisp_Marker); |
| 428 | 2326 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_marker 1000 |
| 2327 | |
| 2328 DEFUN ("make-marker", Fmake_marker, 0, 0, 0, /* | |
| 2329 Return a new marker which does not point at any place. | |
| 2330 */ | |
| 2331 ()) | |
| 2332 { | |
| 440 | 2333 Lisp_Marker *p; |
| 2334 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2335 ALLOC_FROB_BLOCK_LISP_OBJECT (marker, Lisp_Marker, p, &lrecord_marker); |
| 428 | 2336 p->buffer = 0; |
| 665 | 2337 p->membpos = 0; |
| 428 | 2338 marker_next (p) = 0; |
| 2339 marker_prev (p) = 0; | |
| 2340 p->insertion_type = 0; | |
| 793 | 2341 return wrap_marker (p); |
| 428 | 2342 } |
| 2343 | |
| 2344 Lisp_Object | |
| 2345 noseeum_make_marker (void) | |
| 2346 { | |
| 440 | 2347 Lisp_Marker *p; |
| 2348 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2349 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
|
2350 &lrecord_marker); |
| 428 | 2351 p->buffer = 0; |
| 665 | 2352 p->membpos = 0; |
| 428 | 2353 marker_next (p) = 0; |
| 2354 marker_prev (p) = 0; | |
| 2355 p->insertion_type = 0; | |
| 793 | 2356 return wrap_marker (p); |
| 428 | 2357 } |
| 2358 | |
| 2359 | |
| 2360 /************************************************************************/ | |
| 2361 /* String allocation */ | |
| 2362 /************************************************************************/ | |
| 2363 | |
| 2364 /* The data for "short" strings generally resides inside of structs of type | |
| 2365 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
|
2366 other frob-block lrecord, and these are freelisted when they get garbage |
| 1204 | 2367 collected. The data for short strings get compacted, but the data for |
| 2368 large strings do not. | |
| 428 | 2369 |
| 2370 Previously Lisp_String structures were relocated, but this caused a lot | |
| 2371 of bus-errors because the C code didn't include enough GCPRO's for | |
| 2372 strings (since EVERY REFERENCE to a short string needed to be GCPRO'd so | |
| 2373 that the reference would get relocated). | |
| 2374 | |
| 2375 This new method makes things somewhat bigger, but it is MUCH safer. */ | |
| 2376 | |
| 438 | 2377 DECLARE_FIXED_TYPE_ALLOC (string, Lisp_String); |
| 428 | 2378 /* strings are used and freed quite often */ |
| 2379 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 10000 */ | |
| 2380 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 1000 | |
| 2381 | |
| 2382 static Lisp_Object | |
| 2383 mark_string (Lisp_Object obj) | |
| 2384 { | |
| 793 | 2385 if (CONSP (XSTRING_PLIST (obj)) && EXTENT_INFOP (XCAR (XSTRING_PLIST (obj)))) |
| 2386 flush_cached_extent_info (XCAR (XSTRING_PLIST (obj))); | |
| 2387 return XSTRING_PLIST (obj); | |
| 428 | 2388 } |
| 2389 | |
| 2390 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
|
2391 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
|
2392 int foldcase) |
| 428 | 2393 { |
| 2394 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
|
2395 if (foldcase) |
|
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2396 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
|
2397 else |
|
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2398 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
|
2399 !memcmp (XSTRING_DATA (obj1), XSTRING_DATA (obj2), len)); |
| 428 | 2400 } |
| 2401 | |
| 1204 | 2402 static const struct memory_description string_description[] = { |
| 3092 | 2403 #ifdef NEW_GC |
| 2404 { XD_LISP_OBJECT, offsetof (Lisp_String, data_object) }, | |
| 2405 #else /* not NEW_GC */ | |
| 793 | 2406 { XD_BYTECOUNT, offsetof (Lisp_String, size_) }, |
| 2407 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String, data_), XD_INDIRECT(0, 1) }, | |
| 3092 | 2408 #endif /* not NEW_GC */ |
| 440 | 2409 { XD_LISP_OBJECT, offsetof (Lisp_String, plist) }, |
| 428 | 2410 { XD_END } |
| 2411 }; | |
| 2412 | |
| 442 | 2413 /* We store the string's extent info as the first element of the string's |
| 2414 property list; and the string's MODIFF as the first or second element | |
| 2415 of the string's property list (depending on whether the extent info | |
| 2416 is present), but only if the string has been modified. This is ugly | |
| 2417 but it reduces the memory allocated for the string in the vast | |
| 2418 majority of cases, where the string is never modified and has no | |
| 2419 extent info. | |
| 2420 | |
| 2421 #### This means you can't use an int as a key in a string's plist. */ | |
| 2422 | |
| 2423 static Lisp_Object * | |
| 2424 string_plist_ptr (Lisp_Object string) | |
| 2425 { | |
| 793 | 2426 Lisp_Object *ptr = &XSTRING_PLIST (string); |
| 442 | 2427 |
| 2428 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr))) | |
| 2429 ptr = &XCDR (*ptr); | |
| 2430 if (CONSP (*ptr) && INTP (XCAR (*ptr))) | |
| 2431 ptr = &XCDR (*ptr); | |
| 2432 return ptr; | |
| 2433 } | |
| 2434 | |
| 2435 static Lisp_Object | |
| 2436 string_getprop (Lisp_Object string, Lisp_Object property) | |
| 2437 { | |
| 2438 return external_plist_get (string_plist_ptr (string), property, 0, ERROR_ME); | |
| 2439 } | |
| 2440 | |
| 2441 static int | |
| 2442 string_putprop (Lisp_Object string, Lisp_Object property, Lisp_Object value) | |
| 2443 { | |
| 2444 external_plist_put (string_plist_ptr (string), property, value, 0, ERROR_ME); | |
| 2445 return 1; | |
| 2446 } | |
| 2447 | |
| 2448 static int | |
| 2449 string_remprop (Lisp_Object string, Lisp_Object property) | |
| 2450 { | |
| 2451 return external_remprop (string_plist_ptr (string), property, 0, ERROR_ME); | |
| 2452 } | |
| 2453 | |
| 2454 static Lisp_Object | |
| 2455 string_plist (Lisp_Object string) | |
| 2456 { | |
| 2457 return *string_plist_ptr (string); | |
| 2458 } | |
| 2459 | |
| 3263 | 2460 #ifndef NEW_GC |
| 442 | 2461 /* No `finalize', or `hash' methods. |
| 2462 internal_hash() already knows how to hash strings and finalization | |
| 2463 is done with the ADDITIONAL_FREE_string macro, which is the | |
| 2464 standard way to do finalization when using | |
| 2465 SWEEP_FIXED_TYPE_BLOCK(). */ | |
| 2720 | 2466 |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2467 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
|
2468 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
|
2469 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
|
2470 string_description, |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2471 Lisp_String); |
| 3263 | 2472 #endif /* not NEW_GC */ |
| 2720 | 2473 |
| 3092 | 2474 #ifdef NEW_GC |
| 2475 #define STRING_FULLSIZE(size) \ | |
| 2476 ALIGN_SIZE (FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_String_Direct_Data, Lisp_Object, data, (size) + 1), sizeof (Lisp_Object *)); | |
| 2477 #else /* not NEW_GC */ | |
| 428 | 2478 /* String blocks contain this many useful bytes. */ |
| 2479 #define STRING_CHARS_BLOCK_SIZE \ | |
| 814 | 2480 ((Bytecount) (8192 - MALLOC_OVERHEAD - \ |
| 2481 ((2 * sizeof (struct string_chars_block *)) \ | |
| 2482 + sizeof (EMACS_INT)))) | |
| 428 | 2483 /* Block header for small strings. */ |
| 2484 struct string_chars_block | |
| 2485 { | |
| 2486 EMACS_INT pos; | |
| 2487 struct string_chars_block *next; | |
| 2488 struct string_chars_block *prev; | |
| 2489 /* Contents of string_chars_block->string_chars are interleaved | |
| 2490 string_chars structures (see below) and the actual string data */ | |
| 2491 unsigned char string_chars[STRING_CHARS_BLOCK_SIZE]; | |
| 2492 }; | |
| 2493 | |
| 2494 static struct string_chars_block *first_string_chars_block; | |
| 2495 static struct string_chars_block *current_string_chars_block; | |
| 2496 | |
| 2497 /* If SIZE is the length of a string, this returns how many bytes | |
| 2498 * the string occupies in string_chars_block->string_chars | |
| 2499 * (including alignment padding). | |
| 2500 */ | |
| 438 | 2501 #define STRING_FULLSIZE(size) \ |
| 826 | 2502 ALIGN_FOR_TYPE (((size) + 1 + sizeof (Lisp_String *)), Lisp_String *) |
| 428 | 2503 |
| 2504 #define BIG_STRING_FULLSIZE_P(fullsize) ((fullsize) >= STRING_CHARS_BLOCK_SIZE) | |
| 2505 #define BIG_STRING_SIZE_P(size) (BIG_STRING_FULLSIZE_P (STRING_FULLSIZE(size))) | |
| 2506 | |
| 454 | 2507 #define STRING_CHARS_FREE_P(ptr) ((ptr)->string == NULL) |
| 2508 #define MARK_STRING_CHARS_AS_FREE(ptr) ((void) ((ptr)->string = NULL)) | |
| 3092 | 2509 #endif /* not NEW_GC */ |
| 454 | 2510 |
| 3263 | 2511 #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
|
2512 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
|
2513 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
|
2514 string_description, Lisp_String); |
| 3092 | 2515 |
| 2516 | |
| 2517 static const struct memory_description string_direct_data_description[] = { | |
| 3514 | 2518 { XD_BYTECOUNT, offsetof (Lisp_String_Direct_Data, size) }, |
| 3092 | 2519 { XD_END } |
| 2520 }; | |
| 2521 | |
| 2522 static Bytecount | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2523 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
|
2524 { |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2525 return STRING_FULLSIZE (XSTRING_DIRECT_DATA (obj)->size); |
| 3092 | 2526 } |
| 2527 | |
| 2528 | |
|
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2529 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
|
2530 string_direct_data, |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2531 0, |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2532 string_direct_data_description, |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2533 size_string_direct_data, |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2534 Lisp_String_Direct_Data); |
| 3092 | 2535 |
| 2536 | |
| 2537 static const struct memory_description string_indirect_data_description[] = { | |
| 2538 { XD_BYTECOUNT, offsetof (Lisp_String_Indirect_Data, size) }, | |
| 2539 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String_Indirect_Data, data), | |
| 2540 XD_INDIRECT(0, 1) }, | |
| 2541 { XD_END } | |
| 2542 }; | |
| 2543 | |
|
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2544 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
|
2545 string_indirect_data, |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2546 0, |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2547 string_indirect_data_description, |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2548 Lisp_String_Indirect_Data); |
| 3092 | 2549 #endif /* NEW_GC */ |
| 2720 | 2550 |
| 3092 | 2551 #ifndef NEW_GC |
| 428 | 2552 struct string_chars |
| 2553 { | |
| 438 | 2554 Lisp_String *string; |
| 428 | 2555 unsigned char chars[1]; |
| 2556 }; | |
| 2557 | |
| 2558 struct unused_string_chars | |
| 2559 { | |
| 438 | 2560 Lisp_String *string; |
| 428 | 2561 EMACS_INT fullsize; |
| 2562 }; | |
| 2563 | |
| 2564 static void | |
| 2565 init_string_chars_alloc (void) | |
| 2566 { | |
| 2567 first_string_chars_block = xnew (struct string_chars_block); | |
| 2568 first_string_chars_block->prev = 0; | |
| 2569 first_string_chars_block->next = 0; | |
| 2570 first_string_chars_block->pos = 0; | |
| 2571 current_string_chars_block = first_string_chars_block; | |
| 2572 } | |
| 2573 | |
| 1550 | 2574 static Ibyte * |
| 2575 allocate_big_string_chars (Bytecount length) | |
| 2576 { | |
| 2577 Ibyte *p = xnew_array (Ibyte, length); | |
| 2578 INCREMENT_CONS_COUNTER (length, "string chars"); | |
| 2579 return p; | |
| 2580 } | |
| 2581 | |
| 428 | 2582 static struct string_chars * |
| 793 | 2583 allocate_string_chars_struct (Lisp_Object string_it_goes_with, |
| 814 | 2584 Bytecount fullsize) |
| 428 | 2585 { |
| 2586 struct string_chars *s_chars; | |
| 2587 | |
| 438 | 2588 if (fullsize <= |
| 2589 (countof (current_string_chars_block->string_chars) | |
| 2590 - current_string_chars_block->pos)) | |
| 428 | 2591 { |
| 2592 /* This string can fit in the current string chars block */ | |
| 2593 s_chars = (struct string_chars *) | |
| 2594 (current_string_chars_block->string_chars | |
| 2595 + current_string_chars_block->pos); | |
| 2596 current_string_chars_block->pos += fullsize; | |
| 2597 } | |
| 2598 else | |
| 2599 { | |
| 2600 /* Make a new current string chars block */ | |
| 2601 struct string_chars_block *new_scb = xnew (struct string_chars_block); | |
| 2602 | |
| 2603 current_string_chars_block->next = new_scb; | |
| 2604 new_scb->prev = current_string_chars_block; | |
| 2605 new_scb->next = 0; | |
| 2606 current_string_chars_block = new_scb; | |
| 2607 new_scb->pos = fullsize; | |
| 2608 s_chars = (struct string_chars *) | |
| 2609 current_string_chars_block->string_chars; | |
| 2610 } | |
| 2611 | |
| 793 | 2612 s_chars->string = XSTRING (string_it_goes_with); |
| 428 | 2613 |
| 2614 INCREMENT_CONS_COUNTER (fullsize, "string chars"); | |
| 2615 | |
| 2616 return s_chars; | |
| 2617 } | |
| 3092 | 2618 #endif /* not NEW_GC */ |
| 428 | 2619 |
| 771 | 2620 #ifdef SLEDGEHAMMER_CHECK_ASCII_BEGIN |
| 2621 void | |
| 2622 sledgehammer_check_ascii_begin (Lisp_Object str) | |
| 2623 { | |
| 2624 Bytecount i; | |
| 2625 | |
| 2626 for (i = 0; i < XSTRING_LENGTH (str); i++) | |
| 2627 { | |
| 826 | 2628 if (!byte_ascii_p (string_byte (str, i))) |
| 771 | 2629 break; |
| 2630 } | |
| 2631 | |
| 2632 assert (i == (Bytecount) XSTRING_ASCII_BEGIN (str) || | |
| 2633 (i > MAX_STRING_ASCII_BEGIN && | |
| 2634 (Bytecount) XSTRING_ASCII_BEGIN (str) == | |
| 2635 (Bytecount) MAX_STRING_ASCII_BEGIN)); | |
| 2636 } | |
| 2637 #endif | |
| 2638 | |
| 2639 /* You do NOT want to be calling this! (And if you do, you must call | |
| 851 | 2640 XSET_STRING_ASCII_BEGIN() after modifying the string.) Use ALLOCA () |
| 771 | 2641 instead and then call make_string() like the rest of the world. */ |
| 2642 | |
| 428 | 2643 Lisp_Object |
| 2644 make_uninit_string (Bytecount length) | |
| 2645 { | |
| 438 | 2646 Lisp_String *s; |
| 814 | 2647 Bytecount fullsize = STRING_FULLSIZE (length); |
| 428 | 2648 |
| 438 | 2649 assert (length >= 0 && fullsize > 0); |
| 428 | 2650 |
| 3263 | 2651 #ifdef NEW_GC |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2652 s = XSTRING (ALLOC_NORMAL_LISP_OBJECT (string)); |
| 3263 | 2653 #else /* not NEW_GC */ |
| 428 | 2654 /* Allocate the string header */ |
| 438 | 2655 ALLOCATE_FIXED_TYPE (string, Lisp_String, s); |
| 793 | 2656 xzero (*s); |
| 771 | 2657 set_lheader_implementation (&s->u.lheader, &lrecord_string); |
| 3263 | 2658 #endif /* not NEW_GC */ |
| 2720 | 2659 |
| 3063 | 2660 /* The above allocations set the UID field, which overlaps with the |
| 2661 ascii-length field, to some non-zero value. We need to zero it. */ | |
| 2662 XSET_STRING_ASCII_BEGIN (wrap_string (s), 0); | |
| 2663 | |
| 3092 | 2664 #ifdef NEW_GC |
| 3304 | 2665 set_lispstringp_direct (s); |
| 3092 | 2666 STRING_DATA_OBJECT (s) = |
|
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2667 alloc_sized_lrecord (fullsize, &lrecord_string_direct_data); |
| 3092 | 2668 #else /* not NEW_GC */ |
| 826 | 2669 set_lispstringp_data (s, BIG_STRING_FULLSIZE_P (fullsize) |
| 2720 | 2670 ? allocate_big_string_chars (length + 1) |
| 2671 : allocate_string_chars_struct (wrap_string (s), | |
| 2672 fullsize)->chars); | |
| 3092 | 2673 #endif /* not NEW_GC */ |
| 438 | 2674 |
| 826 | 2675 set_lispstringp_length (s, length); |
| 428 | 2676 s->plist = Qnil; |
| 793 | 2677 set_string_byte (wrap_string (s), length, 0); |
| 2678 | |
| 2679 return wrap_string (s); | |
| 428 | 2680 } |
| 2681 | |
| 2682 #ifdef VERIFY_STRING_CHARS_INTEGRITY | |
| 2683 static void verify_string_chars_integrity (void); | |
| 2684 #endif | |
| 2685 | |
| 2686 /* Resize the string S so that DELTA bytes can be inserted starting | |
| 2687 at POS. If DELTA < 0, it means deletion starting at POS. If | |
| 2688 POS < 0, resize the string but don't copy any characters. Use | |
| 2689 this if you're planning on completely overwriting the string. | |
| 2690 */ | |
| 2691 | |
| 2692 void | |
| 793 | 2693 resize_string (Lisp_Object s, Bytecount pos, Bytecount delta) |
| 428 | 2694 { |
| 3092 | 2695 #ifdef NEW_GC |
| 2696 Bytecount newfullsize, len; | |
| 2697 #else /* not NEW_GC */ | |
| 438 | 2698 Bytecount oldfullsize, newfullsize; |
| 3092 | 2699 #endif /* not NEW_GC */ |
| 428 | 2700 #ifdef VERIFY_STRING_CHARS_INTEGRITY |
| 2701 verify_string_chars_integrity (); | |
| 2702 #endif | |
| 800 | 2703 #ifdef ERROR_CHECK_TEXT |
| 428 | 2704 if (pos >= 0) |
| 2705 { | |
| 793 | 2706 assert (pos <= XSTRING_LENGTH (s)); |
| 428 | 2707 if (delta < 0) |
| 793 | 2708 assert (pos + (-delta) <= XSTRING_LENGTH (s)); |
| 428 | 2709 } |
| 2710 else | |
| 2711 { | |
| 2712 if (delta < 0) | |
| 793 | 2713 assert ((-delta) <= XSTRING_LENGTH (s)); |
| 428 | 2714 } |
| 800 | 2715 #endif /* ERROR_CHECK_TEXT */ |
| 428 | 2716 |
| 2717 if (delta == 0) | |
| 2718 /* simplest case: no size change. */ | |
| 2719 return; | |
| 438 | 2720 |
| 2721 if (pos >= 0 && delta < 0) | |
| 2722 /* If DELTA < 0, the functions below will delete the characters | |
| 2723 before POS. We want to delete characters *after* POS, however, | |
| 2724 so convert this to the appropriate form. */ | |
| 2725 pos += -delta; | |
| 2726 | |
| 3092 | 2727 #ifdef NEW_GC |
| 2728 newfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s) + delta); | |
| 2729 | |
| 2730 len = XSTRING_LENGTH (s) + 1 - pos; | |
| 2731 | |
| 2732 if (delta < 0 && pos >= 0) | |
| 2733 memmove (XSTRING_DATA (s) + pos + delta, | |
| 2734 XSTRING_DATA (s) + pos, len); | |
| 2735 | |
| 2736 XSTRING_DATA_OBJECT (s) = | |
| 2737 wrap_string_direct_data (mc_realloc (XPNTR (XSTRING_DATA_OBJECT (s)), | |
| 2738 newfullsize)); | |
| 2739 if (delta > 0 && pos >= 0) | |
| 2740 memmove (XSTRING_DATA (s) + pos + delta, XSTRING_DATA (s) + pos, | |
| 2741 len); | |
| 2742 | |
| 3263 | 2743 #else /* not NEW_GC */ |
| 793 | 2744 oldfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s)); |
| 2745 newfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s) + delta); | |
| 438 | 2746 |
| 2747 if (BIG_STRING_FULLSIZE_P (oldfullsize)) | |
| 428 | 2748 { |
| 438 | 2749 if (BIG_STRING_FULLSIZE_P (newfullsize)) |
| 428 | 2750 { |
| 440 | 2751 /* Both strings are big. We can just realloc(). |
| 2752 But careful! If the string is shrinking, we have to | |
| 2753 memmove() _before_ realloc(), and if growing, we have to | |
| 2754 memmove() _after_ realloc() - otherwise the access is | |
| 2755 illegal, and we might crash. */ | |
| 793 | 2756 Bytecount len = XSTRING_LENGTH (s) + 1 - pos; |
| 440 | 2757 |
| 2758 if (delta < 0 && pos >= 0) | |
| 793 | 2759 memmove (XSTRING_DATA (s) + pos + delta, |
| 2760 XSTRING_DATA (s) + pos, len); | |
| 2761 XSET_STRING_DATA | |
| 867 | 2762 (s, (Ibyte *) xrealloc (XSTRING_DATA (s), |
| 793 | 2763 XSTRING_LENGTH (s) + delta + 1)); |
| 440 | 2764 if (delta > 0 && pos >= 0) |
| 793 | 2765 memmove (XSTRING_DATA (s) + pos + delta, XSTRING_DATA (s) + pos, |
| 2766 len); | |
| 1550 | 2767 /* Bump the cons counter. |
| 2768 Conservative; Martin let the increment be delta. */ | |
| 2769 INCREMENT_CONS_COUNTER (newfullsize, "string chars"); | |
| 428 | 2770 } |
| 438 | 2771 else /* String has been demoted from BIG_STRING. */ |
| 428 | 2772 { |
| 867 | 2773 Ibyte *new_data = |
| 438 | 2774 allocate_string_chars_struct (s, newfullsize)->chars; |
| 867 | 2775 Ibyte *old_data = XSTRING_DATA (s); |
| 438 | 2776 |
| 2777 if (pos >= 0) | |
| 2778 { | |
| 2779 memcpy (new_data, old_data, pos); | |
| 2780 memcpy (new_data + pos + delta, old_data + pos, | |
| 793 | 2781 XSTRING_LENGTH (s) + 1 - pos); |
| 438 | 2782 } |
| 793 | 2783 XSET_STRING_DATA (s, new_data); |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
2784 xfree (old_data); |
| 438 | 2785 } |
| 2786 } | |
| 2787 else /* old string is small */ | |
| 2788 { | |
| 2789 if (oldfullsize == newfullsize) | |
| 2790 { | |
| 2791 /* special case; size change but the necessary | |
| 2792 allocation size won't change (up or down; code | |
| 2793 somewhere depends on there not being any unused | |
| 2794 allocation space, modulo any alignment | |
| 2795 constraints). */ | |
| 428 | 2796 if (pos >= 0) |
| 2797 { | |
| 867 | 2798 Ibyte *addroff = pos + XSTRING_DATA (s); |
| 428 | 2799 |
| 2800 memmove (addroff + delta, addroff, | |
| 2801 /* +1 due to zero-termination. */ | |
| 793 | 2802 XSTRING_LENGTH (s) + 1 - pos); |
| 428 | 2803 } |
| 2804 } | |
| 2805 else | |
| 2806 { | |
| 867 | 2807 Ibyte *old_data = XSTRING_DATA (s); |
| 2808 Ibyte *new_data = | |
| 438 | 2809 BIG_STRING_FULLSIZE_P (newfullsize) |
| 1550 | 2810 ? allocate_big_string_chars (XSTRING_LENGTH (s) + delta + 1) |
| 438 | 2811 : allocate_string_chars_struct (s, newfullsize)->chars; |
| 2812 | |
| 428 | 2813 if (pos >= 0) |
| 2814 { | |
| 438 | 2815 memcpy (new_data, old_data, pos); |
| 2816 memcpy (new_data + pos + delta, old_data + pos, | |
| 793 | 2817 XSTRING_LENGTH (s) + 1 - pos); |
| 428 | 2818 } |
| 793 | 2819 XSET_STRING_DATA (s, new_data); |
| 438 | 2820 |
|
4776
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2821 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
|
2822 { |
|
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2823 /* 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
|
2824 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
|
2825 freak. */ |
|
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2826 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
|
2827 ((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
|
2828 /* 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
|
2829 alignment/padding. */ |
|
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2830 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
|
2831 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
|
2832 ((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
|
2833 oldfullsize; |
|
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2834 } |
| 428 | 2835 } |
| 438 | 2836 } |
| 3092 | 2837 #endif /* not NEW_GC */ |
| 438 | 2838 |
| 793 | 2839 XSET_STRING_LENGTH (s, XSTRING_LENGTH (s) + delta); |
| 438 | 2840 /* If pos < 0, the string won't be zero-terminated. |
| 2841 Terminate now just to make sure. */ | |
| 793 | 2842 XSTRING_DATA (s)[XSTRING_LENGTH (s)] = '\0'; |
| 438 | 2843 |
| 2844 if (pos >= 0) | |
| 793 | 2845 /* We also have to adjust all of the extent indices after the |
| 2846 place we did the change. We say "pos - 1" because | |
| 2847 adjust_extents() is exclusive of the starting position | |
| 2848 passed to it. */ | |
| 2849 adjust_extents (s, pos - 1, XSTRING_LENGTH (s), delta); | |
| 428 | 2850 |
| 2851 #ifdef VERIFY_STRING_CHARS_INTEGRITY | |
| 2852 verify_string_chars_integrity (); | |
| 2853 #endif | |
| 2854 } | |
| 2855 | |
| 2856 #ifdef MULE | |
| 2857 | |
| 771 | 2858 /* WARNING: If you modify an existing string, you must call |
| 2859 CHECK_LISP_WRITEABLE() before and bump_string_modiff() afterwards. */ | |
| 428 | 2860 void |
| 867 | 2861 set_string_char (Lisp_Object s, Charcount i, Ichar c) |
| 428 | 2862 { |
| 867 | 2863 Ibyte newstr[MAX_ICHAR_LEN]; |
| 771 | 2864 Bytecount bytoff = string_index_char_to_byte (s, i); |
| 867 | 2865 Bytecount oldlen = itext_ichar_len (XSTRING_DATA (s) + bytoff); |
| 2866 Bytecount newlen = set_itext_ichar (newstr, c); | |
| 428 | 2867 |
| 793 | 2868 sledgehammer_check_ascii_begin (s); |
| 428 | 2869 if (oldlen != newlen) |
| 2870 resize_string (s, bytoff, newlen - oldlen); | |
| 793 | 2871 /* Remember, XSTRING_DATA (s) might have changed so we can't cache it. */ |
| 2872 memcpy (XSTRING_DATA (s) + bytoff, newstr, newlen); | |
| 771 | 2873 if (oldlen != newlen) |
| 2874 { | |
| 793 | 2875 if (newlen > 1 && i <= (Charcount) XSTRING_ASCII_BEGIN (s)) |
| 771 | 2876 /* Everything starting with the new char is no longer part of |
| 2877 ascii_begin */ | |
| 793 | 2878 XSET_STRING_ASCII_BEGIN (s, i); |
| 2879 else if (newlen == 1 && i == (Charcount) XSTRING_ASCII_BEGIN (s)) | |
| 771 | 2880 /* We've extended ascii_begin, and we have to figure out how much by */ |
| 2881 { | |
| 2882 Bytecount j; | |
| 814 | 2883 for (j = (Bytecount) i + 1; j < XSTRING_LENGTH (s); j++) |
| 771 | 2884 { |
| 826 | 2885 if (!byte_ascii_p (XSTRING_DATA (s)[j])) |
| 771 | 2886 break; |
| 2887 } | |
| 814 | 2888 XSET_STRING_ASCII_BEGIN (s, min (j, (Bytecount) MAX_STRING_ASCII_BEGIN)); |
| 771 | 2889 } |
| 2890 } | |
| 793 | 2891 sledgehammer_check_ascii_begin (s); |
| 428 | 2892 } |
| 2893 | |
| 2894 #endif /* MULE */ | |
| 2895 | |
| 2896 DEFUN ("make-string", Fmake_string, 2, 2, 0, /* | |
| 444 | 2897 Return a new string consisting of LENGTH copies of CHARACTER. |
| 2898 LENGTH must be a non-negative integer. | |
| 428 | 2899 */ |
| 444 | 2900 (length, character)) |
| 428 | 2901 { |
|
5307
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
2902 check_integer_range (length, Qzero, make_int (ARRAY_DIMENSION_LIMIT)); |
| 444 | 2903 CHECK_CHAR_COERCE_INT (character); |
| 428 | 2904 { |
| 867 | 2905 Ibyte init_str[MAX_ICHAR_LEN]; |
| 2906 int len = set_itext_ichar (init_str, XCHAR (character)); | |
| 428 | 2907 Lisp_Object val = make_uninit_string (len * XINT (length)); |
| 2908 | |
| 2909 if (len == 1) | |
| 771 | 2910 { |
| 2911 /* Optimize the single-byte case */ | |
| 2912 memset (XSTRING_DATA (val), XCHAR (character), XSTRING_LENGTH (val)); | |
| 793 | 2913 XSET_STRING_ASCII_BEGIN (val, min (MAX_STRING_ASCII_BEGIN, |
| 2914 len * XINT (length))); | |
| 771 | 2915 } |
| 428 | 2916 else |
| 2917 { | |
| 647 | 2918 EMACS_INT i; |
| 867 | 2919 Ibyte *ptr = XSTRING_DATA (val); |
| 428 | 2920 |
| 2921 for (i = XINT (length); i; i--) | |
| 2922 { | |
| 867 | 2923 Ibyte *init_ptr = init_str; |
| 428 | 2924 switch (len) |
| 2925 { | |
| 2926 case 4: *ptr++ = *init_ptr++; | |
| 2927 case 3: *ptr++ = *init_ptr++; | |
| 2928 case 2: *ptr++ = *init_ptr++; | |
| 2929 case 1: *ptr++ = *init_ptr++; | |
| 2930 } | |
| 2931 } | |
| 2932 } | |
| 771 | 2933 sledgehammer_check_ascii_begin (val); |
| 428 | 2934 return val; |
| 2935 } | |
| 2936 } | |
| 2937 | |
| 2938 DEFUN ("string", Fstring, 0, MANY, 0, /* | |
| 2939 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
|
2940 |
|
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
2941 arguments: (&rest ARGS) |
| 428 | 2942 */ |
| 2943 (int nargs, Lisp_Object *args)) | |
| 2944 { | |
| 2367 | 2945 Ibyte *storage = alloca_ibytes (nargs * MAX_ICHAR_LEN); |
| 867 | 2946 Ibyte *p = storage; |
| 428 | 2947 |
| 2948 for (; nargs; nargs--, args++) | |
| 2949 { | |
| 2950 Lisp_Object lisp_char = *args; | |
| 2951 CHECK_CHAR_COERCE_INT (lisp_char); | |
| 867 | 2952 p += set_itext_ichar (p, XCHAR (lisp_char)); |
| 428 | 2953 } |
| 2954 return make_string (storage, p - storage); | |
| 2955 } | |
| 2956 | |
| 771 | 2957 /* Initialize the ascii_begin member of a string to the correct value. */ |
| 2958 | |
| 2959 void | |
| 2960 init_string_ascii_begin (Lisp_Object string) | |
| 2961 { | |
| 2962 #ifdef MULE | |
| 2963 int i; | |
| 2964 Bytecount length = XSTRING_LENGTH (string); | |
| 867 | 2965 Ibyte *contents = XSTRING_DATA (string); |
| 771 | 2966 |
| 2967 for (i = 0; i < length; i++) | |
| 2968 { | |
| 826 | 2969 if (!byte_ascii_p (contents[i])) |
| 771 | 2970 break; |
| 2971 } | |
| 793 | 2972 XSET_STRING_ASCII_BEGIN (string, min (i, MAX_STRING_ASCII_BEGIN)); |
| 771 | 2973 #else |
| 793 | 2974 XSET_STRING_ASCII_BEGIN (string, min (XSTRING_LENGTH (string), |
| 2975 MAX_STRING_ASCII_BEGIN)); | |
| 771 | 2976 #endif |
| 2977 sledgehammer_check_ascii_begin (string); | |
| 2978 } | |
| 428 | 2979 |
| 2980 /* Take some raw memory, which MUST already be in internal format, | |
| 2981 and package it up into a Lisp string. */ | |
| 2982 Lisp_Object | |
| 867 | 2983 make_string (const Ibyte *contents, Bytecount length) |
| 428 | 2984 { |
| 2985 Lisp_Object val; | |
| 2986 | |
| 2987 /* Make sure we find out about bad make_string's when they happen */ | |
| 800 | 2988 #if defined (ERROR_CHECK_TEXT) && defined (MULE) |
| 428 | 2989 bytecount_to_charcount (contents, length); /* Just for the assertions */ |
| 2990 #endif | |
| 2991 | |
| 2992 val = make_uninit_string (length); | |
| 2993 memcpy (XSTRING_DATA (val), contents, length); | |
| 771 | 2994 init_string_ascii_begin (val); |
| 2995 sledgehammer_check_ascii_begin (val); | |
| 428 | 2996 return val; |
| 2997 } | |
| 2998 | |
| 2999 /* Take some raw memory, encoded in some external data format, | |
| 3000 and convert it into a Lisp string. */ | |
| 3001 Lisp_Object | |
|
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3002 make_extstring (const Extbyte *contents, EMACS_INT length, |
| 440 | 3003 Lisp_Object coding_system) |
| 428 | 3004 { |
| 440 | 3005 Lisp_Object string; |
| 3006 TO_INTERNAL_FORMAT (DATA, (contents, length), | |
| 3007 LISP_STRING, string, | |
| 3008 coding_system); | |
| 3009 return string; | |
| 428 | 3010 } |
| 3011 | |
| 3012 Lisp_Object | |
|
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3013 build_istring (const Ibyte *str) |
| 771 | 3014 { |
| 3015 /* Some strlen's crash and burn if passed null. */ | |
| 814 | 3016 return make_string (str, (str ? qxestrlen (str) : (Bytecount) 0)); |
| 771 | 3017 } |
| 3018 | |
| 3019 Lisp_Object | |
|
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3020 build_cistring (const CIbyte *str) |
|
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3021 { |
|
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3022 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
|
3023 } |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3024 |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3025 Lisp_Object |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3026 build_ascstring (const Ascbyte *str) |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3027 { |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3028 ASSERT_ASCTEXT_ASCII (str); |
|
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3029 return build_istring ((const Ibyte *) str); |
| 428 | 3030 } |
| 3031 | |
| 3032 Lisp_Object | |
|
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3033 build_extstring (const Extbyte *str, Lisp_Object coding_system) |
| 428 | 3034 { |
| 3035 /* 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
|
3036 return make_extstring ((const Extbyte *) str, |
| 2367 | 3037 (str ? dfc_external_data_len (str, coding_system) : |
| 3038 0), | |
| 440 | 3039 coding_system); |
| 428 | 3040 } |
| 3041 | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3042 /* 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
|
3043 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
|
3044 |
| 428 | 3045 Lisp_Object |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3046 build_msg_istring (const Ibyte *str) |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3047 { |
|
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3048 return build_istring (IGETTEXT (str)); |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3049 } |
|
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 /* 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
|
3052 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
|
3053 |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3054 Lisp_Object |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3055 build_msg_cistring (const CIbyte *str) |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3056 { |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3057 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
|
3058 } |
|
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 /* 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
|
3061 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
|
3062 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
|
3063 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
|
3064 |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3065 Lisp_Object |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3066 build_msg_ascstring (const Ascbyte *str) |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3067 { |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3068 ASSERT_ASCTEXT_ASCII (str); |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3069 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
|
3070 } |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3071 |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3072 /* 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
|
3073 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
|
3074 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
|
3075 translated. |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3076 |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3077 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
|
3078 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
|
3079 properly. */ |
|
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 Lisp_Object |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3082 build_defer_istring (const Ibyte *str) |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3083 { |
|
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3084 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
|
3085 /* 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
|
3086 return retval; |
| 771 | 3087 } |
| 3088 | |
| 428 | 3089 Lisp_Object |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3090 build_defer_cistring (const CIbyte *str) |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3091 { |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3092 return build_defer_istring ((Ibyte *) str); |
| 771 | 3093 } |
| 3094 | |
| 3095 Lisp_Object | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3096 build_defer_ascstring (const Ascbyte *str) |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3097 { |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3098 ASSERT_ASCTEXT_ASCII (str); |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3099 return build_defer_istring ((Ibyte *) str); |
| 428 | 3100 } |
| 3101 | |
| 3102 Lisp_Object | |
| 867 | 3103 make_string_nocopy (const Ibyte *contents, Bytecount length) |
| 428 | 3104 { |
| 438 | 3105 Lisp_String *s; |
| 428 | 3106 Lisp_Object val; |
| 3107 | |
| 3108 /* Make sure we find out about bad make_string_nocopy's when they happen */ | |
| 800 | 3109 #if defined (ERROR_CHECK_TEXT) && defined (MULE) |
| 428 | 3110 bytecount_to_charcount (contents, length); /* Just for the assertions */ |
| 3111 #endif | |
| 3112 | |
| 3263 | 3113 #ifdef NEW_GC |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3114 s = XSTRING (ALLOC_NORMAL_LISP_OBJECT (string)); |
| 2720 | 3115 mcpro (wrap_pointer_1 (s)); /* otherwise nocopy_strings get |
| 3116 collected and static data is tried to | |
| 3117 be freed. */ | |
| 3263 | 3118 #else /* not NEW_GC */ |
| 428 | 3119 /* Allocate the string header */ |
| 438 | 3120 ALLOCATE_FIXED_TYPE (string, Lisp_String, s); |
| 771 | 3121 set_lheader_implementation (&s->u.lheader, &lrecord_string); |
| 3122 SET_C_READONLY_RECORD_HEADER (&s->u.lheader); | |
| 3263 | 3123 #endif /* not NEW_GC */ |
| 3063 | 3124 /* Don't need to XSET_STRING_ASCII_BEGIN() here because it happens in |
| 3125 init_string_ascii_begin(). */ | |
| 428 | 3126 s->plist = Qnil; |
| 3092 | 3127 #ifdef NEW_GC |
| 3128 set_lispstringp_indirect (s); | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3129 STRING_DATA_OBJECT (s) = ALLOC_NORMAL_LISP_OBJECT (string_indirect_data); |
| 3092 | 3130 XSTRING_INDIRECT_DATA_DATA (STRING_DATA_OBJECT (s)) = (Ibyte *) contents; |
| 3131 XSTRING_INDIRECT_DATA_SIZE (STRING_DATA_OBJECT (s)) = length; | |
| 3132 #else /* not NEW_GC */ | |
| 867 | 3133 set_lispstringp_data (s, (Ibyte *) contents); |
| 826 | 3134 set_lispstringp_length (s, length); |
| 3092 | 3135 #endif /* not NEW_GC */ |
| 793 | 3136 val = wrap_string (s); |
| 771 | 3137 init_string_ascii_begin (val); |
| 3138 sledgehammer_check_ascii_begin (val); | |
| 3139 | |
| 428 | 3140 return val; |
| 3141 } | |
| 3142 | |
| 3143 | |
| 3263 | 3144 #ifndef NEW_GC |
| 428 | 3145 /************************************************************************/ |
| 3146 /* lcrecord lists */ | |
| 3147 /************************************************************************/ | |
| 3148 | |
| 3149 /* 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
|
3150 sorts of lcrecords, to avoid calling ALLOC_NORMAL_LISP_OBJECT() (and thus |
| 428 | 3151 malloc() and garbage-collection junk) as much as possible. |
| 3152 It is similar to the Blocktype class. | |
| 3153 | |
| 1204 | 3154 See detailed comment in lcrecord.h. |
| 3155 */ | |
| 3156 | |
| 3157 const struct memory_description free_description[] = { | |
| 2551 | 3158 { XD_LISP_OBJECT, offsetof (struct free_lcrecord_header, chain), 0, { 0 }, |
| 1204 | 3159 XD_FLAG_FREE_LISP_OBJECT }, |
| 3160 { XD_END } | |
| 3161 }; | |
| 3162 | |
|
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3163 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
|
3164 struct free_lcrecord_header); |
| 1204 | 3165 |
| 3166 const struct memory_description lcrecord_list_description[] = { | |
| 2551 | 3167 { XD_LISP_OBJECT, offsetof (struct lcrecord_list, free), 0, { 0 }, |
| 1204 | 3168 XD_FLAG_FREE_LISP_OBJECT }, |
| 3169 { XD_END } | |
| 3170 }; | |
| 428 | 3171 |
| 3172 static Lisp_Object | |
| 3173 mark_lcrecord_list (Lisp_Object obj) | |
| 3174 { | |
| 3175 struct lcrecord_list *list = XLCRECORD_LIST (obj); | |
| 3176 Lisp_Object chain = list->free; | |
| 3177 | |
| 3178 while (!NILP (chain)) | |
| 3179 { | |
| 3180 struct lrecord_header *lheader = XRECORD_LHEADER (chain); | |
| 3181 struct free_lcrecord_header *free_header = | |
| 3182 (struct free_lcrecord_header *) lheader; | |
| 3183 | |
| 442 | 3184 gc_checking_assert |
| 3185 (/* There should be no other pointers to the free list. */ | |
| 3186 ! MARKED_RECORD_HEADER_P (lheader) | |
| 3187 && | |
| 3188 /* Only lcrecords should be here. */ | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3189 ! list->implementation->frob_block_p |
| 442 | 3190 && |
| 3191 /* 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
|
3192 lheader->free |
| 442 | 3193 && |
| 3194 /* The type of the lcrecord must be right. */ | |
| 1204 | 3195 lheader->type == lrecord_type_free |
| 442 | 3196 && |
| 3197 /* So must the size. */ | |
| 1204 | 3198 (list->implementation->static_size == 0 || |
| 3199 list->implementation->static_size == list->size) | |
| 442 | 3200 ); |
| 428 | 3201 |
| 3202 MARK_RECORD_HEADER (lheader); | |
| 3203 chain = free_header->chain; | |
| 3204 } | |
| 3205 | |
| 3206 return Qnil; | |
| 3207 } | |
| 3208 | |
|
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3209 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
|
3210 mark_lcrecord_list, |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3211 lcrecord_list_description, |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3212 struct lcrecord_list); |
| 934 | 3213 |
| 428 | 3214 Lisp_Object |
| 665 | 3215 make_lcrecord_list (Elemcount size, |
| 442 | 3216 const struct lrecord_implementation *implementation) |
| 428 | 3217 { |
|
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
3218 /* 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
|
3219 allocating this. */ |
|
5151
641d0cdd1d00
fix compilation problems identified by Robert Delius Royar
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3220 struct lcrecord_list *p = |
|
641d0cdd1d00
fix compilation problems identified by Robert Delius Royar
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3221 XLCRECORD_LIST (old_alloc_lcrecord (&lrecord_lcrecord_list)); |
| 428 | 3222 |
| 3223 p->implementation = implementation; | |
| 3224 p->size = size; | |
| 3225 p->free = Qnil; | |
| 793 | 3226 return wrap_lcrecord_list (p); |
| 428 | 3227 } |
| 3228 | |
| 3229 Lisp_Object | |
| 1204 | 3230 alloc_managed_lcrecord (Lisp_Object lcrecord_list) |
| 428 | 3231 { |
| 3232 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list); | |
| 3233 if (!NILP (list->free)) | |
| 3234 { | |
| 3235 Lisp_Object val = list->free; | |
| 3236 struct free_lcrecord_header *free_header = | |
| 3237 (struct free_lcrecord_header *) XPNTR (val); | |
| 1204 | 3238 struct lrecord_header *lheader = &free_header->lcheader.lheader; |
| 428 | 3239 |
| 3240 #ifdef ERROR_CHECK_GC | |
| 1204 | 3241 /* Major overkill here. */ |
| 428 | 3242 /* There should be no other pointers to the free list. */ |
| 442 | 3243 assert (! MARKED_RECORD_HEADER_P (lheader)); |
| 428 | 3244 /* 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
|
3245 assert (lheader->free); |
| 1204 | 3246 assert (lheader->type == lrecord_type_free); |
| 3247 /* Only lcrecords should be here. */ | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3248 assert (! (list->implementation->frob_block_p)); |
| 1204 | 3249 #if 0 /* Not used anymore, now that we set the type of the header to |
| 3250 lrecord_type_free. */ | |
| 428 | 3251 /* The type of the lcrecord must be right. */ |
| 442 | 3252 assert (LHEADER_IMPLEMENTATION (lheader) == list->implementation); |
| 1204 | 3253 #endif /* 0 */ |
| 428 | 3254 /* So must the size. */ |
| 1204 | 3255 assert (list->implementation->static_size == 0 || |
| 3256 list->implementation->static_size == list->size); | |
| 428 | 3257 #endif /* ERROR_CHECK_GC */ |
| 442 | 3258 |
| 428 | 3259 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
|
3260 lheader->free = 0; |
| 1204 | 3261 /* Put back the correct type, as we set it to lrecord_type_free. */ |
| 3262 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
|
3263 zero_sized_lisp_object (val, list->size); |
| 428 | 3264 return val; |
| 3265 } | |
| 3266 else | |
|
5151
641d0cdd1d00
fix compilation problems identified by Robert Delius Royar
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
3267 return old_alloc_sized_lcrecord (list->size, list->implementation); |
| 428 | 3268 } |
| 3269 | |
| 771 | 3270 /* "Free" a Lisp object LCRECORD by placing it on its associated free list |
| 1204 | 3271 LCRECORD_LIST; next time alloc_managed_lcrecord() is called with the |
| 771 | 3272 same LCRECORD_LIST as its parameter, it will return an object from the |
| 3273 free list, which may be this one. Be VERY VERY SURE there are no | |
| 3274 pointers to this object hanging around anywhere where they might be | |
| 3275 used! | |
| 3276 | |
| 3277 The first thing this does before making any global state change is to | |
| 3278 call the finalize method of the object, if it exists. */ | |
| 3279 | |
| 428 | 3280 void |
| 3281 free_managed_lcrecord (Lisp_Object lcrecord_list, Lisp_Object lcrecord) | |
| 3282 { | |
| 3283 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list); | |
| 3284 struct free_lcrecord_header *free_header = | |
| 3285 (struct free_lcrecord_header *) XPNTR (lcrecord); | |
| 442 | 3286 struct lrecord_header *lheader = &free_header->lcheader.lheader; |
| 3287 const struct lrecord_implementation *implementation | |
| 428 | 3288 = LHEADER_IMPLEMENTATION (lheader); |
| 3289 | |
|
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3290 /* 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
|
3291 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
|
3292 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
|
3293 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
|
3294 super long-lived afterwards, anyway. */ |
|
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3295 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
|
3296 return; |
|
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3297 |
| 771 | 3298 /* Finalizer methods may try to free objects within them, which typically |
| 3299 won't be marked and thus are scheduled for demolition. Putting them | |
| 3300 on the free list would be very bad, as we'd have xfree()d memory in | |
| 3301 the list. Even if for some reason the objects are still live | |
| 3302 (generally a logic error!), we still will have problems putting such | |
| 3303 an object on the free list right now (e.g. we'd have to avoid calling | |
| 3304 the finalizer twice, etc.). So basically, those finalizers should not | |
| 3305 be freeing any objects if during GC. Abort now to catch those | |
| 3306 problems. */ | |
| 3307 gc_checking_assert (!gc_in_progress); | |
| 3308 | |
| 428 | 3309 /* Make sure the size is correct. This will catch, for example, |
| 3310 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
|
3311 gc_checking_assert (lisp_object_size (lcrecord) == list->size); |
| 771 | 3312 /* 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
|
3313 gc_checking_assert (!lheader->free); |
| 2367 | 3314 /* Freeing stuff in dumped memory is bad. If you trip this, you |
| 3315 may need to check for this before freeing. */ | |
| 3316 gc_checking_assert (!OBJECT_DUMPED_P (lcrecord)); | |
| 771 | 3317 |
| 428 | 3318 if (implementation->finalizer) |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
3319 implementation->finalizer (lcrecord); |
| 1204 | 3320 /* Yes, there are two ways to indicate freeness -- the type is |
| 3321 lrecord_type_free or the ->free flag is set. We used to do only the | |
| 3322 latter; now we do the former as well for KKCC purposes. Probably | |
| 3323 safer in any case, as we will lose quicker this way than keeping | |
| 3324 around an lrecord of apparently correct type but bogus junk in it. */ | |
| 3325 MARK_LRECORD_AS_FREE (lheader); | |
| 428 | 3326 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
|
3327 lheader->free = 1; |
| 428 | 3328 list->free = lcrecord; |
| 3329 } | |
| 3330 | |
| 771 | 3331 static Lisp_Object all_lcrecord_lists[countof (lrecord_implementations_table)]; |
| 3332 | |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3333 Lisp_Object |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3334 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
|
3335 const struct lrecord_implementation *imp) |
| 771 | 3336 { |
| 3337 if (EQ (all_lcrecord_lists[imp->lrecord_type_index], Qzero)) | |
| 3338 all_lcrecord_lists[imp->lrecord_type_index] = | |
| 3339 make_lcrecord_list (size, imp); | |
| 3340 | |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3341 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
|
3342 } |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3343 |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3344 Lisp_Object |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3345 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
|
3346 { |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3347 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
|
3348 return alloc_automanaged_sized_lcrecord (imp->static_size, imp); |
| 771 | 3349 } |
| 3350 | |
| 3351 void | |
| 3024 | 3352 old_free_lcrecord (Lisp_Object rec) |
| 771 | 3353 { |
| 3354 int type = XRECORD_LHEADER (rec)->type; | |
| 3355 | |
| 3356 assert (!EQ (all_lcrecord_lists[type], Qzero)); | |
| 3357 | |
| 3358 free_managed_lcrecord (all_lcrecord_lists[type], rec); | |
| 3359 } | |
| 3263 | 3360 #endif /* not NEW_GC */ |
| 428 | 3361 |
| 3362 | |
| 3363 /************************************************************************/ | |
|
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3364 /* Staticpro, MCpro */ |
| 428 | 3365 /************************************************************************/ |
| 3366 | |
| 771 | 3367 /* We want the staticpro list relocated, but not the pointers found |
| 3368 therein, because they refer to locations in the global data segment, not | |
| 3369 in the heap; we only dump heap objects. Hence we use a trivial | |
| 3370 description, as for pointerless objects. (Note that the data segment | |
| 3371 objects, which are global variables like Qfoo or Vbar, themselves are | |
| 3372 pointers to heap objects. Each needs to be described to pdump as a | |
| 3373 "root pointer"; this happens in the call to staticpro(). */ | |
| 1204 | 3374 static const struct memory_description staticpro_description_1[] = { |
| 452 | 3375 { XD_END } |
| 3376 }; | |
| 3377 | |
| 1204 | 3378 static const struct sized_memory_description staticpro_description = { |
| 452 | 3379 sizeof (Lisp_Object *), |
| 3380 staticpro_description_1 | |
| 3381 }; | |
| 3382 | |
| 1204 | 3383 static const struct memory_description staticpros_description_1[] = { |
| 452 | 3384 XD_DYNARR_DESC (Lisp_Object_ptr_dynarr, &staticpro_description), |
| 3385 { XD_END } | |
| 3386 }; | |
| 3387 | |
| 1204 | 3388 static const struct sized_memory_description staticpros_description = { |
| 452 | 3389 sizeof (Lisp_Object_ptr_dynarr), |
| 3390 staticpros_description_1 | |
| 3391 }; | |
| 3392 | |
| 771 | 3393 #ifdef DEBUG_XEMACS |
| 3394 | |
| 3395 /* Help debug crashes gc-marking a staticpro'ed object. */ | |
| 3396 | |
| 3397 Lisp_Object_ptr_dynarr *staticpros; | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3398 const_Ascbyte_ptr_dynarr *staticpro_names; |
| 771 | 3399 |
| 3400 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
| 3401 garbage collection, and for dumping. */ | |
| 3402 void | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3403 staticpro_1 (Lisp_Object *varaddress, const Ascbyte *varname) |
| 771 | 3404 { |
| 3405 Dynarr_add (staticpros, varaddress); | |
| 3406 Dynarr_add (staticpro_names, varname); | |
| 1204 | 3407 dump_add_root_lisp_object (varaddress); |
| 771 | 3408 } |
| 3409 | |
|
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3410 const Ascbyte *staticpro_name (int count); |
|
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3411 |
|
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3412 /* 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
|
3413 COUNT. */ |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3414 const Ascbyte * |
|
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3415 staticpro_name (int count) |
|
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3416 { |
|
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3417 return Dynarr_at (staticpro_names, count); |
|
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3418 } |
| 771 | 3419 |
| 3420 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
|
3421 const_Ascbyte_ptr_dynarr *staticpro_nodump_names; |
| 771 | 3422 |
| 3423 /* Mark the Lisp_Object at heap VARADDRESS as a root object for | |
| 3424 garbage collection, but not for dumping. (See below.) */ | |
| 3425 void | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3426 staticpro_nodump_1 (Lisp_Object *varaddress, const Ascbyte *varname) |
| 771 | 3427 { |
| 3428 Dynarr_add (staticpros_nodump, varaddress); | |
| 3429 Dynarr_add (staticpro_nodump_names, varname); | |
| 3430 } | |
| 3431 | |
|
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3432 const Ascbyte *staticpro_nodump_name (int count); |
|
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3433 |
|
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3434 /* 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
|
3435 COUNT. */ |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3436 const Ascbyte * |
|
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3437 staticpro_nodump_name (int count) |
|
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3438 { |
|
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3439 return Dynarr_at (staticpro_nodump_names, count); |
|
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3440 } |
|
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3441 |
| 996 | 3442 #ifdef HAVE_SHLIB |
| 3443 /* Stop treating the Lisp_Object at non-heap VARADDRESS as a root object | |
| 3444 for garbage collection, but not for dumping. */ | |
| 3445 void | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3446 unstaticpro_nodump_1 (Lisp_Object *varaddress, const Ascbyte *varname) |
| 996 | 3447 { |
| 3448 Dynarr_delete_object (staticpros, varaddress); | |
| 3449 Dynarr_delete_object (staticpro_names, varname); | |
| 3450 } | |
| 3451 #endif | |
| 3452 | |
| 771 | 3453 #else /* not DEBUG_XEMACS */ |
| 3454 | |
| 452 | 3455 Lisp_Object_ptr_dynarr *staticpros; |
| 3456 | |
| 3457 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
| 3458 garbage collection, and for dumping. */ | |
| 428 | 3459 void |
| 3460 staticpro (Lisp_Object *varaddress) | |
| 3461 { | |
| 452 | 3462 Dynarr_add (staticpros, varaddress); |
| 1204 | 3463 dump_add_root_lisp_object (varaddress); |
| 428 | 3464 } |
| 3465 | |
| 442 | 3466 |
| 452 | 3467 Lisp_Object_ptr_dynarr *staticpros_nodump; |
| 3468 | |
| 771 | 3469 /* Mark the Lisp_Object at heap VARADDRESS as a root object for garbage |
| 3470 collection, but not for dumping. This is used for objects where the | |
| 3471 only sure pointer is in the heap (rather than in the global data | |
| 3472 segment, as must be the case for pdump root pointers), but not inside of | |
| 3473 another Lisp object (where it will be marked as a result of that Lisp | |
| 3474 object's mark method). The call to staticpro_nodump() must occur *BOTH* | |
| 3475 at initialization time and at "reinitialization" time (startup, after | |
| 3476 pdump load.) (For example, this is the case with the predicate symbols | |
| 3477 for specifier and coding system types. The pointer to this symbol is | |
| 3478 inside of a methods structure, which is allocated on the heap. The | |
| 3479 methods structure will be written out to the pdump data file, and may be | |
| 3480 reloaded at a different address.) | |
| 3481 | |
| 3482 #### The necessity for reinitialization is a bug in pdump. Pdump should | |
| 3483 automatically regenerate the staticpro()s for these symbols when it | |
| 3484 loads the data in. */ | |
| 3485 | |
| 428 | 3486 void |
| 3487 staticpro_nodump (Lisp_Object *varaddress) | |
| 3488 { | |
| 452 | 3489 Dynarr_add (staticpros_nodump, varaddress); |
| 428 | 3490 } |
| 3491 | |
| 996 | 3492 #ifdef HAVE_SHLIB |
| 3493 /* Unmark the Lisp_Object at non-heap VARADDRESS as a root object for | |
| 3494 garbage collection, but not for dumping. */ | |
| 3495 void | |
| 3496 unstaticpro_nodump (Lisp_Object *varaddress) | |
| 3497 { | |
| 3498 Dynarr_delete_object (staticpros, varaddress); | |
| 3499 } | |
| 3500 #endif | |
| 3501 | |
| 771 | 3502 #endif /* not DEBUG_XEMACS */ |
| 3503 | |
| 3263 | 3504 #ifdef NEW_GC |
| 2720 | 3505 static const struct memory_description mcpro_description_1[] = { |
| 3506 { XD_END } | |
| 3507 }; | |
| 3508 | |
| 3509 static const struct sized_memory_description mcpro_description = { | |
| 3510 sizeof (Lisp_Object *), | |
| 3511 mcpro_description_1 | |
| 3512 }; | |
| 3513 | |
| 3514 static const struct memory_description mcpros_description_1[] = { | |
| 3515 XD_DYNARR_DESC (Lisp_Object_dynarr, &mcpro_description), | |
| 3516 { XD_END } | |
| 3517 }; | |
| 3518 | |
| 3519 static const struct sized_memory_description mcpros_description = { | |
| 3520 sizeof (Lisp_Object_dynarr), | |
| 3521 mcpros_description_1 | |
| 3522 }; | |
| 3523 | |
| 3524 #ifdef DEBUG_XEMACS | |
| 3525 | |
| 3526 /* Help debug crashes gc-marking a mcpro'ed object. */ | |
| 3527 | |
| 3528 Lisp_Object_dynarr *mcpros; | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3529 const_Ascbyte_ptr_dynarr *mcpro_names; |
| 2720 | 3530 |
| 3531 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
| 3532 garbage collection, and for dumping. */ | |
| 3533 void | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3534 mcpro_1 (Lisp_Object varaddress, const Ascbyte *varname) |
| 2720 | 3535 { |
| 3536 Dynarr_add (mcpros, varaddress); | |
| 3537 Dynarr_add (mcpro_names, varname); | |
| 3538 } | |
| 3539 | |
| 5046 | 3540 const Ascbyte *mcpro_name (int count); |
| 3541 | |
|
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3542 /* 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
|
3543 COUNT. */ |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3544 const Ascbyte * |
|
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3545 mcpro_name (int count) |
|
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3546 { |
|
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3547 return Dynarr_at (mcpro_names, count); |
|
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3548 } |
|
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3549 |
| 2720 | 3550 #else /* not DEBUG_XEMACS */ |
| 3551 | |
| 3552 Lisp_Object_dynarr *mcpros; | |
| 3553 | |
| 3554 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
| 3555 garbage collection, and for dumping. */ | |
| 3556 void | |
| 3557 mcpro (Lisp_Object varaddress) | |
| 3558 { | |
| 3559 Dynarr_add (mcpros, varaddress); | |
| 3560 } | |
| 3561 | |
| 3562 #endif /* not DEBUG_XEMACS */ | |
| 3263 | 3563 #endif /* NEW_GC */ |
| 3564 | |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3565 #ifdef ALLOC_TYPE_STATS |
| 428 | 3566 |
| 3567 | |
|
5167
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 /* Determining allocation overhead */ |
|
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 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3572 /* 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
|
3573 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
|
3574 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3575 It seems that the following holds: |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3576 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3577 1. When using the old allocator (malloc.c): |
|
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 -- 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
|
3580 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
|
3581 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
|
3582 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
|
3583 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
|
3584 it. |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3585 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3586 2. When using the new allocator (gmalloc.c): |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3587 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3588 -- 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
|
3589 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
|
3590 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
|
3591 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
|
3592 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
|
3593 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
|
3594 allocated. |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3595 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3596 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
|
3597 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
|
3598 allocators. One possibly reasonable assumption to make |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3599 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
|
3600 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
|
3601 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
|
3602 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
|
3603 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3604 Bytecount |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3605 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
|
3606 struct usage_stats *stats) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3607 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3608 Bytecount orig_claimed_size = claimed_size; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3609 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3610 #ifndef SYSTEM_MALLOC |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3611 if (claimed_size < (Bytecount) (2 * sizeof (void *))) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3612 claimed_size = 2 * sizeof (void *); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3613 # ifdef SUNOS_LOCALTIME_BUG |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3614 if (claimed_size < 16) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3615 claimed_size = 16; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3616 # endif |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3617 if (claimed_size < 4096) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3618 { |
|
5384
3889ef128488
Fix misspelled words, and some grammar, across the entire source tree.
Jerry James <james@xemacs.org>
parents:
5354
diff
changeset
|
3619 /* fxg: rename log->log2 to suppress gcc3 shadow warning */ |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3620 int log2 = 1; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3621 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3622 /* 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
|
3623 the block size needed. */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3624 claimed_size--; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3625 /* 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
|
3626 while ((claimed_size /= 2) != 0) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3627 ++log2; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3628 claimed_size = 1; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3629 /* It's better than bad, it's good! */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3630 while (log2 > 0) |
|
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 claimed_size *= 2; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3633 log2--; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3634 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3635 /* 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
|
3636 blocks used. */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3637 if ((Bytecount) (rand () & 4095) < claimed_size) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3638 claimed_size += 3 * sizeof (void *); |
|
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 else |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3641 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3642 claimed_size += 4095; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3643 claimed_size &= ~4095; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3644 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
|
3645 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3646 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3647 #else |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3648 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3649 if (claimed_size < 16) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3650 claimed_size = 16; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3651 claimed_size += 2 * sizeof (void *); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3652 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3653 #endif /* system allocator */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3654 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3655 if (stats) |
|
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 stats->was_requested += orig_claimed_size; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3658 stats->malloc_overhead += claimed_size - orig_claimed_size; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3659 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3660 return claimed_size; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3661 } |
|
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 #ifndef NEW_GC |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3664 static Bytecount |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3665 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
|
3666 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3667 Bytecount overhead = 0; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3668 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
|
3669 while (size >= per_block) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3670 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3671 size -= per_block; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3672 overhead += storage_size - per_block; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3673 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3674 if (rand () % per_block < size) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3675 overhead += storage_size - per_block; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3676 return overhead; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3677 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3678 #endif /* not NEW_GC */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3679 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3680 Bytecount |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3681 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
|
3682 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3683 #ifndef NEW_GC |
|
5179
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3684 const struct lrecord_implementation *imp; |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3685 #endif /* not NEW_GC */ |
|
5179
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3686 Bytecount size; |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3687 |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3688 if (!LRECORDP (obj)) |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3689 return 0; |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3690 |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3691 size = lisp_object_size (obj); |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3692 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3693 #ifdef NEW_GC |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3694 return mc_alloced_storage_size (size, ustats); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3695 #else |
|
5179
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
3696 imp = XRECORD_LHEADER_IMPLEMENTATION (obj); |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3697 if (imp->frob_block_p) |
|
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 Bytecount overhead = |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3700 /* #### 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
|
3701 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
|
3702 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
|
3703 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
|
3704 if (ustats) |
|
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 ustats->was_requested += size; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3707 ustats->malloc_overhead += overhead; |
|
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 return size + overhead; |
|
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 else |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3712 return malloced_storage_size (XPNTR (obj), size, ustats); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3713 #endif |
|
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 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3716 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3717 /************************************************************************/ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3718 /* Allocation Statistics: Accumulate */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3719 /************************************************************************/ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3720 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3721 #ifdef NEW_GC |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3722 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3723 void |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3724 init_lrecord_stats (void) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3725 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3726 xzero (lrecord_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 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
|
3731 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3732 int type_index = h->type; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3733 if (!size) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3734 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 |
|
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3739 #ifdef MEMORY_USAGE_STATS |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3740 += mc_alloced_storage_size (size, 0); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3741 #else /* not MEMORY_USAGE_STATS */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3742 += size; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3743 #endif /* not MEMORY_USAGE_STATS */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3744 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3745 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3746 void |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3747 dec_lrecord_stats (Bytecount size_including_overhead, |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3748 const struct lrecord_header *h) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3749 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3750 int type_index = h->type; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3751 int size = detagged_lisp_object_size (h); |
|
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 lrecord_stats[type_index].instances_in_use--; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3754 lrecord_stats[type_index].bytes_in_use -= size; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3755 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
|
3756 -= size_including_overhead; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3757 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3758 DECREMENT_CONS_COUNTER (size); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3759 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3760 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3761 int |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3762 lrecord_stats_heap_size (void) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3763 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3764 int i; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3765 int size = 0; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3766 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
|
3767 size += lrecord_stats[i].bytes_in_use; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3768 return size; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3769 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3770 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3771 #else /* not NEW_GC */ |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3772 |
|
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3773 static void |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3774 clear_lrecord_stats (void) |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3775 { |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3776 xzero (lrecord_stats); |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3777 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
|
3778 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
|
3779 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
|
3780 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
|
3781 } |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3782 |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3783 /* 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
|
3784 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
|
3785 static void |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3786 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
|
3787 { |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3788 Bytecount size = p->size_; |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3789 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
|
3790 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
|
3791 { |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3792 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
|
3793 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
|
3794 } |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3795 else |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3796 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
|
3797 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
|
3798 /* 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
|
3799 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
|
3800 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
|
3801 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
|
3802 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
|
3803 if (!from_sweep) |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3804 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
|
3805 } |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3806 |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3807 /* 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
|
3808 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
|
3809 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
|
3810 (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
|
3811 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
|
3812 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
|
3813 frob blocks. */ |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3814 |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3815 void |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3816 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
|
3817 enum lrecord_alloc_status status) |
| 428 | 3818 { |
| 647 | 3819 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
|
3820 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
|
3821 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
|
3822 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
|
3823 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
|
3824 |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3825 switch (status) |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3826 { |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3827 case ALLOC_IN_USE: |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3828 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
|
3829 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
|
3830 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
|
3831 if (STRINGP (obj)) |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3832 tick_string_stats (XSTRING (obj), 0); |
|
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3833 #ifdef MEMORY_USAGE_STATS |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3834 { |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3835 struct generic_usage_stats stats; |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3836 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
|
3837 { |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3838 int i; |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3839 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
|
3840 xzero (stats); |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3841 OBJECT_METH (obj, memory_usage, (obj, &stats)); |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3842 for (i = 0; i < total_stats; i++) |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3843 lrecord_stats[type_index].stats.othervals[i] += |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3844 stats.othervals[i]; |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3845 } |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3846 } |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3847 #endif |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3848 break; |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3849 case ALLOC_FREE: |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3850 lrecord_stats[type_index].instances_freed++; |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3851 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
|
3852 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
|
3853 break; |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3854 case ALLOC_ON_FREE_LIST: |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3855 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
|
3856 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
|
3857 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
|
3858 break; |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3859 default: |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3860 ABORT (); |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3861 } |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3862 } |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3863 |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3864 inline static void |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3865 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
|
3866 { |
|
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
3867 if (h->free) |
| 428 | 3868 { |
| 442 | 3869 gc_checking_assert (!free_p); |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3870 tick_lrecord_stats (h, ALLOC_ON_FREE_LIST); |
| 428 | 3871 } |
| 3872 else | |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
3873 tick_lrecord_stats (h, free_p ? ALLOC_FREE : ALLOC_IN_USE); |
| 428 | 3874 } |
|
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
3875 |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3876 #endif /* (not) NEW_GC */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3877 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3878 void |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3879 finish_object_memory_usage_stats (void) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3880 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3881 /* 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
|
3882 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
|
3883 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
|
3884 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
|
3885 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
|
3886 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
|
3887 #if defined (MEMORY_USAGE_STATS) && !defined (NEW_GC) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3888 int i; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3889 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
|
3890 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3891 struct lrecord_implementation *imp = lrecord_implementations_table[i]; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3892 if (imp && imp->num_extra_nonlisp_memusage_stats) |
|
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 int j; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3895 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
|
3896 lrecord_stats[i].nonlisp_bytes_in_use += |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3897 lrecord_stats[i].stats.othervals[j]; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3898 } |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
3899 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
|
3900 { |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
3901 int j; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
3902 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
|
3903 lrecord_stats[i].lisp_ancillary_bytes_in_use += |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
3904 lrecord_stats[i].stats.othervals |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
3905 [j + imp->offset_lisp_ancillary_memusage_stats]; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
3906 } |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3907 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3908 #endif /* defined (MEMORY_USAGE_STATS) && !defined (NEW_GC) */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3909 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3910 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3911 #define COUNT_FROB_BLOCK_USAGE(type) \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3912 EMACS_INT s = 0; \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3913 EMACS_INT s_overhead = 0; \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3914 struct type##_block *x = current_##type##_block; \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3915 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
|
3916 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
|
3917 DO_NOTHING |
|
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 #define COPY_INTO_LRECORD_STATS(type) \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3920 do { \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3921 COUNT_FROB_BLOCK_USAGE (type); \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3922 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
|
3923 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
|
3924 s_overhead; \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3925 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
|
3926 gc_count_num_##type##_freelist; \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3927 lrecord_stats[lrecord_type_##type].instances_in_use += \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3928 gc_count_num_##type##_in_use; \ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3929 } while (0) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3930 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3931 |
|
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 /* Allocation statistics: format nicely */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3934 /************************************************************************/ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3935 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3936 static Lisp_Object |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3937 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
|
3938 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3939 /* 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
|
3940 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
|
3941 arrays, or exceptions, or ...) */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3942 return cons3 (intern (name), make_int (value), tail); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3943 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3944 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3945 /* 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
|
3946 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
|
3947 static void |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3948 pluralize_word (Ascbyte *buf) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3949 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3950 Bytecount len = strlen (buf); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3951 int upper = 0; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3952 Ascbyte d, e; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3953 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3954 if (len == 0 || len == 1) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3955 goto pluralize_apostrophe_s; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3956 e = buf[len - 1]; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3957 d = buf[len - 2]; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3958 upper = isupper (e); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3959 e = tolower (e); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3960 d = tolower (d); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3961 if (e == 'y') |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3962 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3963 switch (d) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3964 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3965 case 'a': |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3966 case 'e': |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3967 case 'i': |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3968 case 'o': |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3969 case 'u': |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3970 goto pluralize_s; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3971 default: |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3972 buf[len - 1] = (upper ? 'I' : 'i'); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3973 goto pluralize_es; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3974 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3975 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3976 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
|
3977 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3978 pluralize_es: |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3979 buf[len++] = (upper ? 'E' : 'e'); |
|
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 pluralize_s: |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3982 buf[len++] = (upper ? 'S' : 's'); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3983 buf[len] = '\0'; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3984 return; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3985 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3986 pluralize_apostrophe_s: |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3987 buf[len++] = '\''; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3988 goto pluralize_s; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3989 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3990 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3991 static void |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3992 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
|
3993 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3994 strcpy (buf, name); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3995 pluralize_word (buf); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3996 strcat (buf, suffix); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3997 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3998 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
3999 static Lisp_Object |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4000 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
|
4001 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4002 Lisp_Object pl = Qnil; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4003 int i; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4004 EMACS_INT tgu_val = 0; |
|
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 #ifdef NEW_GC |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4007 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
|
4008 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4009 if (lrecord_stats[i].instances_in_use != 0) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4010 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4011 Ascbyte buf[255]; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4012 const Ascbyte *name = lrecord_implementations_table[i]->name; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4013 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4014 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
|
4015 lrecord_stats[i].bytes_in_use) |
|
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 sprintf (buf, "%s-storage-including-overhead", name); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4018 pl = gc_plist_hack (buf, |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4019 lrecord_stats[i] |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4020 .bytes_in_use_including_overhead, |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4021 pl); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4022 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4023 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4024 sprintf (buf, "%s-storage", name); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4025 pl = gc_plist_hack (buf, |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4026 lrecord_stats[i].bytes_in_use, |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4027 pl); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4028 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
|
4029 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4030 pluralize_and_append (buf, name, "-used"); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4031 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
|
4032 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4033 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4034 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4035 #else /* not NEW_GC */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4036 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4037 for (i = 0; i < lrecord_type_count; i++) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4038 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4039 if (lrecord_stats[i].bytes_in_use != 0 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4040 || lrecord_stats[i].bytes_freed != 0 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4041 || lrecord_stats[i].instances_on_free_list != 0) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4042 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4043 Ascbyte buf[255]; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4044 const Ascbyte *name = lrecord_implementations_table[i]->name; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4045 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4046 sprintf (buf, "%s-storage-overhead", name); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4047 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
|
4048 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
|
4049 sprintf (buf, "%s-storage", name); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4050 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
|
4051 tgu_val += lrecord_stats[i].bytes_in_use; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4052 #ifdef MEMORY_USAGE_STATS |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4053 if (lrecord_stats[i].nonlisp_bytes_in_use) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4054 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4055 sprintf (buf, "%s-non-lisp-storage", name); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4056 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
|
4057 pl); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4058 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
|
4059 } |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4060 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
|
4061 { |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4062 sprintf (buf, "%s-lisp-ancillary-storage", name); |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4063 pl = gc_plist_hack (buf, lrecord_stats[i]. |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4064 lisp_ancillary_bytes_in_use, |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4065 pl); |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4066 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
|
4067 } |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4068 #endif /* MEMORY_USAGE_STATS */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4069 pluralize_and_append (buf, name, "-freed"); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4070 if (lrecord_stats[i].instances_freed != 0) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4071 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
|
4072 pluralize_and_append (buf, name, "-on-free-list"); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4073 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
|
4074 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
|
4075 pl); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4076 pluralize_and_append (buf, name, "-used"); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4077 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
|
4078 } |
|
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 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4081 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
|
4082 gc_count_long_string_storage_including_overhead - |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4083 (gc_count_string_total_size |
|
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-string-chars-storage", |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4086 gc_count_string_total_size |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4087 - gc_count_short_string_total_size, pl); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4088 do |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4089 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4090 COUNT_FROB_BLOCK_USAGE (string_chars); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4091 tgu_val += s + s_overhead; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4092 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
|
4093 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
|
4094 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4095 while (0); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4096 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4097 pl = gc_plist_hack ("long-strings-total-length", |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4098 gc_count_string_total_size |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4099 - gc_count_short_string_total_size, pl); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4100 pl = gc_plist_hack ("short-strings-total-length", |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4101 gc_count_short_string_total_size, pl); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4102 pl = gc_plist_hack ("long-strings-used", |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4103 gc_count_num_string_in_use |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4104 - gc_count_num_short_string_in_use, pl); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4105 pl = gc_plist_hack ("short-strings-used", |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4106 gc_count_num_short_string_in_use, pl); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4107 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4108 #endif /* NEW_GC */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4109 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4110 if (set_total_gc_usage) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4111 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4112 total_gc_usage = tgu_val; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4113 total_gc_usage_set = 1; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4114 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4115 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4116 return pl; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4117 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4118 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4119 static Lisp_Object |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4120 garbage_collection_statistics (void) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4121 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4122 /* The things we do for backwards-compatibility */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4123 #ifdef 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 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4126 (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
|
4127 make_int (lrecord_stats[lrecord_type_cons] |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4128 .bytes_in_use_including_overhead)), |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4129 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
|
4130 make_int (lrecord_stats[lrecord_type_symbol] |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4131 .bytes_in_use_including_overhead)), |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4132 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
|
4133 make_int (lrecord_stats[lrecord_type_marker] |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4134 .bytes_in_use_including_overhead)), |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4135 make_int (lrecord_stats[lrecord_type_string] |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4136 .bytes_in_use_including_overhead), |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4137 make_int (lrecord_stats[lrecord_type_vector] |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4138 .bytes_in_use_including_overhead), |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4139 object_memory_usage_stats (1)); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4140 #else /* not NEW_GC */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4141 return |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4142 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
|
4143 make_int (gc_count_num_cons_freelist)), |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4144 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
|
4145 make_int (gc_count_num_symbol_freelist)), |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4146 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
|
4147 make_int (gc_count_num_marker_freelist)), |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4148 make_int (gc_count_string_total_size), |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4149 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
|
4150 lrecord_stats[lrecord_type_vector].bytes_freed + |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4151 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
|
4152 object_memory_usage_stats (1)); |
| 3263 | 4153 #endif /* not NEW_GC */ |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4154 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4155 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4156 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
|
4157 Return statistics about memory usage of Lisp objects. |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4158 */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4159 ()) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4160 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4161 return object_memory_usage_stats (0); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4162 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4163 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4164 #endif /* ALLOC_TYPE_STATS */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4165 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4166 #ifdef MEMORY_USAGE_STATS |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4167 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4168 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
|
4169 Return stats about the memory usage of OBJECT. |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4170 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
|
4171 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
|
4172 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
|
4173 other object), including internal structures and any malloc() |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4174 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
|
4175 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
|
4176 \(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
|
4177 X server). |
|
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 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
|
4180 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
|
4181 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
|
4182 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
|
4183 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
|
4184 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
|
4185 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4186 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
|
4187 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
|
4188 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
|
4189 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4190 #### 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
|
4191 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
|
4192 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
|
4193 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
|
4194 itself. |
|
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 (object)) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4197 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4198 struct generic_usage_stats gustats; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4199 struct usage_stats object_stats; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4200 int i; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4201 Lisp_Object val = Qnil; |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4202 Lisp_Object stats_list; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4203 |
|
5179
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4204 if (!LRECORDP (object)) |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4205 invalid_argument |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4206 ("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
|
4207 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4208 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
|
4209 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4210 xzero (object_stats); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4211 lisp_object_storage_size (object, &object_stats); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4212 |
|
5354
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
4213 val = Facons (Qobject_actually_requested, |
|
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
4214 make_int (object_stats.was_requested), val); |
|
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
4215 val = Facons (Qobject_malloc_overhead, |
|
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
4216 make_int (object_stats.malloc_overhead), val); |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4217 assert (!object_stats.dynarr_overhead); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4218 assert (!object_stats.gap_overhead); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4219 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4220 if (!NILP (stats_list)) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4221 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4222 xzero (gustats); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4223 MAYBE_OBJECT_METH (object, memory_usage, (object, &gustats)); |
|
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 val = Fcons (Qt, val); |
|
5354
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
4226 val = Facons (Qother_memory_actually_requested, |
|
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
4227 make_int (gustats.u.was_requested), val); |
|
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
4228 val = Facons (Qother_memory_malloc_overhead, |
|
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
4229 make_int (gustats.u.malloc_overhead), val); |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4230 if (gustats.u.dynarr_overhead) |
|
5354
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
4231 val = Facons (Qother_memory_dynarr_overhead, |
|
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
4232 make_int (gustats.u.dynarr_overhead), val); |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4233 if (gustats.u.gap_overhead) |
|
5354
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
4234 val = Facons (Qother_memory_gap_overhead, |
|
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
4235 make_int (gustats.u.gap_overhead), val); |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4236 val = Fcons (Qnil, 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 i = 0; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4239 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4240 LIST_LOOP_2 (item, stats_list) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4241 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4242 if (NILP (item) || EQ (item, Qt)) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4243 val = Fcons (item, val); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4244 else |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4245 { |
|
5354
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
4246 val = Facons (item, make_int (gustats.othervals[i]), val); |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4247 i++; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4248 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4249 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4250 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4251 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4252 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4253 return Fnreverse (val); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4254 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4255 |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4256 /* 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
|
4257 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4258 (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
|
4259 (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
|
4260 to the object |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4261 (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
|
4262 to the object |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4263 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4264 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
|
4265 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
|
4266 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
|
4267 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4268 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
|
4269 memory associated with the ancillary Lisp objects. |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4270 */ |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4271 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4272 Bytecount |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4273 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
|
4274 Bytecount *extra_nonlisp_storage, |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4275 Bytecount *extra_lisp_ancillary_storage, |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4276 struct generic_usage_stats *stats) |
|
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 Bytecount total; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4279 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4280 total = lisp_object_storage_size (object, NULL); |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4281 if (storage_size) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4282 *storage_size = total; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4283 |
|
5179
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4284 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
|
4285 { |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4286 int i; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4287 struct generic_usage_stats gustats; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4288 Bytecount sum; |
|
5179
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4289 struct lrecord_implementation *imp = |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4290 XRECORD_LHEADER_IMPLEMENTATION (object); |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4291 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4292 xzero (gustats); |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4293 OBJECT_METH (object, memory_usage, (object, &gustats)); |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4294 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4295 if (stats) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4296 *stats = gustats; |
|
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 sum = 0; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4299 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
|
4300 sum += gustats.othervals[i]; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4301 total += sum; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4302 if (extra_nonlisp_storage) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4303 *extra_nonlisp_storage = sum; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4304 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4305 sum = 0; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4306 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
|
4307 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
|
4308 i]; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4309 total += sum; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4310 if (extra_lisp_ancillary_storage) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4311 *extra_lisp_ancillary_storage = sum; |
|
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 else |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4314 { |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4315 if (extra_nonlisp_storage) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4316 *extra_nonlisp_storage = 0; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4317 if (extra_lisp_ancillary_storage) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4318 *extra_lisp_ancillary_storage = 0; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4319 } |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4320 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4321 return total; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4322 } |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4323 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4324 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4325 Bytecount |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4326 lisp_object_memory_usage (Lisp_Object object) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4327 { |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4328 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
|
4329 } |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4330 |
|
5179
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4331 static Bytecount |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4332 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
|
4333 { |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4334 Bytecount total = 0; |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4335 |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4336 if (depth > 200) |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4337 return total; |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4338 |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4339 if (CONSP (arg)) |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4340 { |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4341 SAFE_LIST_LOOP_3 (elt, arg, tail) |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4342 { |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4343 total += lisp_object_memory_usage (tail); |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4344 if (CONSP (elt) || VECTORP (elt)) |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4345 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
|
4346 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
|
4347 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
|
4348 } |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4349 } |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4350 else if (VECTORP (arg) && vectorp) |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4351 { |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4352 int i = XVECTOR_LENGTH (arg); |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4353 int j; |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4354 total += lisp_object_memory_usage (arg); |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4355 for (j = 0; j < i; j++) |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4356 { |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4357 Lisp_Object elt = XVECTOR_DATA (arg) [j]; |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4358 if (CONSP (elt) || VECTORP (elt)) |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4359 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
|
4360 } |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4361 } |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4362 return total; |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4363 } |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4364 |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4365 Bytecount |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4366 tree_memory_usage (Lisp_Object arg, int vectorp) |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4367 { |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4368 return tree_memory_usage_1 (arg, vectorp, 0); |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4369 } |
|
14fda1dbdb26
add memory usage info for specifiers
Ben Wing <ben@xemacs.org>
parents:
5172
diff
changeset
|
4370 |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4371 #endif /* MEMORY_USAGE_STATS */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4372 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4373 #ifdef ALLOC_TYPE_STATS |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4374 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4375 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
|
4376 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
|
4377 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
|
4378 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
|
4379 */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4380 ()) |
|
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 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
|
4383 } |
|
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 #endif /* ALLOC_TYPE_STATS */ |
|
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 |
|
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 /* Allocation statistics: Initialization */ |
|
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 #ifdef MEMORY_USAGE_STATS |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4392 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4393 /* 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
|
4394 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
|
4395 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
|
4396 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
|
4397 after all objects have been initialized. */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4398 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4399 static void |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4400 compute_memusage_stats_length (void) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4401 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4402 int i; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4403 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4404 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
|
4405 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4406 struct lrecord_implementation *imp = lrecord_implementations_table[i]; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4407 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4408 if (!imp) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4409 continue; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4410 /* 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
|
4411 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
|
4412 Fix that now. */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4413 if (EQ (imp->memusage_stats_list, Qnull_pointer)) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4414 imp->memusage_stats_list = Qnil; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4415 { |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4416 Elemcount len = 0; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4417 Elemcount nonlisp_len = 0; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4418 Elemcount lisp_len = 0; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4419 Elemcount lisp_offset = 0; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4420 int group_num = 0; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4421 int slice_num = 0; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4422 |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4423 LIST_LOOP_2 (item, imp->memusage_stats_list) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4424 { |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4425 if (EQ (item, Qt)) |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4426 { |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4427 group_num++; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4428 if (group_num == 1) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4429 lisp_offset = len; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4430 slice_num = 0; |
|
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 else if (EQ (item, Qnil)) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4433 { |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4434 slice_num++; |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4435 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4436 else |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4437 { |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4438 if (slice_num == 0) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4439 { |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4440 if (group_num == 0) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4441 nonlisp_len++; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4442 else if (group_num == 1) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4443 lisp_len++; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4444 } |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4445 len++; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4446 } |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4447 } |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4448 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4449 imp->num_extra_memusage_stats = len; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4450 imp->num_extra_nonlisp_memusage_stats = nonlisp_len; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5167
diff
changeset
|
4451 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
|
4452 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
|
4453 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4454 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4455 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4456 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
4457 #endif /* MEMORY_USAGE_STATS */ |
| 428 | 4458 |
| 4459 | |
|
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
4460 /************************************************************************/ |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
4461 /* Garbage Collection -- Sweep/Compact */ |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
4462 /************************************************************************/ |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
4463 |
| 3263 | 4464 #ifndef NEW_GC |
| 428 | 4465 /* Free all unmarked records */ |
| 4466 static void | |
| 3024 | 4467 sweep_lcrecords_1 (struct old_lcrecord_header **prev, int *used) |
| 4468 { | |
| 4469 struct old_lcrecord_header *header; | |
| 428 | 4470 int num_used = 0; |
| 4471 /* int total_size = 0; */ | |
| 4472 | |
| 4473 /* First go through and call all the finalize methods. | |
| 4474 Then go through and free the objects. There used to | |
| 4475 be only one loop here, with the call to the finalizer | |
| 4476 occurring directly before the xfree() below. That | |
| 4477 is marginally faster but much less safe -- if the | |
| 4478 finalize method for an object needs to reference any | |
| 4479 other objects contained within it (and many do), | |
| 4480 we could easily be screwed by having already freed that | |
| 4481 other object. */ | |
| 4482 | |
| 4483 for (header = *prev; header; header = header->next) | |
| 4484 { | |
| 4485 struct lrecord_header *h = &(header->lheader); | |
| 442 | 4486 |
| 4487 GC_CHECK_LHEADER_INVARIANTS (h); | |
| 4488 | |
|
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
4489 if (! MARKED_RECORD_HEADER_P (h) && !h->free) |
| 428 | 4490 { |
| 4491 if (LHEADER_IMPLEMENTATION (h)->finalizer) | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
4492 LHEADER_IMPLEMENTATION (h)->finalizer (wrap_pointer_1 (h)); |
| 428 | 4493 } |
| 4494 } | |
| 4495 | |
| 4496 for (header = *prev; header; ) | |
| 4497 { | |
| 4498 struct lrecord_header *h = &(header->lheader); | |
| 442 | 4499 if (MARKED_RECORD_HEADER_P (h)) |
| 428 | 4500 { |
| 442 | 4501 if (! C_READONLY_RECORD_HEADER_P (h)) |
| 428 | 4502 UNMARK_RECORD_HEADER (h); |
| 4503 num_used++; | |
| 4504 /* total_size += n->implementation->size_in_bytes (h);*/ | |
| 440 | 4505 /* #### May modify header->next on a C_READONLY lcrecord */ |
| 428 | 4506 prev = &(header->next); |
| 4507 header = *prev; | |
| 4508 tick_lcrecord_stats (h, 0); | |
| 4509 } | |
| 4510 else | |
| 4511 { | |
| 3024 | 4512 struct old_lcrecord_header *next = header->next; |
| 428 | 4513 *prev = next; |
| 4514 tick_lcrecord_stats (h, 1); | |
| 4515 /* used to call finalizer right here. */ | |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
4516 xfree (header); |
| 428 | 4517 header = next; |
| 4518 } | |
| 4519 } | |
| 4520 *used = num_used; | |
| 4521 /* *total = total_size; */ | |
| 4522 } | |
| 4523 | |
| 4524 /* And the Lord said: Thou shalt use the `c-backslash-region' command | |
| 4525 to make macros prettier. */ | |
| 4526 | |
| 4527 #ifdef ERROR_CHECK_GC | |
| 4528 | |
| 771 | 4529 #define SWEEP_FIXED_TYPE_BLOCK_1(typename, obj_type, lheader) \ |
| 428 | 4530 do { \ |
| 4531 struct typename##_block *SFTB_current; \ | |
| 4532 int SFTB_limit; \ | |
| 4533 int num_free = 0, num_used = 0; \ | |
| 4534 \ | |
| 444 | 4535 for (SFTB_current = current_##typename##_block, \ |
| 428 | 4536 SFTB_limit = current_##typename##_block_index; \ |
| 4537 SFTB_current; \ | |
| 4538 ) \ | |
| 4539 { \ | |
| 4540 int SFTB_iii; \ | |
| 4541 \ | |
| 4542 for (SFTB_iii = 0; SFTB_iii < SFTB_limit; SFTB_iii++) \ | |
| 4543 { \ | |
| 4544 obj_type *SFTB_victim = &(SFTB_current->block[SFTB_iii]); \ | |
| 4545 \ | |
| 454 | 4546 if (LRECORD_FREE_P (SFTB_victim)) \ |
| 428 | 4547 { \ |
| 4548 num_free++; \ | |
| 4549 } \ | |
| 4550 else if (C_READONLY_RECORD_HEADER_P (&SFTB_victim->lheader)) \ | |
| 4551 { \ | |
| 4552 num_used++; \ | |
| 4553 } \ | |
| 442 | 4554 else if (! MARKED_RECORD_HEADER_P (&SFTB_victim->lheader)) \ |
| 428 | 4555 { \ |
| 4556 num_free++; \ | |
| 4557 FREE_FIXED_TYPE (typename, obj_type, SFTB_victim); \ | |
| 4558 } \ | |
| 4559 else \ | |
| 4560 { \ | |
| 4561 num_used++; \ | |
| 4562 UNMARK_##typename (SFTB_victim); \ | |
| 4563 } \ | |
| 4564 } \ | |
| 4565 SFTB_current = SFTB_current->prev; \ | |
| 4566 SFTB_limit = countof (current_##typename##_block->block); \ | |
| 4567 } \ | |
| 4568 \ | |
| 4569 gc_count_num_##typename##_in_use = num_used; \ | |
| 4570 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
|
4571 COPY_INTO_LRECORD_STATS (typename); \ |
| 428 | 4572 } while (0) |
| 4573 | |
| 4574 #else /* !ERROR_CHECK_GC */ | |
| 4575 | |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4576 #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
|
4577 do { \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4578 struct typename##_block *SFTB_current; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4579 struct typename##_block **SFTB_prev; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4580 int SFTB_limit; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4581 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
|
4582 \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4583 typename##_free_list = 0; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4584 \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4585 for (SFTB_prev = ¤t_##typename##_block, \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4586 SFTB_current = current_##typename##_block, \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4587 SFTB_limit = current_##typename##_block_index; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4588 SFTB_current; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4589 ) \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4590 { \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4591 int SFTB_iii; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4592 int SFTB_empty = 1; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4593 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
|
4594 \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4595 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
|
4596 { \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4597 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
|
4598 \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4599 if (LRECORD_FREE_P (SFTB_victim)) \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4600 { \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4601 num_free++; \ |
| 771 | 4602 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
|
4603 } \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4604 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
|
4605 { \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4606 SFTB_empty = 0; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4607 num_used++; \ |
|
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 (! 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
|
4610 { \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4611 num_free++; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4612 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
|
4613 } \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4614 else \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4615 { \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4616 SFTB_empty = 0; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4617 num_used++; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4618 UNMARK_##typename (SFTB_victim); \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4619 } \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4620 } \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4621 if (!SFTB_empty) \ |
|
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->prev); \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4624 SFTB_current = SFTB_current->prev; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4625 } \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4626 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
|
4627 && !SFTB_current->prev) \ |
|
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 /* 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
|
4630 break; \ |
|
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 else \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4633 { \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4634 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
|
4635 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
|
4636 current_##typename##_block_index \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4637 = countof (current_##typename##_block->block); \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4638 SFTB_current = SFTB_current->prev; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4639 { \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4640 *SFTB_prev = SFTB_current; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4641 xfree (SFTB_victim_block); \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4642 /* 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
|
4643 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
|
4644 num_free -= SFTB_limit; \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4645 } \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4646 } \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4647 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
|
4648 } \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4649 \ |
|
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4650 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
|
4651 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
|
4652 COPY_INTO_LRECORD_STATS (typename); \ |
| 428 | 4653 } while (0) |
| 4654 | |
| 4655 #endif /* !ERROR_CHECK_GC */ | |
| 4656 | |
| 771 | 4657 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \ |
| 4658 SWEEP_FIXED_TYPE_BLOCK_1 (typename, obj_type, lheader) | |
| 4659 | |
| 3263 | 4660 #endif /* not NEW_GC */ |
| 2720 | 4661 |
| 428 | 4662 |
| 3263 | 4663 #ifndef NEW_GC |
| 428 | 4664 static void |
| 4665 sweep_conses (void) | |
| 4666 { | |
| 4667 #define UNMARK_cons(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4668 #define ADDITIONAL_FREE_cons(ptr) | |
| 4669 | |
| 440 | 4670 SWEEP_FIXED_TYPE_BLOCK (cons, Lisp_Cons); |
| 428 | 4671 } |
| 3263 | 4672 #endif /* not NEW_GC */ |
| 428 | 4673 |
| 4674 /* Explicitly free a cons cell. */ | |
| 4675 void | |
| 853 | 4676 free_cons (Lisp_Object cons) |
| 428 | 4677 { |
| 3263 | 4678 #ifndef NEW_GC /* to avoid compiler warning */ |
| 853 | 4679 Lisp_Cons *ptr = XCONS (cons); |
| 3263 | 4680 #endif /* not NEW_GC */ |
| 853 | 4681 |
| 428 | 4682 #ifdef ERROR_CHECK_GC |
| 3263 | 4683 #ifdef NEW_GC |
| 2720 | 4684 Lisp_Cons *ptr = XCONS (cons); |
| 3263 | 4685 #endif /* NEW_GC */ |
| 428 | 4686 /* If the CAR is not an int, then it will be a pointer, which will |
| 4687 always be four-byte aligned. If this cons cell has already been | |
| 4688 placed on the free list, however, its car will probably contain | |
| 4689 a chain pointer to the next cons on the list, which has cleverly | |
| 4690 had all its 0's and 1's inverted. This allows for a quick | |
| 1204 | 4691 check to make sure we're not freeing something already freed. |
| 4692 | |
| 4693 NOTE: This check may not be necessary. Freeing an object sets its | |
| 4694 type to lrecord_type_free, which will trip up the XCONS() above -- as | |
| 4695 well as a check in FREE_FIXED_TYPE(). */ | |
| 853 | 4696 if (POINTER_TYPE_P (XTYPE (cons_car (ptr)))) |
| 4697 ASSERT_VALID_POINTER (XPNTR (cons_car (ptr))); | |
| 428 | 4698 #endif /* ERROR_CHECK_GC */ |
| 4699 | |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4700 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (cons, cons, Lisp_Cons, ptr); |
| 428 | 4701 } |
| 4702 | |
| 4703 /* explicitly free a list. You **must make sure** that you have | |
| 4704 created all the cons cells that make up this list 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_list (Lisp_Object list) | |
| 4710 { | |
| 4711 Lisp_Object rest, next; | |
| 4712 | |
| 4713 for (rest = list; !NILP (rest); rest = next) | |
| 4714 { | |
| 4715 next = XCDR (rest); | |
| 853 | 4716 free_cons (rest); |
| 428 | 4717 } |
| 4718 } | |
| 4719 | |
| 4720 /* explicitly free an alist. You **must make sure** that you have | |
| 4721 created all the cons cells that make up this alist and that there | |
| 4722 are no pointers to any of these cons cells anywhere else. If there | |
| 4723 are, you will lose. */ | |
| 4724 | |
| 4725 void | |
| 4726 free_alist (Lisp_Object alist) | |
| 4727 { | |
| 4728 Lisp_Object rest, next; | |
| 4729 | |
| 4730 for (rest = alist; !NILP (rest); rest = next) | |
| 4731 { | |
| 4732 next = XCDR (rest); | |
| 853 | 4733 free_cons (XCAR (rest)); |
| 4734 free_cons (rest); | |
| 428 | 4735 } |
| 4736 } | |
| 4737 | |
| 3263 | 4738 #ifndef NEW_GC |
| 428 | 4739 static void |
| 4740 sweep_compiled_functions (void) | |
| 4741 { | |
| 4742 #define UNMARK_compiled_function(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 945 | 4743 #define ADDITIONAL_FREE_compiled_function(ptr) \ |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
4744 if (ptr->args_in_array) xfree (ptr->args) |
| 428 | 4745 |
| 4746 SWEEP_FIXED_TYPE_BLOCK (compiled_function, Lisp_Compiled_Function); | |
| 4747 } | |
| 4748 | |
| 4749 static void | |
| 4750 sweep_floats (void) | |
| 4751 { | |
| 4752 #define UNMARK_float(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4753 #define ADDITIONAL_FREE_float(ptr) | |
| 4754 | |
| 440 | 4755 SWEEP_FIXED_TYPE_BLOCK (float, Lisp_Float); |
| 428 | 4756 } |
| 4757 | |
| 1983 | 4758 #ifdef HAVE_BIGNUM |
| 4759 static void | |
| 4760 sweep_bignums (void) | |
| 4761 { | |
| 4762 #define UNMARK_bignum(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4763 #define ADDITIONAL_FREE_bignum(ptr) bignum_fini (ptr->data) | |
| 4764 | |
| 4765 SWEEP_FIXED_TYPE_BLOCK (bignum, Lisp_Bignum); | |
| 4766 } | |
| 4767 #endif /* HAVE_BIGNUM */ | |
| 4768 | |
| 4769 #ifdef HAVE_RATIO | |
| 4770 static void | |
| 4771 sweep_ratios (void) | |
| 4772 { | |
| 4773 #define UNMARK_ratio(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4774 #define ADDITIONAL_FREE_ratio(ptr) ratio_fini (ptr->data) | |
| 4775 | |
| 4776 SWEEP_FIXED_TYPE_BLOCK (ratio, Lisp_Ratio); | |
| 4777 } | |
| 4778 #endif /* HAVE_RATIO */ | |
| 4779 | |
| 4780 #ifdef HAVE_BIGFLOAT | |
| 4781 static void | |
| 4782 sweep_bigfloats (void) | |
| 4783 { | |
| 4784 #define UNMARK_bigfloat(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4785 #define ADDITIONAL_FREE_bigfloat(ptr) bigfloat_fini (ptr->bf) | |
| 4786 | |
| 4787 SWEEP_FIXED_TYPE_BLOCK (bigfloat, Lisp_Bigfloat); | |
| 4788 } | |
| 4789 #endif | |
| 4790 | |
| 428 | 4791 static void |
| 4792 sweep_symbols (void) | |
| 4793 { | |
| 4794 #define UNMARK_symbol(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4795 #define ADDITIONAL_FREE_symbol(ptr) | |
| 4796 | |
| 440 | 4797 SWEEP_FIXED_TYPE_BLOCK (symbol, Lisp_Symbol); |
| 428 | 4798 } |
| 4799 | |
| 4800 static void | |
| 4801 sweep_extents (void) | |
| 4802 { | |
| 4803 #define UNMARK_extent(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4804 #define ADDITIONAL_FREE_extent(ptr) | |
| 4805 | |
| 4806 SWEEP_FIXED_TYPE_BLOCK (extent, struct extent); | |
| 4807 } | |
| 4808 | |
| 4809 static void | |
| 4810 sweep_events (void) | |
| 4811 { | |
| 4812 #define UNMARK_event(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4813 #define ADDITIONAL_FREE_event(ptr) | |
| 4814 | |
| 440 | 4815 SWEEP_FIXED_TYPE_BLOCK (event, Lisp_Event); |
| 428 | 4816 } |
| 3263 | 4817 #endif /* not NEW_GC */ |
| 428 | 4818 |
| 1204 | 4819 #ifdef EVENT_DATA_AS_OBJECTS |
| 934 | 4820 |
| 3263 | 4821 #ifndef NEW_GC |
| 934 | 4822 static void |
| 4823 sweep_key_data (void) | |
| 4824 { | |
| 4825 #define UNMARK_key_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4826 #define ADDITIONAL_FREE_key_data(ptr) | |
| 4827 | |
| 4828 SWEEP_FIXED_TYPE_BLOCK (key_data, Lisp_Key_Data); | |
| 4829 } | |
| 3263 | 4830 #endif /* not NEW_GC */ |
| 934 | 4831 |
| 1204 | 4832 void |
| 4833 free_key_data (Lisp_Object ptr) | |
| 4834 { | |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4835 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
|
4836 XKEY_DATA (ptr)); |
| 2720 | 4837 } |
| 4838 | |
| 3263 | 4839 #ifndef NEW_GC |
| 934 | 4840 static void |
| 4841 sweep_button_data (void) | |
| 4842 { | |
| 4843 #define UNMARK_button_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4844 #define ADDITIONAL_FREE_button_data(ptr) | |
| 4845 | |
| 4846 SWEEP_FIXED_TYPE_BLOCK (button_data, Lisp_Button_Data); | |
| 4847 } | |
| 3263 | 4848 #endif /* not NEW_GC */ |
| 934 | 4849 |
| 1204 | 4850 void |
| 4851 free_button_data (Lisp_Object ptr) | |
| 4852 { | |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4853 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
|
4854 XBUTTON_DATA (ptr)); |
| 2720 | 4855 } |
| 4856 | |
| 3263 | 4857 #ifndef NEW_GC |
| 934 | 4858 static void |
| 4859 sweep_motion_data (void) | |
| 4860 { | |
| 4861 #define UNMARK_motion_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4862 #define ADDITIONAL_FREE_motion_data(ptr) | |
| 4863 | |
| 4864 SWEEP_FIXED_TYPE_BLOCK (motion_data, Lisp_Motion_Data); | |
| 4865 } | |
| 3263 | 4866 #endif /* not NEW_GC */ |
| 934 | 4867 |
| 1204 | 4868 void |
| 4869 free_motion_data (Lisp_Object ptr) | |
| 4870 { | |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4871 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
|
4872 XMOTION_DATA (ptr)); |
| 2720 | 4873 } |
| 4874 | |
| 3263 | 4875 #ifndef NEW_GC |
| 934 | 4876 static void |
| 4877 sweep_process_data (void) | |
| 4878 { | |
| 4879 #define UNMARK_process_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4880 #define ADDITIONAL_FREE_process_data(ptr) | |
| 4881 | |
| 4882 SWEEP_FIXED_TYPE_BLOCK (process_data, Lisp_Process_Data); | |
| 4883 } | |
| 3263 | 4884 #endif /* not NEW_GC */ |
| 934 | 4885 |
| 1204 | 4886 void |
| 4887 free_process_data (Lisp_Object ptr) | |
| 4888 { | |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4889 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
|
4890 XPROCESS_DATA (ptr)); |
| 2720 | 4891 } |
| 4892 | |
| 3263 | 4893 #ifndef NEW_GC |
| 934 | 4894 static void |
| 4895 sweep_timeout_data (void) | |
| 4896 { | |
| 4897 #define UNMARK_timeout_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4898 #define ADDITIONAL_FREE_timeout_data(ptr) | |
| 4899 | |
| 4900 SWEEP_FIXED_TYPE_BLOCK (timeout_data, Lisp_Timeout_Data); | |
| 4901 } | |
| 3263 | 4902 #endif /* not NEW_GC */ |
| 934 | 4903 |
| 1204 | 4904 void |
| 4905 free_timeout_data (Lisp_Object ptr) | |
| 4906 { | |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4907 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
|
4908 XTIMEOUT_DATA (ptr)); |
| 2720 | 4909 } |
| 4910 | |
| 3263 | 4911 #ifndef NEW_GC |
| 934 | 4912 static void |
| 4913 sweep_magic_data (void) | |
| 4914 { | |
| 4915 #define UNMARK_magic_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4916 #define ADDITIONAL_FREE_magic_data(ptr) | |
| 4917 | |
| 4918 SWEEP_FIXED_TYPE_BLOCK (magic_data, Lisp_Magic_Data); | |
| 4919 } | |
| 3263 | 4920 #endif /* not NEW_GC */ |
| 934 | 4921 |
| 1204 | 4922 void |
| 4923 free_magic_data (Lisp_Object ptr) | |
| 4924 { | |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4925 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
|
4926 XMAGIC_DATA (ptr)); |
| 2720 | 4927 } |
| 4928 | |
| 3263 | 4929 #ifndef NEW_GC |
| 934 | 4930 static void |
| 4931 sweep_magic_eval_data (void) | |
| 4932 { | |
| 4933 #define UNMARK_magic_eval_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4934 #define ADDITIONAL_FREE_magic_eval_data(ptr) | |
| 4935 | |
| 4936 SWEEP_FIXED_TYPE_BLOCK (magic_eval_data, Lisp_Magic_Eval_Data); | |
| 4937 } | |
| 3263 | 4938 #endif /* not NEW_GC */ |
| 934 | 4939 |
| 1204 | 4940 void |
| 4941 free_magic_eval_data (Lisp_Object ptr) | |
| 4942 { | |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4943 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
|
4944 XMAGIC_EVAL_DATA (ptr)); |
| 2720 | 4945 } |
| 4946 | |
| 3263 | 4947 #ifndef NEW_GC |
| 934 | 4948 static void |
| 4949 sweep_eval_data (void) | |
| 4950 { | |
| 4951 #define UNMARK_eval_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4952 #define ADDITIONAL_FREE_eval_data(ptr) | |
| 4953 | |
| 4954 SWEEP_FIXED_TYPE_BLOCK (eval_data, Lisp_Eval_Data); | |
| 4955 } | |
| 3263 | 4956 #endif /* not NEW_GC */ |
| 934 | 4957 |
| 1204 | 4958 void |
| 4959 free_eval_data (Lisp_Object ptr) | |
| 4960 { | |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4961 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
|
4962 XEVAL_DATA (ptr)); |
| 2720 | 4963 } |
| 4964 | |
| 3263 | 4965 #ifndef NEW_GC |
| 934 | 4966 static void |
| 4967 sweep_misc_user_data (void) | |
| 4968 { | |
| 4969 #define UNMARK_misc_user_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4970 #define ADDITIONAL_FREE_misc_user_data(ptr) | |
| 4971 | |
| 4972 SWEEP_FIXED_TYPE_BLOCK (misc_user_data, Lisp_Misc_User_Data); | |
| 4973 } | |
| 3263 | 4974 #endif /* not NEW_GC */ |
| 934 | 4975 |
| 1204 | 4976 void |
| 4977 free_misc_user_data (Lisp_Object ptr) | |
| 4978 { | |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
4979 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
|
4980 XMISC_USER_DATA (ptr)); |
| 1204 | 4981 } |
| 4982 | |
| 4983 #endif /* EVENT_DATA_AS_OBJECTS */ | |
| 934 | 4984 |
| 3263 | 4985 #ifndef NEW_GC |
| 428 | 4986 static void |
| 4987 sweep_markers (void) | |
| 4988 { | |
| 4989 #define UNMARK_marker(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
| 4990 #define ADDITIONAL_FREE_marker(ptr) \ | |
| 4991 do { Lisp_Object tem; \ | |
| 793 | 4992 tem = wrap_marker (ptr); \ |
| 428 | 4993 unchain_marker (tem); \ |
| 4994 } while (0) | |
| 4995 | |
| 440 | 4996 SWEEP_FIXED_TYPE_BLOCK (marker, Lisp_Marker); |
| 428 | 4997 } |
| 3263 | 4998 #endif /* not NEW_GC */ |
| 428 | 4999 |
| 5000 /* Explicitly free a marker. */ | |
| 5001 void | |
| 1204 | 5002 free_marker (Lisp_Object ptr) |
| 428 | 5003 { |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
5004 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (ptr, marker, Lisp_Marker, XMARKER (ptr)); |
| 428 | 5005 } |
| 5006 | |
| 5007 | |
| 5008 #if defined (MULE) && defined (VERIFY_STRING_CHARS_INTEGRITY) | |
| 5009 | |
| 5010 static void | |
| 5011 verify_string_chars_integrity (void) | |
| 5012 { | |
| 5013 struct string_chars_block *sb; | |
| 5014 | |
| 5015 /* Scan each existing string block sequentially, string by string. */ | |
| 5016 for (sb = first_string_chars_block; sb; sb = sb->next) | |
| 5017 { | |
| 5018 int pos = 0; | |
| 5019 /* POS is the index of the next string in the block. */ | |
| 5020 while (pos < sb->pos) | |
| 5021 { | |
| 5022 struct string_chars *s_chars = | |
| 5023 (struct string_chars *) &(sb->string_chars[pos]); | |
| 438 | 5024 Lisp_String *string; |
| 428 | 5025 int size; |
| 5026 int fullsize; | |
| 5027 | |
| 454 | 5028 /* If the string_chars struct is marked as free (i.e. the |
| 5029 STRING pointer is NULL) then this is an unused chunk of | |
| 5030 string storage. (See below.) */ | |
| 5031 | |
| 5032 if (STRING_CHARS_FREE_P (s_chars)) | |
| 428 | 5033 { |
| 5034 fullsize = ((struct unused_string_chars *) s_chars)->fullsize; | |
| 5035 pos += fullsize; | |
| 5036 continue; | |
| 5037 } | |
| 5038 | |
| 5039 string = s_chars->string; | |
| 5040 /* Must be 32-bit aligned. */ | |
| 5041 assert ((((int) string) & 3) == 0); | |
| 5042 | |
| 793 | 5043 size = string->size_; |
| 428 | 5044 fullsize = STRING_FULLSIZE (size); |
| 5045 | |
| 5046 assert (!BIG_STRING_FULLSIZE_P (fullsize)); | |
| 2720 | 5047 assert (XSTRING_DATA (string) == s_chars->chars); |
| 428 | 5048 pos += fullsize; |
| 5049 } | |
| 5050 assert (pos == sb->pos); | |
| 5051 } | |
| 5052 } | |
| 5053 | |
| 1204 | 5054 #endif /* defined (MULE) && defined (VERIFY_STRING_CHARS_INTEGRITY) */ |
| 428 | 5055 |
| 3092 | 5056 #ifndef NEW_GC |
| 428 | 5057 /* Compactify string chars, relocating the reference to each -- |
| 5058 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
|
5059 static void |
| 428 | 5060 compact_string_chars (void) |
| 5061 { | |
| 5062 struct string_chars_block *to_sb = first_string_chars_block; | |
| 5063 int to_pos = 0; | |
| 5064 struct string_chars_block *from_sb; | |
| 5065 | |
| 5066 /* Scan each existing string block sequentially, string by string. */ | |
| 5067 for (from_sb = first_string_chars_block; from_sb; from_sb = from_sb->next) | |
| 5068 { | |
| 5069 int from_pos = 0; | |
| 5070 /* FROM_POS is the index of the next string in the block. */ | |
| 5071 while (from_pos < from_sb->pos) | |
| 5072 { | |
| 5073 struct string_chars *from_s_chars = | |
| 5074 (struct string_chars *) &(from_sb->string_chars[from_pos]); | |
| 5075 struct string_chars *to_s_chars; | |
| 438 | 5076 Lisp_String *string; |
| 428 | 5077 int size; |
| 5078 int fullsize; | |
| 5079 | |
| 454 | 5080 /* If the string_chars struct is marked as free (i.e. the |
| 5081 STRING pointer is NULL) then this is an unused chunk of | |
| 5082 string storage. This happens under Mule when a string's | |
| 5083 size changes in such a way that its fullsize changes. | |
| 5084 (Strings can change size because a different-length | |
| 5085 character can be substituted for another character.) | |
| 5086 In this case, after the bogus string pointer is the | |
| 5087 "fullsize" of this entry, i.e. how many bytes to skip. */ | |
| 5088 | |
| 5089 if (STRING_CHARS_FREE_P (from_s_chars)) | |
| 428 | 5090 { |
| 5091 fullsize = ((struct unused_string_chars *) from_s_chars)->fullsize; | |
| 5092 from_pos += fullsize; | |
| 5093 continue; | |
| 5094 } | |
| 5095 | |
| 5096 string = from_s_chars->string; | |
| 1204 | 5097 gc_checking_assert (!(LRECORD_FREE_P (string))); |
| 428 | 5098 |
| 793 | 5099 size = string->size_; |
| 428 | 5100 fullsize = STRING_FULLSIZE (size); |
| 5101 | |
| 442 | 5102 gc_checking_assert (! BIG_STRING_FULLSIZE_P (fullsize)); |
| 428 | 5103 |
| 5104 /* Just skip it if it isn't marked. */ | |
| 771 | 5105 if (! MARKED_RECORD_HEADER_P (&(string->u.lheader))) |
| 428 | 5106 { |
| 5107 from_pos += fullsize; | |
| 5108 continue; | |
| 5109 } | |
| 5110 | |
| 5111 /* If it won't fit in what's left of TO_SB, close TO_SB out | |
| 5112 and go on to the next string_chars_block. We know that TO_SB | |
| 5113 cannot advance past FROM_SB here since FROM_SB is large enough | |
| 5114 to currently contain this string. */ | |
| 5115 if ((to_pos + fullsize) > countof (to_sb->string_chars)) | |
| 5116 { | |
| 5117 to_sb->pos = to_pos; | |
| 5118 to_sb = to_sb->next; | |
| 5119 to_pos = 0; | |
| 5120 } | |
| 5121 | |
| 5122 /* Compute new address of this string | |
| 5123 and update TO_POS for the space being used. */ | |
| 5124 to_s_chars = (struct string_chars *) &(to_sb->string_chars[to_pos]); | |
| 5125 | |
| 5126 /* Copy the string_chars to the new place. */ | |
| 5127 if (from_s_chars != to_s_chars) | |
| 5128 memmove (to_s_chars, from_s_chars, fullsize); | |
| 5129 | |
| 5130 /* Relocate FROM_S_CHARS's reference */ | |
| 826 | 5131 set_lispstringp_data (string, &(to_s_chars->chars[0])); |
| 428 | 5132 |
| 5133 from_pos += fullsize; | |
| 5134 to_pos += fullsize; | |
| 5135 } | |
| 5136 } | |
| 5137 | |
| 5138 /* Set current to the last string chars block still used and | |
| 5139 free any that follow. */ | |
| 5140 { | |
| 5141 struct string_chars_block *victim; | |
| 5142 | |
| 5143 for (victim = to_sb->next; victim; ) | |
| 5144 { | |
| 5145 struct string_chars_block *next = victim->next; | |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
5146 xfree (victim); |
| 428 | 5147 victim = next; |
| 5148 } | |
| 5149 | |
| 5150 current_string_chars_block = to_sb; | |
| 5151 current_string_chars_block->pos = to_pos; | |
| 5152 current_string_chars_block->next = 0; | |
| 5153 } | |
| 5154 } | |
| 3092 | 5155 #endif /* not NEW_GC */ |
| 428 | 5156 |
| 3263 | 5157 #ifndef NEW_GC |
| 428 | 5158 #if 1 /* Hack to debug missing purecopy's */ |
| 5159 static int debug_string_purity; | |
| 5160 | |
| 5161 static void | |
| 793 | 5162 debug_string_purity_print (Lisp_Object p) |
| 428 | 5163 { |
| 5164 Charcount i; | |
| 826 | 5165 Charcount s = string_char_length (p); |
| 442 | 5166 stderr_out ("\""); |
| 428 | 5167 for (i = 0; i < s; i++) |
| 5168 { | |
| 867 | 5169 Ichar ch = string_ichar (p, i); |
| 428 | 5170 if (ch < 32 || ch >= 126) |
| 5171 stderr_out ("\\%03o", ch); | |
| 5172 else if (ch == '\\' || ch == '\"') | |
| 5173 stderr_out ("\\%c", ch); | |
| 5174 else | |
| 5175 stderr_out ("%c", ch); | |
| 5176 } | |
| 5177 stderr_out ("\"\n"); | |
| 5178 } | |
| 5179 #endif /* 1 */ | |
| 3263 | 5180 #endif /* not NEW_GC */ |
| 5181 | |
| 5182 #ifndef NEW_GC | |
| 428 | 5183 static void |
| 5184 sweep_strings (void) | |
| 5185 { | |
| 5186 int debug = debug_string_purity; | |
| 5187 | |
| 793 | 5188 #define UNMARK_string(ptr) do { \ |
| 5189 Lisp_String *p = (ptr); \ | |
| 5190 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
|
5191 tick_string_stats (p, 1); \ |
| 793 | 5192 if (debug) \ |
| 5193 debug_string_purity_print (wrap_string (p)); \ | |
| 438 | 5194 } while (0) |
| 5195 #define ADDITIONAL_FREE_string(ptr) do { \ | |
| 793 | 5196 Bytecount size = ptr->size_; \ |
| 438 | 5197 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
|
5198 xfree (ptr->data_); \ |
| 438 | 5199 } while (0) |
| 5200 | |
| 771 | 5201 SWEEP_FIXED_TYPE_BLOCK_1 (string, Lisp_String, u.lheader); |
| 428 | 5202 } |
| 3263 | 5203 #endif /* not NEW_GC */ |
| 428 | 5204 |
| 3092 | 5205 #ifndef NEW_GC |
| 5206 void | |
| 5207 gc_sweep_1 (void) | |
| 428 | 5208 { |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
5209 /* 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
|
5210 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
|
5211 clear_lrecord_stats (); |
|
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
5058
diff
changeset
|
5212 |
| 428 | 5213 /* Free all unmarked records. Do this at the very beginning, |
| 5214 before anything else, so that the finalize methods can safely | |
| 5215 examine items in the objects. sweep_lcrecords_1() makes | |
| 5216 sure to call all the finalize methods *before* freeing anything, | |
| 5217 to complete the safety. */ | |
| 5218 { | |
| 5219 int ignored; | |
| 5220 sweep_lcrecords_1 (&all_lcrecords, &ignored); | |
| 5221 } | |
| 5222 | |
| 5223 compact_string_chars (); | |
| 5224 | |
| 5225 /* Finalize methods below (called through the ADDITIONAL_FREE_foo | |
| 5226 macros) must be *extremely* careful to make sure they're not | |
| 5227 referencing freed objects. The only two existing finalize | |
| 5228 methods (for strings and markers) pass muster -- the string | |
| 5229 finalizer doesn't look at anything but its own specially- | |
| 5230 created block, and the marker finalizer only looks at live | |
| 5231 buffers (which will never be freed) and at the markers before | |
| 5232 and after it in the chain (which, by induction, will never be | |
| 5233 freed because if so, they would have already removed themselves | |
| 5234 from the chain). */ | |
| 5235 | |
| 5236 /* Put all unmarked strings on free list, free'ing the string chars | |
| 5237 of large unmarked strings */ | |
| 5238 sweep_strings (); | |
| 5239 | |
| 5240 /* Put all unmarked conses on free list */ | |
| 5241 sweep_conses (); | |
| 5242 | |
| 5243 /* Free all unmarked compiled-function objects */ | |
| 5244 sweep_compiled_functions (); | |
| 5245 | |
| 5246 /* Put all unmarked floats on free list */ | |
| 5247 sweep_floats (); | |
| 5248 | |
| 1983 | 5249 #ifdef HAVE_BIGNUM |
| 5250 /* Put all unmarked bignums on free list */ | |
| 5251 sweep_bignums (); | |
| 5252 #endif | |
| 5253 | |
| 5254 #ifdef HAVE_RATIO | |
| 5255 /* Put all unmarked ratios on free list */ | |
| 5256 sweep_ratios (); | |
| 5257 #endif | |
| 5258 | |
| 5259 #ifdef HAVE_BIGFLOAT | |
| 5260 /* Put all unmarked bigfloats on free list */ | |
| 5261 sweep_bigfloats (); | |
| 5262 #endif | |
| 5263 | |
| 428 | 5264 /* Put all unmarked symbols on free list */ |
| 5265 sweep_symbols (); | |
| 5266 | |
| 5267 /* Put all unmarked extents on free list */ | |
| 5268 sweep_extents (); | |
| 5269 | |
| 5270 /* Put all unmarked markers on free list. | |
| 5271 Dechain each one first from the buffer into which it points. */ | |
| 5272 sweep_markers (); | |
| 5273 | |
| 5274 sweep_events (); | |
| 5275 | |
| 1204 | 5276 #ifdef EVENT_DATA_AS_OBJECTS |
| 934 | 5277 sweep_key_data (); |
| 5278 sweep_button_data (); | |
| 5279 sweep_motion_data (); | |
| 5280 sweep_process_data (); | |
| 5281 sweep_timeout_data (); | |
| 5282 sweep_magic_data (); | |
| 5283 sweep_magic_eval_data (); | |
| 5284 sweep_eval_data (); | |
| 5285 sweep_misc_user_data (); | |
| 1204 | 5286 #endif /* EVENT_DATA_AS_OBJECTS */ |
|
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
5287 |
| 428 | 5288 #ifdef PDUMP |
| 442 | 5289 pdump_objects_unmark (); |
| 428 | 5290 #endif |
| 5291 } | |
| 3092 | 5292 #endif /* not NEW_GC */ |
|
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5293 |
| 428 | 5294 |
|
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5295 /************************************************************************/ |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5296 /* "Disksave Finalization" -- Preparing for Dumping */ |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5297 /************************************************************************/ |
| 428 | 5298 |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5299 static void |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5300 disksave_object_finalization_1 (void) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5301 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5302 #ifdef NEW_GC |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5303 mc_finalize_for_disksave (); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5304 #else /* not NEW_GC */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5305 struct old_lcrecord_header *header; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5306 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5307 for (header = all_lcrecords; header; header = header->next) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5308 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5309 struct lrecord_header *objh = &header->lheader; |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5310 const struct lrecord_implementation *imp = LHEADER_IMPLEMENTATION (objh); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5311 #if 0 /* possibly useful for debugging */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5312 if (!RECORD_DUMPABLE (objh) && !objh->free) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5313 { |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5314 stderr_out ("Disksaving a non-dumpable object: "); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5315 debug_print (wrap_pointer_1 (header)); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5316 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5317 #endif |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5318 if (imp->disksave && !objh->free) |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5319 (imp->disksave) (wrap_pointer_1 (header)); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5320 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5321 #endif /* not NEW_GC */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5322 } |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5323 |
| 428 | 5324 void |
| 5325 disksave_object_finalization (void) | |
| 5326 { | |
| 5327 /* It's important that certain information from the environment not get | |
| 5328 dumped with the executable (pathnames, environment variables, etc.). | |
| 5329 To make it easier to tell when this has happened with strings(1) we | |
| 5330 clear some known-to-be-garbage blocks of memory, so that leftover | |
| 5331 results of old evaluation don't look like potential problems. | |
| 5332 But first we set some notable variables to nil and do one more GC, | |
| 5333 to turn those strings into garbage. | |
| 440 | 5334 */ |
| 428 | 5335 |
| 5336 /* Yeah, this list is pretty ad-hoc... */ | |
| 5337 Vprocess_environment = Qnil; | |
| 771 | 5338 env_initted = 0; |
| 428 | 5339 Vexec_directory = Qnil; |
| 5340 Vdata_directory = Qnil; | |
| 5341 Vsite_directory = Qnil; | |
| 5342 Vdoc_directory = Qnil; | |
| 5343 Vexec_path = Qnil; | |
| 5344 Vload_path = Qnil; | |
| 5345 /* Vdump_load_path = Qnil; */ | |
| 5346 /* Release hash tables for locate_file */ | |
| 5347 Flocate_file_clear_hashing (Qt); | |
| 771 | 5348 uncache_home_directory (); |
| 776 | 5349 zero_out_command_line_status_vars (); |
| 872 | 5350 clear_default_devices (); |
| 428 | 5351 |
| 5352 #if defined(LOADHIST) && !(defined(LOADHIST_DUMPED) || \ | |
| 5353 defined(LOADHIST_BUILTIN)) | |
| 5354 Vload_history = Qnil; | |
| 5355 #endif | |
| 5356 Vshell_file_name = Qnil; | |
| 5357 | |
| 3092 | 5358 #ifdef NEW_GC |
| 5359 gc_full (); | |
| 5360 #else /* not NEW_GC */ | |
| 428 | 5361 garbage_collect_1 (); |
| 3092 | 5362 #endif /* not NEW_GC */ |
| 428 | 5363 |
| 5364 /* Run the disksave finalization methods of all live objects. */ | |
| 5365 disksave_object_finalization_1 (); | |
| 5366 | |
| 3092 | 5367 #ifndef NEW_GC |
| 428 | 5368 /* Zero out the uninitialized (really, unused) part of the containers |
| 5369 for the live strings. */ | |
| 5370 { | |
| 5371 struct string_chars_block *scb; | |
| 5372 for (scb = first_string_chars_block; scb; scb = scb->next) | |
| 5373 { | |
| 5374 int count = sizeof (scb->string_chars) - scb->pos; | |
| 5375 | |
| 5376 assert (count >= 0 && count < STRING_CHARS_BLOCK_SIZE); | |
| 440 | 5377 if (count != 0) |
| 5378 { | |
| 5379 /* from the block's fill ptr to the end */ | |
| 5380 memset ((scb->string_chars + scb->pos), 0, count); | |
| 5381 } | |
| 428 | 5382 } |
| 5383 } | |
| 3092 | 5384 #endif /* not NEW_GC */ |
| 428 | 5385 |
| 5386 /* There, that ought to be enough... */ | |
| 5387 | |
| 5388 } | |
| 5389 | |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5390 |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5391 /************************************************************************/ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5392 /* Lisp interface onto garbage collection */ |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5393 /************************************************************************/ |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5394 |
| 2994 | 5395 /* Debugging aids. */ |
| 5396 | |
| 5397 DEFUN ("garbage-collect", Fgarbage_collect, 0, 0, "", /* | |
| 5398 Reclaim storage for Lisp objects no longer needed. | |
| 5399 Return info on amount of space in use: | |
| 5400 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS) | |
| 5401 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS | |
| 5402 PLIST) | |
| 5403 where `PLIST' is a list of alternating keyword/value pairs providing | |
| 5404 more detailed information. | |
| 5405 Garbage collection happens automatically if you cons more than | |
| 5406 `gc-cons-threshold' bytes of Lisp data since previous garbage collection. | |
| 5407 */ | |
| 5408 ()) | |
| 5409 { | |
| 5410 /* Record total usage for purposes of determining next GC */ | |
| 3092 | 5411 #ifdef NEW_GC |
| 5412 gc_full (); | |
| 5413 #else /* not NEW_GC */ | |
| 2994 | 5414 garbage_collect_1 (); |
| 3092 | 5415 #endif /* not NEW_GC */ |
| 2994 | 5416 |
| 5417 /* This will get set to 1, and total_gc_usage computed, as part of the | |
| 5418 call to object_memory_usage_stats() -- if ALLOC_TYPE_STATS is enabled. */ | |
| 5419 total_gc_usage_set = 0; | |
| 5420 #ifdef ALLOC_TYPE_STATS | |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5421 return garbage_collection_statistics (); |
|
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5422 #else |
| 2994 | 5423 return Qnil; |
|
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
5424 #endif |
| 2994 | 5425 } |
| 428 | 5426 |
| 5427 DEFUN ("consing-since-gc", Fconsing_since_gc, 0, 0, "", /* | |
| 5428 Return the number of bytes consed since the last garbage collection. | |
| 5429 \"Consed\" is a misnomer in that this actually counts allocation | |
| 5430 of all different kinds of objects, not just conses. | |
| 5431 | |
| 5432 If this value exceeds `gc-cons-threshold', a garbage collection happens. | |
| 5433 */ | |
| 5434 ()) | |
| 5435 { | |
| 5436 return make_int (consing_since_gc); | |
| 5437 } | |
| 5438 | |
| 440 | 5439 #if 0 |
| 444 | 5440 DEFUN ("memory-limit", Fmemory_limit, 0, 0, 0, /* |
| 801 | 5441 Return the address of the last byte XEmacs has allocated, divided by 1024. |
| 5442 This may be helpful in debugging XEmacs's memory usage. | |
| 428 | 5443 The value is divided by 1024 to make sure it will fit in a lisp integer. |
| 5444 */ | |
| 5445 ()) | |
| 5446 { | |
| 5447 return make_int ((EMACS_INT) sbrk (0) / 1024); | |
| 5448 } | |
| 440 | 5449 #endif |
| 428 | 5450 |
| 2994 | 5451 DEFUN ("total-memory-usage", Ftotal_memory_usage, 0, 0, 0, /* |
| 801 | 5452 Return the total number of bytes used by the data segment in XEmacs. |
| 5453 This may be helpful in debugging XEmacs's memory usage. | |
| 2994 | 5454 NOTE: This may or may not be accurate! It is hard to determine this |
| 5455 value in a system-independent fashion. On Windows, for example, the | |
| 5456 returned number tends to be much greater than reality. | |
| 801 | 5457 */ |
| 5458 ()) | |
| 5459 { | |
| 5460 return make_int (total_data_usage ()); | |
| 5461 } | |
| 5462 | |
|
4803
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5463 #ifdef USE_VALGRIND |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5464 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
|
5465 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
|
5466 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
|
5467 */ |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5468 ()) |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5469 { |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5470 VALGRIND_DO_LEAK_CHECK; |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5471 return Qnil; |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5472 } |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5473 |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5474 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
|
5475 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
|
5476 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
|
5477 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
|
5478 */ |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5479 ()) |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5480 { |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5481 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
|
5482 return Qnil; |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5483 } |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5484 #endif /* USE_VALGRIND */ |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5485 |
| 428 | 5486 |
|
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5487 /************************************************************************/ |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5488 /* Initialization */ |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5489 /************************************************************************/ |
|
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5159
diff
changeset
|
5490 |
| 428 | 5491 /* Initialization */ |
| 771 | 5492 static void |
| 1204 | 5493 common_init_alloc_early (void) |
| 428 | 5494 { |
| 771 | 5495 #ifndef Qzero |
| 5496 Qzero = make_int (0); /* Only used if Lisp_Object is a union type */ | |
| 5497 #endif | |
| 5498 | |
| 5499 #ifndef Qnull_pointer | |
| 5500 /* C guarantees that Qnull_pointer will be initialized to all 0 bits, | |
| 5501 so the following is actually a no-op. */ | |
| 793 | 5502 Qnull_pointer = wrap_pointer_1 (0); |
| 771 | 5503 #endif |
| 5504 | |
| 3263 | 5505 #ifndef NEW_GC |
| 428 | 5506 breathing_space = 0; |
| 5507 all_lcrecords = 0; | |
| 3263 | 5508 #endif /* not NEW_GC */ |
| 428 | 5509 ignore_malloc_warnings = 1; |
| 5510 #ifdef DOUG_LEA_MALLOC | |
| 5511 mallopt (M_TRIM_THRESHOLD, 128*1024); /* trim threshold */ | |
| 5512 mallopt (M_MMAP_THRESHOLD, 64*1024); /* mmap threshold */ | |
| 5513 #if 0 /* Moved to emacs.c */ | |
| 5514 mallopt (M_MMAP_MAX, 64); /* max. number of mmap'ed areas */ | |
| 5515 #endif | |
| 5516 #endif | |
| 3092 | 5517 #ifndef NEW_GC |
| 2720 | 5518 init_string_chars_alloc (); |
| 428 | 5519 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
|
5520 /* #### Is it intentional that this is called twice? --ben */ |
| 428 | 5521 init_string_chars_alloc (); |
| 5522 init_cons_alloc (); | |
| 5523 init_symbol_alloc (); | |
| 5524 init_compiled_function_alloc (); | |
| 5525 init_float_alloc (); | |
| 1983 | 5526 #ifdef HAVE_BIGNUM |
| 5527 init_bignum_alloc (); | |
| 5528 #endif | |
| 5529 #ifdef HAVE_RATIO | |
| 5530 init_ratio_alloc (); | |
| 5531 #endif | |
| 5532 #ifdef HAVE_BIGFLOAT | |
| 5533 init_bigfloat_alloc (); | |
| 5534 #endif | |
| 428 | 5535 init_marker_alloc (); |
| 5536 init_extent_alloc (); | |
| 5537 init_event_alloc (); | |
| 1204 | 5538 #ifdef EVENT_DATA_AS_OBJECTS |
| 934 | 5539 init_key_data_alloc (); |
| 5540 init_button_data_alloc (); | |
| 5541 init_motion_data_alloc (); | |
| 5542 init_process_data_alloc (); | |
| 5543 init_timeout_data_alloc (); | |
| 5544 init_magic_data_alloc (); | |
| 5545 init_magic_eval_data_alloc (); | |
| 5546 init_eval_data_alloc (); | |
| 5547 init_misc_user_data_alloc (); | |
| 1204 | 5548 #endif /* EVENT_DATA_AS_OBJECTS */ |
| 3263 | 5549 #endif /* not NEW_GC */ |
| 428 | 5550 |
| 5551 ignore_malloc_warnings = 0; | |
| 5552 | |
| 452 | 5553 if (staticpros_nodump) |
| 5554 Dynarr_free (staticpros_nodump); | |
| 5555 staticpros_nodump = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *); | |
| 5556 Dynarr_resize (staticpros_nodump, 100); /* merely a small optimization */ | |
| 771 | 5557 #ifdef DEBUG_XEMACS |
| 5558 if (staticpro_nodump_names) | |
| 5559 Dynarr_free (staticpro_nodump_names); | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5560 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
|
5561 const Ascbyte *); |
| 771 | 5562 Dynarr_resize (staticpro_nodump_names, 100); /* ditto */ |
| 5563 #endif | |
| 428 | 5564 |
| 3263 | 5565 #ifdef NEW_GC |
| 2720 | 5566 mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object); |
| 5567 Dynarr_resize (mcpros, 1410); /* merely a small optimization */ | |
| 5568 dump_add_root_block_ptr (&mcpros, &mcpros_description); | |
| 5569 #ifdef DEBUG_XEMACS | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5570 mcpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *); |
| 2720 | 5571 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
|
5572 dump_add_root_block_ptr (&mcpro_names, |
| 4964 | 5573 &const_Ascbyte_ptr_dynarr_description); |
| 2720 | 5574 #endif |
| 3263 | 5575 #endif /* NEW_GC */ |
| 2720 | 5576 |
| 428 | 5577 consing_since_gc = 0; |
| 851 | 5578 need_to_check_c_alloca = 0; |
| 5579 funcall_allocation_flag = 0; | |
| 5580 funcall_alloca_count = 0; | |
| 814 | 5581 |
| 3263 | 5582 #ifndef NEW_GC |
| 428 | 5583 debug_string_purity = 0; |
| 3263 | 5584 #endif /* not NEW_GC */ |
| 428 | 5585 |
| 800 | 5586 #ifdef ERROR_CHECK_TYPES |
| 428 | 5587 ERROR_ME.really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = |
| 5588 666; | |
| 5589 ERROR_ME_NOT. | |
| 5590 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = 42; | |
| 5591 ERROR_ME_WARN. | |
| 5592 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = | |
| 5593 3333632; | |
| 793 | 5594 ERROR_ME_DEBUG_WARN. |
| 5595 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = | |
| 5596 8675309; | |
| 800 | 5597 #endif /* ERROR_CHECK_TYPES */ |
| 428 | 5598 } |
| 5599 | |
| 3263 | 5600 #ifndef NEW_GC |
| 771 | 5601 static void |
| 5602 init_lcrecord_lists (void) | |
| 5603 { | |
| 5604 int i; | |
| 5605 | |
| 5606 for (i = 0; i < countof (lrecord_implementations_table); i++) | |
| 5607 { | |
| 5608 all_lcrecord_lists[i] = Qzero; /* Qnil not yet set */ | |
| 5609 staticpro_nodump (&all_lcrecord_lists[i]); | |
| 5610 } | |
| 5611 } | |
| 3263 | 5612 #endif /* not NEW_GC */ |
| 771 | 5613 |
| 5614 void | |
| 1204 | 5615 init_alloc_early (void) |
| 771 | 5616 { |
| 1204 | 5617 #if defined (__cplusplus) && defined (ERROR_CHECK_GC) |
| 5618 static struct gcpro initial_gcpro; | |
| 5619 | |
| 5620 initial_gcpro.next = 0; | |
| 5621 initial_gcpro.var = &Qnil; | |
| 5622 initial_gcpro.nvars = 1; | |
| 5623 gcprolist = &initial_gcpro; | |
| 5624 #else | |
| 5625 gcprolist = 0; | |
| 5626 #endif /* defined (__cplusplus) && defined (ERROR_CHECK_GC) */ | |
| 5627 } | |
| 5628 | |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5629 static void |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5630 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
|
5631 { |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5632 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
|
5633 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
|
5634 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
|
5635 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
|
5636 } |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5637 |
| 1204 | 5638 void |
| 5639 reinit_alloc_early (void) | |
| 5640 { | |
| 5641 common_init_alloc_early (); | |
| 3263 | 5642 #ifndef NEW_GC |
| 771 | 5643 init_lcrecord_lists (); |
| 3263 | 5644 #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
|
5645 reinit_alloc_objects_early (); |
| 771 | 5646 } |
| 5647 | |
| 428 | 5648 void |
| 5649 init_alloc_once_early (void) | |
| 5650 { | |
| 1204 | 5651 common_init_alloc_early (); |
| 428 | 5652 |
| 442 | 5653 { |
| 5654 int i; | |
| 5655 for (i = 0; i < countof (lrecord_implementations_table); i++) | |
| 5656 lrecord_implementations_table[i] = 0; | |
| 5657 } | |
| 5658 | |
|
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
|
5659 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
|
5660 |
| 452 | 5661 staticpros = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *); |
| 5662 Dynarr_resize (staticpros, 1410); /* merely a small optimization */ | |
| 2367 | 5663 dump_add_root_block_ptr (&staticpros, &staticpros_description); |
| 771 | 5664 #ifdef DEBUG_XEMACS |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5665 staticpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *); |
| 771 | 5666 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
|
5667 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
|
5668 &const_Ascbyte_ptr_dynarr_description); |
| 771 | 5669 #endif |
| 5670 | |
| 3263 | 5671 #ifdef NEW_GC |
| 2720 | 5672 mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object); |
| 5673 Dynarr_resize (mcpros, 1410); /* merely a small optimization */ | |
| 5674 dump_add_root_block_ptr (&mcpros, &mcpros_description); | |
| 5675 #ifdef DEBUG_XEMACS | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5676 mcpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *); |
| 2720 | 5677 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
|
5678 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
|
5679 &const_Ascbyte_ptr_dynarr_description); |
| 2720 | 5680 #endif |
| 3263 | 5681 #else /* not NEW_GC */ |
| 771 | 5682 init_lcrecord_lists (); |
| 3263 | 5683 #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
|
5684 |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5685 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
|
5686 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
|
5687 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
|
5688 |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5689 #ifdef NEW_GC |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5690 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
|
5691 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
|
5692 #endif /* NEW_GC */ |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5693 #ifndef NEW_GC |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5694 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
|
5695 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
|
5696 #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
|
5697 |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5698 reinit_alloc_objects_early (); |
| 428 | 5699 } |
| 5700 | |
| 5701 void | |
| 5702 syms_of_alloc (void) | |
| 5703 { | |
| 442 | 5704 DEFSYMBOL (Qgarbage_collecting); |
| 428 | 5705 |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5706 #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
|
5707 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
|
5708 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
|
5709 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
|
5710 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
|
5711 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
|
5712 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
|
5713 #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
|
5714 |
| 428 | 5715 DEFSUBR (Fcons); |
| 5716 DEFSUBR (Flist); | |
|
5354
22c4e67a2e69
Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5307
diff
changeset
|
5717 DEFSUBR (Facons); |
| 428 | 5718 DEFSUBR (Fvector); |
| 5719 DEFSUBR (Fbit_vector); | |
| 5720 DEFSUBR (Fmake_byte_code); | |
| 5721 DEFSUBR (Fmake_list); | |
| 5722 DEFSUBR (Fmake_vector); | |
| 5723 DEFSUBR (Fmake_bit_vector); | |
| 5724 DEFSUBR (Fmake_string); | |
| 5725 DEFSUBR (Fstring); | |
| 5726 DEFSUBR (Fmake_symbol); | |
| 5727 DEFSUBR (Fmake_marker); | |
| 2994 | 5728 #ifdef ALLOC_TYPE_STATS |
| 5729 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
|
5730 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
|
5731 #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
|
5732 #ifdef MEMORY_USAGE_STATS |
| 2994 | 5733 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
|
5734 #endif /* MEMORY_USAGE_STATS */ |
| 428 | 5735 DEFSUBR (Fgarbage_collect); |
| 440 | 5736 #if 0 |
| 428 | 5737 DEFSUBR (Fmemory_limit); |
| 440 | 5738 #endif |
| 2994 | 5739 DEFSUBR (Ftotal_memory_usage); |
| 428 | 5740 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
|
5741 #ifdef USE_VALGRIND |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5742 DEFSUBR (Fvalgrind_leak_check); |
|
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5743 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
|
5744 #endif |
| 428 | 5745 } |
| 5746 | |
| 5747 void | |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5748 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
|
5749 { |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5750 #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
|
5751 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
|
5752 #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
|
5753 } |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5754 |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
5755 void |
| 428 | 5756 vars_of_alloc (void) |
| 5757 { | |
|
5307
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5758 DEFVAR_CONST_INT ("array-rank-limit", &Varray_rank_limit /* |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5759 The exclusive upper bound on the number of dimensions an array may have. |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5760 |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5761 XEmacs does not support multidimensional arrays, meaning this constant is, |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5762 for the moment, 2. |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5763 */); |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5764 Varray_rank_limit = 2; |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5765 |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5766 DEFVAR_CONST_INT ("array-dimension-limit", &Varray_dimension_limit /* |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5767 The exclusive upper bound of an array's dimension. |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5768 Note that XEmacs may not have enough memory available to create an array |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5769 with this dimension. |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5770 */); |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5771 Varray_dimension_limit = ARRAY_DIMENSION_LIMIT; |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5772 |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5773 DEFVAR_CONST_INT ("array-total-size-limit", &Varray_total_size_limit /* |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5774 The exclusive upper bound on the number of elements an array may contain. |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5775 |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5776 In Common Lisp, this is distinct from `array-dimension-limit', because |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5777 arrays can have more than one dimension. In XEmacs this is not the case, |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5778 and multi-dimensional arrays need to be implemented by the user with arrays |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5779 of arrays. |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5780 |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5781 Note that XEmacs may not have enough memory available to create an array |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5782 with this dimension. |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5783 */); |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5784 Varray_total_size_limit = ARRAY_DIMENSION_LIMIT; |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5229
diff
changeset
|
5785 |
| 428 | 5786 #ifdef DEBUG_XEMACS |
| 5787 DEFVAR_INT ("debug-allocation", &debug_allocation /* | |
| 5788 If non-zero, print out information to stderr about all objects allocated. | |
| 5789 See also `debug-allocation-backtrace-length'. | |
| 5790 */ ); | |
| 5791 debug_allocation = 0; | |
| 5792 | |
| 5793 DEFVAR_INT ("debug-allocation-backtrace-length", | |
| 5794 &debug_allocation_backtrace_length /* | |
| 5795 Length (in stack frames) of short backtrace printed out by `debug-allocation'. | |
| 5796 */ ); | |
| 5797 debug_allocation_backtrace_length = 2; | |
| 5798 #endif | |
| 5799 | |
| 5800 DEFVAR_BOOL ("purify-flag", &purify_flag /* | |
| 5801 Non-nil means loading Lisp code in order to dump an executable. | |
| 5802 This means that certain objects should be allocated in readonly space. | |
| 5803 */ ); | |
| 5804 } |
