2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991-1996 by Xerox Corporation. All rights reserved.
4 * Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
6 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
7 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
9 * Permission is hereby granted to use or copy this program
10 * for any purpose, provided the above notices are retained on all copies.
11 * Permission to modify the code and to distribute modified code is granted,
12 * provided the above notices are retained, and a notice that the code was
13 * modified is included with the above copyright notice.
15 /* Boehm, February 1, 1996 1:19 pm PST */
16 # define I_HIDE_POINTERS
17 # include "private/gc_pmark.h"
19 # ifdef FINALIZE_ON_DEMAND
20 int GC_finalize_on_demand
= 1;
22 int GC_finalize_on_demand
= 0;
25 # ifdef JAVA_FINALIZATION
26 int GC_java_finalization
= 1;
28 int GC_java_finalization
= 0;
31 /* Type of mark procedure used for marking from finalizable object. */
32 /* This procedure normally does not mark the object, only its */
34 typedef void finalization_mark_proc(/* ptr_t finalizable_obj_ptr */);
36 # define HASH3(addr,size,log_size) \
37 ((((word)(addr) >> 3) ^ ((word)(addr) >> (3+(log_size)))) \
39 #define HASH2(addr,log_size) HASH3(addr, 1 << log_size, log_size)
41 struct hash_chain_entry
{
43 struct hash_chain_entry
* next
;
46 unsigned GC_finalization_failures
= 0;
47 /* Number of finalization requests that failed for lack of memory. */
49 static struct disappearing_link
{
50 struct hash_chain_entry prolog
;
51 # define dl_hidden_link prolog.hidden_key
52 /* Field to be cleared. */
53 # define dl_next(x) (struct disappearing_link *)((x) -> prolog.next)
54 # define dl_set_next(x,y) (x) -> prolog.next = (struct hash_chain_entry *)(y)
56 word dl_hidden_obj
; /* Pointer to object base */
59 static signed_word log_dl_table_size
= -1;
61 /* current size of array pointed to by dl_head. */
62 /* -1 ==> size is 0. */
64 word GC_dl_entries
= 0; /* Number of entries currently in disappearing */
67 static struct finalizable_object
{
68 struct hash_chain_entry prolog
;
69 # define fo_hidden_base prolog.hidden_key
70 /* Pointer to object base. */
71 /* No longer hidden once object */
72 /* is on finalize_now queue. */
73 # define fo_next(x) (struct finalizable_object *)((x) -> prolog.next)
74 # define fo_set_next(x,y) (x) -> prolog.next = (struct hash_chain_entry *)(y)
75 GC_finalization_proc fo_fn
; /* Finalizer. */
77 word fo_object_size
; /* In bytes. */
78 finalization_mark_proc
* fo_mark_proc
; /* Mark-through procedure */
81 struct finalizable_object
* GC_finalize_now
= 0;
82 /* LIst of objects that should be finalized now. */
84 static signed_word log_fo_table_size
= -1;
86 word GC_fo_entries
= 0;
88 void GC_push_finalizer_structures
GC_PROTO((void))
90 GC_push_all((ptr_t
)(&dl_head
), (ptr_t
)(&dl_head
) + sizeof(word
));
91 GC_push_all((ptr_t
)(&fo_head
), (ptr_t
)(&fo_head
) + sizeof(word
));
92 GC_push_all((ptr_t
)(&GC_finalize_now
),
93 (ptr_t
)(&GC_finalize_now
) + sizeof(word
));
96 /* Double the size of a hash table. *size_ptr is the log of its current */
97 /* size. May be a noop. */
98 /* *table is a pointer to an array of hash headers. If we succeed, we */
99 /* update both *table and *log_size_ptr. */
100 /* Lock is held. Signals are disabled. */
101 void GC_grow_table(table
, log_size_ptr
)
102 struct hash_chain_entry
***table
;
103 signed_word
* log_size_ptr
;
106 register struct hash_chain_entry
*p
;
107 int log_old_size
= *log_size_ptr
;
108 register int log_new_size
= log_old_size
+ 1;
109 word old_size
= ((log_old_size
== -1)? 0: (1 << log_old_size
));
110 register word new_size
= 1 << log_new_size
;
111 struct hash_chain_entry
**new_table
= (struct hash_chain_entry
**)
112 GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE(
113 (size_t)new_size
* sizeof(struct hash_chain_entry
*), NORMAL
);
115 if (new_table
== 0) {
117 ABORT("Insufficient space for initial table allocation");
122 for (i
= 0; i
< old_size
; i
++) {
125 register ptr_t real_key
= (ptr_t
)REVEAL_POINTER(p
-> hidden_key
);
126 register struct hash_chain_entry
*next
= p
-> next
;
127 register int new_hash
= HASH3(real_key
, new_size
, log_new_size
);
129 p
-> next
= new_table
[new_hash
];
130 new_table
[new_hash
] = p
;
134 *log_size_ptr
= log_new_size
;
138 # if defined(__STDC__) || defined(__cplusplus)
139 int GC_register_disappearing_link(GC_PTR
* link
)
141 int GC_register_disappearing_link(link
)
147 base
= (ptr_t
)GC_base((GC_PTR
)link
);
149 ABORT("Bad arg to GC_register_disappearing_link");
150 return(GC_general_register_disappearing_link(link
, base
));
153 # if defined(__STDC__) || defined(__cplusplus)
154 int GC_general_register_disappearing_link(GC_PTR
* link
,
157 int GC_general_register_disappearing_link(link
, obj
)
163 struct disappearing_link
*curr_dl
;
165 struct disappearing_link
* new_dl
;
168 if ((word
)link
& (ALIGNMENT
-1))
169 ABORT("Bad arg to GC_general_register_disappearing_link");
174 if (log_dl_table_size
== -1
175 || GC_dl_entries
> ((word
)1 << log_dl_table_size
)) {
179 GC_grow_table((struct hash_chain_entry
***)(&dl_head
),
182 if (GC_print_stats
) {
183 GC_printf1("Grew dl table to %lu entries\n",
184 (unsigned long)(1 << log_dl_table_size
));
191 index
= HASH2(link
, log_dl_table_size
);
192 curr_dl
= dl_head
[index
];
193 for (curr_dl
= dl_head
[index
]; curr_dl
!= 0; curr_dl
= dl_next(curr_dl
)) {
194 if (curr_dl
-> dl_hidden_link
== HIDE_POINTER(link
)) {
195 curr_dl
-> dl_hidden_obj
= HIDE_POINTER(obj
);
203 new_dl
= (struct disappearing_link
*)
204 GC_INTERNAL_MALLOC(sizeof(struct disappearing_link
),NORMAL
);
210 new_dl
= (struct disappearing_link
*)
211 GC_oom_fn(sizeof(struct disappearing_link
));
213 GC_finalization_failures
++;
216 /* It's not likely we'll make it here, but ... */
222 new_dl
-> dl_hidden_obj
= HIDE_POINTER(obj
);
223 new_dl
-> dl_hidden_link
= HIDE_POINTER(link
);
224 dl_set_next(new_dl
, dl_head
[index
]);
225 dl_head
[index
] = new_dl
;
234 # if defined(__STDC__) || defined(__cplusplus)
235 int GC_unregister_disappearing_link(GC_PTR
* link
)
237 int GC_unregister_disappearing_link(link
)
241 struct disappearing_link
*curr_dl
, *prev_dl
;
247 index
= HASH2(link
, log_dl_table_size
);
248 if (((unsigned long)link
& (ALIGNMENT
-1))) goto out
;
249 prev_dl
= 0; curr_dl
= dl_head
[index
];
250 while (curr_dl
!= 0) {
251 if (curr_dl
-> dl_hidden_link
== HIDE_POINTER(link
)) {
253 dl_head
[index
] = dl_next(curr_dl
);
255 dl_set_next(prev_dl
, dl_next(curr_dl
));
261 dl_set_next(curr_dl
, 0);
263 GC_free((GC_PTR
)curr_dl
);
268 curr_dl
= dl_next(curr_dl
);
276 /* Possible finalization_marker procedures. Note that mark stack */
277 /* overflow is handled by the caller, and is not a disaster. */
278 GC_API
void GC_normal_finalize_mark_proc(p
)
283 PUSH_OBJ((word
*)p
, hhdr
, GC_mark_stack_top
,
284 &(GC_mark_stack
[GC_mark_stack_size
]));
287 /* This only pays very partial attention to the mark descriptor. */
288 /* It does the right thing for normal and atomic objects, and treats */
289 /* most others as normal. */
290 GC_API
void GC_ignore_self_finalize_mark_proc(p
)
294 word descr
= hhdr
-> hb_descr
;
297 ptr_t target_limit
= p
+ WORDS_TO_BYTES(hhdr
-> hb_sz
) - 1;
299 if ((descr
& GC_DS_TAGS
) == GC_DS_LENGTH
) {
300 scan_limit
= p
+ descr
- sizeof(word
);
302 scan_limit
= target_limit
+ 1 - sizeof(word
);
304 for (q
= p
; q
<= scan_limit
; q
+= ALIGNMENT
) {
306 if (r
< p
|| r
> target_limit
) {
307 GC_PUSH_ONE_HEAP((word
)r
, q
);
313 GC_API
void GC_null_finalize_mark_proc(p
)
320 /* Register a finalization function. See gc.h for details. */
321 /* in the nonthreads case, we try to avoid disabling signals, */
322 /* since it can be expensive. Threads packages typically */
323 /* make it cheaper. */
324 /* The last parameter is a procedure that determines */
325 /* marking for finalization ordering. Any objects marked */
326 /* by that procedure will be guaranteed to not have been */
327 /* finalized when this finalizer is invoked. */
328 GC_API
void GC_register_finalizer_inner(obj
, fn
, cd
, ofn
, ocd
, mp
)
330 GC_finalization_proc fn
;
332 GC_finalization_proc
* ofn
;
334 finalization_mark_proc
* mp
;
337 struct finalizable_object
* curr_fo
, * prev_fo
;
339 struct finalizable_object
*new_fo
;
347 if (log_fo_table_size
== -1
348 || GC_fo_entries
> ((word
)1 << log_fo_table_size
)) {
352 GC_grow_table((struct hash_chain_entry
***)(&fo_head
),
355 if (GC_print_stats
) {
356 GC_printf1("Grew fo table to %lu entries\n",
357 (unsigned long)(1 << log_fo_table_size
));
364 /* in the THREADS case signals are disabled and we hold allocation */
365 /* lock; otherwise neither is true. Proceed carefully. */
367 index
= HASH2(base
, log_fo_table_size
);
368 prev_fo
= 0; curr_fo
= fo_head
[index
];
369 while (curr_fo
!= 0) {
370 if (curr_fo
-> fo_hidden_base
== HIDE_POINTER(base
)) {
371 /* Interruption by a signal in the middle of this */
372 /* should be safe. The client may see only *ocd */
373 /* updated, but we'll declare that to be his */
375 if (ocd
) *ocd
= (GC_PTR
) curr_fo
-> fo_client_data
;
376 if (ofn
) *ofn
= curr_fo
-> fo_fn
;
377 /* Delete the structure for base. */
379 fo_head
[index
] = fo_next(curr_fo
);
381 fo_set_next(prev_fo
, fo_next(curr_fo
));
385 /* May not happen if we get a signal. But a high */
386 /* estimate will only make the table larger than */
388 # if !defined(THREADS) && !defined(DBG_HDRS_ALL)
389 GC_free((GC_PTR
)curr_fo
);
392 curr_fo
-> fo_fn
= fn
;
393 curr_fo
-> fo_client_data
= (ptr_t
)cd
;
394 curr_fo
-> fo_mark_proc
= mp
;
395 /* Reinsert it. We deleted it first to maintain */
396 /* consistency in the event of a signal. */
398 fo_head
[index
] = curr_fo
;
400 fo_set_next(prev_fo
, curr_fo
);
410 curr_fo
= fo_next(curr_fo
);
423 /* We won't collect it, hence finalizer wouldn't be run. */
430 new_fo
= (struct finalizable_object
*)
431 GC_INTERNAL_MALLOC(sizeof(struct finalizable_object
),NORMAL
);
437 new_fo
= (struct finalizable_object
*)
438 GC_oom_fn(sizeof(struct finalizable_object
));
440 GC_finalization_failures
++;
443 /* It's not likely we'll make it here, but ... */
449 new_fo
-> fo_hidden_base
= (word
)HIDE_POINTER(base
);
450 new_fo
-> fo_fn
= fn
;
451 new_fo
-> fo_client_data
= (ptr_t
)cd
;
452 new_fo
-> fo_object_size
= hhdr
-> hb_sz
;
453 new_fo
-> fo_mark_proc
= mp
;
454 fo_set_next(new_fo
, fo_head
[index
]);
456 fo_head
[index
] = new_fo
;
463 # if defined(__STDC__)
464 void GC_register_finalizer(void * obj
,
465 GC_finalization_proc fn
, void * cd
,
466 GC_finalization_proc
*ofn
, void ** ocd
)
468 void GC_register_finalizer(obj
, fn
, cd
, ofn
, ocd
)
470 GC_finalization_proc fn
;
472 GC_finalization_proc
* ofn
;
476 GC_register_finalizer_inner(obj
, fn
, cd
, ofn
,
477 ocd
, GC_normal_finalize_mark_proc
);
480 # if defined(__STDC__)
481 void GC_register_finalizer_ignore_self(void * obj
,
482 GC_finalization_proc fn
, void * cd
,
483 GC_finalization_proc
*ofn
, void ** ocd
)
485 void GC_register_finalizer_ignore_self(obj
, fn
, cd
, ofn
, ocd
)
487 GC_finalization_proc fn
;
489 GC_finalization_proc
* ofn
;
493 GC_register_finalizer_inner(obj
, fn
, cd
, ofn
,
494 ocd
, GC_ignore_self_finalize_mark_proc
);
497 # if defined(__STDC__)
498 void GC_register_finalizer_no_order(void * obj
,
499 GC_finalization_proc fn
, void * cd
,
500 GC_finalization_proc
*ofn
, void ** ocd
)
502 void GC_register_finalizer_no_order(obj
, fn
, cd
, ofn
, ocd
)
504 GC_finalization_proc fn
;
506 GC_finalization_proc
* ofn
;
510 GC_register_finalizer_inner(obj
, fn
, cd
, ofn
,
511 ocd
, GC_null_finalize_mark_proc
);
515 void GC_dump_finalization()
517 struct disappearing_link
* curr_dl
;
518 struct finalizable_object
* curr_fo
;
519 ptr_t real_ptr
, real_link
;
520 int dl_size
= (log_dl_table_size
== -1 ) ? 0 : (1 << log_dl_table_size
);
521 int fo_size
= (log_fo_table_size
== -1 ) ? 0 : (1 << log_fo_table_size
);
524 GC_printf0("Disappearing links:\n");
525 for (i
= 0; i
< dl_size
; i
++) {
526 for (curr_dl
= dl_head
[i
]; curr_dl
!= 0; curr_dl
= dl_next(curr_dl
)) {
527 real_ptr
= (ptr_t
)REVEAL_POINTER(curr_dl
-> dl_hidden_obj
);
528 real_link
= (ptr_t
)REVEAL_POINTER(curr_dl
-> dl_hidden_link
);
529 GC_printf2("Object: 0x%lx, Link:0x%lx\n", real_ptr
, real_link
);
532 GC_printf0("Finalizers:\n");
533 for (i
= 0; i
< fo_size
; i
++) {
534 for (curr_fo
= fo_head
[i
]; curr_fo
!= 0; curr_fo
= fo_next(curr_fo
)) {
535 real_ptr
= (ptr_t
)REVEAL_POINTER(curr_fo
-> fo_hidden_base
);
536 GC_printf1("Finalizable object: 0x%lx\n", real_ptr
);
542 /* Called with world stopped. Cause disappearing links to disappear, */
543 /* and invoke finalizers. */
546 struct disappearing_link
* curr_dl
, * prev_dl
, * next_dl
;
547 struct finalizable_object
* curr_fo
, * prev_fo
, * next_fo
;
548 ptr_t real_ptr
, real_link
;
550 int dl_size
= (log_dl_table_size
== -1 ) ? 0 : (1 << log_dl_table_size
);
551 int fo_size
= (log_fo_table_size
== -1 ) ? 0 : (1 << log_fo_table_size
);
553 /* Make disappearing links disappear */
554 for (i
= 0; i
< dl_size
; i
++) {
555 curr_dl
= dl_head
[i
];
557 while (curr_dl
!= 0) {
558 real_ptr
= (ptr_t
)REVEAL_POINTER(curr_dl
-> dl_hidden_obj
);
559 real_link
= (ptr_t
)REVEAL_POINTER(curr_dl
-> dl_hidden_link
);
560 if (!GC_is_marked(real_ptr
)) {
561 *(word
*)real_link
= 0;
562 next_dl
= dl_next(curr_dl
);
564 dl_head
[i
] = next_dl
;
566 dl_set_next(prev_dl
, next_dl
);
568 GC_clear_mark_bit((ptr_t
)curr_dl
);
573 curr_dl
= dl_next(curr_dl
);
577 /* Mark all objects reachable via chains of 1 or more pointers */
578 /* from finalizable objects. */
579 GC_ASSERT(GC_mark_state
== MS_NONE
);
580 for (i
= 0; i
< fo_size
; i
++) {
581 for (curr_fo
= fo_head
[i
]; curr_fo
!= 0; curr_fo
= fo_next(curr_fo
)) {
582 real_ptr
= (ptr_t
)REVEAL_POINTER(curr_fo
-> fo_hidden_base
);
583 if (!GC_is_marked(real_ptr
)) {
584 GC_MARKED_FOR_FINALIZATION(real_ptr
);
585 GC_MARK_FO(real_ptr
, curr_fo
-> fo_mark_proc
);
586 if (GC_is_marked(real_ptr
)) {
587 WARN("Finalization cycle involving %lx\n", real_ptr
);
592 /* Enqueue for finalization all objects that are still */
594 GC_words_finalized
= 0;
595 for (i
= 0; i
< fo_size
; i
++) {
596 curr_fo
= fo_head
[i
];
598 while (curr_fo
!= 0) {
599 real_ptr
= (ptr_t
)REVEAL_POINTER(curr_fo
-> fo_hidden_base
);
600 if (!GC_is_marked(real_ptr
)) {
601 if (!GC_java_finalization
) {
602 GC_set_mark_bit(real_ptr
);
604 /* Delete from hash table */
605 next_fo
= fo_next(curr_fo
);
607 fo_head
[i
] = next_fo
;
609 fo_set_next(prev_fo
, next_fo
);
612 /* Add to list of objects awaiting finalization. */
613 fo_set_next(curr_fo
, GC_finalize_now
);
614 GC_finalize_now
= curr_fo
;
615 /* unhide object pointer so any future collections will */
617 curr_fo
-> fo_hidden_base
=
618 (word
) REVEAL_POINTER(curr_fo
-> fo_hidden_base
);
619 GC_words_finalized
+=
620 ALIGNED_WORDS(curr_fo
-> fo_object_size
)
621 + ALIGNED_WORDS(sizeof(struct finalizable_object
));
622 GC_ASSERT(GC_is_marked(GC_base((ptr_t
)curr_fo
)));
626 curr_fo
= fo_next(curr_fo
);
631 if (GC_java_finalization
) {
632 /* make sure we mark everything reachable from objects finalized
633 using the no_order mark_proc */
634 for (curr_fo
= GC_finalize_now
;
635 curr_fo
!= NULL
; curr_fo
= fo_next(curr_fo
)) {
636 real_ptr
= (ptr_t
)curr_fo
-> fo_hidden_base
;
637 if (!GC_is_marked(real_ptr
)) {
638 if (curr_fo
-> fo_mark_proc
== GC_null_finalize_mark_proc
) {
639 GC_MARK_FO(real_ptr
, GC_normal_finalize_mark_proc
);
641 GC_set_mark_bit(real_ptr
);
646 /* Remove dangling disappearing links. */
647 for (i
= 0; i
< dl_size
; i
++) {
648 curr_dl
= dl_head
[i
];
650 while (curr_dl
!= 0) {
651 real_link
= GC_base((ptr_t
)REVEAL_POINTER(curr_dl
-> dl_hidden_link
));
652 if (real_link
!= 0 && !GC_is_marked(real_link
)) {
653 next_dl
= dl_next(curr_dl
);
655 dl_head
[i
] = next_dl
;
657 dl_set_next(prev_dl
, next_dl
);
659 GC_clear_mark_bit((ptr_t
)curr_dl
);
664 curr_dl
= dl_next(curr_dl
);
670 #ifndef JAVA_FINALIZATION_NOT_NEEDED
672 /* Enqueue all remaining finalizers to be run - Assumes lock is
673 * held, and signals are disabled */
674 void GC_enqueue_all_finalizers()
676 struct finalizable_object
* curr_fo
, * prev_fo
, * next_fo
;
681 fo_size
= (log_fo_table_size
== -1 ) ? 0 : (1 << log_fo_table_size
);
682 GC_words_finalized
= 0;
683 for (i
= 0; i
< fo_size
; i
++) {
684 curr_fo
= fo_head
[i
];
686 while (curr_fo
!= 0) {
687 real_ptr
= (ptr_t
)REVEAL_POINTER(curr_fo
-> fo_hidden_base
);
688 GC_MARK_FO(real_ptr
, GC_normal_finalize_mark_proc
);
689 GC_set_mark_bit(real_ptr
);
691 /* Delete from hash table */
692 next_fo
= fo_next(curr_fo
);
694 fo_head
[i
] = next_fo
;
696 fo_set_next(prev_fo
, next_fo
);
700 /* Add to list of objects awaiting finalization. */
701 fo_set_next(curr_fo
, GC_finalize_now
);
702 GC_finalize_now
= curr_fo
;
704 /* unhide object pointer so any future collections will */
706 curr_fo
-> fo_hidden_base
=
707 (word
) REVEAL_POINTER(curr_fo
-> fo_hidden_base
);
709 GC_words_finalized
+=
710 ALIGNED_WORDS(curr_fo
-> fo_object_size
)
711 + ALIGNED_WORDS(sizeof(struct finalizable_object
));
719 /* Invoke all remaining finalizers that haven't yet been run.
720 * This is needed for strict compliance with the Java standard,
721 * which can make the runtime guarantee that all finalizers are run.
722 * Unfortunately, the Java standard implies we have to keep running
723 * finalizers until there are no more left, a potential infinite loop.
725 * Note that this is even more dangerous than the usual Java
726 * finalizers, in that objects reachable from static variables
727 * may have been finalized when these finalizers are run.
728 * Finalizers run at this point must be prepared to deal with a
729 * mostly broken world.
730 * This routine is externally callable, so is called without
731 * the allocation lock.
733 GC_API
void GC_finalize_all()
739 while (GC_fo_entries
> 0) {
740 GC_enqueue_all_finalizers();
743 GC_INVOKE_FINALIZERS();
752 /* Returns true if it is worth calling GC_invoke_finalizers. (Useful if */
753 /* finalizers can only be called from some kind of `safe state' and */
754 /* getting into that safe state is expensive.) */
755 int GC_should_invoke_finalizers
GC_PROTO((void))
757 return GC_finalize_now
!= 0;
760 /* Invoke finalizers for all objects that are ready to be finalized. */
761 /* Should be called without allocation lock. */
762 int GC_invoke_finalizers()
764 struct finalizable_object
* curr_fo
;
766 word mem_freed_before
;
769 while (GC_finalize_now
!= 0) {
775 mem_freed_before
= GC_mem_freed
;
777 curr_fo
= GC_finalize_now
;
779 if (curr_fo
!= 0) GC_finalize_now
= fo_next(curr_fo
);
782 if (curr_fo
== 0) break;
784 GC_finalize_now
= fo_next(curr_fo
);
786 fo_set_next(curr_fo
, 0);
787 (*(curr_fo
-> fo_fn
))((ptr_t
)(curr_fo
-> fo_hidden_base
),
788 curr_fo
-> fo_client_data
);
789 curr_fo
-> fo_client_data
= 0;
792 /* This is probably a bad idea. It throws off accounting if */
793 /* nearly all objects are finalizable. O.w. it shouldn't */
795 GC_free((GC_PTR
)curr_fo
);
798 if (count
!= 0 && mem_freed_before
!= GC_mem_freed
) {
800 GC_finalizer_mem_freed
+= (GC_mem_freed
- mem_freed_before
);
806 void (* GC_finalizer_notifier
)() = (void (*) GC_PROTO((void)))0;
808 static GC_word last_finalizer_notification
= 0;
810 void GC_notify_or_invoke_finalizers
GC_PROTO((void))
812 /* This is a convenient place to generate backtraces if appropriate, */
813 /* since that code is not callable with the allocation lock. */
814 # if defined(KEEP_BACK_PTRS) || defined(MAKE_BACK_GRAPH)
815 static word last_back_trace_gc_no
= 1; /* Skip first one. */
817 if (GC_gc_no
> last_back_trace_gc_no
) {
820 # ifdef KEEP_BACK_PTRS
822 /* Stops when GC_gc_no wraps; that's OK. */
823 last_back_trace_gc_no
= (word
)(-1); /* disable others. */
824 for (i
= 0; i
< GC_backtraces
; ++i
) {
825 /* FIXME: This tolerates concurrent heap mutation, */
826 /* which may cause occasional mysterious results. */
827 /* We need to release the GC lock, since GC_print_callers */
828 /* acquires it. It probably shouldn't. */
830 GC_generate_random_backtrace_no_gc();
833 last_back_trace_gc_no
= GC_gc_no
;
836 # ifdef MAKE_BACK_GRAPH
837 if (GC_print_back_height
)
838 GC_print_back_graph_stats();
842 if (GC_finalize_now
== 0) return;
843 if (!GC_finalize_on_demand
) {
844 (void) GC_invoke_finalizers();
846 GC_ASSERT(GC_finalize_now
== 0);
847 # endif /* Otherwise GC can run concurrently and add more */
850 if (GC_finalizer_notifier
!= (void (*) GC_PROTO((void)))0
851 && last_finalizer_notification
!= GC_gc_no
) {
852 last_finalizer_notification
= GC_gc_no
;
853 GC_finalizer_notifier();
858 GC_PTR
GC_call_with_alloc_lock(GC_fn_type fn
,
861 GC_PTR
GC_call_with_alloc_lock(fn
, client_data
)
874 result
= (*fn
)(client_data
);
876 # ifndef GC_ASSERTIONS
878 # endif /* o.w. UNLOCK() does it implicitly */
885 #if !defined(NO_DEBUGGING)
887 void GC_print_finalization_stats()
889 struct finalizable_object
*fo
= GC_finalize_now
;
892 GC_printf2("%lu finalization table entries; %lu disappearing links\n",
893 GC_fo_entries
, GC_dl_entries
);
894 for (; 0 != fo
; fo
= fo_next(fo
)) ++ready
;
895 GC_printf1("%lu objects are eligible for immediate finalization\n", ready
);
898 #endif /* NO_DEBUGGING */