platform/upstream/libgc.git
6 years agoRemove unused HAVE_EXECINFO_H macro definition in configure
Ivan Maidanski [Fri, 27 Apr 2018 18:30:41 +0000 (21:30 +0300)]
Remove unused HAVE_EXECINFO_H macro definition in configure
(fix of commit 978c9b90d)

* configure.ac (AC_CHECK_HEADERS(execinfo.h)): Replace with
AC_CHECK_HEADER.
* configure.ac [!ac_cv_header_execinfo_h] (GC_MISSING_EXECINFO_H): Move
AC_DEFINE to action-if-not-found argument of AC_CHECK_HEADER.

6 years agoRemove unused HAVE_GETCONTEXT macro definition in configure
Ivan Maidanski [Fri, 27 Apr 2018 18:02:32 +0000 (21:02 +0300)]
Remove unused HAVE_GETCONTEXT macro definition in configure
(fix of commits 7c13fb8fc99134699a)

* configure.ac (getcontext): Replace AC_CHECK_FUNCS to AC_CHECK_FUNC.
* configure.ac [!ac_cv_func_getcontext] (NO_GETCONTEXT): Move AC_DEFINE
to action-if-not-found argument of AC_CHECK_FUNC.

6 years agoRemove explicit HAVE_DL_ITERATE_PHDR definition in configure.ac
Ivan Maidanski [Fri, 27 Apr 2018 17:39:44 +0000 (20:39 +0300)]
Remove explicit HAVE_DL_ITERATE_PHDR definition in configure.ac
(code refactoring of commit 0d5a8de)

HAVE_DL_ITERATE_PHDR is defined implicitly by AC_CHECK_FUNCS().

* configure.ac [ac_cv_func_dl_iterate_phdr] (HAVE_DL_ITERATE_PHDR):
Remove explicit AC_DEFINE.

6 years agoFix syntax of conditional operator in with_callee_saves_pushed
Ivan Maidanski [Thu, 26 Apr 2018 07:59:34 +0000 (10:59 +0300)]
Fix syntax of conditional operator in with_callee_saves_pushed
(fix of commit b594132)

Issue #133 (bdwgc).

* mach_dep.c [!HAVE_PUSH_REGS && UNIX_LIKE && !NO_GETCONTEXT]
(GC_with_callee_saves_pushed): Fix syntax of ?: operator (add missing
'?' symbol).

6 years agoAvoid multiple 'getcontext failed' warnings if getcontext is broken
Ivan Maidanski [Thu, 26 Apr 2018 07:54:52 +0000 (10:54 +0300)]
Avoid multiple 'getcontext failed' warnings if getcontext is broken

Issue #133 (bdwgc).

* mach_dep.c [!HAVE_PUSH_REGS && UNIX_LIKE && !NO_GETCONTEXT]
(GC_with_callee_saves_pushed): Define getcontext_works static variable;
do not call getcontext() if getcontext_works < 0; add comment; set
getcontext_works to 1 or -1 (depending whether getcontext is working)
if getcontext_works is zero.
* misc.c [THREADS && UNIX_LIKE && !NO_GETCONTEXT]
(callee_saves_pushed_dummy_fn): New static function (empty).
* misc.c [THREADS && UNIX_LIKE && !NO_GETCONTEXT] (GC_init): Call
GC_with_callee_saves_pushed(callee_saves_pushed_dummy_fn) if GC_dont_gc
or GC_dont_precollect (otherwise it is called by GC_gcollect_inner);
add comment.

6 years agoTravis CI: test --enable-large-config and LINT2 with assertions on (linux)
Ivan Maidanski [Tue, 24 Apr 2018 23:20:59 +0000 (02:20 +0300)]
Travis CI: test --enable-large-config and LINT2 with assertions on (linux)

6 years agoTravis CI: test --enable-gc-debug in 32-bit mode (linux)
Ivan Maidanski [Tue, 24 Apr 2018 23:17:23 +0000 (02:17 +0300)]
Travis CI: test --enable-gc-debug in 32-bit mode (linux)

6 years agoUpdate ChangeLog file
Ivan Maidanski [Tue, 24 Apr 2018 23:01:53 +0000 (02:01 +0300)]
Update ChangeLog file

6 years agoInstall gc.3 man page instead of copying gc.man to doc folder (configure)
Ivan Maidanski [Tue, 24 Apr 2018 21:56:36 +0000 (00:56 +0300)]
Install gc.3 man page instead of copying gc.man to doc folder (configure)

* doc/doc.am [ENABLE_DOCS] (dist_doc_DATA): Remove doc/gc.man.
* doc/doc.am [ENABLE_DOCS] (dist_man3_MANS): Set to doc/gc.man.
* doc/gc.man (.TH): Rename GC_MALLOC to BDWGC.

6 years agoExpose API to control rate and max prior attempts of collect_a_little
Jonathan Chambers [Tue, 10 Apr 2018 17:02:57 +0000 (13:02 -0400)]
Expose API to control rate and max prior attempts of collect_a_little
(a cherry-pick of commit d897344 from 'unity-release-7_4-incremental')

* alloc.c (GC_RATE): Update comment.
* alloc.c (GC_rate): New STATIC variable (initialized to GC_RATE).
* alloc.c (GC_set_rate, GC_get_rate, GC_set_max_prior_attempts,
GC_get_max_prior_attempts): New API function definition.
* alloc.c (max_prior_attempts): New static variable (initialized to
MAX_PRIOR_ATTEMPTS).
* alloc.c (GC_collect_a_little_inner): Replace GC_RATE to GC_rate;
declare max_deficit local variable and compute GC_rate*n once (per
a function call); replace MAX_PRIOR_ATTEMPTS to max_prior_attempts.
* include/gc.h (GC_set_rate, GC_get_rate, GC_set_max_prior_attempts,
GC_get_max_prior_attempts): New API function declaration.
* tests/test.c [GC_PTHREADS] (main): Call GC_set_rate, GC_get_rate,
GC_set_max_prior_attempts, GC_get_max_prior_attempts.

6 years agoExpose API to control the minimum bytes allocated before a GC occurs
Jonathan Chambers [Tue, 10 Apr 2018 17:07:41 +0000 (13:07 -0400)]
Expose API to control the minimum bytes allocated before a GC occurs
(a cherry-pick of commit 4c0e58d from 'unity-release-7_4-incremental')

* alloc.c (min_bytes_allocd_minimum): New static variable.
* alloc.c (GC_set_min_bytes_allocd, GC_get_min_bytes_allocd): New API
function definition (to set/get min_bytes_allocd_minimum).
* alloc.c (min_bytes_allocd): Return min_bytes_allocd_minimum if
result is less than min_bytes_allocd_minimum.
* include/gc.h (GC_set_min_bytes_allocd, GC_get_min_bytes_allocd): New
API function declaration.
* tests/test.c [GC_PTHREADS] (main): Call GC_set_min_bytes_allocd()
and GC_get_min_bytes_allocd().

6 years agoUpdate ChangeLog file
Ivan Maidanski [Sun, 22 Apr 2018 08:29:00 +0000 (11:29 +0300)]
Update ChangeLog file

