platform/upstream/libgc.git
8 years agoFix de_win WndProc prototype parameters for 64-bit (Win64)
Ivan Maidanski [Fri, 12 Feb 2016 08:46:06 +0000 (11:46 +0300)]
Fix de_win WndProc prototype parameters for 64-bit (Win64)

* cord/tests/de_win.h (WndProc): Change UINT type (for wParam) to
WPARAM; change LONG type to LPARAM.
* cord/tests/de_win.h (AboutBox): Remove unused declaration.

8 years agoFix null-pointer dereferences in case of out-of-memory in cord
Ivan Maidanski [Thu, 11 Feb 2016 21:22:44 +0000 (00:22 +0300)]
Fix null-pointer dereferences in case of out-of-memory in cord

* cord/cordprnt.c: Include <stdlib.h> (for abort() declaration).
* cord/cordprnt.c (OUT_OF_MEMORY): New macro.
* cord/tests/de.c (OUT_OF_MEMORY): Likewise.
* cord/cordprnt.c (CORD_vsprintf): Execute OUT_OF_MEMORY if
GC_MALLOC_ATOMIC returns NULL.
* cord/cordxtra.c (CORD_ec_flush_buf): Likewise.
* cord/tests/de.c (replace_line, main): Likewise.
* tests/cordtest.c (test_extras): Declare "u" local variable; do ABORT
if CORD_substr returns NULL (to avoid null pointer dereference in
strcmp).
* cord/tests/de_win.c (plain_chars, control_chars): Return NULL if
GC_MALLOC_ATOMIC returns NULL.
* cord/tests/de_win.c (WndProc): Execute de_error() (with the
appropriate message) if plain_chars() or control_chars() returned
NULL (and do not call the corresponding TextOutA in such a case).

8 years agoFix null pointer dereference on out-of-memory in tests
Ivan Maidanski [Tue, 9 Feb 2016 20:35:33 +0000 (23:35 +0300)]
Fix null pointer dereference on out-of-memory in tests

* tests/disclaim_bench.c (main): Check GC_MALLOC result for NULL
(abort in case of out-of-memory) before dereference.
* tests/test.c (run_one_test): Likewise.
* tests/disclaim_test.c (pair_new): Move is_pair call (in my_assert)
down to be after GC_finalized_malloc result check for NULL.

8 years agoWorkaround 'identical expr on both sides of bitwise op' warning
Ivan Maidanski [Tue, 9 Feb 2016 06:51:22 +0000 (09:51 +0300)]
Workaround 'identical expr on both sides of bitwise op' warning

* gcj_mlc.c (GC_init_gcj_malloc): Comment out "0 |" (in the expression
of "0 | GC_DS_LENGTH").
* mark.c (GC_obj_kinds, GC_push_marked, GC_push_unconditionally):
Likewise.

8 years agoUpdate AUTHORS file
Ivan Maidanski [Wed, 3 Feb 2016 20:53:04 +0000 (23:53 +0300)]
Update AUTHORS file

8 years agoFix Cygwin64 build
Yuki Okumura [Tue, 2 Feb 2016 13:49:11 +0000 (22:49 +0900)]
Fix Cygwin64 build

On x86_64, Cygwin symbols do not have leading underscore anymore,
so an additional underscore is needed on linker-generated symbols
access from C.

* include/gc.h (GC_DATASTART, GC_DATAEND): Prefix _data_start__,
_bss_start__, _data_end__ and _bss_end__ with an extra underscore if
__x86_64__ (only if __CYGWIN__); reformat code.

8 years agoGC_malloc[_atomic] global and thread-local generalization with kind
Alessandro Bruni [Wed, 27 Jan 2016 21:03:49 +0000 (00:03 +0300)]
GC_malloc[_atomic] global and thread-local generalization with kind

* include/gc_inline.h (GC_malloc_kind, GC_malloc_kind_global): New
public function declaration.
* include/gc_inline.h (GC_MALLOC_WORDS_KIND): New public macro.
* include/gc_inline.h (GC_MALLOC_WORDS, GC_MALLOC_ATOMIC_WORDS): Use
GC_MALLOC_WORDS_KIND.
* include/gc_inline.h (GC_CONS): Use GC_malloc_kind (instead of
GC_malloc); reformat code.
* include/private/gc_priv.h (MAXOBJKINDS): Allow user-defined values.
* include/private/gc_priv.h (GC_core_malloc, GC_core_malloc_atomic):
Remove prototype.
* malloc.c: Include gc_inline.h (to get GC_malloc_kind prototype).
* mallocx.c: Likewise.
* malloc.c (GC_generic_malloc_inner,
GC_generic_malloc_inner_ignore_off_page, GC_generic_malloc): Add
assertion on "k" (kind) argument (should be less than MAXOBJKINDS).
* mallocx.c (GC_generic_malloc_ignore_off_page,
GC_generic_malloc_many): Likewise.
* malloc.c (GC_generic_malloc_uncollectable): Add assertion on "k"
argument (should be less than PREDEFINED_KINDS).
* malloc.c (GC_core_malloc_atomic, GC_core_malloc): Replace with
GC_malloc_kind_global.
* malloc.c (GC_malloc_atomic, GC_malloc): Define as a wrapper around
GC_malloc_kind_global.
* malloc.c (GC_malloc_kind): Redirect to GC_malloc_kind_global if
not defined in gc_inline.h (as a macro) or in thread_local_alloc.c.
* mallocx.c (GC_generic_or_special_malloc): Call GC_malloc_kind
instead of GC_malloc_kind and GC_malloc.
* thread_local_alloc.c (GC_malloc, GC_malloc_atomic): Replace with
GC_malloc_kind; remove tiny_fl local variable; call
GC_malloc_kind_global instead of GC_core_malloc and
GC_core_malloc_atomic.
* thread_local_alloc.c (GC_destroy_thread_local): Adjust static assert
to guard against global _freelists overrun.

8 years agoGC_malloc_[atomic_]uncollectable generalization
Ivan Maidanski [Fri, 15 Jan 2016 09:48:06 +0000 (12:48 +0300)]
GC_malloc_[atomic_]uncollectable generalization

* include/gc_mark.h (GC_generic_malloc_uncollectable): New public
function declaration.
* malloc.c (GC_generic_malloc_uncollectable): New function
(imlementation mostly copied from GC_malloc_uncollectable).
* malloc.c (GC_malloc_uncollectable, GC_malloc_atomic_uncollectable,
calloc): Use GC_malloc_atomic_uncollectable.
* mallocx.c (GC_generic_or_special_malloc): Likewise.
* mallocx.c (GC_malloc_atomic_uncollectable): Move to malloc.c.

8 years agoRemove redundant comments in GC_obj_kinds
Ivan Maidanski [Fri, 15 Jan 2016 09:26:36 +0000 (12:26 +0300)]
Remove redundant comments in GC_obj_kinds

* mark.c (GC_obj_kinds): Remove comments duplicating code.

8 years agoFix typo in GC_malloc_uncollectable comment
Ivan Maidanski [Wed, 13 Jan 2016 08:34:56 +0000 (11:34 +0300)]
Fix typo in GC_malloc_uncollectable comment

* ChangeLog: Fix typo ("was").
* malloc.c (GC_malloc_uncollectable): Fix typo ("was") in comment.

8 years agoRefactoring of thread-local *_freelists
Alessandro Bruni [Tue, 12 Jan 2016 08:09:00 +0000 (11:09 +0300)]
Refactoring of thread-local *_freelists
(use single array to keep free lists except for GCJ and "finalized" kinds)

* include/private/thread_local_alloc.h (THREAD_FREELISTS_KINDS): New
macro.
* include/private/thread_local_alloc.h (thread_local_freelists):
Replace ptrfree_freelists and normal_freelists fields with
_freelists[]; define ptrfree_freelists and normal_freelists as macros
(they are used by some external clients, e.g., Mono).
* thread_local_alloc.c (GC_init_thread_local): Rename "i" local
variable to "j"; refine comment about zero-sized GCJ object; remove
loop unrolling (for zero index).
* thread_local_alloc.c (GC_init_thread_local, GC_destroy_thread_local,
GC_mark_thread_local_fls_for, GC_check_tls_for): Define "i" local
variable; replace ptrfree_freelists and normal_freelists with
_freelists[i].

