Ivan Maidanski [Mon, 29 Apr 2019 06:44:42 +0000 (09:44 +0300)]
Fix first_thread stack_base initialzation if custom GC_stackbottom (Win32)
Stack bottom value of the primordial thread should be obtained from
GC_stackbottom.
* win32_threads.c [GC_ASSERTIONS] (GC_thr_init): Remove sb_result local
variable.
* win32_threads.c (GC_thr_init): Initalize sb mem_base and reg_base
fields with GC_stackbottom and GC_register_stackbottom, respectively;
do not call GC_get_stack_base().
Ivan Maidanski [Fri, 26 Apr 2019 16:03:42 +0000 (19:03 +0300)]
Replace 'stack base' with 'stack bottom' in the documentation
* README.md (The C Interface to the Allocator): Outline that stack base
means its bottom; remove a note that client should set GC_stackbottom
on HP PA machines manually.
* doc/README.macros (USE_GET_STACKBASE_FOR_MAIN): Rename "stack base"
to "stack bottom".
* doc/porting.md (Adding Platforms to gcconfig.h): Likewise.
* doc/porting.md (Adding Platforms to gcconfig.h): Rename
"cool end of the stack" to "cold end of the stack"; refine
documentation about STACKBOTTOM.
* include/private/gcconfig.h (STACKBOTTOM): Rename "cool end" to
"cold end" in comment.
* include/gc.h (GC_stackbottom): Likewise.
* include/private/gcconfig.h (LINUX_STACKBOTTOM): Rename "stack base"
to "stack bottom" in comment.
* include/gc.h (GC_stack_base, GC_call_with_stack_base): Likewise.
* include/gc.h [GC_THREADS] (GC_register_my_thread): Likewise.
* misc.c [!THREADS] (GC_call_with_gc_active): Likewise.
* os_dep.c [LINUX_STACKBOTTOM] (GC_linux_main_stack_base): Likewise.
* os_dep.c (GC_get_stack_base): Likewise.
* pthread_support.c (GC_call_with_gc_active): Likewise.
* win32_threads.c (GC_call_with_gc_active): Likewise.
Ivan Maidanski [Thu, 25 Apr 2019 07:28:40 +0000 (10:28 +0300)]
Refine do_blocking() documentation in gc.h
* include/gc.h (GC_do_blocking): Refine comment (copy part of comment
from misc.c, add information that GC should be initialized and the
current thread should be registered).
* misc.c (GC_do_blocking): Remove title comment (as it duplicates the
one in gc.h).
Ivan Maidanski [Thu, 25 Apr 2019 06:54:13 +0000 (09:54 +0300)]
Check real-symbols are already initialized in pthread_join/detach
* pthread_support.c (ASSERT_SYMS_INITIALIZED): New macro (checks either
GC_syms_initialized or parallel_initialized depending on
GC_USE_DLOPEN_WRAP).
* pthread_support.c [!SN_TARGET_ORBIS && !SN_TARGET_PSP2] (pthread_join,
pthread_detach): Call ASSERT_SYMS_INITIALIZED() instead of
INIT_REAL_SYMS().
Ivan Maidanski [Tue, 23 Apr 2019 19:21:54 +0000 (22:21 +0300)]
Workaround 'duplicate expression for condition and assignment' cppcheck FP
The entitled cppcheck warnings are false positives.
* alloc.c (GC_should_collect): Move reassignment of the global variable
which is checked in the conditional expression to the end of the
conditional block statement.
* finalize.c (GC_notify_or_invoke_finalizers): Likewise.
* mark.c [WRAP_MARK_SOME] (GC_mark_some): Likewise.
Ivan Maidanski [Fri, 19 Apr 2019 05:07:52 +0000 (08:07 +0300)]
Remove Win32 main_thread static variable if threads discovery is disabled
(code refactoring)
* win32_threads.c (GC_main_thread): Do not define static variable if
GC_NO_THREADS_DISCOVERY.
* win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_attached_thread):
Reformat comment; move the definition to be near GC_please_stop.
* win32_threads.c [GC_NO_THREADS_DISCOVERY] (GC_thr_init): Define
GC_main_thread as a macro (and undefine it at the end of the function).
Ivan Maidanski [Tue, 16 Apr 2019 21:52:59 +0000 (00:52 +0300)]
Enable true incremental collection even if parallel marker is on
Issue #151 (bdwgc).
Because of the current limitation of the parallel marker implementation,
it is not possible to interrupt the collection when performed by the
parallel marker. This change allows to have the true incremental mode
at the expense of disabling the parallel marker during most collection
phases. By default, the old behavior (a generational collection with
the parallel marker enabled) is preserved unless the client sets
GC_time_limit to a value other than GC_TIME_UNLIMITED.
* alloc.c [(!GC_TIME_LIMIT || CPPCHECK) && PARALLEL_MARK]
(GC_time_limit): Set to GC_TIME_UNLIMITED; add comment.
* alloc.c [PARALLEL_MARK] (GC_collect_a_little_inner): Temporarily
set GC_parallel_mark_disabled to TRUE before GC_mark_some repeated
invocation if GC_time_limit is not GC_TIME_UNLIMITED.
* alloc.c [PARALLEL_MARK] (GC_stopped_mark): Temporarily set
GC_parallel_mark_disabled to TRUE before GC_mark_some repeated
invocation if stop_func is not GC_never_stop_func; add verbose logging
if parallel marking is disabled temporarily.
* doc/README.environment (GC_PAUSE_TIME_TARGET): Update the description
(remove the limitation for the case when parallel marking is on).
* doc/scale.md (The Parallel Marking Algorithm): Update the
documentation regarding incremental mode.
* include/gc.h (GC_parallel, GC_enable_incremental): Update the comment
(remove the limitation on the incremental mode when parallel marking
is on).
* include/private/gc_priv.h [PARALLEL_MARK] (GC_parallel_mark_disabled):
Declare global variable.
* mark.c [PARALLEL_MARK] (GC_parallel_mark_disabled): Define.
* mark.c [PARALLEL_MARK] (GC_mark_some_inner): Do not call
GC_do_parallel_mark() if GC_parallel_mark_disabled; update comment.
* pthread_support.c [PARALLEL_MARK] (GC_thr_init): Do not set
GC_time_limit to GC_TIME_UNLIMITED if available_markers_m1 > 0; remove
comment.
* win32_threads.c [PARALLEL_MARK] (GC_thr_init): Likewise.
Ivan Maidanski [Tue, 16 Apr 2019 06:29:42 +0000 (09:29 +0300)]
Simplify loops of collect_a_little/stopped_mark invoking mark_some
(code refactoring)
* alloc.c (GC_collect_a_little_inner, GC_stopped_mark): If
GC_mark_some() returns true then just break to quit the loop; move the
logic that is needed to funish the collection outside the loop.
* alloc.c (GC_stopped_mark): Change i local variable type from unsigned
to int.
Ivan Maidanski [Fri, 12 Apr 2019 17:25:47 +0000 (20:25 +0300)]
Allow GC_PAUSE_TIME_TARGET environment variable values smaller than 5 ms
All time limit values starting from 1 ms are now accepted.
* misc.c [!GC_DISABLE_INCREMENTAL] (GC_init): Do not set GC_time_limit
if NO_CLOCK; allow all non-zero time_limit values (instead of >4);
do not call WARN() if time_limit value is incorrect.
Ivan Maidanski [Wed, 10 Apr 2019 20:25:50 +0000 (23:25 +0300)]
Fix 'un-mprotect failed' gctest error on Cygwin
(fix of commit fa7f7a72b)
Issue #272 (bdwgc).
* include/private/gcconfig.h [(I386 || X86_64) && CYGWIN32]
(MPROTECT_VDB): Do not define if USE_WINALLOC.
* os_dep.c [CYGWIN32 && MPROTECT_VDB] (GC_setpagesize): Set
GC_page_size to dwAllocationGranularity.
Ivan Maidanski [Tue, 9 Apr 2019 19:50:09 +0000 (22:50 +0300)]
Move QNX and Emscripten macro definitions to proper place in gcconfig.h
(code refactoring)
* include/private/gcconfig.h [__QNX__] (I386, mach_type_known): Move
macro definition down (to be in a group where mach_type_known is
defined for most platforms).
* include/private/gcconfig.h [__QNX__] (OS_TYPE, SA_RESTART,
HEURISTIC1, DATASTART, DATAEND): Move macro definition down; define
only if I386.
* include/private/gcconfig.h [__EMSCRIPTEN__] (OS_TYPE, CPP_WORDSZ,
ALIGNMENT, DATASTART, DATAEND, STACK_NOT_SCANNED): Likewise.
Ivan Maidanski [Thu, 4 Apr 2019 21:34:04 +0000 (00:34 +0300)]
Update documentation about the incremental collector support
* doc/README.darwin (Important Usage Notes): Remove outdated note about
flaky incremental mode.
* doc/README.darwin (Implementation Information): Remove information
about old incremental collector implementation.
* doc/README.win32 (Watcom compiler): Refine information about the
incremental mode support.
* doc/scale.md (Options for enhanced scalability): Refine when the
dedicated marker threads are created.
Ivan Maidanski [Fri, 22 Mar 2019 21:02:55 +0000 (00:02 +0300)]
Remove 'current users' section from overview.md
Information about known BDWGC clients is moved to
https://github.com/ivmai/bdwgc/wiki/Known-clients
* doc/overview.md (Current users): Remove section.
* doc/overview.md (Information provided on the BDWGC site): Add a link
to the list of known clients.
Ivan Maidanski [Fri, 22 Mar 2019 16:44:35 +0000 (19:44 +0300)]
Use KB/MB/GB abbreviations uniformly across entire documentation
* README.md (Installation and Portability): Precede MB with a space.
* doc/README.amiga (WHATS NEW): Likewise.
* doc/debugging.md: Likewise.
* README.md (The C Interface to the Allocator): Replace Kbytes to KB.
* doc/gc.man: Likewise.
* README.Mac: Replace k to KB with a preceding space.
* doc/debugging.md: Likewise.
* doc/README.amiga: Precede MHz with a space.
* doc/debugging.md: Precede KB with a space.
* include/gc.h (GC_malloc_ignore_off_page): Replace K to KB with
a preceding space in a comment.
* tests/test.c (BIG): Likewise.
* include/private/gc_priv.h (ALL_INTERIOR_POINTERS, HBLKSIZE,
CPP_LOG_HBLKSIZE, LOG_PHT_ENTRIES): Likewise.
* include/private/gc_priv.h (LOG_PHT_ENTRIES): Replace M to MB with
a preceding space in a comment.
* include/private/gc_priv.h (LOG_PHT_ENTRIES): Replace G to GB with
a preceding space in a comment.
* os_dep.c [GC_USE_MEM_TOP_DOWN && USE_WINALLOC] (GC_mem_top_down):
Likewise.
* include/gc_priv.h (GC_printf): Replace k to KB with a preceding
space in a comment.
* include/private/specific.h (quick_thread_id): Likewise.
* os_dep.c [MSWINCE] (GC_wince_get_mem): Likewise.
* os_dep.c [USE_WINALLOC && !MSWIN_XBOX1 || CYGWIN32]
(GC_win32_get_mem): Likewise.
* include/private/gcconfig.h [I386 && LINUX] (HEAP_START): Precede GB
with a space in a comment.
Ivan Maidanski [Thu, 21 Mar 2019 07:43:12 +0000 (10:43 +0300)]
Remove documentation specific to particular old BDWGC releases
* doc/README.Mac: Remove mentioning of particular GC versions; adjust
the information (if needed) to match the current GC functionality.
* doc/README.amiga: Likewise.
* doc/README.arm.cross: Likewise.
* doc/README.autoconf: Likewise.
* doc/README.linux: Likewise.
* doc/README.macros (FINALIZE_ON_DEMAND, JAVA_FINALIZATION): Likewise.
* doc/README.sgi: Likewise.
* doc/README.solaris2 (SOLARIS THREADS): Likewise.
* doc/README.symbian: Likewise.
* doc/README.win32 (Threads): Likewise.
* doc/README.win64: Likewise.
* doc/gcdescr.md (Allocation, Thread support,
Thread-local allocation): Likewise.
* doc/gcinterface.md (GC_INIT): Likewise.
* doc/leak.md: Likewise.
* doc/porting.md (Additional requirements for a basic port,
Thread support): Likewise.
* doc/scale.md (Options for enhanced scalability, Performance):
Likewise.
* doc/simple_example.md (Debugging): Do not mention removed
`--enable-full-debug` option of configure.
* include/gc.h (GC_parallel, GC_dont_gc, GC_use_entire_heap,
GC_set_handle_fork): Remove comment that the behavior has changed in
a particular GC version.
* include/gc_inline.h (GC_MALLOC_WORDS_KIND): Likewise.
* include/gc.h (GC_set_free_space_divisor, GC_warn_proc): Reword
comment about ABI incompatible change in some GC version.
* include/gc.h (GC_get_heap_usage_safe): Remove comment that the API
was introduced in a particular GC version.
* include/gc_cpp.h (UseGC): Likewise.
* os_dep.c [LINUX_STACKBOTTOM && IA64] (GC_get_register_stack_base):
Remove mentioning of a particular GC version (and of an old behavior
on an ancient kernel) in a comment.
* win32_threads.c [!GC_PTHREADS && !GC_NO_THREADS_DISCOVERY]
(GC_DllMain): Likewise.
* OS2_MAKEFILE: Likewise.
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).