2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
5 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
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.
15 #include "private/gc_priv.h"
19 /* Data structure for list of root sets. */
20 /* We keep a hash table, so that we can filter out duplicate additions. */
21 /* Under Win32, we need to do a better job of filtering overlaps, so */
22 /* we resort to sequential search, and pay the price. */
23 /* This is really declared in gc_priv.h:
27 # if !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32)
28 struct roots * r_next;
31 -- Delete before registering new dynamic libraries
34 struct roots GC_static_roots[MAX_ROOT_SETS];
37 int GC_no_dls
= 0; /* Register dynamic library data segments. */
39 static int n_root_sets
= 0;
40 /* GC_static_roots[0..n_root_sets) contains the valid root sets. */
42 #if !defined(NO_DEBUGGING) || defined(GC_ASSERTIONS)
43 /* Should return the same value as GC_root_size. */
44 GC_INNER word
GC_compute_root_size(void)
49 for (i
= 0; i
< n_root_sets
; i
++) {
50 size
+= GC_static_roots
[i
].r_end
- GC_static_roots
[i
].r_start
;
54 #endif /* !NO_DEBUGGING || GC_ASSERTIONS */
56 #if !defined(NO_DEBUGGING)
58 void GC_print_static_roots(void)
63 for (i
= 0; i
< n_root_sets
; i
++) {
64 GC_printf("From %p to %p%s\n",
65 GC_static_roots
[i
].r_start
, GC_static_roots
[i
].r_end
,
66 GC_static_roots
[i
].r_tmp
? " (temporary)" : "");
68 GC_printf("GC_root_size: %lu\n", (unsigned long)GC_root_size
);
70 if ((size
= GC_compute_root_size()) != GC_root_size
)
71 GC_err_printf("GC_root_size incorrect!! Should be: %lu\n",
74 #endif /* !NO_DEBUGGING */
77 /* Primarily for debugging support: */
78 /* Is the address p in one of the registered static root sections? */
79 GC_INNER GC_bool
GC_is_static_root(ptr_t p
)
81 static int last_root_set
= MAX_ROOT_SETS
;
84 if (last_root_set
< n_root_sets
85 && (word
)p
>= (word
)GC_static_roots
[last_root_set
].r_start
86 && (word
)p
< (word
)GC_static_roots
[last_root_set
].r_end
)
88 for (i
= 0; i
< n_root_sets
; i
++) {
89 if ((word
)p
>= (word
)GC_static_roots
[i
].r_start
90 && (word
)p
< (word
)GC_static_roots
[i
].r_end
) {
99 #if !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32)
101 # define LOG_RT_SIZE 6
102 # define RT_SIZE (1 << LOG_RT_SIZE) -- Power of 2, may be != MAX_ROOT_SETS
104 struct roots * GC_root_index[RT_SIZE];
105 -- Hash table header. Used only to check whether a range is
107 -- really defined in gc_priv.h
110 GC_INLINE
int rt_hash(ptr_t addr
)
112 word result
= (word
) addr
;
113 # if CPP_WORDSZ > 8*LOG_RT_SIZE
114 result
^= result
>> 8*LOG_RT_SIZE
;
116 # if CPP_WORDSZ > 4*LOG_RT_SIZE
117 result
^= result
>> 4*LOG_RT_SIZE
;
119 result
^= result
>> 2*LOG_RT_SIZE
;
120 result
^= result
>> LOG_RT_SIZE
;
121 result
&= (RT_SIZE
-1);
125 /* Is a range starting at b already in the table? If so return a */
126 /* pointer to it, else NULL. */
127 GC_INNER
void * GC_roots_present(ptr_t b
)
130 struct roots
*p
= GC_root_index
[h
];
133 if (p
-> r_start
== (ptr_t
)b
) return(p
);
139 /* Add the given root structure to the index. */
140 GC_INLINE
void add_roots_to_index(struct roots
*p
)
142 int h
= rt_hash(p
-> r_start
);
144 p
-> r_next
= GC_root_index
[h
];
145 GC_root_index
[h
] = p
;
147 #endif /* !MSWIN32 && !MSWINCE && !CYGWIN32 */
149 GC_INNER word GC_root_size
= 0;
151 GC_API
void GC_CALL
GC_add_roots(void *b
, void *e
)
155 if (!EXPECT(GC_is_initialized
, TRUE
)) GC_init();
157 GC_add_roots_inner((ptr_t
)b
, (ptr_t
)e
, FALSE
);
162 /* Add [b,e) to the root set. Adding the same interval a second time */
163 /* is a moderately fast no-op, and hence benign. We do not handle */
164 /* different but overlapping intervals efficiently. (We do handle */
165 /* them correctly.) */
166 /* Tmp specifies that the interval may be deleted before */
167 /* re-registering dynamic libraries. */
168 void GC_add_roots_inner(ptr_t b
, ptr_t e
, GC_bool tmp
)
172 GC_ASSERT((word
)b
<= (word
)e
);
173 b
= (ptr_t
)(((word
)b
+ (sizeof(word
) - 1)) & ~(sizeof(word
) - 1));
174 /* round b up to word boundary */
175 e
= (ptr_t
)((word
)e
& ~(sizeof(word
) - 1));
176 /* round e down to word boundary */
177 if ((word
)b
>= (word
)e
) return; /* nothing to do */
179 # if defined(MSWIN32) || defined(MSWINCE) || defined(CYGWIN32)
180 /* Spend the time to ensure that there are no overlapping */
181 /* or adjacent intervals. */
182 /* This could be done faster with e.g. a */
183 /* balanced tree. But the execution time here is */
184 /* virtually guaranteed to be dominated by the time it */
185 /* takes to scan the roots. */
188 old
= 0; /* initialized to prevent warning. */
189 for (i
= 0; i
< n_root_sets
; i
++) {
190 old
= GC_static_roots
+ i
;
191 if ((word
)b
<= (word
)old
->r_end
192 && (word
)e
>= (word
)old
->r_start
) {
193 if ((word
)b
< (word
)old
->r_start
) {
194 GC_root_size
+= old
->r_start
- b
;
197 if ((word
)e
> (word
)old
->r_end
) {
198 GC_root_size
+= e
- old
->r_end
;
205 if (i
< n_root_sets
) {
206 /* merge other overlapping intervals */
209 for (i
++; i
< n_root_sets
; i
++) {
210 other
= GC_static_roots
+ i
;
211 b
= other
-> r_start
;
213 if ((word
)b
<= (word
)old
->r_end
214 && (word
)e
>= (word
)old
->r_start
) {
215 if ((word
)b
< (word
)old
->r_start
) {
216 GC_root_size
+= old
->r_start
- b
;
219 if ((word
)e
> (word
)old
->r_end
) {
220 GC_root_size
+= e
- old
->r_end
;
223 old
-> r_tmp
&= other
-> r_tmp
;
224 /* Delete this entry. */
225 GC_root_size
-= (other
-> r_end
- other
-> r_start
);
226 other
-> r_start
= GC_static_roots
[n_root_sets
-1].r_start
;
227 other
-> r_end
= GC_static_roots
[n_root_sets
-1].r_end
;
235 old
= (struct roots
*)GC_roots_present(b
);
237 if ((word
)e
<= (word
)old
->r_end
) /* already there */ return;
239 GC_root_size
+= e
- old
-> r_end
;
244 if (n_root_sets
== MAX_ROOT_SETS
) {
245 ABORT("Too many root sets");
248 # ifdef DEBUG_ADD_DEL_ROOTS
249 GC_log_printf("Adding data root section %d: %p .. %p\n",
252 GC_static_roots
[n_root_sets
].r_start
= (ptr_t
)b
;
253 GC_static_roots
[n_root_sets
].r_end
= (ptr_t
)e
;
254 GC_static_roots
[n_root_sets
].r_tmp
= tmp
;
255 # if !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32)
256 GC_static_roots
[n_root_sets
].r_next
= 0;
257 add_roots_to_index(GC_static_roots
+ n_root_sets
);
259 GC_root_size
+= e
- b
;
263 static GC_bool roots_were_cleared
= FALSE
;
265 GC_API
void GC_CALL
GC_clear_roots(void)
269 if (!EXPECT(GC_is_initialized
, TRUE
)) GC_init();
271 roots_were_cleared
= TRUE
;
274 # if !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32)
275 BZERO(GC_root_index
, RT_SIZE
* sizeof(void *));
277 # ifdef DEBUG_ADD_DEL_ROOTS
278 GC_log_printf("Clear all data root sections\n");
283 /* Internal use only; lock held. */
284 STATIC
void GC_remove_root_at_pos(int i
)
286 # ifdef DEBUG_ADD_DEL_ROOTS
287 GC_log_printf("Remove data root section %d: %p .. %p\n",
288 i
, GC_static_roots
[i
].r_start
, GC_static_roots
[i
].r_end
);
290 GC_root_size
-= (GC_static_roots
[i
].r_end
- GC_static_roots
[i
].r_start
);
291 GC_static_roots
[i
].r_start
= GC_static_roots
[n_root_sets
-1].r_start
;
292 GC_static_roots
[i
].r_end
= GC_static_roots
[n_root_sets
-1].r_end
;
293 GC_static_roots
[i
].r_tmp
= GC_static_roots
[n_root_sets
-1].r_tmp
;
297 #if !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32)
298 STATIC
void GC_rebuild_root_index(void)
301 BZERO(GC_root_index
, RT_SIZE
* sizeof(void *));
302 for (i
= 0; i
< n_root_sets
; i
++)
303 add_roots_to_index(GC_static_roots
+ i
);
307 #if defined(DYNAMIC_LOADING) || defined(MSWIN32) || defined(MSWINCE) \
308 || defined(PCR) || defined(CYGWIN32)
309 /* Internal use only; lock held. */
310 STATIC
void GC_remove_tmp_roots(void)
314 for (i
= 0; i
< n_root_sets
; ) {
315 if (GC_static_roots
[i
].r_tmp
) {
316 GC_remove_root_at_pos(i
);
321 # if !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32)
322 GC_rebuild_root_index();
327 #if !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32)
328 STATIC
void GC_remove_roots_inner(ptr_t b
, ptr_t e
);
330 GC_API
void GC_CALL
GC_remove_roots(void *b
, void *e
)
334 /* Quick check whether has nothing to do */
335 if ((((word
)b
+ (sizeof(word
) - 1)) & ~(sizeof(word
) - 1)) >=
336 ((word
)e
& ~(sizeof(word
) - 1)))
340 GC_remove_roots_inner((ptr_t
)b
, (ptr_t
)e
);
344 /* Should only be called when the lock is held */
345 STATIC
void GC_remove_roots_inner(ptr_t b
, ptr_t e
)
348 for (i
= 0; i
< n_root_sets
; ) {
349 if ((word
)GC_static_roots
[i
].r_start
>= (word
)b
350 && (word
)GC_static_roots
[i
].r_end
<= (word
)e
) {
351 GC_remove_root_at_pos(i
);
356 GC_rebuild_root_index();
358 #endif /* !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32) */
360 #if (defined(MSWIN32) || defined(MSWINCE) || defined(CYGWIN32)) \
361 && !defined(NO_DEBUGGING)
362 /* Not used at present (except for, may be, debugging purpose). */
363 /* Workaround for the OS mapping and unmapping behind our back: */
364 /* Is the address p in one of the temporary static root sections? */
365 GC_bool
GC_is_tmp_root(ptr_t p
)
367 static int last_root_set
= MAX_ROOT_SETS
;
370 if (last_root_set
< n_root_sets
371 && (word
)p
>= (word
)GC_static_roots
[last_root_set
].r_start
372 && (word
)p
< (word
)GC_static_roots
[last_root_set
].r_end
)
373 return GC_static_roots
[last_root_set
].r_tmp
;
374 for (i
= 0; i
< n_root_sets
; i
++) {
375 if ((word
)p
>= (word
)GC_static_roots
[i
].r_start
376 && (word
)p
< (word
)GC_static_roots
[i
].r_end
) {
378 return GC_static_roots
[i
].r_tmp
;
383 #endif /* MSWIN32 || MSWINCE || CYGWIN32 */
385 GC_INNER ptr_t
GC_approx_sp(void)
389 /* Also force stack to grow if necessary. Otherwise the */
390 /* later accesses might cause the kernel to think we're */
391 /* doing something wrong. */
393 /* GNU C: alternatively, we may return the value of */
394 /*__builtin_frame_address(0). */
398 * Data structure for excluded static roots.
399 * Real declaration is in gc_priv.h.
406 struct exclusion GC_excl_table[MAX_EXCLUSIONS];
407 -- Array of exclusions, ascending
411 STATIC
size_t GC_excl_table_entries
= 0;/* Number of entries in use. */
413 /* Return the first exclusion range that includes an address >= start_addr */
414 /* Assumes the exclusion table contains at least one entry (namely the */
415 /* GC data structures). */
416 STATIC
struct exclusion
* GC_next_exclusion(ptr_t start_addr
)
419 size_t high
= GC_excl_table_entries
- 1;
423 mid
= (low
+ high
) >> 1;
424 /* low <= mid < high */
425 if ((word
) GC_excl_table
[mid
].e_end
<= (word
) start_addr
) {
431 if ((word
) GC_excl_table
[low
].e_end
<= (word
) start_addr
) return 0;
432 return GC_excl_table
+ low
;
435 /* Should only be called when the lock is held. The range boundaries */
436 /* should be properly aligned and valid. */
437 GC_INNER
void GC_exclude_static_roots_inner(void *start
, void *finish
)
439 struct exclusion
* next
;
440 size_t next_index
, i
;
442 GC_ASSERT((word
)start
% sizeof(word
) == 0);
443 GC_ASSERT((word
)start
< (word
)finish
);
445 if (0 == GC_excl_table_entries
) {
448 next
= GC_next_exclusion(start
);
451 if ((word
)(next
-> e_start
) < (word
) finish
) {
452 /* incomplete error check. */
453 ABORT("Exclusion ranges overlap");
455 if ((word
)(next
-> e_start
) == (word
) finish
) {
456 /* extend old range backwards */
457 next
-> e_start
= (ptr_t
)start
;
460 next_index
= next
- GC_excl_table
;
461 for (i
= GC_excl_table_entries
; i
> next_index
; --i
) {
462 GC_excl_table
[i
] = GC_excl_table
[i
-1];
465 next_index
= GC_excl_table_entries
;
467 if (GC_excl_table_entries
== MAX_EXCLUSIONS
) ABORT("Too many exclusions");
468 GC_excl_table
[next_index
].e_start
= (ptr_t
)start
;
469 GC_excl_table
[next_index
].e_end
= (ptr_t
)finish
;
470 ++GC_excl_table_entries
;
473 GC_API
void GC_CALL
GC_exclude_static_roots(void *b
, void *e
)
477 if (b
== e
) return; /* nothing to exclude? */
479 /* Round boundaries (in direction reverse to that of GC_add_roots). */
480 b
= (void *)((word
)b
& ~(sizeof(word
) - 1));
481 e
= (void *)(((word
)e
+ (sizeof(word
) - 1)) & ~(sizeof(word
) - 1));
482 if (0 == e
) e
= (void *)(word
)(~(sizeof(word
) - 1)); /* handle overflow */
485 GC_exclude_static_roots_inner(b
, e
);
489 /* Invoke push_conditional on ranges that are not excluded. */
490 STATIC
void GC_push_conditional_with_exclusions(ptr_t bottom
, ptr_t top
,
491 GC_bool all GC_ATTR_UNUSED
)
493 struct exclusion
* next
;
496 while ((word
)bottom
< (word
)top
) {
497 next
= GC_next_exclusion(bottom
);
498 if (0 == next
|| (word
)(excl_start
= next
-> e_start
) >= (word
)top
) {
499 GC_PUSH_CONDITIONAL(bottom
, top
, all
);
502 if ((word
)excl_start
> (word
)bottom
)
503 GC_PUSH_CONDITIONAL(bottom
, excl_start
, all
);
504 bottom
= next
-> e_end
;
509 /* Similar to GC_push_all_stack_sections() but for IA-64 registers store. */
510 GC_INNER
void GC_push_all_register_sections(ptr_t bs_lo
, ptr_t bs_hi
,
511 int eager
, struct GC_traced_stack_sect_s
*traced_stack_sect
)
513 while (traced_stack_sect
!= NULL
) {
514 ptr_t frame_bs_lo
= traced_stack_sect
-> backing_store_end
;
515 GC_ASSERT((word
)frame_bs_lo
<= (word
)bs_hi
);
517 GC_push_all_eager(frame_bs_lo
, bs_hi
);
519 GC_push_all_stack(frame_bs_lo
, bs_hi
);
521 bs_hi
= traced_stack_sect
-> saved_backing_store_ptr
;
522 traced_stack_sect
= traced_stack_sect
-> prev
;
524 GC_ASSERT((word
)bs_lo
<= (word
)bs_hi
);
526 GC_push_all_eager(bs_lo
, bs_hi
);
528 GC_push_all_stack(bs_lo
, bs_hi
);
535 GC_INNER
void GC_push_all_stack_sections(ptr_t lo
, ptr_t hi
,
536 struct GC_traced_stack_sect_s
*traced_stack_sect
)
538 while (traced_stack_sect
!= NULL
) {
539 GC_ASSERT((word
)lo
HOTTER_THAN (word
)traced_stack_sect
);
540 # ifdef STACK_GROWS_UP
541 GC_push_all_stack((ptr_t
)traced_stack_sect
, lo
);
542 # else /* STACK_GROWS_DOWN */
543 GC_push_all_stack(lo
, (ptr_t
)traced_stack_sect
);
545 lo
= traced_stack_sect
-> saved_stack_ptr
;
546 GC_ASSERT(lo
!= NULL
);
547 traced_stack_sect
= traced_stack_sect
-> prev
;
549 GC_ASSERT(!((word
)hi
HOTTER_THAN (word
)lo
));
550 # ifdef STACK_GROWS_UP
551 /* We got them backwards! */
552 GC_push_all_stack(hi
, lo
);
553 # else /* STACK_GROWS_DOWN */
554 GC_push_all_stack(lo
, hi
);
561 /* Defined in mark.c. */
562 void GC_add_trace_entry(char *kind
, word arg1
, word arg2
);
565 /* Similar to GC_push_all_eager, but only the */
566 /* part hotter than cold_gc_frame is scanned */
567 /* immediately. Needed to ensure that callee- */
568 /* save registers are not missed. */
570 * A version of GC_push_all that treats all interior pointers as valid
571 * and scans part of the area immediately, to make sure that saved
572 * register values are not lost.
573 * Cold_gc_frame delimits the stack section that must be scanned
574 * eagerly. A zero value indicates that no eager scanning is needed.
575 * We don't need to worry about the MANUAL_VDB case here, since this
576 * is only called in the single-threaded case. We assume that we
577 * cannot collect between an assignment and the corresponding
580 STATIC
void GC_push_all_stack_partially_eager(ptr_t bottom
, ptr_t top
,
583 if (!NEED_FIXUP_POINTER
&& GC_all_interior_pointers
) {
584 /* Push the hot end of the stack eagerly, so that register values */
585 /* saved inside GC frames are marked before they disappear. */
586 /* The rest of the marking can be deferred until later. */
587 if (0 == cold_gc_frame
) {
588 GC_push_all_stack(bottom
, top
);
591 GC_ASSERT((word
)bottom
<= (word
)cold_gc_frame
592 && (word
)cold_gc_frame
<= (word
)top
);
593 # ifdef STACK_GROWS_DOWN
594 GC_push_all(cold_gc_frame
- sizeof(ptr_t
), top
);
595 GC_push_all_eager(bottom
, cold_gc_frame
);
596 # else /* STACK_GROWS_UP */
597 GC_push_all(bottom
, cold_gc_frame
+ sizeof(ptr_t
));
598 GC_push_all_eager(cold_gc_frame
, top
);
599 # endif /* STACK_GROWS_UP */
601 GC_push_all_eager(bottom
, top
);
604 GC_add_trace_entry("GC_push_all_stack", bottom
, top
);
608 /* Similar to GC_push_all_stack_sections() but also uses cold_gc_frame. */
609 STATIC
void GC_push_all_stack_part_eager_sections(ptr_t lo
, ptr_t hi
,
610 ptr_t cold_gc_frame
, struct GC_traced_stack_sect_s
*traced_stack_sect
)
612 GC_ASSERT(traced_stack_sect
== NULL
|| cold_gc_frame
== NULL
||
613 (word
)cold_gc_frame
HOTTER_THAN (word
)traced_stack_sect
);
615 while (traced_stack_sect
!= NULL
) {
616 GC_ASSERT((word
)lo
HOTTER_THAN (word
)traced_stack_sect
);
617 # ifdef STACK_GROWS_UP
618 GC_push_all_stack_partially_eager((ptr_t
)traced_stack_sect
, lo
,
620 # else /* STACK_GROWS_DOWN */
621 GC_push_all_stack_partially_eager(lo
, (ptr_t
)traced_stack_sect
,
624 lo
= traced_stack_sect
-> saved_stack_ptr
;
625 GC_ASSERT(lo
!= NULL
);
626 traced_stack_sect
= traced_stack_sect
-> prev
;
627 cold_gc_frame
= NULL
; /* Use at most once. */
630 GC_ASSERT(!((word
)hi
HOTTER_THAN (word
)lo
));
631 # ifdef STACK_GROWS_UP
632 /* We got them backwards! */
633 GC_push_all_stack_partially_eager(hi
, lo
, cold_gc_frame
);
634 # else /* STACK_GROWS_DOWN */
635 GC_push_all_stack_partially_eager(lo
, hi
, cold_gc_frame
);
639 #endif /* !THREADS */
641 /* Push enough of the current stack eagerly to */
642 /* ensure that callee-save registers saved in */
643 /* GC frames are scanned. */
644 /* In the non-threads case, schedule entire */
645 /* stack for scanning. */
646 /* The second argument is a pointer to the */
647 /* (possibly null) thread context, for */
648 /* (currently hypothetical) more precise */
649 /* stack scanning. */
651 * In the absence of threads, push the stack contents.
652 * In the presence of threads, push enough of the current stack
653 * to ensure that callee-save registers saved in collector frames have been
655 * FIXME: Merge with per-thread stuff.
657 STATIC
void GC_push_current_stack(ptr_t cold_gc_frame
,
658 void * context GC_ATTR_UNUSED
)
660 # if defined(THREADS)
661 if (0 == cold_gc_frame
) return;
662 # ifdef STACK_GROWS_DOWN
663 GC_push_all_eager(GC_approx_sp(), cold_gc_frame
);
664 /* For IA64, the register stack backing store is handled */
665 /* in the thread-specific code. */
667 GC_push_all_eager(cold_gc_frame
, GC_approx_sp());
670 GC_push_all_stack_part_eager_sections(GC_approx_sp(), GC_stackbottom
,
671 cold_gc_frame
, GC_traced_stack_sect
);
673 /* We also need to push the register stack backing store. */
674 /* This should really be done in the same way as the */
675 /* regular stack. For now we fudge it a bit. */
676 /* Note that the backing store grows up, so we can't use */
677 /* GC_push_all_stack_partially_eager. */
679 ptr_t bsp
= GC_save_regs_ret_val
;
680 ptr_t cold_gc_bs_pointer
= bsp
- 2048;
681 if (GC_all_interior_pointers
682 && (word
)cold_gc_bs_pointer
> (word
)BACKING_STORE_BASE
) {
683 /* Adjust cold_gc_bs_pointer if below our innermost */
684 /* "traced stack section" in backing store. */
685 if (GC_traced_stack_sect
!= NULL
686 && (word
)cold_gc_bs_pointer
687 < (word
)GC_traced_stack_sect
->backing_store_end
)
689 GC_traced_stack_sect
->backing_store_end
;
690 GC_push_all_register_sections(BACKING_STORE_BASE
,
691 cold_gc_bs_pointer
, FALSE
, GC_traced_stack_sect
);
692 GC_push_all_eager(cold_gc_bs_pointer
, bsp
);
694 GC_push_all_register_sections(BACKING_STORE_BASE
, bsp
,
695 TRUE
/* eager */, GC_traced_stack_sect
);
697 /* All values should be sufficiently aligned that we */
698 /* don't have to worry about the boundary. */
701 # endif /* !THREADS */
704 GC_INNER
void (*GC_push_typed_structures
)(void) = 0;
706 /* Push GC internal roots. These are normally */
707 /* included in the static data segment, and */
708 /* Thus implicitly pushed. But we must do this */
709 /* explicitly if normal root processing is */
712 * Push GC internal roots. Only called if there is some reason to believe
713 * these would not otherwise get registered.
715 STATIC
void GC_push_gc_structures(void)
717 # ifndef GC_NO_FINALIZATION
718 GC_push_finalizer_structures();
720 # if defined(THREADS)
721 GC_push_thread_structures();
723 if( GC_push_typed_structures
)
724 GC_push_typed_structures();
727 GC_INNER
void GC_cond_register_dynamic_libraries(void)
729 # if defined(DYNAMIC_LOADING) || defined(MSWIN32) || defined(MSWINCE) \
730 || defined(CYGWIN32) || defined(PCR)
731 GC_remove_tmp_roots();
732 if (!GC_no_dls
) GC_register_dynamic_libraries();
738 STATIC
void GC_push_regs_and_stack(ptr_t cold_gc_frame
)
740 GC_with_callee_saves_pushed(GC_push_current_stack
, cold_gc_frame
);
744 * Call the mark routines (GC_tl_push for a single pointer,
745 * GC_push_conditional on groups of pointers) on every top level
746 * accessible pointer.
747 * If all is FALSE, arrange to push only possibly altered values.
748 * Cold_gc_frame is an address inside a GC frame that
749 * remains valid until all marking is complete.
750 * A zero value indicates that it's OK to miss some
753 GC_INNER
void GC_push_roots(GC_bool all
, ptr_t cold_gc_frame
)
759 * Next push static data. This must happen early on, since it's
760 * not robust against mark stack overflow.
762 /* Re-register dynamic libraries, in case one got added. */
763 /* There is some argument for doing this as late as possible, */
764 /* especially on win32, where it can change asynchronously. */
765 /* In those cases, we do it here. But on other platforms, it's */
766 /* not safe with the world stopped, so we do it earlier. */
767 # if !defined(REGISTER_LIBRARIES_EARLY)
768 GC_cond_register_dynamic_libraries();
771 /* Mark everything in static data areas */
772 for (i
= 0; i
< n_root_sets
; i
++) {
773 GC_push_conditional_with_exclusions(
774 GC_static_roots
[i
].r_start
,
775 GC_static_roots
[i
].r_end
, all
);
778 /* Mark all free list header blocks, if those were allocated from */
779 /* the garbage collected heap. This makes sure they don't */
780 /* disappear if we are not marking from static data. It also */
781 /* saves us the trouble of scanning them, and possibly that of */
782 /* marking the freelists. */
783 for (kind
= 0; kind
< GC_n_kinds
; kind
++) {
784 void *base
= GC_base(GC_obj_kinds
[kind
].ok_freelist
);
786 GC_set_mark_bit(base
);
790 /* Mark from GC internal roots if those might otherwise have */
792 if (GC_no_dls
|| roots_were_cleared
) {
793 GC_push_gc_structures();
796 /* Mark thread local free lists, even if their mark */
797 /* descriptor excludes the link field. */
798 /* If the world is not stopped, this is unsafe. It is */
799 /* also unnecessary, since we will do this again with the */
801 # if defined(THREAD_LOCAL_ALLOC)
802 if (GC_world_stopped
) GC_mark_thread_local_free_lists();
806 * Now traverse stacks, and mark from register contents.
807 * These must be done last, since they can legitimately overflow
809 * This is usually done by saving the current context on the
810 * stack, and then just tracing from the stack.
812 GC_push_regs_and_stack(cold_gc_frame
);
814 if (GC_push_other_roots
!= 0) (*GC_push_other_roots
)();
815 /* In the threads case, this also pushes thread stacks. */
816 /* Note that without interior pointer recognition lots */
817 /* of stuff may have been pushed already, and this */
818 /* should be careful about mark stack overflows. */