Add thread suspend/resume signals public setters (POSIX threads)
* include/gc.h (GC_set_suspend_signal, GC_set_thr_restart_signal):
Add public function declaration (to specify non-default signals to
suspend/resume threads).
* include/gc.h (GC_get_suspend_signal, GC_get_thr_restart_signal):
Update comment.
* misc.c (GC_set_suspend_signal, GC_set_thr_restart_signal): Add
public no-op function (only for Darwin, OpenBSD, Win32 and NaCl).
* pthread_stop_world.c (GC_set_suspend_signal,
GC_set_thr_restart_signal): Add public setter to alter the default
signals used to suspend and resume threads (only if not OpenBSD or
NaCl); has no effect if GC is initialized.
Ivan Maidanski [Wed, 4 Jul 2012 15:59:34 +0000 (19:59 +0400)]
Move GC_get_suspend/thr_restart_signal to misc.c for NaCl and OpenBSD
* misc.c (GC_get_suspend_signal, GC_get_thr_restart_signal): Define
also for OpenBSD and NaCl targets in this file (always returns -1).
* pthread_stop_world.c (GC_get_suspend_signal,
GC_get_thr_restart_signal): Move function definition up to the
definition of GC_sig_suspend and GC_sig_thr_restart variables (i.e.,
define function only if not OpenBSD and not NaCl target in this file).
Ivan Maidanski [Wed, 4 Jul 2012 15:00:41 +0000 (19:00 +0400)]
Replace SIG_SUSPEND macro to a variable in pthread_stop_world
* misc.c (GC_get_suspend_signal): Define (as always returning -1) in
this file only if Darwin or Win32 threads.
* os_dep.c (GC_dirty_init): Replace SIG_SUSPEND with the value of
GC_get_suspend_signal() invocation.
* pthread_support.c (pthread_sigmask): Likewise.
* pthread_stop_world.c (GC_sig_suspend): New STATIC variable (only
unless NaCl or OpenBSD) initialized to SIG_SUSPEND.
* pthread_stop_world.c (GC_unblock_gc_signals,
GC_suspend_handler_inner, GC_suspend_all, GC_stop_init): Use
GC_sig_suspend instead of SIG_SUSPEND (only unless NaCl or OpenBSD);
update comment.
* pthread_stop_world.c (GC_get_suspend_signal): Define function (which
returns GC_sig_suspend if available).
Ivan Maidanski [Sat, 23 Jun 2012 18:42:36 +0000 (22:42 +0400)]
Add public GC_set/get_abort_func to replace default GC_on_abort
* include/gc.h (GC_abort_func): New public typedef.
* include/gc.h (GC_set_abort_func, GC_get_abort_func): New API
function declaration.
* include/private/gc_priv.h (GC_on_abort): Change function
declaration to function pointer of GC_abort_func type (only if
SMALL_CONFIG and not PCR).
* misc.c (GC_on_abort): Rename to GC_default_on_abort; make it STATIC
and decorate with GC_CALLBACK; define GC_on_abort variable initialized
to GC_default_on_abort (only if SMALL_CONFIG and not PCR).
* misc.c (GC_set_abort_func, GC_get_abort_func): New public function
(only if if SMALL_CONFIG and not PCR) to alter and read GC_on_abort
value.
Ivan Maidanski [Sun, 24 Jun 2012 09:04:32 +0000 (13:04 +0400)]
Turn off GC_LOOP_ON_ABORT functionality if GC compiled with NO_DEBUGGING
* misc.c (looping_handler, installed_looping_handler): Do not define
if NO_DEBUGGING.
* misc.c (maybe_install_looping_handler): Define as an empty macro if
NO_DEBUGGING.
* misc.c (GC_on_abort): Do not test "GC_LOOP_ON_ABORT" environment
variable if GC_LOOP_ON_ABORT.
Ivan Maidanski [Sun, 24 Jun 2012 08:49:10 +0000 (12:49 +0400)]
Call GC_on_abort (with NULL argument) on exit(1)
* include/private/gc_priv.h (EXIT): Call GC_on_abort(NULL) before
exit(1) (unless PCR) enabling the collector to enter a tight loop
(for debugging purpose) on abnormal EXIT if "GC_LOOP_ON_ABORT"
environment variable is set.
* misc.c (GC_on_abort): Allow "msg" argument to be NULL (skip
printing the message in such a case); update comment.
Ivan Maidanski [Sun, 17 Jun 2012 16:25:09 +0000 (20:25 +0400)]
Fix thread-related tests for pthreads-w32
* tests/initsecondarythread.c: Include "private/config.h" if
HAVE_CONFIG_H (mostly to have GC_WIN32_PTHREADS defined for
pthreads-w32 target).
* tests/thread_leak_test.c: Likewise.
* tests/threadkey_test.c: Likewise.
Ivan Maidanski [Sat, 16 Jun 2012 09:35:53 +0000 (13:35 +0400)]
tools: Include proper header file for configuration macros
* tools/if_mach.c: Include private/gc_priv.h instead of
private/gcconfig.h (to get proper configuration macros defined).
* tools/if_not_there.c: Likewise.
* tools/threadlibs.c: Likewise.
* tools/threadlibs.c: Do not include gc_config_macros.h directly.
Ivan Maidanski [Sat, 16 Jun 2012 08:34:06 +0000 (12:34 +0400)]
Fix test_cpp (ensure the collector recognizes pointers to interiors)
* tests/test_cpp.cc (main): Call GC_set_all_interior_pointers(1)
before GC_INIT to ensure that the collector considers pointers to
object interiors as valid ones (such a pointer could emerge as
a result of a type cast to subclass in case of multiple inheritance);
add comment.
Ivan Maidanski [Sat, 16 Jun 2012 07:57:18 +0000 (11:57 +0400)]
cord tests: Suppress GCC warnings in 'de' app
* cord/tests/de.c (retrieve_line): Change type of "eol" local variable
from int to size_t (to prevent "comparison between signed and unsigned"
compiler warning).
* cord/tests/de_win.c (WinMain): Cast GetLastError() result to
unsigned int (to match printf format specifier).
* cord/tests/de_win.c (AboutBoxCallback): Suppress "unused parameter"
compiler warning for "lParam" (by casting the later to void).
Ivan Maidanski [Fri, 15 Jun 2012 14:24:18 +0000 (18:24 +0400)]
test_cpp: Suppress GCC warnings in WinMain
* tests/test_cpp.cc (ATTR_UNUSED): New macro.
* tests/test_cpp.cc (WinMain): Tag "instance", "prev" and "cmdShow"
arguments with ATTR_UNUSED.
* tests/test_cpp.cc (WinMain): Explicitly cast "xio", "f", "d", "a"
local variables to void (to suppress "variable set but not used"
compiler warning).
Ivan Maidanski [Sat, 9 Jun 2012 18:13:53 +0000 (22:13 +0400)]
Recognize GC_DONT_GC macro in gc.h (causes GC_INIT to turn off GC)
* include/gc.h (GC_INIT_CONF_MAX_RETRIES): Recognize GC_DONT_GC
(set GC_dont_gc to 1 in that case) to turn off GC at start-up (for
a debugging purpose).
Ivan Maidanski [Sat, 2 Jun 2012 15:27:57 +0000 (19:27 +0400)]
Add GC_push_all/conditional() to GC public API
* include/gc_mark.h (GC_push_all, GC_push_conditional): Expose
function as a part of public API (use GC_API and GC_CALL); replace
internal ptr_t and GC_bool type to char* and int, respectively; add
comment.
* mark.c (GC_push_all, GC_push_conditional): Likewise.
* include/private/gc_priv.h (GC_push_all, GC_push_conditional): Remove
function declaration.
* include/private/gc_priv.h (GC_PUSH_CONDITIONAL): New macro used
internally instead of GC_push_conditional (defined depending on
GC_DISABLE_INCREMENTAL).
* include/private/gc_priv.h (GC_PUSH_CONDITIONAL, GC_push_all_stack):
Update comment.
* mark.c (GC_push_conditional): Define for GC_DISABLE_INCREMENTAL case
(rediect to GC_push_all).
* mark_rts.c (GC_push_conditional_with_exclusions): Use
GC_PUSH_CONDITIONAL() instead of GC_push_conditional().
* mark_rts.c (GC_push_roots): Reformat the comment.
Ivan Maidanski [Sat, 2 Jun 2012 08:33:03 +0000 (12:33 +0400)]
Fix visibility of GC_push_all/conditional, GC_push_other_roots symbols
* include/private/gc_priv.h (GC_push_all, GC_push_other_roots):
Declare as GC_API_PRIV (instead of GC_INNER) to make the symbol
externally visible to some well-known 3rd-party software (e.g., ECL).
* include/private/gc_priv.h (GC_push_conditional): Declare as
GC_API_PRIV (only if GC_DISABLE_INCREMENTAL is undefined).
* mark.c (GC_push_all, GC_push_conditional): Remove GC_INNER (to match
the declaration).
* os_dep.c (GC_push_other_roots): Likewise.
Tsugutomo Enami [Sat, 2 Jun 2012 09:31:43 +0000 (13:31 +0400)]
Fix GC_FirstDLOpenedLinkMap() for NetBSD 6 release
(this empty commit contains only the fixed message for the previous commit)
* dyn_load.c: Include sys/param.h and dlfcn.h on NetBSD.
* dyn_load.c (GC_FirstDLOpenedLinkMap): Obtain link map using dlinfo()
on NetBSD if RTLD_DI_LINKMAP feature present (defined).
Tsugutomo Enami [Thu, 31 May 2012 23:12:24 +0000 (03:12 +0400)]
Fix GC_FirstDLOpenedLinkMap() for FreeBSD 9 release
* dyn_load.c: Include sys/param.h and dlfcn.h on FreeBSD.
* dyn_load.c (GC_FirstDLOpenedLinkMap): Obtain link map using dlinfo()
on FreeBSD if RTLD_DI_LINKMAP feature present (defined).
Ivan Maidanski [Wed, 16 May 2012 04:34:10 +0000 (08:34 +0400)]
Fix assertion in GC_malloc_[atomic_]uncollectable (THREADS case only)
* malloc.c (GC_malloc_uncollectable): Do not check assertion on
hb_n_marks to be zero if multi-threaded; add comment.
* mallocx.c (GC_malloc_atomic_uncollectable): Likewise.
* dbg_mlc.c (GC_debug_generic_malloc_inner): Add GC_start_debugging() if not
done. This fixes the missing registration of the debug header displacement.
* dbg_mlc.c (GC_debug_generic_malloc_inner_ignore_off_page): Ditto.
Ivan Maidanski [Sat, 21 Apr 2012 16:18:55 +0000 (20:18 +0400)]
Fix USE_CUSTOM_SPECIFIC mode (if manually enabled) for Win32
* win32_threads.c (GC_unregister_my_thread,
GC_remove_all_threads_but_me, GC_thread_exit_proc): Invoke
GC_remove_specific (if THREAD_LOCAL_ALLOC) after destroying
thread-local list (same as in pthread_support.c).
Ivan Maidanski [Sat, 21 Apr 2012 19:44:19 +0000 (23:44 +0400)]
Code refactoring of specific.c and specific.h;
cast pointers to word instead of unsigned long
* include/private/specific.h (CACHE_HASH, HASH): Add parentheses
around the argument.
* include/private/specific.h (CACHE_HASH): Remove unnecessary cast to
long.
* include/private/specific.h (HASH): Rename "n" argument to "p";
cast "p" to word instead of long; cast result to unsigned.
* include/private/specific.h (quick_thread_id, INVALID_QTID): Cast to
word instead of unsigned long.
* specific.c (GC_key_create_inner): Cast invalid_tse.next (pointer) to
word instead of unsigned long.
* include/private/specific.h (GC_slow_getspecific, GC_getspecific):
Change type of "qtid" from unsigned long to word.
* specific.c (GC_slow_getspecific): Likewise.
* include/private/specific.h (GC_getspecific): Remove "hash_val"
local variable.
* specific.c: Do not include gc_priv.h as included from
thread_local_alloc.h; do not include atomic_ops.h as included from
specific.h file.
Ivan Maidanski [Sat, 21 Apr 2012 16:18:55 +0000 (20:18 +0400)]
Fix USE_CUSTOM_SPECIFIC mode (if manually enabled) for Win32
* win32_threads.c (GC_unregister_my_thread,
GC_remove_all_threads_but_me, GC_thread_exit_proc): Invoke
GC_remove_specific (if THREAD_LOCAL_ALLOC) after destroying
thread-local list (same as in pthread_support.c).
* alloc.c (GC_check_fl_marks): Re-read each pointer atomically before
following the pointed-to link and bail out if the result is different
(this can happen if the thread has popped the object off the
free-list); the function is a no-op if AO_load is unavailable.
Ivan Maidanski [Fri, 20 Apr 2012 05:12:47 +0000 (09:12 +0400)]
Code refactoring of GC_check_tls_for/GC_check_fl_marks
* alloc.c (GC_check_fl_marks): Change prototype (pass pointer to
"freelist" element instead of value); do not define the function if
THREAD_LOCAL_ALLOC undefined.
* include/private/gc_priv.h (GC_check_fl_marks): Likewise.
* alloc.c (GC_check_fl_marks): Skip check if the argument points to
a special (non-pointer) value; update comment; rename "q" local
variable to "list".
* thread_local_alloc.c (GC_check_tls_for): Update code according to
GC_check_fl_marks functionality change (remove checks for special
value).
Ivan Maidanski [Fri, 20 Apr 2012 04:53:46 +0000 (08:53 +0400)]
Code refactoring of GC_generic_malloc_inner (eliminate recursion)
* malloc.c (GC_generic_malloc_inner): Update "lg" value after GC_init
and GC_extend_size_map calls; add assertion on "lg" value after
GC_extend_size_map call; update "opp" and "op" values and retry
allocation instead of recursive call; replace "goto" with return
(remove "out" label).
* include/private/gc_priv.h, alloc.c (GC_check_fl_marks): Re-read each
pointer before following the pointed-to link, and bail out if the result is
different. This can happen if the thread has popped the object off the
free-list. The prototype is changed to allow re-reading the pointers.
* thread_local_alloc.c (GC_check_tls_for): Adjust the calls accordingly.
Ivan Maidanski [Tue, 17 Apr 2012 03:52:08 +0000 (07:52 +0400)]
Minor code refactoring regarding HAVE_BUILTIN_UNWIND_INIT
* include/private/gcconfig.h (HAVE_BUILTIN_UNWIND_INIT): Do not define
for Darwin/ppc and RTEMS.
* mach_dep.c (GC_with_callee_saves_pushed): Remove target-specific
checks for Darwin/ppc and RTEMS as HAVE_BUILTIN_UNWIND_INIT is not
defined in that case.
Fix GC_with_callee_saves_pushed for clang (disable __builtin_unwind_init)
* include/private/gcconfig.h (HAVE_BUILTIN_UNWIND_INIT): Do not define
for clang (as __builtin_unwind_init seems to be a no-op in the latest
clang release).
Ivan Maidanski [Mon, 9 Apr 2012 04:02:42 +0000 (08:02 +0400)]
Do not compile backgraph.c unless configure '--enable-gc-debug'
* Makefile.am (libgc_la_SOURCES): Exclude "backgraph" entry from
unconditional list; add this entry only if MAKE_BACK_GRAPH.
* configure.ac (MAKE_BACK_GRAPH): New AM conditional (defined only if
enable_gc_debug explicitly set to yes).
Ivan Maidanski [Mon, 2 Apr 2012 18:31:22 +0000 (22:31 +0400)]
FIX: Disable incremental mode on Darwin if fork handling requested
* doc/README.macros (NO_HANDLE_FORK): Replace back with HANDLE_FORK
and update.
* include/private/gcconfig.h (CAN_HANDLE_FORK): Define also for Darwin
in case of MPROTECT_VDB.
* misc.c (GC_set_handle_fork): Handle Darwin properly; add comment.
* os_dep.c (GC_dirty_init): Do not turn on GC_dirty_maintained for
Darwin if GC_handle_fork is on; add comment; remove FIXME.
* pthread_support.c (GC_fork_prepare_proc): Remove WARN for Darwin
(since GC_dirty_maintained is off in that case).
* pthread_support.c (GC_fork_child_proc): Remove comment (for Darwin).
Ivan Maidanski [Mon, 2 Apr 2012 16:18:12 +0000 (20:18 +0400)]
Add public GC_set_handle_fork to control forked child handling support
* include/gc.h (GC_set_handle_fork): New API function.
* misc.c (GC_set_handle_fork): Likewise.
* include/private/gc_priv.h (GC_handle_fork): New internal variable
declaration (only if CAN_HANDLE_FORK).
* misc.c (GC_handle_fork): New internal variable (defined only if
CAN_HANDLE_FORK); initialize to TRUE if HANDLE_FORK.
* include/private/gcconfig.h (HANDLE_FORK): Replace with
CAN_HANDLE_FORK.
* pthread_support.c (HANDLE_FORK): Likewise.
* win32_threads.c (HANDLE_FORK): Likewise.
* include/private/gcconfig.h (CAN_HANDLE_FORK): Always define macro if
HANDLE_FORK.
* pthread_support.c (GC_thr_init): Replace HANDLE_FORK with
CAN_HANDLE_FORK; call pthread_atfork only if GC_handle_fork; update
the comment.
* win32_threads.c (GC_thr_init): Likewise.
* tests/test.c (NO_TEST_HANDLE_FORK): Define new macro if fork
handling is not supported (or is a no-op) on the target.
* tests/test.c (INIT_FORK_SUPPORT): New macro (invoke
GC_set_handle_fork unless NO_TEST_HANDLE_FORK).
* tests/test.c (GC_OPT_INIT): New macro (defined to GC_INIT or empty).
* tests/test.c (GC_COND_INIT): Use INIT_FORK_SUPPORT and GC_OPT_INIT.
* tests/test.c (run_one_test): Test NO_TEST_HANDLE_FORK (instead of
target-specific macros).
* win32_threads.c (GC_remove_all_threads_but_me, GC_fork_prepare_proc,
GC_fork_parent_proc, GC_fork_child_proc): Do not test GC_PTHREADS.
* configure.ac (HANDLE_FORK, NO_HANDLE_FORK): Update message.
Ivan Maidanski [Fri, 30 Mar 2012 03:53:06 +0000 (07:53 +0400)]
Remove redundant public GC_HAVE_GET_HEAP_USAGE_SAFE macro
* include/gc.h (GC_HAVE_GET_HEAP_USAGE_SAFE): Remove public HAVE_
macro (since function availability could be determined by autotools);
update the comment.
Andy Wingo [Tue, 27 Mar 2012 11:20:37 +0000 (13:20 +0200)]
configure: add --enable-handle-fork option
* configure.ac: Add --enable-handle-fork option; if explicitly passed,
enables or disables the pthread_atfork support; if not passed, the
default, as determined by gcconfig.h, is to enable HANDLE_FORK if it
is supported on the target platform.
Ivan Maidanski [Sun, 25 Mar 2012 07:07:25 +0000 (11:07 +0400)]
Replace GC_ms_entry declaration with opaque definition for public API
* include/gc_mark.h (GC_ms_entry): Define structure as opaque unless
GC_BUILD (otherwise remains as declaration which is defined in
private/gc_pmark.h).