From: Ivan Maidanski Date: Fri, 6 Apr 2018 16:45:23 +0000 (+0300) Subject: Add assertions about held lock for apply_to_each_object callers X-Git-Tag: v8.0.0~248 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=72f159b81640d8e5ab706b4104868eb6d9677fb2;p=gc Add assertions about held lock for apply_to_each_object callers (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). --- diff --git a/alloc.c b/alloc.c index 1d4c90c4..14c1c53b 100644 --- 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. */ diff --git a/backgraph.c b/backgraph.c index 64fc92f9..89d5f9b9 100644 --- a/backgraph.c +++ b/backgraph.c @@ -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 d8b69e5f..8dd257f3 100644 --- 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