Ivan Maidanski [Fri, 4 Oct 2019 17:42:54 +0000 (20:42 +0300)]
Check thread is alive on each SuspendThread loop iteration (Win32)
(fix of commit 449eda034)
* win32_threads.c [!GC_NO_THREADS_DISCOVERY]
(GC_delete_gc_thread_no_free): Reset suspended if GC_win32_dll_threads.
* win32_threads.c [!MSWINCE] (GC_suspend): Move comment near exitCode
declaration to be near GetExitCodeThread() call; adjust comment.
* win32_threads.c [!MSWINCE && RETRY_GET_THREAD_CONTEXT] (GC_suspend):
Call GetExitCodeThread() on each iteration of the suspend loop; refine
ABORT message on ResumeThread failure.
Ivan Maidanski [Wed, 2 Oct 2019 22:03:51 +0000 (01:03 +0300)]
Use CreateThread without GC_ prefix in gctest
(code refactoring)
* tests/test.c (GC_NO_THREAD_REDIRECTS): Do not undefine unless
GC_NO_THREADS_DISCOVERY is defined.
* tests/test.c [GC_WIN32_THREADS] (fork_a_thread, WinMain): Call
CreateThread() instead of GC_CreateThread().
Ivan Maidanski [Thu, 26 Sep 2019 08:31:27 +0000 (11:31 +0300)]
Workaround 'condition appendToFile is always false' cppcheck false positive
* misc.c [(MSWIN32 && !CONSOLE_LOG || MSWINCE) && !MSWINRT_FLAVOR
&& NO_GETENV_WIN32 && CPPCHECK] (GC_CreateLogFile): Define appendToFile
as macro (to FALSE) instead of a local variable; undefine appendToFile
at the function.
Ivan Maidanski [Wed, 25 Sep 2019 07:31:31 +0000 (10:31 +0300)]
Prevent use of unsaved thread context registers in incremental GC (Windows)
(fix of commits 449eda034, 190e18c75)
During incremental collection GC_push_all_stacks() may be called when
the world is not stopped. If the context registers and sp value are
saved during thread suspension then GC_push_all_stacks() gets these
values of the previous GC cycle or, even, gets all zeros instead the
context registers and sp on the first GC after the thread creation.
This commit fixes this by calling GetThreadContext in GC_push_stack_for
if thread is not suspended.
* win32_threads.c (first_thread): Refine the comment.
* win32_threads.c [!GC_NO_THREADS_DISCOVERY && RETRY_GET_THREAD_CONTEXT]
(GC_delete_gc_thread_no_free): Reset context_sp if GC_win32_dll_threads.
* win32_threads.c (GC_push_stack_for): Change the assertion expression
from thread->suspended to thread->suspended||!GC_world_stopped (the
assertion is off unless THREAD_LOCAL_ALLOC).
* win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_push_stack_for): If
thread is not suspended then call GetThreadContext(), if it fails then
use sp value and the context registers saved during the latest
stop-the-world; add comments.
* win32_threads.c (GC_push_all_stacks): Add the title comment (copied
from pthread_stop_world.c).
Ivan Maidanski [Tue, 24 Sep 2019 07:52:51 +0000 (10:52 +0300)]
Remove redundant GC_with_callee_saves_pushed call in multi-threaded builds
In GC_push_regs_and_stack, if cold_gc_frame is null and threads
support is on then there is no need to call
GC_with_callee_saves_pushed(GC_push_current_stack) as
GC_push_current_stack is no-op in this case.
* mark_rts.c (GC_push_current_stack): Reformat title comment.
* mark_rts.c [THREADS] (GC_push_current_stack): Do not check that
cold_gc_frame is non-zero; add comment about it.
* mark_rts.c [THREADS] (GC_push_regs_and_stack): If cold_gc_frame is
null then do not call GC_with_callee_saves_pushed().
Ivan Maidanski [Mon, 16 Sep 2019 07:41:11 +0000 (10:41 +0300)]
Add debug messages on thread suspend/resume (Win32)
The messages are similar to the ones for Darwin.
* win32_threads.c [DEBUG_THREADS] (GC_suspend): Log a message that the
thread is going to be suspended.
* win32_threads.c [DEBUG_THREADS] (GC_start_world): Log a message
whether the thread is going to be resumed or it cannot be resumed
because it is not suspended.
Ivan Maidanski [Wed, 11 Sep 2019 20:03:49 +0000 (23:03 +0300)]
Do not define GC_write_cs for Xbox One target
(fix of commit d16debf3e)
Issue #173 (bdwgc).
GC_write_cs is not used in GC_write thus there is no need to define
and use it in GC_stop_world.
* include/private/gc_priv.h [THREADS && MSWIN_XBOX1] (GC_write_cs):
Do not declare.
* misc.c [THREADS && MSWIN_XBOX1] (GC_write_cs): Do not define.
* win32_threads.c (GC_stop_world): Call EnterCriticalSection() and
LeaveCriticalSection() only if MSWIN32 or MSWINCE.
Ivan Maidanski [Tue, 10 Sep 2019 08:09:42 +0000 (11:09 +0300)]
Replace push_one calls with push_many_regs one for Win32 thread context
(code refactoring)
Also, do not define GC_push_one except for Darwin (and some ancient
targets that use the function).
* include/private/gc_priv.h [MSWIN32 || MSWINCE] (GC_push_one): Do not
declare.
* include/private/gc_priv.h [!MSWIN32 && !MSWINCE] (GC_push_one):
Declare only if AMIGA or MACOS or GC_DARWIN_THREADS.
* include/private/gc_priv.h [GC_WIN32_THREADS] (GC_push_many_regs):
Declare function; add comment.
* mark.c (GC_push_one): Define only if AMIGA or MACOS or
GC_DARWIN_THREADS.
* mark.c [GC_WIN32_THREADS] (GC_push_many_regs): New GC_INNER function.
* win32_threads.c (GC_push_stack_for): Remove i local variable; call
GC_push_many_regs() instead of a loop with GC_push_one() calls (ignore
2 first registers if WOW64_THREAD_CONTEXT_WORKAROUND).
Ivan Maidanski [Tue, 10 Sep 2019 08:01:09 +0000 (11:01 +0300)]
Fix incorrect code generation by MS VC caused by excessive Thread_Rep size
(fix of commit 449eda034)
The gctest crashes were observed in debug builds produced by MS VC.
In addition, this change greatly reduces memory usage by GC_threads[]
and dll_thread_table[] (compared to the solution that stores the full
CONTEXT in GC_Thread_Rep).
* win32_threads.c (copy_ptr_regs): Declare static function.
* win32_threads.c (PUSHED_REGS_COUNT): Define macro.
* win32_threads.c [RETRY_GET_THREAD_CONTEXT]
(GC_Thread_Rep.saved_context): Move down to be the last field; change
type from CONTEXT to word[PUSHED_REGS_COUNT]; rename to context_regs.
* win32_threads.c [RETRY_GET_THREAD_CONTEXT]
(GC_Thread_Rep.context_sp): New field.
* win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_suspend): Declare
context local variable and use it for GetThreadContext() call; if the
latter succeeds then call copy_ptr_regs(); update comment.
* win32_threads.c (copy_ptr_regs): Define static function (move
PUSH-related part of GC_push_stack_for code here); change PUSH1(reg) to
store reg to regs[]; define context as *pcontext; add assertion that
number of stored registers is equal to PUSHED_REGS_COUNT.
* win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND] (copy_ptr_regs):
Store ContextFlags and SegFs as the first elements of regs[].
* win32_threads.c (GC_push_stack_for): Declare i local variable (set
to 0).
* win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_push_stack_for):
Replace pcontext and context with word *regs; set sp from
thread->context_sp; remove undef context.
* win32_threads.c [!RETRY_GET_THREAD_CONTEXT] (GC_push_stack_for):
Declare regs[PUSHED_REGS_COUNT]; call copy_ptr_regs() to initialize
regs[] and sp; limit context scope to GetThreadContext() and
copy_ptr_regs() calls only.
* win32_threads.c (GC_push_stack_for): Call GC_push_one() for each
regs[] element (except for the first 2 ones if
WOW64_THREAD_CONTEXT_WORKAROUND).
* win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND]
(GC_push_stack_for): Define ContextFlags, SegFs local variables
(the values are obtained from regs[]); use these variables instead of
context one; do not overwrite sp local variable value so that not to
use context.Esp directly (i.e. not to use context out of its scope).
Prevent GetThreadContext failure (Windows)
(a cherry-pick of commits 3f39ea8, ab3699da from 'unity-master')
Calls to GetThreadContext may fail. Work around this by putting
access in suspend/resume loop to advance thread past problematic areas
where suspend fails. Capture context in per thread structure at
suspend time rather than retreiving it during the push logic.
* include/private/gcconfig.h [(I386 || X86_64) && (CYGWIN32 || MSWIN32)]
(RETRY_GET_THREAD_CONTEXT): Define macro.
* win32_threads.c [RETRY_GET_THREAD_CONTEXT]
(MAX_SUSPEND_THREAD_RETRIES): Likewise.
* include/private/gcconfig.h [NO_RETRY_GET_THREAD_CONTEXT]
(RETRY_GET_THREAD_CONTEXT): Undefine macro (for test purposes).
* win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_Thread_Rep): Add
saved_context field; add comment.
* win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_suspend): Define
retry_cnt local variable; set ContextFlags and call GetThreadContext()
after invocation of SuspendThread(); call ResumeThread() and proceed to
SuspendThread() if GetThreadContext() failed (the limit of iterations
is MAX_SUSPEND_THREAD_RETRIES); call Sleep(0) after ResumeThread() or
failed SuspendThread() except for the first 2 iterations.
* win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_push_stack_for):
Declare pcontext local variable (which refers to thread->saved_context);
define context as a macro (to *pcontext) instead of a local variable;
add comment; do not set ContextFlags and do not call GetThreadContext();
undefine context after last use of PUSHn().
Ivan Maidanski [Thu, 5 Sep 2019 08:44:27 +0000 (11:44 +0300)]
Refactoring of WoW64 workaround (Win32)
(code refactoring of commit 9483d5bba)
Issue #262 (bdwgc).
* include/private/gcconfig.h [I386 && (CYGWIN32 || MSWIN32)]
(WOW64_THREAD_CONTEXT_WORKAROUND): Define macro.
* win32_threads.c [!CONTEXT_EXCEPTION_ACTIVE] (CONTEXT_EXCEPTION_ACTIVE,
CONTEXT_EXCEPTION_REQUEST, CONTEXT_EXCEPTION_REPORTING): Move macro
definition upper to be before GC_suspend(); define only if
WOW64_THREAD_CONTEXT_WORKAROUND is defined (instead of I386).
* win32_threads.c (isWow64): Move static variable upper to be before
GC_suspend(); define only if WOW64_THREAD_CONTEXT_WORKAROUND.
* win32_threads.c (GET_THREAD_CONTEXT_FLAGS): New macro.
* win32_threads.c (GC_push_stack_for): Always set context.ContextFlags
to GET_THREAD_CONTEXT_FLAGS.
* win32_threads.c [I386] (GC_push_stack_for): Always store context.Esp
to sp (as the initial value).
* win32_threads.c (GC_push_stack_for): Use WoW64 workaround only
if WOW64_THREAD_CONTEXT_WORKAROUND (instead of I386).
* win32_threads.c (GC_thr_init): Set isWow64 only if
WOW64_THREAD_CONTEXT_WORKAROUND (instead of I386).
Ivan Maidanski [Thu, 29 Aug 2019 21:46:43 +0000 (00:46 +0300)]
Prevent WARN of incompatible incremental GC if default or manual VDB
Incremental GC based on mprotect is considered incompatible with /proc
roots but the default and manual VDB modes are OK.
* mark.c [WRAP_MARK_SOME && !MSWIN32 && !MSWINCE] (GC_mark_some):
Do not WARN about incompatibility of incremental GC with /proc roots
if DEFAULT_VDB or GC_auto_incremental is false (i.e. manual VDB is on).
Ivan Maidanski [Thu, 22 Aug 2019 20:30:34 +0000 (23:30 +0300)]
Refactoring of CMake script to use ANDROID/APPLE/CYGWIN/MSYS variables
* CMakeLists.txt [CMAKE_USE_PTHREADS_INIT]: Replace
"HOST MATCHES .*-.*-android.*", "HOST MATCHES .*-.*-cygwin.*",
"HOST MATCHES .*-.*-darwin.*", "HOST MATCHES .*-.*-msys.*" with
ANDROID, CYGWIN, APPLE and MSYS variables, respectively; add comment
that ANDROID is defined only starting from cmake-3.7.0; remove
commented out darwin_threads variable assignment.
Ivan Maidanski [Wed, 21 Aug 2019 21:48:30 +0000 (00:48 +0300)]
Fix HOST determination in CMake script
As per the configure script, HOST variable value should identify the
target, not build host.
* CMakeLists.txt (HOST): Set variable before find_package(Threads);
change message type to STATUS; report ${HOST} value as "TARGET".
* CMakeLists.txt (_HOST): Use CMAKE_SYSTEM_PROCESSOR instead
of CMAKE_HOST_SYSTEM_PROCESSOR; specify vendor as "unknown" (instead
of empty string); remove FIXME.
Ivan Maidanski [Wed, 21 Aug 2019 08:31:52 +0000 (11:31 +0300)]
Fix subexpression widening in memhash() of disclaim_weakmap_test
(fix of commit 0cc2c0e7e)
It would be more correct to widen the argument (from unsigned to
GC_word) of multiply operation instead of implicit widening of the
result.
* tests/disclaim_weakmap_test.c (memhash): Cast acc to GC_word before
multiplying by 2003; cast the whole expression to unsigned type (before
assigning it to acc).
Ivan Maidanski [Fri, 2 Aug 2019 18:21:59 +0000 (21:21 +0300)]
Fix 'wrong finalization data' gctest failure on Windows
(fix of commit aefc738c1)
Issue #289 (bdwgc).
This commit workarounds some bug in MS compiler for x86 (v19.10.25017,
as of now) which causes generation of an incorrect code for
GC_normal_finalize_mark_proc() if code optimizations are on.
Ivan Maidanski [Tue, 30 Jul 2019 23:01:57 +0000 (02:01 +0300)]
Fix passing CFLAGS_EXTRA to compiler in CMake script
(fix of commit b6ac6a5a4)
The previous solution does not work for MS VC target.
* CMakeLists.txt [CFLAGS_EXTRA] (CMAKE_C_FLAGS, CMAKE_CXX_FLAGS): Do
not set.
* CMakeLists.txt [CFLAGS_EXTRA]: Pass $(CFLAGS_EXTRA) to
add_compile_options.
Ivan Maidanski [Fri, 26 Jul 2019 18:24:18 +0000 (21:24 +0300)]
Pass -D GC_DLL -fvisibility=hidden if default configure build is requested
(fix of commit c9964cfc0)
If --disable-shared and --enable-static are not passed to configure
then build generates only shared libraries, thus the internal symbols
visibility could be restricted.
Ivan Maidanski [Wed, 24 Jul 2019 21:55:22 +0000 (00:55 +0300)]
Compile gc.c unless building static libraries (NT_MAKEFILE, WCC_MAKEFILE)
This is to match the behavior of CMake and configure scripts.
* NT_MAKEFILE [!ENABLE_STATIC] (OBJS): Set to extra\gc.obj,
extra\msvc_dbg.obj.
* WCC_MAKEFILE (OBJS): Define only if ENABLE_STATIC.
* WCC_MAKEFILE [!ENABLE_STATIC] (gc.obj): New target.
* WCC_MAKEFILE [!ENABLE_STATIC] (gc.dll): Depend on and append gc.obj
instead of $(OBJS) elements.
Ivan Maidanski [Fri, 19 Jul 2019 17:42:38 +0000 (20:42 +0300)]
Build gccpp library by Makefile.direct, NT_MAKEFILE and WCC_MAKEFILE
* Makefile.direct: Update header comment about all, gc.a (base_lib),
c++, check, check-cpp targets.
* Makefile.direct (CXX): Refine comment.
* Makefile.direct (all): Depend also on c++.
* Makefile.direct (bsd-libgccpp.a): New target (duplicates bsd-libgc.a
one).
* Makefile.direct (bsd-libgc.a): Add a rename of gccpp.a to
bsd-libgccpp.a.
* Makefile.direct (BSD-pkg-install): Copy bsd-libgccpp.a file to
libgccpp.a, install the latter one.
* Makefile.direct (test_cpp): Depend on c++ instead of gc_cpp.o; pass
gccpp.a (instead of gc_cpp.o) to $(CXX).
* Makefile.direct (gccpp.a): New target (duplicates c++ one).
* Makefile.direct (c++): Do not depend on gc_cpp.h and base_lib;
create gccpp.a instead of updating gc.a.
* Makefile.direct (clean): Delete *.a files instead of gc.a.
* Makefile.direct (check): Depend also on test_cpp$(EXEEXT); run also
test_cpp.
* NT_MAKEFILE (LINK_GC, LINK_DLL_FLAGS): Remove variable.
* NT_MAKEFILE (OBJS): Remove gc_cpp.obj.
* NT_MAKEFILE (all, test_cpp.exe): Depend also on gccpp.lib.
* WCC_MAKEFILE (all, test_cpp.exe): Likewise.
* NT_MAKEFILE (gccpp.lib): New target (depending on gc_cpp.obj).
* WCC_MAKEFILE (gccpp.lib): Likewise.
* WCC_MAKEFILE [MAKE_AS_DLL] (gccpp.dll): Likewise.
* NT_MAKEFILE (test_cpp.exe): Pass gccpp.lib to $(link).
* WCC_MAKEFILE [MAKE_AS_LIB] (MAKE_AS_LIB): Set to -DGC_NOT_DLL.
* WCC_MAKEFILE (gc.lib): Do not depend gc_cpp.obj.
* WCC_MAKEFILE [MAKE_AS_DLL] (gc.lib): Do not add gc_cpp.obj to gc.lib.
* WCC_MAKEFILE [MAKE_AS_DLL] (gc.dll): Specify "op case".
Ivan Maidanski [Wed, 17 Jul 2019 08:52:26 +0000 (11:52 +0300)]
Update README.cmake regarding Unix, C++ and tests
Issue #105 (bdwgc).
* doc/README.cmake: Mention that Unix targets are also supported;
remove not that support is not yet complete; update the list of
supported targets (that CMake is able to generate for); use Visual
Studio 9 instead of Visual Studio 8 in the examples; document
enable_cplusplus and build_tests options; provide an example with
--config option; change "build" artifacts folder to "out" one in
the example.
Ivan Maidanski [Wed, 17 Jul 2019 08:39:26 +0000 (11:39 +0300)]
Remove gc.mak script (MS VC)
Issue #105 (bdwgc).
CMake script or NT_MAKEFILE should be used instead of gc.mak.
* ChangeLog (8.1.0): Remove item about gc.mak.
* Makefile.am (EXTRA_DIST): Remove gc.mak.
* gc.mak: Remove file.
* doc/README.win32 (Threads): Remove gc.mak usage information; mention
that CMake script is the preferred way of building for Windows.