Skip to content

Commit

Permalink
Fix handling of GC_gc_no counter wrap in GC_notify_or_invoke_finalizers
Browse files Browse the repository at this point in the history
(a cherry-pick of commits 6594e9a, fa19ed0 from 'master')

* finalize.c [KEEP_BACK_PTRS] (GC_notify_or_invoke_finalizers):
Compare GC_gc_no and last_back_trace_gc_no values using inequality
operator (instead of greater-than); define bt_in_progress static
variable; if bt_in_progress then do not do print any backtraces, else
set bt_in_progress (instead of setting last_back_trace_gc_no to
GC_WORD_MAX) while printing the backtraces; remove comment about
wrap of GC_gc_no counter.
  • Loading branch information
ivmai committed Nov 15, 2023
1 parent 0e58744 commit 9c57d8a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -1298,12 +1298,15 @@ GC_INNER void GC_notify_or_invoke_finalizers(void)
/* This is a convenient place to generate backtraces if appropriate, */
/* since that code is not callable with the allocation lock. */
# if defined(KEEP_BACK_PTRS) || defined(MAKE_BACK_GRAPH)
if (GC_gc_no > last_back_trace_gc_no) {
if (GC_gc_no != last_back_trace_gc_no) {
# ifdef KEEP_BACK_PTRS
long i;
/* Stops when GC_gc_no wraps; that's OK. */
last_back_trace_gc_no = GC_WORD_MAX; /* disable others. */
for (i = 0; i < GC_backtraces; ++i) {
static GC_bool bt_in_progress = FALSE;

if (!bt_in_progress) {
long i;

bt_in_progress = TRUE; /* prevent recursion or parallel usage */
for (i = 0; i < GC_backtraces; ++i) {
/* FIXME: This tolerates concurrent heap mutation, */
/* which may cause occasional mysterious results. */
/* We need to release the GC lock, since GC_print_callers */
Expand All @@ -1314,6 +1317,8 @@ GC_INNER void GC_notify_or_invoke_finalizers(void)
GC_printf("\n****Chosen address %p in object\n", current);
GC_print_backtrace(current);
LOCK();
}
bt_in_progress = FALSE;
}
# endif
last_back_trace_gc_no = GC_gc_no;
Expand Down

0 comments on commit 9c57d8a

Please sign in to comment.