Ivan Maidanski [Mon, 18 Jun 2018 21:50:07 +0000 (00:50 +0300)]
Remove duplicate local variable in reclaim_block
(fix of commit 6c1a92445)
* reclaim.c [ENABLE_DISCLAIM] (GC_reclaim_block): Remove duplicate ok
local variable definition (which hides the one in the outermost block
and has the same value).
Ivan Maidanski [Thu, 14 Jun 2018 23:27:11 +0000 (02:27 +0300)]
Fix large object base computation in PUSH_CONTENTS() if MARK_BIT_PER_OBJ
Issue #177 (bdwgc).
* include/private/gc_pmark.h [MARK_BIT_PER_OBJ] (PUSH_CONTENTS_HDR):
Do not call LONG_MULT() if inv_sz == LARGE_INV_SZ; set base to
hhdr->hb_block if inv_sz == LARGE_INV_SZ regardless of low_prod>>16
value; use EXPECT(FALSE) for inv_sz == LARGE_INV_SZ expression;
remove FIXME about offset; adjust assertion to allow hb_block==current.
Ivan Maidanski [Wed, 13 Jun 2018 23:20:34 +0000 (02:20 +0300)]
Remove unnecessary type casts in n_set_marks
(code refactoring)
* reclaim.c (GC_n_set_marks): Change return type from int to unsigned;
change type of result local variable to unsigned.
* reclaim.c [!USE_MARK_BYTES] (set_bits): Likewise.
* reclaim.c (GC_n_set_marks): Change type of i, offset, limit,
n_mark_words, n_objs local variables to word; remove redundant casts.
Ivan Maidanski [Wed, 13 Jun 2018 21:40:46 +0000 (00:40 +0300)]
Skip typed_test in gctest if NO_TYPED_TEST macro is defined
This is purely for a debugging purpose.
* tests/test.c: Do not include gc_typed.h if NO_TYPED_TEST.
* tests/test.c [GC_AMIGA_FASTALLOC && AMIGA]
(GC_amiga_gctest_malloc_explicitly_typed,
GC_amiga_gctest_calloc_explicitly_typed): Do not define if NO_TYPED_TEST.
* tests/test.c (bm_huge, typed_test): Likewise.
* tests/test.c [!DBG_HDRS_ALL] (run_one_test): Do not call typed_test
if NO_TYPED_TEST.
Ivan Maidanski [Fri, 8 Jun 2018 20:21:38 +0000 (23:21 +0300)]
Fix 'scope of var can be reduced' cppcheck warnings in check_heap_stats
(fix of commit 4e909d2)
Also, print the message about the leak-find mode just once per gctest
execution.
* tests/test.c (INIT_FIND_LEAK): Define macro.
* tests/test.c (GC_COND_INIT): Invoke INIT_FIND_LEAK.
* tests/test.c (run_one_test): Remove print about leak-find mode.
* tests/test.c [!GC_NO_FINALIZATION] (check_heap_stats): Move
still_live and still_long_live local variables to the block of their
usage.
Ivan Maidanski [Fri, 8 Jun 2018 08:34:23 +0000 (11:34 +0300)]
Use noexcept specifier in gc_cpp if C++11
* gc_cpp.cc [!_MSC_VER && !__DMC__] (delete, delete[]): Rename
GC_DECL_DELETE_THROW to GC_NOEXCEPT.
* include/gc_cpp.h: Always include "new" header.
* include/gc_cpp.h [!GC_NEW_DELETE_THROW_NOT_NEEDED]
(GC_NEW_DELETE_NEED_THROW): Do not define if __BORLANDC__ or _MSC_VER,
or __WATCOMC__, or if __cplusplus>=201103L and !__clang__.
* include/gc_cpp.h (GC_DECL_DELETE_THROW): Remove.
* include/gc_cpp.h [!GC_NOEXCEPT] (GC_NOEXCEPT): Define internal macro
to except or throw(), or nothing (same as that in gc_allocator.h).
* include/gc_cpp.h [!GC_NEW_ABORTS_ON_OOM] (GC_NEW_ABORTS_ON_OOM):
Define if GC_NOEXCEPT is defined to nothing.
* include/gc_cpp.h (new(size_t,void*), new[](size_t,void*), delete):
Add GC_NOEXCEPT.
Ivan Maidanski [Thu, 7 Jun 2018 09:09:57 +0000 (12:09 +0300)]
Fix gctest in leak-finding mode
* tests/test.c [!FIND_LEAK] (mktree): Do not call GC_REGISTER_FINALIZER
and GC_GENERAL_REGISTER_DISAPPEARING_LINK if GC_get_find_leak().
* tests/test.c (run_one_test): Replace "ifdef FIND_LEAK" with
if(GC_get_find_leak()).
* tests/test.c (check_heap_stats): Do not fail on unexpected heap
growth if GC_get_find_leak().
Ivan Maidanski [Thu, 7 Jun 2018 08:39:27 +0000 (11:39 +0300)]
Use noexcept in gc_allocator
* include/gc_allocator.h [!GC_NOEXCEPT] (GC_NOEXCEPT): Define internal
macro (to noexcept if C++11, otherwise to throw() or nothing); define
GC_NEW_ABORTS_ON_OOM if GC_NOEXCEPT is defined to nothing.
* include/gc_allocator.h (gc_allocator(), deallocate, operator==,
operator!=, gc_allocator_ignore_off_page()): Add GC_NOEXCEPT.
* include/gc_allocator.h (gc_allocator, gc_allocator_ignore_off_page,
traceable_allocator): Replace throw() to GC_NOEXCEPT.
* include/gc_allocator.h (deallocate): Remove outdated comment that
p should be non-null.
Ivan Maidanski [Wed, 6 Jun 2018 22:08:07 +0000 (01:08 +0300)]
Never return null by C++ GC allocators
Now, in case of the allocation failure, the allocators (defined in
gc_allocator.h or new_gc_alloc.h) throw bad_alloc (or abort the
application if compiled without exceptions support).
* include/gc_allocator.h (GC_ALLOCATOR_THROW_OR_ABORT): New macro
(either throws bad_alloc or calls GC_abort_on_oom).
* include/gc_allocator.h (GC_selective_alloc,
traceable_allocator::allocate): Call GC_ALLOCATOR_THROW_OR_ABORT() if
the allocation failed.
* include/new_gc_alloc.h (GC_ALLOCATOR_THROW_OR_ABORT): New macro
(redirected to GC_abort_on_oom).
* include/new_gc_alloc.h (GC_out_of_line_malloc,
single_client_gc_alloc_template::allocate,
single_client_gc_alloc_template::ptr_free_allocate,
single_client_traceable_alloc_template::allocate,
single_client_traceable_alloc_template::ptr_free_allocate,
gc_alloc_template::allocate, gc_alloc_template::ptr_free_allocate,
traceable_alloc_template::allocate,
traceable_alloc_template::ptr_free_allocate): Call
GC_ALLOCATOR_THROW_OR_ABORT() instead of returning 0.
* include/new_gc_alloc.h (simple_alloc::allocate): If n is 0 then
allocate 1 byte.
* include/new_gc_alloc.h (simple_alloc::deallocate): If n is 0 then
call ptr_free_deallocate for 1-byte object.
Ivan Maidanski [Mon, 4 Jun 2018 20:04:17 +0000 (23:04 +0300)]
Eliminate 'cast between incompatible function types' compiler warning
* cord/cordxtra.c (refill_cache): Add GC_CALLBACK; change return type
from char to void*; change argument type from refill_data* to void*;
add necessary casts to client_data and the return expression.
* cord/cordxtra.c (CORD_lf_func): Do not cast refill_cache.
* os_dep.c [MPROTECT_VDB] (GC_write_fault_handler,
GC_mprotect_dirty_init): Cast SIG_DFL, SIG_IGN and oldact.sa_handler
to SIG_HNDLR_PTR via signed_word type.
* os_dep.c [MPROTECT_VDB && !MSWIN32 && !MSWINCE]
(GC_write_fault_handler): Cast old_handler to PLAIN_HNDLR_PTR via
signed_word type.
Ivan Maidanski [Mon, 4 Jun 2018 07:04:09 +0000 (10:04 +0300)]
Fix new and delete operators definition for DigitalMars compiler
* gc_cpp.cc (new, delete, new[], delete[]): Do not define if __DMC__.
* include/gc_cpp.h (new[], delete[], new, delete): Define also if
__DMC__.
* include/gc_cpp.h [_MSC_VER] (new[], delete[]): Replace _MSC_VER>1020
to defined(GC_OPERATOR_NEW_ARRAY).
Ivan Maidanski [Tue, 29 May 2018 18:01:23 +0000 (21:01 +0300)]
Make subthreadcreate test compilable even without libatomic_ops
(fix of commit 4becbc906)
* tests/subthread_create.c [HAVE_CONFIG_H]: Update comment.
* tests/subthread_create.c: Do not include gc.h and gc_atomic_ops.h
(and do not define AO_REQUIRE_CAS) unless GC_THREADS is defined.
Ivan Maidanski [Tue, 29 May 2018 17:51:48 +0000 (20:51 +0300)]
Eliminate 'comparing signed and unsigned values' compiler warnings (bcc)
* allchblk.c (GC_allochblk_nth): Cast HBLKSIZE to signed_word in
comparison to size_needed.
* reclaim.c (GC_reclaim_all): Cast hhdr->hb_last_reclaimed to word in
comparison to GC_gc_no-1.
Ivan Maidanski [Thu, 24 May 2018 22:08:25 +0000 (01:08 +0300)]
Fix GC_out_of_line_malloc in new_gc_alloc.h for out-of-memory case
* include/new_gc_alloc.h (GC_out_of_line_malloc): Call
GC_generic_malloc_words_small() before the counters update; do not
update the counters if GC_generic_malloc_words_small() returns 0.
Ivan Maidanski [Thu, 24 May 2018 08:41:51 +0000 (11:41 +0300)]
Fix test_cpp for MANUAL_VDB
* tests/test_cpp.cc (C(C&), C::operator=): Call new if and only if
level>0.
* tests/test_cpp.cc (C(C&), C::operator=, C(int), main): Call
GC_end_stubborn_change for the result of new operator.
* tests/test_cpp.cc (main): Call GC_end_stubborn_change after update
of *xptr.
Ivan Maidanski [Wed, 23 May 2018 08:14:44 +0000 (11:14 +0300)]
Fix staticroots and trace tests for MANUAL_VDB
* tests/staticrootslib.c (mktree): Call GC_end_stubborn_change() at the
end of function if GC_NEW() was called.
* tests/trace_test.c (mktree): Likewise.
* os_dep.c [NEED_PROC_MAPS] (READ): Move macro definition inside the
function where it is used; undefine the macro at the function end.
* os_dep.c [PROC_VDB] (READ): Likewise.
* os_dep.c [!GWW_VDB] (GC_GWW_AVAILABLE): Define to FALSE.
* os_dep.c [!GC_DISABLE_INCREMENTAL] (GC_page_was_dirty,
GC_page_was_ever_dirty, GC_remove_protection, GC_read_dirty): Collapse
multiple definitions into a single one; reformat code; replace
GC_ATTR_UNUSED with (void)arg.
* os_dep.c [GWW_VDB && MPROTECT_VDB] (GC_gww_page_was_ever_dirty):
Remove.
* os_dep.c [GWW_VDB && !MPROTECT_VDB] (GC_read_dirty): Rename to
GC_gww_read_dirty; define as GC_INLINE.
* os_dep.c [PROC_VDB] (GC_read_dirty): Rename to GC_proc_read_dirty;
define as GC_INLINE.
Ivan Maidanski [Sat, 19 May 2018 09:02:00 +0000 (12:02 +0300)]
Fix FAST_MALLOC_GRANS and malloc_many for MANUAL_VDB
(fix of commit 73d30d2)
This commit actually disables multiple objects allocation in
GC_generic_malloc_many (if MANUAL_VDB and the incremental mode is on);
the proper implementation would require GC_dirty call for each of the
allocated object (except for the last one).
* include/gc_inline.h (GC_FAST_MALLOC_GRANS): Call
GC_end_stubborn_change(my_fl) after GC_generic_malloc_many().
* mallocx.c [MANUAL_VDB] (GC_generic_malloc_many): Always fall back to
GC_generic_malloc (unless !GC_incremental).
Ivan Maidanski [Sat, 19 May 2018 06:50:23 +0000 (09:50 +0300)]
Enable compilation for Cygwin with MPROTECT_VDB
Note: It just compiles but not working.
* include/private/gc_priv.h [GC_WIN32_THREADS && MPROTECT_VDB]
(GC_set_write_fault_handler): Do not declare if CYGWIN32.
* os_dep.c [MPROTECT_VDB && !DARWIN && !USE_WINALLOC]: Do not include
sys/syscall.h if CYGWIN32.
* os_dep.c [MPROTECT_VDB && CYGWIN32] (CODE_OK): Define (to true).
* os_dep.c [MPROTECT_VDB && GC_WIN32_THREADS]
(GC_set_write_fault_handler): Do not define if CYGWIN32.
* win32_threads.c [MPROTECT_VDB] (GC_register_my_thread_inner): Do not
call GC_gww_dirty_init() and GC_set_write_fault_handler() if CYGWIN32.
Ivan Maidanski [Fri, 18 May 2018 19:00:36 +0000 (22:00 +0300)]
Do not use PKG_CHECK_MODULES in configure
Issue #200 (bdwgc).
Presence of libatomic_ops is now detected only by checking the
installed headers, but libatomic_ops is no longer needed for most of
the clients which have atomic intrinsics support by the compiler.
* README.md (Installation and Portability): Remove information about
"syntax error near unexpected token ATOMIC_OPS".
* autogen.sh: Update comment removing pkg-config from the requirements.
* configure.ac (PKG_CHECK_MODULES(ATOMIC_OPS)): Comment out; update the
comment.
Ivan Maidanski [Fri, 18 May 2018 18:36:37 +0000 (21:36 +0300)]
Fix comments style in configure.ac and Makefile.am
(code refactoring)
Do not allow the comments that are meaningless in the auto-generated
configure and Makefile.in to be put to these files.
* Makefile.am (EXTRA_DIST, SINGLE_GC_OBJ, EXTRA_DIST,
include doc/doc.am): Change comment style from "#" to "##".
* Makefile.am (CPLUSPLUS): Move "#" inside the conditional block.
* configure.ac: Update the copyright.
* configure.ac: Change comment style from "#" to "dnl" for the comments
that are meaningless in auto-generated configure file.
Ivan Maidanski [Wed, 16 May 2018 08:49:33 +0000 (11:49 +0300)]
Remove code duplication in gcj_malloc and malloc_explicitly_typed
(code refactoring)
* gcj_mlc.c [GC_GCJ_SUPPORT] (GC_gcj_malloc): Store
ptr_to_struct_containing_descr in a single place of code.
* typd_mlc.c (GC_malloc_explicitly_typed_ignore_off_page): Store d (to
the object) in a single place of code.
Ivan Maidanski [Wed, 16 May 2018 08:33:02 +0000 (11:33 +0300)]
Add assertions to finalize and threads support for MANUAL_VDB needs
(code refactoring)
* finalize.c (GC_unregister_disappearing_link_inner,
GC_enqueue_all_finalizers): Remove redundant comment about held lock.
* finalize.c (GC_unregister_disappearing_link_inner,
GC_move_disappearing_link_inner, ITERATE_DL_HASHTBL_BEGIN,
GC_finalize, GC_enqueue_all_finalizers): Add assertion that the
allocation lock is held.
* pthread_support.c (first_thread): Refine comment.
* pthread_support.c (GC_new_thread): Add assertion that when the first
thread is added then GC_threads[hv] is null (thus "next" field is set
to null).
* win32_threads.c (GC_new_thread): Likewise.
* pthread_support.c (GC_delete_thread, GC_delete_gc_thread): Add
assertion that "next" field of the first thread is not modified.
* win32_threads.c (GC_delete_gc_thread_no_free, GC_delete_thread):
Likewise.
* win32_threads.c (GC_delete_thread): Use EXPECT() when checking that
p is not the first thread.
* win32_threads.c [GC_PTHREADS] (GC_pthread_start_inner): Add assertion
that the current thread is not the first one (thus "status" field of
the first thread is not modified).
Ivan Maidanski [Tue, 8 May 2018 19:21:59 +0000 (22:21 +0300)]
Fix tests for GC compiled with MANUAL_VDB
* tests/disclaim_test.c (pair_dct, pair_new): Call
GC_end_stubborn_change(p) after writing the last pointer field of p.
* tests/test.c [!DBG_HDRS_ALL] (run_one_test): Likewise.
* tests/test.c (small_cons, small_cons_uncollectable, mktree,
typed_test): Call GC_END_STUBBORN_CHANGE(r) after writing the last
pointer field of r.
* tests/test.c [GC_GCJ_SUPPORT] (gcj_cons): Likewise.
* tests/test.c [!SMALL_CONFIG && !GC_DEBUG] (alloc8bytes): Likewise.
Ivan Maidanski [Tue, 8 May 2018 18:36:41 +0000 (21:36 +0300)]
Keep pointer to the start of previous entry in remove_specific_after_fork
(code refactoring)
* specific.c [USE_CUSTOM_SPECIFIC] (GC_remove_specific_after_fork):
Replace tse** link local variable with tse* prev one; replace *link
with either key->hash[hash_val].p or prev->next.
Ivan Maidanski [Tue, 8 May 2018 17:17:48 +0000 (20:17 +0300)]
Fix assertion violation and partial overlapping in remove_roots_subregion
(fix of commit 38d194a)
Issue #218 (bdwgc).
* mark_rts.c [USE_PROC_FOR_LIBRARIES] (GC_remove_roots_subregion):
Update comment; add assertion that b and e pointers are word-aligned;
handle also cases of partial overlapping with the existing roots;
call GC_rebuild_root_index() only when needed; update existing root
instead of removing old and adding new one (where possible); move
newly static added root to precede dynamic ones (if any); process all
static roots even if an intersection is already found.
Ivan Maidanski [Tue, 8 May 2018 07:33:48 +0000 (10:33 +0300)]
Do not merge dynamic root with the existing static one in add_roots_inner
* mark_rts.c [!MSWIN32 && !MSWINCE && !CYGWIN32] (GC_add_roots_inner):
If the root already exists and it is static then set the found root
to static (if not yet); if dynamic root with the same r_start but
different r_tmp is found then add a new root starting from r_end of
the found root (instead of extending the found root).
Ivan Maidanski [Mon, 7 May 2018 21:47:48 +0000 (00:47 +0300)]
Fix potential null dereference in GC_CONS
* include/gc_inline.h (GC_CONS): Remove granules local variable; replace
GC_FAST_MALLOC_GRANS(GC_malloc_kind) to GC_MALLOC_WORDS_KIND(n=2);
store second element only if result is non-null; store first element
along with second one.
Ivan Maidanski [Mon, 7 May 2018 08:05:15 +0000 (11:05 +0300)]
Fix infinite restarting of mark_some when a static root disappeared (Linux)
Issue #218 (bdwgc).
* dyn_load.c [USE_PROC_FOR_LIBRARIES] (GC_register_map_entries): Call
GC_remove_roots_subregion for each region which has prot starting
with "---"; add comment.
* include/private/gc_priv.h [USE_PROC_FOR_LIBRARIES]
(GC_remove_roots_subregion): Declare function.
* mark_rts.c[USE_PROC_FOR_LIBRARIES] (GC_remove_roots_subregion):
Implement.
Ivan Maidanski [Mon, 7 May 2018 05:20:57 +0000 (08:20 +0300)]
Turn on incremental collection in gctest also if DEFAULT_VDB or MANUAL_VDB
* tests/test.c [DEFAULT_VDB] (TEST_DEFAULT_VDB): Define (before include
gc.h).
* tests/test.c [!GC_DISABLE_INCREMENTAL] (main): Call
GC_enable_incremental also if MANUAL_VDB or TEST_DEFAULT_VDB; print
message about emulating dirty bits with mprotect only if MPROTECT_VDB.
Ivan Maidanski [Fri, 4 May 2018 20:44:57 +0000 (23:44 +0300)]
Remove unnecessary argument casts in add_roots_inner calls
(code refactoring)
* dyn_load.c [USE_PROC_FOR_LIBRARIES] (GC_register_map_entries): Remove
unnecessary casting of arguments in GC_add_roots_inner call.
* dyn_load.c [PCR && !DYNAMIC_LOADING && !MSWIN32]
(GC_register_dynamic_libraries): Likewise.
* dyn_load.c [HAVE_DL_ITERATE_PHDR]
(GC_register_dynamic_libraries_dl_iterate_phdr): Change type of
datastart and dataend local variables from char* to ptr_t.
Ivan Maidanski [Fri, 4 May 2018 20:28:22 +0000 (23:28 +0300)]
Do not rebuild_root_index unless remove_root_at_pos is called
* mark_rts.c [!MSWIN32 && !MSWINCE && !CYGWIN32] (GC_remove_tmp_roots,
GC_remove_roots_inner): Call GC_rebuild_root_index() only if
GC_remove_root_at_pos() is called at least once.
Naoyuki Sawa [Wed, 2 May 2018 04:10:23 +0000 (13:10 +0900)]
Fix register_dynamic_libraries on Windows 10
Issue #219 (bdwgc).
In the past (Windows XP, Windows 7, and older Windows 10), VirtualQuery
always returned PAGE_READWRITE for the data section.
In the April 2018 Update of Windows 10, it seems that PAGE_WRITECOPY
is returned sometimes (thus causing GC_register_dynamic_libraries not
to call GC_cond_add_roots for the section).
* dyn_load.c [MSWIN32 || MSWINCE || CYGWIN32]
(GC_register_dynamic_libraries): Call GC_cond_add_roots()
also for PAGE_EXECUTE_WRITECOPY and PAGE_WRITECOPY pages.
Ivan Maidanski [Thu, 26 Apr 2018 07:54:52 +0000 (10:54 +0300)]
Avoid multiple 'getcontext failed' warnings if getcontext is broken
Issue #133 (bdwgc).
* mach_dep.c [!HAVE_PUSH_REGS && UNIX_LIKE && !NO_GETCONTEXT]
(GC_with_callee_saves_pushed): Define getcontext_works static variable;
do not call getcontext() if getcontext_works < 0; add comment; set
getcontext_works to 1 or -1 (depending whether getcontext is working)
if getcontext_works is zero.
* misc.c [THREADS && UNIX_LIKE && !NO_GETCONTEXT]
(callee_saves_pushed_dummy_fn): New static function (empty).
* misc.c [THREADS && UNIX_LIKE && !NO_GETCONTEXT] (GC_init): Call
GC_with_callee_saves_pushed(callee_saves_pushed_dummy_fn) if GC_dont_gc
or GC_dont_precollect (otherwise it is called by GC_gcollect_inner);
add comment.