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 if (log_old_size >= GC_ON_GROW_LOG_SIZE_MIN) {
128 IF_CANCEL(int cancel_state;)
130 DISABLE_CANCEL(cancel_state);
131 (void)GC_try_to_collect_inner(GC_never_stop_func);
132 RESTORE_CANCEL(cancel_state);
133 /* GC_finalize might decrease entries value. */
134 if (*entries_ptr < ((word)1 << log_old_size) - (*entries_ptr >> 2))
138 new_table = (struct hash_chain_entry **)
139 GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE(
140 (size_t)new_size * sizeof(struct hash_chain_entry *),
142 if (new_table == 0) {
144 ABORT("Insufficient space for initial table allocation");
149 for (i = 0; i < old_size; i++) {
152 ptr_t real_key = (ptr_t)GC_REVEAL_POINTER(p->hidden_key);
153 struct hash_chain_entry *next = p -> next;
154 size_t new_hash = HASH3(real_key, new_size, log_new_size);
156 p -> next = new_table[new_hash];
158 new_table[new_hash] = p;
162 *log_size_ptr = log_new_size;
164 GC_dirty(new_table); /* entire object */
167 GC_API int GC_CALL GC_register_disappearing_link(void * * link)
171 base = (ptr_t)GC_base(link);
173 ABORT("Bad arg to GC_register_disappearing_link");
174 return(GC_general_register_disappearing_link(link, base));
177 STATIC int GC_register_disappearing_link_inner(
178 struct dl_hashtbl_s *dl_hashtbl, void **link,
179 const void *obj, const char *tbl_log_name)
181 struct disappearing_link *curr_dl;
183 struct disappearing_link * new_dl;
186 if (EXPECT(GC_find_leak, FALSE)) return GC_UNIMPLEMENTED;
188 GC_ASSERT(obj != NULL && GC_base_C(obj) == obj);
189 if (dl_hashtbl -> log_size == -1
190 || dl_hashtbl -> entries > ((word)1 << dl_hashtbl -> log_size)) {
191 GC_grow_table((struct hash_chain_entry ***)&dl_hashtbl -> head,
192 &dl_hashtbl -> log_size, &dl_hashtbl -> entries);
194 if (dl_hashtbl->log_size < 0) ABORT("log_size is negative");
196 GC_COND_LOG_PRINTF("Grew %s table to %u entries\n", tbl_log_name,
197 1 << (unsigned)dl_hashtbl -> log_size);
199 index = HASH2(link, dl_hashtbl -> log_size);
200 for (curr_dl = dl_hashtbl -> head[index]; curr_dl != 0;
201 curr_dl = dl_next(curr_dl)) {
202 if (curr_dl -> dl_hidden_link == GC_HIDE_POINTER(link)) {
203 curr_dl -> dl_hidden_obj = GC_HIDE_POINTER(obj);
208 new_dl = (struct disappearing_link *)
209 GC_INTERNAL_MALLOC(sizeof(struct disappearing_link),NORMAL);
211 GC_oom_func oom_fn = GC_oom_fn;
213 new_dl = (struct disappearing_link *)
214 (*oom_fn)(sizeof(struct disappearing_link));
218 /* It's not likely we'll make it here, but ... */
220 /* Recalculate index since the table may grow. */
221 index = HASH2(link, dl_hashtbl -> log_size);
222 /* Check again that our disappearing link not in the table. */
223 for (curr_dl = dl_hashtbl -> head[index]; curr_dl != 0;
224 curr_dl = dl_next(curr_dl)) {
225 if (curr_dl -> dl_hidden_link == GC_HIDE_POINTER(link)) {
226 curr_dl -> dl_hidden_obj = GC_HIDE_POINTER(obj);
228 # ifndef DBG_HDRS_ALL
229 /* Free unused new_dl returned by GC_oom_fn() */
230 GC_free((void *)new_dl);
236 new_dl -> dl_hidden_obj = GC_HIDE_POINTER(obj);
237 new_dl -> dl_hidden_link = GC_HIDE_POINTER(link);
238 dl_set_next(new_dl, dl_hashtbl -> head[index]);
239 dl_hashtbl -> head[index] = new_dl;
240 dl_hashtbl -> entries++;
241 GC_dirty(dl_hashtbl->head + index);
247 GC_API int GC_CALL GC_general_register_disappearing_link(void * * link,
250 if (((word)link & (ALIGNMENT-1)) != 0 || !NONNULL_ARG_NOT_NULL(link))
251 ABORT("Bad arg to GC_general_register_disappearing_link");
252 return GC_register_disappearing_link_inner(&GC_dl_hashtbl, link, obj,
257 # define FREE_DL_ENTRY(curr_dl) dl_set_next(curr_dl, NULL)
259 # define FREE_DL_ENTRY(curr_dl) GC_free(curr_dl)
262 /* Unregisters given link and returns the link entry to free. */
263 GC_INLINE struct disappearing_link *GC_unregister_disappearing_link_inner(
264 struct dl_hashtbl_s *dl_hashtbl, void **link)
266 struct disappearing_link *curr_dl;
267 struct disappearing_link *prev_dl = NULL;
270 GC_ASSERT(I_HOLD_LOCK());
271 if (dl_hashtbl->log_size == -1)
272 return NULL; /* prevent integer shift by a negative amount */
274 index = HASH2(link, dl_hashtbl->log_size);
275 for (curr_dl = dl_hashtbl -> head[index]; curr_dl;
276 curr_dl = dl_next(curr_dl)) {
277 if (curr_dl -> dl_hidden_link == GC_HIDE_POINTER(link)) {
278 /* Remove found entry from the table. */
279 if (NULL == prev_dl) {
280 dl_hashtbl -> head[index] = dl_next(curr_dl);
281 GC_dirty(dl_hashtbl->head + index);
283 dl_set_next(prev_dl, dl_next(curr_dl));
286 dl_hashtbl -> entries--;
294 GC_API int GC_CALL GC_unregister_disappearing_link(void * * link)
296 struct disappearing_link *curr_dl;
299 if (((word)link & (ALIGNMENT-1)) != 0) return(0); /* Nothing to do. */
302 curr_dl = GC_unregister_disappearing_link_inner(&GC_dl_hashtbl, link);
304 if (NULL == curr_dl) return 0;
305 FREE_DL_ENTRY(curr_dl);
309 /* Toggle-ref support. */
310 #ifndef GC_TOGGLE_REFS_NOT_NEEDED
312 /* Lowest bit is used to distinguish between choices. */
314 GC_hidden_pointer weak_ref;
317 STATIC GC_toggleref_func GC_toggleref_callback = 0;
318 STATIC GCToggleRef *GC_toggleref_arr = NULL;
319 STATIC int GC_toggleref_array_size = 0;
320 STATIC int GC_toggleref_array_capacity = 0;
322 GC_INNER void GC_process_togglerefs(void)
326 GC_bool needs_barrier = FALSE;
328 GC_ASSERT(I_HOLD_LOCK());
329 for (i = 0; i < GC_toggleref_array_size; ++i) {
330 GCToggleRef r = GC_toggleref_arr[i];
331 void *obj = r.strong_ref;
333 if (((word)obj & 1) != 0) {
334 obj = GC_REVEAL_POINTER(r.weak_ref);
339 switch (GC_toggleref_callback(obj)) {
340 case GC_TOGGLE_REF_DROP:
342 case GC_TOGGLE_REF_STRONG:
343 GC_toggleref_arr[new_size++].strong_ref = obj;
344 needs_barrier = TRUE;
346 case GC_TOGGLE_REF_WEAK:
347 GC_toggleref_arr[new_size++].weak_ref = GC_HIDE_POINTER(obj);
350 ABORT("Bad toggle-ref status returned by callback");
354 if (new_size < GC_toggleref_array_size) {
355 BZERO(&GC_toggleref_arr[new_size],
356 (GC_toggleref_array_size - new_size) * sizeof(GCToggleRef));
357 GC_toggleref_array_size = new_size;
360 GC_dirty(GC_toggleref_arr); /* entire object */
363 STATIC void GC_normal_finalize_mark_proc(ptr_t);
365 static void push_and_mark_object(void *p)
367 GC_normal_finalize_mark_proc((ptr_t)p);
368 while (!GC_mark_stack_empty()) {
369 MARK_FROM_MARK_STACK();
372 if (GC_mark_state != MS_NONE) {
373 while (!GC_mark_some(0)) {
379 STATIC void GC_mark_togglerefs(void)
382 if (NULL == GC_toggleref_arr)
385 /* TODO: Hide GC_toggleref_arr to avoid its marking from roots. */
386 GC_set_mark_bit(GC_toggleref_arr);
387 for (i = 0; i < GC_toggleref_array_size; ++i) {
388 void *obj = GC_toggleref_arr[i].strong_ref;
389 if (obj != NULL && ((word)obj & 1) == 0) {
390 push_and_mark_object(obj);
395 STATIC void GC_clear_togglerefs(void)
398 for (i = 0; i < GC_toggleref_array_size; ++i) {
399 if ((GC_toggleref_arr[i].weak_ref & 1) != 0) {
400 if (!GC_is_marked(GC_REVEAL_POINTER(GC_toggleref_arr[i].weak_ref))) {
401 GC_toggleref_arr[i].weak_ref = 0;
403 /* No need to copy, BDWGC is a non-moving collector. */
409 GC_API void GC_CALL GC_set_toggleref_func(GC_toggleref_func fn)
414 GC_toggleref_callback = fn;
418 GC_API GC_toggleref_func GC_CALL GC_get_toggleref_func(void)
420 GC_toggleref_func fn;
424 fn = GC_toggleref_callback;
429 static GC_bool ensure_toggleref_capacity(int capacity_inc)
431 GC_ASSERT(capacity_inc >= 0);
432 GC_ASSERT(I_HOLD_LOCK());
433 if (NULL == GC_toggleref_arr) {
434 GC_toggleref_array_capacity = 32; /* initial capacity */
435 GC_toggleref_arr = (GCToggleRef *)GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE(
436 GC_toggleref_array_capacity * sizeof(GCToggleRef),
438 if (NULL == GC_toggleref_arr)
441 if ((unsigned)GC_toggleref_array_size + (unsigned)capacity_inc
442 >= (unsigned)GC_toggleref_array_capacity) {
443 GCToggleRef *new_array;
444 while ((unsigned)GC_toggleref_array_capacity
445 < (unsigned)GC_toggleref_array_size + (unsigned)capacity_inc) {
446 GC_toggleref_array_capacity *= 2;
447 if (GC_toggleref_array_capacity < 0) /* overflow */
451 new_array = (GCToggleRef *)GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE(
452 GC_toggleref_array_capacity * sizeof(GCToggleRef),
454 if (NULL == new_array)
456 if (EXPECT(GC_toggleref_array_size > 0, TRUE))
457 BCOPY(GC_toggleref_arr, new_array,
458 GC_toggleref_array_size * sizeof(GCToggleRef));
459 GC_INTERNAL_FREE(GC_toggleref_arr);
460 GC_toggleref_arr = new_array;
465 GC_API int GC_CALL GC_toggleref_add(void *obj, int is_strong_ref)
467 int res = GC_SUCCESS;
470 GC_ASSERT(NONNULL_ARG_NOT_NULL(obj));
472 if (GC_toggleref_callback != 0) {
473 if (!ensure_toggleref_capacity(1)) {
476 GC_toggleref_arr[GC_toggleref_array_size].strong_ref =
477 is_strong_ref ? obj : (void *)GC_HIDE_POINTER(obj);
479 GC_dirty(GC_toggleref_arr + GC_toggleref_array_size);
480 GC_toggleref_array_size++;
486 #endif /* !GC_TOGGLE_REFS_NOT_NEEDED */
488 /* Finalizer callback support. */
489 STATIC GC_await_finalize_proc GC_object_finalized_proc = 0;
491 GC_API void GC_CALL GC_set_await_finalize_proc(GC_await_finalize_proc fn)
496 GC_object_finalized_proc = fn;
500 GC_API GC_await_finalize_proc GC_CALL GC_get_await_finalize_proc(void)
502 GC_await_finalize_proc fn;
506 fn = GC_object_finalized_proc;
511 #ifndef GC_LONG_REFS_NOT_NEEDED
512 GC_API int GC_CALL GC_register_long_link(void * * link, const void * obj)
514 if (((word)link & (ALIGNMENT-1)) != 0 || !NONNULL_ARG_NOT_NULL(link))
515 ABORT("Bad arg to GC_register_long_link");
516 return GC_register_disappearing_link_inner(&GC_ll_hashtbl, link, obj,
520 GC_API int GC_CALL GC_unregister_long_link(void * * link)
522 struct disappearing_link *curr_dl;
525 if (((word)link & (ALIGNMENT-1)) != 0) return(0); /* Nothing to do. */
528 curr_dl = GC_unregister_disappearing_link_inner(&GC_ll_hashtbl, link);
530 if (NULL == curr_dl) return 0;
531 FREE_DL_ENTRY(curr_dl);
534 #endif /* !GC_LONG_REFS_NOT_NEEDED */
536 #ifndef GC_MOVE_DISAPPEARING_LINK_NOT_NEEDED
537 /* Moves a link. Assume the lock is held. */
538 STATIC int GC_move_disappearing_link_inner(
539 struct dl_hashtbl_s *dl_hashtbl,
540 void **link, void **new_link)
542 struct disappearing_link *curr_dl, *prev_dl, *new_dl;
543 size_t curr_index, new_index;
544 word curr_hidden_link;
545 word new_hidden_link;
547 GC_ASSERT(I_HOLD_LOCK());
548 if (dl_hashtbl->log_size == -1)
549 return GC_NOT_FOUND; /* prevent integer shift by a negative amount */
551 /* Find current link. */
552 curr_index = HASH2(link, dl_hashtbl -> log_size);
553 curr_hidden_link = GC_HIDE_POINTER(link);
555 for (curr_dl = dl_hashtbl -> head[curr_index]; curr_dl;
556 curr_dl = dl_next(curr_dl)) {
557 if (curr_dl -> dl_hidden_link == curr_hidden_link)
562 if (NULL == curr_dl) {
566 if (link == new_link) {
567 return GC_SUCCESS; /* Nothing to do. */
570 /* link found; now check new_link not present. */
571 new_index = HASH2(new_link, dl_hashtbl -> log_size);
572 new_hidden_link = GC_HIDE_POINTER(new_link);
573 for (new_dl = dl_hashtbl -> head[new_index]; new_dl;
574 new_dl = dl_next(new_dl)) {
575 if (new_dl -> dl_hidden_link == new_hidden_link) {
576 /* Target already registered; bail. */
581 /* Remove from old, add to new, update link. */
582 if (NULL == prev_dl) {
583 dl_hashtbl -> head[curr_index] = dl_next(curr_dl);
585 dl_set_next(prev_dl, dl_next(curr_dl));
588 curr_dl -> dl_hidden_link = new_hidden_link;
589 dl_set_next(curr_dl, dl_hashtbl -> head[new_index]);
590 dl_hashtbl -> head[new_index] = curr_dl;
592 GC_dirty(dl_hashtbl->head); /* entire object */
596 GC_API int GC_CALL GC_move_disappearing_link(void **link, void **new_link)
601 if (((word)new_link & (ALIGNMENT-1)) != 0
602 || !NONNULL_ARG_NOT_NULL(new_link))
603 ABORT("Bad new_link arg to GC_move_disappearing_link");
604 if (((word)link & (ALIGNMENT-1)) != 0)
605 return GC_NOT_FOUND; /* Nothing to do. */
608 result = GC_move_disappearing_link_inner(&GC_dl_hashtbl, link, new_link);
613 # ifndef GC_LONG_REFS_NOT_NEEDED
614 GC_API int GC_CALL GC_move_long_link(void **link, void **new_link)
619 if (((word)new_link & (ALIGNMENT-1)) != 0
620 || !NONNULL_ARG_NOT_NULL(new_link))
621 ABORT("Bad new_link arg to GC_move_long_link");
622 if (((word)link & (ALIGNMENT-1)) != 0)
623 return GC_NOT_FOUND; /* Nothing to do. */
626 result = GC_move_disappearing_link_inner(&GC_ll_hashtbl, link, new_link);
630 # endif /* !GC_LONG_REFS_NOT_NEEDED */
631 #endif /* !GC_MOVE_DISAPPEARING_LINK_NOT_NEEDED */
633 /* Possible finalization_marker procedures. Note that mark stack */
634 /* overflow is handled by the caller, and is not a disaster. */
635 STATIC void GC_normal_finalize_mark_proc(ptr_t p)
639 PUSH_OBJ(p, hhdr, GC_mark_stack_top,
640 &(GC_mark_stack[GC_mark_stack_size]));
643 /* This only pays very partial attention to the mark descriptor. */
644 /* It does the right thing for normal and atomic objects, and treats */
645 /* most others as normal. */
646 STATIC void GC_ignore_self_finalize_mark_proc(ptr_t p)
649 word descr = hhdr -> hb_descr;
652 ptr_t target_limit = p + hhdr -> hb_sz - 1;
654 if ((descr & GC_DS_TAGS) == GC_DS_LENGTH) {
655 scan_limit = p + descr - sizeof(word);
657 scan_limit = target_limit + 1 - sizeof(word);
659 for (q = p; (word)q <= (word)scan_limit; q += ALIGNMENT) {
662 if (r < (word)p || r > (word)target_limit) {
663 GC_PUSH_ONE_HEAP(r, q, GC_mark_stack_top);
668 STATIC void GC_null_finalize_mark_proc(ptr_t p GC_ATTR_UNUSED) {}
670 /* Possible finalization_marker procedures. Note that mark stack */
671 /* overflow is handled by the caller, and is not a disaster. */
673 /* GC_unreachable_finalize_mark_proc is an alias for normal marking, */
674 /* but it is explicitly tested for, and triggers different */
675 /* behavior. Objects registered in this way are not finalized */
676 /* if they are reachable by other finalizable objects, even if those */
677 /* other objects specify no ordering. */
678 STATIC void GC_unreachable_finalize_mark_proc(ptr_t p)
680 GC_normal_finalize_mark_proc(p);
683 /* Register a finalization function. See gc.h for details. */
684 /* The last parameter is a procedure that determines */
685 /* marking for finalization ordering. Any objects marked */
686 /* by that procedure will be guaranteed to not have been */
687 /* finalized when this finalizer is invoked. */
688 STATIC void GC_register_finalizer_inner(void * obj,
689 GC_finalization_proc fn, void *cd,
690 GC_finalization_proc *ofn, void **ocd,
691 finalization_mark_proc mp)
693 struct finalizable_object * curr_fo;
695 struct finalizable_object *new_fo = 0;
696 hdr *hhdr = NULL; /* initialized to prevent warning. */
699 if (EXPECT(GC_find_leak, FALSE)) return;
701 if (log_fo_table_size == -1
702 || GC_fo_entries > ((word)1 << log_fo_table_size)) {
703 GC_grow_table((struct hash_chain_entry ***)&GC_fnlz_roots.fo_head,
704 &log_fo_table_size, &GC_fo_entries);
706 if (log_fo_table_size < 0) ABORT("log_size is negative");
708 GC_COND_LOG_PRINTF("Grew fo table to %u entries\n",
709 1 << (unsigned)log_fo_table_size);
711 /* in the THREADS case we hold allocation lock. */
713 struct finalizable_object *prev_fo = NULL;
716 index = HASH2(obj, log_fo_table_size);
717 curr_fo = GC_fnlz_roots.fo_head[index];
718 while (curr_fo != 0) {
719 GC_ASSERT(GC_size(curr_fo) >= sizeof(struct finalizable_object));
720 if (curr_fo -> fo_hidden_base == GC_HIDE_POINTER(obj)) {
721 /* Interruption by a signal in the middle of this */
722 /* should be safe. The client may see only *ocd */
723 /* updated, but we'll declare that to be his problem. */
724 if (ocd) *ocd = (void *) (curr_fo -> fo_client_data);
725 if (ofn) *ofn = curr_fo -> fo_fn;
726 /* Delete the structure for obj. */
728 GC_fnlz_roots.fo_head[index] = fo_next(curr_fo);
730 fo_set_next(prev_fo, fo_next(curr_fo));
735 /* May not happen if we get a signal. But a high */
736 /* estimate will only make the table larger than */
738 # if !defined(THREADS) && !defined(DBG_HDRS_ALL)
739 GC_free((void *)curr_fo);
742 curr_fo -> fo_fn = fn;
743 curr_fo -> fo_client_data = (ptr_t)cd;
744 curr_fo -> fo_mark_proc = mp;
746 /* Reinsert it. We deleted it first to maintain */
747 /* consistency in the event of a signal. */
749 GC_fnlz_roots.fo_head[index] = curr_fo;
751 fo_set_next(prev_fo, curr_fo);
756 GC_dirty(GC_fnlz_roots.fo_head + index);
758 # ifndef DBG_HDRS_ALL
759 if (EXPECT(new_fo != 0, FALSE)) {
760 /* Free unused new_fo returned by GC_oom_fn() */
761 GC_free((void *)new_fo);
767 curr_fo = fo_next(curr_fo);
769 if (EXPECT(new_fo != 0, FALSE)) {
770 /* new_fo is returned by GC_oom_fn(). */
773 if (NULL == hhdr) ABORT("Bad hhdr in GC_register_finalizer_inner");
784 if (EXPECT(0 == hhdr, FALSE)) {
785 /* We won't collect it, hence finalizer wouldn't be run. */
791 new_fo = (struct finalizable_object *)
792 GC_INTERNAL_MALLOC(sizeof(struct finalizable_object),NORMAL);
793 if (EXPECT(new_fo != 0, TRUE))
797 new_fo = (struct finalizable_object *)
798 (*oom_fn)(sizeof(struct finalizable_object));
800 /* No enough memory. *ocd and *ofn remains unchanged. */
803 /* It's not likely we'll make it here, but ... */
805 /* Recalculate index since the table may grow and */
806 /* check again that our finalizer is not in the table. */
808 GC_ASSERT(GC_size(new_fo) >= sizeof(struct finalizable_object));
811 new_fo -> fo_hidden_base = GC_HIDE_POINTER(obj);
812 new_fo -> fo_fn = fn;
813 new_fo -> fo_client_data = (ptr_t)cd;
814 new_fo -> fo_object_size = hhdr -> hb_sz;
815 new_fo -> fo_mark_proc = mp;
816 fo_set_next(new_fo, GC_fnlz_roots.fo_head[index]);
818 GC_fnlz_roots.fo_head[index] = new_fo;
819 GC_dirty(GC_fnlz_roots.fo_head + index);
824 GC_API void GC_CALL GC_register_finalizer(void * obj,
825 GC_finalization_proc fn, void * cd,
826 GC_finalization_proc *ofn, void ** ocd)
828 GC_register_finalizer_inner(obj, fn, cd, ofn,
829 ocd, GC_normal_finalize_mark_proc);
832 GC_API void GC_CALL GC_register_finalizer_ignore_self(void * obj,
833 GC_finalization_proc fn, void * cd,
834 GC_finalization_proc *ofn, void ** ocd)
836 GC_register_finalizer_inner(obj, fn, cd, ofn,
837 ocd, GC_ignore_self_finalize_mark_proc);
840 GC_API void GC_CALL GC_register_finalizer_no_order(void * obj,
841 GC_finalization_proc fn, void * cd,
842 GC_finalization_proc *ofn, void ** ocd)
844 GC_register_finalizer_inner(obj, fn, cd, ofn,
845 ocd, GC_null_finalize_mark_proc);
848 static GC_bool need_unreachable_finalization = FALSE;
849 /* Avoid the work if this isn't used. */
851 GC_API void GC_CALL GC_register_finalizer_unreachable(void * obj,
852 GC_finalization_proc fn, void * cd,
853 GC_finalization_proc *ofn, void ** ocd)
855 need_unreachable_finalization = TRUE;
856 GC_ASSERT(GC_java_finalization);
857 GC_register_finalizer_inner(obj, fn, cd, ofn,
858 ocd, GC_unreachable_finalize_mark_proc);
862 STATIC void GC_dump_finalization_links(
863 const struct dl_hashtbl_s *dl_hashtbl)
865 size_t dl_size = dl_hashtbl->log_size == -1 ? 0 :
866 (size_t)1 << dl_hashtbl->log_size;
869 for (i = 0; i < dl_size; i++) {
870 struct disappearing_link *curr_dl;
872 for (curr_dl = dl_hashtbl -> head[i]; curr_dl != 0;
873 curr_dl = dl_next(curr_dl)) {
874 ptr_t real_ptr = (ptr_t)GC_REVEAL_POINTER(curr_dl->dl_hidden_obj);
875 ptr_t real_link = (ptr_t)GC_REVEAL_POINTER(curr_dl->dl_hidden_link);
877 GC_printf("Object: %p, link: %p\n",
878 (void *)real_ptr, (void *)real_link);
883 GC_API void GC_CALL GC_dump_finalization(void)
885 struct finalizable_object * curr_fo;
886 size_t fo_size = log_fo_table_size == -1 ? 0 :
887 (size_t)1 << log_fo_table_size;
890 GC_printf("Disappearing (short) links:\n");
891 GC_dump_finalization_links(&GC_dl_hashtbl);
892 # ifndef GC_LONG_REFS_NOT_NEEDED
893 GC_printf("Disappearing long links:\n");
894 GC_dump_finalization_links(&GC_ll_hashtbl);
896 GC_printf("Finalizers:\n");
897 for (i = 0; i < fo_size; i++) {
898 for (curr_fo = GC_fnlz_roots.fo_head[i];
899 curr_fo != NULL; curr_fo = fo_next(curr_fo)) {
900 ptr_t real_ptr = (ptr_t)GC_REVEAL_POINTER(curr_fo->fo_hidden_base);
902 GC_printf("Finalizable object: %p\n", (void *)real_ptr);
906 #endif /* !NO_DEBUGGING */
909 STATIC word GC_old_dl_entries = 0; /* for stats printing */
910 # ifndef GC_LONG_REFS_NOT_NEEDED
911 STATIC word GC_old_ll_entries = 0;
913 #endif /* !SMALL_CONFIG */
916 /* Global variables to minimize the level of recursion when a client */
917 /* finalizer allocates memory. */
918 STATIC int GC_finalizer_nested = 0;
919 /* Only the lowest byte is used, the rest is */
920 /* padding for proper global data alignment */
921 /* required for some compilers (like Watcom). */
922 STATIC unsigned GC_finalizer_skipped = 0;
924 /* Checks and updates the level of finalizers recursion. */
925 /* Returns NULL if GC_invoke_finalizers() should not be called by the */
926 /* collector (to minimize the risk of a deep finalizers recursion), */
927 /* otherwise returns a pointer to GC_finalizer_nested. */
928 STATIC unsigned char *GC_check_finalizer_nested(void)
930 unsigned nesting_level = *(unsigned char *)&GC_finalizer_nested;
932 /* We are inside another GC_invoke_finalizers(). */
933 /* Skip some implicitly-called GC_invoke_finalizers() */
934 /* depending on the nesting (recursion) level. */
935 if (++GC_finalizer_skipped < (1U << nesting_level)) return NULL;
936 GC_finalizer_skipped = 0;
938 *(char *)&GC_finalizer_nested = (char)(nesting_level + 1);
939 return (unsigned char *)&GC_finalizer_nested;
943 #define ITERATE_DL_HASHTBL_BEGIN(dl_hashtbl, curr_dl, prev_dl) \
946 size_t dl_size = dl_hashtbl->log_size == -1 ? 0 : \
947 (size_t)1 << dl_hashtbl->log_size; \
948 GC_bool needs_barrier = FALSE; \
949 GC_ASSERT(I_HOLD_LOCK()); \
950 for (i = 0; i < dl_size; i++) { \
951 struct disappearing_link *prev_dl = NULL; \
952 curr_dl = dl_hashtbl -> head[i]; \
955 #define ITERATE_DL_HASHTBL_END(curr_dl, prev_dl) \
957 curr_dl = dl_next(curr_dl); \
961 GC_dirty(dl_hashtbl -> head); /* entire object */ \
964 #define DELETE_DL_HASHTBL_ENTRY(dl_hashtbl, curr_dl, prev_dl, next_dl) \
966 next_dl = dl_next(curr_dl); \
967 if (NULL == prev_dl) { \
968 dl_hashtbl -> head[i] = next_dl; \
969 needs_barrier = TRUE; \
971 dl_set_next(prev_dl, next_dl); \
974 GC_clear_mark_bit(curr_dl); \
975 dl_hashtbl -> entries--; \
980 GC_INLINE void GC_make_disappearing_links_disappear(
981 struct dl_hashtbl_s* dl_hashtbl)
983 struct disappearing_link *curr, *next;
985 ITERATE_DL_HASHTBL_BEGIN(dl_hashtbl, curr, prev)
986 ptr_t real_ptr = (ptr_t)GC_REVEAL_POINTER(curr->dl_hidden_obj);
987 ptr_t real_link = (ptr_t)GC_REVEAL_POINTER(curr->dl_hidden_link);
989 if (!GC_is_marked(real_ptr)) {
990 *(word *)real_link = 0;
991 GC_clear_mark_bit(curr);
992 DELETE_DL_HASHTBL_ENTRY(dl_hashtbl, curr, prev, next);
994 ITERATE_DL_HASHTBL_END(curr, prev)
997 GC_INLINE void GC_remove_dangling_disappearing_links(
998 struct dl_hashtbl_s* dl_hashtbl)
1000 struct disappearing_link *curr, *next;
1002 ITERATE_DL_HASHTBL_BEGIN(dl_hashtbl, curr, prev)
1004 (ptr_t)GC_base(GC_REVEAL_POINTER(curr->dl_hidden_link));
1006 if (NULL != real_link && !GC_is_marked(real_link)) {
1007 GC_clear_mark_bit(curr);
1008 DELETE_DL_HASHTBL_ENTRY(dl_hashtbl, curr, prev, next);
1010 ITERATE_DL_HASHTBL_END(curr, prev)
1013 /* Called with held lock (but the world is running). */
1014 /* Cause disappearing links to disappear and unreachable objects to be */
1015 /* enqueued for finalization. */
1016 GC_INNER void GC_finalize(void)
1018 struct finalizable_object * curr_fo, * prev_fo, * next_fo;
1021 size_t fo_size = log_fo_table_size == -1 ? 0 :
1022 (size_t)1 << log_fo_table_size;
1023 GC_bool needs_barrier = FALSE;
1025 GC_ASSERT(I_HOLD_LOCK());
1026 # ifndef SMALL_CONFIG
1027 /* Save current GC_[dl/ll]_entries value for stats printing */
1028 GC_old_dl_entries = GC_dl_hashtbl.entries;
1029 # ifndef GC_LONG_REFS_NOT_NEEDED
1030 GC_old_ll_entries = GC_ll_hashtbl.entries;
1034 # ifndef GC_TOGGLE_REFS_NOT_NEEDED
1035 GC_mark_togglerefs();
1037 GC_make_disappearing_links_disappear(&GC_dl_hashtbl);
1039 /* Mark all objects reachable via chains of 1 or more pointers */
1040 /* from finalizable objects. */
1041 GC_ASSERT(GC_mark_state == MS_NONE);
1042 for (i = 0; i < fo_size; i++) {
1043 for (curr_fo = GC_fnlz_roots.fo_head[i];
1044 curr_fo != NULL; curr_fo = fo_next(curr_fo)) {
1045 GC_ASSERT(GC_size(curr_fo) >= sizeof(struct finalizable_object));
1046 real_ptr = (ptr_t)GC_REVEAL_POINTER(curr_fo->fo_hidden_base);
1047 if (!GC_is_marked(real_ptr)) {
1048 GC_MARKED_FOR_FINALIZATION(real_ptr);
1049 GC_MARK_FO(real_ptr, curr_fo -> fo_mark_proc);
1050 if (GC_is_marked(real_ptr)) {
1051 WARN("Finalization cycle involving %p\n", real_ptr);
1056 /* Enqueue for finalization all objects that are still */
1058 GC_bytes_finalized = 0;
1059 for (i = 0; i < fo_size; i++) {
1060 curr_fo = GC_fnlz_roots.fo_head[i];
1062 while (curr_fo != 0) {
1063 real_ptr = (ptr_t)GC_REVEAL_POINTER(curr_fo->fo_hidden_base);
1064 if (!GC_is_marked(real_ptr)) {
1065 if (!GC_java_finalization) {
1066 GC_set_mark_bit(real_ptr);
1068 /* Delete from hash table */
1069 next_fo = fo_next(curr_fo);
1070 if (NULL == prev_fo) {
1071 GC_fnlz_roots.fo_head[i] = next_fo;
1072 needs_barrier = TRUE;
1074 fo_set_next(prev_fo, next_fo);
1078 if (GC_object_finalized_proc)
1079 GC_object_finalized_proc(real_ptr);
1081 /* Add to list of objects awaiting finalization. */
1082 fo_set_next(curr_fo, GC_fnlz_roots.finalize_now);
1084 SET_FINALIZE_NOW(curr_fo);
1085 /* unhide object pointer so any future collections will */
1087 curr_fo -> fo_hidden_base =
1088 (word)GC_REVEAL_POINTER(curr_fo -> fo_hidden_base);
1089 GC_bytes_finalized +=
1090 curr_fo -> fo_object_size
1091 + sizeof(struct finalizable_object);
1092 GC_ASSERT(GC_is_marked(GC_base(curr_fo)));
1096 curr_fo = fo_next(curr_fo);
1101 if (GC_java_finalization) {
1102 /* make sure we mark everything reachable from objects finalized
1103 using the no_order mark_proc */
1104 for (curr_fo = GC_fnlz_roots.finalize_now;
1105 curr_fo != NULL; curr_fo = fo_next(curr_fo)) {
1106 real_ptr = (ptr_t)curr_fo -> fo_hidden_base;
1107 if (!GC_is_marked(real_ptr)) {
1108 if (curr_fo -> fo_mark_proc == GC_null_finalize_mark_proc) {
1109 GC_MARK_FO(real_ptr, GC_normal_finalize_mark_proc);
1111 if (curr_fo -> fo_mark_proc != GC_unreachable_finalize_mark_proc) {
1112 GC_set_mark_bit(real_ptr);
1117 /* now revive finalize-when-unreachable objects reachable from
1118 other finalizable objects */
1119 if (need_unreachable_finalization) {
1120 curr_fo = GC_fnlz_roots.finalize_now;
1121 # if defined(GC_ASSERTIONS) || defined(LINT2)
1122 if (curr_fo != NULL && log_fo_table_size < 0)
1123 ABORT("log_size is negative");
1126 while (curr_fo != NULL) {
1127 next_fo = fo_next(curr_fo);
1128 if (curr_fo -> fo_mark_proc == GC_unreachable_finalize_mark_proc) {
1129 real_ptr = (ptr_t)curr_fo -> fo_hidden_base;
1130 if (!GC_is_marked(real_ptr)) {
1131 GC_set_mark_bit(real_ptr);
1133 if (NULL == prev_fo) {
1134 SET_FINALIZE_NOW(next_fo);
1136 fo_set_next(prev_fo, next_fo);
1139 curr_fo -> fo_hidden_base =
1140 GC_HIDE_POINTER(curr_fo -> fo_hidden_base);
1141 GC_bytes_finalized -=
1142 curr_fo->fo_object_size + sizeof(struct finalizable_object);
1144 i = HASH2(real_ptr, log_fo_table_size);
1145 fo_set_next(curr_fo, GC_fnlz_roots.fo_head[i]);
1148 GC_fnlz_roots.fo_head[i] = curr_fo;
1150 needs_barrier = TRUE;
1159 GC_dirty(GC_fnlz_roots.fo_head); /* entire object */
1161 GC_remove_dangling_disappearing_links(&GC_dl_hashtbl);
1162 # ifndef GC_TOGGLE_REFS_NOT_NEEDED
1163 GC_clear_togglerefs();
1165 # ifndef GC_LONG_REFS_NOT_NEEDED
1166 GC_make_disappearing_links_disappear(&GC_ll_hashtbl);
1167 GC_remove_dangling_disappearing_links(&GC_ll_hashtbl);
1170 if (GC_fail_count) {
1171 /* Don't prevent running finalizers if there has been an allocation */
1172 /* failure recently. */
1174 GC_reset_finalizer_nested();
1176 GC_finalizer_nested = 0;
1181 #ifndef JAVA_FINALIZATION_NOT_NEEDED
1183 /* Enqueue all remaining finalizers to be run. */
1184 STATIC void GC_enqueue_all_finalizers(void)
1186 struct finalizable_object * next_fo;
1190 GC_ASSERT(I_HOLD_LOCK());
1191 fo_size = log_fo_table_size == -1 ? 0 : 1 << log_fo_table_size;
1192 GC_bytes_finalized = 0;
1193 for (i = 0; i < fo_size; i++) {
1194 struct finalizable_object * curr_fo = GC_fnlz_roots.fo_head[i];
1196 GC_fnlz_roots.fo_head[i] = NULL;
1197 while (curr_fo != NULL) {
1198 ptr_t real_ptr = (ptr_t)GC_REVEAL_POINTER(curr_fo->fo_hidden_base);
1200 GC_MARK_FO(real_ptr, GC_normal_finalize_mark_proc);
1201 GC_set_mark_bit(real_ptr);
1203 next_fo = fo_next(curr_fo);
1205 /* Add to list of objects awaiting finalization. */
1206 fo_set_next(curr_fo, GC_fnlz_roots.finalize_now);
1208 SET_FINALIZE_NOW(curr_fo);
1210 /* unhide object pointer so any future collections will */
1212 curr_fo -> fo_hidden_base =
1213 (word)GC_REVEAL_POINTER(curr_fo -> fo_hidden_base);
1214 GC_bytes_finalized +=
1215 curr_fo -> fo_object_size + sizeof(struct finalizable_object);
1219 GC_fo_entries = 0; /* all entries deleted from the hash table */
1222 /* Invoke all remaining finalizers that haven't yet been run.
1223 * This is needed for strict compliance with the Java standard,
1224 * which can make the runtime guarantee that all finalizers are run.
1225 * Unfortunately, the Java standard implies we have to keep running
1226 * finalizers until there are no more left, a potential infinite loop.
1228 * Note that this is even more dangerous than the usual Java
1229 * finalizers, in that objects reachable from static variables
1230 * may have been finalized when these finalizers are run.
1231 * Finalizers run at this point must be prepared to deal with a
1232 * mostly broken world.
1233 * This routine is externally callable, so is called without
1234 * the allocation lock.
1236 GC_API void GC_CALL GC_finalize_all(void)
1241 while (GC_fo_entries > 0) {
1242 GC_enqueue_all_finalizers();
1244 GC_invoke_finalizers();
1245 /* Running the finalizers in this thread is arguably not a good */
1246 /* idea when we should be notifying another thread to run them. */
1247 /* But otherwise we don't have a great way to wait for them to */
1254 #endif /* !JAVA_FINALIZATION_NOT_NEEDED */
1256 /* Returns true if it is worth calling GC_invoke_finalizers. (Useful if */
1257 /* finalizers can only be called from some kind of "safe state" and */
1258 /* getting into that safe state is expensive.) */
1259 GC_API int GC_CALL GC_should_invoke_finalizers(void)
1261 # ifdef AO_HAVE_load
1262 return AO_load((volatile AO_t *)&GC_fnlz_roots.finalize_now) != 0;
1264 return GC_fnlz_roots.finalize_now != NULL;
1265 # endif /* !THREADS */
1268 /* Invoke finalizers for all objects that are ready to be finalized. */
1269 /* Should be called without allocation lock. */
1270 GC_API int GC_CALL GC_invoke_finalizers(void)
1273 word bytes_freed_before = 0; /* initialized to prevent warning. */
1276 while (GC_should_invoke_finalizers()) {
1277 struct finalizable_object * curr_fo;
1283 bytes_freed_before = GC_bytes_freed;
1284 /* Don't do this outside, since we need the lock. */
1286 curr_fo = GC_fnlz_roots.finalize_now;
1288 if (curr_fo != NULL)
1289 SET_FINALIZE_NOW(fo_next(curr_fo));
1291 if (curr_fo == 0) break;
1293 GC_fnlz_roots.finalize_now = fo_next(curr_fo);
1295 fo_set_next(curr_fo, 0);
1296 (*(curr_fo -> fo_fn))((ptr_t)(curr_fo -> fo_hidden_base),
1297 curr_fo -> fo_client_data);
1298 curr_fo -> fo_client_data = 0;
1300 /* Explicit freeing of curr_fo is probably a bad idea. */
1301 /* It throws off accounting if nearly all objects are */
1302 /* finalizable. Otherwise it should not matter. */
1304 /* bytes_freed_before is initialized whenever count != 0 */
1306 # if defined(THREADS) && !defined(THREAD_SANITIZER)
1307 /* A quick check whether some memory was freed. */
1308 /* The race with GC_free() is safe to be ignored */
1309 /* because we only need to know if the current */
1310 /* thread has deallocated something. */
1311 && bytes_freed_before != GC_bytes_freed
1315 GC_finalizer_bytes_freed += (GC_bytes_freed - bytes_freed_before);
1321 static word last_finalizer_notification = 0;
1323 GC_INNER void GC_notify_or_invoke_finalizers(void)
1325 GC_finalizer_notifier_proc notifier_fn = 0;
1326 # if defined(KEEP_BACK_PTRS) || defined(MAKE_BACK_GRAPH)
1327 static word last_back_trace_gc_no = 1; /* Skip first one. */
1331 # if defined(THREADS) && !defined(KEEP_BACK_PTRS) \
1332 && !defined(MAKE_BACK_GRAPH)
1333 /* Quick check (while unlocked) for an empty finalization queue. */
1334 if (!GC_should_invoke_finalizers())
1339 /* This is a convenient place to generate backtraces if appropriate, */
1340 /* since that code is not callable with the allocation lock. */
1341 # if defined(KEEP_BACK_PTRS) || defined(MAKE_BACK_GRAPH)
1342 if (GC_gc_no > last_back_trace_gc_no) {
1343 # ifdef KEEP_BACK_PTRS
1345 /* Stops when GC_gc_no wraps; that's OK. */
1346 last_back_trace_gc_no = (word)(-1); /* disable others. */
1347 for (i = 0; i < GC_backtraces; ++i) {
1348 /* FIXME: This tolerates concurrent heap mutation, */
1349 /* which may cause occasional mysterious results. */
1350 /* We need to release the GC lock, since GC_print_callers */
1351 /* acquires it. It probably shouldn't. */
1353 GC_generate_random_backtrace_no_gc();
1356 last_back_trace_gc_no = GC_gc_no;
1358 # ifdef MAKE_BACK_GRAPH
1359 if (GC_print_back_height) {
1360 GC_print_back_graph_stats();
1365 if (NULL == GC_fnlz_roots.finalize_now) {
1370 if (!GC_finalize_on_demand) {
1371 unsigned char *pnested = GC_check_finalizer_nested();
1373 /* Skip GC_invoke_finalizers() if nested */
1374 if (pnested != NULL) {
1375 (void) GC_invoke_finalizers();
1376 *pnested = 0; /* Reset since no more finalizers. */
1378 GC_ASSERT(NULL == GC_fnlz_roots.finalize_now);
1379 # endif /* Otherwise GC can run concurrently and add more */
1384 /* These variables require synchronization to avoid data races. */
1385 if (last_finalizer_notification != GC_gc_no) {
1386 last_finalizer_notification = GC_gc_no;
1387 notifier_fn = GC_finalizer_notifier;
1390 if (notifier_fn != 0)
1391 (*notifier_fn)(); /* Invoke the notifier */
1394 #ifndef SMALL_CONFIG
1395 # ifndef GC_LONG_REFS_NOT_NEEDED
1396 # define IF_LONG_REFS_PRESENT_ELSE(x,y) (x)
1398 # define IF_LONG_REFS_PRESENT_ELSE(x,y) (y)
1401 GC_INNER void GC_print_finalization_stats(void)
1403 struct finalizable_object *fo;
1404 unsigned long ready = 0;
1406 GC_log_printf("%lu finalization entries;"
1407 " %lu/%lu short/long disappearing links alive\n",
1408 (unsigned long)GC_fo_entries,
1409 (unsigned long)GC_dl_hashtbl.entries,
1410 (unsigned long)IF_LONG_REFS_PRESENT_ELSE(
1411 GC_ll_hashtbl.entries, 0));
1413 for (fo = GC_fnlz_roots.finalize_now; fo != NULL; fo = fo_next(fo))
1415 GC_log_printf("%lu finalization-ready objects;"
1416 " %ld/%ld short/long links cleared\n",
1418 (long)GC_old_dl_entries - (long)GC_dl_hashtbl.entries,
1419 (long)IF_LONG_REFS_PRESENT_ELSE(
1420 GC_old_ll_entries - GC_ll_hashtbl.entries, 0));
1422 #endif /* !SMALL_CONFIG */
1424 #endif /* !GC_NO_FINALIZATION */