8 years agoUpdate AUTHORS file
Ivan Maidanski [Mon, 11 Jan 2016 07:06:28 +0000 (10:06 +0300)]
Update AUTHORS file

8 years agoEnable build with musl libc
Michael Fox [Mon, 11 Jan 2016 07:01:34 +0000 (10:01 +0300)]
Enable build with musl libc

* include/private/gcconfig.h (NO_GETCONTEXT): Define if __gnu_linux__
undefined (in case of LINUX is defined).

8 years agoUpdate AUTHORS file
Ivan Maidanski [Tue, 5 Jan 2016 08:08:37 +0000 (11:08 +0300)]
Update AUTHORS file

8 years agoRefactoring of GC_Xobjfreelist
Alessandro Bruni [Tue, 5 Jan 2016 07:51:52 +0000 (10:51 +0300)]
Refactoring of GC_Xobjfreelist
(use single array to keep free lists of all kinds)

* alloc.c: Update comment (replace GC_objfreelist with
GC_freelists[NORMAL]).
* checksums.c (GC_on_free_list): Replace GC_sobjfreelist with
GC_freelists[STUBBORN].
* mark.c (GC_obj_kinds): Likewise.
* include/private/gc_priv.h (PTRFREE, NORMAL, UNCOLLECTABLE,
AUNCOLLECTABLE, STUBBORN, IS_UNCOLLECTABLE): Move definition upper to
be before _GC_arrays declaration.
* include/private/gc_priv.h (PREDEFINED_KINDS): New macro.
* include/private/gc_priv.h (GC_freelists): New macro (of global
variable if SEPARATE_GLOBALS).
* include/private/gc_priv.h (_GC_arrays): Replace _objfreelist,
_aobjfreelist, _uobjfreelist, _auobjfreelist, _sobjfreelist fields
with single _freelists[] field.
* include/private/gc_priv.h (GC_objfreelist, GC_aobjfreelist,
GC_auobjfreelist, GC_sobjfreelist, GC_uobjfreelist,
beginGC_objfreelist, endGC_objfreelist, beginGC_aobjfreelist,
endGC_aobjfreelist): Remove macro.
* include/private/gc_priv.h (GC_objfreelist, GC_aobjfreelist): Replace
variable declarations with single GC_freelists[] one (if
SEPARATE_GLOBALS).
* malloc.c (GC_malloc_atomic): Replace GC_aobjfreelist with
GC_freelists[PTRFREE].
* mallocx.c (GC_aobjfreelist_ptr): Likewise.
* mark.c (GC_obj_kinds): Likewise.
* thread_local_alloc.c (GC_destroy_thread_local): Likewise.
* malloc.c (GC_malloc): Replace GC_objfreelist with
GC_freelists[NORMAL].
* mallocx.c (GC_objfreelist_ptr): Likewise.
* mark.c (GC_obj_kinds): Likewise.
* thread_local_alloc.c (GC_destroy_thread_local): Likewise.
* malloc.c (GC_malloc_uncollectable): Replace GC_uobjfreelist with
GC_freelists[UNCOLLECTABLE].
* mallocx.c (GC_uobjfreelist_ptr): Likewise.
* mark.c (GC_obj_kinds): Likewise.
* mallocx.c (GC_auobjfreelist_ptr, GC_malloc_atomic_uncollectable):
Replace GC_auobjfreelist with GC_freelists[AUNCOLLECTABLE].
* mark.c (GC_obj_kinds): Likewise.
* misc.c (GC_init): Exclude whole GC_freelists from scanning instead
of beginGC_objfreelist and beginGC_aobjfreelist (if SEPARATE_GLOBALS).

8 years agoFix typo in comment of ERROR_FL
Ivan Maidanski [Wed, 30 Dec 2015 09:13:55 +0000 (12:13 +0300)]
Fix typo in comment of ERROR_FL

* include/private/thread_local_alloc.h (ERROR_FL): Fix typo in comment
("gcj_freelists").

8 years agoFix typos in gc_priv.h
Ivan Maidanski [Wed, 30 Dec 2015 05:44:18 +0000 (08:44 +0300)]
Fix typos in gc_priv.h

* include/private/gc_priv.h (CPP_MAXOBJBYTES): Add missing ')' in
comment.
* include/private/gc_priv.h (obj_kind.ok_freelist): Fix typo in
comment ("list headers").
* include/private/gc_priv.h (obj_kind.ok_freelist,
obj_kind.ok_reclaim_list): Reformat comment.

8 years agoFix undefined PTRFREE/NORMAL in gc_inline.h
Ivan Maidanski [Mon, 28 Dec 2015 17:24:33 +0000 (20:24 +0300)]
Fix undefined PTRFREE/NORMAL in gc_inline.h

Allow to use gc_inline.h public header without include gc_priv.h.

* include/gc_inline.h (GC_I_PTRFREE, GC_I_NORMAL): New macro.
* include/gc_inline.h (GC_FAST_MALLOC_GRANS, GC_MALLOC_WORDS,
GC_MALLOC_ATOMIC_WORDS, GC_CONS): Use GC_I_PTRFREE and GC_I_NORMAL
instead of PTRFREE and NORMAL (private macros), respectively.

8 years agoPrefix PREFETCH_FOR_WRITE with GC_ as used in gc_inline.h public header
Ivan Maidanski [Mon, 28 Dec 2015 16:11:43 +0000 (19:11 +0300)]
Prefix PREFETCH_FOR_WRITE with GC_ as used in gc_inline.h public header

* doc/porting.html: Rename PREFETCH_FOR_WRITE to GC_PREFETCH_FOR_WRITE.
* fnlz_mlc.c (GC_finalized_malloc): Likewise.
* include/gc_inline.h (GC_FAST_MALLOC_GRANS): Likewise.
* include/private/gcconfig.h: Likewise.
* new_hblk.c (GC_build_fl_clear4, GC_build_fl4, GC_build_fl): Likewise.
* include/gc_inline.h (GC_PREFETCH_FOR_WRITE): Define to no-op if
undefined.

8 years agoAllow GC_FAST_MALLOC_GRANS() multiple use in a function
Ivan Maidanski [Mon, 28 Dec 2015 15:34:57 +0000 (18:34 +0300)]
Allow GC_FAST_MALLOC_GRANS() multiple use in a function

Avoid goto statement in gc_inline.h public header (to fix
'duplicate label' compiler error in GC_FAST_MALLOC_GRANS if the macro
is used multiple times in a function).

* include/gc_inline.h (GC_FAST_MALLOC_GRANS): Replace goto with break

8 years agoWorkaround 'comparison is always false' GCC warning in GC_FAST_MALLOC_GRANS
Ivan Maidanski [Mon, 28 Dec 2015 14:49:54 +0000 (17:49 +0300)]
Workaround 'comparison is always false' GCC warning in GC_FAST_MALLOC_GRANS

* include/gc_inline.h (GC_FAST_MALLOC_GRANS): Refactoring of condition
expression for entry containing counter or is NULL to avoid
"comparison of unsigned expression < 0 is always false" warning
reported by GCC.

8 years agoUpdate AUTHORS file
Ivan Maidanski [Thu, 24 Dec 2015 20:46:56 +0000 (23:46 +0300)]
Update AUTHORS file

8 years agoFix CMake warning about CMP0054 by unquoting instances of HOST
Andrew Buss [Mon, 21 Dec 2015 10:20:01 +0000 (02:20 -0800)]
Fix CMake warning about CMP0054 by unquoting instances of HOST

See CMake v3.1 policy CMP0054.

* CMakeLists.txt: Use HOST variable without quotes.

8 years agoReturn GC_UNIMPLEMENTED instead of abort in GC_get_stack_base (OS/2)
Ivan Maidanski [Thu, 17 Dec 2015 18:25:16 +0000 (21:25 +0300)]
Return GC_UNIMPLEMENTED instead of abort in GC_get_stack_base (OS/2)

* os_dep.c (GC_get_stack_base): Replace ABORT (in case of
DosGetInfoBlocks failure) with WARN() and return GC_UNIMPLEMENTED.

8 years agoFix typo (items numbering) in GC_finalize_all documentation
Ivan Maidanski [Fri, 4 Dec 2015 08:20:41 +0000 (11:20 +0300)]
Fix typo (items numbering) in GC_finalize_all documentation