6 years agoUpdate ChangeLog file (add gc-7.6.6 release date, list its all changes)
Ivan Maidanski [Fri, 20 Apr 2018 18:07:37 +0000 (21:07 +0300)]
Update ChangeLog file (add gc-7.6.6 release date, list its all changes)

6 years agoUpdate ChangeLog file (v7.6 changes only)
Ivan Maidanski [Fri, 20 Apr 2018 07:58:39 +0000 (10:58 +0300)]
Update ChangeLog file (v7.6 changes only)

6 years agoEliminate 'boolean result used in bitwise operation' cppcheck warning
Ivan Maidanski [Thu, 19 Apr 2018 23:19:19 +0000 (02:19 +0300)]
Eliminate 'boolean result used in bitwise operation' cppcheck warning

* finalize.c (GC_push_finalizer_structures): Replace (word)&sym to
(word)(&sym).
* typd_mlc.c (GC_add_ext_descriptor): Likewise.

6 years agoWorkaround gctest hang on kFreeBSD if thread-local allocations are on
Ivan Maidanski [Thu, 19 Apr 2018 22:15:53 +0000 (01:15 +0300)]
Workaround gctest hang on kFreeBSD if thread-local allocations are on

Issue #185 (bdwgc).

* configure.ac [enable_gcj_support && enable_thread_local_alloc]
(GC_ENABLE_SUSPEND_THREAD): Do not AC_DEFINE if host is kfreebsd;
add FIXME item.

6 years agoUse THREAD_EQUAL consistently to compare pthread_t values
Ivan Maidanski [Thu, 19 Apr 2018 21:32:14 +0000 (00:32 +0300)]
Use THREAD_EQUAL consistently to compare pthread_t values
(code refactoring)

* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD] (GC_suspend_thread):
Use THREAD_EQUAL() to compare pthread_t values.
* pthread_support.c (GC_unregister_my_thread): Likewise.
* specific.c [USE_CUSTOM_SPECIFIC] (GC_remove_specific_after_fork,
GC_slow_getspecific): Likewise.

6 years agoUpdate ChangeLog file (add gc-7.4.12 release date)
Ivan Maidanski [Thu, 19 Apr 2018 06:44:21 +0000 (09:44 +0300)]
Update ChangeLog file (add gc-7.4.12 release date)

6 years agoUpdate ChangeLog file (v7.2 - v7.4 changes only)
Ivan Maidanski [Wed, 18 Apr 2018 22:12:56 +0000 (01:12 +0300)]
Update ChangeLog file (v7.2 - v7.4 changes only)

6 years agoTravis CI: Test with disabled memory unmapping
Ivan Maidanski [Sat, 14 Apr 2018 06:49:17 +0000 (09:49 +0300)]
Travis CI: Test with disabled memory unmapping

6 years agoEnable memory unmapping by default
Ivan Maidanski [Sat, 14 Apr 2018 06:26:03 +0000 (09:26 +0300)]
Enable memory unmapping by default

Issue #152 (bdwgc).

* CMakeLists.txt (enable_munmap): New OPTION (on by default).
* CMakeLists.txt [enable_munmap] (USE_MMAP, USE_MUNMAP): Define macro.
* CMakeLists.txt [enable_checksums && enable_munmap): Issue MESSAGE
that CHECKSUMS is not compatible with USE_MUNMAP.
* configure.ac (AC_ARG_ENABLE(munmap)): Update the help message.
* configure.ac [$enable_munmap=""]: Treat as enable_munmap="yes".
* configure.ac [$MUNMAP_THRESHOLD=""]: Treat as MUNMAP_THRESHOLD="yes".
* doc/README.win32 (GNU Tools): Note about "--disable-munmap" option.
* doc/debugging.md (Unexpectedly Large Heap): Remove advice about
"--enable-munmap" option.

6 years agoFix 'unexpected newline after ELSE' CMake error
Ivan Maidanski [Fri, 13 Apr 2018 16:29:45 +0000 (19:29 +0300)]
Fix 'unexpected newline after ELSE' CMake error
(fix of commit 32479d59c)

* CMakeLists.txt [enable_redirect_malloc]: Fix ELSE directive syntax.

6 years agoAppveyor CI: Remove unexpected trailing '.' from cmake arguments
Ivan Maidanski [Fri, 13 Apr 2018 16:18:29 +0000 (19:18 +0300)]
Appveyor CI: Remove unexpected trailing '.' from cmake arguments
(fix of commit c228259)

6 years agoAppveyor CI: Build/test with GC assertion checking
Ivan Maidanski [Fri, 13 Apr 2018 15:52:31 +0000 (18:52 +0300)]
Appveyor CI: Build/test with GC assertion checking

Note: option for GCJ support is removed because the latter is now on
by default.

6 years agoComment out unused enable_cplusplus option in CMake script
Ivan Maidanski [Fri, 13 Apr 2018 15:22:04 +0000 (18:22 +0300)]
Comment out unused enable_cplusplus option in CMake script
(code refactoring)

Note: gc_cpp.cc is always compiled by CMake.

* CMakeLists.txt (enable_cplusplus): Comment out OPTION.
* CMakeLists.txt (SRC): Move addition of gc_cpp.cc to a separate line.

6 years agoAllocate non-executable memory by default (CMake)
Ivan Maidanski [Fri, 13 Apr 2018 15:15:23 +0000 (18:15 +0300)]
Allocate non-executable memory by default (CMake)

* CMakeLists.txt (NO_EXECUTE_PERMISSION): Define macro.

6 years agoTurn on atomic uncollectable functionality by default (CMake)
Ivan Maidanski [Fri, 13 Apr 2018 15:08:40 +0000 (18:08 +0300)]
Turn on atomic uncollectable functionality by default (CMake)

* CMakeLists.txt (enable_atomic_uncollectable): New OPTION (on by
default).
* CMakeLists.txt [enable_atomic_uncollectable]
(GC_ATOMIC_UNCOLLECTABLE): Define macro.

6 years agoTurn on gcj, disclaim and java finalization by default (CMake)
Ivan Maidanski [Fri, 13 Apr 2018 15:04:24 +0000 (18:04 +0300)]
Turn on gcj, disclaim and java finalization by default (CMake)

* CMakeLists.txt (enable_gcj_support): Enable by default.
* CMakeLists.txt (enable_disclaim, enable_java_finalization): New
OPTION (on by default).
* CMakeLists.txt [enable_disclaim] (ENABLE_DISCLAIM): Define macro.
* CMakeLists.txt [enable_java_finalization] (JAVA_FINALIZATION):
Likewise.
* CMakeLists.txt [enable_disclaim] (SRC): Add fnlz_mlc.c entry.

6 years agoAllow gc_assertions enabling in CMake script
Ivan Maidanski [Fri, 13 Apr 2018 14:45:59 +0000 (17:45 +0300)]
Allow gc_assertions enabling in CMake script

* CMakeLists.txt (enable_gc_assertions): New OPTION, off by default.
* CMakeLists.txt [enable_gc_assertions] (GC_ASSERTIONS): Define macro.

