]> granicus.if.org Git - gc/commitdiff
Fix 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, 17 Apr 2018 20:06:13 +0000 (23:06 +0300)
(back-port of commit d7ea0b1 from 'master')

Issue #144 (bdwgc).

* 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 675df1f5089ddf1f81b920c0f421b6148487e7d7..4d09ea5b99659b456acf0bf858a47aba72b07f6c 100644 (file)
@@ -471,14 +471,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 bdda2ed641a2bc67f7cbe4c6ebc95ed44288da94..8a2ca37c68b7c6f5f1ce238b19d99bc9a331aa22 100644 (file)
@@ -1288,9 +1288,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
       }