Ivan Maidanski [Fri, 23 Nov 2018 06:23:02 +0000 (09:23 +0300)]
Fix mutex_trylock failure in disclaim_weakmap_test in leak detection mode
* tests/disclaim_weakmap_test.c (weakmap.links): Add comment.
* tests/disclaim_weakmap_test.c (weakmap_disclaim): If wm->links is
null then return 0 (do not use wm).
* tests/disclaim_weakmap_test.c (weakmap_destroy): Set links to null.
Ivan Maidanski [Thu, 22 Nov 2018 23:22:41 +0000 (02:22 +0300)]
Fix 'collecting from unknown thread' abort in leak-finding mode for Win32
(fix of commit 8e6460052)
* include/private/gc_priv.h [THREADS] (GC_in_thread_creation): Declare
not only for pthreads.
* misc.c [!DONT_USE_ATEXIT && THREADS] (GC_exit_check): Set
GC_in_thread_creation to true before calling GC_gcollect for windows
threads as well.
* win32_threads.c (GC_in_thread_creation): Change STATIC to GC_INNER.
Ivan Maidanski [Thu, 22 Nov 2018 11:34:03 +0000 (14:34 +0300)]
Workaround 'nonlocal var will use ptr to local var' cppcheck false positive
* extra/msvc_dbg.c (sym_namebuf_u): New union type.
* extra/msvc_dbg.c (GetSymbolNameFromAddress): Use sym_namebuf_u
instead of anonymous union.
* os_dep.c [MPROTECT_VDB && DARWIN] (mp_reply_s, mp_msg_s): Move struct
type definition out of GC_mprotect_thread (adding mp_ prefix).
Ivan Maidanski [Wed, 21 Nov 2018 21:32:50 +0000 (00:32 +0300)]
Fix test_cpp assertion violation in find-leak mode
* tests/test_cpp.cc (C.Test, D.Test, F.Test): Do not fail on
nFreed>=0.8*nAllocated[F] assertion violation if GC_get_find_leak() returns
non-zero; replace .8*nAllocated[F] to (nAllocated[F]/5)*4 to avoid
floating-point operations.
Ivan Maidanski [Wed, 21 Nov 2018 09:16:01 +0000 (12:16 +0300)]
Turn off parallel marker, thread-local allocation if used AO ops emulated
* configure.ac (use_parallel_mark, use_thread_local_alloc): New
variable (set to enable_parallel_mark and enable_thread_local_alloc,
respectively, if threads are enabled).
* configure.ac (PARALLEL_MARK, THREAD_LOCAL_ALLOC): Group and move
AC_DEFINE down (the definition depends on the final value of
use_parallel_mark or use_thread_local_alloc, respectively).
* configure.ac (THREAD_LOCAL_ALLOC): Move AM_CONDITIONAL down to use
the final value of use_thread_local_alloc; do not check THREADS.
* configure.ac (handle-fork): Move AC_ARG_ENABLE and its processing
down to use the final value of use_parallel_mark (the latter is used
instead of enable_parallel_mark).
* configure.ac [$with_libatomic_ops!=none && $need_atomic_ops_asm!=true]
(use_thread_local_alloc): Set explicitly to "no" if
BASE_ATOMIC_OPS_EMULATED is defined.
* configure.ac [$with_libatomic_ops!=none && $need_atomic_ops_asm!=true
&& $use_parallel_mark!=no] (use_parallel_mark): Set explicitly to "no"
in case of a failure of AC_TRY_LINK of a code snippet calling
AO_fetch_and_add and AO_compare_and_swap (provided AO_REQUIRE_CAS is
defined).
* include/private/gc_pmark.h [USE_MARK_BYTES && PARALLEL_MARK
&& AO_HAVE_char_store] (SET_MARK_BIT_EXIT_IF_SET): Do not use
AO_char_load() and AO_char_store() if BASE_ATOMIC_OPS_EMULATED.
Ivan Maidanski [Tue, 20 Nov 2018 21:19:20 +0000 (00:19 +0300)]
Fix a deadlock in write_fault_handler if AO_or is emulated
* configure.ac [$with_libatomic_ops!=none && $need_atomic_ops_asm!=true]
(HAVE_LOCKFREE_AO_OR): New AC_DEFINE (defined in case of success of
AC_TRY_LINK of a code snippet calling AO_or).
* include/private/gc_atomic_ops.h [GC_BUILTIN_ATOMIC
&& !NO_LOCKFREE_AO_OR] (HAVE_LOCKFREE_AO_OR): Define (to 1).
* include/private/gc_priv.h [THREADS] (GC_acquire_dirty_lock,
GC_release_dirty_lock): Define to no-op only if HAVE_LOCKFREE_AO_OR
or GC_DISABLE_INCREMENTAL.
* os_dep.c [!GC_DISABLE_INCREMENTAL] (async_set_pht_entry_from_index):
Use set_pht_entry_from_index_concurrent() only if HAVE_LOCKFREE_AO_OR
(or not THREADS).
Ivan Maidanski [Tue, 20 Nov 2018 20:44:08 +0000 (23:44 +0300)]
Do not use spin locks if AO test-and-set is emulated (pthreads)
* include/private/gc_locks.h [BASE_ATOMIC_OPS_EMULATED && GC_PTHREADS]
(USE_PTHREAD_LOCKS): Define.
* include/private/gc_locks.h [BASE_ATOMIC_OPS_EMULATED && GC_PTHREADS]
(USE_SPIN_LOCK): Undefine.
* pthread_support.c [(USE_SPIN_LOCK || !NO_PTHREAD_TRYLOCK)
&& AO_CLEAR] (GC_pause): Do not use AO_compiler_barrier() if
BASE_ATOMIC_OPS_EMULATED.
* pthread_support.c [AO_HAVE_char_load] (is_collecting): Do not use
AO_char_load() if BASE_ATOMIC_OPS_EMULATED.
Ivan Maidanski [Tue, 20 Nov 2018 08:42:52 +0000 (11:42 +0300)]
Fix deadlocks in write and suspend handlers if AO test-and-set is emulated
This could be tested with -D AO_USE_PTHREAD_DEFS passed to CFLAGS.
* configure.ac (AO_TRYLINK_CFLAGS): New variable.
* configure.ac [$with_libatomic_ops!=none && $need_atomic_ops_asm!=true]
(BASE_ATOMIC_OPS_EMULATED): New AC_DEFINE (defined in case of failure
of AC_TRY_LINK of a code snippet calling AO_test_and_set_acquire,
AO_CLEAR, AO_compiler_barrier, AO_store, AO_load, AO_char_store,
AO_char_load, AO_store_release, AO_load_acquire); use AO_TRYLINK_CFLAGS;
add comment.
* include/private/gcconfig.h [BASE_ATOMIC_OPS_EMULATED] (MPROTECT_VDB):
Undefine.
* mark.c [AO_CLEAR] (GC_noop6): Do not call AO_compiler_barrier() if
BASE_ATOMIC_OPS_EMULATED.
* misc.c [!GC_DISABLE_INCREMENTAL] (GC_init, GC_enable_incremental):
Do not set GC_manual_vdb if BASE_ATOMIC_OPS_EMULATED.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(ao_load_acquire_async, ao_load_async, ao_store_release_async,
ao_store_async): New macro; undefine it after the usage.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_store_stack_ptr): Use ao_store_async() instead of AO_store().
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]
(GC_suspend_handler_inner): Use ao_load[_acquire]_async() and
ao_store_release_async() instead of AO_load[_acquire]() and
AO_store_release(), respectively.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL
&& GC_ENABLE_SUSPEND_THREAD] (suspend_self_inner): Use
ao_load_acquire_async() instead of AO_load_acquire().
Fix linkage with a system libatomic_ops shared library
Issue #247 (bdwgc).
When bdwgc is linked with the external libatomic_ops, bdw-gc.pc must
contain the needed dynamic libraries (such as -latomic_ops) otherwise
build of applications could fail on the link stage on some hosts:
* libgc.so: undefined reference to 'AO_fetch_compare_and_swap_emulation'
* libgc.so: undefined reference to 'AO_store_full_emulation'
So, this commit sets ATOMIC_OPS_LIBS to "-latomic_ops" when a system
atomic_ops library is used and uses ATOMIC_OPS_LIBS in bdw-gc.pc.in.
* bdw-gc.pc.in (Libs): Add @ATOMIC_OPS_LIBS@.
* configure.ac [$with_libatomic_ops!=no && $with_libatomic_ops!=none
&& $THREADS!=none] (ATOMIC_OPS_LIBS): Set to -latomic_ops; do AC_SUBST.
Ivan Maidanski [Wed, 14 Nov 2018 07:49:27 +0000 (10:49 +0300)]
Use standalone private macro to guard against ptr_t redefinition
(code refactoring)
* include/private/gc_priv.h (ptr_t): Define only if PTR_T_DEFINED is
not defined (previously).
* include/private/gcconfig.h (ptr_t): Likewise.
* include/private/gc_priv.h (PTR_T_DEFINED): Define macro.
* include/private/gcconfig.h (PTR_T_DEFINED): Likewise.
* include/private/gcconfig.h (ptr_t): Change type to char*; remove
void comments.
* include/private/gcconfig.h: Include stddef.h only if sony_news is
not defined (like in gc_priv.h).
Ivan Maidanski [Tue, 13 Nov 2018 22:24:13 +0000 (01:24 +0300)]
Remove redundant header double-inclusion checks in the private headers
(code refactoring)
* include/private/gc_pmark.h [HAVE_CONFIG_H]: Include config.h
regardless of GC_PRIVATE_H.
* include/private/gc_pmark.h: Include gc_mark.h regardless of GC_MARK_H;
include gc_priv.h regardless of GC_PRIVATE_H.
* include/private/gc_priv.h: Include gc_tiny_fl.h regardless of
GC_TINY_FL_H; include gc_mark.h regardless of GC_MARK_H; include
gcconfig.h regardless of GCCONFIG_H; include gc_locks.h regardless
of GC_LOCKS_H.
Ivan Maidanski [Mon, 12 Nov 2018 07:30:18 +0000 (10:30 +0300)]
Eliminate 'casting signed to bigger unsigned int' CSA warning
* cord/cordprnt.c (CORD_vsprintf): Cast prec, width, max_size, res
local variables to unsigned.
* cord/tests/cordtest.c (test_basics): Change type of i local variable
from int to size_t; cast c local variable to unsigned char.
* dbg_mlc.c (GC_store_debug_info_inner): Do not cast linenum parameter.
* include/private/dbg_mlc.h (oh.oh_string, oh.oh_int): Refine comment.
* include/private/dbg_mlc.h (oh.oh_int): Change type from word to
signed_word.
* misc.c [!GC_GET_HEAP_USAGE_NOT_NEEDED] (fill_prof_stats): Cast
GC_markers_m1 to signed_word first.
* misc.c (GC_init): Cast space_divisor local variable to unsigned
(instead of word).
* misc.c [!MSWIN32 && !MSWINCE && !OS2 && !MACOS && !GC_ANDROID_LOG]
(GC_write): Cast bytes_written local variable to unsigned (instead of
size_t).
Ivan Maidanski [Fri, 9 Nov 2018 17:08:20 +0000 (20:08 +0300)]
Eliminate 'uninitialized var' cppcheck false positive in mach_dep, os_dep
* mach_dep.c (GC_with_callee_saves_pushed): Change type of "context"
local variable from void* volatile to volatile ptr_t.
* os_dep.c [(SVR4 || AIX || DGUX || (LINUX && SPARC)) && !PCR]
(GC_SysVGetDataStart): Change type of "result" local variable from
char* volatile to volatile ptr_t.
Ivan Maidanski [Thu, 8 Nov 2018 22:05:51 +0000 (01:05 +0300)]
Eliminate redundant check in backwards_height
This eliminates 'the condition pred!=NULL is redundant' cppcheck warning.
* backgraph.c [MAKE_BACK_GRAPH] (backwards_height): Remove duplicate
pred!=NULL check (the case of NULL is already handled by
"if(NULL==pred)return 1" statement).
Ivan Maidanski [Thu, 8 Nov 2018 21:45:14 +0000 (00:45 +0300)]
Reduce scope of local variables in GC_remove_all_threads_but_me
This eliminates 'the scope of the variable can be reduced' cppcheck
warning in GC_remove_all_threads_but_me.
* pthread_support.c [CAN_HANDLE_FORK] (GC_remove_all_threads_but_me):
Move p, next, me local variables to an inner scope there they are used.
* win32_threads.c [CAN_HANDLE_FORK] (GC_remove_all_threads_but_me):
Move p, next local variables to an inner scope.
Ivan Maidanski [Wed, 7 Nov 2018 19:47:02 +0000 (22:47 +0300)]
Eliminate 'unreferenced formal parameter' compiler warning in msvc_dbg
* extra/msvc_dbg.c (GetDescriptionFromAddress): Cast format argument
to void.
* extra/msvc_dbg.c (GetDescriptionFromStack): Pass format argument to
GetDescriptionFromAddress (instead of NULL).
Ivan Maidanski [Wed, 7 Nov 2018 07:15:31 +0000 (10:15 +0300)]
Workaround 'pointer addition with NULL pointer' cppcheck error in msvc_dbg
* extra/msvc_dbg.c (GetDescriptionFromStack): Change type of begin,
end, buffer local variables from char* to GC_ULONG_PTR; do not update
size local variable value; do not store elements to description[]
if description is NULL (instead of checking of size is non-zero).
Fix marks and hb_n_marks consistency when disclaim returns true
* reclaim.c [ENABLE_DISCLAIM] (GC_disclaim_and_reclaim): When a
disclaim callback returns 1 to protect an object from being reclaimed,
mark it to skip it on repeated scans within the cycle. In particular,
this fixes sz*hhdr->hb_n_marks<=HBLKSIZE assertion failure due to
excessive increments of hb_n_marks.
Ivan Maidanski [Tue, 30 Oct 2018 07:38:56 +0000 (10:38 +0300)]
Fix data race in disclaim_weakmap_test statistic counters update
(fix of commit 6eba4218a)
Issue #239 (bdwgc).
The stat_* variables need to be atomically updated, since the locking
of the map is granular (cf WEAKMAP_MUTEX_COUNT) to allow parallelism
between different key hashes.
* tests/disclaim_weakmap_test.c [!AO_CLEAR] (AO_t): Define.
* tests/disclaim_weakmap_test.c [!AO_HAVE_fetch_and_add1]
(AO_fetch_and_add1): Define.
* tests/disclaim_weakmap_test.c (stat_added, stat_found, stat_removed,
stat_skip_marked, stat_skip_locked): Change type back from unsigned to
volatile AO_t.
* tests/disclaim_weakmap_test.c (weakmap_add, weakmap_disclaim):
Update stat_* counters using AO_fetch_and_add1(); move counters update
outside weakmap_lock/unlock block.
* tests/disclaim_weakmap_test.c (main): Cast stat_* counters to
unsigned type in printf() call.
Michael DeRoy [Mon, 29 Oct 2018 04:45:59 +0000 (07:45 +0300)]
Enable compilation without C runtime (Win32)
(part of commit 193af77 from Unity-Technologies/bdwgc)
* include/private/gcconfig.h [MSWIN32 && !__GNUC__
&& !NO_WRAP_MARK_SOME] (WRAP_MARK_SOME): Do not define if NO_CRT.
* mach_dep.c [!HAVE_BUILTIN_UNWIND_INIT && NO_CRT && MSWIN32]
(GC_with_callee_saves_pushed): Call RtlCaptureContext() instead of
setjmp().
* misc.c [MSWIN32 && _MSC_VER && _DEBUG] (GC_write): Do not call
MultiByteToWideChar() and OutputDebugStringW() if NO_CRT.
* win32_threads.c [NO_CRT] (GC_NO_THREADS_DISCOVERY): Define.
* win32_threads.c [!__GNUC__] (GC_win32_start_inner): Do not use __try
and __finally if NO_CRT.
* win32_threads.c [!CYGWIN32 && !MSWINCE && !MSWIN_XBOX1]
(GC_beginthreadex): Do not define if NO_CRT.
Ivan Maidanski [Tue, 23 Oct 2018 22:50:14 +0000 (01:50 +0300)]
Add I_HOLD_LOCK assertion to expand_hp_inner and related functions
(code refactoring)
* alloc.c (GC_expand_hp_inner, GC_collect_or_expand): Add
GC_ASSERT(I_HOLD_LOCK()) at the beginning of the function.
* obj_map.c (GC_register_displacement_inner): Likewise.
Ivan Maidanski [Mon, 15 Oct 2018 20:54:57 +0000 (23:54 +0300)]
New API function to get size of object debug header
GC_get_debug_header_size() is exported in addition to
GC_debug_header_size variable. The usage of the latter is deprecated.
* dbg_mlc.c [CPPCHECK] (GC_start_debugging_inner): Call
GC_noop1(GC_debug_header_size) to suppress a cppcheck warning about
unused symbol.
* dbg_mlc.c (GC_debug_header_size): Add const.
* dbg_mlc.c (GC_get_debug_header_size): New API function definition.
* include/gc_config_macros.h (GC_ATTR_CONST): New macro.
* include/gc_mark.h (GC_debug_header_size): Add GC_ATTR_DEPRECATED and
const; update comment.
* include/gc_mark.h (GC_get_debug_header_size): New API public const
function declaration; move the comment from GC_debug_header_size.
* include/gc_mark.h (GC_USR_PTR_FROM_BASE): Use
GC_get_debug_header_size() instead of GC_debug_header_size.
Ivan Maidanski [Tue, 9 Oct 2018 07:59:39 +0000 (10:59 +0300)]
Eliminate 'pointer targets differ in signedness' compiler warning (Win32)
(fix of commit b66a887d7)
* win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_Thread_Rep.tm): Add
long_in_use field to union; add comment.
* win32_threads.c [!GC_NO_THREADS_DISCOVERY]
(GC_register_my_thread_inner): Pass pointer to long_in_use field
instead of a pointer to in_use one casted to word*; remove outdated
comment.
Ivan Maidanski [Wed, 3 Oct 2018 07:08:17 +0000 (10:08 +0300)]
Remove extra USE_MMAP definition for Interix
(code refactoring)
* include/private/gcconfig.h [I386 && INTERIX && !USE_MMAP] (USE_MMAP):
Remove macro definition (because in gc v8.0.0+ it is defined later in this
file).
Ivan Maidanski [Wed, 26 Sep 2018 22:38:02 +0000 (01:38 +0300)]
Prevent a deadlock in suspend_thread and after process forking
(fix of commit 0c0e4cd)
Issue #235 (bdwgc).
* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD] (GC_suspend_thread):
Remove unneeded comment for AO_store_release() call; invoke
GC_acquire_dirty_lock() and GC_release_dirty_lock() only if
GC_manual_vdb; add comment for GC_acquire_dirty_lock() call.
* pthread_stop_world.c [NACL] (GC_suspend_all): If GC_manual_vdb then
call GC_acquire_dirty_lock() and GC_release_dirty_lock() around the
code which ensures parking of threads.
* pthread_support.c [CAN_HANDLE_FORK] (fork_prepare_proc): Call
GC_acquire_dirty_lock().
* pthread_support.c [CAN_HANDLE_FORK] (fork_parent_proc,
fork_child_proc): Call GC_release_dirty_lock().
Ivan Maidanski [Wed, 26 Sep 2018 07:12:06 +0000 (10:12 +0300)]
Use AO_or in async_set_pht_entry_from_index if available
* blacklst.c (backlist_set_pht_entry_from_index): New macro; move
comment from gc_priv.h.
* blacklst.c (GC_add_to_black_list_normal, GC_add_to_black_list_stack):
Use backlist_set_pht_entry_from_index() instead of
set_pht_entry_from_index_concurrent().
* include/private/gc_priv.h (set_pht_entry_from_index): Add outermost
parentheses; cast result to void.
* include/private/gc_priv.h [THREADS]
(set_pht_entry_from_index_concurrent): Define only if AO_HAVE_or;
update comment.
* include/private/gc_priv.h [THREADS] (GC_acquire_dirty_lock,
GC_release_dirty_lock): Define to no-op if
set_pht_entry_from_index_concurrent is defined.
* include/private/gc_priv.h [THREADS
&& set_pht_entry_from_index_concurrent] (GC_fault_handler_lock): Do not
declare.
* os_dep.c [!GC_DISABLE_INCREMENTAL && THREADS
&& set_pht_entry_from_index_concurrent]
(async_set_pht_entry_from_index): Redirect to
set_pht_entry_from_index_concurrent; do not define
GC_fault_handler_lock variable.
* os_dep.c [!GC_DISABLE_INCREMENTAL && THREADS
&& !set_pht_entry_from_index_concurrent && AO_HAVE_test_and_set_acquire]
(async_set_pht_entry_from_index): Remove GC_ATTR_NO_SANITIZE_THREAD
(because AO_HAVE_or should be defined in case of TSan).
Ivan Maidanski [Sat, 22 Sep 2018 12:55:45 +0000 (15:55 +0300)]
Refine documentation in gc_disclaim.h about closure object protection
(fix of commit 8ce6ef6)
* include/gc_disclaim.h (GC_register_disclaim_proc,
GC_finalized_malloc): Refine comment about the protection of the
finalizer closure object from collection.
* include/gc_config_macros.h [!GC_THREADS] (GC_THREADS): Do not check
SN_TARGET_ORBIS and SN_TARGET_PSP2 macros.
* include/private/gcconfig.h [X86_64 && SN_TARGET_ORBIS]: Do not
include pthread.h (should be included from gc_locks.h).
* include/private/gcconfig.h [NN_PLATFORM_CTR || NINTENDO_SWITCH
|| SN_TARGET_ORBIS || SN_TARGET_PS3 || SN_TARGET_PSP2] (THREADS):
Define only if GC_THREADS is defined.
Ivan Maidanski [Wed, 19 Sep 2018 06:57:51 +0000 (09:57 +0300)]
Test marking of finalizer closure object in disclaim_test
* tests/disclaim_test.c (PTR_HASH): New macro.
* tests/disclaim_test.c (pair_dct): Change assertion condition about cd
(it should be equal to the hash value of p).
* tests/disclaim_test.c (pair_new): Replace static fc variable to local
pfc one which is assigned a pointer to atomic object; set pfc->cd to
the hash value of p.
Ivan Maidanski [Mon, 17 Sep 2018 06:49:56 +0000 (09:49 +0300)]
Fix unneeded end_stubborn_change/ptr_store_and_dirty in disclaim_test
(fix of commits b52c140, 263ffbb)
* tests/disclaim_test.c (pair_dct): Add my_assert that cd is null;
store null to p->car (instead of storing cd and calling
GC_end_stubborn_change/GC_reachable_here).
Ivan Maidanski [Thu, 13 Sep 2018 06:31:11 +0000 (09:31 +0300)]
Specify register_disclaim_proc and finalized_malloc argument as non-null
Also, a check is added that the actual finalizer closure pointer does
not have FINALIZER_CLOSURE_FLAG set.
* fnlz_mlc.c (GC_register_disclaim_proc): Add assertion that proc is
non-null.
* fnlz_mlc.c (GC_finalized_malloc): Add assertions that fclos argument
is non-null and that fclos itself does not have FINALIZER_CLOSURE_FLAG
set.
* include/gc_disclaim.h (GC_register_disclaim_proc,
GC_finalized_malloc): Add GC_ATTR_NONNULL for the pointer argument.
Ivan Maidanski [Fri, 7 Sep 2018 18:21:01 +0000 (21:21 +0300)]
Fix GC_VSNPRINTF in cordprnt for DJGPP and MS VC for WinCE
(fix of commit c10a1d900)
GC-internal DJGPP and MSWINCE macros are not available in cord.
* cord/cordprnt.c (GC_VSNPRINTF): Test __DJGPP__ instead of DJGPP macro.
* cord/cordprnt.c [_MSC_VER] (GC_VSNPRINTF): Test _WIN32_WCE instead
of MSWINCE macro.