6 years agoAllow gc_debug, redirect_malloc, large_config options in CMake script
Ivan Maidanski [Fri, 13 Apr 2018 14:40:35 +0000 (17:40 +0300)]
Allow gc_debug, redirect_malloc, large_config options in CMake script

* CMakeLists.txt (enable_gc_debug, enable_redirect_malloc,
enable_large_config): New OPTION (off by default).
* CMakeLists.txt [enable_gc_debug] (DBG_HDRS_ALL, KEEP_BACK_PTRS):
Define macro.
* CMakeLists.txt [enable_redirect_malloc] (REDIRECT_MALLOC,
REDIRECT_REALLOC, REDIRECT_FREE, GC_USE_DLOPEN_WRAP): Likewise.
* CMakeLists.txt [enable_large_config] (LARGE_CONFIG): Likewise.
* CMakeLists.txt [enable_gc_debug] (MAKE_BACK_GRAPH): Define macro if
host is Linux or DG/UX.
* CMakeLists.txt [enable_gc_debug] (SAVE_CALL_COUNT): Define macro to 8
if host is Linux.
* CMakeLists.txt [enable_gc_debug] (SRC): Add backgraph.c if host is
Linux or DG/UX.

6 years agoTravis CI: Test with disabled and manual handle-fork
Ivan Maidanski [Wed, 11 Apr 2018 06:51:04 +0000 (09:51 +0300)]
Travis CI: Test with disabled and manual handle-fork

Also, remove unneeded --enable-handle-fork since it is on by default.

6 years agoAvoid 'Unexpected heap growth' in 64-bit multi-threaded gctest if n_tests=1
Ivan Maidanski [Wed, 11 Apr 2018 06:19:09 +0000 (09:19 +0300)]
Avoid 'Unexpected heap growth' in 64-bit multi-threaded gctest if n_tests=1

* tests/test.c [!VERY_SMALL_CONFIG && CPP_WORDSZ==64] (check_heap_stats):
Increase max_heap_sz initial value by ~8.7% (so that the ratio of
max_heap_sz initial values between 32-bit and 64-bit targets
is the roughly same as exists for VERY_SMALL_CONFIG).

6 years agoAllow subthreadcreate_test to be compiled with zero NTHREADS
Ivan Maidanski [Tue, 10 Apr 2018 21:26:09 +0000 (00:26 +0300)]
Allow subthreadcreate_test to be compiled with zero NTHREADS

* tests/subthread_create.c [AO_HAVE_fetch_and_add1] (main): Skip the
test (except for printing the number of created and ended threads) if
NTHREADS is 0.

6 years agoAvoid potential data race during GC_dump execution
Ivan Maidanski [Tue, 10 Apr 2018 08:48:51 +0000 (11:48 +0300)]
Avoid potential data race during GC_dump execution

* include/gc.h (GC_dump): Separate declaration from GC_dump_named; add
comment that it acquires the lock.
* include/gc.h (GC_dump_named): Refine comment (add note that the lock
is not acquired by this function).
* include/private/gc_priv.h (GC_dump): Remove commented out declaration.
* include/private/gc_priv.h [!NO_DEBUGGING] (COND_DUMP): Call
GC_dump_named(NULL) instead of GC_dump().
* misc.c (GC_init) [GC_ASSERTIONS && GC_ALWAYS_MULTITHREADED]: Call
COND_DUMP while holding the allocation lock.
* misc.c [!NO_DEBUGGING] (GC_dump): Place LOCK/UNLOCK around
GC_dump_named() call.

6 years agoRemove assertion about held lock from apply_to_all_blocks
Ivan Maidanski [Tue, 10 Apr 2018 08:28:09 +0000 (11:28 +0300)]
Remove assertion about held lock from apply_to_all_blocks
(fix of commit 5e6cc59b0)

GC_apply_to_all_blocks may be called by GC_print_block_list which,
in turn, might be called from the debugger not holding the lock.

* headers.c (GC_apply_to_all_blocks): Add comment about the lock;
remove VARARGS1 in comment; remove explicit assertion that the lock
is held.

6 years agoAvoid potential data race during apply_to_each_object(reset_back_edge)
Ivan Maidanski [Tue, 10 Apr 2018 08:07:08 +0000 (11:07 +0300)]
Avoid potential data race during apply_to_each_object(reset_back_edge)

* backgraph.c [MAKE_BACK_GRAPH] (GC_print_back_graph_stats): Add
assertion that the allocation lock is held; store GC_deepest_obj to
obj local variable (while holding the lock); place UNLOCK/LOCK around
GC_print_heap_obj() call; pass obj to GC_print_heap_obj().
* finalize.c [MAKE_BACK_GRAPH] (GC_notify_or_invoke_finalizers): Remove
UNLOCK/LOCK around GC_print_back_graph_stats() call.

6 years agoAvoid potential race in print_static_roots called by dyld_image_add/remove
Ivan Maidanski [Tue, 10 Apr 2018 07:31:57 +0000 (10:31 +0300)]
Avoid potential race in print_static_roots called by dyld_image_add/remove

* dyn_load.c [DARWIN && DARWIN_DEBUG && !NO_DEBUGGING]
(GC_dyld_image_add, GC_dyld_image_remove): Place LOCK/UNLOCK around
GC_print_static_roots() call.
* dyn_load.c [DARWIN && DARWIN_DEBUG && !NO_DEBUGGING]
(GC_dyld_image_remove): Add DCL_LOCK_STATE.

6 years agoAdd assertions about held lock for apply_to_each_object callers
Ivan Maidanski [Fri, 6 Apr 2018 16:45:23 +0000 (19:45 +0300)]
Add assertions about held lock for apply_to_each_object callers
(code refactoring of commit 5e6cc59b0)

* alloc.c (GC_stopped_mark, GC_finish_collection): Add assertion (at
the beginning of the function) that the allocation lock is held.
* backgraph.c [MAKE_BACK_GRAPH] (GC_build_back_graph,
GC_traverse_back_graph): Likewise.
* mark.c (GC_initiate_gc): Likewise.
* alloc.c (GC_stopped_mark): Remove comment about the held lock
(because there is an assertion about it).

6 years agoFix null dereference in print_callers on backtrace_symbols failure
Ivan Maidanski [Fri, 6 Apr 2018 16:07:50 +0000 (19:07 +0300)]
Fix null dereference in print_callers on backtrace_symbols failure

* os_dep.c [NEED_CALLINFO && GC_HAVE_BUILTIN_BACKTRACE
&& !GC_BACKTRACE_SYMBOLS_BROKEN] (GC_print_callers): If sym_name is
NULL then print info[i].ci_pc to buf and set name to buf (instead of
to sym_name[0]).
* os_dep.c [NEED_CALLINFO && GC_HAVE_BUILTIN_BACKTRACE
&& !GC_BACKTRACE_SYMBOLS_BROKEN] (GC_print_callers): Do not call
free(sym_name) if sym_name is NULL.

6 years agoFix null pointer dereference in get_private_path_and_zero_file (Symbian)
Ivan Maidanski [Fri, 6 Apr 2018 06:32:12 +0000 (09:32 +0300)]
Fix null pointer dereference in get_private_path_and_zero_file (Symbian)

