]> granicus.if.org Git - gc/log
gc
7 years agoFix data race in mark_thread when updating mark_no
Ivan Maidanski [Fri, 1 Dec 2017 16:23:13 +0000 (19:23 +0300)]
Fix data race in mark_thread when updating mark_no
(Cherry-pick commit 613ec90c from 'master' branch.)

* 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.

7 years agoFix assertion violation about disabled cancel in try_to_collect_inner
Ivan Maidanski [Wed, 29 Nov 2017 22:10:20 +0000 (01:10 +0300)]
Fix assertion violation about disabled cancel in try_to_collect_inner
(Cherry-pick commit 218bfbfa from 'master' branch.)

* misc.c [!GC_DISABLE_INCREMENTAL && !KEEP_BACK_PTRS]
(GC_enable_incremental): Wrap GC_gcollect_inner and GC_read_dirty calls
into DISABLE/RESTORE_CANCEL.

7 years agoFix data race in make_descriptor when setting explicit_typing_initialized
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).

7 years agoFix lack of barriers to synchronize memory for suspend_handler
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.

7 years agoFix data race in last_stop_count access (suspend_handler_inner)
Ivan Maidanski [Thu, 23 Nov 2017 17:15:54 +0000 (20:15 +0300)]
Fix data race in last_stop_count access (suspend_handler_inner)
(Cherry-pick commit 11792032 from 'master' branch.)

* 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).

7 years agoFix data race in GC_suspend/resume_thread
Ivan Maidanski [Thu, 23 Nov 2017 09:20:18 +0000 (12:20 +0300)]
Fix data race in GC_suspend/resume_thread
(Cherry-pick commits ce09fd557b6576 from 'master' branch.)

* 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.

7 years agoFix data race when getting object size in explicitly-typed allocators
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.

7 years agoFix data race in a list referenced by A.aa (gctest)
Ivan Maidanski [Fri, 3 Nov 2017 17:08:09 +0000 (20:08 +0300)]
Fix data race in a list referenced by A.aa (gctest)
(Cherry-pick commits 8f5746e0f5a88d from 'master' branch.)

* 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): Likewise.
* 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()))).

7 years agoUpdate comment in finalized_disclaim to match FINALIZER_CLOSURE_FLAG
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).

7 years agoDocument base and size of objects allocated by finalized_malloc
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).

7 years agoAvoid data race in finalized_count (gctest)
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

7 years agoFix typo in a function name in README.sgi
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").

7 years agoFix typo in 'gcdescr' documentation file
Ivan Maidanski [Fri, 10 Nov 2017 07:33:32 +0000 (10:33 +0300)]
Fix typo in 'gcdescr' documentation file
(Cherry-pick commit 419f4de9 from 'master' branch.)

* doc/gcdescr.html (Allocation): Fix a typo ("the request is rounded").

7 years agoUpdate ChangeLog file (v7.6 changes only)
Ivan Maidanski [Thu, 26 Oct 2017 05:31:47 +0000 (08:31 +0300)]
Update ChangeLog file (v7.6 changes only)

7 years agoUpdate ChangeLog file (v7.4 changes only)
Ivan Maidanski [Wed, 25 Oct 2017 15:32:35 +0000 (18:32 +0300)]
Update ChangeLog file (v7.4 changes only)

7 years agoTravis CI: Test NO_CLOCK
Ivan Maidanski [Wed, 25 Oct 2017 08:12:34 +0000 (11:12 +0300)]
Travis CI: Test NO_CLOCK

7 years agoRefine should_invoke_finalizers documentation
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.

7 years agoUpdate AUTHORS file (add Erik M. Bray)
Ivan Maidanski [Tue, 17 Oct 2017 08:52:20 +0000 (11:52 +0300)]
Update AUTHORS file (add Erik M. Bray)

7 years agoUse mprotect instead of mmap in GC_unmap() on Cygwin
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.

7 years agoAllow PKG_CHECK_MODULES in configure.ac to be commented out easily
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
(Cherry-pick commits 3d34335fbb22e9 from 'master' branch.)

* configure.ac [$with_libatomic_ops!=no && $THREADS!=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).

7 years agoNew API function (GC_is_init_called) to check if BDWGC is initialized
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
(Cherry-pick commit 58c5c05 from 'master' branch.)

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.

7 years agoTest GC initialization from non-main thread on FreeBSD and NetBSD
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().

7 years agoFix typos in documentation (for extend_size_map and ews4800)
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.

7 years ago.gitignore: Do not ignore include/private/config.h
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.

7 years agoTravis CI: Remove NO_CLONE_LIBATOMIC_OPS for multi-threaded OS X builds
Ivan Maidanski [Thu, 12 Oct 2017 08:13:51 +0000 (11:13 +0300)]
Travis CI: Remove NO_CLONE_LIBATOMIC_OPS for multi-threaded OS X builds
(fix commit 270a547)

7 years agoUpdate ChangeLog file (v7.6 changes only)
Ivan Maidanski [Thu, 12 Oct 2017 08:01:53 +0000 (11:01 +0300)]
Update ChangeLog file (v7.6 changes only)

7 years agoUpdate ChangeLog file (v7.2 - v7.4 changes only)
Ivan Maidanski [Tue, 10 Oct 2017 22:06:54 +0000 (01:06 +0300)]
Update ChangeLog file (v7.2 - v7.4 changes only)

7 years agoTravis CI: Test also 32-bit build with ASan (on OS X, with unmapping)
Ivan Maidanski [Fri, 6 Oct 2017 18:47:00 +0000 (21:47 +0300)]
Travis CI: Test also 32-bit build with ASan (on OS X, with unmapping)
(Cherry-pick commits 535cf3609c981a from 'master' branch.)

7 years agoTravis CI: Test also with Leak Sanitizer (LSan)
Ivan Maidanski [Fri, 6 Oct 2017 18:31:35 +0000 (21:31 +0300)]
Travis CI: Test also with Leak Sanitizer (LSan)
(Cherry-pick commit 5c8663d from 'master' branch.)

7 years agoSupport GC_init (and get_stack_base) from non-main thread on NetBSD
Ivan Maidanski [Mon, 9 Oct 2017 19:17:15 +0000 (22:17 +0300)]
Support GC_init (and get_stack_base) from non-main thread on NetBSD

Now GC_get_[main_]stack_base uses pthread_getattr_np() and
pthread_attr_getstack() to determine the stack base address on NetBSD.

* include/private/gcconfig.h [NETBSD && !NO_PTHREAD_GETATTR_NP]
(HAVE_PTHREAD_GETATTR_NP): Define.

7 years agoEliminate TSan warnings for all counters and A.aa variable (gctest)
Ivan Maidanski [Mon, 9 Oct 2017 19:07:24 +0000 (22:07 +0300)]
Eliminate TSan warnings for all counters and A.aa variable (gctest)

