summaryrefslogtreecommitdiff
path: root/dbg_mlc.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix comparisons to heap boundary in GC_get_back_ptr_info and GC_mark_fromIvan Maidanski2023-05-131-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The region delimited by GC_least_plausible_heap_addr and GC_greatest_plausible_heap_addr might contain part of static data roots or stacks (in addition to potential heap expansion areas). Certain comparisons in GC_get_back_ptr_info (when ALIGNMENT is 1) and in GC_mark_from (in assertions) expect the real heap boundaries. * alloc.c [SET_REAL_HEAP_BOUNDS] (GC_add_to_heap): Update GC_least_real_heap_addr and GC_greatest_real_heap_addr variables. * dbg_mlc.c [KEEP_BACK_PTRS && ALIGNMENT == 1] (GC_get_back_ptr_info): Compare alternate_target and target to GC_least_real_heap_addr and GC_greatest_real_heap_addr (instead of GC_least_plausible_heap_addr and GC_greatest_plausible_heap_addr). * include/gc/gc_mark.h (GC_greatest_plausible_heap_addr): Refine comment. * include/private/gc_priv.h [GC_ASSERTIONS || KEEP_BACK_PTRS && ALIGNMENT == 1] (SET_REAL_HEAP_BOUNDS): Define macro. * include/private/gc_priv.h [GC_ASSERTIONS || KEEP_BACK_PTRS && ALIGNMENT == 1] (GC_least_real_heap_addr, GC_greatest_real_heap_addr): Define (as macro). * include/private/gc_priv.h [GC_ASSERTIONS || KEEP_BACK_PTRS && ALIGNMENT == 1] (_GC_arrays._least_real_heap_addr, _GC_arrays._greatest_real_heap_addr): New field; add comment. * mark.c (GC_mark_from): Use GC_greatest_real_heap_addr and GC_least_real_heap_addr instead of GC_least_plausible_heap_addr and GC_greatest_plausible_heap_addr, respectively, in assertions.
* Refine comparisons to GC_greatest_plausible_heap_addrIvan Maidanski2023-04-091-2/+2
| | | | | | | | | | | | | | | | | | GC_greatest_plausible_heap_addr should always be greater (strictly) than any address of a heap object. * backgraph.c (add_back_edges): Check that pointer is strictly less than GC_greatest_plausible_heap_addr (instead of less or equal). * dbg_mlc.c [KEEP_BACK_PTRS && ALIGNMENT==1] (GC_get_back_ptr_info): Likewise. * include/gc/gc_mark.h (GC_MARK_AND_PUSH): Likewise. * malloc.c (GC_malloc_kind_global): Likewise. * typd_mlc.c (GC_typed_mark_proc): Likewise. * include/gc/gc_mark.h (GC_greatest_plausible_heap_addr): Refine comment (that any object address is strictly less). * mark.c (GC_mark_from): Allow descr in assertions to be equal to GC_greatest_plausible_heap_addr-GC_least_plausible_heap_addr; reformat comment.
* Avoid code duplication in IGNORE_OFF_PAGE-specific malloc functionsIvan Maidanski2023-03-241-27/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * alloc.c: Update comment regarding GC_generic_malloc_inner usage. * alloc.c (GC_collect_or_expand): Replace ignore_off_page argument to flags (check IGNORE_OFF_PAGE bit only in it); update comment. * alloc.c (GC_allocobj): Pass 0 as flags to GC_collect_or_expand. * dbg_mlc.c (GC_debug_generic_malloc, GC_debug_generic_or_special_malloc): Rename knd argument to k. * mallocx.c (GC_generic_or_special_malloc): Likewise. * dbg_mlc.c (GC_debug_generic_malloc): Use GC_generic_malloc_aligned() instead of GC_generic_malloc(). * dbg_mlc.c (GC_debug_generic_malloc_inner): Add flags argument. * gcj_mlc.c [GC_GCJ_SUPPORT] (GC_core_gcj_malloc): Likewise. * include/private/gc_priv.h (C_generic_malloc_aligned, GC_generic_malloc_inner): Likewise. * include/private/gc_priv.h [THREAD_LOCAL_ALLOC && GC_GCJ_SUPPORT] (GC_core_gcj_malloc): Likewise. * include/private/gc_priv.h [DBG_HDRS_ALL] (GC_debug_generic_malloc_inner): Likewise. * malloc.c (GC_generic_malloc_inner, GC_generic_malloc_aligned): Likewise. * dbg_mlc.c (GC_debug_generic_malloc_inner): Use GC_generic_malloc_inner() instead of GC_generic_malloc_inner_ignore_off_page(). * dbg_mlc.c [DBG_HDRS_ALL] (GC_debug_generic_malloc_inner_ignore_off_page): Remove GC_INNER function. * include/private/gc_priv.h [DBG_HDRS_ALL || GC_GCJ_SUPPORT || !GC_NO_FINALIZATION] (GC_generic_malloc_inner_ignore_off_page): Likewise. * include/private/gc_priv.h [DBG_HDRS_ALL] (GC_debug_generic_malloc_inner_ignore_off_page): Likewise. * malloc.c [DBG_HDRS_ALL || GC_GCJ_SUPPORT || !GC_NO_FINALIZATION] (GC_generic_malloc_inner_ignore_off_page): Likewise. * gcj_mlc.c [GC_GCJ_SUPPORT && !THREAD_LOCAL_ALLOC] (GC_gcj_malloc): Define as STATIC GC_core_gcj_malloc. * gcj_mlc.c [GC_GCJ_SUPPORT] (GC_core_gcj_malloc): Reformat comment; pass flags to GC_generic_malloc_inner(). * gcj_mlc.c [GC_GCJ_SUPPORT && !THREAD_LOCAL_ALLOC] (GC_gcj_malloc): Redirect to GC_core_gcj_malloc() passing 0 to flags argument. * thread_local_alloc.c [THREAD_LOCAL_ALLOC && GC_GCJ_SUPPORT] (GC_gcj_malloc): Likewise. * gcj_mlc.c [GC_GCJ_SUPPORT] (GC_gcj_malloc_ignore_off_page): Redirect to GC_core_gcj_malloc() passing IGNORE_OFF_PAGE. * gcj_mlc.c [GC_GCJ_SUPPORT] (GC_debug_gcj_malloc): Pass 0 as flags to GC_generic_malloc_inner(). * include/private/gc_priv.h (GC_generic_malloc_inner): Update comment. * mallocx.c (GC_generic_malloc_many): Likewise. * include/private/gc_priv.h (GC_collect_or_expand): Replace GC_bool ignore_off_page argument to unsigned flags. * include/private/gc_priv.h (GC_INTERNAL_MALLOC, GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE): Specify macro arguments. * include/private/gc_priv.h (GC_INTERNAL_MALLOC): Pass 0 as flags argument to GC_[debug_]generic_malloc_inner(). * include/private/gc_priv.h (GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE): Pass IGNORE_OFF_PAGE to GC_[debug_]generic_malloc_inner(). * malloc.c (GC_alloc_large): Pass flags (instead of flags!=0) to GC_collect_or_expand(). * malloc.c (GC_generic_malloc_inner_small): New STATIC function (move most of code from GC_generic_malloc_inner). * malloc.c (GC_generic_malloc_inner): Move comment to gc_priv.h; call GC_generic_malloc_inner_small(). * malloc.c (GC_generic_malloc_aligned): Call GC_generic_malloc_inner_small() instead of GC_generic_malloc_inner(); pass flags (instead of 0) to GC_alloc_large(); do not cast result of GC_alloc_large() to ptr_t. * malloc.c (GC_generic_malloc): Pass 0 as flags to GC_generic_malloc_aligned(). * malloc.c (GC_memalign): Likewise. * malloc.c (GC_malloc_kind_global, GC_generic_malloc_uncollectable): Call GC_generic_malloc_aligned() instead of GC_generic_malloc(). * mallocx.c (GC_generic_malloc_many): Likewise. * malloc.c (free_internal): Rename knd local variable to k. * mallocx.c (GC_generic_malloc_ignore_off_page, GC_malloc_ignore_off_page, GC_malloc_atomic_ignore_off_page): Redirect to GC_generic_malloc_aligned() passing IGNORE_OFF_PAGE. * typd_mlc.c (GC_generic_malloc_ignore_off_page): Likewise. * tests/gctest.c (run_one_test): Call GC_generic_malloc_ignore_off_page() (with size larger than HBLKSIZE); increment collectable_count.
* Fix mistyped GC_register_finalizer[_unreachable] in commentsIvan Maidanski2023-03-181-1/+1
| | | | | | | | (fix of commits 074de161d, f69ca1a96) * dbg_mlc.c (store_old): Fix name in comment ("GC_register_finalizer"). * include/gc/gc.h (GC_java_finalization): Fix name in comment ("GC_register_finalizer_unreachable").
* Add assertion about kind argument range in GC_register_describe_type_fnIvan Maidanski2023-02-121-0/+1
| | | | | * dbg_mlc.c (GC_register_describe_type_fn): Add assertion that kind is less than MAXOBJKINDS and not negative.
* Better document missing debugging version for aligned allocation routinesIvan Maidanski2023-01-311-0/+3
| | | | | | | | * dbg_mlc.c (GC_debug_free): Add TODO item to suppress a GC warning. * include/gc/leak_detector.h (aligned_alloc): Add comment that the debugging version is missing. * mallocx.c (GC_memalign): Add TODO item about the missing debugging version.
* Remove unused DCL_LOCK_STATEIvan Maidanski2023-01-301-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * alloc.c (GC_set_disable_automatic_collection, GC_set_stop_func, GC_get_disable_automatic_collection, GC_get_stop_func, GC_set_start_callback, GC_get_start_callback, GC_set_on_collection_event, GC_get_on_collection_event, GC_collect_a_little, GC_try_to_collect_general, GC_expand_hp): Remove DCL_LOCK_STATE. * alloc.c [!GC_DISABLE_INCREMENTAL] (GC_start_incremental_collection): Likewise. * dbg_mlc.c (GC_generate_random_backtrace, store_debug_info, GC_debug_register_displacement): Likewise. * dyn_load.c [DARWIN_DEBUG && !NO_DEBUGGING] (GC_dyld_image_add, GC_dyld_image_remove): Likewise. * finalize.c (GC_register_disappearing_link_inner, GC_unregister_disappearing_link, GC_complete_ongoing_collection, GC_set_toggleref_func, GC_get_toggleref_func, GC_toggleref_add, GC_set_await_finalize_proc, GC_get_await_finalize_proc, GC_unregister_long_link, GC_move_disappearing_link, GC_move_long_link, GC_register_finalizer_inner, GC_finalize, GC_invoke_finalizers, GC_notify_or_invoke_finalizers): Likewise. * fnlz_mlc.c (GC_init_finalized_malloc): Likewise. * gc_dlopen.c [!USE_PROC_FOR_LIBRARIES] (disable_gc_for_dlopen): Likewise. * gcj_mlc.c (GC_init_gcj_malloc, maybe_finalize, GC_core_gcj_malloc, GC_debug_gcj_malloc, GC_gcj_malloc_ignore_off_page): Likewise. * malloc.c (GC_alloc_large, GC_generic_malloc_inner, GC_generic_malloc_aligned, GC_malloc_kind_global, GC_generic_malloc_uncollectable, GC_free): Likewise. * mallocx.c (GC_realloc, GC_generic_malloc_ignore_off_page, GC_generic_malloc_many): Likewise. * mark.c (GC_print_trace): Likewise. * mark_rts.c (GC_add_roots, GC_clear_roots, GC_remove_roots): Likewise. * misc.c (GC_get_heap_usage_safe, GC_get_heap_usage_safe, GC_is_init_called, GC_init, GC_enable_incremental, GC_start_mark_threads, GC_set_warn_proc, GC_get_warn_proc, GC_set_abort_func, GC_get_abort_func, GC_enable, GC_disable, GC_new_free_list, GC_new_kind, GC_new_proc, GC_call_with_alloc_lock, GC_dump, GC_get_memory_use, GC_alloc_lock, GC_set_on_thread_event, GC_get_on_thread_event, GC_set_oom_fn, GC_get_oom_fn, GC_set_on_heap_resize, GC_get_on_heap_resize, GC_set_finalizer_notifier, GC_get_finalizer_notifier, GC_set_all_interior_pointers): Likewise. * obj_map.c (GC_register_displacement): Likewise. * os_dep.c (GC_get_stack_base, GC_print_callers): Likewise. * pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD] (GC_suspend_thread, GC_resume_thread, GC_is_thread_suspended): Likewise. * pthread_support.c (GC_is_thread_tsd_valid, GC_thread_is_registered, GC_register_altstack, GC_wait_for_gc_completion, GC_init_parallel, GC_do_blocking_inner, GC_suspend_self_blocked, GC_get_my_stackbottom, GC_call_with_gc_active, GC_unregister_my_thread, GC_pthread_cancel, GC_pthread_exit, GC_allow_register_threads, GC_register_my_thread, GC_thread_exit_proc, GC_pthread_join, GC_pthread_detach, GC_start_rtn_prepare_thread): Likewise. * ptr_chck.c (GC_set_same_obj_print_proc, GC_get_same_obj_print_proc, GC_set_is_valid_displacement_print_proc, GC_set_is_visible_print_proc, GC_get_is_valid_displacement_print_proc, GC_get_is_visible_print_proc): Likewise. * reclaim.c (GC_print_all_errors): Likewise. * typd_mlc.c (GC_add_ext_descriptor, GC_make_descriptor, GC_malloc_explicitly_typed_ignore_off_page, GC_calloc_explicitly_typed): Likewise. * alloc.c (GC_max_retries): Change type from GC_word to word. * include/private/gc_locks.h: Remove DCL_LOCK_STATE from comment, * include/private/gc_locks.h (DCL_LOCK_STATE): Do not define.
* Include stdio.h and stdlib.h only from gc_priv.hIvan Maidanski2022-09-261-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * allchblk.c: Do not include stdio.h directly. * alloc.c: Likewise. * dyn_load.c [(DYNAMIC_LOADING || MSWIN32 || MSWINCE || CYGWIN32) && !PCR]: Likewise. * mach_dep.c [!PLATFORM_MACH_DEP && !SN_TARGET_PSP2]: Likewise. * malloc.c: Likewise. * mallocx.c: Likewise. * mark.c: Likewise. * mark_rts.c: Likewise. * misc.c: Likewise. * new_hblk.c: Likewise. * os_dep.c: Likewise. * reclaim.c: Likewise. * tests/disclaim_bench.c: Likewise. * tests/gctest.c: Likewise. * dbg_mlc.c [KEEP_BACK_PTRS && !LINT2]: Do not include stdlib.h directly. * dyn_load.c [MSWIN32 || MSWINCE || CYGWIN32]: Likewise. * os_dep.c [HAIKU]: Likewise. * pthread_support.c [GC_PTHREADS && !GC_WIN32_THREADS]: Likewise. * tests/disclaim_bench.c: Likewise. * tests/gctest.c [!mips || !SYSTYPE_BSD43]: Likewise. * thread_local_alloc.c: Likewise. * include/private/gc_priv.h: Include stdio.h.
* Use cast to void instead of the attribute to indicate unused argumentsIvan Maidanski2022-09-151-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * CMakeLists.txt [BORLAND] (add_compile_options): Remove "/w-par"; reorder options. * CMakeLists.txt [!BORLAND && MSVC] (add_compile_options): Remove "/wd4100"; update comment. * NT_MAKEFILE (.c.obj): Likewise. * allchblk.c [!NO_DEBUGGING || GC_ASSERTIONS] (add_hb_sz): Use UNUSED_ARG() instead of GC_ATTR_UNUSED. * allchblk.c [USE_MUNMAP] (GC_adjust_num_unmapped): Likewise. * backgraph.c [MAKE_BACK_GRAPH] (pop_in_progress, reset_back_edge, update_max_height): Likewise. * checksums.c [CHECKSUMS] (GC_add_block): Likewise. * darwin_stop_world.c (GC_stack_range_for): Likewise. * dbg_mlc.c (GC_store_debug_info_inner, GC_debug_change_stubborn, GC_check_heap_block): Likewise. * finalize.c [!GC_NO_FINALIZATION] (GC_null_finalize_mark_proc): Likewise. * gcj_mlc.c [GC_GCJ_SUPPORT] (GC_gcj_fake_mark_proc): Likewise. * mallocx.c [!CPPCHECK] (GC_change_stubborn): Likewise. * mark.c (GC_noop6, clear_marks_for_block): Likewise. * mark.c [WRAP_MARK_SOME && (MSWIN32 || MSWINCE) && __GNUC__] (mark_ex_handler): Likewise. * mark.c [GC_DISABLE_INCREMENTAL] (GC_push_conditional): Likewise. * mark_rts.c (GC_push_current_stack, GC_push_roots): Likewise. * misc.c (GC_default_oom_fn, GC_set_handle_fork): Likewise. * misc.c [THREADS && !SIGNAL_BASED_STOP_WORLD] (GC_set_suspend_signal, GC_set_thr_restart_signal): Likewise. * misc.c [THREADS && UNIX_LIKE && !NO_GETCONTEXT] (callee_saves_pushed_dummy_fn): Likewise. * misc.c [!THREADS] (GC_do_blocking_inner): Likewise. * misc.c [!PARALLEL_MARK] (GC_set_markers_count): Likewise. * os_dep.c [OPENBSD] (GC_fault_handler_openbsd): Likewise. * os_dep.c [NEED_FIND_LIMIT || WRAP_MARK_SOME && !MSWIN32 && !MSWINCE || USE_PROC_FOR_LIBRARIES && THREADS] (GC_fault_handler): Likewise. * os_dep.c [!HAVE_GET_STACK_BASE && !NEED_FIND_LIMIT] (GC_get_stack_base): Likewise. * os_dep.c [MPROTECT_VDB && DARWIN] (catch_exception_raise_state, catch_exception_raise_state_identity, catch_exception_raise): Likewise. * pthread_stop_world.c [!NACL && !GC_OPENBSD_UTHREADS && !SUSPEND_HANDLER_NO_CONTEXT] (GC_suspend_sigaction): Likewise. * pthread_stop_world.c [!NACL && !GC_OPENBSD_UTHREADS] (GC_suspend_handler_inner): Likewise. * pthread_support.c (GC_do_blocking_inner): Likewise. * pthread_support.c [GC_ENABLE_SUSPEND_THREAD && SIGNAL_BASED_STOP_WORLD] (GC_suspend_self_blocked): Likewise. * tests/gctest.c [!DBG_HDRS_ALL] (fail_proc1): Likewise. * tests/gctest.c [(MSWIN32 && !__MINGW32__ || MSWINCE) && !NO_WINMAIN_ENTRY] (WinMain): Likewise. * tests/gctest.c [!PCR && !GC_WIN32_THREADS && !GC_PTHREADS && CPPCHECK && RTEMS] (Init): Likewise. * tests/gctest.c [GC_WIN32_THREADS && !GC_PTHREADS] (thr_run_one_test): Likewise. * tests/gctest.c [MSWINCE] (thr_window): Likewise. * tests/gctest.c [GC_PTHREADS] (thr_run_one_test): Likewise. * typd_mlc.c (GC_array_mark_proc): Likewise. * win32_threads.c (GC_register_altstack, GC_do_blocking_inner): Likewise. * win32_threads.c [!GC_PTHREADS && !GC_NO_THREADS_DISCOVERY] (GC_DllMain): Likewise. * cord/cordxtra.c (CORD_ATTR_UNUSED): Remove. * include/private/gc_priv.h [!GC_ATTR_UNUSED] (GC_ATTR_UNUSED): Likewise. * cord/cordxtra.c (CORD_nul_func): Cast unused argument to void instead of using CORD_ATTR_UNUSED. * cord/cordxtra.c [!GC_NO_FINALIZATION] (CORD_lf_close_proc): Likewise. * include/private/gc_priv.h [!UNUSED_ARG] (UNUSED_ARG): Define macro.
* Fix 'passing arg 1 of GC_apply_to_all_blocks from incompatible type' errorIvan Maidanski2022-08-051-1/+2
| | | | | | | | | | | | | | | | | | (fix of commit e717f1191) Issue #460 (bdwgc). * backgraph.c [MAKE_BACK_GRAPH] (per_object_helper): Add GC_CALLBACK modifier; change 2nd argument type from word to GC_word. * checksums.c [CHECKSUMS] (GC_add_block): Likewise. * dbg_mlc.c [!SHORT_DBG_HDRS] (GC_check_heap_block): Likewise. * mark.c (clear_marks_for_block): Likewise. * misc.c (block_add_size): Likewise. * reclaim.c (GC_reclaim_block, GC_print_block_descr, GC_do_enumerate_reachable_objects): Likewise. * checksums.c [CHECKSUMS] (GC_check_blocks): Remove unnecessary cast of zero to word. * include/gc/gc_mark.h (GC_apply_to_all_blocks): Add GC_ATTR_NONNULL(1).
* Update copyright information in alloc.c and other modified files (2022)Ivan Maidanski2022-05-271-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * CMakeLists.txt: Update year in copyright comment (2021 to 2022). * alloc.c: Likewise. * configure.ac: Likewise. * dyn_load.c: Likewise. * include/private/gc_priv.h: Likewise. * include/private/gcconfig.h: Likewise. * mallocx.c: Likewise. * mark.c: Likewise. * mark_rts.c: Likewise. * misc.c: Likewise. * os_dep.c: Likewise. * pthread_support.c: Likewise. * reclaim.c: Likewise. * tests/gctest.c: Likewise. * win32_threads.c: Likewise. * LICENSE: Update year (2021 to 2022). * allchblk.c: Add copyright line in header comment. * darwin_stop_world.c: Likewise. * dbg_mlc.c: Likewise. * gcj_mlc.c: Likewise. * headers.c: Likewise. * include/gc/gc_inline.h: Likewise. * include/gc/gc_mark.h: Likewise. * include/private/gc_locks.h: Likewise. * include/private/gc_pmark.h: Likewise. * include/private/pthread_stop_world.h: Likewise. * include/private/pthread_support.h: Likewise. * mach_dep.c: Likewise. * malloc.c: Likewise. * thread_local_alloc.c: Likewise. * typd_mlc.c: Likewise. * finalize.c: Update year in copyright comment (2020 to 2022). * include/gc/gc.h: Likewise. * pthread_stop_world.c: Likewise.
* Remove extra space after comma in license termsIvan Maidanski2022-05-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (reformatting) * CMakeLists.txt: Remove an extra space after comma in license header comment. * Makefile.am: Likewise. * allchblk.c: Likewise. * alloc.c: Likewise. * backgraph.c: Likewise. * blacklst.c: Likewise. * checksums.c: Likewise. * configure.ac: Likewise. * cord/cordbscs.c: Likewise. * cord/cordprnt.c: Likewise. * cord/cordxtra.c: Likewise. * cord/tests/cordtest.c: Likewise. * cord/tests/de.c: Likewise. * cord/tests/de_cmds.h: Likewise. * cord/tests/de_win.c: Likewise. * cord/tests/de_win.h: Likewise. * cord/tests/de_win.rc: Likewise. * darwin_stop_world.c: Likewise. * dbg_mlc.c: Likewise. * dyn_load.c: Likewise. * extra/gc.c: Likewise. * extra/msvc_dbg.c: Likewise. * extra/pcr_interface.c: Likewise. * extra/real_malloc.c: Likewise. * finalize.c: Likewise. * fnlz_mlc.c: Likewise. * gc_badalc.cc: Likewise. * gc_cpp.cc: Likewise. * gc_dlopen.c: Likewise. * gcj_mlc.c: Likewise. * headers.c: Likewise. * include/gc/cord.h: Likewise. * include/gc/cord_pos.h: Likewise. * include/gc/ec.h: Likewise. * include/gc/gc.h: Likewise. * include/gc/gc_backptr.h: Likewise. * include/gc/gc_config_macros.h: Likewise. * include/gc/gc_disclaim.h: Likewise. * include/gc/gc_gcj.h: Likewise. * include/gc/gc_inline.h: Likewise. * include/gc/gc_mark.h: Likewise. * include/gc/gc_pthread_redirects.h: Likewise. * include/gc/gc_tiny_fl.h: Likewise. * include/gc/gc_typed.h: Likewise. * include/gc/gc_version.h: Likewise. * include/gc/javaxfc.h: Likewise. * include/gc/leak_detector.h: Likewise. * include/include.am: Likewise. * include/private/darwin_semaphore.h: Likewise. * include/private/darwin_stop_world.h: Likewise. * include/private/dbg_mlc.h: Likewise. * include/private/gc_alloc_ptrs.h: Likewise. * include/private/gc_atomic_ops.h: Likewise. * include/private/gc_hdrs.h: Likewise. * include/private/gc_locks.h: Likewise. * include/private/gc_pmark.h: Likewise. * include/private/gc_priv.h: Likewise. * include/private/gcconfig.h: Likewise. * include/private/pthread_stop_world.h: Likewise. * include/private/pthread_support.h: Likewise. * include/private/specific.h: Likewise. * include/private/thread_local_alloc.h: Likewise. * m4/gc_set_version.m4: Likewise. * mach_dep.c: Likewise. * malloc.c: Likewise. * mallocx.c: Likewise. * mark.c: Likewise. * mark_rts.c: Likewise. * misc.c: Likewise. * new_hblk.c: Likewise. * obj_map.c: Likewise. * os_dep.c: Likewise. * pthread_start.c: Likewise. * pthread_stop_world.c: Likewise. * pthread_support.c: Likewise. * ptr_chck.c: Likewise. * reclaim.c: Likewise. * specific.c: Likewise. * tests/atomicops.c: Likewise. * tests/cpp.cc: Likewise. * tests/disclaim.c: Likewise. * tests/disclaim_bench.c: Likewise. * tests/gctest.c: Likewise. * tests/tests.am: Likewise. * tests/weakmap.c: Likewise. * thread_local_alloc.c: Likewise. * tools/setjmp_t.c: Likewise. * tools/threadlibs.c: Likewise. * typd_mlc.c: Likewise. * win32_threads.c: Likewise. * LICENSE: Remove an extra space after comma in license terms.
* Remove extra parentheses in return statementIvan Maidanski2022-05-011-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) Also, replace 0 to NULL where appropriate. * allchblk.c (setup_header, GC_get_first_part, GC_allochblk_nth): Remove outermost parentheses in the expression of return statement. * alloc.c (GC_never_stop_func, GC_timeout_stop_func, GC_adj_bytes_allocd, GC_try_to_collect_inner, GC_collect_a_little, GC_stopped_mark, GC_try_to_collect_general, GC_expand_hp_inner, GC_collect_or_expand, GC_allocobj): Likewise. * blacklst.c (GC_is_black_listed, GC_number_stack_black_listed, total_stack_black_listed): Likewise. * checksums.c (GC_checksum): Likewise. * cord/cordbscs.c (CORD_cat_char_star, CORD_cat, CORD_len, CORD_index_access_fn, CORD_apply_access_fn, CORD_substr_checked, CORD_substr, CORD_iter5, CORD_iter, CORD_riter4, CORD_riter, CORD_concat_forest, CORD_balance, CORD__pos_fetch, CORD__prev, CORD_prev, CORD_pos_to_cord, CORD_pos_valid): Likewise. * cord/cordprnt.c (extract_conv_spec, CORD_vsprintf, CORD_sprintf, CORD_fprintf, CORD_vfprintf, CORD_printf, CORD_vprintf): Likewise. * cord/cordxtra.c (CORD_cat_char, CORD_catn, CORD_fill_proc, CORD_batched_fill_proc, CORD_cmp, CORD_ncmp, CORD_to_char_star, CORD_from_char_star, CORD_to_const_char_star, CORD_fetch, CORD_put_proc, CORD_batched_put_proc, CORD_put, CORD_chr_proc, CORD_rchr_proc, CORD_batched_chr_proc, CORD_chr, CORD_rchr, CORD_str, CORD_from_file_eager, CORD_lf_func, CORD_from_file_lazy_inner, CORD_from_file_lazy, CORD_from_file): Likewise. * cord/tests/cordtest.c (test_fn, id_cord_fn, test_basics): Likewise. * cord/tests/de.c (line_pos, add_hist, retrieve_line, beep): Likewise. * cord/tests/de_win.c (WinMain, plain_chars, control_chars, WndProc): Likewise. * dbg_mlc.c (store_debug_info, GC_debug_generic_malloc, GC_debug_generic_malloc, GC_debug_realloc, GC_make_closure): Likewise. * dyn_load.c (GC_FirstDLOpenedLinkMap): Likewise. * extra/real_malloc.c (real_malloc): Likewise. * finalize.c (GC_register_disappearing_link, GC_unregister_disappearing_link): Likewise. * gc_dlopen.c (dlopen): Likewise. * gcj_mlc.c (maybe_finalize, GC_debug_gcj_malloc, GC_gcj_malloc_ignore_off_page): Likewise. * headers.c (GC_find_header, alloc_hdr, get_index, GC_install_header, GC_next_block, GC_prev_block): Likewise. * malloc.c (GC_generic_malloc): Likewise. * mallocx.c (GC_realloc, GC_generic_malloc_ignore_off_page): Likewise. * mark.c (GC_collection_in_progress, GC_mark_some, GC_signal_mark_stack_overflow, GC_block_was_dirty, GC_push_next_marked, GC_push_next_marked_dirty, GC_push_next_marked_uncollectable): Likewise. * mark_rts.c (GC_is_static_root, rt_hash, GC_roots_present, GC_remove_tmp_roots, GC_approx_sp): Likewise. * misc.c (GC_default_oom_fn, GC_clear_stack_inner, GC_base, GC_write, GC_get_warn_proc, GC_call_with_alloc_lock): Likewise. * new_hblk.c (GC_build_fl_clear2, GC_build_fl_clear4, GC_build_fl2, GC_build_fl4, GC_build_fl): Likewise. * obj_map.c (GC_register_displacement_inner): Likewise. * os_dep.c (GC_find_limit_openbsd, GC_skip_hole_openbsd, GC_get_writable_length, GC_get_writable_length, GC_get_main_stack_base, GC_FreeBSDGetDataStart, GC_unix_mmap_get_mem, GC_unix_sbrk_get_mem, os2_alloc, GC_wince_get_mem, GC_win32_get_mem, GC_push_thread_stack, GC_push_old_obj, GC_write_fault_handler, catch_exception_raise_state, catch_exception_raise_state_identity): Likewise. * pthread_support.c (GC_new_thread, GC_lookup_thread, GC_get_nprocs, pthread_sigmask, pthread_create): Likewise. * ptr_chck.c (GC_same_obj, GC_default_is_visible_print_proc, GC_default_is_valid_displacement_print_proc, GC_is_visible, GC_pre_incr, GC_post_incr): Likewise. * reclaim.c (GC_block_empty, GC_reclaim_uninit, GC_n_set_marks, GC_reclaim_all): Likewise. * tests/cpp.cc (main): Likewise. * tests/gctest.c (fake_gcj_mark_proc, reverse1, reverse, ints, gcj_reverse1, gcj_reverse, gcj_ints, uncollectable_ints, mktree, alloc8bytes, main, test): Likewise. * tools/if_mach.c (main): Likewise. * tools/if_not_there.c (main): Likewise. * tools/setjmp_t.c (getpagesize, main, g): Likewise. * typd_mlc.c (GC_add_ext_descriptor, GC_add_ext_descriptor, GC_double_descr, GC_make_array_descriptor, GC_make_sequence_descriptor, GC_typed_mark_proc, GC_descr_obj_size, GC_push_complex_descriptor, GC_array_mark_proc, GC_make_descriptor, GC_calloc_explicitly_typed): Likewise. * win32_threads.c (GC_new_thread, GC_lookup_thread_inner, GC_get_stack_min, GC_pthread_create, GC_pthread_start_inner): Likewise. * allchblk.c (GC_get_first_part, GC_allochblk_nth): Replace 0 to NULL where appropriate. * alloc.c (GC_allocobj): Likewise. * blacklst.c (GC_is_black_listed): Likewise. * cord/cordbscs.c (CORD_from_fn_inner, CORD_substr_checked): Likewise. * cord/cordxtra.c (CORD_cat_char, CORD_to_char_star, CORD_from_char_star, CORD_lf_func, CORD_from_file_lazy_inner): Likewise. * dbg_mlc.c (store_debug_info, GC_debug_generic_malloc, GC_debug_generic_malloc): Likewise. * dyn_load.c (GC_FirstDLOpenedLinkMap): Likewise. * gcj_mlc.c (GC_debug_gcj_malloc): Likewise. * headers.c (GC_next_block, GC_prev_block): Likewise. * malloc.c (GC_generic_malloc, strdup): Likewise. * mallocx.c (GC_realloc): Likewise. * misc.c (GC_default_oom_fn, GC_base): Likewise. * os_dep.c (GC_get_main_stack_base, os2_alloc, GC_win32_get_mem): Likewise. * pthread_support.c (GC_new_thread, GC_lookup_thread): Likewise. * ptr_chck.c (GC_same_obj, GC_is_visible, GC_default_is_valid_displacement_print_proc): Likewise. * tests/gctest.c (mktree): Likewise. * typd_mlc.c (GC_make_array_descriptor, GC_push_complex_descriptor, GC_array_mark_proc, GC_calloc_explicitly_typed): Likewise. * win32_threads.c (GC_new_thread, GC_lookup_thread_inner): Likewise. * alloc.c (GC_never_stop_func, GC_timeout_stop_func): Replace 0 and 1 (in return statement) to FALSE and TRUE, respectively. * include/private/gcconfig.h: Remove outermost parentheses in the expression of return statement in comment.
* Adjust indentation in C preprocessor directivesIvan Maidanski2022-04-181-5/+5
| | | | | | | | | | | | | | | | | | | | | | | (reformatting) * cord/tests/de.c: Adjust indentation in directives. * cord/tests/de_win.c: Likewise. * dbg_mlc.c: Likewise. * dyn_load.c: Likewise. * extra/AmigaOS.c: Likewise. * include/gc/ec.h: Likewise. * include/gc/gc_tiny_fl.h: Likewise. * include/private/gc_locks.h: Likewise. * include/private/gc_priv.h: Likewise. * include/private/gcconfig.h: Likewise. * include/private/thread_local_alloc.h: Likewise. * malloc.c: Likewise. * mark.c: Likewise. * os_dep.c: Likewise. * ptr_chck.c: Likewise. * reclaim.c: Likewise. * tests/gctest.c: Likewise. * tools/threadlibs.c: Likewise.
* Workaround 'data access w/o lock' code defect FP in GC_incr_bytes_freedIvan Maidanski2022-04-171-1/+9
| | | | | | * dbg_mlc.c [LINT2]: Include gc_alloc_ptrs.h. * dbg_mlc.c [LINT2] (GC_debug_free): Use GC_incr_bytes_freed() instead of direct increment of GC_bytes_freed.
* Ensure GC lock is held in add_leaked/smashed and check_heap_procIvan Maidanski2022-04-011-3/+5
| | | | | | | | | | (refactoring) * dbg_mlc.c [!SHORT_DBG_HDRS] (GC_add_smashed, GC_check_heap_proc): Assert that the GC lock is held (I_HOLD_LOCK). * reclaim.c (GC_add_leaked): Likewise. * dbg_mlc.c [!SHORT_DBG_HDRS] (GC_check_heap_proc): Remove "I hold lock" from comment not to duplicate the assertion.
* Eliminate data race reported by TSan in GC_have_errorsIvan Maidanski2022-04-011-3/+3
| | | | | | | | | | | | | | | | | * alloc.c (GC_gcollect): Replace read of GC_have_errors with get_have_errors() call. * malloc.c (GC_generic_malloc): Likewise. * mallocx.c (GC_generic_malloc_ignore_off_page, GC_generic_malloc_many): Likewise. * reclaim.c (GC_print_all_errors): Likewise. * dbg_mlc.c [!SHORT_DBG_HDRS] (GC_debug_free, GC_add_smashed): Replace GC_have_errors=TRUE with GC_SET_HAVE_ERRORS(). * reclaim.c (GC_add_leaked): Likewise. * include/private/gc_priv.h [AO_HAVE_store] (GC_have_errors): Change type from GC_bool to volatile AO_t; refine comment. * reclaim.c [AO_HAVE_store] (GC_have_errors): Likewise. * include/private/gc_priv.h (GC_SET_HAVE_ERRORS, get_have_errors): Define macro.
* Better document GC_generate_random_heap/valid_address API functionsIvan Maidanski2022-01-161-0/+2
| | | | | | | | | | | | | | Also, add an assertion to GC_print_backtrace and GC_generate_random_backtrace that the caller should not hold the GC lock. * dbg_mlc.c [KEEP_BACK_PTRS] (GC_print_backtrace, GC_generate_random_backtrace): Add assert that the GC lock is not held. * include/gc/gc_backptr.h (GC_generate_random_heap_address): Reformat comment. * include/gc/gc_backptr.h (GC_generate_random_heap_address, GC_generate_random_valid_address): Add comment that the caller should hold the GC lock.
* Fix missing lock when GC_generate_random_valid_address is calledIvan Maidanski2022-01-161-11/+10
| | | | | | | | | | | | | | | | | | Issue #414 (bdwgc). * dbg_mlc.c [KEEP_BACK_PTRS] (GC_generate_random_backtrace_no_gc): Remove definition. * dbg_mlc.c [KEEP_BACK_PTRS] (GC_generate_random_backtrace): Declare current local variable; expand GC_generate_random_backtrace_no_gc() manually. * finalize.c [KEEP_BACK_PTRS] (GC_notify_or_invoke_finalizers): Likewise. * dbg_mlc.c [KEEP_BACK_PTRS] (GC_generate_random_backtrace): Wrap GC_generate_random_valid_address() call into LOCK/UNLOCK. * finalize.c [KEEP_BACK_PTRS] (GC_notify_or_invoke_finalizers): UNLOCK after GC_generate_random_valid_address() call. * include/private/gc_priv.h [KEEP_BACK_PTRS] (GC_generate_random_backtrace_no_gc): Remove declaration.
* Remove duplication of random numbers generator formulaIvan Maidanski2022-01-151-14/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * dbg_mlc.c [LINT2] (GC_random): Rename to GC_rand and change return type from long to int; define as static (to match that in disclaim_test but w/o GC_ATTR_NO_SANITIZE_THREAD); define only if KEEP_BACK_PTRS. * dbg_mlc.c [LINT2] (GC_random): Change type of seed local variable to GC_RAND_STATE_T; use GC_RAND_NEXT() instead of the direct RNG formula. * tests/disclaim_test.c [GC_PTHREADS || LINT2] (GC_rand): Likewise. * tests/disclaim_weakmap_test.c [GC_PTHREADS || LINT2] (GC_rand): Likewise. * dbg_mlc.c [KEEP_BACK_PTRS && LINT2] (RANDOM): Replace GC_random() to (int)GC_rand(). * dbg_mlc.c [KEEP_BACK_PTRS && !LINT2] (GC_RAND_MAX): Undefine before redefine. * dbg_mlc.c [KEEP_BACK_PTRS] (GC_generate_random_heap_address): Cast RANDOM() and GC_RAND_MAX to word. * include/private/gc_priv.h [LINT2] (GC_random): Do not declare. * include/private/gc_priv.h [THREADS || LINT2] (GC_RAND_STATE_T, GC_RAND_NEXT): New macro; add comment. * include/private/gc_priv.h [THREADS || LINT2] (GC_RAND_MAX): Cast to int; define also in case of THREADS. * tests/disclaim_bench.c [LINT2] (seed): New static variable. * tests/disclaim_bench.c [LINT2] (rand): Define to GC_RAND_NEXT(&seed) instead of (int)GC_random(). * tests/disclaim_test.c [GC_PTHREADS || LINT2] (GC_rand): Do not refer GC_random in comment.
* Eliminate 'value exceeds maximum object size' gcc warning in debug_mallocIvan Maidanski2021-12-271-1/+7
| | | | | | | | Issue #406 (bdwgc). * dbg_mlc.c [_FORTIFY_SOURCE && !__clang__] (GC_debug_malloc): Expand SIZET_SAT_ADD() manually changing it to return GC_SIZE_MAX>>1 in case of addition overflow; add comment.
* Fix oldProc initialization in gc_cleanup and eliminate related warningsIvan Maidanski2021-12-261-5/+5
| | | | | | | | | | | | | | Issue #406 (bdwgc). GC_register_finalizer and similar functions do not guarantee to set *ofn an *ocd values, thus the client should do it. * dbg_mlc.c [!GC_NO_FINALIZATION] (GC_debug_register_finalizer_no_order, GC_debug_register_finalizer, GC_debug_register_finalizer_unreachable, GC_debug_register_finalizer_ignore_self): Initialize my_old_cd to 0; add comment. * include/gc/gc_cpp.h (gc_cleanup::gc_cleanup): Initialize oldProc and oldData to 0; add comment.
* Synchronize copyright years between README filesIvan Maidanski2021-11-221-1/+1
| | | | | | | | | | | | | | | * README.QUICK: Copy copyright years from README.md. * README.md (Copyright & Warranty): Adjust copyrights (synchronize with that of the source files). * alloc.c: Adjust copyrights in the file head comment and GC_copyright (synchronize with that of updated README.QUICK). * include/gc.h: Likewise. * alloc.c (GC_copyright): Reformat. * dbg_mlc.c: Add trailing dot to a copyright in the file head comment. * finalize.c: Likewise. * include/gc.h: Likewise. * tests/initsecondarythread.c: Reformat copyright in the file head comment (change C to lower case).
* Adjust spaces around '=' in printed messagesIvan Maidanski2021-09-151-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * checksums.c (GC_check_blocks): Remove space before '=' and add a space (if missing) after '=' in printed message. * darwin_stop_world.c [DEBUG_THREADS_EXTRA] (GC_FindTopOfStack): Likewise. * dbg_mlc.c (GC_print_obj, GC_debug_print_heap_obj_proc): Likewise. * dyn_load.c [IRIX5 || USE_PROC_FOR_LIBRARIES && !LINUX || HPUX] (GC_register_dynamic_libraries): Likewise. [DEBUG_VIRTUALQUERY] (GC_dump_meminfo): Likewise. * os_dep.c [NEED_PROC_MAPS] (GC_get_maps): Likewise. * os_dep.c [PROC_VDB] (GC_proc_read_dirty): Likewise. * os_dep.c [SOFT_VDB] (soft_read_dirty): Likewise. * pthread_support.c (set_marker_thread_name, GC_start_mark_threads_inner): Likewise. * pthread_support.c [DEBUG_THREADS] (GC_delete_thread, GC_unregister_my_thread_inner, GC_unregister_my_thread, GC_thread_exit_proc, GC_start_rtn_prepare_thread): Likewise. * pthread_support.c [GC_LINUX_THREADS] (GC_get_nprocs): Likewise. * tests/disclaim_weakmap_test.c [DEBUG_DISCLAIM_WEAKMAP] (weakmap_add, weakmap_disclaim): Likewise. * tests/subthread_create.c (run_one_test): Likewise. * win32_threads.c (GC_delete_thread, GC_push_stack_for, GC_get_next_stack): Likewise. * darwin_stop_world.c [DEBUG_THREADS] (GC_stack_range_for): Remove '=' in printed message and/or improve message. * mark.c (GC_signal_mark_stack_overflow): Likewise. * mark_rts.c [!NO_DEBUGGING] (GC_print_static_roots): Likewise. * pthread_stop_world.c [DEBUG_THREADS] (GC_push_all_stacks, GC_suspend_all): Likewise. * pthread_support.c (GC_thr_init): Likewise. * tests/disclaim_test.c (pair_dct, pair_new): Likewise. * tests/disclaim_weakmap_test.c (pair_check_rec): Likewise. * tests/initsecondarythread.c (main): Likewise. * tests/subthread_create.c (entry, main): Likewise. * tests/test.c [THREADS] (fork_a_thread, main): Likewise. * tests/test.c [MSWINCE] (thr_window): Likewise. * tests/test.c [NTHREADS>0] (main): Likewise. * tests/threadkey_test.c (main): Likewise. * dyn_load.c [ALPHA && OSF1 && DL_VERBOSE] (GC_register_dynamic_libraries): Reformat printed messages. * tests/disclaim_test.c (main): Remove space after '#' in printed message.
* Workaround '*_stubborn function is never used' cppcheck warningsIvan Maidanski2018-11-231-4/+6
| | | | | | | | | | * dbg_mlc.c (GC_debug_malloc_stubborn, GC_debug_change_stubborn): Do not define if CPPCHECK. * mallocx.c (GC_malloc_stubborn, GC_end_stubborn_change): Likewise. * include/gc.h (GC_debug_change_stubborn): Always mark as GC_ATTR_DEPRECATED (regardless of CPPCHECK). * tests/test.c [!PCR && !GC_WIN32_THREADS && !GC_PTHREADS && CPPCHECK] (main): Remove UNTESTED(GC_debug_change_stubborn).
* Eliminate 'casting signed to bigger unsigned int' CSA warningIvan Maidanski2018-11-121-1/+1
| | | | | | | | | | | | | | | | | | * cord/cordprnt.c (CORD_vsprintf): Cast prec, width, max_size, res local variables to unsigned. * cord/tests/cordtest.c (test_basics): Change type of i local variable from int to size_t; cast c local variable to unsigned char. * dbg_mlc.c (GC_store_debug_info_inner): Do not cast linenum parameter. * include/private/dbg_mlc.h (oh.oh_string, oh.oh_int): Refine comment. * include/private/dbg_mlc.h (oh.oh_int): Change type from word to signed_word. * misc.c [!GC_GET_HEAP_USAGE_NOT_NEEDED] (fill_prof_stats): Cast GC_markers_m1 to signed_word first. * misc.c (GC_init): Cast space_divisor local variable to unsigned (instead of word). * misc.c [!MSWIN32 && !MSWINCE && !OS2 && !MACOS && !GC_ANDROID_LOG] (GC_write): Cast bytes_written local variable to unsigned (instead of size_t).
* New API function to get size of object debug headerIvan Maidanski2018-10-151-1/+8
| | | | | | | | | | | | | | | | | | GC_get_debug_header_size() is exported in addition to GC_debug_header_size variable. The usage of the latter is deprecated. * dbg_mlc.c [CPPCHECK] (GC_start_debugging_inner): Call GC_noop1(GC_debug_header_size) to suppress a cppcheck warning about unused symbol. * dbg_mlc.c (GC_debug_header_size): Add const. * dbg_mlc.c (GC_get_debug_header_size): New API function definition. * include/gc_config_macros.h (GC_ATTR_CONST): New macro. * include/gc_mark.h (GC_debug_header_size): Add GC_ATTR_DEPRECATED and const; update comment. * include/gc_mark.h (GC_get_debug_header_size): New API public const function declaration; move the comment from GC_debug_header_size. * include/gc_mark.h (GC_USR_PTR_FROM_BASE): Use GC_get_debug_header_size() instead of GC_debug_header_size.
* Workaround 'bad pointer arithmetic' false waring in check_annotated_objIvan Maidanski2018-08-311-2/+2
| | | | | * dbg_mlc.c [!SHORT_DBG_HDRS] (GC_check_annotated_obj): Change (word*)ptr+ofs expressions to &((word*)ptr)[ofs].
* Fix test_cpp failure in case GC_DEBUG is definedIvan Maidanski2018-07-051-2/+8
| | | | | | | | | 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.
* New public API (PTR_STORE_AND_DIRTY) to simplify store-and-dirty operationIvan Maidanski2018-07-011-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | * cord/cordbscs.c (CORD_cat_char_star, CORD_cat, CORD_from_fn_inner, CORD_substr_closure): Replace the last store to the heap-allocated object, GC_END_STUBBORN_CHANGE() and GC_reachable_here() with GC_PTR_STORE_AND_DIRTY() call. * cord/tests/de.c (prune_map, add_map, replace_line): Likewise. * include/gc_inline.h (GC_CONS): Likewise. * tests/disclaim_test.c (pair_dct, pair_new): Likewise. * tests/test.c [!VERY_SMALL_CONFIG] (cons): Likewise. * tests/test.c (small_cons, small_cons_uncollectable, reverse_test_inner, mktree): Likewise. * tests/test.c [GC_GCJ_SUPPORT] (gcj_cons): Likewise. * tests/test.c [GC_PTHREADS && !SMALL_CONFIG && !GC_DEBUG] (alloc8bytes): Likewise. * tests/test.c [!NO_TYPED_TEST] (typed_test): Likewise. * tests/test_cpp.cc (main): Likewise. * dbg_mlc.c (GC_debug_ptr_store_and_dirty): Implement. * mallocx.c (GC_ptr_store_and_dirty): Likewise. * include/gc.h (GC_PTR_STORE_AND_DIRTY): New public macro. * include/gc.h (GC_debug_ptr_store_and_dirty, GC_ptr_store_and_dirty): Declare new public API function; add comment. * tests/test.c (reverse_test_inner): Remove tmp local variable. * tests/test.c (mktree): Remove right_left local variable.
* Remove stubborn objects allocation code completelyIvan Maidanski2018-05-151-50/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (code refactoring) * README.md (Incremental/Generational Collection): Remove information about stubborn objects; add information about GC_end_stubborn_change usage. * alloc.c [STUBBORN_ALLOC] (GC_finish_collection): Do not call GC_clean_changing_list. * checksums.c (NSUMS, GC_check_dirty): Remove comment related to stubborn objects. * checksums.c [STUBBORN_ALLOC] (GC_on_free_list): Remove. * doc/README.macros (STUBBORN_ALLOC): Likewise. * include/private/gc_priv.h [STUBBORN_ALLOC] (GC_sobjfreelist, GC_arrays._sobjfreelist, GC_changed_pages, GC_arrays._changed_pages, GC_prev_changed_pages, GC_arrays._prev_changed_pages): Likewise. * include/private/gc_priv.h (GC_read_changed, GC_page_was_changed, GC_clean_changing_list, GC_stubborn_init): Likewise. * tests/test.c (stubborn_count): Likewise. * checksums.c (GC_n_changed_errors): Likewise. * checksums.c [STUBBORN_ALLOC] (GC_update_check_page, GC_check_dirty): Do not update GC_n_changed_errors value. * checksums.c (GC_check_dirty): Do not check/print GC_n_changed_errors value. * configure.ac (checksums): Update help message (remove information about stubborn objects). * dbg_mlc.c (GC_print_obj, GC_debug_end_stubborn_change, GC_debug_realloc, GC_debug_generic_or_special_malloc): Do not handle STUBBORN object kind specially. * mallocx.c (GC_generic_or_special_malloc, GC_realloc): Likewise. * mark.c [!GC_DISABLE_INCREMENTAL] (GC_push_next_marked_dirty): Likewise. * dbg_mlc.c [STUBBORN_ALLOC] (GC_debug_malloc_stubborn): Redirect to GC_debug_malloc; remove GC_ATTR_MALLOC. * dbg_mlc.c [STUBBORN_ALLOC] (GC_debug_change_stubborn): Change to no-op. * doc/README.amiga (WHATS NEW): Do not reference GC_malloc_stubborn. * doc/README.macros (CHECKSUMS): Update (remove information about stubborn objects). * doc/gcdescr.md (Allocation, Generational Collection and Dirty Bits): Likewise. * doc/gcinterface.md (C/C++ Interface): Likewise. * doc/leak.md (Using the Garbage Collector as Leak Detector): Likewise. * doc/gcdescr.md (Generational Collection and Dirty Bits): Add information about MANUAL_VDB. * include/gc.h (GC_malloc, GC_free, GC_realloc): Update comment (remove information about stubborn objects). * malloc.c (GC_generic_malloc_inner): Likewise. * tests/test.c (reverse_test_inner): Likewise. * include/gc.h (GC_malloc_stubborn, GC_debug_malloc_stubborn): Add GC_ATTR_DEPRECATED; remove GC_ATTR_MALLOC and GC_ATTR_ALLOC_SIZE. * include/gc.h (GC_MALLOC_STUBBORN, GC_NEW_STUBBORN): Redirect to normal GC_MALLOC/NEW; add comment that stubborn objects allocation is deprecated. * include/gc.h [GC_DEBUG] (GC_CHANGE_STUBBORN): Redirect to GC_change_stubborn (not GC_debug_change_stubborn). * include/gc.h (GC_change_stubborn): Add GC_ATTR_DEPRECATED. * include/gc.h [!CPPCHECK] (GC_debug_change_stubborn): Likewise. * include/gc.h (GC_change_stubborn, GC_debug_change_stubborn): Remove GC_ATTR_NONNULL. * include/gc.h (GC_end_stubborn_change): Add comment related to usage when the library is built with MANUAL_VDB defined. * include/gc.h [_AMIGA && !GC_AMIGA_MAKINGLIB] (GC_malloc_stubborn): Remove macro. * include/private/gc_priv.h (STUBBORN_ALLOC): Remove comment. * include/private/gc_priv.h (STUBBORN): Replace with GC_N_KINDS_INITIAL_VALUE definition. * mark.c (GC_obj_kinds): Remove initialization for STUBBORN_ALLOC element. * mark.c (GC_N_KINDS_INITIAL_VALUE): Move to gc_priv.h. * mark.c (GC_n_rescuing_pages): Define only if GC_DISABLE_INCREMENTAL. * mark.c [STUBBORN_ALLOC] (GC_initiate_gc): Do not call GC_read_changed. * misc.c [STUBBORN_ALLOC] (GC_init): Do not call GC_stubborn_init. * stubborn.c (GC_malloc_stubborn): Remove GC_ATTR_MALLOC. * tests/test.c [!VERY_SMALL_CONFIG] (cons): Replace GC_MALLOC_STUBBORN with GC_MALLOC call; update collectable_count instead of stubborn_count. * tests/test.c (check_heap_stats): Do not print stubborn_count value.
* Fix missing GC_dirty invocation from debug_end_stubborn_changeIvan Maidanski2018-05-081-19/+15
| | | | | | | | | GC_debug_end_stubborn_change was no-op unless STUBBORN_ALLOC defined. * dbg_mlc.c (GC_debug_end_stubborn_change): De-duplicate definition; remove hhdr local variable. * dbg_mlc.c [!STUBBORN_ALLOC] (GC_debug_end_stubborn_change): Check p belongs to GC heap; call GC_end_stubborn_change(GC_base(p)).
* Use OPT_RA instead of STORE_DEBUG_INFO in dbg_mlcIvan Maidanski2018-03-201-15/+17
| | | | | | | | | | | (fix of commit d6ccabe) * dbg_mlc.c (STORE_DEBUG_INFO): Remove macro. * dbg_mlc.c (GC_debug_malloc, GC_debug_malloc_ignore_off_page, GC_debug_malloc_atomic_ignore_off_page, GC_debug_generic_malloc, GC_debug_malloc_stubborn, GC_debug_malloc_atomic, GC_debug_malloc_uncollectable, GC_debug_malloc_atomic_uncollectable): Replace STORE_DEBUG_INFO() to store_debug_info() call; use OPT_RA.
* Add assertions to ensure ADD_CALL_CHAIN is called holding the lockIvan Maidanski2018-03-151-7/+10
| | | | | | | | | | | | | | | (code refactoring) * alloc.c (GC_collect_a_little_inner, GC_allocobj): Add assertion that the allocation lock is held. * dbg_mlc.c (GC_store_debug_info_inner): Likewise. * dbg_mlc.c [DBG_HDRS_ALL] (GC_debug_generic_malloc_inner, GC_debug_generic_malloc_inner_ignore_off_page): Likewise. * finalize.c [!GC_TOGGLE_REFS_NOT_NEEDED] (ensure_toggleref_capacity): Likewise. * specific.c [USE_CUSTOM_SPECIFIC] (GC_key_create_inner): Likewise. * alloc.c (GC_allocobj): Remove comment (about the lock). * dbg_mlc.c [DBG_HDRS_ALL] (GC_debug_generic_malloc_inner): Likewise.
* Fix comment for debug_generic_malloc_inner[_ignore_off_page]Ivan Maidanski2018-03-151-2/+1
| | | | | | | (fix of commit 38965f279) * dbg_mlc.c [DBG_HDRS_ALL] (GC_debug_generic_malloc_inner): Update comment after adding GC_start_debugging[_inner] call.
* Fix the collector hang when it is configured with --enable-gc-debugIvan Maidanski2018-03-151-103/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Issue #205 (bdwgc). * dbg_mlc.c (GC_store_debug_info_inner): Remove comment (as it exists in the header); change from STATIC to GC_INNER. * dbg_mlc.c (STORE_DEBUG_INFO): New macro. * dbg_mlc.c (GC_store_debug_info): Change from GC_INNER to static; remove GC_ prefix; replace ptr_t to void*; add fn argument; replace "const char *string, int linenum" with GC_EXTRA_PARAMS; change "word sz" argument to "size_t lb"; allow p to be null (print error message in this case); call GC_start_debugging_inner unless GC_debugging_started; call ADD_CALL_CHAIN. * dbg_mlc.c (GC_start_debugging): Remove. * dbg_mlc.c (GC_debug_malloc, GC_debug_malloc_ignore_off_page, GC_debug_malloc_atomic_ignore_off_page, GC_debug_generic_malloc, GC_debug_malloc_atomic, GC_debug_malloc_uncollectable): Call STORE_DEBUG_INFO() instead of checking result for null and calling GC_start_debugging, ADD_CALL_CHAIN, GC_store_debug_info. * dbg_mlc.c [STUBBORN_ALLOC] (GC_debug_malloc_stubborn): Likewise. * dbg_mlc.c [GC_ATOMIC_UNCOLLECTABLE] (GC_debug_malloc_atomic_uncollectable): Likewise. * gcj_mlc.c [GC_GCJ_SUPPORT] (GC_debug_gcj_malloc): Call ADD_CALL_CHAIN while holding the lock; call GC_store_debug_info_inner (holding the lock) instead of GC_store_debug_info. * include/private/dbg_mlc.h (ADD_CALL_CHAIN): Update comment. * include/private/gc_priv.h (GC_store_debug_info): Replace with GC_store_debug_info_inner; update comment; change ptr_t to void*. * os_dep.c [SAVE_CALL_CHAIN] (GC_save_callers): Add assertion that the allocation lock is held; add comment.
* Avoid potential race when storing oh_back_ptr during parallel markingIvan Maidanski2018-03-071-1/+6
| | | | | | * dbg_mlc.c [KEEP_BACK_PTRS && PARALLEL_MARK] (GC_store_back_pointer): Store source to dest->oh_back_ptr atomically (unordered atomic store is sufficient here).
* Change backtrace-specific code to comply with C++11 standardIvan Maidanski2018-03-021-4/+4
| | | | | | | | | | | Issue #206 (bdwgc). * dbg_mlc.c (GC_get_back_ptr_info): Cast GC_REVEAL_POINTER() result to ptr_t (when assigned to bp local variable). * dbg_mlc.c (GC_generate_random_valid_address): Cast result of GC_generate_random_heap_address() to ptr_t. * dbg_mlc.c (GC_print_backtrace): Cast GC_print_heap_obj() argument to ptr_t.
* Convert GC source files to valid C++ codeIvan Maidanski2018-02-161-34/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Issue #206 (bdwgc). * alloc.c (GC_copyright): Change type from char* const to const char* const. * alloc.c (GC_set_fl_marks, GC_clear_fl_marks, GC_finish_collection, GC_allocobj): Add missing explicit casts from void* to ptr_t. * backgraph.c [MAKE_BACK_GRAPH] (add_back_edges): Likewise. * blacklst.c (GC_default_print_heap_obj_proc, GC_print_blacklisted_ptr): Likewise. * dbg_mlc.c (GC_get_back_ptr_info, GC_store_debug_info_inner, GC_store_debug_info, GC_debug_malloc, GC_debug_malloc_ignore_off_page, GC_debug_malloc_atomic_ignore_off_page, GC_debug_generic_malloc, GC_debug_malloc_stubborn, GC_debug_malloc_atomic, GC_debug_malloc_uncollectable, GC_debug_malloc_atomic_uncollectable, GC_debug_free, GC_debug_free_inner, GC_debug_register_finalizer, GC_debug_register_finalizer_no_order, GC_debug_register_finalizer_unreachable, GC_debug_register_finalizer_ignore_self): Likewise. * finalize.c (GC_grow_table, push_and_mark_object, ensure_toggleref_capacity, GC_dump_finalization_links, GC_dump_finalization, GC_make_disappearing_links_disappear, GC_remove_dangling_disappearing_links, GC_finalize): Likewise. * gcj_mlc.c (GC_gcj_malloc, GC_debug_gcj_malloc, GC_gcj_malloc_ignore_off_page): Likewise. * include/private/gc_pmark.h (PUSH_CONTENTS_HDR): Likewise. * mallocx.c (GC_memalign): Likewise. * mark.c (GC_mark_from, GC_mark_and_push, GC_push_all_eager, GC_push_all_stack, GC_push_marked1, GC_push_marked2, GC_push_marked4): Likewise. * mark_rts.c (GC_exclude_static_roots_inner): Likewise. * misc.c (GC_base): Likewise. * new_hblk.c (GC_new_hblk): Likewise. * pthread_support.c (GC_register_altstack, GC_thr_init, GC_record_stack_base): Likewise. * ptr_chck.c (GC_is_visible): Likewise. * reclaim.c (GC_reclaim_small_nonempty_block, GC_disclaim_and_reclaim_or_free_small_block): Likewise. * thread_local_alloc.c (GC_mark_thread_local_fls_for): Likewise. * typd_mlc.c (GC_typed_mark_proc, GC_malloc_explicitly_typed_ignore_off_page): Likewise. * win32_threads.c (GC_record_stack_base, GC_get_stack_min, GC_push_stack_for): Likewise. * blacklst.c (GC_copy_bl): Rename "new" argument to "dest". * dbg_mlc.c (GC_store_debug_info_inner, GC_print_smashed_obj): Change type of p argument from ptr_t to void*. * include/private/gc_priv.h (GC_is_heap_base, GC_is_static_root): Likewise. * mark_rts.c [!THREADS] (GC_is_static_root): Likewise. * os_dep.c (GC_is_malloc_heap_base, GC_is_heap_base): Likewise. * ptr_chck.c (GC_on_stack): Likewise. * dbg_mlc.c (GC_print_obj): Change type of kind_str local variable from char* to const char*. * dbg_mlc.c (GC_debug_strdup, GC_debug_strndup): Cast result of GC_debug_malloc_atomic() to char*. * mallocx.c (GC_strdup, GC_strndup): Likewise. * dbg_mlc.c (GC_debug_wcsdup): Cast result of GC_debug_malloc_atomic() to wchar_t*. * mallocx.c (GC_wcsdup): Likewise. * dyn_load.c [MSWIN32 || MSWINCE || CYGWIN32] (GC_register_dynamic_libraries): Cast p local variable to char*. * os_dep.c (GC_register_data_segments): Likewise. * fnlz_mlc.c [ENABLE_DISCLAIM] (GC_finalized_disclaim): Cast masked fc_word to struct GC_finalizer_closure* (instead of void*). * fnlz_mlc.c [ENABLE_DISCLAIM] (GC_finalized_malloc): Cast result of GC_malloc_kind() to word*. * typd_mlc.c (GC_malloc_explicitly_typed, GC_calloc_explicitly_typed): Likewise. * include/private/gc_priv.h (WARN): Cast away const qualifier for msg (and the string literal). * misc.c (GC_default_on_abort): Remove cast to void* for WRITE() buf argument. * misc.c (GC_new_free_list_inner): Cast result local variable to void**. * misc.c (GC_new_free_list): Change type of result local variable from void* to void**. * pthread_support.c (GC_start_rtn_prepare_thread): Cast arg to struct start_info*. * win32_threads.c [GC_PTHREADS] (GC_pthread_start_inner): Likewise. * reclaim.c (GC_print_free_list): Replace ptr_t flh to void *flh_next local variable; remove redundant casts. * tools/if_mach.c (EXECV_ARGV_T): New macro; add comment. * tools/if_not_there.c (EXECV_ARGV_T): Likewise. * tools/if_mach.c (main): Use EXECV_ARGV_T instead of void* for execvp() argument. * tools/if_not_there.c (main): Likewise. * typd_mlc.c (LeafDescriptor, ComplexArrayDescriptor, SequenceDescriptor): Move struct definition out of union ComplexDescriptor. * typd_mlc.c (GC_add_ext_descriptor): Rename "new" local variable to newExtD. * win32_threads.c (GC_CreateThread, GC_beginthreadex): Cast result of GC_malloc_uncollectable() to thread_args*. * win32_threads.c [PARALLEL_MARK && !MSWINCE && __cplusplus] (GC_thr_init): Do not cast GetProcessAffinityMask() arguments to void*.
* Change type of hb_sz field (of hblkhdr) from size_t to wordIvan Maidanski2018-02-081-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is needed to make the size of hb_sz to be the same as of AO_t. * allchblk.c [USE_MUNMAP] (GC_unmap_old): Cast hhdr->hb_sz to size_t when passed to GC_unmap(). * allchblk.c (GC_allochblk_nth): Cast hhdr->hb_sz to signed_word when assigned to size_avail. * allchblk.c [USE_MUNMAP] (GC_allochblk_nth): Cast hhdr->hb_sz to size_t when passed to GC_remap(). * alloc.c (GC_set_fl_marks, GC_clear_fl_marks): Change type of sz and bit_no local variables from size_t/unsigned to word. * dbg_mlc.c (GC_check_heap_block): Likewise. * backgraph.c [MAKE_BACK_GRAPH] (per_object_helper): Cast hhdr->hb_sz to size_t; change type of i local variables from int to size_t. * checksums.c [CHECKSUMS] (GC_on_free_list): Change type of sz local variable from size_t to word. * mark.c (GC_push_marked, GC_push_unconditionally, GC_block_was_dirty): Likewise. * reclaim.c (GC_reclaim_small_nonempty_block, GC_disclaim_and_reclaim_or_free_small_block, GC_reclaim_block, GC_n_set_marks): Likewise. * checksums.c [CHECKSUMS] (GC_add_block): Remove bytes local variable (to avoid casting of hhdr->hb_sz). * dbg_mlc.c (GC_debug_free): Change type of i and obj_sz local variables from size_t to word. * dbg_mlc.c (GC_check_leaked): Likewise. * extra/pcr_interface.c (GC_enumerate_block): Change type of sz local variable from int to size_t. * extra/pcr_interface.c (GC_enumerate_block): Cast hhdr->hb_sz to size_t when assigned to sz. * mallocx.c (GC_realloc): Likewise. * mark.c (GC_set_hdr_marks): Likewise. * reclaim.c (GC_do_enumerate_reachable_objects): Likewise. * include/private/gc_pmark.h [MARK_BIT_PER_OBJ] (PUSH_CONTENTS_HDR): Cast hhdr->hb_sz to size_t in assignment of obj_displ. * include/private/gc_priv.h (struct hblkhdr): Change type of hb_sz from size_t to word. * include/private/gc_priv.h (MARK_BIT_NO): Cast offset argument to word instead of unsigned. * malloc.c (GC_free): Cast hhdr->hb_sz to size_t. * mallocx.c (GC_get_kind_and_size): Likewise. * mark.c (GC_clear_hdr_marks): Likewise. * misc.c (GC_size): Likewise. * misc.c (GC_do_blocking): Remove redundant cast of hhdr->hb_sz. * reclaim.c (GC_reclaim_clear, GC_reclaim_uninit, GC_disclaim_and_reclaim, GC_continue_reclaim): Change type of sz argument from size_t to word. * typd_mlc.c (GC_array_mark_proc): Change type of sz and nwords local variables from size_t to word.
* Eliminate TSan warning about data race when accessing GC_debugging_startedIvan Maidanski2017-11-171-8/+13
| | | | | | | | | | | | | | | | Now GC_debugging_started variable is double-checked with the allocation lock held before calling GC_start_debugging_inner. * dbg_mlc.c (GC_start_debugging_inner): Define as GC_INNER (instead of STATIC). * dbg_mlc.c [THREADS] (GC_start_debugging): Define as STATIC; do not call GC_start_debugging_inner() if GC_debugging_started. * dbg_mlc.c [!THREADS] (GC_start_debugging): Define as macro (redirect to GC_start_debugging_inner). * gcj_mlc.c (GC_debug_gcj_malloc): Call GC_start_debugging_inner (holding the lock) instead of GC_start_debugging. * include/private/gc_priv.h (GC_start_debugging): Rename to GC_start_debugging_inner; improve usage comment.
* Add TODO item to suppress 'called on pointer without debugging info'Ivan Maidanski2017-09-191-0/+4
| | | | | | * dbg_mlc.c [REDIRECT_FREE && USE_PROC_FOR_LIBRARIES] (GC_debug_free): Add TODO item not to call GC_err_printf() when free() is called from libpthread or libdl.
* Do not call BCOPY and BZERO if size is zeroIvan Maidanski2017-08-091-2/+4
| | | | | | | | | | | | | | | | | | | | * dbg_mlc.c (GC_debug_strndup): Do not call BCOPY() if elements count is zero. * dbg_mlc.c (GC_debug_realloc): Likewise. * finalize.c [!GC_TOGGLE_REFS_NOT_NEEDED] (ensure_toggleref_capacity): Likewise. * malloc.c [REDIRECT_MALLOC && !strndup] (strndup): Likewise. * mallocx.c (GC_strndup): Likewise. * misc.c [!GC_GET_HEAP_USAGE_NOT_NEEDED] (GC_get_prof_stats): Likewise. * os_dep.c [SAVE_CALL_CHAIN && GC_HAVE_BUILTIN_BACKTRACE] (GC_save_callers): Likewise. * reclaim.c (GC_print_all_errors): Likewise. * malloc.c (GC_free): Do not call BZERO() if elements count is zero. * malloc.c [THREADS] (GC_free_inner): Likewise. * reclaim.c (GC_print_all_errors): Likewise. * misc.c [!GC_GET_HEAP_USAGE_NOT_NEEDED && THREADS] (GC_get_prof_stats_unsafe): Do not call fill_prof_stats() and BCOPY() if stats_sz is zero.
* Fix leak_test crash in print_callers if free() is redirectedIvan Maidanski2017-08-071-0/+8
| | | | | | | | | | | | | | * dbg_mlc.c [REDIRECT_MALLOC && (GC_LINUX_THREADS || GC_SOLARIS_THREADS || MSWIN32 || NEED_CALLINFO && GC_HAVE_BUILTIN_BACKTRACE)] (GC_debug_free): If the object is not in the GC heap then just return (instead of ABORT). * malloc.c [REDIRECT_MALLOC && NEED_CALLINFO && GC_HAVE_BUILTIN_BACKTRACE] (GC_free): If hhdr is null (i.e. the object is not in the GC heap) then return without the object deallocation; add comment. * os_dep.c [NEED_CALLINFO && GC_HAVE_BUILTIN_BACKTRACE && !GC_BACKTRACE_SYMBOLS_BROKEN] (GC_print_callers): Adjust comment for free().
* Workaround 'insecure libc pseudo-random number generator used' code defectIvan Maidanski2016-10-281-2/+18
| | | | | | | | | | | | | | | | * dbg_mlc.c [LINT2] (GC_random): New function. * dbg_mlc.c [KEEP_BACK_PTRS && LINT2] (RANDOM): Define to GC_random. * dbg_mlc.c [KEEP_BACK_PTRS && LINT2]: Do not include stdlib.h. * dbg_mlc.c [KEEP_BACK_PTRS && !LINT2] (GC_RAND_MAX): Define. * dbg_mlc.c (GC_generate_random_heap_address): Replace RAND_MAX with GC_RAND_MAX. * include/private/gc_priv.h [LINT2] (GC_RAND_MAX): New macro. * include/private/gc_priv.h [LINT2] (GC_random): Prototype (as GC_API_PRIV). * tests/disclaim_bench.c [LINT2] (rand): Redefine to GC_random. * tests/disclaim_test.c [LINT2] (rand): Likewise. * tests/disclaim_test.c [LINT2]: Include private/gc_priv.h instead of config.h.
* Eliminate 'value of GC_RETURN_ADDR_PARENT unknown' cppcheck info messagesIvan Maidanski2016-10-221-1/+1
| | | | | | | | * dbg_mlc.c [GC_ADD_CALLER]: Replace defined(GC_RETURN_ADDR_PARENT) with defined(GC_HAVE_RETURN_ADDR_PARENT). * include/private/gc_priv.h (GC_DBG_EXTRAS): Likewise. * include/gc_config_macros.h [GC_RETURN_ADDR_PARENT] (GC_HAVE_RETURN_ADDR_PARENT): New macro.
* Eliminate 'printf format specifies type void*' GCC pedantic warningsIvan Maidanski2016-10-211-6/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Explicitly cast pointer arguments (passed to printf and ABORT_ARGn) to void* to match %p format specifier. * allchblk.c [!NO_DEBUGGING] (GC_dump_regions): Cast arguments to void* those printf format specifier is %p. * alloc.c [!NO_DEBUGGING] (GC_print_heap_sects): Likewise. * backgraph.c [MAKE_BACK_GRAPH] (backwards_height): Likewise. * blacklst.c (GC_default_print_heap_obj_proc): Likewise. * blacklst.c [PRINT_BLACK_LIST] (GC_print_blacklisted_ptr): Likewise. * cord/cordbscs.c (CORD_dump_inner): Likewise. * darwin_stop_world.c [DEBUG_THREADS_EXTRA] (GC_FindTopOfStack): Likewise. * darwin_stop_world.c [DEBUG_THREADS] (GC_stack_range_for): Likewise. * dbg_mlc.c (GC_print_obj): Likewise. * dbg_mlc.c [!SHORT_DBG_HDRS] (GC_print_smashed_obj): Likewise. * dyn_load.c [HAVE_DL_ITERATE_PHDR] (GC_register_dynamic_libraries_dl_iterate_phdr): Likewise. * dyn_load.c [IRIX5] (GC_register_dynamic_libraries): Likewise. * finalize.c [!NO_DEBUGGING] (GC_dump_finalization_links, GC_dump_finalization): Likewise. * include/private/gc_pmark.h [MARK_BIT_PER_GRANULE || MARK_BIT_PER_OBJ] (PUSH_CONTENTS_HDR): Likewise. * mark.c [ENABLE_TRACE] (GC_mark_from): Likewise. * mark_rts.c [!NO_DEBUGGING] (GC_print_static_roots): Likewise. * mark_rts.c [DEBUG_ADD_DEL_ROOTS] (GC_add_roots_inner, GC_remove_root_at_pos): Likewise. * misc.c [ENABLE_TRACE] (GC_init): Likewise. * os_dep.c [LINUX || HURD] (GC_init_linux_data_start): Likewise. * os_dep.c [!OS2 && !MSWIN32] (GC_register_data_segments): Likewise. * os_dep.c [USE_MUNMAP && !USE_WINALLOC && !NACL] (GC_remap): Likewise. * os_dep.c [!DARWIN && !MSWIN32 && !MSWINCE] (GC_write_fault_handler): Likewise. * os_dep.c [PROC_VDB && DEBUG_DIRTY_BITS] (GC_read_dirty): Likewise. * os_dep.c [MPROTECT_VDB && DARWIN && BROKEN_EXCEPTION_HANDLING] (catch_exception_raise): Likewise. * pthread_stop_world.c [DEBUG_THREADS] (GC_push_all_stacks): Likewise. * pthread_support.c [DEBUG_THREADS] (GC_unregister_my_thread_inner, GC_unregister_my_thread, GC_start_rtn_prepare_thread): Likewise. * reclaim.c [!NO_DEBUGGING] (GC_print_free_list): Likewise. * specific.c [USE_CUSTOM_SPECIFIC && GC_ASSERTIONS] (GC_check_tsd_marks): Likewise. * win32_threads.c [DEBUG_THREADS] (GC_push_stack_for): Likewise. * win32_threads.c [GC_PTHREADS && DEBUG_THREADS] (GC_pthread_join, GC_pthread_create, GC_pthread_start_inner, GC_thread_exit_proc): Likewise. * dbg_mlc.c: Remove duplicate check of SHORT_DBG_HDRS. * include/private/gc_pmark.h [MARK_BIT_PER_GRANULE || MARK_BIT_PER_OBJ] (PUSH_CONTENTS_HDR): Add missing parentheses around "source" argument when casting it to ptr_t.
* Fix malloc routines to prevent size value wrap-aroundIvan Maidanski2016-09-231-11/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | See issue #135 on Github. * allchblk.c (GC_allochblk, GC_allochblk_nth): Use OBJ_SZ_TO_BLOCKS_CHECKED instead of OBJ_SZ_TO_BLOCKS. * malloc.c (GC_alloc_large): Likewise. * alloc.c (GC_expand_hp_inner): Type of "bytes" local variable changed from word to size_t; cast ROUNDUP_PAGESIZE argument to size_t; prevent overflow when computing GC_heapsize+bytes > GC_max_heapsize. * dbg_mlc.c (GC_debug_malloc, GC_debug_malloc_ignore_off_page, GC_debug_malloc_atomic_ignore_off_page, GC_debug_generic_malloc, GC_debug_generic_malloc_inner, GC_debug_generic_malloc_inner_ignore_off_page, GC_debug_malloc_stubborn, GC_debug_malloc_atomic, GC_debug_malloc_uncollectable, GC_debug_malloc_atomic_uncollectable): Use SIZET_SAT_ADD (instead of "+" operator) to add extra bytes to lb value. * fnlz_mlc.c (GC_finalized_malloc): Likewise. * gcj_mlc.c (GC_debug_gcj_malloc): Likewise. * include/private/gc_priv.h (ROUNDUP_GRANULE_SIZE, ROUNDED_UP_GRANULES, ADD_SLOP, ROUNDUP_PAGESIZE): Likewise. * include/private/gcconfig.h (GET_MEM): Likewise. * mallocx.c (GC_malloc_many, GC_memalign): Likewise. * os_dep.c (GC_wince_get_mem, GC_win32_get_mem): Likewise. * typd_mlc.c (GC_malloc_explicitly_typed, GC_malloc_explicitly_typed_ignore_off_page, GC_calloc_explicitly_typed): Likewise. * headers.c (GC_scratch_alloc): Change type of bytes_to_get from word to size_t (because ROUNDUP_PAGESIZE_IF_MMAP result type changed). * include/private/gc_priv.h: Include limits.h (unless SIZE_MAX already defined). * include/private/gc_priv.h (GC_SIZE_MAX, GC_SQRT_SIZE_MAX): Move from malloc.c file. * include/private/gc_priv.h (SIZET_SAT_ADD): New macro (defined before include gcconfig.h). * include/private/gc_priv.h (EXTRA_BYTES, GC_page_size): Change type to size_t. * os_dep.c (GC_page_size): Likewise. * include/private/gc_priv.h (ROUNDUP_GRANULE_SIZE, ROUNDED_UP_GRANULES, ADD_SLOP, ROUNDUP_PAGESIZE): Add comment about the argument. * include/private/gcconfig.h (GET_MEM): Likewise. * include/private/gc_priv.h (ROUNDUP_GRANULE_SIZE, ROUNDED_UP_GRANULES, ADD_SLOP, OBJ_SZ_TO_BLOCKS, ROUNDUP_PAGESIZE, ROUNDUP_PAGESIZE_IF_MMAP): Rename argument to "lb". * include/private/gc_priv.h (OBJ_SZ_TO_BLOCKS_CHECKED): New macro. * include/private/gcconfig.h (GC_win32_get_mem, GC_wince_get_mem, GC_unix_get_mem): Change argument type from word to int. * os_dep.c (GC_unix_mmap_get_mem, GC_unix_get_mem, GC_unix_sbrk_get_mem, GC_wince_get_mem, GC_win32_get_mem): Likewise. * malloc.c (GC_alloc_large_and_clear): Call OBJ_SZ_TO_BLOCKS only if no value wrap around is guaranteed. * malloc.c (GC_generic_malloc): Do not check for lb_rounded < lb case (because ROUNDED_UP_GRANULES and GRANULES_TO_BYTES guarantees no value wrap around). * mallocx.c (GC_generic_malloc_ignore_off_page): Likewise. * misc.c (GC_init_size_map): Change "i" local variable type from int to size_t. * os_dep.c (GC_write_fault_handler, catch_exception_raise): Likewise. * misc.c (GC_envfile_init): Cast len to size_t when passed to ROUNDUP_PAGESIZE_IF_MMAP. * os_dep.c (GC_setpagesize): Cast GC_sysinfo.dwPageSize and GETPAGESIZE() to size_t (when setting GC_page_size). * os_dep.c (GC_unix_mmap_get_mem, GC_unmap_start, GC_remove_protection): Expand ROUNDUP_PAGESIZE macro but without value wrap-around checking (the argument is of word type). * os_dep.c (GC_unix_mmap_get_mem): Replace -GC_page_size with ~GC_page_size+1 (because GC_page_size is unsigned); remove redundant cast to size_t. * os_dep.c (GC_unix_sbrk_get_mem): Add explicit cast of GC_page_size to SBRK_ARG_T. * os_dep.c (GC_wince_get_mem): Change type of res_bytes local variable to size_t. * typd_mlc.c: Do not include limits.h. * typd_mlc.c (GC_SIZE_MAX, GC_SQRT_SIZE_MAX): Remove (as defined in gc_priv.h now).
* Fix 'void pointers in calculations: behavior undefined' cppcheck warningIvan Maidanski2016-09-141-1/+1
| | | | | * dbg_mlc.c (OFN_UNSET): Replace -1 with ~(signed_word)0; add outermost parentheses.
* Eliminate 'scope of variable can be reduced' cppcheck warningsIvan Maidanski2016-08-271-1/+2
| | | | | | | | | | | | | | | | | * cord/cordbscs.c (CORD_cat_char_star, CORD_from_fn, CORD_substr_checked, CORD_riter4, CORD_init_min_len): Move local variable declaration to the inner scope where the variable is used. * cord/cordxtra.c (CORD_cmp, CORD_ncmp, CORD_from_file_eager): Likewise. * cord/tests/cordtest.c (test_basics): Likewise. * cord/tests/de.c (line_pos, replace_line): Likewise. * dbg_mlc.c (GC_generate_random_heap_address): Likewise. * mark.c (GC_print_trace_inner): Likewise. * misc.c (GC_printf): Likewise. * cord/cordbscs.c (CORD_cat_char_star, CORD_from_fn, CORD_substr_checked, CORD_riter4, CORD_init_min_len): Remove "register" keyword for the moved variable. * cord/cordxtra.c (CORD_cmp, CORD_ncmp, CORD_from_file_eager): Likewise. * cord/tests/de.c (replace_line): Likewise.