* extra/symbian.cpp (GC_get_private_path_and_zero_file): Do not call
memcpy() if allocation of copyChar is failed.
* os_dep.c [MMAP_SUPPORTED && !USE_MMAP_ANON] (zero_fd): Initialize
global variable to -1 (instead of 0).
* os_dep.c [MMAP_SUPPORTED && !USE_MMAP_ANON && SYMBIAN]
(GC_unix_mmap_get_mem): Do not call open() and free() if path is NULL.

6 years agoFix missing SIGBUS handler setup for kFreeBSD
Ivan Maidanski [Fri, 6 Apr 2018 06:13:03 +0000 (09:13 +0300)]
Fix missing SIGBUS handler setup for kFreeBSD

Issue #184 (bdwgc).

* os_dep.c [MPROTECT_VDB && !DARWIN && !MSWIN32 && !MSWINCE && FREEBSD
&& __GLIBC__] (GC_mprotect_dirty_init): Call sigaction(SIGBUS).

6 years agoDefine GC_FREEBSD_THREADS and GC_ADD_CALLER macros for kFreeBSD
Ivan Maidanski [Fri, 6 Apr 2018 05:59:22 +0000 (08:59 +0300)]
Define GC_FREEBSD_THREADS and GC_ADD_CALLER macros for kFreeBSD

* include/gc_config_macros.h [__FreeBSD_kernel__] (GC_FREEBSD_THREADS):
Define macro.
* include/gc_config_macros.h [__FreeBSD_kernel__
&& !GC_CAN_SAVE_CALL_STACKS] (GC_ADD_CALLER): Likewise.

6 years agoDo not declare dl_iterate_phdr as weak for kFreeBSD
Ivan Maidanski [Fri, 6 Apr 2018 05:51:33 +0000 (08:51 +0300)]
Do not declare dl_iterate_phdr as weak for kFreeBSD

* dyn_load.c [!USE_PROC_FOR_LIBRARIES && __FreeBSD_kernel__]
(HAVE_DL_ITERATE_PHDR, DL_ITERATE_PHDR_STRONG): Define.

6 years agoDo not match kFreeBSD by FreeBSD host string pattern (CMake/configure)
Ivan Maidanski [Fri, 6 Apr 2018 05:30:50 +0000 (08:30 +0300)]
Do not match kFreeBSD by FreeBSD host string pattern (CMake/configure)
(code refactoring of commit 686a66731)

Issue #174 (bdwgc).

* CMakeLists.txt [CMAKE_USE_PTHREADS_INIT && enable_handle_fork]:
Replace ".*-.*-.*freebsd.*" to ".*-.*-freebsd.*".
* configure.ac [$enable_handle_fork=auto && $THREADS=posix]: Replace
"*-*-*freebsd*" to "*-*-freebsd*".

6 years agoDetermine whether to use compiler TLS for kFreeBSD at compile time
Ivan Maidanski [Thu, 5 Apr 2018 22:06:48 +0000 (01:06 +0300)]
Determine whether to use compiler TLS for kFreeBSD at compile time
(code refactoring)

* configure.ac [$THREADS=posix && $host=*-*-kfreebsd*-gnu]
(USE_COMPILER_TLS): Do not define macro.
* configure.ac [THREAD_LOCAL_ALLOC && FREEBSD && __GLIBC__
&& GC_GNUC_PREREQ(4, 4)] (USE_COMPILER_TLS): Define macro.

6 years agoEliminate 'there is pointer arithmetic with NULL' cppcheck warning
Ivan Maidanski [Thu, 5 Apr 2018 21:42:29 +0000 (00:42 +0300)]
Eliminate 'there is pointer arithmetic with NULL' cppcheck warning

* extra/msvc_dbg.c (GetDescriptionFromStack): Compare size to 0 instead
of comparing description to NULL; mark format argument as used.
* extra/msvc_dbg.c (backtrace_symbols): Do not call
GetDescriptionFromStack if symbols (description) is NULL but size is
non-zero.

6 years agoDo not resend the restart signal to threads that are already restarted
Ivan Maidanski [Wed, 4 Apr 2018 22:40:58 +0000 (01:40 +0300)]
Do not resend the restart signal to threads that are already restarted
(fix of commit 3498427)

Issue #181 (bdwgc).

* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL] (GC_stop_count):
Update comment.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_suspend_handler_inner): Add assertion that my_stop_count is even.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_suspend_handler_inner): Mask lowest bit of last_stop_count when
checking for the duplicate signal.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_suspend_handler_inner): If GC_retry_signals then
set the lowest bit of last_stop_count (by AO_store_release) after the
second sem_post() call; add comment.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_suspend_all): Add comment for last_stop_count check.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL] (GC_stop_world):
Increment GC_stop_count by 2 (instead of by one).
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_restart_all): If GC_retry_signals and last_stop_count has the same
value as GC_stop_count+1 then do not increment n_live_threads and do
not send the restart signal to the thread.

6 years agoTravis CI: Remove duplicate build configuration (linux/clang with cpp)
Ivan Maidanski [Wed, 4 Apr 2018 21:40:34 +0000 (00:40 +0300)]
Travis CI: Remove duplicate build configuration (linux/clang with cpp)
(fix of commit 96a81eb55)

6 years agoReplace GC_NO_RETRY_SIGNALS environment variable with GC_RETRY_SIGNALS=0
Ivan Maidanski [Mon, 2 Apr 2018 23:21:00 +0000 (02:21 +0300)]
Replace GC_NO_RETRY_SIGNALS environment variable with GC_RETRY_SIGNALS=0

* doc/README.environment (GC_NO_RETRY_SIGNALS): Remove.
* doc/README.environment (GC_RETRY_SIGNALS): Document "0" value.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL] (GC_stop_init):
Declare str local variable; do not check GC_NO_RETRY_SIGNALS
environment variable; refine comment; set GC_retry_signals to false
if the value of GC_RETRY_SIGNALS environment variable is "0".

6 years agoHandle pthread restart signals loss if retry_signals
Ivan Maidanski [Mon, 2 Apr 2018 22:23:01 +0000 (01:23 +0300)]
Handle pthread restart signals loss if retry_signals

Issue #181 (bdwgc).

* doc/README.environment (GC_RETRY_SIGNALS, GC_NO_RETRY_SIGNALS):
Update documentation (support of restart signals loss, try signals
if compiled with ASan/MSan/TSan).
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_retry_signals): Set true also if ADDRESS_SANITIZER or
MEMORY_SANITIZER.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& !GC_NETBSD_THREADS_WORKAROUND] (GC_suspend_handler_inner): Call
sem_post(GC_suspend_ack_sem) at the function end if GC_retry_signals;
update comment about the RESTART signal loss.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& !GC_OPENBSD_UTHREADS] (GC_start_world): Call
resend_lost_signals(GC_restart_all) and update n_live_threads value.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& !GC_OPENBSD_UTHREADS && !GC_NETBSD_THREADS_WORKAROUND]
(GC_start_world): Call suspend_restart_barrier() if GC_retry_signals.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL] (GC_stop_init):
Update the message logged if GC_retry_signals.

