Avoid potential data race during apply_to_each_object(reset_back_edge)
authorIvan Maidanski <ivmai@mail.ru>
Tue, 10 Apr 2018 08:07:08 +0000 (11:07 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 10 Apr 2018 08:07:08 +0000 (11:07 +0300)
* 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.

backgraph.c
finalize.c

index 89d5f9b..f52ed14 100644 (file)
@@ -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);
index 8c4e380..c76b31b 100644 (file)
@@ -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
       }