From faa3bafd2da2d814b6ee1e99e38c44f3a54eed10 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 25 May 2022 08:41:37 +0300 Subject: Ensure GC is initialized when GC_push_all_stacks() is called (refactoring) Also, remove an unnecessary lock in GC pthread_create (of pthread_support.c), and ensure that GC_thr_init() is called only once. * alloc.c (GC_try_to_collect_inner, GC_collect_a_little_inner, GC_stopped_mark, GC_collect_or_expand, GC_allocobj): Add assertion that GC is initialized. * finalize.c (GC_register_disappearing_link_inner, GC_register_finalizer_inner): Likewise. * mark.c (GC_clear_marks, GC_initiate_gc): Likewise. * mark_rts.c (GC_push_roots): Likewise. * alloc.c (GC_collect_a_little): Call GC_init if GC is not initialized. * alloc.c (GC_expand_hp): Move part of comment to gc.h. * include/gc/gc.h (GC_expand_hp): Reformat comment. * darwin_stop_world.c (GC_push_all_stacks): Replace GC_init() call with the assertion that GC_thr_initialized. * pthread_stop_world.c (GC_push_all_stacks): Likewise. * pthread_support.c (pthread_create): Likewise. * darwin_stop_world.c (GC_stop_world): Add assertion that GC_thr_initialized. * pthread_stop_world.c (GC_stop_world): Likewise. * win32_threads.c (GC_push_all_stacks): Likewise. * finalize.c (GC_register_finalizer_inner): Add assertion (after LOCK) that obj points to the base address of the object. * include/private/pthread_support.h (GC_thr_initialized): Declare only if GC_ASSERTIONS. * pthread_support.c (GC_thr_initialized): Define only if GC_ASSERTIONS. * win32_threads.c (GC_thr_initialized): Likewise. * pthread_support.c (GC_thr_init): Add assertion that GC_thr_initialized is not set on entry; set GC_thr_initialized only if GC_ASSERTIONS. * win32_threads.c (GC_thr_init): Likewise. * pthread_support.c (pthread_create): Remove LOCK/UNLOCK around setup of si. * win32_threads.c (GC_stop_world): Replace ABORT (about GC_thr_initialized) with the assertion. * win32_threads.c (GC_CreateThread): Add assertion that GC_thr_initialized after GC_init_parallel() call. * win32_threads.c [!CYGWIN32 && !MSWINCE && !MSWIN_XBOX1 && !NO_CRT] (GC_beginthreadex): Likewise. * win32_threads.c [GC_PTHREADS] (GC_pthread_create): Likewise. * win32_threads.c [!CYGWIN32 && !MSWINCE && !MSWIN_XBOX1 && !NO_CRT] (GC_beginthreadex): Remove comment duplicating that in GC_CreateThread. * win32_threads.c [GC_PTHREADS] (GC_pthread_create): Likewise. --- finalize.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'finalize.c') diff --git a/finalize.c b/finalize.c index 60279e52..6a75451a 100644 --- a/finalize.c +++ b/finalize.c @@ -166,6 +166,7 @@ STATIC int GC_register_disappearing_link_inner( struct disappearing_link * new_dl; DCL_LOCK_STATE; + GC_ASSERT(GC_is_initialized); if (EXPECT(GC_find_leak, FALSE)) return GC_UNIMPLEMENTED; # ifdef GC_ASSERTIONS GC_noop1((word)(*link)); /* check accessibility */ @@ -684,11 +685,13 @@ STATIC void GC_register_finalizer_inner(void * obj, hdr *hhdr = NULL; /* initialized to prevent warning. */ DCL_LOCK_STATE; + GC_ASSERT(GC_is_initialized); if (EXPECT(GC_find_leak, FALSE)) { /* No-op. *ocd and *ofn remain unchanged. */ return; } LOCK(); + GC_ASSERT(obj != NULL && GC_base_C(obj) == obj); if (EXPECT(NULL == GC_fnlz_roots.fo_head, FALSE) || EXPECT(GC_fo_entries > ((word)1 << GC_log_fo_table_size), FALSE)) { GC_grow_table((struct hash_chain_entry ***)&GC_fnlz_roots.fo_head, -- cgit v1.2.1