6 years agoFix a typo in WARN message of resend_lost_signals
Ivan Maidanski [Mon, 2 Apr 2018 22:03:17 +0000 (01:03 +0300)]
Fix a typo in WARN message of resend_lost_signals
(fix of commit c2e9583)

Issue #181 (bdwgc).

* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(resend_lost_signals): Fix typo ("stopping") in WARN message.

6 years agoDefine static resend_lost_signals(), restart_all() in pthread_stop_world
Ivan Maidanski [Mon, 2 Apr 2018 06:22:51 +0000 (09:22 +0300)]
Define static resend_lost_signals(), restart_all() in pthread_stop_world
(code refactoring)

Issue #181 (bdwgc).

* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL && GC_ASSERTIONS]
(suspend_restart_barrier): Check that the count of GC_suspend_ack_sem
is zero at the end of the function.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(resend_lost_signals): New static function (the code is moved from
GC_stop_world).
* pthread_stop_world.c [DEBUG_THREADS] (GC_suspend_all): Move the
assignment of GC_stopping_thread and GC_stopping_pid to GC_stop_world.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL] (GC_stop_world):
Call resend_lost_signals() if GC_retry_signals.
* pthread_stop_world.c [!NACL] (GC_restart_all): New static function
(the code is moved from GC_start_world).
* pthread_stop_world.c [!NACL] (GC_start_world): Declare n_live_threads
local variable; call GC_restart_all.

6 years agoUnblock only GC signals in suspend_handler (TSan)
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.

6 years agoAdd assertions about held lock when accessing all_bottom_indices
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.

6 years agoUpdate top_index entry pointer only when the entry is constructed fully
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.

6 years agoTravis CI: Fix TSan builds after enabling handle-fork by default
Ivan Maidanski [Thu, 29 Mar 2018 07:44:17 +0000 (10:44 +0300)]
Travis CI: Fix TSan builds after enabling handle-fork by default

6 years agoAcknowledge thread restart from suspend_handler (NetBSD)
Ivan Maidanski [Thu, 29 Mar 2018 07:23:27 +0000 (10:23 +0300)]
Acknowledge thread restart from suspend_handler (NetBSD)

Issue #181 (bdwgc).

Also, one sem_t variable is used to acknowledge both thread suspends
and restarts.

* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_suspend_ack_sem): Add comment.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& GC_NETBSD_THREADS_WORKAROUND] (GC_restart_ack_sem): Remove static
variable.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& GC_NETBSD_THREADS_WORKAROUND] (GC_suspend_handler_inner): Call
sem_post(&GC_suspend_ack_sem) at the end of the handler (just before
RESTORE_CANCEL).
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(suspend_restart_barrier): New static function.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& GC_NETBSD_THREADS_WORKAROUND] (GC_restart_handler): Do not call
sem_post(&GC_restart_ack_sem).
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL] (GC_stop_world):
Remove i, code local variables; call suspend_restart_barrier instead
of sem_wait calls in a loop.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& GC_NETBSD_THREADS_WORKAROUND] (GC_start_world): Likewise.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& GC_NETBSD_THREADS_WORKAROUND] (GC_stop_init): Remove
sem_init(&GC_restart_ack_sem) call.

6 years agoMinimize delay between sem_post and sigsuspend in suspend_handler if TSan
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.

6 years agoEnable handle-fork by default
Ivan Maidanski [Wed, 28 Mar 2018 22:08:11 +0000 (01:08 +0300)]
Enable handle-fork by default

Issue #174 (bdwgc).

* CMakeLists.txt (enable_handle_fork): New option (on by default).
* CMakeLists.txt [CMAKE_USE_PTHREADS_INIT && enable_handle_fork]:
Define HANDLE_FORK macro for aix, cygwin, freebsd, haiku, hpux11,
irix, kfreebsd, linux, netbsd, openbsd, osf, solaris hosts.
* CMakeLists.txt [CMAKE_USE_PTHREADS_INIT && HOST=*-*-darwin*
&& enable_handle_fork && enable_parallel_mark]: Define HANDLE_FORK
macro; add comment.
* configure.ac (AC_ARG_ENABLE(handle-fork)): Allow "auto" and "manual"
values; update help message.
* configure.ac [$enable_handle_fork!=yes && $enable_handle_fork!=no
&& $enable_handle_fork!=manual && $THREADS=posix]: Define HANDLE_FORK
macro for aix, cygwin, freebsd, haiku, hpux11, irix, kfreebsd, linux,
netbsd, openbsd, osf, solaris hosts (and also for darwin if
enable_parallel_mark); add comment.

6 years agoSupport Haiku multi-threaded build by CMake
Ivan Maidanski [Tue, 27 Mar 2018 22:06:01 +0000 (01:06 +0300)]
Support Haiku multi-threaded build by CMake

Issue #97 (bdwgc).

* CMakeLists.txt [CMAKE_USE_PTHREADS_INIT && HOST=*-*-haiku*]: Define
GC_THREADS and _REENTRANT macros.
* CMakeLists.txt [CMAKE_USE_PTHREADS_INIT && HOST=*-*-haiku*
&& enable_parallel_mark]: Define PARALLEL_MARK macro.
* CMakeLists.txt [CMAKE_USE_PTHREADS_INIT && HOST=*-*-haiku*
&& enable_thread_local_alloc]: Define THREAD_LOCAL_ALLOC macro.

6 years agoAccept Android platform by both CMake and configure
Ivan Maidanski [Tue, 27 Mar 2018 18:27:48 +0000 (21:27 +0300)]
Accept Android platform by both CMake and configure
(fix of commit 1680d91)

* CMakeLists.txt (_HOST): Adjust FIXME comment.
* CMakeLists.txt (HOST): Remove replacement of "android" to "linux".
* CMakeLists.txt [CMAKE_USE_PTHREADS_INIT && HOST=*-*-android*]:
Define GC_THREADS and _REENTRANT macros.
* CMakeLists.txt [CMAKE_USE_PTHREADS_INIT && HOST=*-*-android*
&& enable_parallel_mark]: Define PARALLEL_MARK macro.
* CMakeLists.txt [CMAKE_USE_PTHREADS_INIT && HOST=*-*-android*
&& enable_thread_local_alloc]: Define THREAD_LOCAL_ALLOC macro.
* configure.ac [$THREADS=posix && $host=*-*-android*] (GC_THREADS,
_REENTRANT): Define macro.
* configure.ac [$THREADS=posix && $host=*-*-android*
&& $enable_parallel_mark] (PARALLEL_MARK): Likewise.
* configure.ac [$THREADS=posix && $host=*-*-android*
&& $enable_thread_local_alloc] (THREAD_LOCAL_ALLOC): Likewise.

6 years agoReduce probability of collision in threads hashtable for 64-bit targets
Ivan Maidanski [Mon, 26 Mar 2018 18:30:32 +0000 (21:30 +0300)]
Reduce probability of collision in threads hashtable for 64-bit targets

* include/private/pthread_support.h [GC_PTHREADS && !GC_WIN32_THREADS
&& CPP_WORDSZ==64] (THREAD_TABLE_INDEX): Xor also 4th byte of id value.