* include/javaxfc.h (GC_finalize_all): Fix 2nd item numbering in
comment.

8 years agoRemove references to missing linux_threads.c from documentation
Ivan Maidanski [Wed, 2 Dec 2015 21:08:02 +0000 (00:08 +0300)]
Remove references to missing linux_threads.c from documentation

* README.md (copyright): Change linux_threads.c to pthread_stop_world.c
and pthread_support.c files.
* doc/README.DGUX386: Remove reference to linux-threads.c file.
* doc/README.environment (GC_RETRY_SIGNALS, GC_NO_RETRY_SIGNALS):
Likewise.
* doc/gcdescr.html: Likewise.
* doc/README.DGUX386: Update information how to pass DEBUG_THREADS to
make.
* doc/gcdescr.html: Update threads support information for Irix and
Solaris.
* include/private/gc_locks.h: Remove reference to linux-threads.c in
a comment.
* pthread_support.c: Likewise.

8 years agoRemove documentation about obsolete GC_REDIRECT_TO_LOCAL
Ivan Maidanski [Tue, 1 Dec 2015 08:49:02 +0000 (11:49 +0300)]
Remove documentation about obsolete GC_REDIRECT_TO_LOCAL

* doc/scale.html (GC_REDIRECT_TO_LOCAL): Remove documentation.
* doc/simple_example.html (GC_REDIRECT_TO_LOCAL): Likewise.

8 years agoFix missing GC_get_stack_base for Amiga
Ivan Maidanski [Thu, 26 Nov 2015 20:24:38 +0000 (23:24 +0300)]
Fix missing GC_get_stack_base for Amiga

* os_dep.c (GET_MAIN_STACKBASE_SPECIAL): Define if AMIGA (which, in
turn, causes default GC_get_stack_base to be defined).

8 years agoRemove 'sig' argument of GC_suspend_handler_inner
Ivan Maidanski [Thu, 19 Nov 2015 22:22:39 +0000 (01:22 +0300)]
Remove 'sig' argument of GC_suspend_handler_inner
(Code refactoring)

* pthread_stop_world.c (GC_suspend_handler_inner): Rename "sig_arg"
argument to "dummy"; mark it as GC_ATTR_UNUSED.
* pthread_stop_world.c (GC_suspend_handler): Pass NULL instead of sig
to GC_suspend_handler_inner.
* pthread_stop_world.c (GC_suspend_handler): Move sig check from
GC_suspend_handler_inner.

8 years agoAllow specific TLS attributes for GC_thread_key
Ivan Maidanski [Tue, 17 Nov 2015 08:39:29 +0000 (11:39 +0300)]
Allow specific TLS attributes for GC_thread_key

* doc/README.macros (GC_ATTR_TLS_FAST): Document.
* include/private/thread_local_alloc.h (GC_ATTR_TLS_FAST): New macro
(empty by default).
* include/private/thread_local_alloc.h (GC_thread_key): Use
GC_ATTR_TLS_FAST.
* thread_local_alloc.c (GC_thread_key): Likewise.

8 years agoFix USE_COMPILER_TLS macro duplicate description in README
Ivan Maidanski [Tue, 17 Nov 2015 21:43:25 +0000 (00:43 +0300)]
Fix USE_COMPILER_TLS macro duplicate description in README

* doc/README.macros (USE_COMPILER_TLS): Remove duplicate description.

8 years agoDocument GC_register_my_thread returned value
Ivan Maidanski [Wed, 11 Nov 2015 08:20:21 +0000 (11:20 +0300)]
Document GC_register_my_thread returned value

* include/gc.h (GC_register_my_thread): Refine comment (about returned
value).

8 years agoAvoid unstructured procfs on Solaris
Rainer Orth [Thu, 27 Aug 2015 11:26:18 +0000 (11:26 +0000)]
Avoid unstructured procfs on Solaris
(Cherry-picked commit f9711f5 from 'gcc_boehmgc' branch.)

* os_dep.c [PROC_VDB] (GC_dirty_init): Use /proc/<pid>/pagedata
instead of PIOCOPENPD; remove fd local variable; increase buf[] size.

8 years agoDo no declare kernel_id field of GC_Thread_Rep for 64-bit Android
Ivan Maidanski [Thu, 29 Oct 2015 21:08:44 +0000 (00:08 +0300)]
Do no declare kernel_id field of GC_Thread_Rep for 64-bit Android

* include/private/pthread_support.h (GC_Thread_Rep): Do not declare
kernel_id field unless USE_TKILL_ON_ANDROID (instead of
PLATFORM_ANDROID).
* pthread_support.c (GC_new_thread, GC_remove_all_threads_but_me): Do
not set kernel_id field unless USE_TKILL_ON_ANDROID.

8 years agoABORT_ARGn log details at INFO level (Android)
Ivan Maidanski [Mon, 26 Oct 2015 21:08:01 +0000 (00:08 +0300)]
ABORT_ARGn log details at INFO level (Android)

* include/private/gc_priv.h (ABORT_ARG1, ABORT_ARG2, ABORT_ARG3): Use
GC_INFOLOG_PRINTF instead of GC_COND_LOG_PRINTF.

8 years agoRemove item from TODO file about resuming parallel markers
Ivan Maidanski [Mon, 26 Oct 2015 05:29:32 +0000 (08:29 +0300)]
Remove item from TODO file about resuming parallel markers

8 years agoCheck DATASTART is less than DATAEND even assertions off
Ivan Maidanski [Mon, 26 Oct 2015 05:25:54 +0000 (08:25 +0300)]
Check DATASTART is less than DATAEND even assertions off

* dyn_load.c (GC_register_dynamic_libraries_dl_iterate_phdr):
Abort with the appropriate message if DATASTART is NULL or greater than
DATAEND (same for DATASTART2 and DATAEND2).
* os_dep.c (GC_init_linux_data_start, GC_register_data_segments):
Likewise.
* os_dep.c (GC_init_linux_data_start, GC_register_data_segments):
Remove assertion about DATASTART and DATAEND.
* os_dep.c (GC_init_linux_data_start): Code refactoring.

8 years agoWorkaround invalid '_end' symbol on Android clang 3.5+
Ivan Maidanski [Fri, 23 Oct 2015 09:24:21 +0000 (12:24 +0300)]
Workaround invalid '_end' symbol on Android clang 3.5+

* include/gc.h (GC_INIT_CONF_ROOTS): Handle Android clang (3.5-3.6)
case when "_end" symbol has incorrect address but "__end__" is defined
(by bfd linker only); declare "__end__" symbol as weak.
* include/private/gcconfig.h (DATAEND): Redefine for Android/clang;
define __end__ as weak symbol.
* os_dep.c (_end): Remove declaration (declared in gcconfig.h).
* os_dep.c (GC_init_linux_data_start): Define new local variable
(data_end); set it to DATAEND; use it instead of _end.

8 years agoFix lock assert violation in GC_gcollect_inner if GC_ALWAYS_MULTITHREADED
Ivan Maidanski [Wed, 21 Oct 2015 23:50:00 +0000 (02:50 +0300)]
Fix lock assert violation in GC_gcollect_inner if GC_ALWAYS_MULTITHREADED

* alloc.c (GC_expand_hp): Do not hold the allocation lock when calling
GC_init.
* malloc.c (GC_alloc_large, GC_generic_malloc_inner): Likewise.
* mallocx.c (GC_generic_malloc_many): Likewise.
* misc.c (GC_enable_incremental): Likewise.
* misc.c (GC_init): Surround GC_gcollect_inner call with LOCK/UNLOCK
(only if GC_ASSERTIONS and GC_ALWAYS_MULTITHREADED otherwise
redundant).

8 years agoWorkaround 'unresolved __tls_get_addr' error for Android NDK Clang
Ivan Maidanski [Wed, 21 Oct 2015 23:01:33 +0000 (02:01 +0300)]
Workaround 'unresolved __tls_get_addr' error for Android NDK Clang

* include/private/thread_local_alloc.h (USE_COMPILER_TLS): Do not
define for Android Clang (any CPU arch); update comment.

8 years agoAdd assertion on lock status to GC_alloc_large and its callers
Ivan Maidanski [Wed, 21 Oct 2015 22:52:39 +0000 (01:52 +0300)]
Add assertion on lock status to GC_alloc_large and its callers
(code refactoring)

