From: Ivan Maidanski Date: Tue, 10 Apr 2018 08:07:08 +0000 (+0300) Subject: Avoid potential data race during apply_to_each_object(reset_back_edge) X-Git-Tag: v8.0.0~246 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d7ea0b1;p=gc Avoid potential data race during apply_to_each_object(reset_back_edge) * backgraph.c [MAKE_BACK_GRAPH] (GC_print_back_graph_stats): Add assertion that the allocation lock is held; store GC_deepest_obj to obj local variable (while holding the lock); place UNLOCK/LOCK around GC_print_heap_obj() call; pass obj to GC_print_heap_obj(). * finalize.c [MAKE_BACK_GRAPH] (GC_notify_or_invoke_finalizers): Remove UNLOCK/LOCK around GC_print_back_graph_stats() call. --- diff --git a/backgraph.c b/backgraph.c index 89d5f9b9..f52ed144 100644 --- a/backgraph.c +++ b/backgraph.c @@ -473,14 +473,19 @@ GC_INNER void GC_traverse_back_graph(void) void GC_print_back_graph_stats(void) { + GC_ASSERT(I_HOLD_LOCK()); GC_printf("Maximum backwards height of reachable objects at GC %lu is %lu\n", (unsigned long) GC_gc_no, (unsigned long)GC_max_height); if (GC_max_height > GC_max_max_height) { + ptr_t obj = GC_deepest_obj; + GC_max_max_height = GC_max_height; + UNLOCK(); GC_err_printf( "The following unreachable object is last in a longest chain " "of unreachable objects:\n"); - GC_print_heap_obj(GC_deepest_obj); + GC_print_heap_obj(obj); + LOCK(); } GC_COND_LOG_PRINTF("Needed max total of %d back-edge structs\n", GC_n_back_edge_structs); diff --git a/finalize.c b/finalize.c index 8c4e3804..c76b31bc 100644 --- a/finalize.c +++ b/finalize.c @@ -1315,9 +1315,7 @@ GC_INNER void GC_notify_or_invoke_finalizers(void) # endif # ifdef MAKE_BACK_GRAPH if (GC_print_back_height) { - UNLOCK(); GC_print_back_graph_stats(); - LOCK(); } # endif }