6 years agoDo not use AO_store in FAST_MALLOC_GRANS() in the single-threaded mode
Ivan Maidanski [Mon, 26 Mar 2018 07:15:50 +0000 (10:15 +0300)]
Do not use AO_store in FAST_MALLOC_GRANS() in the single-threaded mode
(fix of commit effa229)

Issue #214 (bdwgc).

* include/gc_inline.h (GC_FAST_M_AO_STORE): Do not use AO_store unless
GC_THREADS.

6 years agoInclude malloc.c in extra/gc.c after include gc_inline.h
Ivan Maidanski [Fri, 23 Mar 2018 18:47:39 +0000 (21:47 +0300)]
Include malloc.c in extra/gc.c after include gc_inline.h
(code refactoring)

* extra/gc.c: Move include malloc.c to be near include mallocx.c.

6 years agoAvoid potential race between malloc_kind and mark_thread_local_fls_for
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].

6 years agoFix thread_suspend fail for threads registered from key destructor (OS X)
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.

6 years agoExplicitly unblock GC signals on GC initialization
Ivan Maidanski [Thu, 22 Mar 2018 22:09:40 +0000 (01:09 +0300)]
Explicitly unblock GC signals on GC initialization

Issue #175 (bdgwc).

Note: NO_SIGNALS_UNBLOCK_IN_MAIN macro is to be defined manually to
turn off this feature (for a reason).

* include/private/gcconfig.h [GC_NO_PTHREAD_SIGMASK]
(NO_SIGNALS_UNBLOCK_IN_MAIN): New macro.
* pthread_stop_world.c [GC_PTHREADS && !GC_WIN32_THREADS
&& !GC_DARWIN_THREADS && !SN_TARGET_ORBIS && !SN_TARGET_PSP2 && !NACL
&& !GC_OPENBSD_UTHREADS && !NO_SIGNALS_UNBLOCK_IN_MAIN]
(GC_unblock_gc_signals): Define.
* pthread_stop_world.c [GC_PTHREADS && !GC_WIN32_THREADS
&& !GC_DARWIN_THREADS && !SN_TARGET_ORBIS && !SN_TARGET_PSP2 && !NACL
&& !GC_OPENBSD_UTHREADS && !NO_SIGNALS_UNBLOCK_IN_MAIN] (GC_stop_init):
Call GC_unblock_gc_signals; add comment.

6 years agoMatch GC_FAST_MALLOC_GRANS formal and actual arguments where possible
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.

6 years agoFix assertion violation in DllMain of win32_threads
Ivan Maidanski [Thu, 22 Mar 2018 08:24:04 +0000 (11:24 +0300)]
Fix assertion violation in DllMain of win32_threads

DllMain(DLL_THREAD_ATTACH) might be called for C runtime threads
before main() is launched, so this commit just removes wrong
assertion in DllMain.

* win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_DllMain): Remove
entry_count static variable; remove assertion for entry_count and
parallel_initialized values in DLL_THREAD_ATTACH case.

6 years agoCheck consistency of descr, adjust, clear arguments of GC_new_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).

6 years agoFix ASSERT_CANCEL_DISABLED violation in try_to_collect_inner
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.

6 years agoFix unbounded heap growth in case of intensive disappearing links usage
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.

6 years agoUse OPT_RA instead of STORE_DEBUG_INFO in dbg_mlc
Ivan Maidanski [Mon, 19 Mar 2018 21:51:18 +0000 (00:51 +0300)]
Use OPT_RA instead of STORE_DEBUG_INFO in dbg_mlc
(fix of commit d6ccabe)

* dbg_mlc.c (STORE_DEBUG_INFO): Remove macro.
* dbg_mlc.c (GC_debug_malloc, GC_debug_malloc_ignore_off_page,
GC_debug_malloc_atomic_ignore_off_page, GC_debug_generic_malloc,
GC_debug_malloc_stubborn, GC_debug_malloc_atomic,
GC_debug_malloc_uncollectable, GC_debug_malloc_atomic_uncollectable):
Replace STORE_DEBUG_INFO() to store_debug_info() call; use OPT_RA.

6 years agoFix 'scope of var can be reduced' cppcheck err in enqueue_all_finalizers
Ivan Maidanski [Thu, 15 Mar 2018 20:38:31 +0000 (23:38 +0300)]
Fix 'scope of var can be reduced' cppcheck err in enqueue_all_finalizers

* finalize.c [!JAVA_FINALIZATION_NOT_NEEDED]
(GC_enqueue_all_finalizers): Declare curr_fo and real_ptr in the scopes
of their use.

6 years agoAdd assertions to ensure ADD_CALL_CHAIN is called holding the lock
Ivan Maidanski [Thu, 15 Mar 2018 20:16:36 +0000 (23:16 +0300)]
Add assertions to ensure ADD_CALL_CHAIN is called holding the lock
(code refactoring)

* alloc.c (GC_collect_a_little_inner, GC_allocobj): Add assertion that
the allocation lock is held.
* dbg_mlc.c (GC_store_debug_info_inner): Likewise.
* dbg_mlc.c [DBG_HDRS_ALL] (GC_debug_generic_malloc_inner,
GC_debug_generic_malloc_inner_ignore_off_page): Likewise.
* finalize.c [!GC_TOGGLE_REFS_NOT_NEEDED] (ensure_toggleref_capacity):
Likewise.
* specific.c [USE_CUSTOM_SPECIFIC] (GC_key_create_inner): Likewise.
* alloc.c (GC_allocobj): Remove comment (about the lock).
* dbg_mlc.c [DBG_HDRS_ALL] (GC_debug_generic_malloc_inner): Likewise.

6 years agoFix comment for debug_generic_malloc_inner[_ignore_off_page]
Ivan Maidanski [Thu, 15 Mar 2018 07:41:22 +0000 (10:41 +0300)]
Fix comment for debug_generic_malloc_inner[_ignore_off_page]
(fix of commit 38965f279)

* dbg_mlc.c [DBG_HDRS_ALL] (GC_debug_generic_malloc_inner): Update
comment after adding GC_start_debugging[_inner] call.

6 years agoFix the collector hang when it is configured with --enable-gc-debug
Ivan Maidanski [Thu, 15 Mar 2018 07:10:39 +0000 (10:10 +0300)]
Fix the collector hang when it is configured with --enable-gc-debug

Issue #205 (bdwgc).