* alloc.c (GC_try_to_collect_inner): Remove comment about expected
lock status; add assertion about holding the allocation lock.
* finalize.c (GC_grow_table): Likewise.
* malloc.c (GC_alloc_large, GC_alloc_large_and_clear,
GC_generic_malloc_inner, GC_generic_malloc_inner_ignore_off_page):
Likewise.
* misc.c (GC_new_free_list_inner): Likewise.

8 years agoFix lock assertion violation in GC_new_thread if GC_ALWAYS_MULTITHREADED
Ivan Maidanski [Tue, 20 Oct 2015 21:48:56 +0000 (00:48 +0300)]
Fix lock assertion violation in GC_new_thread if GC_ALWAYS_MULTITHREADED

* include/private/gc_priv.h (GC_start_mark_threads_inner): Define macro
(or declare function depending on CAN_HANDLE_FORK).
* misc.c (GC_init): Surround GC_thr_init call with LOCK/UNLOCK (only
if GC_ASSERTIONS and GC_ALWAYS_MULTITHREADED otherwise redundant);
call GC_start_mark_threads_inner (if PARALLEL_MARK).
* pthread_support.c (GC_mark_thread): Update comment.
* win32_threads.c (GC_mark_thread): Likewise.
* pthread_support.c (start_mark_threads): Remove macro (moved to
gc_priv.h); rename function to GC_start_mark_threads_inner; replace
"static" to GC_INNER; check assertion on GC_fl_builder_count only if
the markers should actually be started; move the check for disabled
parallel markers (available_markers_m1) from GC_thr_init (make it
unconditional).
* win32_threads.c (start_mark_threads): Likewise.
* win32_threads.c (GC_start_mark_threads_inner): Add assertion about
the lock status.
* pthread_support.c (GC_thr_init): Remove comment about expected lock
status; add assertion about holding the lock (duplicating that in
GC_new_thread); remove start_mark_threads call (moved to GC_init).
* win32_threads.c (GC_thr_init): Likewise.

8 years agoConsistently set type of DATASTART/END to ptr_t
Ivan Maidanski [Thu, 15 Oct 2015 22:38:08 +0000 (01:38 +0300)]
Consistently set type of DATASTART/END to ptr_t
(code refactoring)

* dyn_load.c (GC_register_map_entries,
GC_register_dynamic_libraries_dl_iterate_phdr): Remove redundant
casting to ptr_t of DATASTART, DATAEND, DATAEND2.
* os_dep.c (GC_register_data_segments): Likewise.
* include/private/gcconfig.h (DATAEND, DATASTART): Add cast to ptr_t
where missing.

8 years agoConsistently use outermost parentheses for DATASTART/END, STACKBOTTOM
Ivan Maidanski [Thu, 15 Oct 2015 20:49:06 +0000 (23:49 +0300)]
Consistently use outermost parentheses for DATASTART/END, STACKBOTTOM
(code refactoring)

* include/private/gcconfig.h (DATASTART, DATAEND, STACKBOTTOM,
DATAEND2): Add outermost parentheses where missing; remove space in
cast.

8 years agoNaCl/arm initial support
Elijah Taylor [Thu, 31 Jan 2013 22:00:58 +0000 (14:00 -0800)]
NaCl/arm initial support
(Apply part of commit 21f0df7 from 'mono_libgc' branch.)

Conflicts:
* include/private/gc_locks.h
* include/private/gcconfig.h
* pthread_stop_world.c

8 years agoNaCl runtime fixes
Elijah Taylor [Thu, 31 Jan 2013 20:04:20 +0000 (12:04 -0800)]
NaCl runtime fixes
(Apply commit b328e88 from 'mono_libgc' branch.)

* fix compile/runtime issues caused by upstream changes
* add NaCl glibc support
* various changes to support running tests in NaCl glibc
from 'make check'

Conflicts:
* dyn_load.c
* include/private/gcconfig.h
* misc.c
* pthread_stop_world.c
* pthread_support.c

8 years agoNaCl GC improvements (fix volatile for vars accessed by syscall hooks)
Elijah Taylor [Thu, 31 Jan 2013 20:48:49 +0000 (12:48 -0800)]
NaCl GC improvements (fix volatile for vars accessed by syscall hooks)
(Apply part of commit 204bcc6 from 'mono_libgc' branch.)

Conflicts:
* pthread_stop_world.c
* pthread_support.c

8 years agoDefine GC_LINUX_THREADS, NO_EXECUTE_PERMISSION in configure for NaCl
Elijah Taylor [Fri, 17 Dec 2010 00:26:34 +0000 (16:26 -0800)]
Define GC_LINUX_THREADS, NO_EXECUTE_PERMISSION in configure for NaCl
(Apply part of commit 14b353e from 'mono_libgc' branch.)

* configure.ac: Handle *-*-nacl* (define GC_LINUX_THREADS and
NO_EXECUTE_PERMISSION).

8 years agoFix gc.mak regarding msvc_dbg and test (MSVC)
Ivan Maidanski [Wed, 30 Sep 2015 21:46:06 +0000 (00:46 +0300)]
Fix gc.mak regarding msvc_dbg and test (MSVC)

* gc.mak (CLEAN, BSC32_SBRS, LINK32_OBJS): Rename msvc_dbg.* to
msvc_dbg.copied.* file names.
* gc.mak (CLEAN): Erase msvc_dbg.copied.c, test.copied.c.
* gc.mak (msvc_dbg.copied.c): New rule.
* gc.mak (CLEAN, LINK32_OBJS, BSC32_SBRS, test.c): Rename test.* to
test.copied.* file names.
* gc.mak (CPP_PROJ): Add /D for "ALL_INTERIOR_POINTERS".

8 years ago.gitignore: Ignore .copied.c, .dll.manifest, idb, ilk files (MSVC)
Ivan Maidanski [Wed, 23 Sep 2015 07:43:53 +0000 (10:43 +0300)]
.gitignore: Ignore .copied.c, .dll.manifest, idb, ilk files (MSVC)

8 years agoFix race (and potential deadlock) at marker threads initialization
Ivan Maidanski [Tue, 22 Sep 2015 05:42:40 +0000 (08:42 +0300)]
Fix race (and potential deadlock) at marker threads initialization

* include/private/gc_priv.h (GC_wait_for_markers_init): New prototype.
* mark.c (GC_wait_for_markers_init): New function (if PARALLEL_MARK).
* pthread_support.c (GC_mark_thread): Notify start_mark_threads()
about completion of marker data initialization.
* win32_threads.c (GC_mark_thread): Likewise.
* pthread_support.c (start_mark_threads): Add assertion about
GC_fl_builder_count; call GC_wait_for_markers_init.
* win32_threads.c (start_mark_threads): Likewise.
* win32_threads.c (GC_mark_thread): Reformat code.

8 years agoFix 'value truncated' compiler warning in CORD_cat (MS VC)
Ivan Maidanski [Fri, 18 Sep 2015 22:26:36 +0000 (01:26 +0300)]
Fix 'value truncated' compiler warning in CORD_cat (MS VC)

* cord/cordbscs.c (CORD_cat_char_star, CORD_cat): Cast "lenx" to
unsigned char (to workaround false compiler warning about value
truncation).

8 years agoFix compilation for Android clang/arm with bfd linker
Ivan Maidanski [Wed, 16 Sep 2015 22:18:36 +0000 (01:18 +0300)]
Fix compilation for Android clang/arm with bfd linker

* include/private/thread_local_alloc.h (USE_COMPILER_TLS): Do not
define if ARM32 (and PLATFORM_ANDROID and __clang__); update comment.

8 years agoEnable thread-local storage for Android Clang
Ivan Maidanski [Wed, 16 Sep 2015 09:14:34 +0000 (12:14 +0300)]
Enable thread-local storage for Android Clang

* include/private/thread_local_alloc.h (USE_COMPILER_TLS): Define for
Android NDK clang3.6+ arm/arm64/x86/x86_64 (NDK r10e); update comment.

8 years agowindows-untested: Fix paths to msvc_dbg.c/h
Ivan Maidanski [Tue, 15 Sep 2015 07:49:01 +0000 (10:49 +0300)]
windows-untested: Fix paths to msvc_dbg.c/h

