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.
5 * Copyright (C) 2007 Free Software Foundation, Inc
7 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 * Permission is hereby granted to use or copy this program
11 * for any purpose, provided the above notices are retained on all copies.
12 * Permission to modify the code and to distribute modified code is granted,
13 * provided the above notices are retained, and a notice that the code was
14 * modified is included with the above copyright notice.
17 #include "private/gc_pmark.h"
19 #ifndef GC_NO_FINALIZATION
20 # include "javaxfc.h" /* to get GC_finalize_all() as extern "C" */
22 /* Type of mark procedure used for marking from finalizable object. */
23 /* This procedure normally does not mark the object, only its */
25 typedef void (* finalization_mark_proc)(ptr_t /* finalizable_obj_ptr */);
27 #define HASH3(addr,size,log_size) \
28 ((((word)(addr) >> 3) ^ ((word)(addr) >> (3 + (log_size)))) \
30 #define HASH2(addr,log_size) HASH3(addr, (word)1 << (log_size), log_size)
32 struct hash_chain_entry {
34 struct hash_chain_entry * next;
37 struct disappearing_link {
38 struct hash_chain_entry prolog;
39 # define dl_hidden_link prolog.hidden_key
40 /* Field to be cleared. */
41 # define dl_next(x) (struct disappearing_link *)((x) -> prolog.next)
42 # define dl_set_next(x, y) \
43 (void)((x)->prolog.next = (struct hash_chain_entry *)(y))
44 word dl_hidden_obj; /* Pointer to object base */
48 struct disappearing_link **head;
53 STATIC struct dl_hashtbl_s GC_dl_hashtbl = {
54 /* head */ NULL, /* log_size */ -1, /* entries */ 0 };
55 #ifndef GC_LONG_REFS_NOT_NEEDED
56 STATIC struct dl_hashtbl_s GC_ll_hashtbl = { NULL, -1, 0 };
59 struct finalizable_object {
60 struct hash_chain_entry prolog;
61 # define fo_hidden_base prolog.hidden_key
62 /* Pointer to object base. */
63 /* No longer hidden once object */
64 /* is on finalize_now queue. */
65 # define fo_next(x) (struct finalizable_object *)((x) -> prolog.next)
66 # define fo_set_next(x,y) ((x)->prolog.next = (struct hash_chain_entry *)(y))
67 GC_finalization_proc fo_fn; /* Finalizer. */
69 word fo_object_size; /* In bytes. */
70 finalization_mark_proc fo_mark_proc; /* Mark-through procedure */
73 static signed_word log_fo_table_size = -1;
75 STATIC struct fnlz_roots_s {
76 struct finalizable_object **fo_head;
77 /* List of objects that should be finalized now: */
78 struct finalizable_object *finalize_now;
79 } GC_fnlz_roots = { NULL, NULL };
82 /* Update finalize_now atomically as GC_should_invoke_finalizers does */
83 /* not acquire the allocation lock. */
84 # define SET_FINALIZE_NOW(fo) \
85 AO_store((volatile AO_t *)&GC_fnlz_roots.finalize_now, (AO_t)(fo))
87 # define SET_FINALIZE_NOW(fo) (void)(GC_fnlz_roots.finalize_now = (fo))
90 GC_API void GC_CALL GC_push_finalizer_structures(void)
92 GC_ASSERT((word)(&GC_dl_hashtbl.head) % sizeof(word) == 0);
93 GC_ASSERT((word)(&GC_fnlz_roots) % sizeof(word) == 0);
94 # ifndef GC_LONG_REFS_NOT_NEEDED
95 GC_ASSERT((word)(&GC_ll_hashtbl.head) % sizeof(word) == 0);
96 GC_PUSH_ALL_SYM(GC_ll_hashtbl.head);
98 GC_PUSH_ALL_SYM(GC_dl_hashtbl.head);
99 GC_PUSH_ALL_SYM(GC_fnlz_roots);
102 /* Threshold of log_size to initiate full collection before growing */
104 #ifndef GC_ON_GROW_LOG_SIZE_MIN
105 # define GC_ON_GROW_LOG_SIZE_MIN CPP_LOG_HBLKSIZE
108 /* Double the size of a hash table. *log_size_ptr is the log of its */
109 /* current size. May be a no-op. */
110 /* *table is a pointer to an array of hash headers. If we succeed, we */
111 /* update both *table and *log_size_ptr. Lock is held. */
112 STATIC void GC_grow_table(struct hash_chain_entry ***table,
113 signed_word *log_size_ptr, word *entries_ptr)
116 struct hash_chain_entry *p;
117 signed_word log_old_size = *log_size_ptr;
118 signed_word log_new_size = log_old_size + 1;
119 word old_size = log_old_size == -1 ? 0 : (word)1 << log_old_size;
120 word new_size = (word)1 << log_new_size;
121 /* FIXME: Power of 2 size often gets rounded up to one more page. */
122 struct hash_chain_entry **new_table;
124 GC_ASSERT(I_HOLD_LOCK());
125 /* Avoid growing the table in case of at least 25% of entries can */
126 /* be deleted by enforcing a collection. Ignored for small tables. */
127 /* In incremental mode we skip this optimization, as we want to */
128 /* avoid triggering a full GC whenever possible. */
129 if (log_old_size >= GC_ON_GROW_LOG_SIZE_MIN && !GC_incremental) {
130 IF_CANCEL(int cancel_state;)
132 DISABLE_CANCEL(cancel_state);
133 (void)GC_try_to_collect_inner(GC_never_stop_func);
134 RESTORE_CANCEL(cancel_state);
135 /* GC_finalize might decrease entries value. */
136 if (*entries_ptr < ((word)1 << log_old_size) - (*entries_ptr >> 2))
140 new_table = (struct hash_chain_entry **)
141 GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE(
142 (size_t)new_size * sizeof(struct hash_chain_entry *),
144 if (new_table == 0) {
146 ABORT("Insufficient space for initial table allocation");
151 for (i = 0; i < old_size; i++) {
154 ptr_t real_key = (ptr_t)GC_REVEAL_POINTER(p->hidden_key);
155 struct hash_chain_entry *next = p -> next;
156 size_t new_hash = HASH3(real_key, new_size, log_new_size);
158 p -> next = new_table[new_hash];
160 new_table[new_hash] = p;
164 *log_size_ptr = log_new_size;
166 GC_dirty(new_table); /* entire object */
169 GC_API int GC_CALL GC_register_disappearing_link(void * * link)
173 base = (ptr_t)GC_base(link);
175 ABORT("Bad arg to GC_register_disappearing_link");
176 return(GC_general_register_disappearing_link(link, base));
179 STATIC int GC_register_disappearing_link_inner(
180 struct dl_hashtbl_s *dl_hashtbl, void **link,
181 const void *obj, const char *tbl_log_name)
183 struct disappearing_link *curr_dl;
185 struct disappearing_link * new_dl;
188 if (EXPECT(GC_find_leak, FALSE)) return GC_UNIMPLEMENTED;
190 GC_ASSERT(obj != NULL && GC_base_C(obj) == obj);
191 if (dl_hashtbl -> log_size == -1
192 || dl_hashtbl -> entries > ((word)1 << dl_hashtbl -> log_size)) {
193 GC_grow_table((struct hash_chain_entry ***)&dl_hashtbl -> head,
194 &dl_hashtbl -> log_size, &dl_hashtbl -> entries);
196 if (dl_hashtbl->log_size < 0) ABORT("log_size is negative");
198 GC_COND_LOG_PRINTF("Grew %s table to %u entries\n", tbl_log_name,
199 1 << (unsigned)dl_hashtbl -> log_size);
201 index = HASH2(link, dl_hashtbl -> log_size);
202 for (curr_dl = dl_hashtbl -> head[index]; curr_dl != 0;
203 curr_dl = dl_next(curr_dl)) {
204 if (curr_dl -> dl_hidden_link == GC_HIDE_POINTER(link)) {
205 curr_dl -> dl_hidden_obj = GC_HIDE_POINTER(obj);
210 new_dl = (struct disappearing_link *)
211 GC_INTERNAL_MALLOC(sizeof(struct disappearing_link),NORMAL);
213 GC_oom_func oom_fn = GC_oom_fn;
215 new_dl = (struct disappearing_link *)
216 (*oom_fn)(sizeof(struct disappearing_link));
220 /* It's not likely we'll make it here, but ... */
222 /* Recalculate index since the table may grow. */
223 index = HASH2(link, dl_hashtbl -> log_size);
224 /* Check again that our disappearing link not in the table. */
225 for (curr_dl = dl_hashtbl -> head[index]; curr_dl != 0;
226 curr_dl = dl_next(curr_dl)) {
227 if (curr_dl -> dl_hidden_link == GC_HIDE_POINTER(link)) {
228 curr_dl -> dl_hidden_obj = GC_HIDE_POINTER(obj);
230 # ifndef DBG_HDRS_ALL
231 /* Free unused new_dl returned by GC_oom_fn() */
232 GC_free((void *)new_dl);
238 new_dl -> dl_hidden_obj = GC_HIDE_POINTER(obj);
239 new_dl -> dl_hidden_link = GC_HIDE_POINTER(link);
240 dl_set_next(new_dl, dl_hashtbl -> head[index]);
242 dl_hashtbl -> head[index] = new_dl;
243 dl_hashtbl -> entries++;
244 GC_dirty(dl_hashtbl->head + index);
249 GC_API int GC_CALL GC_general_register_disappearing_link(void * * link,
252 if (((word)link & (ALIGNMENT-1)) != 0 || !NONNULL_ARG_NOT_NULL(link))
253 ABORT("Bad arg to GC_general_register_disappearing_link");
254 return GC_register_disappearing_link_inner(&GC_dl_hashtbl, link, obj,
259 # define FREE_DL_ENTRY(curr_dl) dl_set_next(curr_dl, NULL)
261 # define FREE_DL_ENTRY(curr_dl) GC_free(curr_dl)
264 /* Unregisters given link and returns the link entry to free. */
265 GC_INLINE struct disappearing_link *GC_unregister_disappearing_link_inner(
266 struct dl_hashtbl_s *dl_hashtbl, void **link)
268 struct disappearing_link *curr_dl;
269 struct disappearing_link *prev_dl = NULL;
272 GC_ASSERT(I_HOLD_LOCK());
273 if (dl_hashtbl->log_size == -1)
274 return NULL; /* prevent integer shift by a negative amount */
276 index = HASH2(link, dl_hashtbl->log_size);
277 for (curr_dl = dl_hashtbl -> head[index]; curr_dl;
278 curr_dl = dl_next(curr_dl)) {
279 if (curr_dl -> dl_hidden_link == GC_HIDE_POINTER(link)) {
280 /* Remove found entry from the table. */
281 if (NULL == prev_dl) {
282 dl_hashtbl -> head[index] = dl_next(curr_dl);
283 GC_dirty(dl_hashtbl->head + index);
285 dl_set_next(prev_dl, dl_next(curr_dl));
288 dl_hashtbl -> entries--;
296 GC_API int GC_CALL GC_unregister_disappearing_link(void * * link)
298 struct disappearing_link *curr_dl;
301 if (((word)link & (ALIGNMENT-1)) != 0) return(0); /* Nothing to do. */
304 curr_dl = GC_unregister_disappearing_link_inner(&GC_dl_hashtbl, link);
306 if (NULL == curr_dl) return 0;
307 FREE_DL_ENTRY(curr_dl);
311 /* Toggle-ref support. */
312 #ifndef GC_TOGGLE_REFS_NOT_NEEDED
314 /* Lowest bit is used to distinguish between choices. */
316 GC_hidden_pointer weak_ref;
319 STATIC GC_toggleref_func GC_toggleref_callback = 0;
320 STATIC GCToggleRef *GC_toggleref_arr = NULL;
321 STATIC int GC_toggleref_array_size = 0;
322 STATIC int GC_toggleref_array_capacity = 0;
324 GC_INNER void GC_process_togglerefs(void)
328 GC_bool needs_barrier = FALSE;
330 GC_ASSERT(I_HOLD_LOCK());
331 for (i = 0; i < GC_toggleref_array_size; ++i) {
332 GCToggleRef r = GC_toggleref_arr[i];
333 void *obj = r.strong_ref;
335 if (((word)obj & 1) != 0) {
336 obj = GC_REVEAL_POINTER(r.weak_ref);
341 switch (GC_toggleref_callback(obj)) {
342 case GC_TOGGLE_REF_DROP:
344 case GC_TOGGLE_REF_STRONG:
345 GC_toggleref_arr[new_size++].strong_ref = obj;
346 needs_barrier = TRUE;
348 case GC_TOGGLE_REF_WEAK:
349 GC_toggleref_arr[new_size++].weak_ref = GC_HIDE_POINTER(obj);
352 ABORT("Bad toggle-ref status returned by callback");
356 if (new_size < GC_toggleref_array_size) {
357 BZERO(&GC_toggleref_arr[new_size],
358 (GC_toggleref_array_size - new_size) * sizeof(GCToggleRef));
359 GC_toggleref_array_size = new_size;
362 GC_dirty(GC_toggleref_arr); /* entire object */
365 STATIC void GC_normal_finalize_mark_proc(ptr_t);
367 static void push_and_mark_object(void *p)
369 GC_normal_finalize_mark_proc((ptr_t)p);
370 while (!GC_mark_stack_empty()) {
371 MARK_FROM_MARK_STACK();
374 if (GC_mark_state != MS_NONE) {
375 while (!GC_mark_some(0)) {
381 STATIC void GC_mark_togglerefs(void)
384 if (NULL == GC_toggleref_arr)
387 /* TODO: Hide GC_toggleref_arr to avoid its marking from roots. */
388 GC_set_mark_bit(GC_toggleref_arr);
389 for (i = 0; i < GC_toggleref_array_size; ++i) {
390 void *obj = GC_toggleref_arr[i].strong_ref;
391 if (obj != NULL && ((word)obj & 1) == 0) {
392 push_and_mark_object(obj);
397 STATIC void GC_clear_togglerefs(void)
400 for (i = 0; i < GC_toggleref_array_size; ++i) {
401 if ((GC_toggleref_arr[i].weak_ref & 1) != 0) {
402 if (!GC_is_marked(GC_REVEAL_POINTER(GC_toggleref_arr[i].weak_ref))) {
403 GC_toggleref_arr[i].weak_ref = 0;
405 /* No need to copy, BDWGC is a non-moving collector. */
411 GC_API void GC_CALL GC_set_toggleref_func(GC_toggleref_func fn)
416 GC_toggleref_callback = fn;
420 GC_API GC_toggleref_func GC_CALL GC_get_toggleref_func(void)
422 GC_toggleref_func fn;
426 fn = GC_toggleref_callback;
431 static GC_bool ensure_toggleref_capacity(int capacity_inc)
433 GC_ASSERT(capacity_inc >= 0);
434 GC_ASSERT(I_HOLD_LOCK());
435 if (NULL == GC_toggleref_arr) {
436 GC_toggleref_array_capacity = 32; /* initial capacity */
437 GC_toggleref_arr = (GCToggleRef *)GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE(
438 GC_toggleref_array_capacity * sizeof(GCToggleRef),
440 if (NULL == GC_toggleref_arr)
443 if ((unsigned)GC_toggleref_array_size + (unsigned)capacity_inc
444 >= (unsigned)GC_toggleref_array_capacity) {
445 GCToggleRef *new_array;
446 while ((unsigned)GC_toggleref_array_capacity
447 < (unsigned)GC_toggleref_array_size + (unsigned)capacity_inc) {
448 GC_toggleref_array_capacity *= 2;
449 if (GC_toggleref_array_capacity < 0) /* overflow */
453 new_array = (GCToggleRef *)GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE(
454 GC_toggleref_array_capacity * sizeof(GCToggleRef),
456 if (NULL == new_array)
458 if (EXPECT(GC_toggleref_array_size > 0, TRUE))
459 BCOPY(GC_toggleref_arr, new_array,
460 GC_toggleref_array_size * sizeof(GCToggleRef));
461 GC_INTERNAL_FREE(GC_toggleref_arr);
462 GC_toggleref_arr = new_array;
467 GC_API int GC_CALL GC_toggleref_add(void *obj, int is_strong_ref)
469 int res = GC_SUCCESS;
472 GC_ASSERT(NONNULL_ARG_NOT_NULL(obj));
474 if (GC_toggleref_callback != 0) {
475 if (!ensure_toggleref_capacity(1)) {
478 GC_toggleref_arr[GC_toggleref_array_size].strong_ref =
479 is_strong_ref ? obj : (void *)GC_HIDE_POINTER(obj);
481 GC_dirty(GC_toggleref_arr + GC_toggleref_array_size);
482 GC_toggleref_array_size++;
488 #endif /* !GC_TOGGLE_REFS_NOT_NEEDED */
490 /* Finalizer callback support. */
491 STATIC GC_await_finalize_proc GC_object_finalized_proc = 0;
493 GC_API void GC_CALL GC_set_await_finalize_proc(GC_await_finalize_proc fn)
498 GC_object_finalized_proc = fn;
502 GC_API GC_await_finalize_proc GC_CALL GC_get_await_finalize_proc(void)
504 GC_await_finalize_proc fn;
508 fn = GC_object_finalized_proc;
513 #ifndef GC_LONG_REFS_NOT_NEEDED
514 GC_API int GC_CALL GC_register_long_link(void * * link, const void * obj)
516 if (((word)link & (ALIGNMENT-1)) != 0 || !NONNULL_ARG_NOT_NULL(link))
517 ABORT("Bad arg to GC_register_long_link");
518 return GC_register_disappearing_link_inner(&GC_ll_hashtbl, link, obj,
522 GC_API int GC_CALL GC_unregister_long_link(void * * link)
524 struct disappearing_link *curr_dl;
527 if (((word)link & (ALIGNMENT-1)) != 0) return(0); /* Nothing to do. */
530 curr_dl = GC_unregister_disappearing_link_inner(&GC_ll_hashtbl, link);
532 if (NULL == curr_dl) return 0;
533 FREE_DL_ENTRY(curr_dl);
536 #endif /* !GC_LONG_REFS_NOT_NEEDED */
538 #ifndef GC_MOVE_DISAPPEARING_LINK_NOT_NEEDED
539 /* Moves a link. Assume the lock is held. */
540 STATIC int GC_move_disappearing_link_inner(
541 struct dl_hashtbl_s *dl_hashtbl,
542 void **link, void **new_link)
544 struct disappearing_link *curr_dl, *prev_dl, *new_dl;
545 size_t curr_index, new_index;
546 word curr_hidden_link;
547 word new_hidden_link;
549 GC_ASSERT(I_HOLD_LOCK());
550 if (dl_hashtbl->log_size == -1)
551 return GC_NOT_FOUND; /* prevent integer shift by a negative amount */
553 /* Find current link. */
554 curr_index = HASH2(link, dl_hashtbl -> log_size);
555 curr_hidden_link = GC_HIDE_POINTER(link);
557 for (curr_dl = dl_hashtbl -> head[curr_index]; curr_dl;
558 curr_dl = dl_next(curr_dl)) {
559 if (curr_dl -> dl_hidden_link == curr_hidden_link)
564 if (NULL == curr_dl) {
568 if (link == new_link) {
569 return GC_SUCCESS; /* Nothing to do. */
572 /* link found; now check new_link not present. */
573 new_index = HASH2(new_link, dl_hashtbl -> log_size);
574 new_hidden_link = GC_HIDE_POINTER(new_link);
575 for (new_dl = dl_hashtbl -> head[new_index]; new_dl;
576 new_dl = dl_next(new_dl)) {
577 if (new_dl -> dl_hidden_link == new_hidden_link) {
578 /* Target already registered; bail. */
583 /* Remove from old, add to new, update link. */
584 if (NULL == prev_dl) {
585 dl_hashtbl -> head[curr_index] = dl_next(curr_dl);
587 dl_set_next(prev_dl, dl_next(curr_dl));
590 curr_dl -> dl_hidden_link = new_hidden_link;
591 dl_set_next(curr_dl, dl_hashtbl -> head[new_index]);
592 dl_hashtbl -> head[new_index] = curr_dl;
594 GC_dirty(dl_hashtbl->head); /* entire object */
598 GC_API int GC_CALL GC_move_disappearing_link(void **link, void **new_link)
603 if (((word)new_link & (ALIGNMENT-1)) != 0
604 || !NONNULL_ARG_NOT_NULL(new_link))
605 ABORT("Bad new_link arg to GC_move_disappearing_link");
606 if (((word)link & (ALIGNMENT-1)) != 0)
607 return GC_NOT_FOUND; /* Nothing to do. */
610 result = GC_move_disappearing_link_inner(&GC_dl_hashtbl, link, new_link);
615 # ifndef GC_LONG_REFS_NOT_NEEDED
616 GC_API int GC_CALL GC_move_long_link(void **link, void **new_link)
621 if (((word)new_link & (ALIGNMENT-1)) != 0
622 || !NONNULL_ARG_NOT_NULL(new_link))
623 ABORT("Bad new_link arg to GC_move_long_link");
624 if (((word)link & (ALIGNMENT-1)) != 0)
625 return GC_NOT_FOUND; /* Nothing to do. */
628 result = GC_move_disappearing_link_inner(&GC_ll_hashtbl, link, new_link);
632 # endif /* !GC_LONG_REFS_NOT_NEEDED */
633 #endif /* !GC_MOVE_DISAPPEARING_LINK_NOT_NEEDED */
635 /* Possible finalization_marker procedures. Note that mark stack */
636 /* overflow is handled by the caller, and is not a disaster. */
637 STATIC void GC_normal_finalize_mark_proc(ptr_t p)
639 # if defined(_MSC_VER) && defined(I386)
641 /* This is a manually inlined variant of GC_push_obj(). Otherwise */
642 /* some optimizer bug is tickled in VC for X86 (v19, at least). */
643 # define mark_stack_top GC_mark_stack_top
644 mse * mark_stack_limit = GC_mark_stack + GC_mark_stack_size;
645 word descr = hhdr -> hb_descr;
649 if ((word)mark_stack_top >= (word)mark_stack_limit) {
650 mark_stack_top = GC_signal_mark_stack_overflow(mark_stack_top);
652 mark_stack_top -> mse_start = p;
653 mark_stack_top -> mse_descr.w = descr;
655 # undef mark_stack_top
657 GC_mark_stack_top = GC_push_obj(p, HDR(p), GC_mark_stack_top,
658 GC_mark_stack + GC_mark_stack_size);
662 /* This only pays very partial attention to the mark descriptor. */
663 /* It does the right thing for normal and atomic objects, and treats */
664 /* most others as normal. */
665 STATIC void GC_ignore_self_finalize_mark_proc(ptr_t p)
668 word descr = hhdr -> hb_descr;
671 ptr_t target_limit = p + hhdr -> hb_sz - 1;
673 if ((descr & GC_DS_TAGS) == GC_DS_LENGTH) {
674 scan_limit = p + descr - sizeof(word);
676 scan_limit = target_limit + 1 - sizeof(word);
678 for (q = p; (word)q <= (word)scan_limit; q += ALIGNMENT) {
681 if (r < (word)p || r > (word)target_limit) {
682 GC_PUSH_ONE_HEAP(r, q, GC_mark_stack_top);
687 STATIC void GC_null_finalize_mark_proc(ptr_t p GC_ATTR_UNUSED) {}
689 /* Possible finalization_marker procedures. Note that mark stack */
690 /* overflow is handled by the caller, and is not a disaster. */
692 /* GC_unreachable_finalize_mark_proc is an alias for normal marking, */
693 /* but it is explicitly tested for, and triggers different */
694 /* behavior. Objects registered in this way are not finalized */
695 /* if they are reachable by other finalizable objects, even if those */
696 /* other objects specify no ordering. */
697 STATIC void GC_unreachable_finalize_mark_proc(ptr_t p)
699 GC_normal_finalize_mark_proc(p);
702 /* Register a finalization function. See gc.h for details. */
703 /* The last parameter is a procedure that determines */
704 /* marking for finalization ordering. Any objects marked */
705 /* by that procedure will be guaranteed to not have been */
706 /* finalized when this finalizer is invoked. */
707 STATIC void GC_register_finalizer_inner(void * obj,
708 GC_finalization_proc fn, void *cd,
709 GC_finalization_proc *ofn, void **ocd,
710 finalization_mark_proc mp)
712 struct finalizable_object * curr_fo;
714 struct finalizable_object *new_fo = 0;
715 hdr *hhdr = NULL; /* initialized to prevent warning. */
718 if (EXPECT(GC_find_leak, FALSE)) return;
720 if (log_fo_table_size == -1
721 || GC_fo_entries > ((word)1 << log_fo_table_size)) {
722 GC_grow_table((struct hash_chain_entry ***)&GC_fnlz_roots.fo_head,
723 &log_fo_table_size, &GC_fo_entries);
725 if (log_fo_table_size < 0) ABORT("log_size is negative");
727 GC_COND_LOG_PRINTF("Grew fo table to %u entries\n",
728 1 << (unsigned)log_fo_table_size);
730 /* in the THREADS case we hold allocation lock. */
732 struct finalizable_object *prev_fo = NULL;
735 index = HASH2(obj, log_fo_table_size);
736 curr_fo = GC_fnlz_roots.fo_head[index];
737 while (curr_fo != 0) {
738 GC_ASSERT(GC_size(curr_fo) >= sizeof(struct finalizable_object));
739 if (curr_fo -> fo_hidden_base == GC_HIDE_POINTER(obj)) {
740 /* Interruption by a signal in the middle of this */
741 /* should be safe. The client may see only *ocd */
742 /* updated, but we'll declare that to be his problem. */
743 if (ocd) *ocd = (void *) (curr_fo -> fo_client_data);
744 if (ofn) *ofn = curr_fo -> fo_fn;
745 /* Delete the structure for obj. */
747 GC_fnlz_roots.fo_head[index] = fo_next(curr_fo);
749 fo_set_next(prev_fo, fo_next(curr_fo));
754 /* May not happen if we get a signal. But a high */
755 /* estimate will only make the table larger than */
757 # if !defined(THREADS) && !defined(DBG_HDRS_ALL)
758 GC_free((void *)curr_fo);
761 curr_fo -> fo_fn = fn;
762 curr_fo -> fo_client_data = (ptr_t)cd;
763 curr_fo -> fo_mark_proc = mp;
765 /* Reinsert it. We deleted it first to maintain */
766 /* consistency in the event of a signal. */
768 GC_fnlz_roots.fo_head[index] = curr_fo;
770 fo_set_next(prev_fo, curr_fo);
775 GC_dirty(GC_fnlz_roots.fo_head + index);
777 # ifndef DBG_HDRS_ALL
778 if (EXPECT(new_fo != 0, FALSE)) {
779 /* Free unused new_fo returned by GC_oom_fn() */
780 GC_free((void *)new_fo);
786 curr_fo = fo_next(curr_fo);
788 if (EXPECT(new_fo != 0, FALSE)) {
789 /* new_fo is returned by GC_oom_fn(). */
792 if (NULL == hhdr) ABORT("Bad hhdr in GC_register_finalizer_inner");
803 if (EXPECT(0 == hhdr, FALSE)) {
804 /* We won't collect it, hence finalizer wouldn't be run. */
810 new_fo = (struct finalizable_object *)
811 GC_INTERNAL_MALLOC(sizeof(struct finalizable_object),NORMAL);
812 if (EXPECT(new_fo != 0, TRUE))
816 new_fo = (struct finalizable_object *)
817 (*oom_fn)(sizeof(struct finalizable_object));
819 /* No enough memory. *ocd and *ofn remains unchanged. */
822 /* It's not likely we'll make it here, but ... */
824 /* Recalculate index since the table may grow and */
825 /* check again that our finalizer is not in the table. */
827 GC_ASSERT(GC_size(new_fo) >= sizeof(struct finalizable_object));
830 new_fo -> fo_hidden_base = GC_HIDE_POINTER(obj);
831 new_fo -> fo_fn = fn;
832 new_fo -> fo_client_data = (ptr_t)cd;
833 new_fo -> fo_object_size = hhdr -> hb_sz;
834 new_fo -> fo_mark_proc = mp;
835 fo_set_next(new_fo, GC_fnlz_roots.fo_head[index]);
838 GC_fnlz_roots.fo_head[index] = new_fo;
839 GC_dirty(GC_fnlz_roots.fo_head + index);
843 GC_API void GC_CALL GC_register_finalizer(void * obj,
844 GC_finalization_proc fn, void * cd,
845 GC_finalization_proc *ofn, void ** ocd)
847 GC_register_finalizer_inner(obj, fn, cd, ofn,
848 ocd, GC_normal_finalize_mark_proc);
851 GC_API void GC_CALL GC_register_finalizer_ignore_self(void * obj,
852 GC_finalization_proc fn, void * cd,
853 GC_finalization_proc *ofn, void ** ocd)
855 GC_register_finalizer_inner(obj, fn, cd, ofn,
856 ocd, GC_ignore_self_finalize_mark_proc);
859 GC_API void GC_CALL GC_register_finalizer_no_order(void * obj,
860 GC_finalization_proc fn, void * cd,
861 GC_finalization_proc *ofn, void ** ocd)
863 GC_register_finalizer_inner(obj, fn, cd, ofn,
864 ocd, GC_null_finalize_mark_proc);
867 static GC_bool need_unreachable_finalization = FALSE;
868 /* Avoid the work if this isn't used. */
870 GC_API void GC_CALL GC_register_finalizer_unreachable(void * obj,
871 GC_finalization_proc fn, void * cd,
872 GC_finalization_proc *ofn, void ** ocd)
874 need_unreachable_finalization = TRUE;
875 GC_ASSERT(GC_java_finalization);
876 GC_register_finalizer_inner(obj, fn, cd, ofn,
877 ocd, GC_unreachable_finalize_mark_proc);
881 STATIC void GC_dump_finalization_links(
882 const struct dl_hashtbl_s *dl_hashtbl)
884 size_t dl_size = dl_hashtbl->log_size == -1 ? 0 :
885 (size_t)1 << dl_hashtbl->log_size;
888 for (i = 0; i < dl_size; i++) {
889 struct disappearing_link *curr_dl;
891 for (curr_dl = dl_hashtbl -> head[i]; curr_dl != 0;
892 curr_dl = dl_next(curr_dl)) {
893 ptr_t real_ptr = (ptr_t)GC_REVEAL_POINTER(curr_dl->dl_hidden_obj);
894 ptr_t real_link = (ptr_t)GC_REVEAL_POINTER(curr_dl->dl_hidden_link);
896 GC_printf("Object: %p, link: %p\n",
897 (void *)real_ptr, (void *)real_link);
902 GC_API void GC_CALL GC_dump_finalization(void)
904 struct finalizable_object * curr_fo;
905 size_t fo_size = log_fo_table_size == -1 ? 0 :
906 (size_t)1 << log_fo_table_size;
909 GC_printf("Disappearing (short) links:\n");
910 GC_dump_finalization_links(&GC_dl_hashtbl);
911 # ifndef GC_LONG_REFS_NOT_NEEDED
912 GC_printf("Disappearing long links:\n");
913 GC_dump_finalization_links(&GC_ll_hashtbl);
915 GC_printf("Finalizers:\n");
916 for (i = 0; i < fo_size; i++) {
917 for (curr_fo = GC_fnlz_roots.fo_head[i];
918 curr_fo != NULL; curr_fo = fo_next(curr_fo)) {
919 ptr_t real_ptr = (ptr_t)GC_REVEAL_POINTER(curr_fo->fo_hidden_base);
921 GC_printf("Finalizable object: %p\n", (void *)real_ptr);
925 #endif /* !NO_DEBUGGING */
928 STATIC word GC_old_dl_entries = 0; /* for stats printing */
929 # ifndef GC_LONG_REFS_NOT_NEEDED
930 STATIC word GC_old_ll_entries = 0;
932 #endif /* !SMALL_CONFIG */
935 /* Global variables to minimize the level of recursion when a client */
936 /* finalizer allocates memory. */
937 STATIC int GC_finalizer_nested = 0;
938 /* Only the lowest byte is used, the rest is */
939 /* padding for proper global data alignment */
940 /* required for some compilers (like Watcom). */
941 STATIC unsigned GC_finalizer_skipped = 0;
943 /* Checks and updates the level of finalizers recursion. */
944 /* Returns NULL if GC_invoke_finalizers() should not be called by the */
945 /* collector (to minimize the risk of a deep finalizers recursion), */
946 /* otherwise returns a pointer to GC_finalizer_nested. */
947 STATIC unsigned char *GC_check_finalizer_nested(void)
949 unsigned nesting_level = *(unsigned char *)&GC_finalizer_nested;
951 /* We are inside another GC_invoke_finalizers(). */
952 /* Skip some implicitly-called GC_invoke_finalizers() */
953 /* depending on the nesting (recursion) level. */
954 if (++GC_finalizer_skipped < (1U << nesting_level)) return NULL;
955 GC_finalizer_skipped = 0;
957 *(char *)&GC_finalizer_nested = (char)(nesting_level + 1);
958 return (unsigned char *)&GC_finalizer_nested;
962 GC_INLINE void GC_make_disappearing_links_disappear(
963 struct dl_hashtbl_s* dl_hashtbl,
964 GC_bool is_remove_dangling)
967 size_t dl_size = dl_hashtbl->log_size == -1 ? 0
968 : (size_t)1 << dl_hashtbl->log_size;
969 GC_bool needs_barrier = FALSE;
971 GC_ASSERT(I_HOLD_LOCK());
972 for (i = 0; i < dl_size; i++) {
973 struct disappearing_link *curr_dl, *next_dl;
974 struct disappearing_link *prev_dl = NULL;
976 for (curr_dl = dl_hashtbl->head[i]; curr_dl != NULL; curr_dl = next_dl) {
977 next_dl = dl_next(curr_dl);
978 if (is_remove_dangling) {
979 ptr_t real_link = (ptr_t)GC_base(GC_REVEAL_POINTER(
980 curr_dl->dl_hidden_link));
982 if (NULL == real_link || EXPECT(GC_is_marked(real_link), TRUE)) {
987 if (EXPECT(GC_is_marked((ptr_t)GC_REVEAL_POINTER(
988 curr_dl->dl_hidden_obj)), TRUE)) {
992 *(ptr_t *)GC_REVEAL_POINTER(curr_dl->dl_hidden_link) = NULL;
995 /* Delete curr_dl entry from dl_hashtbl. */
996 if (NULL == prev_dl) {
997 dl_hashtbl -> head[i] = next_dl;
998 needs_barrier = TRUE;
1000 dl_set_next(prev_dl, next_dl);
1003 GC_clear_mark_bit(curr_dl);
1004 dl_hashtbl -> entries--;
1008 GC_dirty(dl_hashtbl -> head); /* entire object */
1011 /* Called with held lock (but the world is running). */
1012 /* Cause disappearing links to disappear and unreachable objects to be */
1013 /* enqueued for finalization. */
1014 GC_INNER void GC_finalize(void)
1016 struct finalizable_object * curr_fo, * prev_fo, * next_fo;
1019 size_t fo_size = log_fo_table_size == -1 ? 0 :
1020 (size_t)1 << log_fo_table_size;
1021 GC_bool needs_barrier = FALSE;
1023 GC_ASSERT(I_HOLD_LOCK());
1024 # ifndef SMALL_CONFIG
1025 /* Save current GC_[dl/ll]_entries value for stats printing */
1026 GC_old_dl_entries = GC_dl_hashtbl.entries;
1027 # ifndef GC_LONG_REFS_NOT_NEEDED
1028 GC_old_ll_entries = GC_ll_hashtbl.entries;
1032 # ifndef GC_TOGGLE_REFS_NOT_NEEDED
1033 GC_mark_togglerefs();
1035 GC_make_disappearing_links_disappear(&GC_dl_hashtbl, FALSE);
1037 /* Mark all objects reachable via chains of 1 or more pointers */
1038 /* from finalizable objects. */
1039 GC_ASSERT(GC_mark_state == MS_NONE);
1040 for (i = 0; i < fo_size; i++) {
1041 for (curr_fo = GC_fnlz_roots.fo_head[i];
1042 curr_fo != NULL; curr_fo = fo_next(curr_fo)) {
1043 GC_ASSERT(GC_size(curr_fo) >= sizeof(struct finalizable_object));
1044 real_ptr = (ptr_t)GC_REVEAL_POINTER(curr_fo->fo_hidden_base);
1045 if (!GC_is_marked(real_ptr)) {
1046 GC_MARKED_FOR_FINALIZATION(real_ptr);
1047 GC_MARK_FO(real_ptr, curr_fo -> fo_mark_proc);
1048 if (GC_is_marked(real_ptr)) {
1049 WARN("Finalization cycle involving %p\n", real_ptr);
1054 /* Enqueue for finalization all objects that are still */
1056 GC_bytes_finalized = 0;
1057 for (i = 0; i < fo_size; i++) {
1058 curr_fo = GC_fnlz_roots.fo_head[i];
1060 while (curr_fo != 0) {
1061 real_ptr = (ptr_t)GC_REVEAL_POINTER(curr_fo->fo_hidden_base);
1062 if (!GC_is_marked(real_ptr)) {
1063 if (!GC_java_finalization) {
1064 GC_set_mark_bit(real_ptr);
1066 /* Delete from hash table */
1067 next_fo = fo_next(curr_fo);
1068 if (NULL == prev_fo) {
1069 GC_fnlz_roots.fo_head[i] = next_fo;
1070 if (GC_object_finalized_proc) {
1071 GC_dirty(GC_fnlz_roots.fo_head + i);
1073 needs_barrier = TRUE;
1076 fo_set_next(prev_fo, next_fo);
1080 if (GC_object_finalized_proc)
1081 GC_object_finalized_proc(real_ptr);
1083 /* Add to list of objects awaiting finalization. */
1084 fo_set_next(curr_fo, GC_fnlz_roots.finalize_now);
1086 SET_FINALIZE_NOW(curr_fo);
1087 /* unhide object pointer so any future collections will */
1089 curr_fo -> fo_hidden_base =
1090 (word)GC_REVEAL_POINTER(curr_fo -> fo_hidden_base);
1091 GC_bytes_finalized +=
1092 curr_fo -> fo_object_size
1093 + sizeof(struct finalizable_object);
1094 GC_ASSERT(GC_is_marked(GC_base(curr_fo)));
1098 curr_fo = fo_next(curr_fo);
1103 if (GC_java_finalization) {
1104 /* make sure we mark everything reachable from objects finalized
1105 using the no_order mark_proc */
1106 for (curr_fo = GC_fnlz_roots.finalize_now;
1107 curr_fo != NULL; curr_fo = fo_next(curr_fo)) {
1108 real_ptr = (ptr_t)curr_fo -> fo_hidden_base;
1109 if (!GC_is_marked(real_ptr)) {
1110 if (curr_fo -> fo_mark_proc == GC_null_finalize_mark_proc) {
1111 GC_MARK_FO(real_ptr, GC_normal_finalize_mark_proc);
1113 if (curr_fo -> fo_mark_proc != GC_unreachable_finalize_mark_proc) {
1114 GC_set_mark_bit(real_ptr);
1119 /* now revive finalize-when-unreachable objects reachable from
1120 other finalizable objects */
1121 if (need_unreachable_finalization) {
1122 curr_fo = GC_fnlz_roots.finalize_now;
1123 # if defined(GC_ASSERTIONS) || defined(LINT2)
1124 if (curr_fo != NULL && log_fo_table_size < 0)
1125 ABORT("log_size is negative");
1128 while (curr_fo != NULL) {
1129 next_fo = fo_next(curr_fo);
1130 if (curr_fo -> fo_mark_proc == GC_unreachable_finalize_mark_proc) {
1131 real_ptr = (ptr_t)curr_fo -> fo_hidden_base;
1132 if (!GC_is_marked(real_ptr)) {
1133 GC_set_mark_bit(real_ptr);
1135 if (NULL == prev_fo) {
1136 SET_FINALIZE_NOW(next_fo);
1138 fo_set_next(prev_fo, next_fo);
1141 curr_fo -> fo_hidden_base =
1142 GC_HIDE_POINTER(curr_fo -> fo_hidden_base);
1143 GC_bytes_finalized -=
1144 curr_fo->fo_object_size + sizeof(struct finalizable_object);
1146 i = HASH2(real_ptr, log_fo_table_size);
1147 fo_set_next(curr_fo, GC_fnlz_roots.fo_head[i]);
1150 GC_fnlz_roots.fo_head[i] = curr_fo;
1152 needs_barrier = TRUE;
1161 GC_dirty(GC_fnlz_roots.fo_head); /* entire object */
1163 /* Remove dangling disappearing links. */
1164 GC_make_disappearing_links_disappear(&GC_dl_hashtbl, TRUE);
1166 # ifndef GC_TOGGLE_REFS_NOT_NEEDED
1167 GC_clear_togglerefs();
1169 # ifndef GC_LONG_REFS_NOT_NEEDED
1170 GC_make_disappearing_links_disappear(&GC_ll_hashtbl, FALSE);
1171 GC_make_disappearing_links_disappear(&GC_ll_hashtbl, TRUE);
1174 if (GC_fail_count) {
1175 /* Don't prevent running finalizers if there has been an allocation */
1176 /* failure recently. */
1178 GC_reset_finalizer_nested();
1180 GC_finalizer_nested = 0;
1185 #ifndef JAVA_FINALIZATION_NOT_NEEDED
1187 /* Enqueue all remaining finalizers to be run. */
1188 STATIC void GC_enqueue_all_finalizers(void)
1190 struct finalizable_object * next_fo;
1194 GC_ASSERT(I_HOLD_LOCK());
1195 fo_size = log_fo_table_size == -1 ? 0 : 1 << log_fo_table_size;
1196 GC_bytes_finalized = 0;
1197 for (i = 0; i < fo_size; i++) {
1198 struct finalizable_object * curr_fo = GC_fnlz_roots.fo_head[i];
1200 GC_fnlz_roots.fo_head[i] = NULL;
1201 while (curr_fo != NULL) {
1202 ptr_t real_ptr = (ptr_t)GC_REVEAL_POINTER(curr_fo->fo_hidden_base);
1204 GC_MARK_FO(real_ptr, GC_normal_finalize_mark_proc);
1205 GC_set_mark_bit(real_ptr);
1207 next_fo = fo_next(curr_fo);
1209 /* Add to list of objects awaiting finalization. */
1210 fo_set_next(curr_fo, GC_fnlz_roots.finalize_now);
1212 SET_FINALIZE_NOW(curr_fo);
1214 /* unhide object pointer so any future collections will */
1216 curr_fo -> fo_hidden_base =
1217 (word)GC_REVEAL_POINTER(curr_fo -> fo_hidden_base);
1218 GC_bytes_finalized +=
1219 curr_fo -> fo_object_size + sizeof(struct finalizable_object);
1223 GC_fo_entries = 0; /* all entries deleted from the hash table */
1226 /* Invoke all remaining finalizers that haven't yet been run.
1227 * This is needed for strict compliance with the Java standard,
1228 * which can make the runtime guarantee that all finalizers are run.
1229 * Unfortunately, the Java standard implies we have to keep running
1230 * finalizers until there are no more left, a potential infinite loop.
1232 * Note that this is even more dangerous than the usual Java
1233 * finalizers, in that objects reachable from static variables
1234 * may have been finalized when these finalizers are run.
1235 * Finalizers run at this point must be prepared to deal with a
1236 * mostly broken world.
1237 * This routine is externally callable, so is called without
1238 * the allocation lock.
1240 GC_API void GC_CALL GC_finalize_all(void)
1245 while (GC_fo_entries > 0) {
1246 GC_enqueue_all_finalizers();
1248 GC_invoke_finalizers();
1249 /* Running the finalizers in this thread is arguably not a good */
1250 /* idea when we should be notifying another thread to run them. */
1251 /* But otherwise we don't have a great way to wait for them to */
1258 #endif /* !JAVA_FINALIZATION_NOT_NEEDED */
1260 /* Returns true if it is worth calling GC_invoke_finalizers. (Useful if */
1261 /* finalizers can only be called from some kind of "safe state" and */
1262 /* getting into that safe state is expensive.) */
1263 GC_API int GC_CALL GC_should_invoke_finalizers(void)
1265 # ifdef AO_HAVE_load
1266 return AO_load((volatile AO_t *)&GC_fnlz_roots.finalize_now) != 0;
1268 return GC_fnlz_roots.finalize_now != NULL;
1269 # endif /* !THREADS */
1272 /* Invoke finalizers for all objects that are ready to be finalized. */
1273 /* Should be called without allocation lock. */
1274 GC_API int GC_CALL GC_invoke_finalizers(void)
1277 word bytes_freed_before = 0; /* initialized to prevent warning. */
1280 while (GC_should_invoke_finalizers()) {
1281 struct finalizable_object * curr_fo;
1287 bytes_freed_before = GC_bytes_freed;
1288 /* Don't do this outside, since we need the lock. */
1290 curr_fo = GC_fnlz_roots.finalize_now;
1292 if (curr_fo != NULL)
1293 SET_FINALIZE_NOW(fo_next(curr_fo));
1295 if (curr_fo == 0) break;
1297 GC_fnlz_roots.finalize_now = fo_next(curr_fo);
1299 fo_set_next(curr_fo, 0);
1300 (*(curr_fo -> fo_fn))((ptr_t)(curr_fo -> fo_hidden_base),
1301 curr_fo -> fo_client_data);
1302 curr_fo -> fo_client_data = 0;
1304 /* Explicit freeing of curr_fo is probably a bad idea. */
1305 /* It throws off accounting if nearly all objects are */
1306 /* finalizable. Otherwise it should not matter. */
1308 /* bytes_freed_before is initialized whenever count != 0 */
1310 # if defined(THREADS) && !defined(THREAD_SANITIZER)
1311 /* A quick check whether some memory was freed. */
1312 /* The race with GC_free() is safe to be ignored */
1313 /* because we only need to know if the current */
1314 /* thread has deallocated something. */
1315 && bytes_freed_before != GC_bytes_freed
1319 GC_finalizer_bytes_freed += (GC_bytes_freed - bytes_freed_before);
1325 static word last_finalizer_notification = 0;
1327 GC_INNER void GC_notify_or_invoke_finalizers(void)
1329 GC_finalizer_notifier_proc notifier_fn = 0;
1330 # if defined(KEEP_BACK_PTRS) || defined(MAKE_BACK_GRAPH)
1331 static word last_back_trace_gc_no = 1; /* Skip first one. */
1335 # if defined(THREADS) && !defined(KEEP_BACK_PTRS) \
1336 && !defined(MAKE_BACK_GRAPH)
1337 /* Quick check (while unlocked) for an empty finalization queue. */
1338 if (!GC_should_invoke_finalizers())
1343 /* This is a convenient place to generate backtraces if appropriate, */
1344 /* since that code is not callable with the allocation lock. */
1345 # if defined(KEEP_BACK_PTRS) || defined(MAKE_BACK_GRAPH)
1346 if (GC_gc_no > last_back_trace_gc_no) {
1347 # ifdef KEEP_BACK_PTRS
1349 /* Stops when GC_gc_no wraps; that's OK. */
1350 last_back_trace_gc_no = GC_WORD_MAX; /* disable others. */
1351 for (i = 0; i < GC_backtraces; ++i) {
1352 /* FIXME: This tolerates concurrent heap mutation, */
1353 /* which may cause occasional mysterious results. */
1354 /* We need to release the GC lock, since GC_print_callers */
1355 /* acquires it. It probably shouldn't. */
1357 GC_generate_random_backtrace_no_gc();
1360 last_back_trace_gc_no = GC_gc_no;
1362 # ifdef MAKE_BACK_GRAPH
1363 if (GC_print_back_height) {
1364 GC_print_back_graph_stats();
1369 if (NULL == GC_fnlz_roots.finalize_now) {
1374 if (!GC_finalize_on_demand) {
1375 unsigned char *pnested = GC_check_finalizer_nested();
1377 /* Skip GC_invoke_finalizers() if nested */
1378 if (pnested != NULL) {
1379 (void) GC_invoke_finalizers();
1380 *pnested = 0; /* Reset since no more finalizers. */
1382 GC_ASSERT(NULL == GC_fnlz_roots.finalize_now);
1383 # endif /* Otherwise GC can run concurrently and add more */
1388 /* These variables require synchronization to avoid data races. */
1389 if (last_finalizer_notification != GC_gc_no) {
1390 notifier_fn = GC_finalizer_notifier;
1391 last_finalizer_notification = GC_gc_no;
1394 if (notifier_fn != 0)
1395 (*notifier_fn)(); /* Invoke the notifier */
1398 #ifndef SMALL_CONFIG
1399 # ifndef GC_LONG_REFS_NOT_NEEDED
1400 # define IF_LONG_REFS_PRESENT_ELSE(x,y) (x)
1402 # define IF_LONG_REFS_PRESENT_ELSE(x,y) (y)
1405 GC_INNER void GC_print_finalization_stats(void)
1407 struct finalizable_object *fo;
1408 unsigned long ready = 0;
1410 GC_log_printf("%lu finalization entries;"
1411 " %lu/%lu short/long disappearing links alive\n",
1412 (unsigned long)GC_fo_entries,
1413 (unsigned long)GC_dl_hashtbl.entries,
1414 (unsigned long)IF_LONG_REFS_PRESENT_ELSE(
1415 GC_ll_hashtbl.entries, 0));
1417 for (fo = GC_fnlz_roots.finalize_now; fo != NULL; fo = fo_next(fo))
1419 GC_log_printf("%lu finalization-ready objects;"
1420 " %ld/%ld short/long links cleared\n",
1422 (long)GC_old_dl_entries - (long)GC_dl_hashtbl.entries,
1423 (long)IF_LONG_REFS_PRESENT_ELSE(
1424 GC_old_ll_entries - GC_ll_hashtbl.entries, 0));
1426 #endif /* !SMALL_CONFIG */
1428 #endif /* !GC_NO_FINALIZATION */