Now most of the counters in gctest are updated using atomic increment.
And, the values of gctest dropped_something and A.aa variables are
updated and fetch using the atomic primitives.

* tests/test.c [!AO_CLEAR] (AO_t): Define.
* tests/test.c [!AO_HAVE_load] (AO_load): Define (as a non-atomic
operation).
* tests/test.c [!AO_HAVE_store] (AO_store): Likewise.
* tests/test.c [!AO_HAVE_fetch_and_add1] (AO_fetch_and_add1): Likewise.
* tests/test.c (stubborn_count, uncollectable_count,
collectable_count, atomic_count, realloc_count): Change type from int
to AO_t; add volatile qualifier; update comment; remove FIXME.
* tests/test.c (extra_count): Define unconditionally; change type from
int to AO_t; add volatile qualifier; update comment.
* tests/test.c [!VERY_SMALL_CONFIG] (cons): Use AO_fetch_and_add1 to
get and update the values of extra_count and stubborn_count.
* tests/test.c (small_cons_uncollectable): Use AO_fetch_and_add1 to
update the value of uncollectable_count.
* tests/test.c [!DBG_HDRS_ALL] (run_one_test): Likewise.
* tests/test.c [GC_GCJ_SUPPORT] (gcj_cons): Remove obj_cnt static
variable; use extra_count instead of obj_cnt; use AO_fetch_and_add1 to
get and update the value of extra_count.
* tests/test.c (A): Add volatile qualifier; change the type of aa
field from sexpr to AO_t.
* tests/test.c (a): Do not define (and undefine).
* tests/test.c (a_set, a_get): New macro (that uses AO_store/load).
* tests/test.c (reverse_test_inner): Use a_set() and a_get() to store
and fetch the value of a, respectively; use AO_fetch_and_add1 to
update the value of realloc_count.
* tests/test.c (dropped_something): Change type from int to AO_t.
* tests/test.c (counter): Remove.
* tests/test.c (mktree): Use extra_count instead of counter; use
AO_fetch_and_add1 to update the value of extra_count.
* tests/test.c [GC_PTHREADS && !SMALL_CONFIG && !GC_DEBUG]
(alloc8bytes): Use AO_fetch_and_add1 to update the value of
uncollectable_count.
* tests/test.c (alloc_small, run_one_test): Use AO_fetch_and_add1 to
update the value of atomic_count.
* tests/test.c (tree_test): Use AO_load and AO_store to get and set
the value of dropped_something, respectively.
* tests/test.c (check_heap_stats): Cast uncollectable_count,
atomic_count, stubborn_count, realloc_count to int in printf() call.

7 years agoEliminate TSan warnings for print_proc variables assignment (gctest)
Ivan Maidanski [Fri, 6 Oct 2017 08:14:23 +0000 (11:14 +0300)]
Eliminate TSan warnings for print_proc variables assignment (gctest)

Now GC_is_valid_displacement_print_proc and GC_is_visible_print_proc
are set only once (before the first invocation of run_one_test).

* tests/test.c [DBG_HDRS_ALL] (set_print_procs): New macro (defined
to (void)0).
* tests/test.c [!DBG_HDRS_ALL] (set_print_procs): New function (which
sets GC_is_valid_displacement_print_proc and GC_is_visible_print_proc).
* tests/test.c (fail_count, fail_proc1, TEST_FAIL_COUNT): Do not
define if DBG_HDRS_ALL.
* tests/test.c [!DBG_HDRS_ALL] (run_one_test): Do not set
GC_is_valid_displacement_print_proc and GC_is_visible_print_proc.
* tests/test.c (main): Call set_print_procs() before run_one_test().
* tests/test.c [PCR] (test): Likewise.

7 years agoPrint realloc_count in gctest
Ivan Maidanski [Sun, 8 Oct 2017 10:22:06 +0000 (13:22 +0300)]
Print realloc_count in gctest

Without this patch, realloc_count value is never used.

* tests/test.c (check_heap_stats): Print realloc_count value (after
printing other count variables).

7 years agoFix missing atomic_count and realloc_count incrementation in gctest
Ivan Maidanski [Sun, 8 Oct 2017 10:09:46 +0000 (13:09 +0300)]
Fix missing atomic_count and realloc_count incrementation in gctest

* tests/test.c [!AT_END && !THREADS] (reverse_test_inner): Increment
realloc_count after GC_REALLOC() call.
* tests/test.c (run_one_test): Increment atomic_count after
(void)GC_MALLOC_ATOMIC(0) and GC_malloc_atomic(1) calls.

7 years agoMove conditional GC_need_to_lock setting to gc_locks.h
Ivan Maidanski [Fri, 6 Oct 2017 18:26:06 +0000 (21:26 +0300)]
Move conditional GC_need_to_lock setting to gc_locks.h
(code refactoring)

* include/private/gc_locks.h [GC_PTHREADS && !THREAD_LOCAL_ALLOC
&& !USE_PTHREAD_LOCKS && !GC_ASSERTIONS] (UNCOND_LOCK): Remove
GC_ASSERT(I_DONT_HOLD_LOCK()) because it is no-op (when assertion
checking is off).
* include/private/gc_locks.h [THREADS] (set_need_to_lock): New macro.
* pthread_support.c [!GC_ALWAYS_MULTITHREADED]
(GC_allow_register_threads, WRAP_FUNC(pthread_create)): Replace
GC_need_to_lock=TRUE to set_need_to_lock().
* win32_threads.c [!GC_ALWAYS_MULTITHREADED]
(GC_allow_register_threads, GC_CreateThread, GC_init_parallel):
Likewise.
* win32_threads.c [!MSWINCE && !CYGWIN32 && !GC_ALWAYS_MULTITHREADED]
(GC_beginthreadex): Likewise.
* win32_threads.c [GC_PTHREADS && !GC_ALWAYS_MULTITHREADED]
(GC_pthread_create): Likewise.

7 years agoSupport GC_init (and get_stack_base) from non-main thread on FreeBSD
Ivan Maidanski [Wed, 27 Sep 2017 23:06:31 +0000 (02:06 +0300)]
Support GC_init (and get_stack_base) from non-main thread on FreeBSD
(Cherry-pick commits 49d7fe739ca0b5 from 'master' branch.)

Issue #180 (bdwgc).

Now GC_get_[main_]stack_base uses pthread_attr_get_np() and
pthread_attr_getstack() to determine the stack base address.