* dbg_mlc.c (GC_store_debug_info_inner): Remove comment (as it exists
in the header); change from STATIC to GC_INNER.
* dbg_mlc.c (STORE_DEBUG_INFO): New macro.
* dbg_mlc.c (GC_store_debug_info): Change from GC_INNER to static;
remove GC_ prefix; replace ptr_t to void*; add fn argument;
replace "const char *string, int linenum" with GC_EXTRA_PARAMS;
change "word sz" argument to "size_t lb"; allow p to be null (print
error message in this case); call GC_start_debugging_inner unless
GC_debugging_started; call ADD_CALL_CHAIN.
* dbg_mlc.c (GC_start_debugging): Remove.
* dbg_mlc.c (GC_debug_malloc, GC_debug_malloc_ignore_off_page,
GC_debug_malloc_atomic_ignore_off_page, GC_debug_generic_malloc,
GC_debug_malloc_atomic, GC_debug_malloc_uncollectable): Call
STORE_DEBUG_INFO() instead of checking result for null and calling
GC_start_debugging, ADD_CALL_CHAIN, GC_store_debug_info.
* dbg_mlc.c [STUBBORN_ALLOC] (GC_debug_malloc_stubborn): Likewise.
* dbg_mlc.c [GC_ATOMIC_UNCOLLECTABLE]
(GC_debug_malloc_atomic_uncollectable): Likewise.
* gcj_mlc.c [GC_GCJ_SUPPORT] (GC_debug_gcj_malloc): Call ADD_CALL_CHAIN
while holding the lock; call GC_store_debug_info_inner (holding the
lock) instead of GC_store_debug_info.
* include/private/dbg_mlc.h (ADD_CALL_CHAIN): Update comment.
* include/private/gc_priv.h (GC_store_debug_info): Replace with
GC_store_debug_info_inner; update comment; change ptr_t to void*.
* os_dep.c [SAVE_CALL_CHAIN] (GC_save_callers): Add assertion that the
allocation lock is held; add comment.

6 years agoAccess finalize_now atomically to avoid TSan warning without no-sanitize
Ivan Maidanski [Tue, 13 Mar 2018 22:18:30 +0000 (01:18 +0300)]
Access finalize_now atomically to avoid TSan warning without no-sanitize

* finalize.c (SET_FINALIZE_NOW): New macro (which uses AO_store if
available).
* finalize.c (GC_finalize): Use SET_FINALIZE_NOW(fo) instead of
GC_fnlz_roots.finalize_now=fo.
* finalize.c [!JAVA_FINALIZATION_NOT_NEEDED]
(GC_enqueue_all_finalizers): Likewise.
* finalize.c [THREADS] (GC_invoke_finalizers): Likewise.
* finalize.c (GC_should_invoke_finalizers): Remove
GC_ATTR_NO_SANITIZE_THREAD.
* finalize.c [AO_HAVE_load] (GC_should_invoke_finalizers): Use AO_load
to get GC_fnlz_roots.finalize_now value.

6 years agoTravis CI: Test pointer backtracing full support with TSan
Ivan Maidanski [Tue, 13 Mar 2018 21:44:42 +0000 (00:44 +0300)]
Travis CI: Test pointer backtracing full support with TSan

6 years agoUse atomic load/store for the concurrently accessed variables in GC_lock
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.

6 years agoEliminate TSan warning about non-atomic read in store_back_pointer
Ivan Maidanski [Mon, 12 Mar 2018 22:23:49 +0000 (01:23 +0300)]
Eliminate TSan warning about non-atomic read in store_back_pointer
(fix of commit 701858e)

* include/private/dbg_mlc.h [PARALLEL_MARK && KEEP_BACK_PTRS]
(GC_HAS_DEBUG_INFO): Use AO_load to access the word pointed by p; add
comment.

6 years agoAvoid potential race in SET_MARK_BIT_EXIT_IF_SET if parallel marking
Ivan Maidanski [Fri, 9 Mar 2018 20:23:56 +0000 (23:23 +0300)]
Avoid potential race in SET_MARK_BIT_EXIT_IF_SET if parallel marking

* include/private/gc_atomic_ops.h [GC_BUILTIN_ATOMIC] (AO_char_load,
AO_HAVE_char_load, AO_char_store, AO_HAVE_char_store): Define macro.
* include/private/gc_pmark.h [USE_MARK_BYTES && PARALLEL_MARK
&& AO_HAVE_char_store && !AO_USE_PTHREAD_DEFS]
(SET_MARK_BIT_EXIT_IF_SET): Use AO_char_load/store to access hb_marks.
* include/private/gc_pmark.h [!USE_MARK_BYTES && PARALLEL_MARK
&& THREAD_SANITIZER] (OR_WORD_EXIT_IF_SET): Use AO_load to fetch the
word at addr.
* tests/test_atomic_ops.c [AO_HAVE_char_load || AO_HAVE_char_store]
(main): Define c local variable.
* tests/test_atomic_ops.c [AO_HAVE_char_load] (main): Test AO_char_load.
* tests/test_atomic_ops.c [AO_HAVE_char_store] (main): Test
AO_char_store.

6 years agoReally use AO_load/store in realloc, clear_hdr_marks and reclaim_generic
Ivan Maidanski [Wed, 7 Mar 2018 18:34:28 +0000 (21:34 +0300)]
Really use AO_load/store in realloc, clear_hdr_marks and reclaim_generic
(fix of commit bc7d075)

* include/private/gc_atomic_ops.h [GC_BUILTIN_ATOMIC] (AO_HAVE_load,
AO_HAVE_store, AO_HAVE_store_release_write): Define macro.

6 years agoAvoid potential race when storing oh_back_ptr during parallel marking
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).

6 years agoWorkaround sem_wait failure in pthread_create on Haiku
Ivan Maidanski [Tue, 6 Mar 2018 22:24:05 +0000 (01:24 +0300)]
Workaround sem_wait failure in pthread_create on Haiku

Issue #97 (bdwgc).

sem_wait() fails because of some bug in Haiku OS (as of hrev51798).

* pthread_support.c [GC_HAIKU_THREADS] (WRAP_FUNC(pthread_create)):
If errno is EACCES then just retry sem_wait instead of ABORT.

6 years agoWorkaround Haiku pthread_join failure in subthreadcreate_test
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.

6 years agoRevert 'Report errno in case of sem_wait failure in GC_pthread_create'
Ivan Maidanski [Tue, 6 Mar 2018 21:48:29 +0000 (00:48 +0300)]
Revert 'Report errno in case of sem_wait failure in GC_pthread_create'

This reverts commit 003470047cd1873080657dcb821d02cb806409b4.

The reverted commit was needed only to print the error code on Haiku;
the commit is not needed permanently.

6 years agoAvoid duplication of code handling pthreads case in configure
Ivan Maidanski [Tue, 6 Mar 2018 08:34:17 +0000 (11:34 +0300)]
Avoid duplication of code handling pthreads case in configure
(code refactoring)

* configure.ac [$THREADS=pthreads] (default_threadlibs): New variable.
* configure.ac [$THREADS=pthreads && ($host in *-*-aix* | *-*-cygwin*
| *-*-darwin* | *-*-dragonfly* | *-*-freebsd* | *-*-haiku*
| *-*-hpux11* | *-*-irix* | *-*-kfreebsd*-gnu | *-*-gnu* | *-*-*linux*
| *-*-nacl* | *-*-netbsd* | *-*-openbsd* | *-*-osf* | *-*-solaris*)]
(default_threadlibs): Set to true.
* configure.ac [$THREADS=pthreads && !($host in
*-*-hpux11* | *-*-openbsd* | *-*-freebsd* | *-*-gnu* | *-*-netbsd*
| *-*-solaris* | *-*-cygwin* | *-*-mingw* | *-*-darwin* | *-*-osf*)]:
Do AC_MSG_ERROR() only if default_threadlibs is false.

