Ivan Maidanski [Fri, 31 Aug 2018 16:14:18 +0000 (19:14 +0300)]
Eliminate 'potential unsafe sign check of a bitwise operation' code defect
* mark.c [!OS2] (GC_mark_from): Cast mark_stack_top-mark_stack to word
first, and cast bitwise OR operation result to signed_word, so that not
to apply bitwise OR operation to the value of ptrdiff_t.
Demyan Kimitsa [Tue, 28 Aug 2018 16:40:47 +0000 (19:40 +0300)]
Fix start_world not resuming all threads on Darwin
Issue #231 (bdwgc).
This happens due mach thread ports are released in GC_stop_world as
a result in some cases the system creates new one and GC_start_world
will not find the thread to resume; in turn, the threads will stay
suspended. When this happens to GDC threads, the application is
terminated as the message loop is halt.
The high-level description of the change: thread mach port is not
deallocated when thread is saved in GC_mach_threads as it causes thread
not being resumed as thread port object can be changed; threads are now
being suspended without check of suspend_count (as it can be suspended
by client); the logic of resume is changed, now the primary cycle
iterates threads to resume in GC_mach_threads.
* darwin_stop_world.c (struct GC_mach_thread): Rename already_suspended
filed to suspended.
* darwin_stop_world.c [!GC_NO_THREADS_DISCOVERY]
(GC_suspend_thread_list): Add my_task argument; remove info an outCount
local variables; call mach_port_deallocate uless threaded is added to
GC_mach_threads; do not call thread_info; update the relevant comments.
* darwin_stop_world.c [!GC_NO_THREADS_DISCOVERY] (GC_stop_world):
Remove i local variable; do not call mach_port_deallocate for prevlist
items; add comment.
* darwin_stop_world.c (GC_thread_resume): Call WARN instead of ABORT
if thread_resume failed.
* darwin_stop_world.c [!GC_NO_THREADS_DISCOVERY] (GC_start_world):
Initialize j to listcount; iterate over GC_mach_threads in the outer
loop; if thread is suspended then find it in act_list; if found then
resume thread; call mach_port_deallocate for act_list items.
Ivan Maidanski [Fri, 3 Aug 2018 16:43:18 +0000 (19:43 +0300)]
Fix incorrect roots order after root removal in remove_roots_subregion
(fix of commits 38d194a, e849b45)
Issue #218 (bdwgc).
* mark_rts.c [USE_PROC_FOR_LIBRARIES] (swap_static_roots): New inline
function.
* mark_rts.c [USE_PROC_FOR_LIBRARIES] (GC_remove_roots_subregion):
Use swap_static_roots (after GC_add_roots_inner); if there is
a temporary root after GC_remove_root_at_pos then swap it with the
appropriate non-temporary one to ensure all temporary roots are
grouped at the end.
Jonas Echterhoff [Tue, 31 Jul 2018 14:07:26 +0000 (17:07 +0300)]
Fix more compilation issues for XboxOne
(part of commit c6e7e36 from Unity-Technologies/bdwgc)
Issue #173 (bdwgc).
* include/private/gc_priv.h [!CPPCHECK && !PCR && MSWIN_XBOX1
&& !DebugBreak] (DebugBreak): Define to __debugbreak.
* misc.c [MSWIN32] (GC_win32_MessageBoxA): Do not define if MSWIN_XBOX1.
* misc.c [!PCR && !SMALL_CONFIG && MSWIN32] (GC_default_on_abort): Do
not call GC_win32_MessageBoxA() if MSWINRT_FLAVOR or MSWIN_XBOX1.
Ivan Maidanski [Tue, 31 Jul 2018 06:58:31 +0000 (09:58 +0300)]
Allow register_main_static_data disabling in CMake script
* CMakeLists.txt (enable_register_main_static_data): New OPTION (on by
default).
* CMakeLists.txt [!enable_register_main_static_data]: Define
GC_DONT_REGISTER_MAIN_STATIC_DATA macro.
Ivan Maidanski [Tue, 31 Jul 2018 06:40:22 +0000 (09:40 +0300)]
Allow dynamic_loading disabling in CMake script
* CMakeLists.txt (enable_dynamic_loading): New OPTION (on by default).
* CMakeLists.txt [!enable_dynamic_loading]: Define
IGNORE_DYNAMIC_LOADING macro.
Ivan Maidanski [Mon, 30 Jul 2018 20:58:21 +0000 (23:58 +0300)]
Allow threads_discovery disabling in CMake script
* CMakeLists.txt (enable_threads_discovery): New OPTION (on by default).
* CMakeLists.txt [!enable_threads_discovery]: Define
GC_NO_THREADS_DISCOVERY macro.
Ivan Maidanski [Fri, 27 Jul 2018 21:29:59 +0000 (00:29 +0300)]
Export stop/start_world_external only for multi-threaded builds
(fix of commit bb91f03)
Issue #173 (bdwgc).
Also, update GC_world_stopped value in GC_stop_world_external and
GC_start_world_external.
* include/gc.h (GC_stop_world_external, GC_start_world_external): Do not
declare unless GC_THREADS; add comment.
* misc.c (GC_stop_world_external, GC_start_world_external): Do not
define unless THREADS; add assertion that GC is initialized.
* misc.c [THREADS && THREAD_LOCAL_ALLOC] (GC_stop_world_external): Set
GC_world_stopped to true after STOP_WORLD; add assertion that the
world is not stopped.
* misc.c [THREADS && THREAD_LOCAL_ALLOC] (GC_start_world_external): Set
GC_world_stopped to false before START_WORLD; add assertion that the
world is stopped.
* tests/test.c [GC_PTHREADS && CPPCHECK] (main): Add UNTESTED for
GC_stop_world_external and GC_start_world_external.
Ivan Maidanski [Wed, 25 Jul 2018 09:28:40 +0000 (12:28 +0300)]
Add outermost parentheses to HCE definition
(code refactoring)
* include/private/gc_hdrs.h [COUNT_HDR_CACHE_HITS] (HC_HIT, HC_MISS):
Cast result to void.
* include/private/gc_hdrs.h (HCE): Wrap the whole expression into
parentheses.
Ivan Maidanski [Thu, 12 Jul 2018 07:40:41 +0000 (10:40 +0300)]
Update NT_MAKEFILE usage information in README files for Win32 and Win64
Issue #223 (bdwgc).
* doc/README.win32 (Microsoft Tools): Provide a sample how to build
static library without threads support.
* doc/README.win64: Likewise.
* doc/README.win32 (Threads): Provide a sample how to build dynamic
collector with threads support using NT_MAKEFILE.
* doc/README.win64: Likewise.
Ivan Maidanski [Wed, 11 Jul 2018 20:09:00 +0000 (23:09 +0300)]
Fix GC_is_valid_displacement and GC_is_visible for non-small objects
* ptr_chck.c (GC_is_valid_displacement): Remove redundant
IS_FORWARDING_ADDR_OR_NIL(hhdr) call if GC_all_interior_pointers.
* ptr_chck.c (GC_is_valid_displacement): Do not goto fail if
p+sz-offset > h+1 but IS_FORWARDING_ADDR_OR_NIL(HDR(h+1)).
* ptr_chck.c (GC_is_visible): Transform comment about GC_base to
a TODO item; set hhdr to HDR(base) instead of HDR(p)
if HBLKPTR(base)!=HBLKPTR(p).
Ivan Maidanski [Wed, 11 Jul 2018 06:07:30 +0000 (09:07 +0300)]
Fix 'pointer arithmetic with NULL' code defect in print_callers
* os_dep.c [NEED_CALLINFO && LINUX && !SMALL_CONFIG] (GC_print_callers):
If nl is null then pass result_len (instead of nl-result_buf) to strncmp;
adjust code indentation.
Ivan Maidanski [Thu, 5 Jul 2018 14:38:11 +0000 (17:38 +0300)]
Fix test_cpp failure in case GC_DEBUG is defined
Now GC_bytes_freed is updated even if the real deallocation of the
explicitly freed object is deferred.
* dbg_mlc.c (GC_debug_free): Increment GC_bytes_freed by hhdr->hb_sz
in case of GC_free is not called (when the object is filled with
GC_FREED_MEM_MARKER); add comment.
Ivan Maidanski [Thu, 5 Jul 2018 04:17:09 +0000 (07:17 +0300)]
Remove multi-line macros (ITERATE_DL_HASHTBL_*) in finalize
(code refactoring)
* finalize.c (ITERATE_DL_HASHTBL_BEGIN, ITERATE_DL_HASHTBL_END,
DELETE_DL_HASHTBL_ENTRY): Remove macro.
* finalize.c (GC_make_disappearing_links_disappear): Add
is_remove_dangling argument (true means removal of dangling disappearing
links, false means make the disappearing links disappear); rename curr
and next local variables to curr_dl and next_dl, respectively; expand
ITERATE_DL_HASHTBL_BEGIN, DELETE_DL_HASHTBL_ENTRY and
ITERATE_DL_HASHTBL_END macros; remove real_ptr local variable; reformat
code.
* finalize.c (GC_remove_dangling_disappearing_links): Remove.
Ivan Maidanski [Sat, 30 Jun 2018 04:37:54 +0000 (07:37 +0300)]
Compute GC_CONS arguments just once
(fix of commit 8eb6f8d)
* include/gc_inline.h (GC_CONS): Declare l and r local variables;
compute first and second expression even in case of
GC_MALLOC_WORDS_KIND failure; pass l and r to GC_reachable_here (instead
of first and second).
Ivan Maidanski [Fri, 22 Jun 2018 22:17:46 +0000 (01:17 +0300)]
Fix mark stack overflow checking in push_selected
* mark.c (GC_push_selected): In case of a danger of mark stack overflow
after the first GC_push_all() call then call GC_push_all(bottom, top)
and return; remove redundant checking of GC_mark_stack_top at the end
of the function (overflow is already checked in GC_push_all).
Ivan Maidanski [Fri, 22 Jun 2018 21:42:30 +0000 (00:42 +0300)]
Add GC_reachable_here after GC_dirty in GC source
(fix of commits 73d30d2b4, e5fb574cf)
* README.md (Incremental Collection): Add note about bugs caused by
a missing GC_reachable_here call.
* doc/gcdescr.md (Generational Collection): Mention GC_reachable_here
for MANUAL_VDB mode.
* finalize.c (GC_register_disappearing_link_inner,
GC_register_finalizer_inner): Move GC_dirty(new_dl) call to be before
unlocking (so that to ensure no collection occurs between initialization
of new_dl and GC_dirty() call).
* finalize.c (GC_finalize): Call GC_dirty() immediately after updating
GC_fnlz_roots.fo_head (instead of setting needs_barrier) if
GC_object_finalized_proc is set.
* gcj_mlc.c (GC_gcj_malloc, GC_debug_gcj_malloc,
GC_gcj_malloc_ignore_off_page): Call
REACHABLE_AFTER_DIRTY(ptr_to_struct_containing_descr) after GC_dirty(op).
* include/gc.h (GC_end_stubborn_change): Mention GC_reachable_here
in comment.
* include/gc_inline.h (GC_FAST_MALLOC_GRANS): Call
GC_reachable_here(next) after GC_end_stubborn_change(my_fl); remove
GC_end_stubborn_change() call when a non-pointer is stored to my_fl;
remove GC_end_stubborn_change() after GC_generic_malloc_many() call.
* include/gc_inline.h (GC_CONS): Call GC_reachable_here for the stored
pointers after GC_end_stubborn_change call.
* include/private/gc_priv.h (REACHABLE_AFTER_DIRTY): New macro.
* mallocx.c [MANUAL_VDB] (GC_generic_malloc_many): If
GC_is_heap_ptr(result) then call GC_dirty(result) and
REACHABLE_AFTER_DIRTY(op) after storing op pointer.
* typd_mlc.c (GC_make_sequence_descriptor): Call REACHABLE_AFTER_DIRTY
for the stored pointers after GC_dirty(result).
* typd_mlc.c (GC_malloc_explicitly_typed,
GC_malloc_explicitly_typed_ignore_off_page, GC_calloc_explicitly_typed):
Call REACHABLE_AFTER_DIRTY(d) after GC_dirty(op).
* win32_threads.c (GC_CreateThread, GC_beginthreadex,
GC_pthread_create): Call REACHABLE_AFTER_DIRTY for the stored pointer
after GC_dirty.
Ivan Maidanski [Thu, 21 Jun 2018 21:57:09 +0000 (00:57 +0300)]
Add GC_reachable_here after GC_END_STUBBORN_CHANGE in tests
(fix of commits b52c140d3, f72fc9d43, 08a380c3a)
* tests/disclaim_test.c (pair_dct, pair_new): Call GC_reachable_here
for the stored pointers after GC_end_stubborn_change call.
* tests/staticrootslib.c (libsrl_mktree): Call GC_reachable_here for
the stored pointers after GC_END_STUBBORN_CHANGE call.
* tests/test.c (cons, small_cons, small_cons_uncollectable, mktree,
typed_test): Likewise.
* tests/test.c [GC_GCJ_SUPPORT] (gcj_cons): Likewise.
* tests/test.c [!SMALL_CONFIG && !GC_DEBUG] (alloc8bytes): Likewise.
* tests/test_cpp.cc [!DONT_USE_STD_ALLOCATOR] (main): Likewise.
* tests/trace_test.c (mktree): Likewise.
* tests/test.c (reverse_test_inner): Declare tmp local variable; call
GC_END_STUBBORN_CHANGE() and GC_reachable_here() after storing pointers
to f[5], g[799] and h[1999].
* tests/test_cpp.cc (C_INIT_LEFT_RIGHT): New macro (to call
GC_END_STUBBORN_CHANGE and GC_reachable_here).
* tests/test_cpp.cc (C::C): Use C_INIT_LEFT_RIGHT().
* tests/test_cpp.cc (main): Remove GC_end_stubborn_change(c) call after
because GC_END_STUBBORN_CHANGE() is now called for this (in
C_INIT_LEFT_RIGHT) of the heap-allocated objects.
Ivan Maidanski [Thu, 21 Jun 2018 10:38:56 +0000 (13:38 +0300)]
Add GC_reachable_here after GC_END_STUBBORN_CHANGE in cords
(fix of commit e12e820f3)
* cord/cordbscs.c (CORD_cat_char_star, CORD_cat, CORD_from_fn_inner,
CORD_substr_closure): Call GC_END_STUBBORN_CHANGE() instead of
GC_end_stubborn_change().
* cord/cordxtra.c (refill_cache): Likewise.
* cord/tests/de.c (prune_map, add_map, add_hist, replace_line,
generic_init): Likewise.
* cord/cordbscs.c (CORD_cat_char_star, CORD_cat): Mark x and y as
reachable after GC_END_STUBBORN_CHANGE(result).
* cord/cordbscs.c (CORD_from_fn_inner): Mark client_data as reachable
after GC_END_STUBBORN_CHANGE(result).
* cord/cordbscs.c (CORD_substr_closure): Mark x as reachable after
GC_END_STUBBORN_CHANGE(sa).
* cord/tests/de.c (prune_map): Mark saved map->previous->previous as
reachable after GC_END_STUBBORN_CHANGE(map).
* cord/tests/de.c (add_map): Mark saved current_map as reachable after
GC_END_STUBBORN_CHANGE(new_map).
* cord/tests/de.c (replace_line): Mark s as reachable after
GC_END_STUBBORN_CHANGE(screen+i).
Ivan Maidanski [Wed, 20 Jun 2018 08:52:33 +0000 (11:52 +0300)]
Really use C11 static_assert if available (GCC/Clang/MSVC)
(fix of commit 7d34f4e5c)
Issue #223 (bdwgc).
Improve static assertion message as well.
* include/private/gc_priv.h [__STDC_VERSION__>=201112L]: Include
assert.h (to have static_assert defined).
* include/private/gc_priv.h [_MSC_VER>=1700] (GC_STATIC_ASSERT): Define
as static_assert.
* include/private/gc_priv.h [static_assert && __STDC_VERSION__>=201112L]
(GC_STATIC_ASSERT): Pass #expr as the 2nd argument to static_assert
(instead of "").
Ivan Maidanski [Wed, 20 Jun 2018 08:35:55 +0000 (11:35 +0300)]
Add missing type casts in remap and register_my_thread_inner
(fix of commit a825a2d)
Issue #206 (bdwgc).
* os_dep.c [USE_MUNMAP && USE_WINALLOC] (GC_remap): Cast result of
VirtualAlloc to ptr_t.
* win32_threads.c [!GC_NO_THREADS_DISCOVERY]
(GC_register_my_thread_inner): Cast the first argument of
InterlockedExchange() call to word* (instead of void*).