Ivan Maidanski [Thu, 14 Dec 2017 06:34:00 +0000 (09:34 +0300)]
Travis CI: Test explicit at-fork handlers invocation (TSan)
Ivan Maidanski [Wed, 13 Dec 2017 14:27:36 +0000 (17:27 +0300)]
Travis CI: Test with increased number of test threads
Ivan Maidanski [Wed, 13 Dec 2017 06:27:32 +0000 (09:27 +0300)]
Revert 'Workaround TSan hang in GC_free_inner when called from at-fork'
This reverts commit
d8e271ea8ab4477fc3ac8edb884bbf858d401343.
Because there is a better solution not to skip GC_INTERNAL_FREE in
GC_remove_all_threads_but_me if called from GC_atfork_child.
Ivan Maidanski [Tue, 12 Dec 2017 16:56:28 +0000 (19:56 +0300)]
Really prevent hang in sem_wait in stop_world if compiled with TSan
(fix commit af409e4)
Issue #181 (bdwgc).
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& THREAD_SANITIZER] (GC_retry_signals): Initialize to TRUE.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_store_stack_ptr): Update comment.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& GC_ENABLE_SUSPEND_THREAD] (GC_suspend_thread): Likewise.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& THREAD_SANITIZER] (GC_stop_world): Do not use sem_trywait+sleep
workaround (not needed if GC_retry_signals).
Ivan Maidanski [Tue, 12 Dec 2017 16:24:02 +0000 (19:24 +0300)]
Fix gctest failure if compiled with TSan and parallel marker
As of clang-4.0, Thread Sanitizer does not support creation of threads
in the forked process (before exec). So, GC_start_mark_threads()
is a no-op now if TSan is enabled.
* misc.c [THREADS && PARALLEL_MARK && CAN_HANDLE_FORK]
(GC_start_mark_threads): Do not call GC_start_mark_threads_inner()
if THREAD_SANITIZER; add comment.
Ivan Maidanski [Tue, 12 Dec 2017 16:04:17 +0000 (19:04 +0300)]
Use same macro (NTHREADS) across all tests to specify number of threads
(code refactoring)
* tests/disclaim_test.c [GC_PTHREADS] (THREAD_CNT): Rename to NTHREADS;
do not define if already defined.
* tests/disclaim_test.c [!GC_PTHREADS] (THREAD_CNT): Rename to
NTHREADS; undefine it first.
* tests/disclaim_test.c (MUTATE_CNT, main): Rename THREAD_CNT to
NTHREADS.
* tests/subthread_create.c [!NTHREADS] (INITIAL_THREAD_COUNT): Rename
to NTHREADS; add comment.
* tests/subthread_create.c (main): Rename INITIAL_THREAD_COUNT to
NTHREADS.
* tests/threadkey_test.c (LIMIT, main): Rename LIMIT to NTHREADS.
Ivan Maidanski [Fri, 8 Dec 2017 15:03:19 +0000 (18:03 +0300)]
Travis CI: Workaround disclaim_test failure when TSan is used
(fix commit 153a2c7)
GC incremental mode is not supported if compiled with TSan for now.
Ivan Maidanski [Thu, 7 Dec 2017 21:52:50 +0000 (00:52 +0300)]
Workaround TSan data race report in check_fl_marks
* alloc.c [GC_ASSERTIONS && THREAD_LOCAL_ALLOC
&& AO_HAVE_load_acquire_read] (GC_check_fl_marks): Skip the whole check
if THREAD_SANITIZER; add comment.
Ivan Maidanski [Thu, 7 Dec 2017 08:54:15 +0000 (11:54 +0300)]
Use __builtin_expect in SIZET_SAT_ADD macro
* include/private/gc_priv.h (EXPECT): Move the definition to be before
SIZET_SAT_ADD.
* include/private/gc_priv.h (SIZET_SAT_ADD): Use EXPECT().
Ivan Maidanski [Mon, 4 Dec 2017 06:42:47 +0000 (09:42 +0300)]
Turn on incremental mode (if available) in disclaim_test
* tests/disclaim_test.c [NO_INCREMENTAL] (main): Call
GC_enable_incremental() afer GC_init_finalized_malloc() call.
Petter A. Urkedal [Sun, 3 Dec 2017 11:42:59 +0000 (12:42 +0100)]
Fix marking of disclaim-reachable objects in the incremental mode
Issue #192 (bdwgc).
Unconditional marking is done analogously to marking from uncollectible
blocks, since they are meant to secure access to data for disclaim
notifiers after the data is no longer marked.
* mark.c [ENABLE_DISCLAIM] (GC_push_next_marked_dirty): Honor
MARK_UNCONDITIONALLY when rescanning dirty blocks during incremental
marking.
Ivan Maidanski [Fri, 1 Dec 2017 16:43:02 +0000 (19:43 +0300)]
Travis CI: Add a test with TSan with parallel marker (Linux/clang)
Ivan Maidanski [Fri, 1 Dec 2017 16:38:02 +0000 (19:38 +0300)]
Fix data race in do_local_mark when comparing active_count to helper_count
* mark.c [PARALLEL_MARK] (has_inactive_helpers): New static function
(which compares GC_active_count to GC_helper_count with the mark lock
held).
* mark.c [PARALLEL_MARK && GC_ASSERTIONS] (GC_do_local_mark): Remove
GC_acquire_mark_lock() with immediate GC_acquire_mark_unlock(); add
the appropriate comment to the function description instead.
* mark.c [PARALLEL_MARK] (GC_do_local_mark): Call has_inactive_helpers()
instead of GC_active_count<GC_helper_count; do not call
has_inactive_helpers() unless local_top>local_mark_stack+1.
Ivan Maidanski [Fri, 1 Dec 2017 16:23:13 +0000 (19:23 +0300)]
Fix data race in mark_thread when updating mark_no
* mark.c [PARALLEL_MARK] (GC_mark_local, GC_help_marker): Update
description comment; remove GC_acquire_mark_lock() call at the function
beginning; remove GC_release_mark_lock() call on return.
* mark.c [PARALLEL_MARK] (GC_do_parallel_mark): Remove
GC_acquire/release_mark_lock() calls around GC_mark_local() call.
* pthread_support.c [PARALLEL_MARK] (GC_mark_thread): Remove
GC_release_mark_lock() call.
* win32_threads.c [PARALLEL_MARK] (GC_mark_thread): Likewise.
Ivan Maidanski [Fri, 1 Dec 2017 08:48:08 +0000 (11:48 +0300)]
Workaround TSan warning about data race in generic_malloc_many
It is acceptable to update GC_bytes_found counter without
synchronization (so, it is OK to have inaccurate value in
GC_bytes_found in favor of performance).
* mallocx.c [PARALLEL_MARK && THREAD_SANITIZER]
(GC_generic_malloc_many): Acquire the allocation lock to update
GC_bytes_found (after successful GC_reclaim_generic).
* mallocx.c [PARALLEL_MARK && !THREAD_SANITIZER]
(GC_generic_malloc_many): Move GC_bytes_found update into the block
executed with the mark lock held.
Ivan Maidanski [Fri, 1 Dec 2017 07:35:59 +0000 (10:35 +0300)]
Workaround TSan false positives in add_to_black_list_normal/stack
* blacklst.c (GC_add_to_black_list_normal, GC_add_to_black_list_stack):
Call set_pht_entry_from_index_concurrent() instead of
set_pht_entry_from_index().
* include/private/gc_priv.h [PARALLEL_MARK && THREAD_SANITIZER]
(set_pht_entry_from_index_concurrent): New macro (use AO_or).
* include/private/gc_priv.h [!PARALLEL_MARK || !THREAD_SANITIZER]
(set_pht_entry_from_index_concurrent): Define to
set_pht_entry_from_index.
Ivan Maidanski [Wed, 29 Nov 2017 23:19:10 +0000 (02:19 +0300)]
Document base and size of objects allocated by finalized_malloc
* include/gc_disclaim.h (GC_finalized_malloc): Refine comment (add
a note about GC_base and GC_size).
Ivan Maidanski [Wed, 29 Nov 2017 22:24:33 +0000 (01:24 +0300)]
Update comment in finalized_disclaim to match FINALIZER_CLOSURE_FLAG
(fix commit 012da3f)
* fnlz_mlc.c [ENABLE_DISCLAIM] (GC_finalized_disclaim): Update/refine
comment (about the lowest 2 bits of the first word).
Ivan Maidanski [Wed, 29 Nov 2017 22:18:19 +0000 (01:18 +0300)]
Remove done_init static variable from fnlz_mlc.c
(code refactoring)
GC_init_finalized_malloc!=0 is used instead of boolean done_init.
* fnlz_mlc.c [ENABLE_DISCLAIM] (done_init): Remove static variable.
* fnlz_mlc.c [ENABLE_DISCLAIM] (GC_init_finalized_malloc,
GC_finalized_malloc): Use GC_finalized_kind instead of done_init.
* fnlz_mlc.c [ENABLE_DISCLAIM] (GC_init_finalized_malloc): Add
assertion that the result of GC_new_kind_inner() is non-zero.
Ivan Maidanski [Wed, 29 Nov 2017 22:10:20 +0000 (01:10 +0300)]
Fix assertion violation about disabled cancel in try_to_collect_inner
* misc.c [!GC_DISABLE_INCREMENTAL && !KEEP_BACK_PTRS]
(GC_enable_incremental): Wrap GC_gcollect_inner and GC_read_dirty calls
into DISABLE/RESTORE_CANCEL.
Ivan Maidanski [Wed, 29 Nov 2017 21:51:40 +0000 (00:51 +0300)]
Workaround TSan false positive about read of mark_lock_holder
The assertion should not be violated in GC_acquire_mark_lock even
reading from GC_mark_lock_holder is done before acquiring the mark lock.
* pthread_support.c [PARALLEL_MARK && NUMERIC_THREAD_ID_UNIQUE]
(GC_acquire_mark_lock): Skip assertion on GC_mark_lock_holder (before
acquiring the lock) if THREAD_SANITIZER.
* win32_threads.c [PARALLEL_MARK] (GC_acquire_mark_lock): Likewise.
Ivan Maidanski [Wed, 29 Nov 2017 18:26:28 +0000 (21:26 +0300)]
Add a sanity check that load_acquire and store_release are available
* pthread_stop_world.c [(!AO_HAVE_load_acquire
|| !AO_HAVE_store_release) && !CPPCHECK]: Issue error that
libatomic_ops does not define AO_load_acquire and/or AO_store_release
so the client should manually define AO_REQUIRE_CAS macro.
Ivan Maidanski [Wed, 29 Nov 2017 18:14:59 +0000 (21:14 +0300)]
Improve comment in store_stack_ptr in pthread_stop_world.c
(fix commit a194093)
* pthread_stop_world.c (GC_store_stack_ptr): Refine comment about the
atomic primitives usage.
Ivan Maidanski [Wed, 29 Nov 2017 18:09:52 +0000 (21:09 +0300)]
Remove explicit case of TRUE/FALSE to AO_t in suspend/resume_thread
(fix commit ce09fd5)
* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD
&& !GC_OPENBSD_UTHREADS && !NACL] (GC_suspend_thread,
GC_resume_thread): Do not case TRUE/FALSE to AO_t explicitly.
Ivan Maidanski [Wed, 29 Nov 2017 17:47:59 +0000 (20:47 +0300)]
Guard against USE_PTHREAD_LOCKS and USE_SPIN_LOCK are both defined
USE_SPIN_LOCK might be specified by client. As it and USE_PTHREAD_LOCKS
are mutually exclusive, one of them should be undefined.
* include/private/gc_locks.h [(!AO_HAVE_test_and_set_acquire
|| GC_RTEMS_PTHREADS || SN_TARGET_PS3 || GC_WIN32_THREADS || LINT2)
&& GC_PTHREADS] (USE_SPIN_LOCK): Undefine (as USE_PTHREAD_LOCKS is
defined).
Ivan Maidanski [Wed, 29 Nov 2017 17:15:49 +0000 (20:15 +0300)]
Fix data race in make_descriptor when setting explicit_typing_initialized
(fix commit 5f350a0)
* typd_mlc.c [AO_HAVE_load_acquire] (GC_explicit_typing_initialized):
Add volatile qualifier.
* typd_mlc.c [AO_HAVE_load_acquire] (GC_make_descriptor): Remove
cast of &GC_explicit_typing_initialized; do not check THREADS macro;
fallback to locked checking of GC_explicit_typing_initialized if
AO_HAVE_store_release is not defined; use AO_store_release to set
GC_explicit_typing_initialized (to true).
* typd_mlc.c (GC_make_descriptor): Reformat code dealing with
GC_explicit_typing_initialized (check whether AO_HAVE_load_acquire is
defined only once).
Ivan Maidanski [Wed, 29 Nov 2017 17:06:48 +0000 (20:06 +0300)]
Revert 'Eliminate TSan warning about data race in make_descriptor'
This reverts commit
a3ee14468b807ecf2d6fa279699b7a9879443bdf.
Because it just hides a potential data race.
Ivan Maidanski [Wed, 29 Nov 2017 08:16:21 +0000 (11:16 +0300)]
Travis CI: Add tests with TSan (only without parallel mark, Linux/clang)
Ivan Maidanski [Wed, 29 Nov 2017 08:12:20 +0000 (11:12 +0300)]
Travis CI: Remove -D NO_INCREMENTAL if --enable-munmap
The incremental mode is disabled in gctest automatically now
if compiled with memory unmapping support.
Ivan Maidanski [Wed, 29 Nov 2017 07:06:34 +0000 (10:06 +0300)]
Do not enable mprotect-based incremental mode if unmapping is on (gctest)
Incremental mode based on mprotect() is not compatible with memory
unmapping for now.
* tests/test.c [!PCR && !GC_WIN32_THREADS && !MAKE_BACK_GRAPH
&& !NO_INCREMENTAL] (main): Do not call GC_enable_incremental() if
MPROTECT_VDB && USE_MUNMAP.
Ivan Maidanski [Wed, 29 Nov 2017 08:46:05 +0000 (11:46 +0300)]
Eliminate TSan false positive for stop_info.stack_ptr (v2)
Without this patch, Thread Sanitizer reports a data race between
GC_has_other_debug_info() and the code which sets stop_info.stack_ptr.
* include/private/pthread_support.h [THREAD_SANITIZER]: Include
dbg_mlc.h file.
* include/private/pthread_support.h [THREAD_SANITIZER] (GC_Thread_Rep):
Add dummy field (as the first field of the structure).
* pthread_support.c [THREAD_SANITIZER && CPPCHECK] (GC_new_thread):
Call GC_noop1(first_thread.dummy[0]) (to suppress cppcheck warning
about unused field).
Ivan Maidanski [Wed, 29 Nov 2017 08:45:49 +0000 (11:45 +0300)]
Revert 'Eliminate TSan false positive for stop_info.stack_ptr'
This reverts commit
80ad68c54e8f339204e7f3b4c305d390e7f44006.
Because it does not eliminate the warning fully, a better solution
would be to add a dummy "oh" header to GC_Thread_Rep.
Ivan Maidanski [Wed, 29 Nov 2017 08:44:17 +0000 (11:44 +0300)]
Eliminate 'value exceeds maximum object size' GCC warning in huge_test
* tests/huge_test.c [!GC_ATTR_ALLOC_SIZE] (GC_ATTR_ALLOC_SIZE): Define
to empty (before include gc.h).
Ivan Maidanski [Wed, 29 Nov 2017 08:42:47 +0000 (11:42 +0300)]
Eliminate 'this statement may fall through' GCC warnings
* cord/cordprnt.c (extract_conv_spec): Eliminate fall through in
a switch statement.
* cord/tests/de.c (do_command): Replace "fall through:" comment with
"FALLTHRU" formal comment (on a new line).
* win32_threads.c [!GC_PTHREADS && !GC_NO_THREADS_DISCOVERY]
(GC_DllMain): Likewise.
Ivan Maidanski [Wed, 29 Nov 2017 08:41:22 +0000 (11:41 +0300)]
Fix 'comparison of 255 with expr of type bool' error in gc_atomic_ops.h
* include/private/gc_atomic_ops.h [GC_BUILTIN_ATOMIC && (CPPCHECK
|| !__GCC_ATOMIC_TEST_AND_SET_TRUEVAL)] (AO_TS_SET): Define to 1
instead of 0xff.
Ivan Maidanski [Wed, 29 Nov 2017 08:20:04 +0000 (11:20 +0300)]
Travis CI: Test with ASan and GCC
Ivan Maidanski [Wed, 29 Nov 2017 07:47:33 +0000 (10:47 +0300)]
Remove some redundant macro definitions from gc_atomic_ops.h
(fix commit 46a2411)
* include/private/gc_atomic_ops.h [GC_BUILTIN_ATOMIC] (AO_HAVE_load,
AO_HAVE_store, AO_HAVE_store_release_write): Remove.
* include/private/gc_atomic_ops.h [GC_BUILTIN_ATOMIC && AO_REQUIRE_CAS]
(AO_HAVE_compare_and_swap): Likewise.
* include/private/gc_atomic_ops.h [!GC_BUILTIN_ATOMIC]: Add comment.
* include/private/gc_priv.h (word_ptr_ao_u): Replace
"ifdef AO_HAVE_load" to "ifdef PARALLEL_MARK".
* tests/test_atomic_ops.c [AO_HAVE_compare_and_swap_release] (main):
Do not check whether AO_REQUIRE_CAS and AO_HAVE_compare_and_swap are
defined.
* typd_mlc.c [GC_FORCE_INCLUDE_ATOMIC_OPS || GC_BUILTIN_ATOMIC]
(include gc_atomic_ops.h): Do not check whether AO_HAVE_load_acquire
is defined.
Ivan Maidanski [Tue, 28 Nov 2017 23:57:28 +0000 (02:57 +0300)]
Adjust AO_HAVE_x check to match AO_fetch_and_add primitive variant used
(fix commit 6043293)
* tests/subthread_create.c: Replace "ifdef AO_HAVE_fetch_and_add" with
"ifdef AO_HAVE_fetch_and_add1".
Ivan Maidanski [Tue, 28 Nov 2017 23:39:20 +0000 (02:39 +0300)]
Prevent test_atomic_ops link fail if AO_nop_full is not defined
(fix commit 066e0ca)
* tests/test_atomic_ops.c (main): Call AO_nop_full() only
if AO_HAVE_nop_full is defined.
Ivan Maidanski [Tue, 28 Nov 2017 22:05:47 +0000 (01:05 +0300)]
Remove redundant THREADS macro checks
(code refactoring)
THREAD_LOCAL_ALLOC macro implies THREADS one.
* alloc.c [GC_ASSERTIONS && THREAD_LOCAL_ALLOC] (GC_check_fl_marks,
GC_check_tls, GC_finish_collection): Do not check whether THREADS macro
is defined.
* include/private/gc_priv.h [GC_ASSERTIONS && THREAD_LOCAL_ALLOC]
(GC_check_fl_marks): Likewise.
Ivan Maidanski [Thu, 23 Nov 2017 23:21:46 +0000 (02:21 +0300)]
Fix lack of barriers to synchronize memory for suspend_handler
pthread_kill is not on the list of functions which synchronize memory.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_world_is_stopped): Reformat comment.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_suspend_handler_inner): Use AO_load_acquire instead of AO_load
to fetch the value of GC_stop_count; add comment.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_start_world): Use AO_store_release instead of AO_store to reset
GC_world_is_stopped; add comment.
Ivan Maidanski [Thu, 23 Nov 2017 22:16:50 +0000 (01:16 +0300)]
Eliminate TSan false positive related to stop_info.stack_ptr access
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_store_stack_ptr): New inline function definition (move the code
from GC_suspend_handler_inner but stop_info.stack_ptr is now stored
atomically); add comment.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_suspend_handler_inner): Call GC_store_stack_ptr().
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_push_all_stacks): Use AO_load to fetch p->stop_info.stack_ptr.
Ivan Maidanski [Thu, 23 Nov 2017 17:26:02 +0000 (20:26 +0300)]
Avoid 'Unexpected heap growth' fail if compiled by GCC with ASan (gctest)
* tests/test.c [ADDRESS_SANITIZER && !__clang__] (check_heap_stats):
Multiply max_heap_sz by ~1.66.
Ivan Maidanski [Thu, 23 Nov 2017 17:15:54 +0000 (20:15 +0300)]
Fix data race in last_stop_count access (suspend_handler_inner)
* include/private/pthread_stop_world.h [!GC_OPENBSD_UTHREADS]
(thread_stop_info.last_stop_count): Do not define if NACL; change the
type from word to AO_t; add volatile qualifier; fix a typo in comment
("GC_stop_count").
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(update_last_stop_count): Remove.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_suspend_handler_inner): Replace update_last_stop_count() call with
AO_store_release(&me->stop_info.last_stop_count,my_stop_count).
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_suspend_all): Replace p->stop_info.last_stop_count with
AO_load(&p->stop_info.last_stop_count).
Ivan Maidanski [Thu, 23 Nov 2017 09:20:18 +0000 (12:20 +0300)]
Fix data race in GC_suspend/resume_thread
* include/private/pthread_support.h [GC_ENABLE_SUSPEND_THREAD
&& !GC_DARWIN_THREADS && !GC_OPENBSD_UTHREADS && !NACL]
(GC_Thread_Rep.suspended_ext): New field.
* include/private/pthread_support.h (SUSPENDED_EXT): Remove macro.
* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD
&& !GC_OPENBSD_UTHREADS && !NACL] (GC_suspend_handler_inner): Replace
me->flags & SUSPENDED_EXT with AO_load(&me->suspended_ext).
* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD
&& !GC_OPENBSD_UTHREADS && !NACL] (suspend_self_inner): Replace
me->flags & SUSPENDED_EXT with AO_load_acquire(&me->suspended_ext).
* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD
&& !GC_OPENBSD_UTHREADS && !NACL] (GC_suspend_thread): Replace
t->flags & SUSPENDED_EXT with t->suspended_ext; replace
t->flags|=SUSPENDED_EXT with AO_store_release(&t->suspended_ext, TRUE);
add comment.
* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD
&& !GC_OPENBSD_UTHREADS && !NACL] (GC_resume_thread): Replace
t->flags&=~SUSPENDED_EXT with AO_store(&t->suspended_ext, FALSE).
* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD
&& !GC_OPENBSD_UTHREADS && !NACL] (GC_is_thread_suspended,
GC_suspend_all, GC_start_world): Replace t->flags & SUSPENDED_EXT with
t->suspended_ext.
* pthread_support.c (GC_register_my_thread): Remove assertion that uses
SUSPENDED_EXT.
Ivan Maidanski [Wed, 22 Nov 2017 23:25:05 +0000 (02:25 +0300)]
Revert 'Workaround TSan false positives in suspend/resume_thread'
This reverts commit
918500dcd5f629391e442f68620873909c733ea7.
Because it just hides the data race issues in GC_suspend/resume_thread.
Ivan Maidanski [Wed, 22 Nov 2017 23:19:30 +0000 (02:19 +0300)]
Workaround TSan hang in GC_free_inner when called from at-fork handler
* pthread_support.c [CAN_HANDLE_FORK] (GC_remove_all_threads_but_me):
Do not call GC_INTERNAL_FREE(p) if THREAD_SANITIZER; add comment.
Ivan Maidanski [Wed, 22 Nov 2017 22:58:40 +0000 (01:58 +0300)]
Workaround TSan false positives for at-fork handlers accessing lock_holder
* pthread_support.c (GC_wait_for_gc_completion): Skip I_HOLD_LOCK()
assertion if THREAD_SANITIZER and CAN_HANDLE_FORK; add comment.
* pthread_support.c [CAN_HANDLE_FORK && GC_ASSERTIONS]
(fork_prepare_proc, fork_parent_proc, fork_child_proc): Add
GC_ATTR_NO_SANITIZE_THREAD attribute.
Ivan Maidanski [Wed, 22 Nov 2017 08:35:08 +0000 (11:35 +0300)]
Workaround TSan false positive in lookup_thread called by suspend_handler
* include/private/pthread_support.h (THREAD_TABLE_INDEX): Move the
macro from pthread_support.c file.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& THREAD_SANITIZER] (GC_lookup_thread_async): New static function
(same implementation as of GC_lookup_thread but with
GC_ATTR_NO_SANITIZE_THREAD attribute); add comment.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& !THREAD_SANITIZER] (GC_lookup_thread_async): Define as macro.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_suspend_handler_inner): Call GC_lookup_thread_async() instead of
GC_lookup_thread(); move the corresponding comment to
GC_lookup_thread_async.
Ivan Maidanski [Tue, 21 Nov 2017 22:05:13 +0000 (01:05 +0300)]
Workaround TSan false positive about clear_hdr_marks/realloc data race
* mallocx.c (hb_sz_async_grow_within_hblk): New static function (with
GC_ATTR_NO_SANITIZE_THREAD attribute).
* mallocx.c (GC_realloc): Call hb_sz_async_grow_within_hblk instead of
hhdr->hb_sz=sz.
Ivan Maidanski [Tue, 21 Nov 2017 19:10:22 +0000 (22:10 +0300)]
Eliminate TSan warning about data race in default_on_abort
The warning is about a potential race between GC_default_on_abort
(which updates GC_find_leak) and GC_finish_collection (which reads the
variable).
* misc.c [DONT_USE_ATEXIT && !PCR && !SMALL_CONFIG] (skip_gc_atexit):
New static variable; add comment.
* misc.c [DONT_USE_ATEXIT && (PCR || SMALL_CONFIG)] (skip_gc_atexit):
Define as macro (to FALSE).
* misc.c [DONT_USE_ATEXIT] (GC_exit_check): Do not call GC_gcollect
if skip_gc_atexit.
* misc.c [!PCR && !SMALL_CONFIG] (GC_default_on_abort): Do not modify
GC_find_leak.
* misc.c [DONT_USE_ATEXIT && !PCR && !SMALL_CONFIG]
(GC_default_on_abort): Set skip_gc_atexit to true.
Ivan Maidanski [Tue, 21 Nov 2017 08:45:30 +0000 (11:45 +0300)]
Eliminate TSan warning about data race in make_descriptor
* typd_mlc.c [THREADS) && AO_HAVE_load_acquire && AO_HAVE_store]
(GC_make_descriptor): Use AO_store for setting
GC_explicit_typing_initialized (to true).
Ivan Maidanski [Tue, 21 Nov 2017 08:03:28 +0000 (11:03 +0300)]
Support AddressSanitizer (GCC)
* include/private/gcconfig.h [!__has_feature && __SANITIZE_ADDRESS__]
(ADDRESS_SANITIZER): Define.
Ivan Maidanski [Mon, 20 Nov 2017 21:17:51 +0000 (00:17 +0300)]
Fix 'unknown attribute no_sanitize' compiler warnings for GCC
(fix commits ce75cf1, b850e1c)
* include/private/gc_priv.h [!GC_ATTR_NO_SANITIZE_ADDR
&& ADDRESS_SANITIZER && !AO_CLANG_PREREQ(3,8)]
(GC_ATTR_NO_SANITIZE_ADDR): Define to
__attribute__((no_sanitize_address)).
* include/private/gc_priv.h [!GC_ATTR_NO_SANITIZE_MEMORY
&& MEMORY_SANITIZER && !AO_CLANG_PREREQ(3,8)]
(GC_ATTR_NO_SANITIZE_MEMORY): Define to
__attribute__((no_sanitize_memory)).
* include/private/gc_priv.h [!GC_ATTR_NO_SANITIZE_THREAD
&& THREAD_SANITIZER && !AO_CLANG_PREREQ(3,8)]
(GC_ATTR_NO_SANITIZE_THREAD): Define to
__attribute__((no_sanitize_thread)).
Ivan Maidanski [Mon, 20 Nov 2017 21:10:08 +0000 (00:10 +0300)]
Place no_sanitize attributes in a GCC-compliant way
Now the attributes precede the function prototypes (the format is:
<attribute> void f(void) <body>).
* finalize.c (GC_should_invoke_finalizers): Move
GC_ATTR_NO_SANITIZE_THREAD attribute to the beginning of the function
prototype (even before GC_API, GC_INNER or static).
* malloc.c (fill_size_map): Likewise.
* mark.c (GC_noop1, GC_mark_from, GC_push_all_eager): Likewise.
* mark.c [WRAP_MARK_SOME && PARALLEL_MARK] (GC_push_conditional_eager):
Likewise.
* misc.c [THREADS] (next_random_no): Likewise.
* os_dep.c [MPROTECT_VDB && THREADS && AO_HAVE_test_and_set_acquire]
(async_set_pht_entry_from_index): Likewise.
* os_dep.c [MPROTECT_VDB] (is_header_found_async): Likewise.
* pthread_stop_world.c [!NACL && !GC_OPENBSD_UTHREADS]
(update_last_stop_count): Likewise.
* pthread_stop_world.c [!NACL && !GC_OPENBSD_UTHREADS
&& GC_ENABLE_SUSPEND_THREAD] (set_suspended_ext_flag,
GC_resume_thread): Likewise.
* pthread_support.c [THREAD_SANITIZER && (USE_SPIN_LOCK
|| !NO_PTHREAD_TRYLOCK)] (is_collecting): Likewise.
* pthread_support.c [USE_SPIN_LOCK] (set_last_spins_and_high_spin_max,
reset_spin_max): Likewise.
* mark.c (GC_mark_from, GC_push_all_eager): Move
GC_ATTR_NO_SANITIZE_ADDR, GC_ATTR_NO_SANITIZE_MEMORY attributes to the
beginning of the function prototype.
* mach_dep.c (GC_with_callee_saves_pushed): Likewise.
* mark.c [WRAP_MARK_SOME && PARALLEL_MARK] (GC_push_conditional_eager):
Likewise.
Ivan Maidanski [Fri, 17 Nov 2017 18:32:40 +0000 (21:32 +0300)]
Workaround hangs in sigsuspend and sem_wait if compiled with TSan
Issue #181 (bdwgc).
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& THREAD_SANITIZER] (GC_suspend_handler_inner): Call
pthread_sigmask(SIG_SETMASK) with an empty set (thus unmask all
signals); add comment.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& THREAD_SANITIZER] (GC_stop_world): Call sem_trywait() repeatedly
(with a delay of 100 microseconds) while getting EAGAIN error (instead
of a sem_wait call).
Ivan Maidanski [Fri, 17 Nov 2017 18:20:54 +0000 (21:20 +0300)]
Revert 'Workaround a hang in sigsuspend if compiled with Thread Sanitizer'
This reverts commit
04fd7b5309596423e4342502d3123028d836d551.
Because it does not avoid hangs in all cases when stopping the world.
A better solution is to re-enable signals in the suspend handler.
Ivan Maidanski [Fri, 17 Nov 2017 17:36:47 +0000 (20:36 +0300)]
Allow to turn on spin locking even if thread-local allocations are used
* include/private/gc_locks.h [GC_PTHREADS && !GC_WIN32_THREADS
&& THREAD_LOCAL_ALLOC && !USE_PTHREAD_LOCKS] (UNCOND_LOCK,
UNCOND_UNLOCK): Use spin locks if USE_SPIN_LOCK is defined by client.
Ivan Maidanski [Fri, 17 Nov 2017 16:41:30 +0000 (19:41 +0300)]
Eliminate TSan false positive for stop_info.stack_ptr
Without this patch, Thread Sanitizer reports a data race between
GC_has_other_debug_info() and the code which sets stop_info.stack_ptr.
* include/private/pthread_support.h (GC_Thread_Rep.status): Move the
field to be before stop_info one (so, the latter now has the offset
of at least 3 in words, while oh.oh_sz has the offset of 2 in words
(when KEEP_BACK_PTRS, MAKE_BACK_GRAPH and NEED_CALLINFO are not
defined)).
Ivan Maidanski [Fri, 17 Nov 2017 08:07:03 +0000 (11:07 +0300)]
Eliminate TSan warning about data race when accessing GC_debugging_started
Now GC_debugging_started variable is double-checked with the allocation
lock held before calling GC_start_debugging_inner.
* dbg_mlc.c (GC_start_debugging_inner): Define as GC_INNER (instead of
STATIC).
* dbg_mlc.c [THREADS] (GC_start_debugging): Define as STATIC; do not
call GC_start_debugging_inner() if GC_debugging_started.
* dbg_mlc.c [!THREADS] (GC_start_debugging): Define as macro (redirect
to GC_start_debugging_inner).
* gcj_mlc.c (GC_debug_gcj_malloc): Call GC_start_debugging_inner
(holding the lock) instead of GC_start_debugging.
* include/private/gc_priv.h (GC_start_debugging): Rename to
GC_start_debugging_inner; improve usage comment.
Ivan Maidanski [Thu, 16 Nov 2017 08:20:32 +0000 (11:20 +0300)]
Fix typo in a function name in README.sgi
* doc/README.sgi (4): Fix a typo ("pthread_cond_timedwait").
Ivan Maidanski [Wed, 15 Nov 2017 22:15:14 +0000 (01:15 +0300)]
Workaround TSan false positives in extend_size_map
Thread Sanitizer reports data races between fill_size_map (called from
GC_extend_size_map) and GC_gcj_malloc[_ignore_off_page],
GC_malloc_kind_global, GC_generic_malloc_uncollectable,
GC_malloc_explicitly_typed_ignore_off_page which read a value from
GC_size_map before acquiring the allocation lock. These races could
be ignored as the value is verified after acquiring the lock.
* alloc.c: Refine comment about GC_allocobj (and GC_size_map) usage
for the case of a multi-threaded environment.
* malloc.c (fill_size_map): New static function (with
GC_ATTR_NO_SANITIZE_THREAD attribute).
* malloc.c (GC_extend_size_map): Use fill_size_map() to fill in
a region of GC_size_map.
Ivan Maidanski [Mon, 13 Nov 2017 19:58:37 +0000 (22:58 +0300)]
Remove GENERAL_MALLOC internal macro
(code refactoring)
* alloc.c: Update comment (about GC_allocobj usage).
* include/private/gc_priv.h (GENERAL_MALLOC): Remove.
* include/private/gc_priv.h (GENERAL_MALLOC_IOP): Move to typd_mlc.c.
* malloc.c (GC_malloc_kind_global): Expand GENERAL_MALLOC macro; copy
the comment from gc_priv.h.
Ivan Maidanski [Mon, 13 Nov 2017 06:04:04 +0000 (09:04 +0300)]
Workaround a hang in sigsuspend if compiled with Thread Sanitizer
Issue #181 (bdwgc).
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& THREAD_SANITIZER] (GC_suspend_handler_inner): Use sched_yield()
instead of sigsuspend(&suspend_handler_mask); add TODO item.
Ivan Maidanski [Mon, 13 Nov 2017 04:58:36 +0000 (07:58 +0300)]
Workaround TSan false positives in suspend/resume_thread
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& GC_ENABLE_SUSPEND_THREAD] (set_suspended_ext_flag): New static
function (with GC_ATTR_NO_SANITIZE_THREAD attribute); add comment.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& GC_ENABLE_SUSPEND_THREAD] (GC_suspend_thread): Call
set_suspended_ext_flag() instead of t->flags|=SUSPENDED_EXT.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& GC_ENABLE_SUSPEND_THREAD] (GC_resume_thread): Add
GC_ATTR_NO_SANITIZE_THREAD attribute; add comment.
Ivan Maidanski [Fri, 10 Nov 2017 17:07:16 +0000 (20:07 +0300)]
Fix data race when getting object size in explicitly-typed allocators
* typd_mlc.c (COMPLEX): Reformat comment.
* typd_mlc.c (GC_malloc_explicitly_typed,
GC_malloc_explicitly_typed_ignore_off_page, GC_calloc_explicitly_typed):
Always use BYTES_TO_GRANULES(GC_size(op)) instead of GC_size_map[lb] to
determine size of the allocated object in granules (because the value
of GC_size_map[lb] might be updated by another thread since the value
use in GC_malloc_kind); add comment.
Ivan Maidanski [Fri, 10 Nov 2017 15:44:57 +0000 (18:44 +0300)]
Remove 'ifdef USE_SPIN_LOCK' which is always false in gc_locks.h
(fix commit 9a20535)
* include/private/gc_locks.h [!GC_WIN32_THREADS && GC_PTHREADS
&& USE_PTHREAD_LOCKS && !GC_ASSERTIONS && NO_PTHREAD_TRYLOCK
&& USE_SPIN_LOCK] (UNCOND_LOCK): Define to
pthread_mutex_lock(&GC_allocate_ml) instead of GC_lock().
Ivan Maidanski [Fri, 10 Nov 2017 15:14:55 +0000 (18:14 +0300)]
Workaround TSan false positive in write fault handler
The data races reported between GC_write_fault_handler,
catch_exception_raise and GC_install_header, GC_remove_header are OK
as the added or removed header should be already unprotected.
* os_dep.c [MPROTECT_VDB && THREADS] (is_header_found_async): New
static function (with GC_ATTR_NO_SANITIZE_THREAD attribute).
* os_dep.c [MPROTECT_VDB && !THREADS] (is_header_found_async): New
macro.
* os_dep.c [MPROTECT_VDB && !DARWIN] (GC_write_fault_handler): Use
is_header_found_async() instead of HDR(addr)!=0.
* os_dep.c [MPROTECT_VDB && DARWIN] (catch_exception_raise): Likewise.
Ivan Maidanski [Fri, 10 Nov 2017 07:33:32 +0000 (10:33 +0300)]
Fix typo in 'gcdescr' documentation file
* doc/gcdescr.md (Allocation): Fix a typo ("the request is rounded").
Paul Bone [Fri, 10 Nov 2017 07:12:57 +0000 (10:12 +0300)]
Add basic calculation of the total full-collection time
Issue #139 (bdwgc).
New API functions: GC_start_performance_measurement,
GC_get_full_gc_total_time.
This patch is based on code originally written by Zoltan Somogyi
on 2008-03-18.
* alloc.c [!NO_CLOCK] (full_gc_total_time, measure_performance): New
static variable definition; add comment.
* alloc.c [!NO_CLOCK] (GC_start_performance_measurement,
GC_get_full_gc_total_time): New API function definition.
* alloc.c [!NO_CLOCK] (GC_try_to_collect_inner): Declare
start_time_valid local variable; set start_time_valid to true if
GET_TIME(start_time) is called; call GET_TIME(start_time) also if
measure_performance; declare time_diff local variable (used to store
the result of MS_TIME_DIFF()); GET_TIME(current_time) is called only
if start_time_valid; update full_gc_total_time if measure_performance.
* include/gc.h (GC_start_performance_measurement,
GC_get_full_gc_total_time): New API function declaration.
* tests/test.c (INIT_PERF_MEASUREMENT): New macro.
* tests/test.c (GC_COND_INIT): Call INIT_PERF_MEASUREMENT.
* tests/test.c [!NO_CLOCK] (check_heap_stats): Call
GC_get_full_gc_total_time() and print the total time of full
collections.
Ivan Maidanski [Fri, 3 Nov 2017 18:30:23 +0000 (21:30 +0300)]
Fix double lock in a_set(f(a_get())) expression in gctest
(fix commit 8f5746e)
* tests/test.c [!AO_HAVE_store_release] (AO_store_release): Replace
macro with a static function definition (so, new_val argument is
evaluated before acquiring the lock).
Ivan Maidanski [Fri, 3 Nov 2017 17:08:09 +0000 (20:08 +0300)]
Fix data race in a list referenced by A.aa (gctest)
* tests/test.c [!AO_HAVE_load] (AO_load): Remove macro.
* tests/test.c [!AO_HAVE_store] (AO_store): Likewise.
* tests/test.c [!AO_HAVE_load_acquire] (AO_load_acquire): New static
function (which uses FINALIZER_LOCK/FINALIZER_UNLOCK).
* tests/test.c [!AO_HAVE_store_release] (AO_store_release): New macro
(which uses FINALIZER_LOCK/FINALIZER_UNLOCK).
* tests/test.c [!AO_HAVE_fetch_and_add1] (AO_fetch_and_add1): Add
comment.
* tests/test.c (a_set): Use AO_store_release() instead of AO_store().
* tests/test.c (a_get): Use AO_load_acquire() instead of AO_load().
* tests/test.c (reverse_test_inner): Improve comment about thread
safety of a_set(reverse(reverse(a_get()))).
Ivan Maidanski [Fri, 3 Nov 2017 08:03:04 +0000 (11:03 +0300)]
Avoid data race in finalized_count (gctest)
* tests/test.c (FINALIZER_LOCK, FINALIZER_UNLOCK): New macro.
* tests/test.c [GC_PTHREADS] (incr_lock): Move static variable out
of finalizer() and mktree() (use a single lock variable to access
finalized_count in finalizer, mktree and tree_test).
* tests/test.c (dropped_something): Change type back to int; remove
volatile.
* tests/test.c (finalizer, mktree): Use FINALIZER_[UN]LOCK() instead
of PCR_ThCrSec_Enter/ExitSys(), pthread_mutex_[un]lock(),
Enter/LeaveCriticalSection().
* tests/test.c (tree_test): Use FINALIZER_[UN]LOCK() to avoid data
race when accessing finalized_count and dropped_something; do not use
AO_load() and AO_store() to access dropped_something.
* tests/test.c
Ivan Maidanski [Thu, 2 Nov 2017 21:58:18 +0000 (00:58 +0300)]
Eliminate TSan warning about A.dummy in gctest
* tests/test.c (reverse_test_inner): Move A.dummy=17 to
set_print_procs().
* tests/test.c (set_print_procs): Add comment.
Ivan Maidanski [Thu, 2 Nov 2017 21:38:00 +0000 (00:38 +0300)]
Revert 'Eliminate TSan warnings (false positives) in gctest'
This reverts commit
c7837f864970e3859a3b35b9b8c0858a3548a457.
Because it does not avoid potential data race between GC_malloc
(invoked from cons) and check_ints; the proper solution seems to
just use AO_load_acquire and AO_store_release to access A.aa.
Ivan Maidanski [Wed, 1 Nov 2017 21:31:11 +0000 (00:31 +0300)]
Eliminate TSan warnings (false positives) in gctest
* tests/test.c (struct SEXPR): Declare first.
* tests/test.c (union sexpr_or_aot_u): New type.
* tests/test.c (struct SEXPR): Replace struct SEXPR* to sexpr_or_aot_u.
* tests/test.c (car, cdr, small_cons_uncollectable): Add .p suffix when
accessing sexpr_car and sexpr_cdr fields.
* tests/test.c [GC_GCJ_SUPPORT] (fake_gcj_mark_proc, gcj_cons):
Likewise.
* tests/test.c [!VERY_SMALL_CONFIG] (small_cons): Likewise.
* tests/test.c (atomic_car, atomic_cdr): New macro; add comment.
* tests/test.c [!VERY_SMALL_CONFIG] (cons): Store atomic_car and
atomic_cdr atomically.
* tests/test.c [VERY_SMALL_CONFIG] (small_cons): Likewise.
* tests/test.c [!VERY_SMALL_CONFIG] (cons): Ignore store random value
at *p if p points inside r->sexpr_car/cdr; add comment.
* tests/test.c (reverse1, check_ints): Use atomic_car() and
atomic_cdr() instead of car() and cdr(), respectively.
* tests/test.c (reverse_test_inner): Move A.dummy=17 to
set_print_procs().
* tests/test.c (set_print_procs): Add comment.
Ivan Maidanski [Tue, 31 Oct 2017 21:38:00 +0000 (00:38 +0300)]
Workaround TSan false positives in mark_from, push_*_eager
* mark.c (GC_mark_from, GC_push_all_eager): Annotate with
GC_ATTR_NO_SANITIZE_THREAD.
* mark.c [WRAP_MARK_SOME && PARALLEL_MARK] (GC_push_conditional_eager):
Likewise.
Ivan Maidanski [Tue, 31 Oct 2017 08:49:55 +0000 (11:49 +0300)]
Workaround TSan false positive in [set_]mark_bit_from_hdr
There is no data race between GC_set_fl_marks and GC_is_marked because
bit_no is different.
* include/private/gc_priv.h [THREADS && THREAD_SANITIZER]: Include
gc_atomic_ops.h.
* include/private/gc_priv.h [!USE_MARK_BYTES && THREAD_SANITIZER
&& THREADS] (OR_WORD): Use AO_or; update comment.
Ivan Maidanski [Mon, 30 Oct 2017 22:09:56 +0000 (01:09 +0300)]
Workaround TSan false positive in invoke_finalizers
* finalize.c [THREADS && !THREAD_SANITIZER] (GC_invoke_finalizers): Do
not compare bytes_freed_before to GC_bytes_freed without the lock; add
comment.
* include/private/gc_priv.h (_GC_arrays._finalizer_bytes_freed): Replace
"mem." to "memory" in a comment.
Paul Bone [Sun, 29 Oct 2017 07:39:31 +0000 (10:39 +0300)]
Print time passed since GC initialization in GC_dump
Issue #139 (bdwgc).
* misc.c [!NO_DEBUGGING && !NO_CLOCK] (GC_init_time): New static
variable.
* misc.c [!NO_DEBUGGING && !NO_CLOCK] (GC_init): Set GC_init_time.
* misc.c [!NO_DEBUGGING && !NO_CLOCK] (GC_dump_named): Define
current_time local variable; print the time since GC initialization
(in milliseconds); add comment.
Ivan Maidanski [Thu, 26 Oct 2017 05:35:37 +0000 (08:35 +0300)]
Update ChangeLog file
Ivan Maidanski [Thu, 26 Oct 2017 05:31:47 +0000 (08:31 +0300)]
Update ChangeLog file (v7.6 changes only)
Ivan Maidanski [Wed, 25 Oct 2017 15:32:35 +0000 (18:32 +0300)]
Update ChangeLog file (v7.4 changes only)
Ivan Maidanski [Wed, 25 Oct 2017 08:45:38 +0000 (11:45 +0300)]
Do not use system clock consistently if NO_CLOCK
Issue #139 (bdwgc).
* alloc.c (GC_try_to_collect_inner, world_stopped_total_time,
world_stopped_total_divisor, MAX_TOTAL_TIME_DIVISOR, GC_stopped_mark):
Replace "ifndef SMALL_CONFIG" with "ifndef NO_CLOCK".
* reclaim.c (GC_reclaim_all): Likewise.
* alloc.c (GC_finish_collection): Replace "ifndef SMALL_CONFIG" with
"ifndef NO_CLOCK" except for GC_print_finalization_stats invocation.
* doc/README.macros (NO_CLOCK): Document.
* include/private/gc_priv.h (CLOCK_TYPE, GET_TIME, MS_TIME_DIFF): Do
not define if NO_CLOCK.
* include/private/gc_priv.h (GC_print_stats): Define as a macro (to 0)
only if both NO_CLOCK and SMALL_CONFIG are defined.
* misc.c (GC_print_stats): Do not define if both NO_CLOCK and
SMALL_CONFIG are defined.
* misc.c (GC_init): Do not set GC_print_stats only if both NO_CLOCK
and SMALL_CONFIG are defined.
* tests/test.c (run_one_test): Do not define start_time, reverse_time,
time_diff local variables (and do not use GET_TIME, MS_TIME_DIFF) if
NO_CLOCK is defined.
Ivan Maidanski [Wed, 25 Oct 2017 08:12:34 +0000 (11:12 +0300)]
Travis CI: Test NO_CLOCK
Ivan Maidanski [Tue, 24 Oct 2017 21:06:22 +0000 (00:06 +0300)]
Make extend_size_map() static
(code refactoring)
* include/private/gc_priv.h (GC_extend_size_map): Remove prototype.
* malloc.c (GC_extend_size_map): Move the function definition from
misc.c; change GC_INNER to STATIC; reformat code; remove j and
much_smaller_than_i local variables; add assertions that I_HOLD_LOCK
and GC_size_map[i]==0; remove comment that GC_size_map[i] is expected
to be zero.
* malloc.c (GC_generic_malloc_inner): Capitalize the first letter of
the description comment.
* misc.c (GC_extend_size_map): Remove the definition.
Ivan Maidanski [Mon, 23 Oct 2017 21:10:12 +0000 (00:10 +0300)]
Fix typos in documentation (for extend_size_map and ews4800)
* doc/README.ews4800: Fix typos ("32-bit", "64-bit").
* misc.c (GC_extend_size_map): Fix typo ("16-byte") in a comment.
Ivan Maidanski [Fri, 20 Oct 2017 18:54:06 +0000 (21:54 +0300)]
Add two-argument alloc_size attribute to calloc_explicitly_typed (GCC)
* include/gc_config_macros.h [!GC_ATTR_CALLOC_SIZE]
(GC_ATTR_CALLOC_SIZE): New macro (which uses alloc_size attribute
if GCC or Clang).
* include/gc_typed.h (GC_calloc_explicitly_typed): Add
GC_ATTR_CALLOC_SIZE(1,2) attribute.
Ivan Maidanski [Fri, 20 Oct 2017 18:15:54 +0000 (21:15 +0300)]
Use __declspec(allocator) for malloc-like prototypes (MS VS 2015+)
* include/gc_config_macros.h [_MSC_VER>=1900 && !__EDG__]
(GC_ATTR_MALLOC): Add __declspec(allocator).
Ivan Maidanski [Fri, 20 Oct 2017 09:16:20 +0000 (12:16 +0300)]
Revert 'Never try to include private/config.h'
This reverts commit
6abcbd9101a17443a848e58f6bad45d0b0aa4d1a.
Because "config.h" file may be located in some folder other than the
parent of "private" folder, e.g. during "make distcheck".
Ivan Maidanski [Thu, 19 Oct 2017 21:25:52 +0000 (00:25 +0300)]
Workaround Thread Sanitizer (TSan) false positive warnings (partially)
This patch covers only data race false positive warnings reported in
async_set_pht_entry_from_index, GC_clear_stack, GC_invoke_finalizers,
GC_lock, GC_noop1, GC_notify_or_invoke_finalizers, GC_pthread_create,
GC_suspend_handler_inner, I_DONT_HOLD_LOCK.
* finalize.c (GC_should_invoke_finalizers): Add
GC_ATTR_NO_SANITIZE_THREAD.
* mark.c (GC_noop1): Likewise.
* os_dep.c [MPROTECT_VDB && THREADS && AO_HAVE_test_and_set_acquire]
(async_set_pht_entry_from_index): Likewise.
* finalize.c (GC_invoke_finalizers, GC_notify_or_invoke_finalizers):
Call GC_should_invoke_finalizers() instead of
GC_fnlz_roots.finalize_now!=NULL.
* include/private/gc_locks.h [(GC_WIN32_THREADS && !USE_PTHREAD_LOCKS
|| GC_PTHREADS) && GC_ASSERTIONS && THREAD_SANITIZER]
(I_DONT_HOLD_LOCK): Define to TRUE; add comment.
* include/private/gc_locks.h [!GC_ALWAYS_MULTITHREADED
&& THREAD_SANITIZER] (set_need_to_lock): Do not set GC_need_to_lock if
already set; add comment.
* include/private/gc_priv.h [!GC_ATTR_NO_SANITIZE_THREAD]
(GC_ATTR_NO_SANITIZE_THREAD): New macro.
* include/private/gcconfig.h [__has_feature &&
__has_feature(thread_sanitizer)] (THREAD_SANITIZER): Define.
* misc.c [THREADS] (next_random_no): New static function (with
GC_ATTR_NO_SANITIZE_THREAD).
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(update_last_stop_count): Likewise.
* pthread_support.c [THREAD_SANITIZER && (USE_SPIN_LOCK
|| !NO_PTHREAD_TRYLOCK)] (is_collecting): Likewise.
* pthread_support.c [USE_SPIN_LOCK] (set_last_spins_and_high_spin_max,
reset_spin_max): Likewise.
* misc.c [THREADS] (GC_clear_stack): Remove random_no static variable;
use next_random_no() instead of ++random_no%13.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_suspend_handler_inner): Call update_last_stop_count() instead of
me->stop_info.last_stop_count=my_stop_count.
* pthread_support.c [USE_SPIN_LOCK || !NO_PTHREAD_TRYLOCK] (SPIN_MAX):
Define only if not yet.
* pthread_support.c [USE_SPIN_LOCK || !NO_PTHREAD_TRYLOCK]
(GC_collecting): Initialize to FALSE instead of 0.
* pthread_support.c [!(THREAD_SANITIZER && (USE_SPIN_LOCK
|| !NO_PTHREAD_TRYLOCK))] (is_collecting): Define as a macro.
* pthread_support.c [USE_SPIN_LOCK] (low_spin_max, high_spin_max,
spin_max, last_spins): Move definition out of GC_lock().
* pthread_support.c (GC_lock): Use is_collecting(),
set_last_spins_and_high_spin_max() and reset_spin_max().
Ivan Maidanski [Wed, 18 Oct 2017 19:37:30 +0000 (22:37 +0300)]
Refine should_invoke_finalizers documentation
* include/gc.h (GC_should_invoke_finalizers): Add comment that it is
not synchronized.
Ivan Maidanski [Wed, 18 Oct 2017 10:34:08 +0000 (13:34 +0300)]
Never try to include private/config.h
config.h is now located in "include" folder (not "include/private").
* include/private/gc_pmark.h [HAVE_CONFIG_H && !GC_PRIVATE_H]
(include config.h): Add "../" prefix.
* include/private/gc_priv.h [HAVE_CONFIG_H] (include config.h):
Likewise.
Ivan Maidanski [Tue, 17 Oct 2017 21:20:47 +0000 (00:20 +0300)]
.gitignore: Do not ignore include/private/config.h
config.h was moved to "include" folder in gc-7.4.0.
Ivan Maidanski [Tue, 17 Oct 2017 08:52:20 +0000 (11:52 +0300)]
Update AUTHORS file (add Erik M. Bray)
Erik M. Bray [Tue, 17 Oct 2017 08:50:03 +0000 (11:50 +0300)]
Use mprotect instead of mmap in GC_unmap() on Cygwin
Issue #187 (BDWGC).
* configure.ac [$enable_munmap!="" && $enable_munmap!=no]
(USE_WINALLOC): Replace AC_DEFINE with AH_TEMPLATE; remove comment
about a workaround for Cygwin; remove "if $host=*-*-cygwin*".
* os_dep.c [CYGWIN32 && USE_MUNMAP] (GC_setpagesize): Set GC_page_size
to dwAllocationGranularity (instead of dwPageSize); add comment; add
assertion that dwAllocationGranularity is not less than dwPageSize.
* os_dep.c [USE_MUNMAP && CYGWIN32 && !USE_WINALLOC] (GC_unmap,
GC_unmap_gap): Call mprotect() instead of mmap(); add comment.
Ivan Maidanski [Mon, 16 Oct 2017 21:02:27 +0000 (00:02 +0300)]
Fix 'package requirements (atomic_ops) were not met' configure error
(fix commit 3d34335)
* configure.ac [$missing_libatomic_ops] (PKG_CHECK_MODULES):
Pass no-op to action-if-not-found parameter (because the default
action-if-not-found ends the execution with an error in case of the
missing dependency).
Ivan Maidanski [Mon, 16 Oct 2017 08:00:53 +0000 (11:00 +0300)]
Allow PKG_CHECK_MODULES in configure.ac to be commented out easily
(code refactoring)
* configure.ac [$with_libatomic_ops!=no && $with_libatomic_ops!=none]
(missing_libatomic_ops): Set to true (before PKG_CHECK_MODULES).
* configure.ac [$missing_libatomic_ops] (PKG_CHECK_MODULES): Set
missing_libatomic_ops back to false if atomic_ops module is not found;
add comment (about pkg-config and the possibility to comment out
PKG_CHECK_MODULES).
Ivan Maidanski [Mon, 16 Oct 2017 07:25:57 +0000 (10:25 +0300)]
New API function (GC_is_init_called) to check if BDWGC is initialized
Issue #186 (bdwgc).
* include/gc.h (GC_is_init_called): New API function declaration.
* misc.c (GC_is_init_called): New API function definition.
* tests/test.c (check_heap_stats): Add a test that GC is initialized.
Ivan Maidanski [Thu, 12 Oct 2017 22:38:25 +0000 (01:38 +0300)]
Test GC initialization from non-main thread on FreeBSD and NetBSD
Issue #180 (bdwgc).
* tests/initsecondarythread.c [(FREEBSD || LINUX || NETBSD)
&& !NO_PTHREAD_GETATTR_NP && !NO_PTHREAD_ATTR_GET_NP] (main): Do not
call GC_INIT().