* include/private/gcconfig.h [(FREEBSD && __GLIBC__ || LINUX
|| PLATFORM_ANDROID) && !NO_PTHREAD_GETATTR_NP]
(HAVE_PTHREAD_GETATTR_NP): New macro.
* include/private/gcconfig.h [FREEBSD && !__GLIBC__
&& !NO_PTHREAD_ATTR_GET_NP] (HAVE_PTHREAD_NP_H,
HAVE_PTHREAD_ATTR_GET_NP): Likewise.
* os_dep.c [(HAVE_PTHREAD_ATTR_GET_NP || HAVE_PTHREAD_GETATTR_NP)
&& (THREADS || USE_GET_STACKBASE_FOR_MAIN) && HAVE_PTHREAD_NP_H]:
Include pthread_np.h.
* os_dep.c [!BEOS && !AMIGA && !OS2 && !MSWIN32 && !MSWINCE
&& !CYGWIN32 && !GC_OPENBSD_THREADS] (include pthread.h,
GC_get_main_stack_base): Check presence of HAVE_PTHREAD_ATTR_GET_NP,
HAVE_PTHREAD_GETATTR_NP macros instead of LINUX, PLATFORM_ANDROID,
NO_PTHREAD_GETATTR_NP.
* os_dep.c [HAVE_PTHREAD_GETATTR_NP && (USE_GET_STACKBASE_FOR_MAIN
|| THREADS && !REDIRECT_MALLOC)] (GC_get_main_stack_base): Call
pthread_attr_init, pthread_attr_get_np and pthread_attr_getstack
to determine the stack base address of the current thread (fall back
to GC_freebsd_main_stack_base in case of failure).
* os_dep.c [!HAVE_GET_STACK_BASE] (GC_get_stack_base): Check presence
of THREADS, HAVE_PTHREAD_ATTR_GET_NP, HAVE_PTHREAD_GETATTR_NP,
HAVE_PTHREAD_NP_H macros instead of GC_LINUX_THREADS, PLATFORM_ANDROID,
NO_PTHREAD_GETATTR_NP.
* os_dep.c [HAVE_PTHREAD_GETATTR_NP && THREADS && !HAVE_GET_STACK_BASE]
(GC_get_stack_base): Call pthread_attr_init, pthread_attr_get_np and
pthread_attr_getstack to determine the stack base address of the
current thread.

7 years agoTravis CI: Test USE_CUSTOM_SPECIFIC
Ivan Maidanski [Mon, 28 Aug 2017 07:38:18 +0000 (10:38 +0300)]
Travis CI: Test USE_CUSTOM_SPECIFIC

7 years agoTravis CI: Test some --enable-munmap configurations with disable incremental collection
Ivan Maidanski [Tue, 22 Aug 2017 06:09:04 +0000 (09:09 +0300)]
Travis CI: Test some --enable-munmap configurations with disable incremental collection
(Cherry-pick commit 4abb9eb from 'master' branch.)

7 years agoDo not disable parallel mark for WRAP_MARK_SOME
Ivan Maidanski [Mon, 25 Sep 2017 21:52:49 +0000 (00:52 +0300)]
Do not disable parallel mark for WRAP_MARK_SOME

Issue #179 (bdwgc).

Now, if there is a chance of unmapping of root segments, the latter
ones are scanned immediately by GC_push_roots thus preventing memory
protection faults in GC_mark_local.

* include/private/gc_priv.h (GC_PUSH_CONDITIONAL): Move definition to
mark_rts.c.
* include/private/gcconfig.h [WRAP_MARK_SOME && PARALLEL_MARK]
(PARALLEL_MARK): Do not undefine; remove TODO item.
* mark.c [WRAP_MARK_SOME && PARALLEL_MARK] (GC_push_conditional_eager):
New internal function; add TODO item.
* mark_rts.c [WRAP_MARK_SOME && PARALLEL_MARK]
(GC_push_conditional_eager): Declare function.
* mark_rts.c [WRAP_MARK_SOME && PARALLEL_MARK] (GC_PUSH_CONDITIONAL):
Define to GC_push_conditional_eager if GC_parallel.

7 years agoAlign local_mark_stack in help_marker explicitly
Ivan Maidanski [Fri, 22 Sep 2017 18:37:42 +0000 (21:37 +0300)]
Align local_mark_stack in help_marker explicitly

* mark.c [PARALLEL_MARK] (GC_help_marker): Declare my_id_mse local
variable (of mse type) instead of unsigned my_id; define my_id as
macro to my_id_mse.mse_descr.w; cast my_id to unsigned or int in
GC_helper_count assignment and GC_mark_local() call.

7 years agoEliminate '-pedantic is not option that controls warnings' GCC-6.4 message
Ivan Maidanski [Wed, 27 Sep 2017 08:42:46 +0000 (11:42 +0300)]
Eliminate '-pedantic is not option that controls warnings' GCC-6.4 message
(Cherry-pick commit e0a3739 from 'master' branch.)

* mark.c [WRAP_MARK_SOME && (MSWIN32 || MSWINCE) && __GNUC__]
(GC_mark_some): Use "-Wpedantic" instead of "-pedantic" (in pragma
GCC diagnostic) if GCC v6.4+.

7 years agoEliminate 'non-null arg compared to null' warning in toggleref_add (GCC)
Ivan Maidanski [Wed, 27 Sep 2017 08:22:18 +0000 (11:22 +0300)]
Eliminate 'non-null arg compared to null' warning in toggleref_add (GCC)
(fix commit 86991cb)

* finalize.c [!GC_TOGGLE_REFS_NOT_NEEDED] (GC_toggleref_add): Use
NONNULL_ARG_NOT_NULL to check pointer argument marked as non-null (in
the function declaration) is actually non-null.

7 years agoEliminate 'boolean result used in bitwise op' cppcheck false warning
Ivan Maidanski [Tue, 19 Sep 2017 06:58:11 +0000 (09:58 +0300)]
Eliminate 'boolean result used in bitwise op' cppcheck false warning

* extra/AmigaOS.c [GC_AMIGA_DS] (GC_register_data_segments):
Replace (ULONG)&data[1] in comparison to (ULONG)(&data[1]).
* misc.c [!THREADS && !SPARC] (GC_do_blocking_inner):
Replace (ptr_t)&d in comparison to (ptr_t)(&d).

7 years agoEliminate 'memory leak' code defect in remove_specific
Ivan Maidanski [Fri, 25 Aug 2017 14:59:05 +0000 (17:59 +0300)]
Eliminate 'memory leak' code defect in remove_specific

* specific.c [LINT2] (GC_remove_specific): Call GC_noop1(entry) to
indicate that entry is lost (the memory will be collected during GC).

7 years agoEliminate most of collisions in GC_threads on Linux/x64
Ivan Maidanski [Thu, 24 Aug 2017 08:34:05 +0000 (11:34 +0300)]
Eliminate most of collisions in GC_threads on Linux/x64
(Cherry-pick commits 85fce54e897b41 from 'master' branch.)

On some targets (e.g., Linux/x64) pthread_t values always have zero
in the lowest byte (e.g. if pthread_t is actually a page-aligned
pointer) thus causing all the created thread descriptors to have
a collision at GC_threads[0].  This commit mixes 3 lowest bytes
of thread id with a XOR operation (thus greatly reduces the
probability of collisions in GC_threads).
Windows thread Id rarely has non-zero highest half of DWORD, so
it is OK to use only the lowest one for hash value computation.

