Ivan Maidanski [Fri, 30 Mar 2018 17:41:41 +0000 (20:41 +0300)]
Unblock only GC signals in suspend_handler (TSan)
Issue #181 (bdwgc).
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& THREAD_SANITIZER] (GC_suspend_handler_inner): Replace
pthread_sigmask(SIG_SETMASK) to pthread_sigmask(SIG_UNBLOCK) with the
set with GC_sig_suspend and GC_sig_thr_restart signals.
Ivan Maidanski [Thu, 29 Mar 2018 08:50:36 +0000 (11:50 +0300)]
Add assertions about held lock when accessing all_bottom_indices
(code refactoring)
* headers.c (GC_all_bottom_indices, GC_all_bottom_indices_end): Add
comment that the variable should be accessed with the allocation lock
held.
* headers.c (get_index, GC_apply_to_all_blocks, GC_next_used_block,
GC_prev_block): Add assertion (at the beginning of the function) that
the allocation lock is held.
Ivan Maidanski [Thu, 29 Mar 2018 08:40:44 +0000 (11:40 +0300)]
Update top_index entry pointer only when the entry is constructed fully
(code refactoring)
* headers.c [HASH_TL] (get_index): Remove old local variable (use pi
instead).
* headers.c (get_index): Eliminate code duplication; use EXPECT() to
check the result of GC_scratch_alloc().
* headers.c (get_index): Update GC_top_index[i] value only at the end
of the function.
Ivan Maidanski [Thu, 29 Mar 2018 06:54:39 +0000 (09:54 +0300)]
Minimize delay between sem_post and sigsuspend in suspend_handler if TSan
(fix of commit af409e4)
Issue #181 (bdwgc).
This change is to do as less as possible (even in case of TSan usage)
between the sem_post and sigsuspend calls in GC_suspend_handler_inner
(to match the relevant comment after sigsuspend call).
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& THREAD_SANITIZER] (GC_suspend_handler_inner): Move sigemptyset()
and pthread_sigmask() calls to be just before sem_post() call.
Ivan Maidanski [Fri, 23 Mar 2018 18:29:28 +0000 (21:29 +0300)]
Avoid potential race between malloc_kind and mark_thread_local_fls_for
Issue #214 (bdwgc).
* include/gc_inline.h (GC_FAST_M_AO_STORE): New internal macro.
* include/gc_inline.h (GC_FAST_MALLOC_GRANS): Use GC_FAST_M_AO_STORE.
* thread_local_alloc.c [THREAD_LOCAL_ALLOC]
(GC_mark_thread_local_fls_for): Use AO_load to get _freelists[i][j]
value; add comment.
* thread_local_alloc.c [THREAD_LOCAL_ALLOC && GC_GCJ_SUPPORT]
(GC_mark_thread_local_fls_for): Use AO_load to get gcj_freelists[j].
Ivan Maidanski [Fri, 23 Mar 2018 08:13:23 +0000 (11:13 +0300)]
Fix thread_suspend fail for threads registered from key destructor (OS X)
Issue #213 (bdwgc).
* pthread_support.c [GC_DARWIN_THREADS] (GC_register_my_thread):
Reinitialize stop_info.mach_thread if the thread is registered from
the client thread key destructor; add comment.
Ivan Maidanski [Thu, 22 Mar 2018 21:41:13 +0000 (00:41 +0300)]
Match GC_FAST_MALLOC_GRANS formal and actual arguments where possible
(code refactoring)
* include/gc_inline.h (GC_MALLOC_WORDS_KIND): Rename k argument to kind.
* include/gc_inline.h (GC_MALLOC_WORDS_KIND, GC_CONS): Rename grans
local variable to granules.
* thread_local_alloc.c [THREAD_LOCAL_ALLOC] (GC_malloc_kind): Rename
knd to kind.
Ivan Maidanski [Thu, 22 Mar 2018 07:37:00 +0000 (10:37 +0300)]
Check consistency of descr, adjust, clear arguments of GC_new_kind
Issue #83 (bdgwc).
* misc.c (GC_new_kind_inner): Improve assertion about clear argument
to check for the consistency of descr and adjust arguments (in case of
clear is false).
Ivan Maidanski [Wed, 21 Mar 2018 07:26:10 +0000 (10:26 +0300)]
Fix ASSERT_CANCEL_DISABLED violation in try_to_collect_inner
(fix of commit b04b346)
Issue #182 (bdwgc).
* finalize.c (GC_ON_GROW_LOG_SIZE_MIN): Define to CPP_LOG_HBLKSIZE
value by default.
* finalize.c (GC_grow_table): Surround GC_try_to_collect_inner call
with DISABLE/RESTORE_CANCEL.
Ivan Maidanski [Tue, 20 Mar 2018 21:58:24 +0000 (00:58 +0300)]
Fix unbounded heap growth in case of intensive disappearing links usage
Issue #182 (bdwgc).
* finalize.c (GC_ON_GROW_LOG_SIZE_MIN): New macro.
* finalize.c (GC_grow_table): Rename size_ptr to log_size_ptr in
comment; add entries_ptr argument; add comment; call if log_old_size is
GC_ON_GROW_LOG_SIZE_MIN or bigger then call GC_try_to_collect_inner
and, then, return from the function if the number of entries is less
than 75% of the table capacity.
* finalize.c (GC_register_disappearing_link_inner): Pass
dl_hashtbl->entries pointer to GC_grow_table.
* finalize.c (GC_register_finalizer_inner): Pass GC_fo_entries pointer
to GC_grow_table.
Ivan Maidanski [Tue, 13 Mar 2018 08:02:27 +0000 (11:02 +0300)]
Use atomic load/store for the concurrently accessed variables in GC_lock
* include/private/gc_locks.h [!GC_WIN32_THREADS && GC_PTHREADS
&& AO_HAVE_char_store] (ENTER_GC, EXIT_GC): Use AO_char_store to update
GC_collecting.
* pthread_support.c [AO_HAVE_char_load] (is_collecting): Replace
function to macro (and remove GC_ATTR_NO_SANITIZE_THREAD); use
AO_char_load to get GC_collecting value; remove .
* pthread_support.c [USE_SPIN_LOCK] (spin_max, last_spins): Change type
from unsigned to AO_t; reformat comment.
* pthread_support.c [USE_SPIN_LOCK] (set_last_spins_and_high_spin_max,
reset_spin_max): Remove static functions (together with
GC_ATTR_NO_SANITIZE_THREAD).
* pthread_support.c [USE_SPIN_LOCK] (GC_lock): Use AO_load to get
spin_max and last_spins values; replace set_last_spins_and_high_spin_max
and reset_spin_max calls with the relevant AO_store calls.
Ivan Maidanski [Wed, 7 Mar 2018 17:40:05 +0000 (20:40 +0300)]
Avoid potential race when storing oh_back_ptr during parallel marking
* dbg_mlc.c [KEEP_BACK_PTRS && PARALLEL_MARK] (GC_store_back_pointer):
Store source to dest->oh_back_ptr atomically (unordered atomic store
is sufficient here).
Ivan Maidanski [Tue, 6 Mar 2018 22:13:15 +0000 (01:13 +0300)]
Workaround Haiku pthread_join failure in subthreadcreate_test
Issue #97 (bdwgc).
The underlying pthread_join fails because of some bug in Haiku OS
(as of hrev51798) when many threads are created in parallel.
* tests/subthread_create.c [__HAIKU__]: Include errno.h.
* tests/subthread_create.c [__HAIKU__] (main): If pthread_join returned
value is ESRCH then just end the test normally (i.e. ignore the failure
of pthread_join); add comment and TODO item.
Ivan Maidanski [Fri, 2 Mar 2018 09:03:01 +0000 (12:03 +0300)]
Change backtrace-specific code to comply with C++11 standard
Issue #206 (bdwgc).
* dbg_mlc.c (GC_get_back_ptr_info): Cast GC_REVEAL_POINTER() result
to ptr_t (when assigned to bp local variable).
* dbg_mlc.c (GC_generate_random_valid_address): Cast result of
GC_generate_random_heap_address() to ptr_t.
* dbg_mlc.c (GC_print_backtrace): Cast GC_print_heap_obj() argument
to ptr_t.
Ivan Maidanski [Wed, 28 Feb 2018 06:40:27 +0000 (09:40 +0300)]
Remove a redundant check of __cplusplus in Symbian-specific .cpp files
(code refactoring)
* extra/symbian.cpp: Remove "#ifdef __cplusplus" as the latter should
be defined (by default) in case of .cpp file.
* extra/symbian/global_end.cpp: Likewise.
* extra/symbian/global_start.cpp: Likewise.
* extra/symbian/init_global_static_roots.cpp: Likewise.
* extra/symbian/init_global_static_roots.cpp
(GC_init_global_static_roots): Adjust indentation.
Hans Boehm [Mon, 26 Feb 2018 20:45:24 +0000 (23:45 +0300)]
Avoid potential race when accessing size_map table
There is again a data race between GC_extend_size_map and GC_size_map[]
readers, though it is again not likely to fail in practice.
It is feasible to just move all of the GC_size_map accesses under the
lock, and this does not look to incur a substantial penalty.
* gcj_mlc.c (GC_gcj_malloc, GC_gcj_malloc_ignore_off_page): Move
lg=GC_size_map[lb] to be right after LOCK() instead of preceding it.
* malloc.c (GC_malloc_kind_global, GC_generic_malloc_uncollectable):
Likewise.
* typd_mlc.c (GC_malloc_explicitly_typed_ignore_off_page): Likewise.
* include/gc.h (GC_get_size_map_at): Update comment to note that the
client should use synchronization when calling the function.
* include/private/gc_priv.h (_GC_arrays._size_map): Add comment about
synchronization.
Jay Krell [Sun, 18 Feb 2018 05:23:34 +0000 (21:23 -0800)]
Fiddle with linkage to make extra/gc.c valid C++ code
Issue #206 (bdwgc).
Specifically: int i; int i = 0; is not valid, but:
extern int i; int i = 0; is valid. Adding static would also be
desirable here but requires a larger change.
* extra/gc.c (GC_INNER, GC_EXTERN): Do not define if __cplusplus; add
comment and TODO item.
Jay Krell [Mon, 26 Feb 2018 04:53:37 +0000 (07:53 +0300)]
Change Darwin-specific code to comply with C++11 standard
Issue #206 (bdwgc).
* darwin_stop_world.c (GC_stack_range_for): Cast pointer which is
assinged to lo local variable to ptr_t (instead of void*).
* os_dep.c [GC_DARWIN_THREADS && MPROTECT_VDB]: Include
darwin_stop_world.h (so that GC_mprotect_stop and GC_mprotect_resume
to be declared and later defined as extern "C").
* os_dep.c [MPROTECT_VDB && DARWIN] (exc_server, exception_raise,
exception_raise_state): Wrap into extern "C" block; refine comment.
* os_dep.c [MPROTECT_VDB && DARWIN] (catch_exception_raise_state,
catch_exception_raise_state_identity): Declare as extern "C" (before
the definition).
* os_dep.c [MPROTECT_VDB && DARWIN && THREADS] (GC_mprotect_state):
Initialize to GC_MP_NORMAL (instead of integer 0).
Ivan Maidanski [Thu, 22 Feb 2018 20:39:38 +0000 (23:39 +0300)]
Fix type of local variables receiving result of PHT_HASH
The variables should be of word type, not int or size_t.
* os_dep.c (GC_write_fault_handler, GC_remove_protection): Change type
of index local variable from size_t to word.
* os_dep.c [MPROTECT_VDB && DARWIN] (catch_exception_raise): Change
type of index local variable from int to word.
Jay Krell [Mon, 12 Feb 2018 21:34:21 +0000 (00:34 +0300)]
Change pointer arguments of push_all[_eager]/conditional API to void* type
Receiving void* instead of char* is easier to use, as it requires
no casting.
A small downside of this change is that anyone using decltype(GC_push)
in C++ function signatures would get a different name mangling.
* include/gc_mark.h (GC_push_all, GC_push_all_eager,
GC_push_conditional): Change type of bottom and top arguments from
char* to void*.
* mark.c (GC_push_all, GC_push_conditional, GC_push_all_eager):
Likewise.
* include/private/gc_priv.h (GC_PUSH_ALL_SYM): Cast away volatile
qualifier for &sym.
* mark.c (GC_push_all): Remove "register" keyword for length local
variable.
* mark.c [!GC_DISABLE_INCREMENTAL] (GC_push_selected): Remove unneeded
casts for GC_push_all arguments.
* mark.c [WRAP_MARK_SOME && PARALLEL_MARK] (GC_push_conditional_eager):
Change type of bottom and top arguments from ptr_t to void*.
* mark_rts.c [WRAP_MARK_SOME && PARALLEL_MARK]
(GC_push_conditional_eager): Likewise.
* mark_rts.c (GC_PUSH_CONDITIONAL): Remove unneeded casts for
GC_push_all and GC_push_conditional arguments.
Hans Boehm [Mon, 12 Feb 2018 08:24:54 +0000 (11:24 +0300)]
Avoid potential race between realloc and clear_hdr_marks/reclaim_generic
GC_realloc might be changing the block size while GC_reclaim_block
or GC_clear_hdr_marks is examining it. The change to the size field
is benign, in that GC_reclaim (and GC_clear_hdr_marks) would work
correctly with either value, since we are not changing the number
of objects in the block. But seeing a half-updated value (though
unlikely to occur in practice) could be probably bad.
Using unordered atomic accesses on the size and hb_descr fields would
solve the issue.
* mallocx.c [AO_HAVE_store] (GC_realloc): Use AO_store() to update
hhdr->hb_sz and hhdr->hb_descr; add static assert that size of
hhdr->hb_sz matches that of AO_t; add comment.
* mallocx.c [!AO_HAVE_store] (GC_realloc): Add LOCK/UNLOCK around
hb_sz and hb_descr fields assignment.
* mark.c [AO_HAVE_load] (GC_clear_hdr_marks): Use AO_load() to get
hhdr->hb_sz value; add comment.
* reclaim.c (IS_PTRFREE_SAFE): New macro (uses AO_load() if available).
* reclaim.c (GC_reclaim_generic, GC_reclaim_block): Replace
(hhdr)->hb_descr==0 with IS_PTRFREE_SAFE(hhdr).
Because it is not a false positive. And we are lying to the compiler
about the value not changing asynchronously, which is never good.
The proper solution could be use of atomic accesses (even unordered)
on the size field.
Ivan Maidanski [Fri, 9 Feb 2018 08:17:29 +0000 (11:17 +0300)]
Fix build of cord tests as C++ files (Makefile.direct)
* Makefile.direct (cords): Do not depend on cord/cordtest.
* Makefile.direct (cord): Remove.
* Makefile.direct (cord/cordbscs.o, cord/cordxtra.o, cord/cordprnt.o):
Do not depend on cord target (folder); add "mkdir cord" (ignoring
errors) before moving .o file to "cord" folder.
Ivan Maidanski [Thu, 8 Feb 2018 08:41:45 +0000 (11:41 +0300)]
Change type of hb_sz field (of hblkhdr) from size_t to word
This is needed to make the size of hb_sz to be the same as of AO_t.
* allchblk.c [USE_MUNMAP] (GC_unmap_old): Cast hhdr->hb_sz to size_t
when passed to GC_unmap().
* allchblk.c (GC_allochblk_nth): Cast hhdr->hb_sz to signed_word when
assigned to size_avail.
* allchblk.c [USE_MUNMAP] (GC_allochblk_nth): Cast hhdr->hb_sz to
size_t when passed to GC_remap().
* alloc.c (GC_set_fl_marks, GC_clear_fl_marks): Change type of sz and
bit_no local variables from size_t/unsigned to word.
* dbg_mlc.c (GC_check_heap_block): Likewise.
* backgraph.c [MAKE_BACK_GRAPH] (per_object_helper): Cast hhdr->hb_sz
to size_t; change type of i local variables from int to size_t.
* checksums.c [CHECKSUMS] (GC_on_free_list): Change type of sz local
variable from size_t to word.
* mark.c (GC_push_marked, GC_push_unconditionally, GC_block_was_dirty):
Likewise.
* reclaim.c (GC_reclaim_small_nonempty_block,
GC_disclaim_and_reclaim_or_free_small_block, GC_reclaim_block,
GC_n_set_marks): Likewise.
* checksums.c [CHECKSUMS] (GC_add_block): Remove bytes local variable
(to avoid casting of hhdr->hb_sz).
* dbg_mlc.c (GC_debug_free): Change type of i and obj_sz local
variables from size_t to word.
* dbg_mlc.c (GC_check_leaked): Likewise.
* extra/pcr_interface.c (GC_enumerate_block): Change type of sz local
variable from int to size_t.
* extra/pcr_interface.c (GC_enumerate_block): Cast hhdr->hb_sz to
size_t when assigned to sz.
* mallocx.c (GC_realloc): Likewise.
* mark.c (GC_set_hdr_marks): Likewise.
* reclaim.c (GC_do_enumerate_reachable_objects): Likewise.
* include/private/gc_pmark.h [MARK_BIT_PER_OBJ] (PUSH_CONTENTS_HDR):
Cast hhdr->hb_sz to size_t in assignment of obj_displ.
* include/private/gc_priv.h (struct hblkhdr): Change type of hb_sz from
size_t to word.
* include/private/gc_priv.h (MARK_BIT_NO): Cast offset argument to word
instead of unsigned.
* malloc.c (GC_free): Cast hhdr->hb_sz to size_t.
* mallocx.c (GC_get_kind_and_size): Likewise.
* mark.c (GC_clear_hdr_marks): Likewise.
* misc.c (GC_size): Likewise.
* misc.c (GC_do_blocking): Remove redundant cast of hhdr->hb_sz.
* reclaim.c (GC_reclaim_clear, GC_reclaim_uninit,
GC_disclaim_and_reclaim, GC_continue_reclaim): Change type of sz
argument from size_t to word.
* typd_mlc.c (GC_array_mark_proc): Change type of sz and nwords local
variables from size_t to word.