* windows-untested/vc60/gc.dsp (SOURCE): Fix paths to msvc_dbg.c and
msvc_dbg.h.
* windows-untested/vc60/libgc.dsp (SOURCE): Likewise.
* windows-untested/vc60/libgcmt.dsp (SOURCE): Likewise.
* windows-untested/vc60/libgcmt.dsp (File RelativePath): Likewise.
* windows-untested/vc70/libgc.vcproj (File RelativePath): Likewise.
* windows-untested/vc70/libgcmt.vcproj (File RelativePath): Likewise.
* windows-untested/vc71/gc.vcproj (File RelativePath): Likewise.
* windows-untested/vc71/libgc.vcproj (File RelativePath): Likewise.
* windows-untested/vc71/libgcmt.vcproj (File RelativePath): Likewise.

8 years agoUpdate AUTHORS file
Ivan Maidanski [Tue, 15 Sep 2015 07:15:35 +0000 (10:15 +0300)]
Update AUTHORS file

8 years agoFix typos in README for ews4800
Terrell Russell [Mon, 14 Sep 2015 18:48:41 +0000 (14:48 -0400)]
Fix typos in README for ews4800

* doc/README.ews4800: Fix typos ("information", "vendor", "the").

8 years agoUpdate compiler options in gc.mak (Win32)
Ivan Maidanski [Mon, 14 Sep 2015 08:25:03 +0000 (11:25 +0300)]
Update compiler options in gc.mak (Win32)

* gc.mak (CFG): Fix info about default configuration.
* gc.mak (CPP_PROJ): Replace deprecated /GX option with /EHsc; remove
deprecated /YX option; add /D _CRT_SECURE_NO_DEPRECATE option (to
suppress warning about vsprintf usage).

8 years ago.gitignore: Ignore .exp and .sbr also in subfolders (MSVC)
Ivan Maidanski [Mon, 14 Sep 2015 07:41:44 +0000 (10:41 +0300)]
.gitignore: Ignore .exp and .sbr also in subfolders (MSVC)

8 years agoTurn off sigsetjmp workaround for Android/x86 starting from NDK r8e
Ivan Maidanski [Fri, 11 Sep 2015 08:57:54 +0000 (11:57 +0300)]
Turn off sigsetjmp workaround for Android/x86 starting from NDK r8e

* include/private/gcconfig.h (GC_NO_SIGSETJMP): Do not define for
Android/x86 if NDK r8e+; update comment.

8 years agoFix abort message in GC_move_long_link
Ivan Maidanski [Thu, 10 Sep 2015 23:16:42 +0000 (02:16 +0300)]
Fix abort message in GC_move_long_link

* finalize.c (GC_move_long_link): Fix function name in abort message.

8 years agoFix 'comparison of non-null parameter is always false' warning (Clang)
Ivan Maidanski [Thu, 10 Sep 2015 08:48:05 +0000 (11:48 +0300)]
Fix 'comparison of non-null parameter is always false' warning (Clang)

* alloc.c (GC_set_stop_func, GC_try_to_collect): Use
NONNULL_ARG_NOT_NULL to check argument marked as non-null (in
function declaration) is actually non-null.
* finalize.c (GC_general_register_disappearing_link,
GC_register_long_link, GC_move_disappearing_link, GC_move_long_link):
Likewise.
* misc.c (GC_set_warn_proc, GC_set_abort_func, GC_set_oom_fn): Likewise.
* include/private/gc_priv.h (NONNULL_ARG_NOT_NULL): New macro.

8 years agoAllow fork() automatic handling on Android with API level 21+
Ivan Maidanski [Thu, 10 Sep 2015 07:32:52 +0000 (10:32 +0300)]
Allow fork() automatic handling on Android with API level 21+

* include/private/gcconfig.h (CAN_CALL_ATFORK): Define also if
__ANDROID_API__ >= 21.

8 years agoConsistently use int[] type for '_end' symbol
Ivan Maidanski [Thu, 10 Sep 2015 07:23:00 +0000 (10:23 +0300)]
Consistently use int[] type for '_end' symbol
(code refactoring)

* include/private/gcconfig.h (_end): Change char[] type to int[] (for
remaining entries).

8 years agoWorkaround 'sa_sigaction member missing' compiler error (Android/x32)
Ivan Maidanski [Wed, 9 Sep 2015 22:36:30 +0000 (01:36 +0300)]
Workaround 'sa_sigaction member missing' compiler error (Android/x32)

Client should define NO_SA_SIGACTION to enable the workaround.

* include/private/gcconfig.h (NO_SA_SIGACTION): New macro (explicitly
define if SA_SIGINFO undefined).
* include/private/gcconfig.h (MPROTECT_VDB): Undefine if
NO_SA_SIGACTION unless DARWIN, MSWIN32 or MSWINCE.
* pthread_stop_world.c (GC_suspend_handler, GC_stop_init): Check
NO_SA_SIGACTION instead of SA_SIGINFO.

8 years agoSupport build for Android 64-bit (arm64, mips64, x86_64)
Ivan Maidanski [Wed, 9 Sep 2015 21:15:22 +0000 (00:15 +0300)]
Support build for Android 64-bit (arm64, mips64, x86_64)

* include/private/gcconfig.h (_end): Replace type from char[] to int[]
to avoid redefinition error (as it is also declared in gc.h) for
Linux/x86_64.
* include/private/gcconfig.h (NO_GETCONTEXT): Define for all Android
targets.
* include/private/gcconfig.h (USE_TKILL_ON_ANDROID): New macro
(defined only for 32-bit Android targets).
* pthread_stop_world.c (tkill, android_thread_kill, GC_suspend_all,
GC_start_world): Use USE_TKILL_ON_ANDROID instead of PLATFORM_ANDROID.

8 years agoFix 'cast to pointer from integer' warning in GC_on_thread_event (64-bit)
Ivan Maidanski [Wed, 9 Sep 2015 20:55:37 +0000 (23:55 +0300)]
Fix 'cast to pointer from integer' warning in GC_on_thread_event (64-bit)

* pthread_stop_world.c (GC_suspend_all, GC_start_world): Cast thread_id
to pointer via word type on passing to GC_on_thread_event; add comment.

8 years agoSupport Android API level 21
Ivan Maidanski [Wed, 9 Sep 2015 08:42:43 +0000 (11:42 +0300)]
Support Android API level 21
(fix 'link_map redefinition' error on Android with API level 21+)

* dyn_load.c (link_map, r_debug): Do not define if android-21 (or
higher) API is used; update comment.

8 years agoFix (allow) thread local allocations from within pthread TLS destructors
Niklas Therning [Tue, 6 Jan 2015 22:32:43 +0000 (23:32 +0100)]
Fix (allow) thread local allocations from within pthread TLS destructors

Prevents the GC_thread_key from being cleared on thread exit until
after the thread has been unregistered by GC_unregister_my_thread_inner.

* include/private/thread_local_alloc.h (GC_remove_specific): Call
pthread_setspecific(key, NULL) if USE_PTHREAD_SPECIFIC; update comment.
* thread_local_alloc.c (reset_thread_key): New static function if
USE_PTHREAD_SPECIFIC); define (as macro) to 0 otherwise.
* thread_local_alloc.c (GC_init_thread_local): Pass reset_thread_key
(instead of 0) to GC_key_create.

8 years agoFix 'visibility attribute not supported' GCC warning (IBM AIX)
Ivan Maidanski [Wed, 2 Sep 2015 08:52:30 +0000 (11:52 +0300)]
Fix 'visibility attribute not supported' GCC warning (IBM AIX)

* configure.ac (enable_shared): Add -D GC_NO_VISIBILITY to CFLAGS if
not ac_cv_fvisibility_hidden.
* include/cord.h (CORD_API): Do not use visibility attribute if
GC_NO_VISIBILITY.
* include/gc_config_macros.h (GC_API): Likewise.
* include/private/gc_priv.h (GC_INNER, GC_API_OSCALL): Likewise.

8 years agoMerge branch 'toggleref'
Ivan Maidanski [Tue, 1 Sep 2015 06:59:25 +0000 (09:59 +0300)]
Merge branch 'toggleref'