* include/private/pthread_support.h (THREAD_TABLE_SZ): Do not
define if already defined; refine comment.
* pthread_support.c (THREAD_TABLE_INDEX): New macro (similar to that
in win32_threads.c).
* pthread_support.c (GC_new_thread, GC_delete_thread,
GC_delete_gc_thread, GC_lookup_thread): Replace
NUMERIC_THREAD_ID(id)%THREAD_TABLE_SZ to THREAD_TABLE_INDEX(id).
* pthread_support.c (GC_lookup_thread): Remove hv local variable.
* win32_threads.c (THREAD_TABLE_INDEX): Replace (id>>2) to
((id>>8)^id).
* win32_threads.c [GC_PTHREADS] (GC_lookup_pthread): Define win32_id
local variable to pass it to THREAD_TABLE_INDEX() instead of passing
GET_PTHREAD_MAP_CACHE(id) directly.

7 years agoChange type of THREAD_TABLE_INDEX result to int in win32_threads.c
Ivan Maidanski [Wed, 23 Aug 2017 08:46:41 +0000 (11:46 +0300)]
Change type of THREAD_TABLE_INDEX result to int in win32_threads.c
(code refactoring)

* win32_threads.c (THREAD_TABLE_INDEX): Cast result to int; remove cast
of argument to word type; add comment.
* win32_threads.c (GC_new_thread, GC_delete_gc_thread_no_free,
GC_delete_thread): Change type of hv local variable from word to int.
* win32_threads.c (GC_lookup_thread_inner): Remove hv local variable;
remove "register" keyword for p local variable.
* win32_threads.c (GC_lookup_pthread): Change type of hv_guess local
variable from word to int.

7 years agoFix data race in collectable_count (gctest)
Ivan Maidanski [Wed, 27 Sep 2017 22:46:20 +0000 (01:46 +0300)]
Fix data race in collectable_count (gctest)
(Cherry-pick commit c2ded73 from 'master' branch.)

* tests/test.c [THREADS && (PARALLEL_MARK
|| !GC_WIN32_THREADS)]: Include atomic_ops.h.
* tests/test.c [AO_HAVE_fetch_and_add1] (collectable_count): Change
type to volatile AO_t (and make it static to initalize it without "=0").
* tests/test.c [!AO_HAVE_fetch_and_add1] (AO_fetch_and_add1): Define
to a non-atomic increment (for a single-threaded build).
* tests/test.c (small_cons, reverse_test_inner, mktree, chktree,
alloc8bytes, typed_test, run_one_test): Use
AO_fetch_and_add1(&collectable_count) instead of collectable_count++.
* tests/test.c (check_heap_stats): Cast collectable_count to int in
GC_printf() call.

7 years agoFix missing [un]collectable_count increments in gctest
Ivan Maidanski [Wed, 27 Sep 2017 21:52:40 +0000 (00:52 +0300)]
Fix missing [un]collectable_count increments in gctest

* tests/test.c [!DBG_HDRS_ALL] (run_one_test): Increment
uncollectable_count instead of collectable_count (for
GC_malloc_uncollectable(0)).
* tests/test.c [!DBG_HDRS_ALL] (run_one_test): Add missing increments
of collectable_count for GC_malloc(8) and GC_malloc(17).
* tests/test.c (run_one_test): Add missing increment of
collectable_count for (void)GC_MALLOC(0).

7 years agoFix missing started_thread_while_stopped call from mark_some if GCC/Clang
Ivan Maidanski [Mon, 18 Sep 2017 21:34:15 +0000 (00:34 +0300)]
Fix missing started_thread_while_stopped call from mark_some if GCC/Clang

* mark.c [WRAP_MARK_SOME && GC_WIN32_THREADS && !GC_PTHREADS]
(GC_started_thread_while_stopped): Declare even if __GNUC__.
* mark.c [WRAP_MARK_SOME && GC_WIN32_THREADS && (MSWIN32 || MSWINCE)]
(GC_mark_some): Invoke GC_started_thread_while_stopped (unless
GC_PTHREADS).
* win32_threads.c [WRAP_MARK_SOME && !GC_PTHREADS]
(GC_started_thread_while_stopped): Define even if __GNUC__.

7 years agoFix get_maps on proc maps file asynchronous growth
Ivan Maidanski [Tue, 26 Sep 2017 21:56:14 +0000 (00:56 +0300)]
Fix get_maps on proc maps file asynchronous growth

Issue #179 (bdwgc).

Asynchronous growth of /proc/self/maps could be caused by some thread
which is not currently registered (e.g. stack allocation on thread
creation or a non-GC heap allocation from an unregistered thread).

* os_dep.c [NEED_PROC_MAPS] (GC_get_maps): Refine comment.
* os_dep.c [NEED_PROC_MAPS && THREADS] (GC_get_maps): Replace ABORT
with WARN call; refine printed message; add comment.

7 years agoFix infinite mark_some calls after memory mapping disappeared (Glibc)
Ivan Maidanski [Tue, 19 Sep 2017 07:51:24 +0000 (10:51 +0300)]
Fix infinite mark_some calls after memory mapping disappeared (Glibc)

Issue #179 (bdwgc).

* mark.c [WRAP_MARK_SOME && REGISTER_LIBRARIES_EARLY] (GC_mark_some):
Call GC_cond_register_dynamic_libraries (with the world running)
before GC_invalidate_mark_state().

7 years agoFix SIGSEGV in mark_from called from do_local_mark if WRAP_MARK_SOME
Ivan Maidanski [Mon, 18 Sep 2017 07:54:37 +0000 (10:54 +0300)]
Fix SIGSEGV in mark_from called from do_local_mark if WRAP_MARK_SOME
(Cherry-pick commits f4d690eb874d02 from 'master' branch.)

Issue #179 (bdwgc).

Parallel marker is disabled (for now) if there is a chance of
scanning unmapped data roots (because GC_do_local_mark is not
prepared to deal with memory protection faults gracefully).

* include/private/gc_pmark.h [HAVE_CONFIG_H]: Do not include config.h
if already included from gc_priv.h (to avoid PARALLEL_MARK macro
redefinition in config.h after it was undefined in gcconfig.h).
* mark.c [MSWIN32 || USE_PROC_FOR_LIBRARIES] (WRAP_MARK_SOME): Move
definition to gcconfig.h.
* include/private/gcconfig.h [WRAP_MARK_SOME && PARALLEL_MARK]
(PARALLEL_MARK): Undefine (as not implemented yet).

7 years agoRemove unnecessary type casts of printf arguments to unsigned long
Ivan Maidanski [Wed, 30 Aug 2017 07:00:46 +0000 (10:00 +0300)]
Remove unnecessary type casts of printf arguments to unsigned long
(code refactoring)

