Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 736 lines (682 sloc) 27.695 kb
7fd4efa @ivmai gc4.1 tarball import
authored
1 /*
2 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
9f27ae7 @ivmai gc6.0 tarball import
authored
3 * opyright (c) 1999-2000 by Hewlett-Packard Company. All rights reserved.
7fd4efa @ivmai gc4.1 tarball import
authored
4 *
5 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
7 *
8 * Permission is hereby granted to use or copy this program
9 * for any purpose, provided the above notices are retained on all copies.
10 * Permission to modify the code and to distribute modified code is granted,
11 * provided the above notices are retained, and a notice that the code was
12 * modified is included with the above copyright notice.
13 *
14 */
15
bad4c7a 2009-10-21 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
16 #include "private/gc_pmark.h"
7fd4efa @ivmai gc4.1 tarball import
authored
17
18 /*
19 * Some simple primitives for allocation with explicit type information.
20 * Simple objects are allocated such that they contain a GC_descr at the
21 * end (in the last allocated word). This descriptor may be a procedure
22 * which then examines an extended descriptor passed as its environment.
23 *
24 * Arrays are treated as simple objects if they have sufficiently simple
25 * structure. Otherwise they are allocated from an array kind that supplies
26 * a special mark procedure. These arrays contain a pointer to a
27 * complex_descriptor as their last word.
28 * This is done because the environment field is too small, and the collector
29 * must trace the complex_descriptor.
30 *
31 * Note that descriptors inside objects may appear cleared, if we encounter a
4e7edff 2008-10-21 Hans Boehm <Hans.Boehm@hp.com> (Really Ivan Maidanski)
hboehm authored
32 * false reference to an object on a free list. In the GC_descr case, this
7fd4efa @ivmai gc4.1 tarball import
authored
33 * is OK, since a 0 descriptor corresponds to examining no fields.
34 * In the complex_descriptor case, we explicitly check for that case.
35 *
36 * MAJOR PARTS OF THIS CODE HAVE NOT BEEN TESTED AT ALL and are not testable,
37 * since they are not accessible through the current interface.
38 */
39
40 #include "gc_typed.h"
41
bad4c7a 2009-10-21 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
42 #define TYPD_EXTRA_BYTES (sizeof(word) - EXTRA_BYTES)
7fd4efa @ivmai gc4.1 tarball import
authored
43
686e786 2009-06-09 Hans Boehm <Hans.Boehm@hp.com> (Really Ivan Maidanski)
hboehm authored
44 STATIC GC_bool GC_explicit_typing_initialized = FALSE;
7fd4efa @ivmai gc4.1 tarball import
authored
45
06ecaef 2009-09-30 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
46 STATIC int GC_explicit_kind = 0;
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
47 /* Object kind for objects with indirect */
48 /* (possibly extended) descriptors. */
7fd4efa @ivmai gc4.1 tarball import
authored
49
06ecaef 2009-09-30 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
50 STATIC int GC_array_kind = 0;
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
51 /* Object kind for objects with complex */
52 /* descriptors and GC_array_mark_proc. */
7fd4efa @ivmai gc4.1 tarball import
authored
53
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
54 /* Extended descriptors. GC_typed_mark_proc understands these. */
55 /* These are used for simple objects that are larger than what */
56 /* can be described by a BITMAP_BITS sized bitmap. */
7fd4efa @ivmai gc4.1 tarball import
authored
57 typedef struct {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
58 word ed_bitmap; /* lsb corresponds to first word. */
59 GC_bool ed_continued; /* next entry is continuation. */
7fd4efa @ivmai gc4.1 tarball import
authored
60 } ext_descr;
61
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
62 /* Array descriptors. GC_array_mark_proc understands these. */
63 /* We may eventually need to add provisions for headers and */
7fd4efa @ivmai gc4.1 tarball import
authored
64 /* trailers. Hence we provide for tree structured descriptors, */
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
65 /* though we don't really use them currently. */
7fd4efa @ivmai gc4.1 tarball import
authored
66 typedef union ComplexDescriptor {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
67 struct LeafDescriptor { /* Describes simple array */
7fd4efa @ivmai gc4.1 tarball import
authored
68 word ld_tag;
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
69 # define LEAF_TAG 1
70 size_t ld_size; /* bytes per element */
71 /* multiple of ALIGNMENT */
72 size_t ld_nelements; /* Number of elements. */
73 GC_descr ld_descriptor; /* A simple length, bitmap, */
74 /* or procedure descriptor. */
7fd4efa @ivmai gc4.1 tarball import
authored
75 } ld;
76 struct ComplexArrayDescriptor {
77 word ad_tag;
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
78 # define ARRAY_TAG 2
79 size_t ad_nelements;
80 union ComplexDescriptor * ad_element_descr;
7fd4efa @ivmai gc4.1 tarball import
authored
81 } ad;
82 struct SequenceDescriptor {
83 word sd_tag;
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
84 # define SEQUENCE_TAG 3
85 union ComplexDescriptor * sd_first;
86 union ComplexDescriptor * sd_second;
7fd4efa @ivmai gc4.1 tarball import
authored
87 } sd;
88 } complex_descriptor;
89 #define TAG ld.ld_tag
90
06ecaef 2009-09-30 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
91 STATIC ext_descr * GC_ext_descriptors = NULL;
92 /* Points to array of extended */
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
93 /* descriptors. */
7fd4efa @ivmai gc4.1 tarball import
authored
94
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
95 STATIC size_t GC_ed_size = 0; /* Current size of above arrays. */
bad4c7a 2009-10-21 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
96 #define ED_INITIAL_SIZE 100
7fd4efa @ivmai gc4.1 tarball import
authored
97
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
98 STATIC size_t GC_avail_descr = 0; /* Next available slot. */
7fd4efa @ivmai gc4.1 tarball import
authored
99
06ecaef 2009-09-30 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
100 STATIC int GC_typed_mark_proc_index = 0; /* Indices of my mark */
101 STATIC int GC_array_mark_proc_index = 0; /* procedures. */
7fd4efa @ivmai gc4.1 tarball import
authored
102
340c703 2009-10-17 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
103 STATIC void GC_push_typed_structures_proc(void)
0ca3e85 2008-02-06 Hans Boehm <Hans.Boehm@hp.com> (mostly from Henning Makholm)
hboehm authored
104 {
340c703 2009-10-17 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
105 GC_push_all((ptr_t)&GC_ext_descriptors,
106 (ptr_t)&GC_ext_descriptors + sizeof(word));
0ca3e85 2008-02-06 Hans Boehm <Hans.Boehm@hp.com> (mostly from Henning Makholm)
hboehm authored
107 }
108
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
109 /* Add a multiword bitmap to GC_ext_descriptors arrays. Return */
110 /* starting index. */
111 /* Returns -1 on failure. */
112 /* Caller does not hold allocation lock. */
416b03b @ivmai Add 'const' qualifier for GC_make_descriptor bitmap argument
authored
113 STATIC signed_word GC_add_ext_descriptor(const GC_word * bm, word nbits)
7fd4efa @ivmai gc4.1 tarball import
authored
114 {
e35a417 @ivmai gc7.0alpha1 tarball import
authored
115 size_t nwords = divWORDSZ(nbits + WORDSZ-1);
116 signed_word result;
117 size_t i;
118 word last_part;
16509ab 2007-06-06 Hans Boehm <Hans.Boehm@hp.com>
hboehm authored
119 size_t extra_bits;
7fd4efa @ivmai gc4.1 tarball import
authored
120 DCL_LOCK_STATE;
121
122 LOCK();
123 while (GC_avail_descr + nwords >= GC_ed_size) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
124 ext_descr * new;
125 size_t new_size;
126 word ed_size = GC_ed_size;
127
128 if (ed_size == 0) {
d692eb4 @ivmai Add assertion ensuring proper alignment of 'pushed' GC symbols
authored
129 GC_ASSERT((word)&GC_ext_descriptors % sizeof(word) == 0);
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
130 GC_push_typed_structures = GC_push_typed_structures_proc;
131 UNLOCK();
132 new_size = ED_INITIAL_SIZE;
133 } else {
134 UNLOCK();
135 new_size = 2 * ed_size;
136 if (new_size > MAX_ENV) return(-1);
137 }
138 new = (ext_descr *) GC_malloc_atomic(new_size * sizeof(ext_descr));
139 if (new == 0) return(-1);
7fd4efa @ivmai gc4.1 tarball import
authored
140 LOCK();
141 if (ed_size == GC_ed_size) {
142 if (GC_avail_descr != 0) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
143 BCOPY(GC_ext_descriptors, new,
144 GC_avail_descr * sizeof(ext_descr));
145 }
146 GC_ed_size = new_size;
147 GC_ext_descriptors = new;
148 } /* else another thread already resized it in the meantime */
7fd4efa @ivmai gc4.1 tarball import
authored
149 }
150 result = GC_avail_descr;
151 for (i = 0; i < nwords-1; i++) {
152 GC_ext_descriptors[result + i].ed_bitmap = bm[i];
153 GC_ext_descriptors[result + i].ed_continued = TRUE;
154 }
155 last_part = bm[i];
156 /* Clear irrelevant bits. */
157 extra_bits = nwords * WORDSZ - nbits;
158 last_part <<= extra_bits;
159 last_part >>= extra_bits;
160 GC_ext_descriptors[result + i].ed_bitmap = last_part;
161 GC_ext_descriptors[result + i].ed_continued = FALSE;
162 GC_avail_descr += nwords;
163 UNLOCK();
164 return(result);
165 }
166
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
167 /* Table of bitmap descriptors for n word long all pointer objects. */
06ecaef 2009-09-30 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
168 STATIC GC_descr GC_bm_table[WORDSZ/2];
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
169
170 /* Return a descriptor for the concatenation of 2 nwords long objects, */
171 /* each of which is described by descriptor. */
172 /* The result is known to be short enough to fit into a bitmap */
173 /* descriptor. */
174 /* Descriptor is a GC_DS_LENGTH or GC_DS_BITMAP descriptor. */
68b9f27 2008-07-25 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
175 STATIC GC_descr GC_double_descr(GC_descr descriptor, word nwords)
7fd4efa @ivmai gc4.1 tarball import
authored
176 {
9f27ae7 @ivmai gc6.0 tarball import
authored
177 if ((descriptor & GC_DS_TAGS) == GC_DS_LENGTH) {
7fd4efa @ivmai gc4.1 tarball import
authored
178 descriptor = GC_bm_table[BYTES_TO_WORDS((word)descriptor)];
179 };
9f27ae7 @ivmai gc6.0 tarball import
authored
180 descriptor |= (descriptor & ~GC_DS_TAGS) >> nwords;
7fd4efa @ivmai gc4.1 tarball import
authored
181 return(descriptor);
182 }
183
68b9f27 2008-07-25 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
184 STATIC complex_descriptor *
185 GC_make_sequence_descriptor(complex_descriptor *first,
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
186 complex_descriptor *second);
7fd4efa @ivmai gc4.1 tarball import
authored
187
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
188 /* Build a descriptor for an array with nelements elements, */
189 /* each of which can be described by a simple descriptor. */
190 /* We try to optimize some common cases. */
7fd4efa @ivmai gc4.1 tarball import
authored
191 /* If the result is COMPLEX, then a complex_descr* is returned */
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
192 /* in *complex_d. */
193 /* If the result is LEAF, then we built a LeafDescriptor in */
194 /* the structure pointed to by leaf. */
195 /* The tag in the leaf structure is not set. */
196 /* If the result is SIMPLE, then a GC_descr */
197 /* is returned in *simple_d. */
198 /* If the result is NO_MEM, then */
199 /* we failed to allocate the descriptor. */
200 /* The implementation knows that GC_DS_LENGTH is 0. */
201 /* *leaf, *complex_d, and *simple_d may be used as temporaries */
202 /* during the construction. */
bad4c7a 2009-10-21 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
203 #define COMPLEX 2
204 #define LEAF 1
205 #define SIMPLE 0
206 #define NO_MEM (-1)
68b9f27 2008-07-25 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
207 STATIC int GC_make_array_descriptor(size_t nelements, size_t size,
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
208 GC_descr descriptor, GC_descr *simple_d,
209 complex_descriptor **complex_d,
210 struct LeafDescriptor * leaf)
7fd4efa @ivmai gc4.1 tarball import
authored
211 {
212 # define OPT_THRESHOLD 50
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
213 /* For larger arrays, we try to combine descriptors of adjacent */
214 /* descriptors to speed up marking, and to reduce the amount */
215 /* of space needed on the mark stack. */
9f27ae7 @ivmai gc6.0 tarball import
authored
216 if ((descriptor & GC_DS_TAGS) == GC_DS_LENGTH) {
e35a417 @ivmai gc7.0alpha1 tarball import
authored
217 if (descriptor == (GC_descr)size) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
218 *simple_d = nelements * descriptor;
219 return(SIMPLE);
7fd4efa @ivmai gc4.1 tarball import
authored
220 } else if ((word)descriptor == 0) {
221 *simple_d = (GC_descr)0;
222 return(SIMPLE);
223 }
224 }
225 if (nelements <= OPT_THRESHOLD) {
226 if (nelements <= 1) {
227 if (nelements == 1) {
228 *simple_d = descriptor;
229 return(SIMPLE);
230 } else {
231 *simple_d = (GC_descr)0;
232 return(SIMPLE);
233 }
234 }
235 } else if (size <= BITMAP_BITS/2
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
236 && (descriptor & GC_DS_TAGS) != GC_DS_PROC
237 && (size & (sizeof(word)-1)) == 0) {
238 int result =
7fd4efa @ivmai gc4.1 tarball import
authored
239 GC_make_array_descriptor(nelements/2, 2*size,
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
240 GC_double_descr(descriptor,
241 BYTES_TO_WORDS(size)),
242 simple_d, complex_d, leaf);
7fd4efa @ivmai gc4.1 tarball import
authored
243 if ((nelements & 1) == 0) {
244 return(result);
245 } else {
246 struct LeafDescriptor * one_element =
247 (struct LeafDescriptor *)
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
248 GC_malloc_atomic(sizeof(struct LeafDescriptor));
249
7fd4efa @ivmai gc4.1 tarball import
authored
250 if (result == NO_MEM || one_element == 0) return(NO_MEM);
251 one_element -> ld_tag = LEAF_TAG;
252 one_element -> ld_size = size;
253 one_element -> ld_nelements = 1;
254 one_element -> ld_descriptor = descriptor;
255 switch(result) {
256 case SIMPLE:
257 {
258 struct LeafDescriptor * beginning =
259 (struct LeafDescriptor *)
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
260 GC_malloc_atomic(sizeof(struct LeafDescriptor));
7fd4efa @ivmai gc4.1 tarball import
authored
261 if (beginning == 0) return(NO_MEM);
262 beginning -> ld_tag = LEAF_TAG;
263 beginning -> ld_size = size;
264 beginning -> ld_nelements = 1;
265 beginning -> ld_descriptor = *simple_d;
266 *complex_d = GC_make_sequence_descriptor(
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
267 (complex_descriptor *)beginning,
268 (complex_descriptor *)one_element);
7fd4efa @ivmai gc4.1 tarball import
authored
269 break;
270 }
271 case LEAF:
272 {
273 struct LeafDescriptor * beginning =
274 (struct LeafDescriptor *)
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
275 GC_malloc_atomic(sizeof(struct LeafDescriptor));
7fd4efa @ivmai gc4.1 tarball import
authored
276 if (beginning == 0) return(NO_MEM);
277 beginning -> ld_tag = LEAF_TAG;
278 beginning -> ld_size = leaf -> ld_size;
279 beginning -> ld_nelements = leaf -> ld_nelements;
280 beginning -> ld_descriptor = leaf -> ld_descriptor;
281 *complex_d = GC_make_sequence_descriptor(
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
282 (complex_descriptor *)beginning,
283 (complex_descriptor *)one_element);
7fd4efa @ivmai gc4.1 tarball import
authored
284 break;
285 }
286 case COMPLEX:
287 *complex_d = GC_make_sequence_descriptor(
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
288 *complex_d,
289 (complex_descriptor *)one_element);
7fd4efa @ivmai gc4.1 tarball import
authored
290 break;
291 }
292 return(COMPLEX);
293 }
294 }
a9bb70c 2009-09-20 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
295
296 leaf -> ld_size = size;
297 leaf -> ld_nelements = nelements;
298 leaf -> ld_descriptor = descriptor;
299 return(LEAF);
7fd4efa @ivmai gc4.1 tarball import
authored
300 }
301
68b9f27 2008-07-25 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
302 STATIC complex_descriptor *
303 GC_make_sequence_descriptor(complex_descriptor *first,
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
304 complex_descriptor *second)
7fd4efa @ivmai gc4.1 tarball import
authored
305 {
306 struct SequenceDescriptor * result =
307 (struct SequenceDescriptor *)
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
308 GC_malloc(sizeof(struct SequenceDescriptor));
309 /* Can't result in overly conservative marking, since tags are */
310 /* very small integers. Probably faster than maintaining type */
311 /* info. */
7fd4efa @ivmai gc4.1 tarball import
authored
312 if (result != 0) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
313 result -> sd_tag = SEQUENCE_TAG;
7fd4efa @ivmai gc4.1 tarball import
authored
314 result -> sd_first = first;
315 result -> sd_second = second;
316 }
317 return((complex_descriptor *)result);
318 }
319
320 #ifdef UNDEFINED
bad4c7a 2009-10-21 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
321 complex_descriptor * GC_make_complex_array_descriptor(word nelements,
06ecaef 2009-09-30 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
322 complex_descriptor *descr)
bad4c7a 2009-10-21 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
323 {
7fd4efa @ivmai gc4.1 tarball import
authored
324 struct ComplexArrayDescriptor * result =
325 (struct ComplexArrayDescriptor *)
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
326 GC_malloc(sizeof(struct ComplexArrayDescriptor));
327
7fd4efa @ivmai gc4.1 tarball import
authored
328 if (result != 0) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
329 result -> ad_tag = ARRAY_TAG;
7fd4efa @ivmai gc4.1 tarball import
authored
330 result -> ad_nelements = nelements;
331 result -> ad_element_descr = descr;
332 }
333 return((complex_descriptor *)result);
bad4c7a 2009-10-21 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
334 }
7fd4efa @ivmai gc4.1 tarball import
authored
335 #endif
336
06ecaef 2009-09-30 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
337 STATIC ptr_t * GC_eobjfreelist = NULL;
7fd4efa @ivmai gc4.1 tarball import
authored
338
06ecaef 2009-09-30 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
339 STATIC ptr_t * GC_arobjfreelist = NULL;
7fd4efa @ivmai gc4.1 tarball import
authored
340
68b9f27 2008-07-25 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
341 STATIC mse * GC_typed_mark_proc(word * addr, mse * mark_stack_ptr,
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
342 mse * mark_stack_limit, word env);
7fd4efa @ivmai gc4.1 tarball import
authored
343
68b9f27 2008-07-25 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
344 STATIC mse * GC_array_mark_proc(word * addr, mse * mark_stack_ptr,
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
345 mse * mark_stack_limit, word env);
7fd4efa @ivmai gc4.1 tarball import
authored
346
347 /* Caller does not hold allocation lock. */
68b9f27 2008-07-25 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
348 STATIC void GC_init_explicit_typing(void)
7fd4efa @ivmai gc4.1 tarball import
authored
349 {
2c23fbe @ivmai Resolve "comparison of signed and unsigned values" compiler warnings.
authored
350 register unsigned i;
7fd4efa @ivmai gc4.1 tarball import
authored
351 DCL_LOCK_STATE;
352
e35a417 @ivmai gc7.0alpha1 tarball import
authored
353 GC_STATIC_ASSERT(sizeof(struct LeafDescriptor) % sizeof(word) == 0);
7fd4efa @ivmai gc4.1 tarball import
authored
354 LOCK();
355 if (GC_explicit_typing_initialized) {
356 UNLOCK();
357 return;
358 }
359 GC_explicit_typing_initialized = TRUE;
360 /* Set up object kind with simple indirect descriptor. */
cab0705 @ivmai gc6.3alpha5 tarball import
authored
361 GC_eobjfreelist = (ptr_t *)GC_new_free_list_inner();
362 GC_explicit_kind = GC_new_kind_inner(
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
363 (void **)GC_eobjfreelist,
364 (((word)WORDS_TO_BYTES(-1)) | GC_DS_PER_OBJECT),
365 TRUE, TRUE);
366 /* Descriptors are in the last word of the object. */
cab0705 @ivmai gc6.3alpha5 tarball import
authored
367 GC_typed_mark_proc_index = GC_new_proc_inner(GC_typed_mark_proc);
7fd4efa @ivmai gc4.1 tarball import
authored
368 /* Set up object kind with array descriptor. */
cab0705 @ivmai gc6.3alpha5 tarball import
authored
369 GC_arobjfreelist = (ptr_t *)GC_new_free_list_inner();
370 GC_array_mark_proc_index = GC_new_proc_inner(GC_array_mark_proc);
371 GC_array_kind = GC_new_kind_inner(
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
372 (void **)GC_arobjfreelist,
373 GC_MAKE_PROC(GC_array_mark_proc_index, 0),
374 FALSE, TRUE);
7fd4efa @ivmai gc4.1 tarball import
authored
375 for (i = 0; i < WORDSZ/2; i++) {
376 GC_descr d = (((word)(-1)) >> (WORDSZ - i)) << (WORDSZ - i);
9f27ae7 @ivmai gc6.0 tarball import
authored
377 d |= GC_DS_BITMAP;
7fd4efa @ivmai gc4.1 tarball import
authored
378 GC_bm_table[i] = d;
379 }
380 UNLOCK();
381 }
382
68b9f27 2008-07-25 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
383 STATIC mse * GC_typed_mark_proc(word * addr, mse * mark_stack_ptr,
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
384 mse * mark_stack_limit, word env)
7fd4efa @ivmai gc4.1 tarball import
authored
385 {
e35a417 @ivmai gc7.0alpha1 tarball import
authored
386 word bm = GC_ext_descriptors[env].ed_bitmap;
387 word * current_p = addr;
388 word current;
389 ptr_t greatest_ha = GC_greatest_plausible_heap_addr;
390 ptr_t least_ha = GC_least_plausible_heap_addr;
391 DECLARE_HDR_CACHE;
392
393 INIT_HDR_CACHE;
7fd4efa @ivmai gc4.1 tarball import
authored
394 for (; bm != 0; bm >>= 1, current_p++) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
395 if (bm & 1) {
396 current = *current_p;
397 FIXUP_POINTER(current);
68c2498 @ivmai Replace pointer relational comparisons with non-pointer ones
authored
398 if (current >= (word)least_ha && current <= (word)greatest_ha) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
399 PUSH_CONTENTS((ptr_t)current, mark_stack_ptr,
400 mark_stack_limit, (ptr_t)current_p, exit1);
401 }
402 }
7fd4efa @ivmai gc4.1 tarball import
authored
403 }
404 if (GC_ext_descriptors[env].ed_continued) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
405 /* Push an entry with the rest of the descriptor back onto the */
406 /* stack. Thus we never do too much work at once. Note that */
407 /* we also can't overflow the mark stack unless we actually */
408 /* mark something. */
7fd4efa @ivmai gc4.1 tarball import
authored
409 mark_stack_ptr++;
68c2498 @ivmai Replace pointer relational comparisons with non-pointer ones
authored
410 if ((word)mark_stack_ptr >= (word)mark_stack_limit) {
7fd4efa @ivmai gc4.1 tarball import
authored
411 mark_stack_ptr = GC_signal_mark_stack_overflow(mark_stack_ptr);
412 }
e35a417 @ivmai gc7.0alpha1 tarball import
authored
413 mark_stack_ptr -> mse_start = (ptr_t)(addr + WORDSZ);
9ef4c27 @ivmai Use union of AO_t and word for mse_descr to avoid type casting
authored
414 mark_stack_ptr -> mse_descr.w =
415 GC_MAKE_PROC(GC_typed_mark_proc_index, env + 1);
7fd4efa @ivmai gc4.1 tarball import
authored
416 }
417 return(mark_stack_ptr);
418 }
419
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
420 /* Return the size of the object described by d. It would be faster to */
421 /* store this directly, or to compute it as part of */
422 /* GC_push_complex_descriptor, but hopefully it doesn't matter. */
68b9f27 2008-07-25 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
423 STATIC word GC_descr_obj_size(complex_descriptor *d)
7fd4efa @ivmai gc4.1 tarball import
authored
424 {
425 switch(d -> TAG) {
426 case LEAF_TAG:
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
427 return(d -> ld.ld_nelements * d -> ld.ld_size);
7fd4efa @ivmai gc4.1 tarball import
authored
428 case ARRAY_TAG:
429 return(d -> ad.ad_nelements
430 * GC_descr_obj_size(d -> ad.ad_element_descr));
431 case SEQUENCE_TAG:
432 return(GC_descr_obj_size(d -> sd.sd_first)
433 + GC_descr_obj_size(d -> sd.sd_second));
434 default:
8b4a394 @ivmai Replace ABORTs followed by statement with ABORT_RET having dummy
authored
435 ABORT_RET("Bad complex descriptor");
436 return 0;
7fd4efa @ivmai gc4.1 tarball import
authored
437 }
438 }
439
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
440 /* Push descriptors for the object at addr with complex descriptor d */
441 /* onto the mark stack. Return 0 if the mark stack overflowed. */
68b9f27 2008-07-25 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
442 STATIC mse * GC_push_complex_descriptor(word *addr, complex_descriptor *d,
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
443 mse *msp, mse *msl)
7fd4efa @ivmai gc4.1 tarball import
authored
444 {
445 register ptr_t current = (ptr_t) addr;
446 register word nelements;
447 register word sz;
448 register word i;
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
449
7fd4efa @ivmai gc4.1 tarball import
authored
450 switch(d -> TAG) {
451 case LEAF_TAG:
452 {
453 register GC_descr descr = d -> ld.ld_descriptor;
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
454
7fd4efa @ivmai gc4.1 tarball import
authored
455 nelements = d -> ld.ld_nelements;
456 if (msl - msp <= (ptrdiff_t)nelements) return(0);
457 sz = d -> ld.ld_size;
458 for (i = 0; i < nelements; i++) {
459 msp++;
e35a417 @ivmai gc7.0alpha1 tarball import
authored
460 msp -> mse_start = current;
9ef4c27 @ivmai Use union of AO_t and word for mse_descr to avoid type casting
authored
461 msp -> mse_descr.w = descr;
7fd4efa @ivmai gc4.1 tarball import
authored
462 current += sz;
463 }
464 return(msp);
465 }
466 case ARRAY_TAG:
467 {
468 register complex_descriptor *descr = d -> ad.ad_element_descr;
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
469
7fd4efa @ivmai gc4.1 tarball import
authored
470 nelements = d -> ad.ad_nelements;
471 sz = GC_descr_obj_size(descr);
472 for (i = 0; i < nelements; i++) {
473 msp = GC_push_complex_descriptor((word *)current, descr,
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
474 msp, msl);
7fd4efa @ivmai gc4.1 tarball import
authored
475 if (msp == 0) return(0);
476 current += sz;
477 }
478 return(msp);
479 }
480 case SEQUENCE_TAG:
481 {
482 sz = GC_descr_obj_size(d -> sd.sd_first);
483 msp = GC_push_complex_descriptor((word *)current, d -> sd.sd_first,
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
484 msp, msl);
7fd4efa @ivmai gc4.1 tarball import
authored
485 if (msp == 0) return(0);
486 current += sz;
487 msp = GC_push_complex_descriptor((word *)current, d -> sd.sd_second,
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
488 msp, msl);
7fd4efa @ivmai gc4.1 tarball import
authored
489 return(msp);
490 }
491 default:
8b4a394 @ivmai Replace ABORTs followed by statement with ABORT_RET having dummy
authored
492 ABORT_RET("Bad complex descriptor");
493 return 0;
f9b1aa2 @ivmai gc4.11 tarball import
authored
494 }
7fd4efa @ivmai gc4.1 tarball import
authored
495 }
496
68b9f27 2008-07-25 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
497 STATIC mse * GC_array_mark_proc(word * addr, mse * mark_stack_ptr,
47e74a0 @ivmai Replace ARGSUSED comment-based annotation with GCC 'unused' attribute.
authored
498 mse * mark_stack_limit,
499 word env GC_ATTR_UNUSED)
7fd4efa @ivmai gc4.1 tarball import
authored
500 {
e35a417 @ivmai gc7.0alpha1 tarball import
authored
501 hdr * hhdr = HDR(addr);
502 size_t sz = hhdr -> hb_sz;
503 size_t nwords = BYTES_TO_WORDS(sz);
504 complex_descriptor * descr = (complex_descriptor *)(addr[nwords-1]);
7fd4efa @ivmai gc4.1 tarball import
authored
505 mse * orig_mark_stack_ptr = mark_stack_ptr;
506 mse * new_mark_stack_ptr;
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
507
7fd4efa @ivmai gc4.1 tarball import
authored
508 if (descr == 0) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
509 /* Found a reference to a free list entry. Ignore it. */
510 return(orig_mark_stack_ptr);
7fd4efa @ivmai gc4.1 tarball import
authored
511 }
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
512 /* In use counts were already updated when array descriptor was */
513 /* pushed. Here we only replace it by subobject descriptors, so */
514 /* no update is necessary. */
7fd4efa @ivmai gc4.1 tarball import
authored
515 new_mark_stack_ptr = GC_push_complex_descriptor(addr, descr,
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
516 mark_stack_ptr,
517 mark_stack_limit-1);
7fd4efa @ivmai gc4.1 tarball import
authored
518 if (new_mark_stack_ptr == 0) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
519 /* Doesn't fit. Conservatively push the whole array as a unit */
520 /* and request a mark stack expansion. */
521 /* This cannot cause a mark stack overflow, since it replaces */
522 /* the original array entry. */
523 GC_mark_stack_too_small = TRUE;
524 new_mark_stack_ptr = orig_mark_stack_ptr + 1;
525 new_mark_stack_ptr -> mse_start = (ptr_t)addr;
9ef4c27 @ivmai Use union of AO_t and word for mse_descr to avoid type casting
authored
526 new_mark_stack_ptr -> mse_descr.w = sz | GC_DS_LENGTH;
7fd4efa @ivmai gc4.1 tarball import
authored
527 } else {
528 /* Push descriptor itself */
529 new_mark_stack_ptr++;
e35a417 @ivmai gc7.0alpha1 tarball import
authored
530 new_mark_stack_ptr -> mse_start = (ptr_t)(addr + nwords - 1);
9ef4c27 @ivmai Use union of AO_t and word for mse_descr to avoid type casting
authored
531 new_mark_stack_ptr -> mse_descr.w = sizeof(word) | GC_DS_LENGTH;
7fd4efa @ivmai gc4.1 tarball import
authored
532 }
e35a417 @ivmai gc7.0alpha1 tarball import
authored
533 return new_mark_stack_ptr;
7fd4efa @ivmai gc4.1 tarball import
authored
534 }
535
416b03b @ivmai Add 'const' qualifier for GC_make_descriptor bitmap argument
authored
536 GC_API GC_descr GC_CALL GC_make_descriptor(const GC_word * bm, size_t len)
7fd4efa @ivmai gc4.1 tarball import
authored
537 {
e35a417 @ivmai gc7.0alpha1 tarball import
authored
538 signed_word last_set_bit = len - 1;
539 GC_descr result;
16509ab 2007-06-06 Hans Boehm <Hans.Boehm@hp.com>
hboehm authored
540 signed_word i;
7fd4efa @ivmai gc4.1 tarball import
authored
541 # define HIGH_BIT (((word)1) << (WORDSZ - 1))
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
542
089667c @ivmai Use EXPECT for checking various 'initialized' boolean variables
authored
543 if (!EXPECT(GC_explicit_typing_initialized, TRUE))
544 GC_init_explicit_typing();
545
2c23fbe @ivmai Resolve "comparison of signed and unsigned values" compiler warnings.
authored
546 while (last_set_bit >= 0 && !GC_get_bit(bm, last_set_bit))
547 last_set_bit--;
7fd4efa @ivmai gc4.1 tarball import
authored
548 if (last_set_bit < 0) return(0 /* no pointers */);
549 # if ALIGNMENT == CPP_WORDSZ/8
550 {
c521d2c @ivmai gc4.13 tarball import
authored
551 register GC_bool all_bits_set = TRUE;
7fd4efa @ivmai gc4.1 tarball import
authored
552 for (i = 0; i < last_set_bit; i++) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
553 if (!GC_get_bit(bm, i)) {
554 all_bits_set = FALSE;
555 break;
556 }
7fd4efa @ivmai gc4.1 tarball import
authored
557 }
558 if (all_bits_set) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
559 /* An initial section contains all pointers. Use length descriptor. */
e35a417 @ivmai gc7.0alpha1 tarball import
authored
560 return (WORDS_TO_BYTES(last_set_bit+1) | GC_DS_LENGTH);
7fd4efa @ivmai gc4.1 tarball import
authored
561 }
562 }
563 # endif
2c23fbe @ivmai Resolve "comparison of signed and unsigned values" compiler warnings.
authored
564 if ((word)last_set_bit < BITMAP_BITS) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
565 /* Hopefully the common case. */
566 /* Build bitmap descriptor (with bits reversed) */
567 result = HIGH_BIT;
568 for (i = last_set_bit - 1; i >= 0; i--) {
569 result >>= 1;
570 if (GC_get_bit(bm, i)) result |= HIGH_BIT;
571 }
572 result |= GC_DS_BITMAP;
573 return(result);
7fd4efa @ivmai gc4.1 tarball import
authored
574 } else {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
575 signed_word index;
576
577 index = GC_add_ext_descriptor(bm, (word)last_set_bit+1);
578 if (index == -1) return(WORDS_TO_BYTES(last_set_bit+1) | GC_DS_LENGTH);
579 /* Out of memory: use conservative */
580 /* approximation. */
581 result = GC_MAKE_PROC(GC_typed_mark_proc_index, (word)index);
582 return result;
7fd4efa @ivmai gc4.1 tarball import
authored
583 }
584 }
585
559c07b 2008-10-24 Hans Boehm <Hans.Boehm@hp.com> (Really Ivan Maidanski)
hboehm authored
586 GC_API void * GC_CALL GC_malloc_explicitly_typed(size_t lb, GC_descr d)
7fd4efa @ivmai gc4.1 tarball import
authored
587 {
e35a417 @ivmai gc7.0alpha1 tarball import
authored
588 ptr_t op;
589 ptr_t * opp;
590 size_t lg;
591 DCL_LOCK_STATE;
7fd4efa @ivmai gc4.1 tarball import
authored
592
9f27ae7 @ivmai gc6.0 tarball import
authored
593 lb += TYPD_EXTRA_BYTES;
e35a417 @ivmai gc7.0alpha1 tarball import
authored
594 if(SMALL_OBJ(lb)) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
595 lg = GC_size_map[lb];
596 opp = &(GC_eobjfreelist[lg]);
597 LOCK();
33dc2de @ivmai Use EXPECT in malloc result testing for NULL
authored
598 op = *opp;
599 if (EXPECT(0 == op, FALSE)) {
3c50a68 @ivmai gc7.0alpha5 tarball import
authored
600 UNLOCK();
7fd4efa @ivmai gc4.1 tarball import
authored
601 op = (ptr_t)GENERAL_MALLOC((word)lb, GC_explicit_kind);
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
602 if (0 == op) return 0;
603 lg = GC_size_map[lb]; /* May have been uninitialized. */
7fd4efa @ivmai gc4.1 tarball import
authored
604 } else {
605 *opp = obj_link(op);
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
606 obj_link(op) = 0;
e35a417 @ivmai gc7.0alpha1 tarball import
authored
607 GC_bytes_allocd += GRANULES_TO_BYTES(lg);
3c50a68 @ivmai gc7.0alpha5 tarball import
authored
608 UNLOCK();
7fd4efa @ivmai gc4.1 tarball import
authored
609 }
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
610 ((word *)op)[GRANULES_TO_WORDS(lg) - 1] = d;
7fd4efa @ivmai gc4.1 tarball import
authored
611 } else {
612 op = (ptr_t)GENERAL_MALLOC((word)lb, GC_explicit_kind);
4faed82 2009-06-12 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
613 if (op != NULL) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
614 lg = BYTES_TO_GRANULES(GC_size(op));
615 ((word *)op)[GRANULES_TO_WORDS(lg) - 1] = d;
4faed82 2009-06-12 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
616 }
7d3768d @ivmai gc4.12 tarball import
authored
617 }
e35a417 @ivmai gc7.0alpha1 tarball import
authored
618 return((void *) op);
7d3768d @ivmai gc4.12 tarball import
authored
619 }
620
559c07b 2008-10-24 Hans Boehm <Hans.Boehm@hp.com> (Really Ivan Maidanski)
hboehm authored
621 GC_API void * GC_CALL GC_malloc_explicitly_typed_ignore_off_page(size_t lb,
06ecaef 2009-09-30 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
622 GC_descr d)
7d3768d @ivmai gc4.12 tarball import
authored
623 {
a9bb70c 2009-09-20 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
624 ptr_t op;
625 ptr_t * opp;
626 size_t lg;
627 DCL_LOCK_STATE;
7d3768d @ivmai gc4.12 tarball import
authored
628
9f27ae7 @ivmai gc6.0 tarball import
authored
629 lb += TYPD_EXTRA_BYTES;
7d3768d @ivmai gc4.12 tarball import
authored
630 if( SMALL_OBJ(lb) ) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
631 lg = GC_size_map[lb];
632 opp = &(GC_eobjfreelist[lg]);
633 LOCK();
33dc2de @ivmai Use EXPECT in malloc result testing for NULL
authored
634 op = *opp;
635 if (EXPECT(0 == op, FALSE)) {
3c50a68 @ivmai gc7.0alpha5 tarball import
authored
636 UNLOCK();
c63ec82 @ivmai gc4.14 tarball import
authored
637 op = (ptr_t)GENERAL_MALLOC_IOP(lb, GC_explicit_kind);
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
638 if (0 == op) return 0;
639 lg = GC_size_map[lb]; /* May have been uninitialized. */
7d3768d @ivmai gc4.12 tarball import
authored
640 } else {
641 *opp = obj_link(op);
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
642 obj_link(op) = 0;
e35a417 @ivmai gc7.0alpha1 tarball import
authored
643 GC_bytes_allocd += GRANULES_TO_BYTES(lg);
3c50a68 @ivmai gc7.0alpha5 tarball import
authored
644 UNLOCK();
7d3768d @ivmai gc4.12 tarball import
authored
645 }
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
646 ((word *)op)[GRANULES_TO_WORDS(lg) - 1] = d;
7d3768d @ivmai gc4.12 tarball import
authored
647 } else {
c63ec82 @ivmai gc4.14 tarball import
authored
648 op = (ptr_t)GENERAL_MALLOC_IOP(lb, GC_explicit_kind);
4faed82 2009-06-12 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
649 if (op != NULL) {
16509ab 2007-06-06 Hans Boehm <Hans.Boehm@hp.com>
hboehm authored
650 lg = BYTES_TO_WORDS(GC_size(op));
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
651 ((word *)op)[GRANULES_TO_WORDS(lg) - 1] = d;
4faed82 2009-06-12 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
652 }
7fd4efa @ivmai gc4.1 tarball import
authored
653 }
e35a417 @ivmai gc7.0alpha1 tarball import
authored
654 return((void *) op);
7fd4efa @ivmai gc4.1 tarball import
authored
655 }
656
559c07b 2008-10-24 Hans Boehm <Hans.Boehm@hp.com> (Really Ivan Maidanski)
hboehm authored
657 GC_API void * GC_CALL GC_calloc_explicitly_typed(size_t n, size_t lb,
06ecaef 2009-09-30 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
658 GC_descr d)
7fd4efa @ivmai gc4.1 tarball import
authored
659 {
a9bb70c 2009-09-20 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
660 ptr_t op;
661 ptr_t * opp;
662 size_t lg;
663 GC_descr simple_descr;
664 complex_descriptor *complex_descr;
665 register int descr_type;
666 struct LeafDescriptor leaf;
667 DCL_LOCK_STATE;
7fd4efa @ivmai gc4.1 tarball import
authored
668
669 descr_type = GC_make_array_descriptor((word)n, (word)lb, d,
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
670 &simple_descr, &complex_descr, &leaf);
7fd4efa @ivmai gc4.1 tarball import
authored
671 switch(descr_type) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
672 case NO_MEM: return(0);
673 case SIMPLE: return(GC_malloc_explicitly_typed(n*lb, simple_descr));
674 case LEAF:
675 lb *= n;
676 lb += sizeof(struct LeafDescriptor) + TYPD_EXTRA_BYTES;
677 break;
678 case COMPLEX:
679 lb *= n;
680 lb += TYPD_EXTRA_BYTES;
681 break;
7fd4efa @ivmai gc4.1 tarball import
authored
682 }
683 if( SMALL_OBJ(lb) ) {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
684 lg = GC_size_map[lb];
685 opp = &(GC_arobjfreelist[lg]);
686 LOCK();
33dc2de @ivmai Use EXPECT in malloc result testing for NULL
authored
687 op = *opp;
688 if (EXPECT(0 == op, FALSE)) {
3c50a68 @ivmai gc7.0alpha5 tarball import
authored
689 UNLOCK();
7fd4efa @ivmai gc4.1 tarball import
authored
690 op = (ptr_t)GENERAL_MALLOC((word)lb, GC_array_kind);
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
691 if (0 == op) return(0);
692 lg = GC_size_map[lb]; /* May have been uninitialized. */
7fd4efa @ivmai gc4.1 tarball import
authored
693 } else {
694 *opp = obj_link(op);
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
695 obj_link(op) = 0;
e35a417 @ivmai gc7.0alpha1 tarball import
authored
696 GC_bytes_allocd += GRANULES_TO_BYTES(lg);
3c50a68 @ivmai gc7.0alpha5 tarball import
authored
697 UNLOCK();
7fd4efa @ivmai gc4.1 tarball import
authored
698 }
699 } else {
700 op = (ptr_t)GENERAL_MALLOC((word)lb, GC_array_kind);
f9b1aa2 @ivmai gc4.11 tarball import
authored
701 if (0 == op) return(0);
e35a417 @ivmai gc7.0alpha1 tarball import
authored
702 lg = BYTES_TO_GRANULES(GC_size(op));
7fd4efa @ivmai gc4.1 tarball import
authored
703 }
704 if (descr_type == LEAF) {
705 /* Set up the descriptor inside the object itself. */
e35a417 @ivmai gc7.0alpha1 tarball import
authored
706 volatile struct LeafDescriptor * lp =
7fd4efa @ivmai gc4.1 tarball import
authored
707 (struct LeafDescriptor *)
708 ((word *)op
e35a417 @ivmai gc7.0alpha1 tarball import
authored
709 + GRANULES_TO_WORDS(lg)
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
710 - (BYTES_TO_WORDS(sizeof(struct LeafDescriptor)) + 1));
711
7fd4efa @ivmai gc4.1 tarball import
authored
712 lp -> ld_tag = LEAF_TAG;
713 lp -> ld_size = leaf.ld_size;
714 lp -> ld_nelements = leaf.ld_nelements;
715 lp -> ld_descriptor = leaf.ld_descriptor;
e35a417 @ivmai gc7.0alpha1 tarball import
authored
716 ((volatile word *)op)[GRANULES_TO_WORDS(lg) - 1] = (word)lp;
7fd4efa @ivmai gc4.1 tarball import
authored
717 } else {
c14335e @ivmai Allow to exclude finalization support by GC_NO_FINALIZATION macro
authored
718 # ifndef GC_NO_FINALIZATION
e35a417 @ivmai gc7.0alpha1 tarball import
authored
719 size_t lw = GRANULES_TO_WORDS(lg);
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
720
7fd4efa @ivmai gc4.1 tarball import
authored
721 ((word *)op)[lw - 1] = (word)complex_descr;
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
722 /* Make sure the descriptor is cleared once there is any danger */
723 /* it may have been collected. */
4faed82 2009-06-12 Hans Boehm <Hans.Boehm@hp.com> (Really mostly Ivan Maidanski...
hboehm authored
724 if (GC_general_register_disappearing_link((void * *)((word *)op+lw-1),
c14335e @ivmai Allow to exclude finalization support by GC_NO_FINALIZATION macro
authored
725 op) == GC_NO_MEMORY)
726 # endif
727 {
db25651 2009-09-16 Ivan Maidanski <ivmai@mail.ru>
ivmai authored
728 /* Couldn't register it due to lack of memory. Punt. */
729 /* This will probably fail too, but gives the recovery code */
730 /* a chance. */
731 return(GC_malloc(n*lb));
732 }
7fd4efa @ivmai gc4.1 tarball import
authored
733 }
e35a417 @ivmai gc7.0alpha1 tarball import
authored
734 return((void *) op);
7fd4efa @ivmai gc4.1 tarball import
authored
735 }
Something went wrong with that request. Please try again.