8 years agoFix data race in GC_init_explicit_typing
Ivan Maidanski [Tue, 1 Sep 2015 06:57:38 +0000 (09:57 +0300)]
Fix data race in GC_init_explicit_typing

* typd_mlc.c: Force include atomic_ops.h if
GC_FORCE_INCLUDE_ATOMIC_OPS (by default it is included if
PARALLEL_MARK or pthreads are used).
* typd_mlc.c (GC_explicit_typing_initialized): Use AO_t if
AO_load_acquire() available.
* typd_mlc.c (GC_init_explicit_typing): Move locking (and
GC_explicit_typing_initialized access) outside to the caller
(GC_make_descriptor); remove comment; remove "register" keyword for
local variable.
* typd_mlc.c (GC_make_descriptor): Use AO_load_acquire (if available)
to fetch GC_explicit_typing_initialized value (to avoid data race and
avoid lock acquiring on each call).
* typd_mlc.c (GC_explicit_typing_initialized,
GC_malloc_explicitly_typed_ignore_off_page,
GC_calloc_explicitly_typed): Add assertion on
GC_explicit_typing_initialized is true.

8 years agoSupport FreeBSD/mips
Carlos J. Puga Medina [Sat, 29 Aug 2015 06:21:26 +0000 (09:21 +0300)]
Support FreeBSD/mips

* include/private/gcconfig.h (MIPS, mach_type_known, OS_TYPE,
ALIGNMENT, MPROTECT_VDB, SIG_SUSPEND, SIG_THR_RESTART, DYNAMIC_LOADING,
DATASTART_USES_BSDGETDATASTART): Define for FreeBSD/mips.
* os_dep.c (CODE_OK): Define to si->si_code==SEGV_ACCERR for
FreeBSD/mips.

8 years agoReduce GCToggleRef size twice (convert struct to union)
Ivan Maidanski [Fri, 28 Aug 2015 20:21:23 +0000 (23:21 +0300)]
Reduce GCToggleRef size twice (convert struct to union)

* finalize.c (GCToggleRef): Replace struct with union; update comment.
* finalize.c (GC_process_togglerefs): Check lowest bit of strong_ref
to select between strong_ref and weak_ref.
* finalize.c (GC_mark_togglerefs, GC_clear_togglerefs): Likewise.
* finalize.c (GC_process_togglerefs): Store only strong_ref or
weak_ref to GC_toggleref_arr elements.
* finalize.c (GC_toggleref_add): Likewise.

8 years agoCode refactoring of toggle-ref support
Ivan Maidanski [Thu, 27 Aug 2015 22:37:33 +0000 (01:37 +0300)]
Code refactoring of toggle-ref support

* alloc.c (GC_stopped_mark): Move GC_process_togglerefs() call from
GC_stop_world; do not call it if GC_NO_FINALIZATION or
GC_TOGGLE_REFS_NOT_NEEDED.
* darwin_stop_world.c (GC_stop_world): Remove GC_process_togglerefs()
call.
* pthread_stop_world.c (GC_stop_world): Likewise.
* doc/README.macros (GC_TOGGLE_REFS_NOT_NEEDED): Document.
* finalize.c (GCToggleRef, GC_process_togglerefs, push_and_mark_object,
GC_clear_togglerefs, GC_toggleref_add): Replace GC_PTR with void*.
* include/gc.h (GC_toggleref_add): Likewise.
* finalize.c (GCToggleRef, GC_toggleref_callback, GC_toggleref_arr,
GC_toggleref_array_size, GC_toggleref_array_capacity,
GC_process_togglerefs, push_and_mark_object, GC_mark_togglerefs,
GC_clear_togglerefs, GC_set_toggleref_func, ensure_toggleref_capacity,
GC_toggleref_add): Do not defined if GC_TOGGLE_REFS_NOT_NEEDED.
* finalize.c (GCToggleRef): Add comment.
* finalize.c (GC_toggleref_array): Rename to GC_toggleref_arr.
* finalize.c (GC_toggleref_callback, GC_toggleref_array,
GC_toggleref_array_size, GC_toggleref_array_capacity): Make it STATIC
(instead "static").
* finalize.c (GC_process_togglerefs): Decorate with GC_INNER; remove
"toggle_ref_counts", "res" local variables; rename "w" local variable
to "new_size"; add assertion on lock state; use GC_TOGGLE_REF_* enum
element in switch statement; use BZERO to clear moved elements of
GC_toggleref_arr.
* finalize.c (GC_normal_finalize_mark_proc): Declare (before use).
* finalize.c (push_and_mark_object): Replace PUSH_OBJ with
GC_normal_finalize_mark_proc call.
* finalize.c (GC_mark_togglerefs, GC_clear_togglerefs): Remove
"object" local variable.
* finalize.c (GC_toggleref_register_callback): Rename to
GC_set_toggleref_func; change argument to GC_toggleref_func (which
returns GC_ToggleRefStatus instead of int).
* finalize.c (GC_toggleref_register_callback, GC_toggleref_add):
Decorate with GC_API and GC_CALL.
* include/gc.h (GC_toggleref_register_callback): Likewise.
* finalize.c (GC_set_toggleref_func): Acquire allocation lock.
* finalize.c (GC_get_toggleref_func): New API function.
* finalize.c (ensure_toggleref_capacity): Rename "capacity" argument
to "capacity_inc"; add assertion on argument value; rename "tmp" local
variable to "new_array"; remove unused "old_capacity" variable; replace
memcpy() with BCOPY() call.
* finalize.c (GC_toggleref_add): Rename "strong_ref" argument to
"is_strong_ref".
* finalize.c (GC_finalize): Do not call GC_clear_togglerefs and
GC_mark_togglerefs if GC_TOGGLE_REFS_NOT_NEEDED.
* include/gc.h (GC_ToggleRefStatus, GC_toggleref_func): New type.
* include/gc.h (GC_toggleref_register_callback): Add comment
(including about locking).
* include/gc.h (GC_get_toggleref_func): New API function declaration.
* include/gc.h (GC_toggleref_add): Decorate with GC_CALL; add comment;
add GC_ATTR_NONNULL attribute.
* include/private/gc_priv.h (GC_process_togglerefs): Do not declare if
GC_TOGGLE_REFS_NOT_NEEDED; decorate with GC_INNER.

8 years agoFix out-of-memory handling in GC_toggleref_add
Ivan Maidanski [Tue, 25 Aug 2015 07:19:05 +0000 (10:19 +0300)]
Fix out-of-memory handling in GC_toggleref_add

* finalize.c (ensure_toggleref_capacity): Change return type from void
to GC_bool; return FALSE on allocation failure (or desired capacity
value overflow).
* finalize.c (GC_toggleref_add): Change return type from void to int.
* include/gc.h (GC_toggleref_add): Likewise.
* finalize.c (GC_toggleref_add): Return GC_NO_MEMORY if
ensure_toggleref_capacity failed, GC_SUCCESS otherwise (including the
case of no callback).

8 years agoFix clearing of moved toggle-refs array elements
Ivan Maidanski [Fri, 14 Aug 2015 07:29:48 +0000 (10:29 +0300)]
Fix clearing of moved toggle-refs array elements

* finalize.c (GC_process_togglerefs): Replace "w" to "i" local variable
in the loop which clears unused part of GC_toggleref_array.

8 years agoFix memory management for toggle-ref
Rodrigo Kumpera [Thu, 13 Mar 2014 22:47:26 +0000 (18:47 -0400)]
Fix memory management for toggle-ref
(Apply commit 960f233 from 'mono_libgc' branch.)

Replace GC_free with GC_INTERNAL_FREE. The former might take the GC lock
and deadlock us.

Replace GC_INTERNAL_MALLOC with GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE as
we don't need the rest of the GC messing around with the toggleref array.

8 years agoAdd toggle-ref support
Rodrigo Kumpera [Wed, 26 Feb 2014 17:14:39 +0000 (12:14 -0500)]
Add toggle-ref support
(Apply commit af75406 from 'mono_libgc' branch.)

GC backed toggleref machinery.  This enables
an embedder to support toggleref style of external memory management
without hooking up to the host retain/release machinery.
The API export two entry points.  The first let the caller register
a callback that decides the state of a given object, by
probably inspecting its native state.  The second allows registration
of objects with the toggleref machinery.
The idea of toggleref is that we keep an external reference to an
object and it can be  either a strong or weak reference.  We use
a weak reference when the external peer has no interest into the
object and a strong otherwise.

