Ivan Maidanski [Tue, 26 Feb 2019 22:32:53 +0000 (01:32 +0300)]
Avoid potential race in hb_sz access between realloc and reclaim_block
Issue #240 (bdwgc).
GC_realloc might be changing the block size while GC_reclaim_block
is examining it. The change to the size field is benign, i.e.
GC_reclaim would work correctly with either value, since we are not
changing the number of objects in the block. But seeing a half-updated
value (though unlikely to occur in practice) could be probably bad.
Using unordered atomic fetch of hb_sz field should solve the issue.
* reclaim.c (GC_block_nearly_full, GC_reclaim_small_nonempty_block):
Add sz argument; use sz instead of hhdr->hb_sz.
* reclaim.c (GC_reclaim_clear, GC_reclaim_uninit, GC_reclaim_check):
Skip the assertion about hhdr->hb_sz if THREADS.
* reclaim.c [ENABLE_DISCLAIM] (GC_disclaim_and_reclaim): Likewise.
* reclaim.c [AO_HAVE_load] (GC_reclaim_block): Use AO_load to access
hhdr->hb_sz; add comments.
* reclaim.c (GC_reclaim_block): Pass sz to
GC_reclaim_small_nonempty_block() and GC_block_nearly_full().
* reclaim.c (GC_continue_reclaim, GC_reclaim_all): Pass hhdr->hb_sz to
GC_reclaim_small_nonempty_block().
* reclaim.c [!EAGER_SWEEP && ENABLE_DISCLAIM]
(GC_reclaim_unconditionally_marked): Likewise.
Ivan Maidanski [Tue, 26 Feb 2019 21:48:12 +0000 (00:48 +0300)]
Fix 'duplicate symbol' error for tests using multiple static libs (OS X)
Issue #263 (bdwgc).
If configured with --enable-static, libtool passes libgc.a to gcc
twice (with a relative path and with an absolute one) when linking
tests that depend on libcord.a, libgccpp.a or libstaticrootslib_test.a
which, in turn, depends on libgc.a. Double specification of libgc.a
seems to confuse ld tool of MacOS 10.14.
The workaround is to omit libgc.la in *_LDADD specification of the
mentioned tests when the shared libraries are not requested, at least.
* configure.ac (ENABLE_SHARED): New AM_CONDITIONAL.
* cord/cord.am (cordtest_LDADD): Do not add libgc.la unless
ENABLE_SHARED; add comment.
* tests/tests.am (staticrootstest_LDADD): Likewise.
* tests/tests.am [CPLUSPLUS && !AVOID_CPP_LIB] (test_cpp_LDADD):
Likewise.
Ivan Maidanski [Fri, 15 Feb 2019 20:40:49 +0000 (23:40 +0300)]
Avoid unexpected heap growth in gctest caused by GC_disable
(fix of commit 8fc1ebf6d)
Issue #264 (bdwgc).
This commit eliminates the scenario when one thread disables garbage
collections while other threads intensively allocate memory objects.
* tests/test.c (run_one_test): Do not call GC_disable and GC_enable.
* tests/test.c (run_single_threaded_test): New function (which tests
GC_disable and GC_enable).
* tests/test.c (main): Call run_single_threaded_test() (before
check_heap_stats).
Ivan Maidanski [Thu, 14 Feb 2019 19:55:20 +0000 (22:55 +0300)]
Fix thread_info() count argument value (OS X)
* darwin_stop_world.c [DEBUG_THREADS || GC_ASSERTIONS]
(GC_thread_resume): Set outCount to THREAD_BASIC_INFO_COUNT (instead
of THREAD_INFO_MAX) to match the size of info passed to thread_info().
Ivan Maidanski [Wed, 13 Feb 2019 14:41:51 +0000 (17:41 +0300)]
Adjust printf calls in gctest check_heap_stats so that each has new-line
This is useful if GC_printf uses Android logging.
* tests/test.c (finalizable_count): Do not define if
GC_NO_FINALIZATION.
* tests/test.c (mktree): Do not increment finalizable_count if
GC_NO_FINALIZATION.
* tests/test.c (check_heap_stats): Do not print finalization counts
if GC_NO_FINALIZATION or GC_get_find_leak() is true; call GC_printf
to output finalization counts and the check result just once (i.e.
the whole line is printed in a single GC_printf call).
* tests/test.c [!NO_CLOCK] (check_heap_stats): Call GC_printf just
once to output "Completed <N> collections" together with the total
GC time value and the number of marker threads (i.e. the whole line
is printed in a single GC_printf call).
Hamayama [Thu, 7 Feb 2019 21:51:25 +0000 (00:51 +0300)]
Fix GetThreadContext stale register values use if WoW64 (Win32)
Issue #262 (bdwgc).
* misc.c [MSWIN32 && !MSWINRT_FLAVOR && !MSWIN_XBOX1]
(GC_win32_MessageBoxA): Do not define unless SMALL_CONFIG.
* misc.c [MSWIN32 && !_WIN64 && GC_WIN32_THREADS && CHECK_NOT_WOW64]
(GC_init): Do not call IsWow64Process() and GC_win32_MessageBoxA().
* win32_threads.c [I386] (isWow64): New static variable.
* win32_threads.c [I386] (GC_push_stack_for): If isWow64 then set also
CONTEXT_EXCEPTION_REQUEST and CONTEXT_SEGMENTS bits in ContextFlags;
if isWow64, and CONTEXT_EXCEPTION_REPORTING and
CONTEXT_EXCEPTION_ACTIVE are set on return from GetThreadContext then
call GetThreadSelectorEntry and use StackLimit of FS selector to set
sp local variable (instead of context.Esp); add comment.
* win32_threads.c [I386 && DEBUG_THREADS] (GC_push_stack_for): Call
GC_log_printf() to report TIB stack limit/base and the case when
CONTEXT_EXCEPTION_REQUEST is not supported.
* win32_threads.c [I386] (GC_thr_init): Set isWow64 by IsWow64Process()
if the later is available.
Ivan Maidanski [Mon, 21 Jan 2019 22:01:45 +0000 (01:01 +0300)]
Fix 'unexpected mark stack overflow' abort in push_all_stack
Issue #260 (bdwgc).
* mark.c [!NEED_FIXUP_POINTER] (GC_push_all_stack): Call
GC_push_all_eager() instead of GC_push_all() if GC_mark_stack_top is
rather close to GC_mark_stack_limit.
Ivan Maidanski [Fri, 4 Jan 2019 16:37:50 +0000 (19:37 +0300)]
Fix BSD_TIME variant of MS_TIME_DIFF for the case of a.tv_usec < b.tv_usec
(fix of commit 6b2796b69)
* include/private/gc_priv.h [!NO_CLOCK && BSD_TIME] (MS_TIME_DIFF):
Cast the result of a.tv_usec-b.tv_usec to long (so that the result of
the division should be negative if a.tv_usec is less than b.tv_usec).
Ivan Maidanski [Sat, 5 Jan 2019 08:52:53 +0000 (11:52 +0300)]
Fix invalid initializer of CLOCK_TYPE variables if BSD_TIME
(fix of commits 7e59301c1, 06ecaefca)
* alloc.c [!NO_CLOCK] (GC_start_time): Initialize to
CLOCK_TYPE_INITIALIZER (instead of 0).
* alloc.c [!NO_CLOCK] (GC_try_to_collect_inner, GC_stopped_mark,
GC_finish_collection): Initialize local variable of CLOCK_TYPE type to
CLOCK_TYPE_INITIALIZER (instead of 0); remove comment (duplicating that
in gc_priv.h).
* reclaim.c [!NO_CLOCK] (GC_reclaim_all): Likewise.
* include/private/gc_priv.h [!NO_CLOCK] (CLOCK_TYPE_INITIALIZER):
Define macro.
Ivan Maidanski [Sat, 29 Dec 2018 07:12:44 +0000 (10:12 +0300)]
Workaround 'me assigned value never used' cppcheck FP in register_my_thread
* pthread_support.c [CPPCHECK] (GC_register_my_thread): Call
GC_noop1(me->flags) after reassigning me to the result of
GC_register_my_thread_inner(sb,self).
* win32_threads.c [CPPCHECK] (GC_register_my_thread): Likewise.
Ivan Maidanski [Fri, 28 Dec 2018 21:50:34 +0000 (00:50 +0300)]
Travis CI: Workaround timeout of 'cppcheck --enable=unusedFunction --force'
"cppcheck --enable=unusedFunction --force extra/gc.c" takes longer than
the Travis CI timeout (50m), so gc.c is checked for unused functions
without --force option for now.
Ivan Maidanski [Sun, 23 Dec 2018 17:20:56 +0000 (20:20 +0300)]
Update libgc.so version info to differentiate against v8.0.x
There are no API/implementation changes in libcord and libgccpp against
release-8_0 for now, so the corresponding version info is not updated.
There are some implementation changes and new API functions addition in
libgc (without API incompatible changes) against release-8_0, so the
"current" and "age" parts of the version info are incremented.
* Makefile.am (LIBGC_VER_INFO): Change version info to 6:0:5.
Ivan Maidanski [Thu, 20 Dec 2018 08:34:12 +0000 (11:34 +0300)]
Allow to force executable pages allocation in gctest
Pass -D TEST_PAGES_EXECUTABLE to CFLAGS to enable the executable pages
allocation in gctest even if the collector is compiled with
NO_EXECUTE_PERMISSION.
Ivan Maidanski [Wed, 19 Dec 2018 19:50:57 +0000 (22:50 +0300)]
Eliminate 'stop variable is always 0' compiler warning in print_callers
* os_dep.c [NEED_CALLINFO] (GC_print_callers): Declare (and use value
of) stop local variable only if LINUX && !SMALL_CONFIG; move stop local
variable to the scope of its use.
Ivan Maidanski [Wed, 19 Dec 2018 19:11:42 +0000 (22:11 +0300)]
Eliminate 'hash_val value is never used' cppcheck false positive
* specific.c [USE_CUSTOM_SPECIFIC] (GC_setspecific): Change type of
hash_val local variable from int to unsigned.
* specific.c [USE_CUSTOM_SPECIFIC] (GC_slow_getspecific): Remove
hash_val local variable.
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).