* alloc.c [!NO_DEBUGGING] (GC_print_heap_sects): Remove unnecessary
cast to unsigned long in GC_*_printf call and adjust printf format
specifier to match the argument type.
* checksums.c [CHECKSUMS] (GC_checksum): Likewise.
* mark.c [PARALLEL_MARK] (GC_mark_local): Likewise.
* tests/test.c (typed_test): Likewise.
* checksums.c [CHECKSUMS] (GC_checksum): Change type of GC_n_clean,
GC_n_dirty from int to unsigned long.

7 years agoFix pthread_detach for threads not yet registered (Cygwin, winpthreads)
Ivan Maidanski [Wed, 27 Sep 2017 07:52:09 +0000 (10:52 +0300)]
Fix pthread_detach for threads not yet registered (Cygwin, winpthreads)

* win32_threads.c [GC_PTHREADS] (GC_pthread_detach): Repeat
GC_lookup_pthread() (with a 10 msec delay) while t is null; add comment
and TODO; remove ABORT if t is null (as t is never null after
pthread_detach call).

7 years agoFix pthread_join when thread is registered in thread key destructor
Ivan Maidanski [Tue, 26 Sep 2017 08:44:44 +0000 (11:44 +0300)]
Fix pthread_join when thread is registered in thread key destructor

* pthread_support.c (WRAP_FUNC(pthread_join)): Remove assertion that
thread is finished; call GC_delete_gc_thread only if thread is
finished; add comment.
* win32_threads.c [GC_PTHREADS] (GC_pthread_join): Call
GC_delete_gc_thread_no_free and GC_INTERNAL_FREE only if thread is
finished.

7 years agoFix removal of dead threads in a child process
Ivan Maidanski [Tue, 26 Sep 2017 08:01:29 +0000 (11:01 +0300)]
Fix removal of dead threads in a child process

GC_threads table may contain several elements with the same pthread id,
so GC_remove_all_threads_but_me should remove all elements except for
the first found element matching the id of the current thread.

* pthread_support.c [CAN_HANDLE_FORK] (GC_remove_all_threads_but_me):
Do not assign me if it is already non-null; add comment.
* win32_threads.c [CAN_HANDLE_FORK] (GC_remove_all_threads_but_me):
Likewise.
* win32_threads.c [CAN_HANDLE_FORK] (GC_remove_all_threads_but_me):
Remove GC_ASSERT(me==NULL).

7 years agoFix pthread_join to avoid thread removal on failure (Cygwin, winpthreads)
Ivan Maidanski [Tue, 26 Sep 2017 08:29:54 +0000 (11:29 +0300)]
Fix pthread_join to avoid thread removal on failure (Cygwin, winpthreads)

* win32_threads.c [GC_WIN32_PTHREADS] (GC_pthread_join): Do not call
GC_lookup_pthread if pthread_join failed.
* win32_threads.c [GC_PTHREADS] (GC_pthread_join): Do not call
GC_delete_gc_thread_no_free, GC_INTERNAL_FREE if pthread_join failed.
* win32_threads.c [GC_PTHREADS && DEBUG_THREADS] (GC_pthread_join):
Log whether pthread_join succeeded or failed.

7 years agoFix double lock in pthread_detach (Cygwin, winpthreads)
Ivan Maidanski [Mon, 25 Sep 2017 22:12:30 +0000 (01:12 +0300)]
Fix double lock in pthread_detach (Cygwin, winpthreads)

* win32_threads.c [GC_PTHREADS] (GC_pthread_detach): Do not hold the
allocation lock when GC_lookup_pthread is invoked.

7 years agoFix thread id leaks in subthread_create and threadkey_test
Ivan Maidanski [Tue, 19 Sep 2017 22:23:43 +0000 (01:23 +0300)]
Fix thread id leaks in subthread_create and threadkey_test

* tests/subthread_create.c [GC_PTHREADS] (entry): Call pthread_detach
for the created thread.
* tests/threadkey_test.c (main): Likewise.
* tests/test.c [GC_PTHREADS && CPPCHECK] (main): Remove
UNTESTED(GC_pthread_detach).
* tests/threadkey_test.c (on_thread_exit_inner): New local variable
attr; call pthread_attr_init and pthread_attr_setdetachstate;
pass attr to GC_pthread_create; call pthread_attr_destroy.

7 years agoFix missing new-line at format strings end in subthread_create test
Ivan Maidanski [Tue, 19 Sep 2017 22:08:04 +0000 (01:08 +0300)]
Fix missing new-line at format strings end in subthread_create test

* tests/subthread_create.c [GC_PTHREADS] (entry, main): Append "\n" to
fprintf() format string (where missing).

7 years agoFix USE_GET_STACKBASE_FOR_MAIN definition in gcconfig.h
Ivan Maidanski [Mon, 18 Sep 2017 22:07:45 +0000 (01:07 +0300)]
Fix USE_GET_STACKBASE_FOR_MAIN definition in gcconfig.h

* include/private/gcconfig.h [PLATFORM_ANDROID && !THREADS]
(USE_GET_STACKBASE_FOR_MAIN): Move definition down to be after THREADS
definition.

7 years agoFix typo in 'scale' documentation file
Ivan Maidanski [Wed, 30 Aug 2017 23:12:06 +0000 (02:12 +0300)]
Fix typo in 'scale' documentation file
(Cherry-pick commit c875884 from 'master' branch.)

* doc/scale.html (Options for enhanced scalability): Fix a typo
("be replaced").

7 years agoFix printf arguments type in print_callers
Ivan Maidanski [Tue, 29 Aug 2017 22:17:08 +0000 (01:17 +0300)]
Fix printf arguments type in print_callers

* os_dep.c [NEED_CALLINFO] (GC_print_callers): Cast info[i].ci_pc to
unsigned long in GC_err_printf call to match the format specifier.

7 years agoFix assertion violation in return_single_freelist in child process
Ivan Maidanski [Mon, 28 Aug 2017 08:26:51 +0000 (11:26 +0300)]
Fix assertion violation in return_single_freelist in child process

Issue #171 (bdwgc).

GC_destroy_thread_local cannot be called from a thread other than
the current one.

* pthread_support.c [CAN_HANDLE_FORK && THREAD_LOCAL_ALLOC]
(GC_remove_all_threads_but_me): Do not call GC_destroy_thread_local;
add comment.
* win32_threads.c [CAN_HANDLE_FORK && THREAD_LOCAL_ALLOC]
(GC_remove_all_threads_but_me): Likewise.
* thread_local_alloc.c [THREAD_LOCAL_ALLOC] (GC_destroy_thread_local):
Update comment.