8 years agoMark fo_head, finalize_now with a single GC_push_all call
Ivan Maidanski [Wed, 19 Aug 2015 07:23:36 +0000 (10:23 +0300)]
Mark fo_head, finalize_now with a single GC_push_all call
(code refactoring)

* finalize.c (GC_fnlz_roots): New static variable.
* finalize.c (GC_fo_head, GC_finalize_now): Move into GC_fnlz_roots
(remove "GC_" prefix for field names).
* finalize.c (GC_push_finalizer_structures): Replace GC_ASSERT and
GC_PUSH_ALL_SYM for GC_fo_head, GC_finalize_now with a single
GC_ASSERT and GC_PUSH_ALL_SYM for GC_fnlz_roots.
* finalize.c (GC_register_finalizer_inner,
GC_register_finalizer_unreachable, GC_finalize,
GC_should_invoke_finalizers, GC_invoke_finalizers,
GC_notify_or_invoke_finalizers): Replace access to GC_fo_head,
GC_finalize_now with access to the corresponding field of
GC_fnlz_roots.

8 years agoCode refactoring of GC_push_finalizer/thread/typed_structures
Ivan Maidanski [Mon, 17 Aug 2015 11:32:19 +0000 (14:32 +0300)]
Code refactoring of GC_push_finalizer/thread/typed_structures

* finalize.c (GC_push_finalizer_structures): Replace GC_push_all with
GC_PUSH_ALL_SYM invocation.
* pthread_support.c (GC_push_thread_structures): Likewise.
* typd_mlc.c (GC_push_typed_structures_proc): Likewise.
* win32_threads.c (GC_push_thread_structures): Likewise.
* include/private/gc_priv.h (GC_PUSH_ALL_SYM): New macro (handy one to
push a symbol content).

8 years agoGC_make_descriptor code refactoring (eliminate two local variables)
Ivan Maidanski [Mon, 17 Aug 2015 11:47:58 +0000 (14:47 +0300)]
GC_make_descriptor code refactoring (eliminate two local variables)

* typd_mlc.c (GC_make_descriptor): Remove "all_bits_set", "index"
local variables; collapse "return result" statements.

8 years agoFix exporting of GC_push_finalizer_structures
Ivan Maidanski [Fri, 7 Aug 2015 18:35:14 +0000 (21:35 +0300)]
Fix exporting of GC_push_finalizer_structures

* finalize.c (GC_push_finalizer_structures): Use GC_API, GC_CALL
instead of GC_INNER (to match that of gc_mark.h).

8 years agoFix exporting of GC_push_all_eager
Ivan Maidanski [Fri, 7 Aug 2015 18:00:36 +0000 (21:00 +0300)]
Fix exporting of GC_push_all_eager

* include/gc_mark.h (GC_push_all_eager): Move comment from gc_priv.h.
* include/private/gc_priv.h (GC_push_all_eager): Remove (because has
it might have calling conventions different from that in gc.h).

8 years agoDistinct long-link table growth log message
Ivan Maidanski [Tue, 4 Aug 2015 22:43:46 +0000 (01:43 +0300)]
Distinct long-link table growth log message

* finalize.c (GC_register_disappearing_link_inner): Add tbl_log_name
argument and pass it to GC_COND_LOG_PRINTF (instead of "dl" name).
* finalize.c (GC_general_register_disappearing_link,
GC_register_long_link): Pass corresponding link hashtable short name
("dl" or "long dl") to GC_register_disappearing_link_inner.

8 years agoUpdate AUTHORS file
Ivan Maidanski [Tue, 4 Aug 2015 22:28:52 +0000 (01:28 +0300)]
Update AUTHORS file

8 years agoMake heap walker accept callback
Ivan Maidanski [Tue, 4 Aug 2015 22:20:32 +0000 (01:20 +0300)]
Make heap walker accept callback

* alloc.c (GC_mercury_callback_reachable_object): Remove.
* include/gc.h (GC_mercury_callback_reachable_object): Likewise.
* include/private/gc_priv.h (GC_mercury_enumerate_reachable_objects):
Likewise.
* alloc.c (GC_finish_collection): Do not call
GC_mercury_enumerate_reachable_objects.
* include/gc_mark.h (GC_reachable_object_proc): New public typedef.
* include/gc_mark.h (GC_enumerate_reachable_objects_inner): New API
function declaration.
* reclaim.c (enumerate_reachable_s): New struct type.
* reclaim.c (GC_mercury_do_enumerate_reachable_objects): Rename to
GC_do_enumerate_reachable_objects; replace while() with for(); use 2nd
argument to pass client callback and custom data; call client callback
(passed via the argument) instead of
GC_mercury_callback_reachable_object; pass object size in bytes
instead of words to client callback.
* reclaim.c (GC_mercury_enumerate_reachable_objects): Rename to
GC_enumerate_reachable_objects_inner; decorate with GC_API/GC_CALL;
add 2 arguments (client callback and custom data); remove assertion
for GC_mercury_callback_reachable_object; add assertion for acquired
lock.
* tests/test.c: Include gc_mark.h unconditionally.
* tests/test.c (reachable_objs_counter,
reachable_objs_count_enumerator): New function.
* tests/test.c (check_heap_stats): New local variable "obj_count";
invoke GC_call_with_alloc_lock(reachable_objs_count_enumerator);
print final number of reachable objects.

9 years agoAdd support for enumerating the reachable objects in the heap
Peter Wang [Mon, 16 Jun 2014 11:05:05 +0000 (21:05 +1000)]
Add support for enumerating the reachable objects in the heap
(Apply part of commit dbf2db8 from 'paulbone/mercury7_4_pbone' branch.)

This can be used to do heap profiling, helping the developer work out which
objects are live or what kinds of objects account for a lot of their heap
space.

* alloc.c:
* include/gc.h:
* include/private/gc_priv.h:
* reclaim.c:
    As above.

9 years agoReplace non-API occurrences of GC_word to word
Ivan Maidanski [Tue, 28 Jul 2015 08:20:44 +0000 (11:20 +0300)]
Replace non-API occurrences of GC_word to word
(code refactoring)

* finalize.c (last_finalizer_notification): Use "word" type instead of
GC_word.
* include/private/dbg_mlc.h (HIDE_BACK_PTR): Likewise.
* include/private/gc_priv.h (WARN): Likewise.
* include/private/gcconfig.h (POINTER_MASK): Likewise.
* mark.c (GC_push_marked): Likewise.
* misc.c (GC_init, GC_set_max_retries): Likewise.
* os_dep.c (GC_unmap, GC_remap, GC_unmap_gap): Likewise.
* typd_mlc.c (GC_add_ext_descriptor): Likewise.
* include/private/gcconfig.h (GC_amiga_get_mem, ps3_get_mem): Rename
argument to bytes.

9 years agoCode refactoring of 'alt-stack registration support'
Ivan Maidanski [Mon, 27 Jul 2015 07:34:35 +0000 (10:34 +0300)]
Code refactoring of 'alt-stack registration support'

* darwin_stop_world.c (GC_stack_range_for, GC_push_all_stacks):
Reformat code dealing with alt-stack.
* pthread_stop_world.c (GC_push_all_stacks): Likewise.
* darwin_stop_world.c (GC_stack_range_for): Cast pointers to word when
compared.
* GC_push_all_stacks (GC_push_all_stacks): Likewise.
* include/gc.h (GC_register_altstack): Reformat comment; decorate with
GC_CALL; comment out argument names; change type of altstack_size and
stack_size to word.
* include/private/pthread_support.h (altstack, altstack_size, stack,
stack_size): Refine and reformat comment.
* include/private/pthread_support.h (altstack_size, stack_size): Change
type from int to word.
* pthread_support.c (main_stack_size, main_altstack_size): Likewise.
* pthread_support.c (main_pthread_self): Rename to main_pthread_id.
* pthread_support.c (GC_register_altstack): Decorate with GC_API and
GC_CALL.
* win32_threads.c (GC_register_altstack): Likewise.
* pthread_support.c (GC_register_altstack): Rename "thread" local
variable to "me"; new local variable "self"; use DCL_LOCK_STATE;
reformat code.
* pthread_support.c (GC_thr_init): New local variable "self"; compare
thread id using THREAD_EQUAL; reformat code.
* win32_threads.c (GC_register_altstack): Add GC_ATTR_UNUSED to all
arguments to avoid compiler warning (while the function is
unimplemented); add TODO.