6 years agoFix 'pthreads not supported by GC' configure error for DragonFly and Haiku
Ivan Maidanski [Tue, 6 Mar 2018 08:02:02 +0000 (11:02 +0300)]
Fix 'pthreads not supported by GC' configure error for DragonFly and Haiku
(fix of commits 19c81d8, 847927f)

Issue #97 (bdwgc).

* configure.ac [$THREADS=pthreads && ($host=*-*-dragonfly*
|| $host=*-*-haiku*)]: Do not AC_MSG_ERROR (i.e. use the default
THREADDLLIBS).

6 years agoUpdate ChangeLog file
Ivan Maidanski [Mon, 5 Mar 2018 14:04:52 +0000 (17:04 +0300)]
Update ChangeLog file

6 years agoUpdate ChangeLog file (v7.6 changes only)
Ivan Maidanski [Mon, 5 Mar 2018 10:55:41 +0000 (13:55 +0300)]
Update ChangeLog file (v7.6 changes only)
(a cherry-pick of commit 12d1a4d3 from 'release-7_6')

6 years agoUpdate ChangeLog file (v7.2 - v7.4 changes only)
Ivan Maidanski [Sun, 4 Mar 2018 15:52:32 +0000 (18:52 +0300)]
Update ChangeLog file (v7.2 - v7.4 changes only)
(a cherry-pick of commit 08a2e0ba from 'release-7_4')

6 years agoTravis CI: Test compilation of C files by clang++
Ivan Maidanski [Fri, 2 Mar 2018 09:05:24 +0000 (12:05 +0300)]
Travis CI: Test compilation of C files by clang++

6 years agoChange backtrace-specific code to comply with C++11 standard
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.

6 years agoWorkaround missing extern 'C' for _DYNAMIC in link.h on some Linux hosts
Ivan Maidanski [Fri, 2 Mar 2018 08:28:50 +0000 (11:28 +0300)]
Workaround missing extern 'C' for _DYNAMIC in link.h on some Linux hosts

Issue #206 (bdwgc).

* dyn_load.c [DYNAMIC_LOADING && (SCO_ELF || DGUX || HURD
|| __ELF__ && (LINUX || FREEBSD || NACL || NETBSD || OPENBSD))
&& !HOST_ANDROID]: Put EXTERN_C_BEGIN/END around include link.h; add
comment.

6 years agoWrap remaining extern symbols in .c files into EXTERN_C_BEGIN/END
Ivan Maidanski [Thu, 1 Mar 2018 22:38:10 +0000 (01:38 +0300)]
Wrap remaining extern symbols in .c files into EXTERN_C_BEGIN/END

Issue #206 (bdwgc).

* dyn_load.c [SOLARISDL && !USE_PROC_FOR_LIBRARIES] (_DYNAMIC):
Move the extern symbol declaration out of a function body.
* os_dep.c [!PCR && !MACOS && REDIRECT_MALLOC && GC_SOLARIS_THREADS]
(sbrk): Likewise.
* dyn_load.c [SOLARISDL && !USE_PROC_FOR_LIBRARIES] (_DYNAMIC):
Wrap into EXTERN_C_BEGIN/END block.
* dyn_load.c [__ELF__ && LINUX && HOST_ANDROID || HAVE_DL_ITERATE_PHDR]
(dl_iterate_phdr): Likewise.
* dyn_load.c [!USE_PROC_FOR_LIBRARIES] (_DYNAMIC): Likewise.
* dyn_load.c [ALPHA && OSF1 || HPUX] (sys_errlist, sys_nerr, errno):
Likewise.
* os_dep.c [SEARCH_FOR_DATA_START && (LINUX || HURD)] (__data_start,
data_start): Likewise.
* os_dep.c [SEARCH_FOR_DATA_START && LINUX && HOST_ANDROID] (_etext,
__dso_handle): Likewise.
* os_dep.c [NETBSD && __ELF__] (environ): Likewise.
* os_dep.c [OPENBSD && THREADS] (__syscall): Likewise.
* os_dep.c [LINUX_STACKBOTTOM && USE_LIBC_PRIVATES] (__libc_stack_end):
Likewise.
* os_dep.c [LINUX_STACKBOTTOM && USE_LIBC_PRIVATES && IA64]
(__libc_ia64_register_backing_store_base): Likewise.
* os_dep.c [SYMBIAN] (GC_get_main_symbian_stack_base): Likewise.
* os_dep.c [!PCR && !MACOS && REDIRECT_MALLOC && GC_SOLARIS_THREADS]
(sbrk): Likewise.
* os_dep.c [MMAP_SUPPORTED && SYMBIAN]
(GC_get_private_path_and_zero_file): Likewise.
* pthread_stop_world.c [USE_TKILL_ON_ANDROID] (tkill): Likewise.
* pthread_stop_world.c [NACL] (nacl_interface_query): Likewise.
* pthread_support.c [PTHREAD_REGISTER_CANCEL_WEAK_STUBS]
(__pthread_register_cancel, __pthread_unregister_cancel): Likewise.
* pthread_support.c [PTHREAD_REGISTER_CANCEL_WEAK_STUBS]
(__pthread_register_cancel, __pthread_unregister_cancel): Use "void"
to denote empty arguments list.

6 years agowindows-untested: Add gc_alloc_ptrs.h source file
Ivan Maidanski [Thu, 1 Mar 2018 20:06:54 +0000 (23:06 +0300)]
windows-untested: Add gc_alloc_ptrs.h source file

6 years agoEliminate 'unused const variable' C++ warnings for [a][u]objfreelist_ptr
Ivan Maidanski [Thu, 1 Mar 2018 20:02:41 +0000 (23:02 +0300)]
Eliminate 'unused const variable' C++ warnings for [a][u]objfreelist_ptr

Issue #206 (bdwgc).

* Makefile.direct (SRCS): Add include/gc_alloc_ptrs.h.
* include/include.am (dist_noinst_HEADERS): Likewise.
* include/gc_alloc_ptrs.h: New file.
* include/new_gc_alloc.h (GC_objfreelist_ptr, GC_aobjfreelist_ptr,
GC_uobjfreelist_ptr, GC_auobjfreelist_ptr, GC_incr_bytes_allocd,
GC_incr_bytes_freed): Move to the declarations to gc_alloc_ptrs.h.
* include/new_gc_alloc.h: Include gc_alloc_ptrs.h; update comment.
* mallocx.c: Likewise.

6 years agoFix missing GC_generic_malloc_words_small implementation in new_gc_alloc.h
Ivan Maidanski [Thu, 1 Mar 2018 19:47:22 +0000 (22:47 +0300)]
Fix missing GC_generic_malloc_words_small implementation in new_gc_alloc.h

* include/new_gc_alloc.h (GC_generic_malloc_words_small): Replace
prototype with a macro (that uses GC_generic_malloc); remove FIXME item.

6 years agoFix missing explicit cast of si_addr to char* in write_fault_handler
Ivan Maidanski [Thu, 1 Mar 2018 08:58:48 +0000 (11:58 +0300)]
Fix missing explicit cast of si_addr to char* in write_fault_handler

Issue #206 (bdwgc).

* os_dep.c [!DARWIN && !MSWIN32 && !MSWINCE] (GC_write_fault_handler):
Cast si->si_addr to char* when assigned to addr local variable.