7 years agoFix GC_remove_specific invocation from remove_all_threads_but_me
Ivan Maidanski [Mon, 28 Aug 2017 06:27:07 +0000 (09:27 +0300)]
Fix GC_remove_specific invocation from remove_all_threads_but_me
(fix commits fcfae7f38e65ea)

* include/private/specific.h (GC_remove_specific): Define as macro
(calls GC_remove_specific_after_fork).
* include/private/specific.h (GC_remove_specific_after_fork): New
GC_INNER function declaration.
* include/private/thread_local_alloc.h [USE_PTHREAD_SPECIFIC
|| USE_COMPILER_TLS || USE_WIN32_COMPILER_TLS || USE_WIN32_SPECIFIC]
(GC_remove_specific_after_fork): New macro (defined to no-op).
* pthread_support.c [CAN_HANDLE_FORK && THREAD_LOCAL_ALLOC]
(GC_remove_all_threads_but_me): Call GC_remove_specific_after_fork
instead of GC_remove_specific (i.e. delete thread-specific control data
for the given thread instead of the current one).
* win32_threads.c [CAN_HANDLE_FORK && THREAD_LOCAL_ALLOC] Like
* specific.c [USE_CUSTOM_SPECIFIC] (GC_setspecific): Add assertion that
the allocation lock is held; remove the corresponding comment.
* specific.c [USE_CUSTOM_SPECIFIC] (GC_remove_specific): Replace to
GC_remove_specific_after_fork (add t argument); replace self local
variable with t argument; update comment;
* specific.c [USE_CUSTOM_SPECIFIC && CAN_HANDLE_FORK]
(GC_remove_specific_after_fork): Add assertion that the allocation lock
is held; add comment.

7 years agoFix deadlock in GC_help_marker caused by use of mark_cv of parent process
Ivan Maidanski [Tue, 22 Aug 2017 08:23:27 +0000 (11:23 +0300)]
Fix deadlock in GC_help_marker caused by use of mark_cv of parent process

The marker threads of the parent process are blocked on mark_cv at
fork.  So pthread_cond_wait() malfunction (hang) is possible in the
child process without mark_cv state cleanup (reinitialization).

* pthread_support.c [PARALLEL_MARK] (mark_cv): Move static variable
definition upper to be before GC_start_mark_threads_inner).
* win32_threads.c [GC_PTHREADS_PARAMARK] (mark_cv): Likewise.
* pthread_support.c [PARALLEL_MARK && CAN_HANDLE_FORK] (mark_cv):
Do not initialize statically; add comment.
* win32_threads.c [GC_PTHREADS_PARAMARK && CAN_HANDLE_FORK] (mark_cv):
Likewise.
* pthread_support.c [PARALLEL_MARK && CAN_HANDLE_FORK]
(GC_start_mark_threads_inner): Initialize mark_cv to
PTHREAD_COND_INITIALIZER (unless available_markers_m1 <= 0 or
GC_parallel); add comment.
* win32_threads.c [GC_PTHREADS_PARAMARK && CAN_HANDLE_FORK]
(GC_start_mark_threads_inner): Likewise.
* pthread_support.c [PARALLEL_MARK] (GC_wait_marker,
GC_notify_all_marker): Add assertion that GC_parallel is true (so
mark_cv is initialized).
* win32_threads.c [GC_PTHREADS_PARAMARK] (GC_wait_marker,
GC_notify_all_marker): Likewise.

7 years agoAvoid busy waiting in mark_thread while GC_parallel is false
Ivan Maidanski [Tue, 22 Aug 2017 05:56:31 +0000 (08:56 +0300)]
Avoid busy waiting in mark_thread while GC_parallel is false

* mark.c [PARALLEL_MARK] (GC_help_marker): Add assertion that
GC_parallel is true (i.e. GC_markers_m1 is non-zero).
* pthread_support.c [PARALLEL_MARK && CAN_HANDLE_FORK]
(GC_start_mark_threads_inner): Set GC_markers_m1 value before starting
the first marker thread (it is already set if fork handling is off).
* win32_threads.c [GC_PTHREADS_PARAMARK && CAN_HANDLE_FORK]
(GC_start_mark_threads_inner): Likewise.
* pthread_support.c [PARALLEL_MARK] (GC_start_mark_threads_inner):
Adjust GC_markers_m1 value only if pthread_create failed.
* win32_threads.c [GC_PTHREADS_PARAMARK] (GC_start_mark_threads_inner):
Likewise.

7 years agoEliminate unsigned fl_builder_count underflow in mark_thread
Ivan Maidanski [Mon, 21 Aug 2017 22:09:59 +0000 (01:09 +0300)]
Eliminate unsigned fl_builder_count underflow in mark_thread
(refactor commit 0ca6d3f)

* include/private/gc_priv.h [PARALLEL_MARK] (GC_fl_builder_count):
Change type from word to signed_word.
* reclaim.c [PARALLEL_MARK] (GC_fl_builder_count): Likewise.
* mark.c [PARALLEL_MARK] (GC_wait_for_markers_init): Change type of
count local variable to signed_word; add assertion that count is
non-negative.
* pthread_support.c [PARALLEL_MARK] (GC_mark_thread): Add comment that
GC_fl_builder_count can be negative here.
* win32_threads.c [PARALLEL_MARK] (GC_mark_thread): Likewise.
* reclaim.c [PARALLEL_MARK] (GC_fl_builder_count): Refine comment.

7 years agoAdd assertion that no hb_n_marks underflow occurs
Ivan Maidanski [Sat, 19 Aug 2017 15:46:59 +0000 (18:46 +0300)]
Add assertion that no hb_n_marks underflow occurs

Issue #177 (bdwgc).

* alloc.c (GC_clear_fl_marks): Add GC_ASSERT that hhdr->hb_n_marks
is non-zero before decrementing it.
* mark.c (GC_clear_mark_bit): Likewise.

7 years agoFix hb_n_marks underflow in clear_fl_marks if MARK_BIT_PER_OBJ
Ivan Maidanski [Sat, 19 Aug 2017 15:22:37 +0000 (18:22 +0300)]
Fix hb_n_marks underflow in clear_fl_marks if MARK_BIT_PER_OBJ

Issue #177 (bdwgc).

* mark.c [MARK_BIT_PER_OBJ] (GC_set_hdr_marks): Set hhdr->hb_n_marks
exactly to n_marks value (without a decrement by one).

7 years agoUpdate ChangeLog file (v7.6 changes only)
Ivan Maidanski [Thu, 17 Aug 2017 20:13:47 +0000 (23:13 +0300)]
Update ChangeLog file (v7.6 changes only)

7 years agoUpdate ChangeLog file (v7.2 - v7.4 changes only)
Ivan Maidanski [Thu, 17 Aug 2017 07:54:27 +0000 (10:54 +0300)]
Update ChangeLog file (v7.2 - v7.4 changes only)