9 years agoAdd alt-stack registration support
Zoltan Varga [Mon, 21 May 2012 23:02:05 +0000 (01:02 +0200)]
Add alt-stack registration support
(Apply commit ff4ec56 from 'mono_libgc' branch.)

Fix altstack support in libgc by registering the bounds of the normal
stack and the altstack with it.

* darwin_stop_world.c (GC_stack_range_for): Add paltstack_lo,
paltstack_hi argments; set *paltstack_lo, *paltstack_hi, adjust lo and
hi if p->altstack set.
* darwin_stop_world.c (GC_push_all_stacks): Declare altstack_lo,
altstack_hi local variables; pass &altstack_lo, &altstack_hi to
GC_stack_range_for; do not call GC_push_all_stack(lo, hi) and
adjust total_size by hi-lo if lo is NULL; call
GC_push_all_stack(altstack_lo, altstack_hi) and increment total_size
by altstack_hi-altstack_lo if altstack_lo is non-NULL.
* include/gc.h (GC_register_altstack): New API function declaration.
* include/private/pthread_support.h (GC_Thread_Rep): Add altstack,
altstack_size, stack, stack_size fields.
* pthread_stop_world.c (GC_push_all_stacks): Adjust hi value if
p->altstack set.
* pthread_support.c (main_pthread_self, main_stack, main_altstack,
main_stack_size, main_altstack_size): New static variables.
* pthread_support.c (GC_register_altstack): New function.
* pthread_support.c (GC_thr_init): Set altstack, altstack_size, stack,
stack_size fields from values saved by GC_register_altstack (if called
before GC_thr_init).
* win32_threads.c (GC_register_altstack): New function (unimplemented).

9 years agoRemove unsupported FreeBSD/ia64 case from gcconfig.h
Ivan Maidanski [Tue, 21 Jul 2015 06:50:24 +0000 (09:50 +0300)]
Remove unsupported FreeBSD/ia64 case from gcconfig.h

* include/private/gcconfig.h (IA64, mach_type_known): Do not define if
FREEBSD and __ia64__.

9 years agoFreeBSD/arm support improvement
Carlos J. Puga Medina [Tue, 21 Jul 2015 06:44:41 +0000 (09:44 +0300)]
FreeBSD/arm support improvement

Update the arm32 code to match arm64, powerpc and x86.

* include/private/gc_priv.h: Include machine/trap.h if
DATASTART_USES_BSDGETDATASTART (instead of checking for FREEBSD and
particular CPUs).
* include/private/gcconfig.h (ALIGNMENT, HEURISTIC2,
SEARCH_FOR_DATA_START): Remove for FreeBSD/arm.
* include/private/gcconfig.h (MPROTECT_VDB, SIG_SUSPEND,
SIG_THR_RESTART, DATASTART, DATASTART_USES_BSDGETDATASTART): Define
macro if FREEBSD and ARM32.
* os_dep.c (CODE_OK): Define for FreeBSD/arm.

9 years agoCode refactoring of 'finalization extension API'
Ivan Maidanski [Sun, 19 Jul 2015 14:14:16 +0000 (17:14 +0300)]
Code refactoring of 'finalization extension API'

* finalize.c (GC_object_finalized_proc, GC_set_finalizer_notify_proc):
Use GC_await_finalize_proc type.
* finalize.c (GC_object_finalized_proc): Use STATIC instead of
"static".
* finalize.c (GC_set_finalizer_notify_proc): Rename to
GC_set_await_finalize_proc.
* include/gc.h (GC_set_finalizer_notify_proc): Likewise.
* finalize.c (GC_set_await_finalize_proc): Add LOCK/UNLOCK.
* finalize.c (GC_set_await_finalize_proc): Decorate with GC_CALL.
* include/gc.h (GC_set_await_finalize_proc): Likewise.
* finalize.c (GC_get_await_finalize_proc): New API function.
* include/gc.h (GC_await_finalize_proc): New type.
* include/gc.h (GC_set_await_finalize_proc): Document.
* include/gc.h (GC_get_await_finalize_proc): New API function
declaration.

9 years agoImplement the finalization extension API
Rodrigo Kumpera [Fri, 30 May 2014 01:51:29 +0000 (21:51 -0400)]
Implement the finalization extension API
(Apply commit c429e9f from 'mono_libgc' branch.)

Conflicts:

    finalize.c
    include/gc.h

9 years agoFix Makefile.direct for Cygwin
Paul Bone [Thu, 16 Jul 2015 17:31:24 +0000 (20:31 +0300)]
Fix Makefile.direct for Cygwin
(Apply part of commit 9f229e2 from "paulbone/mercury7_4_pbone" branch.)

* Makefile.direct (CXX, AS): Add comment.
* Makefile.direct (LD): New variable.
* Makefile.direct (libalphagc.so, libirixgc.so, mach_dep.o): Use LD
variable.
* Makefile.direct (mach_dep.o): Replace "as $(AS_ABI_FLAG)" with $(AS).
* Makefile.direct (mach_dep.o, mark_rts.o): Add Cygwin-specific rules.

9 years agoUpdate AUTHORS file
Ivan Maidanski [Tue, 14 Jul 2015 08:16:52 +0000 (11:16 +0300)]
Update AUTHORS file

9 years agoCode refactoring regarding 'data start' definition for FreeBSD
Ivan Maidanski [Sun, 12 Jul 2015 07:26:06 +0000 (10:26 +0300)]
Code refactoring regarding 'data start' definition for FreeBSD

* include/private/gcconfig.h (DATASTART_USES_BSDGETDATASTART): New
macro defined for FreeBSD when DATASTART is defined to
GC_FreeBSDGetDataStart().
* include/private/gcconfig.h (GC_FreeBSDGetDataStart,
DATASTART_IS_FUNC): Move declare/definition from the place where
DATASTART defined for FreeBSD to common place guarded with the check
of DATASTART_USES_BSDGETDATASTART.
* include/private/gcconfig.h (GC_FreeBSDGetDataStart): Decorate with
GC_INNER.
* os_dep.c (GC_FreeBSDGetDataStart): Likewise.
* os_dep.c (GC_FreeBSDGetDataStart): Define only if
DATASTART_USES_BSDGETDATASTART (instead of checking FREEBSD and
CPU-specific macros).

9 years agoFix support of FreeBSD/aarch64
Carlos J. Puga Medina [Sat, 11 Jul 2015 18:31:40 +0000 (21:31 +0300)]
Fix support of FreeBSD/aarch64

* include/private/gc_priv.h: Include machine/trap.h if qqqFREEBSD and
AARCH64 defined.
* os_dep.c (GC_FreeBSDGetDataStart, CODE_OK): Define if FREEBSD and
AARCH64.
* include/private/gc_priv.h: Replace checking powerpc/__powerpc__
macros with POWERPC.
* os_dep.c: Likewise.
* include/private/gcconfig.h (ALIGNMENT, HEURISTIC2,
SEARCH_FOR_DATA_START): Do not define for FREEBSD/AARCH64.
* include/private/gcconfig.h (MPROTECT_VDB, FREEBSD_STACKBOTTOM,
DATASTART, DATASTART_IS_FUNC): Define if FREEBSD and AARCH64 defined.

9 years agoCode refactoring, add test and document GC_get_memory_use
Ivan Maidanski [Thu, 9 Jul 2015 21:29:43 +0000 (00:29 +0300)]
Code refactoring, add test and document GC_get_memory_use

* include/gc.h (GC_get_memory_use): Add comment.
* include/gc.h (GC_get_memory_use): Decorate with GC_CALL; change
return type from long to size_t.
* misc.c (GC_get_memory_use): Likewise.
* misc.c (get_size): Rename to block_add_size.
* misc.c (get_size): Rename lptr parameter to pbytes; code refactoring.
* misc.c (GC_get_memory_use): Rename "c" local variable to "bytes";
add DCL_LOCK_STATE.
* tests/test.c (check_heap_stats): Call GC_get_memory_use (and print
returned value).