]> granicus.if.org Git - gc/commitdiff
Add assertions about held lock for apply_to_each_object callers
authorIvan Maidanski <ivmai@mail.ru>
Fri, 6 Apr 2018 16:45:23 +0000 (19:45 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 6 Apr 2018 16:45:23 +0000 (19:45 +0300)
(code refactoring of commit 5e6cc59b0)

* alloc.c (GC_stopped_mark, GC_finish_collection): Add assertion (at
the beginning of the function) that the allocation lock is held.
* backgraph.c [MAKE_BACK_GRAPH] (GC_build_back_graph,
GC_traverse_back_graph): Likewise.
* mark.c (GC_initiate_gc): Likewise.
* alloc.c (GC_stopped_mark): Remove comment about the held lock
(because there is an assertion about it).

alloc.c
backgraph.c
mark.c

diff --git a/alloc.c b/alloc.c
index 1d4c90c4ceb421ddd1cb2853cac46548da6c2887..14c1c53bd53a886e33125fee576fa249ece1a2c7 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -659,7 +659,7 @@ GC_API int GC_CALL GC_collect_a_little(void)
 #endif
 
 /*
- * Assumes lock is held.  We stop the world and mark from all roots.
+ * We stop the world and mark from all roots.
  * If stop_func() ever returns TRUE, we may fail and return FALSE.
  * Increment GC_gc_no if we succeed.
  */
@@ -670,6 +670,7 @@ STATIC GC_bool GC_stopped_mark(GC_stop_func stop_func)
       CLOCK_TYPE start_time = 0; /* initialized to prevent warning. */
 #   endif
 
+    GC_ASSERT(I_HOLD_LOCK());
 #   if !defined(REDIRECT_MALLOC) && defined(USE_WINALLOC)
         GC_add_current_malloc_heap();
 #   endif
@@ -948,6 +949,7 @@ STATIC void GC_finish_collection(void)
       CLOCK_TYPE finalize_time = 0;
 #   endif
 
+    GC_ASSERT(I_HOLD_LOCK());
 #   if defined(GC_ASSERTIONS) \
        && defined(THREAD_LOCAL_ALLOC) && !defined(DBG_HDRS_ALL)
         /* Check that we marked some of our own data.           */
index 64fc92f9c0678719edadcbaeb9db2e8f4dcd0dd4..89d5f9b9e9b3aaf0070df2cfbd31fe68033ea39e 100644 (file)
@@ -357,6 +357,7 @@ static void add_back_edges(ptr_t p, size_t n_bytes, word gc_descr)
 /* Does not examine mark bits.  Can be called before GC.                */
 GC_INNER void GC_build_back_graph(void)
 {
+  GC_ASSERT(I_HOLD_LOCK());
   GC_apply_to_each_object(add_back_edges);
 }
 
@@ -463,6 +464,7 @@ STATIC word GC_max_max_height = 0;
 
 GC_INNER void GC_traverse_back_graph(void)
 {
+  GC_ASSERT(I_HOLD_LOCK());
   GC_max_height = 0;
   GC_apply_to_each_object(update_max_height);
   if (0 != GC_deepest_obj)
diff --git a/mark.c b/mark.c
index d8b69e5f845114354c5855e2cf96166a5fcb0d01..8dd257f342393fb189e79796c3867b0b33c8f701 100644 (file)
--- a/mark.c
+++ b/mark.c
@@ -259,6 +259,7 @@ GC_INNER void GC_clear_marks(void)
 /* mark state is invalid.                                               */
 GC_INNER void GC_initiate_gc(void)
 {
+    GC_ASSERT(I_HOLD_LOCK());
 #   ifndef GC_DISABLE_INCREMENTAL
         if (GC_incremental) {
 #         ifdef CHECKSUMS