7 years agoFix visibility of __asan_default_options in case of shared library
Ivan Maidanski [Wed, 16 Aug 2017 22:39:16 +0000 (01:39 +0300)]
Fix visibility of __asan_default_options in case of shared library
(fix commit ce75cf1)

* os_dep.c [ADDRESS_SANITIZER && (UNIX_LIKE || NEED_FIND_LIMIT
|| MPROTECT_VDB)] (__asan_default_options): Do not define if
CUSTOM_ASAN_DEF_OPTIONS is defined; export it (use GC_API).

7 years agoEliminate '-pedantic is not an option that controls warnings' GCC message
Ivan Maidanski [Wed, 16 Aug 2017 08:23:49 +0000 (11:23 +0300)]
Eliminate '-pedantic is not an option that controls warnings' GCC message
(fix commit b43d928)

* mark.c [WRAP_MARK_SOME && (MSWIN32 || MSWINCE) && __GNUC__]
(GC_mark_some): Use "-Wpedantic" instead of "-pedantic" (in pragma
GCC diagnostic) if GCC v7+.

7 years agoAllow gctest and thread_leak_test with zero NTHREADS
Ivan Maidanski [Wed, 9 Aug 2017 21:47:18 +0000 (00:47 +0300)]
Allow gctest and thread_leak_test with zero NTHREADS

* tests/test.c [GC_PTHREADS || GC_WIN32_THREADS] (reverse_test_inner):
Do not call fork_a_thread() if NTHREADS is 0.
* tests/test.c (MAX_FINALIZED): Increase to be correct for the case of
NTHREADS is 0.
* tests/test.c [GC_PTHREADS] (main): Do not declare and do not use th,
i local variables if NTHREADS is 0.
* tests/thread_leak_test.c (NTHREADS): Do not define if already defined.
* tests/thread_leak_test.c (main):  Do not declare and do not use i,
code, t, thread_id local variables if NTHREADS is 0.

7 years agoFix array_mark_proc to request global mark stack growth on overflow
Ivan Maidanski [Wed, 9 Aug 2017 08:35:25 +0000 (11:35 +0300)]
Fix array_mark_proc to request global mark stack growth on overflow
(fix commit 3f06655)

* typd_mlc.c [PARALLEL_MARK] (GC_array_mark_proc): Set
GC_mark_stack_too_small to true if GC_push_complex_descriptor()
returned null and mark_stack_limit belongs to the global mark stack
(even if GC_parallel is true).

7 years agoTravis CI: Test configure --disable-docs
Ivan Maidanski [Thu, 3 Aug 2017 21:49:57 +0000 (00:49 +0300)]
Travis CI: Test configure --disable-docs
(Cherry-pick commit 021188c from 'master' branch.)

7 years agoTravis CI: Workaround 'real_malloc is never called' cppcheck warning
Ivan Maidanski [Mon, 10 Jul 2017 21:49:14 +0000 (00:49 +0300)]
Travis CI: Workaround 'real_malloc is never called' cppcheck warning
(Cherry-pick commit 64e8fe5 from 'master' branch.)

7 years agoFix leak_test crash in print_callers if free() is redirected
Ivan Maidanski [Mon, 7 Aug 2017 08:37:30 +0000 (11:37 +0300)]
Fix leak_test crash in print_callers if free() is redirected

* dbg_mlc.c [REDIRECT_MALLOC && (GC_LINUX_THREADS || GC_SOLARIS_THREADS
|| MSWIN32 || NEED_CALLINFO && GC_HAVE_BUILTIN_BACKTRACE)]
(GC_debug_free): If the object is not in the GC heap then just return
(instead of ABORT).
* malloc.c [REDIRECT_MALLOC && NEED_CALLINFO
&& GC_HAVE_BUILTIN_BACKTRACE] (GC_free): If hhdr is null (i.e. the
object is not in the GC heap) then return without the object
deallocation; add comment.
* os_dep.c [NEED_CALLINFO && GC_HAVE_BUILTIN_BACKTRACE
&& !GC_BACKTRACE_SYMBOLS_BROKEN] (GC_print_callers): Adjust comment
for free().

7 years agoDo not install documentation if configure --disable-docs (new option)
Ivan Maidanski [Thu, 3 Aug 2017 21:47:56 +0000 (00:47 +0300)]
Do not install documentation if configure --disable-docs (new option)
(Cherry-pick commit e2e1ba7 from 'master' branch.)

* configure.ac (docs): New AC_ARG_ENABLE.
* configure.ac (ENABLE_DOCS): New AM_CONDITIONAL.
* doc/doc.am (dist_doc_DATA): Define only if ENABLE_DOCS.

7 years agoRefine collect_a_little documentation (better explain when 0 is returned)
Ivan Maidanski [Thu, 3 Aug 2017 22:09:34 +0000 (01:09 +0300)]
Refine collect_a_little documentation (better explain when 0 is returned)

Issue #64 (bdwgc).

* include/gc.h (GC_collect_a_little): Refine comment.

7 years agoWorkaround false 'uninitialized var use' code defect (initsecondarythread)
Ivan Maidanski [Fri, 21 Jul 2017 16:34:10 +0000 (19:34 +0300)]
Workaround false 'uninitialized var use' code defect (initsecondarythread)

* tests/initsecondarythread.c [GC_PTHREADS && LINT2] (main): Initialize
"t" local variable to some value (e.g. result of pthread_create()).

7 years agoEliminate CSA warning of non-virtual destructor in test_cpp base class
Ivan Maidanski [Fri, 21 Jul 2017 15:32:22 +0000 (18:32 +0300)]
Eliminate CSA warning of non-virtual destructor in test_cpp base class

* tests/test_cpp.cc (B::~B): Make the destructor virtual.

7 years agoEliminate CSA warning about incorrect cast applied to HBLK_OBJS
Ivan Maidanski [Fri, 21 Jul 2017 15:17:06 +0000 (18:17 +0300)]
Eliminate CSA warning about incorrect cast applied to HBLK_OBJS

HBLK_OBJS() expects the argument value and has the result value of
size_t type.

* reclaim.c (GC_print_block_descr): Cast result of HBLK_OBJS() to
unsigned int instead of casting its argument.

7 years agoEliminate CSA warning about narrowing cast in CleanUp of test_cpp
Ivan Maidanski [Fri, 21 Jul 2017 14:21:02 +0000 (17:21 +0300)]
Eliminate CSA warning about narrowing cast in CleanUp of test_cpp

* tests/test_cpp.cc (D::CleanUp): Cast self->i to word instead of
casting (word)data to int in comparison.

7 years agoEliminate CSA warning of staticroot that can be a local variable (tests)
Ivan Maidanski [Fri, 21 Jul 2017 08:01:01 +0000 (11:01 +0300)]
Eliminate CSA warning of staticroot that can be a local variable (tests)

