Ivan Maidanski [Thu, 6 Dec 2018 08:41:33 +0000 (11:41 +0300)]
Remove goto statement in print_callers
(code refactoring)
* os_dep.c [NEED_CALLINFO && LINUX && !SMALL_CONFIG] (GC_print_callers):
Replace "goto out" to "break" statement in a do-while(0) block; remove
"out" label; move ret_code local variable declaration to the scope of
its usage; close pipe immediately after fread().
Ivan Maidanski [Thu, 6 Dec 2018 08:23:52 +0000 (11:23 +0300)]
Eliminate 'assigned value never used' compiler warning in test_cpp WinMain
* tests/test_cpp.cc [(MSWIN32 && !__MINGW32__ || MSWINCE)
&& !NO_WINMAIN_ENTRY] (WinMain): Remove first argv[argc]=cmd (when cmd
points to a space or tab character).
Ivan Maidanski [Thu, 29 Nov 2018 08:46:48 +0000 (11:46 +0300)]
Fix GC_register_disclaim_proc for leak-finding mode
Issue #252 (bdwgc).
This makes the behavior of GC_register_disclaim_proc() and
GC_finalized_malloc() somewhat consistent with
GC_register_disappearing_link() and GC_register_finalizer() when
find-leak is on. The documentation is updated accordingly.
* fnlz_mlc.c [ENABLE_DISCLAIM] (GC_finalized_disclaim): Add assertion
that GC_find_leak is off.
* fnlz_mlc.c [ENABLE_DISCLAIM] (GC_register_disclaim_proc): Do not
assign ok_disclaim_proc, ok_mark_unconditionally fields if GC_find_leak.
* include/gc_disclaim.h (GC_register_disclaim_proc,
GC_finalized_malloc): Refine comment about leak-find mode and GC_free
invocation.
Ivan Maidanski [Wed, 28 Nov 2018 22:05:26 +0000 (01:05 +0300)]
Workaround 'var reassigned before old value use' cppcheck false positive
* extra/AmigaOS.c [!GC_AMIGA_ONLYFAST && CPPCHECK]
(GC_amiga_allocwrapper_any): Add a dummy read of GC_amiga_dontalloc
global variable; add comment.
* pthread_support.c [CPPCHECK] (GC_do_blocking_inner): Add a dummy read
of thread_blocked field of GC_thread.
* pthread_support.c [CPPCHECK] (GC_call_with_gc_active): Add a dummy
read of traced_stack_sect field of GC_thread.
Ivan Maidanski [Wed, 28 Nov 2018 09:09:59 +0000 (12:09 +0300)]
Travis CI: Pass extra/gc.c to cppcheck --enable=unusedFunction
This fixes a dozen of 'the function is never used' cppcheck style
warnings (for GC_core_gcj_malloc, GC_durango_get_mem,
GC_FreeBSDGetDataStart, GC_haiku_get_mem, GC_mprotect_resume,
GC_mprotect_stop, GC_remove_roots_subregion, GC_win32_get_mem,
GC_wince_get_mem).
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.