* tests/staticrootstest.c (staticroot): Remove redundant initialization
to zero; add comment.
* tests/staticrootstest.c (init_staticroot): New function; move
staticroot=libsrl_init() from main(); add comment.
* tests/staticrootstest.c (main): Call init_staticroot().

7 years agoEliminate CSA warning of unmodified non-const static var (disclaim_test)
Ivan Maidanski [Thu, 20 Jul 2017 21:44:05 +0000 (00:44 +0300)]
Eliminate CSA warning of unmodified non-const static var (disclaim_test)
(fix commit 7b0be48)

* tests/disclaim_test.c (pair_magic): Make it const itself.

7 years agoDo not use tkill (Android)
Ivan Maidanski [Thu, 20 Jul 2017 09:11:22 +0000 (12:11 +0300)]
Do not use tkill (Android)

tkill() has been deprecated in Android.  Starting from NDK r11 (which
introduced android-23 API), the call exists only in libc.a (but not
in libc.so).  The comment in Bionic says that tkill exists only for
Mono clients (and only for 32-bit targets).

* include/private/gcconfig.h [PLATFORM_ANDROID && CPP_WORDSZ==32]
(USE_TKILL_ON_ANDROID): Do not define if __ANDROID_API__ >= 23; add
comment.

7 years agoReplace deprecated rewind to fseek in cordxtra
Ivan Maidanski [Thu, 20 Jul 2017 08:39:29 +0000 (11:39 +0300)]
Replace deprecated rewind to fseek in cordxtra

rewind (unlike fseek) does not report whether the operation failed.

* cord/cordxtra.c (CORD_from_file_lazy_inner, CORD_from_file_lazy,
CORD_from_file): Replace rewind(f) to fseek(f, 0l, SEEK_SET) with
error checking; adjust ABORT message in case of fseek and ftell failure.

7 years agoFix undefined HEAP_START in register_dynamic_libraries
Ivan Maidanski [Wed, 2 Aug 2017 21:37:09 +0000 (00:37 +0300)]
Fix undefined HEAP_START in register_dynamic_libraries

* include/private/gcconfig.h [!HEAP_START] (HEAP_START): Define to 0 by
default (if not previously defined in the file).
* os_dep.c (HEAP_START): Remove.

7 years agoFix bytes count passed to add_to_our_memory in backgraph new_back_edges
Ivan Maidanski [Wed, 2 Aug 2017 08:13:23 +0000 (11:13 +0300)]
Fix bytes count passed to add_to_our_memory in backgraph new_back_edges
(fix commit 180b56c)

* backgraph.c [MAKE_BACK_GRAPH] (new_back_edges): Pass bytes_to_get to
GC_add_to_our_memory() (i.e. pass the same number of bytes as passed
to GET_MEM() even in case of MMAP_SUPPORTED).

7 years agoFix GC_incremental declaration/definition type mismatch
Ivan Maidanski [Fri, 21 Jul 2017 17:59:55 +0000 (20:59 +0300)]
Fix GC_incremental declaration/definition type mismatch

* alloc.c [!GC_DISABLE_INCREMENTAL] (GC_incremental): Change variable
type from int to GC_bool (to match that of the declaration in
gc_priv.h).

7 years agoSpecify that unused select() result is intentional
Ivan Maidanski [Thu, 20 Jul 2017 08:50:04 +0000 (11:50 +0300)]
Specify that unused select() result is intentional
(fix commit 62097c3)

* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD]
(GC_brief_async_signal_safe_sleep): Cast select() result to void.

7 years agoFix SIGSEGV in GC_is_marked when gc_cleanup is used in leak-finding mode
Ivan Maidanski [Fri, 14 Jul 2017 08:11:13 +0000 (11:11 +0300)]
Fix SIGSEGV in GC_is_marked when gc_cleanup is used in leak-finding mode

Issue #162 (bdwgc).

Now finalizers and disappearing links registration is a no-op in case
of the leak-finding mode.

*  finalize.c (GC_register_disappearing_link_inner): Do nothing (return
GC_UNIMPLEMENTED) if GC_find_leak.
* finalize.c (GC_register_finalizer_inner): Do nothing if GC_find_leak.
* include/gc.h (GC_find_leak): More verbose comment.
* include/gc.h (GC_debug_register_finalizer,
GC_general_register_disappearing_link): Document the case of
GC_find_leak.

7 years agoFix deadlock in GC_suspend_thread when thread is rebuilding free list
Ivan Maidanski [Fri, 21 Jul 2017 17:27:12 +0000 (20:27 +0300)]
Fix deadlock in GC_suspend_thread when thread is rebuilding free list
(fix commits 62097c359e2bcf)

* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD] (GC_suspend_thread):
Move DISABLE_CANCEL() upper to cover also GC_wait_for_reclaim() and
RAISE_SIGNAL() calls.
* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD && PARALLEL_MARK]
(GC_suspend_thread): If GC_parallel then call GC_wait_for_reclaim()
holding the allocation lock before RAISE_SIGNAL() call; add comment.

7 years agoFix atomic_ops build in Makefile.direct for Solaris
Ivan Maidanski [Thu, 13 Jul 2017 20:27:15 +0000 (23:27 +0300)]
Fix atomic_ops build in Makefile.direct for Solaris

* Makefile.direct (atomic_ops.o, atomic_ops_sysdeps.o): Expand "$<"
macro manually; add comment.

7 years agoTravis CI: enable builds for release-7_6 branch
Ivan Maidanski [Wed, 12 Jul 2017 08:26:50 +0000 (11:26 +0300)]
Travis CI: enable builds for release-7_6 branch
(Back-port .travis.yml from 'master' branch.)

7 years agoFix push_complex_descriptor to avoid unlimited global mark stack growth
Ivan Maidanski [Tue, 11 Jul 2017 23:04:30 +0000 (02:04 +0300)]
Fix push_complex_descriptor to avoid unlimited global mark stack growth

Global mark stack should not grow in parallel marker mode (as
fixed-size local_mark_stack is used instead).

* typd_mlc.c [PARALLEL_MARK] (GC_array_mark_proc): Do not set
GC_mark_stack_too_small if GC_parallel (and new_mark_stack_ptr is
null); add comment.

7 years agoFix deadlock in GC_suspend_thread when thread is finished
Ivan Maidanski [Tue, 11 Jul 2017 22:10:42 +0000 (01:10 +0300)]
Fix deadlock in GC_suspend_thread when thread is finished
(fix commits 62097c359e2bcf)

* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD] (GC_suspend_thread):
Do not call RAISE_SIGNAL() and sem_wait() if thread has FINISHED flag
set; do not handle ESRCH error result of RAISE_SIGNAL(); add comment.

7 years ago.gitignore: Ignore .log and .trs files for test_atomic_ops
Ivan Maidanski [Tue, 11 Jul 2017 21:39:41 +0000 (00:39 +0300)]
.gitignore: Ignore .log  and .trs files for test_atomic_ops