summaryrefslogtreecommitdiff
path: root/malloc.c
Commit message (Collapse)AuthorAgeFilesLines
* Make comparisons to the lowest heap boundary strictIvan Maidanski2023-05-131-5/+3
| | | | | | | | | | | | | | | | | | | | | | * alloc.c (GC_expand_hp_inner): Subtract sizeof(word) from new_limit (for the case when comparing to GC_least_plausible_heap_addr). * backgraph.c [MAKE_BACK_GRAPH] (add_back_edges): Compare current 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). * malloc.c [GC_ASSERTIONS] (GC_malloc_kind_global): Likewise. * include/gc/gc_mark.h (GC_MARK_AND_PUSH): Replace greater-or-equal to strictly greater when comparing to GC_least_plausible_heap_addr. * include/private/gc_pmark.h (GC_PUSH_ONE_STACK, GC_PUSH_ONE_HEAP): Likewise. * include/private/gc_priv.h [MAKE_BACK_GRAPH] (SET_REAL_HEAP_BOUNDS, GC_least_real_heap_addr, GC_greatest_real_heap_addr): Define. * mark.c (GC_mark_from, GC_push_all): Add dummy "| GC_DS_LENGTH" when storing length to mse_descr.w. * mark.c (GC_mark_from): Replace greater-or-equal to strictly greater when comparing to least_ha variable. * typd_mlc.c (GC_typed_mark_proc): Likewise. * mark.c [GC_DS_TAGS>ALIGNMENT-1] (GC_push_all): Simplify code to round up length.
* Fix 'scope of lg can be reduced' cppcheck warning in generic_malloc_alignedIvan Maidanski2023-04-121-1/+7
| | | | | | | (fix of commit 274e5ced8) * malloc.c [!THREADS] (GC_generic_malloc_aligned): Define lg local variable inside inner block (for use only by GRANULES_TO_BYTES).
* Do not add extra byte to large ignore-off-page objectsIvan Maidanski2023-04-121-4/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For ignore-off-page objects the client should guarantee the pointer within the first heap block of the object, thus no need to add an extra byte for such objects if the object size of at least one heap block. * allchblk.c (setup_header): Add assertion that byte_sz is not less than ALIGNMENT. * allchblk.c [ALIGNMENT>GC_DS_TAGS] (setup_header): Modify descr local variable to make it zero if IGNORE_OFF_PAGE flag is set and kind is NORMAL (and object size is not less than HBLKSIZE); add comment. * mallocx.c [ALIGNMENT>GC_DS_TAGS] (GC_realloc): Likewise. * include/gc/gc.h (GC_all_interior_pointers): Update comment. * include/private/gc_priv.h [MAX_EXTRA_BYTES==0] (ADD_EXTRA_BYTES): Define as no-op. * malloc.c (GC_generic_malloc_inner): Define lb_adjusted local variable; pass lb_adjusted to GC_alloc_large_and_clear(). * malloc.c [MAX_EXTRA_BYTES>0] (GC_generic_malloc_inner): Set lb_adjusted to lb if IGNORE_OFF_PAGE flag is set and lb is not less than HBLKSIZE. * malloc.c [MAX_EXTRA_BYTES>0] (GC_generic_malloc_aligned): Set lb_rounded without EXTRA_BYTES added (and compute lg based on lb_rounded) if IGNORE_OFF_PAGE is set and lb is not less than HBLKSIZE. * mallocx.c (GC_realloc): Define ok local variable. * typd_mlc.c (GC_malloc_explicitly_typed_ignore_off_page): Remove lb_adjusted local variable; call GC_malloc_explicitly_typed() if lb is smaller than HBLKSIZE-sizeof(word), otherwise pass lb plus sizeof(word) (instead of lb plus TYPD_EXTRA_BYTES) to GC_generic_malloc_aligned; add comment.
* Consistent naming of variables of obj_kind typeIvan Maidanski2023-04-101-7/+7
| | | | | | | | | | | | | | | | | | | | (refactoring) Also, reduce scope of local variables in GC_continue_reclaim and GC_reclaim_unconditionally_marked. * allchblk.c (setup_header): Define and use ok local variable. * malloc.c (GC_alloc_reclaim_list): Rename kind argument to ok. * malloc.c (GC_generic_malloc_inner_small): Rename kind local variable to ok. * reclaim.c [ENABLE_DISCLAIM] (GC_disclaim_and_reclaim): Remove ok local variable. * reclaim.c (GC_reclaim_all): Likewise. * reclaim.c (GC_continue_reclaim): Move hhdr local variable to inner block; add comment. * reclaim.c [!EAGER_SWEEP && ENABLE_DISCLAIM] (GC_reclaim_unconditionally_marked): Move sz, hhdr, hbp, ok, rlp, rlh local variables to the appropriate inner blocks.
* Refine comparisons to GC_greatest_plausible_heap_addrIvan Maidanski2023-04-091-1/+1
| | | | | | | | | | | | | | | | | | 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.
* Do not add extra byte to non-small uncollectible objectsIvan Maidanski2023-03-251-5/+7
| | | | | | | | | | | | Previously EXTRA_BYTES value was not added to the allocation size only for small uncollectible objects. * include/gc/gc.h (GC_all_interior_pointers): Refine comment (regarding uncollectible objects). * malloc.c (GC_generic_malloc_uncollectable): Define lb_orig local variable; decrement lb before if(SMALL_OBJ(lb)); do not expect original lb is zero; pass lb_orig (instead of lb) to GC_DBG_COLLECT_AT_MALLOC() and to oom_fn().
* Do not double-clear first two words of object in GC_generic_malloc_alignedIvan Maidanski2023-03-241-4/+12
| | | | | | | | | | The beginning of the allocated object is cleared while holding the allocation lock. * malloc.c [!THREADS] (GC_generic_malloc_aligned): If init then call BZERO() before UNLOCK() line (not after). * malloc.c [THREADS]: Do not clear (again) the first 2 words by BZERO() when not holding the lock; add comment.
* Prevent zero size passed GC_alloc_large if aligned allocationIvan Maidanski2023-03-241-0/+2
| | | | | | | | | (fix of commit ba137368d) * malloc.c (GC_generic_malloc_aligned): If lb is zero then set it to 1 (before rounding it up and converting to granules). * malloc.c [THREADS] (GC_generic_malloc_aligned): Add assertion to ensure GRANULES_TO_WORDS(lg)-2 is not negative.
* Rename ROUNDED_UP_GRANULES macro to ALLOC_REQUEST_GRANSIvan Maidanski2023-03-241-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * include/gc/gc_tiny_fl.h (GC_RAW_BYTES_FROM_INDEX): Update comment (rename ROUNDED_UP_GRANULES to ALLOC_REQUEST_GRANS). * include/private/gc_priv.h (ADD_SLOP): Rename to ADD_EXTRA_BYTES; move definition upper (to be before ALLOC_REQUEST_GRANS). * include/private/gc_priv.h (ROUNDED_UP_GRANULES): Rename to ALLOC_REQUEST_GRANS; refine comment. * include/private/gc_priv.h (SMALL_OBJ): Remove extra parentheses; add comment. * include/private/gc_priv.h (_GC_arrays._size_map): Refine comment. * malloc.c (GC_extend_size_map, GC_generic_malloc_aligned): Rename ROUNDED_UP_GRANULES to ALLOC_REQUEST_GRANS. * misc.c (GC_init_size_map): Likewise. * thread_local_alloc.c [THREAD_LOCAL_ALLOC] (GC_malloc_kind): Likewise. * thread_local_alloc.c [THREAD_LOCAL_ALLOC && GC_GCJ_SUPPORT] (GC_gcj_malloc): Likewise. * malloc.c (GC_generic_malloc_inner): Rename ADD_SLOP to ADD_EXTRA_BYTES. * mallocx.c (GC_realloc): Likewise. * mallocx.c (GC_malloc_many): Define lg local variable; use ALLOC_REQUEST_GRANS() and GRANULES_TO_BYTES(); remove comment.
* Always invoke pending finalizers in GC_generic_malloc_uncollectableIvan Maidanski2023-03-241-4/+11
| | | | | | | | | | This matches the relavant functionality of GC_generic_malloc_aligned. * malloc.c (GC_generic_malloc_uncollectable): Call GC_print_all_errors() and GC_INVOKE_FINALIZERS() always for small objects; call GC_generic_malloc_inner_small() (while holding the lock) instead of GC_generic_malloc_aligned(); hold the lock during GC_is_marked() call.
* Avoid code duplication in IGNORE_OFF_PAGE-specific malloc functionsIvan Maidanski2023-03-241-67/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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 a typo in comment of GC_generic_malloc_innerIvan Maidanski2023-03-241-1/+1
| | | | | * malloc.c (GC_generic_malloc_inner): Fix a typo ("to directly allocate") in comment.
* Move increment of GC_bytes_allocd to GC_alloc_largeIvan Maidanski2023-03-221-19/+6
| | | | | | | | | | | | | | | | | | | | | (refactoring) * include/private/gc_priv.h (GC_alloc_large): Update comment (mention that GC_bytes_allocd is updated too). * malloc.c (GC_alloc_large_and_clear): Likewise. * include/private/gc_priv.h (GC_allocobj): Rename sz argument to gran; update comment. * malloc.c (GC_alloc_large): Increment GC_bytes_allocd (by rounded lb). * malloc.c (GC_generic_malloc_inner): Reformat code; remove lb_adjusted local variable. * malloc.c (GC_generic_malloc_inner_ignore_off_page, GC_generic_malloc_inner, GC_generic_malloc_aligned): Do not update GC_bytes_allocd. * mallocx.c (GC_generic_malloc_ignore_off_page): Likewise. * malloc.c (GC_generic_malloc_inner_ignore_off_page): Remove op and lb_adjusted local variables. * mallocx.c (GC_generic_malloc_ignore_off_page): Remove lb_rounded local variable.
* Fix description of client promise for IGNORE_OFF_PAGE allocated objectsIvan Maidanski2023-03-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | (documentation) The client should keep a pointer within the first heap block for such an allocated object. Previously, it was mentioned in the documentation and comments that such a pointer should be within the first 256 or 512 bytes. * README.md (The C Interface to the Allocator): Fix the description (comment) of GC_malloc_ignore_off_page (the client promises to keep a pointer within the first hblk of the object instead of 256 or 512 bytes, or a page). * docs/gcinterface.md (GC_MALLOC_IGNORE_OFF_PAGE): Likewise. * gc.man (GC_malloc_atomic_ignore_off_page): Likewise. * include/gc/gc.h (GC_malloc_ignore_off_page): Likewise. * include/gc/gc_mark.h (GC_generic_malloc_ignore_off_page): Likewise. * include/private/gc_priv.h (IGNORE_OFF_PAGE): Likewise. * include/private/gc_priv.h [DBG_HDRS_ALL || GC_GCJ_SUPPORT || !GC_NO_FINALIZATION] (GC_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. * include/gc/gc_gcj.h (GC_gcj_malloc_ignore_off_page): Refine comment.
* Fix of GC_bytes_allocd increment in GC_generic_malloc_innerIvan Maidanski2023-03-201-3/+5
| | | | | | | | | | | EXTRA_BYTES should be always counted when updating GC_bytes_allocd. * malloc.c (GC_generic_malloc_inner): Define lb_adjusted local variable and set it to ADD_SLOP(lb); increment GC_bytes_allocd by lb_adjusted instead of lb (in case of a non-small object). * malloc.c [DBG_HDRS_ALL || GC_GCJ_SUPPORT || !GC_NO_FINALIZATION] (GC_generic_malloc_inner_ignore_off_page): Change type of lb_adjusted local variable from word to size_t.
* Remove unused DCL_LOCK_STATEIvan Maidanski2023-01-301-6/+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.
* Support GC_memalign with alignments greater than HBLKSIZEIvan Maidanski2023-01-241-13/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Issue #510 (bdwgc). * allchblk.c (GC_allochblk_nth, GC_allochblk, next_hblk_fits_better, find_nonbl_hblk): Add align_m1 argument. * include/private/gc_priv.h (GC_allochblk, GC_alloc_large): Likewise. * malloc.c (GC_alloc_large): Likewise. * allchblk.c (GC_allochblk): Check that there is no overflow in blocks*HBLKSIZE+align_m1; pass align_m1 to GC_allochblk_nth; try start_list again (with may_split) if non-zero align_m1. * allchblk.c (ALIGN_PAD_SZ): New macro. * allchblk.c (next_hblk_fits_better): Define and use next_ofs local variable; adjust next_hbp passed to GC_is_black_listed(). * allchblk.c (find_nonbl_hblk): Adjust search_end and last_hbp based on align_m1 value. * allchblk.c (GC_allochblk_nth): Add assertion that align_m1+1 is a power of two and that align_m1+1 is 1 or a multiple of HBLKSIZE; define and use align_ofs local variable; add assertion that last_hbp (before GC_install_header() call) is multiple of align_m1+1. * include/gc/gc.h (GC_memalign): Update comment to mention the restriction on align value (should be a power of two and not less than size of a pointer). * include/private/gc_priv.h (GC_allochblk, GC_alloc_large): Update comment (to mention align_m1 argument). * include/private/gc_priv.h (GC_generic_malloc_aligned): Declare function. * include/private/gcconfig.h [(NACL || I386 && (EMSCRIPTEN || WASI)) && !HBLKSIZE && !GC_NO_VALLOC] (HBLKSIZE): Do not define (to 65536 or GETPAGESIZE()); remove TODO item. * malloc.c (GC_alloc_large): Add alignment to n_blocks value (but not to GC_large_allocd_bytes); pass align_m1 to GC_allochblk(); add assertion that result is aligned to align_m1+1. * malloc.c (GC_alloc_large_and_clear): Pass zero align_m1 to GC_alloc_large(). * mallocx.c (GC_generic_malloc_ignore_off_page): Likewise. * malloc.c (GC_generic_malloc_aligned): Move code from GC_generic_malloc; adjust align_m1 to be either zero or not less than HBLKSIZE-1, and pass it to GC_alloc_large(); add comment that the result of GC_oom_fn(lb) might be unaligned. * malloc.c (GC_generic_malloc): Call GC_generic_malloc_aligned() with zero align_m1. * mallocx.c (GC_generic_malloc_ignore_off_page): Expect result of GC_alloc_large() is unlikely to be NULL. * mallocx.c (GC_generic_malloc_many): Pass zero align_m1 to GC_allochblk(). * new_hblk.c (GC_new_hblk): Likewise. * mallocx.c: Do not include limits.h. * mallocx.c (GC_memalign): Remove new_lb local variable; define and use align_m1 local variable; if align is smaller than sizeof(void*) or is not a power of two than return NULL; call GC_generic_malloc_aligned and GC_clear_stack (instead of GC_oom_fn() or GC_malloc()) if align or lb is at least HBLKSIZE/2; replace result%align to result&align_m1; do not result+=offset if offset is zero. * new_hblk.c (GC_new_hblk): Expect result of GC_allochblk() is unlikely to be NULL. * tests/gctest.c (run_one_test): Call GC_memalign() also for bigger alignment values (up to HBLKSIZE*4).
* Simplify code of GC_allochblk_nthIvan Maidanski2023-01-201-16/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) Issue #510 (bdwgc). * allchblk.c (GC_hblk_fl_from_blocks): Change type of blocks argument from word to size_t. * allchblk.c (setup_header): Reformat comment. * allchblk.c (GC_get_first_part): Change type of total_size local variable from word to size_t; add assertion that bytes argument is multiple of HBLKSIZE. * allchblk.c (GC_get_first_part): Specify that result of GC_install_header() is unlikely to be NULL. * alloc.c (GC_add_to_heap): Likewise. * allchblk.c (AVOID_SPLIT_REMAPPED): Define only if USE_MUNMAP. * allchblk.c (GC_allochblk): Remove comment; change blocks*HBLKSIZE<0 to blocks>=GC_SIZE_MAX/(2*HBLKSIZE) and expect its result unlikely to be true. * allchblk.c (GC_allochblk): Vhange type of blocks local variable from word to size_t. * malloc.c (GC_alloc_large): Likewise. * allchblk.c (GC_drop_blacklisted_count): New STATIC varible (replaces\ count static one in GC_allochblk_nth). * allchblk.c (next_hblk_fits_better, find_nonbl_hblk, drop_hblk_in_chunks): New static function (move code GC_allochblk_nth). * allchblk.c (GC_allochblk_nth): Refine comment; add assertion that sz is non-zero; change type of size_needed and size_avail from signed_word to word; add and refine comments; call find_nonbl_hblk, next_hblk_fits_better and drop_hblk_in_chunks; simplify code in the loop; rename lasthbp to last_hbp local variable; rename thishdr to last_hdr local variable; remove thishbp local variable; add assertion that hhdr->hb_sz>=size_needed. * include/private/gc_priv.h (GC_allochblk): Move comment from allchblk.c. * include/private/gc_priv.h (GC_alloc_large) Move comment from malloc.c. * malloc.c (GC_alloc_large): Remove total_bytes local variable. * malloc.c (GC_alloc_large, GC_alloc_large_and_clear, GC_generic_malloc): Specify that result (or h) is unlikely to be NULL.
* Remove unneeded n_blocks local variable in malloc.c and reclaim.cIvan Maidanski2023-01-181-7/+3
| | | | | | | | | | | (refactoring) * malloc.c (GC_alloc_large_and_clear): Remove n_blocks local variable. * malloc.c (GC_generic_malloc): Likewise. * reclaim.c [ENABLE_DISCLAIM] (GC_disclaim_and_reclaim): Replace (*proc)() to proc(). * reclaim.c [ENABLE_DISCLAIM] (GC_reclaim_block): Likewise. * reclaim.c (GC_reclaim_block): Remove blocks local variable.
* Remove code duplication in GC_free[_inner]Ivan Maidanski2023-01-181-77/+37
| | | | | | | | | | | | | | | | | (refactoring) * include/private/gc_priv.h [THREADS] (GC_free_inner): Move comment from malloc.c. * malloc.c (free_internal): New static function (move code from GC_free_inner but with several changes - remove h and nblocks local variables, move hhdr to arguments, specify ngranules <= MAXOBJGRANULES as likely, remove code duplication). * malloc.c (GC_free): Use free_internal(); remove h, sz, ngranules, knd, ok local variables. * malloc.c [THREADS] (GC_free_inner): Likewise. * malloc.c [REDIRECT_MALLOC && (GC_SOLARIS_THREADS || GC_LINUX_THREADS || NEED_CALLINFO && GC_HAVE_BUILTIN_BACKTRACE || MSWIN32)] (GC_free): Specify hhdr==0 as unlikely.
* Fix typos in comments and documentation (regarding 'it is')Ivan Maidanski2023-01-171-1/+1
| | | | | | | | | | | | * ChangeLog (4.3): Fix typo ("it's"). * doc/platforms/README.amiga (GC_AMIGA_GC): Likewise. * extra/AmigaOS.c (GC_amiga_allocwrapper_any): Fix typo in comment ("it's"). * malloc.c (GC_free): Likewise. * new_hblk.c (GC_build_fl): Likewise. * os_dep.c [DATASTART_USES_BSDGETDATASTART] (GC_FreeBSDGetDataStart): Likewise. * reclaim.c (GC_start_reclaim): Likewise.
* Get libpthread.so '.text' mapping only for glibc prior to v2.34 (Linux)Ivan Maidanski2022-10-211-27/+30
| | | | | | | | | | | | | | | | | | | | | | | | Some libc implementations like bionic (on Android), musl and glibc 2.34 (and later) do not have libpthread.so (because the code implementing POSIX threads is located in libc.so file). * include/private/gcconfig.h [GC_LINUX_THREADS && REDIRECT_MALLOC && !HAVE_LIBPTHREAD_SO && __GLIBC__ && !GC_GLIBC_PREREQ(2,34)] (HAVE_LIBPTHREAD_SO): Define macro; move comment from GC_init_lib_bounds. * malloc.c [REDIRECT_MALLOC && GC_LINUX_THREADS] (GC_libpthread_start, GC_libpthread_end): Define variable only if HAVE_LIBPTHREAD_SO. * malloc.c [REDIRECT_MALLOC && GC_LINUX_THREADS] (GC_init_lib_bounds): Call GC_text_mapping("libpthread-") only if HAVE_LIBPTHREAD_SO; remove TODO item. * malloc.c [REDIRECT_MALLOC && GC_LINUX_THREADS] (calloc): Update and place comments properly. * malloc.c [REDIRECT_MALLOC && GC_LINUX_THREADS] (calloc): Check the caller is in range between GC_libpthread_start and GC_libpthread_end only if HAVE_LIBPTHREAD_SO. * malloc.c [REDIRECT_FREE && !REDIRECT_MALLOC_IN_HEADER && !IGNORE_FREE && GC_LINUX_THREADS && !USE_PROC_FOR_LIBRARIES] (free): Likewise.
* Define GC_GLIBC_PREREQ internal macroIvan Maidanski2022-10-211-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * dyn_load.c [(SCO_ELF || DGUX || HURD || NACL || __ELF__ && (LINUX || FREEBSD || NETBSD || OPENBSD)) && !USE_PROC_FOR_LIBRARIES && !HAVE_DL_ITERATE_PHDR] (HAVE_DL_ITERATE_PHDR): Replace __GLIBC__>2||__GLIBC__==2&&__GLIBC_MINOR__>2 to GC_GLIBC_PREREQ(2,3). * dyn_load.c [(SCO_ELF || DGUX || HURD || NACL || __ELF__ && (LINUX || FREEBSD || NETBSD || OPENBSD)) && !USE_PROC_FOR_LIBRARIES && __GLIBC__==2 && __GLIBC_MINOR__==2 && DT_CONFIG && !HAVE_DL_ITERATE_PHDR] (HAVE_DL_ITERATE_PHDR): Do not define. * include/private/gcconfig.h [LINUX]: Move include features.h upper (to be before GC_GLIBC_PREREQ); add TODO item; refine comment. * include/private/gcconfig.h (GC_GLIBC_PREREQ): Define macro. * include/private/gcconfig.h [(M68K || I386 || ARM32) && LINUX && __ELF__]: Replace defined(__GLIBC__)&&__GLIBC__>=2 to GC_GLIBC_PREREQ(2,0). * include/private/gcconfig.h [MIPS && LINUX]: Replace __GLIBC__>2||__GLIBC__==2&&__GLIBC_MINOR__>=2 to GC_GLIBC_PREREQ(2,2). * include/private/gcconfig.h [MPROTECT_VDB && __GLIBC__]: Replace __GLIBC__<2||__GLIBC__==2&&__GLIBC_MINOR__<2 to !GC_GLIBC_PREREQ(2,2). * malloc.c [REDIRECT_MALLOC && GC_LINUX_THREADS && __GLIBC__] (GC_init_lib_bounds): Replace __GLIBC__<2||__GLIBC__==2&&__GLIBC_MINOR__<34 to !GC_GLIBC_PREREQ(2,34). * os_dep.c [(I386 && SAVE_CALL_CHAIN || SPARC) && LINUX]: Do not include features.h.
* Fix uclibc handling and comment in GC_init_lib_boundsIvan Maidanski2022-10-201-2/+2
| | | | | | | | | | | | | | | (fix of commit ffd2f9fe0) Issue #477 (bdwgc). According to uclibc source it seems to have libpthread.so file, unlike musl. This commit replaces uclibc to musl in comment and do not turn off the warning about missing libpthread.so for uclibc. * malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER && GC_LINUX_THREADS && __GLIBC__] (GC_init_lib_bounds): Change uclibc (misspelled) to musl in comment; do not check whether __UCLIBC__ is defined.
* Remove false warning of missing libpthread.so on LinuxIvan Maidanski2022-10-191-2/+12
| | | | | | | | | | | | | | Issue #477 (bdwgc). Some libc implementations like bionic, uclib and glibc 2.34 (and later) do not have libpthread.so because the pthreads-related code is located in libc.so, thus potential calloc calls from such code are forwarded to real (libc) calloc without any special handling on the libgc side. * malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER && GC_LINUX_THREADS] (GC_init_lib_bounds): Do not call WARN to report missing libpthread.so if __UCLIBC__ or not defined __GLIBC__ or glibc version is 2.34 or above; add comment and TODO item.
* Remove duplicate 'called once' check in GC_init_lib_boundsIvan Maidanski2022-10-191-3/+0
| | | | | | | | | | | (refactoring) GC_init_lib_bounds() is called only once - this is ensured by lib_bounds_set variable. * malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER && GC_LINUX_THREADS] (GC_init_lib_bounds): Do not check value of GC_libpthread_start; do not set GC_libpthread_start to 1 after WARN().
* Include gc_inline.h from gc_priv.hIvan Maidanski2022-10-111-1/+0
| | | | | | | | | | | | | | | | | | | (refactoring) Also, use EXPECT(FALSE) for GC_ASSERT. * extra/gc.c: Do not include gc_inline.h. * fnlz_mlc.c [ENABLE_DISCLAIM]: Likewise. * include/private/thread_local_alloc.h [THREAD_LOCAL_ALLOC]: Likewise. * malloc.c: Likewise. * mallocx.c: Likewise. * pthread_support.c: Likewise. * reclaim.c: Likewise. * typd_mlc.c: Likewise. * include/private/gc_priv.h: Move GC_ASSERT definition upper; include gc_inline.h (after GC_ASSERT); define PTRFREE and NORMAL to GC_I_PTRFREE and GC_I_NORMAL, respectively. * include/private/gc_priv.h [GC_ASSERTIONS] (GC_ASSERT): Use EXPECT().
* 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 modHBLKSZ where possibleIvan Maidanski2022-08-031-1/+1
| | | | | | | | | | | | | | | | | | | | | (refactoring) * allchblk.c (GC_remove_from_fl_at, GC_add_to_fl, GC_get_first_part): Replace v&(HBLKSIZE-1) to modHBLKSZ(v). * allchblk.c [!GC_DISABLE_INCREMENTAL] (GC_allochblk_nth): Likewise. * include/private/gc_priv.h (HBLKDISPL): Likewise. * include/private/gc_hdrs.h (MAX_JUMP): Remove spaces in HBLKSIZE-1 (to match similar expressions). * include/private/gc_priv.h (OBJ_SZ_TO_BLOCKS_CHECKED): Likewise. * misc.c (block_add_size): Likewise. * os_dep.c [!MSWIN_XBOX1 && !MSWINCE && (USE_WINALLOC || CYGWIN32)] (GC_win32_get_mem): Likewise. * include/private/gc_priv.h (HBLKMASK): Remove. * include/private/gc_priv.h (obj_link): Remove extra space in the expression. * malloc.c (GC_generic_malloc_uncollectable): Replace (word)op&(HBLKSIZE-1) to HBLKDISPL(op). * mallocx.c (GC_realloc): Replace HBLKMASK to (HBLKSIZE-1).
* Specify that internal allocations failure is unlikelyIvan Maidanski2022-06-071-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * finalize.c [!GC_NO_FINALIZATION] (GC_register_disappearing_link_inner): Assume failure of allocation (resulting in NULL or GC_oom_fn call) is unlikely. * malloc.c [DBG_HDRS_ALL || GC_GCJ_SUPPORT || !GC_NO_FINALIZATION] (GC_generic_malloc_inner_ignore_off_page): Likewise. * malloc.c (GC_generic_malloc): Likewise. * malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER] (calloc, strdup, strndup): Likewise. * mallocx.c (GC_realloc, GC_memalign, GC_strdup, GC_strndup): Likewise. * mallocx.c [GC_REQUIRE_WCSDUP] (GC_wcsdup): Likewise. * specific.c [USE_CUSTOM_SPECIFIC] (GC_setspecific): Likewise. * typd_mlc.c (GC_make_sequence_descriptor, GC_make_descriptor): Likewise. * malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER] (calloc): Expect that lb and n are not greater than GC_SQRT_SIZE_MAX. * typd_mlc.c (GC_calloc_explicitly_typed): Likewise. * typd_mlc.c (GC_add_ext_descriptor): Assume that resizing of GC_ext_descriptors[] is rare. * typd_mlc.c (GC_calloc_explicitly_typed): Do not call GC_make_array_descriptor() if n * lb > GC_SIZE_MAX. * malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER && !strndup] (strndup): Expect that len is not greater than size. * mallocx.c (GC_strndup): Likewise. * typd_mlc.c (GC_make_sequence_descriptor): Reformat code.
* 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.
* Replace comments about GC is held or not with relevant assertionsIvan Maidanski2022-05-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * alloc.c (GC_default_stop_func): Refine comment about the allocation lock. * alloc.c (GC_finish_collection): Remove comment that the allocation lock is held because the assertion about it already exists. * finalize.c (GC_grow_table, GC_mark_fo, GC_finalize): Likewise. * finalize.c [!GC_MOVE_DISAPPEARING_LINK_NOT_NEEDED] (GC_move_disappearing_link_inner): Likewise. * mark.c (GC_mark_some_inner): Likewise. * mark.c [PARALLEL_MARK] (GC_do_parallel_mark): Likewise. * os_dep.c [OPENBSD && GC_OPENBSD_UTHREADS] (GC_find_limit_openbsd, GC_skip_hole_openbsd): Likewise. * os_dep.c [NEED_FIND_LIMIT || USE_PROC_FOR_LIBRARIES && THREADS] (GC_find_limit_with_bound): Likewise. * os_dep.c (GC_register_data_segments): Likewise. * os_dep.c [MPROTECT_VDB || PROC_VDB || SOFT_VDB] (GC_dirty_init): Likewise. * pthread_stop_world.c (GC_start_world): Likewise. * pthread_support.c (GC_new_thread): Likewise. * thread_local_alloc.c (return_freelists): Likewise. * win32_threads.c (GC_new_thread, GC_lookup_thread_inner, GC_delete_gc_thread_no_free): Likewise. * blacklst.c (GC_promote_black_lists): Remove comment that the allocation lock is held, and add the corresponding assertion to the beginning of the function. * blacklst.c [!PARALLEL_MARK] (GC_add_to_black_list_normal, GC_add_to_black_list_stack): Likewise. * darwin_stop_world.c (GC_stop_world, GC_start_world): Likewise. * mark_rts.c (GC_remove_root_at_pos, GC_remove_roots_inner, GC_exclude_static_roots_inner): Likewise. * pthread_stop_world.c (GC_push_all_stacks, GC_suspend_all): Likewise. * pthread_support.c (GC_check_finalizer_nested): Likewise. * thread_local_alloc.c (GC_destroy_thread_local): Likewise. * win32_threads.c (GC_check_finalizer_nested, GC_push_all_stacks): Likewise. * blacklst.c (GC_is_black_listed): Refine comment about the allocation lock. * darwin_stop_world.c (GC_push_all_stacks): Add assertion that the lock is held on entrance. * gcj_mlc.c (maybe_finalize): Likewise. * malloc.c [THREADS] (GC_free_inner): Likewise. * dyn_load.c (GC_dyld_image_add, GC_dyld_image_remove, GC_init_dyld): Remove comment the allocation lock should not be held, and add the corresponding assertion to the beginning of the function. * finalize.c (GC_invoke_finalizers): Likewise. * mark.c [PARALLEL_MARK] (GC_help_marker): Likewise. * pthread_support.c (GC_init_parallel): Likewise. * win32_threads.c (GC_lookup_pthread, GC_init_parallel): Likewise. * finalize.c (GC_finalize_all): Remove comment that the lock is not held on entrance. * gcj_mlc.c (GC_init_gcj_malloc): Likewise. * typd_mlc.c (GC_add_ext_descriptor): Likewise. * include/gc/javaxfc.h (GC_finalize_all): Add comment the function acquires the allocation lock. * mallocx.c (GC_generic_malloc_many): Adjust comment about GC lock. * new_hblk.c (GC_build_fl): Likewise. * pthread_support.c (GC_new_thread): Move the assertion about the allocation lock closer to the beginning of the function. * win32_threads.c (GC_new_thread): 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-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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-1/+1
| | | | | | | | | | | | | | | | | | | | | | | (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.
* Eliminate data race reported by TSan in GC_have_errorsIvan Maidanski2022-04-011-1/+1
| | | | | | | | | | | | | | | | | * 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.
* Fix comments to disambiguate plural nouns followed by 'is'Ivan Maidanski2022-02-231-4/+3
| | | | | | | | | | | | | | | | | * alloc.c (GC_add_to_heap): Change "bytes is" to "bytes argument is" in comment. * alloc.c (GC_expand_hp): Fix typo ("argument is") in comment. * include/gc/gc_inline.h (GC_FAST_MALLOC_GRANS): Change "granules is" to "granules argument is" in comment. * include/private/gcconfig.h [LINUX && REDIRECT_MALLOC]: Change "Linux threads is itself" to "Linux threads implementation itself is". * malloc.c (GC_alloc_large): Change "Flags is" to "flags argument should be" in comment. * include/private/gc_priv.h (GC_alloc_large): Likewise. * malloc.c (GC_alloc_large): Change "EXTRA_BYTES were" to "EXTRA_BYTES value was" in comment. * obj_map.c [MARK_BIT_PER_GRANULE] (GC_add_map_entry): Change "0 granules is" to "0 is" in comment.
* Add I_HOLD_LOCK assertion to scratch_alloc/recycle and their callersIvan Maidanski2022-01-171-6/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * allchblk.c (setup_header, GC_get_first_part, GC_allochblk_nth): Add assertion that the GC lock is held (I_HOLD_LOCK). * alloc.c (GC_add_to_heap, GC_scratch_recycle_inner): Likewise. * backgraph.c (push_in_progress, backwards_height): Likewise. * blacklst.c (GC_bl_init_no_interiors, GC_bl_init): Likewise. * dyn_load.c (GC_register_dynamic_libraries): Likewise. * finalize.c (push_and_mark_object): Likewise. * finalize.c [!GC_TOGGLE_REFS_NOT_NEEDED] (GC_mark_togglerefs): Likewise. * headers.c (GC_scratch_alloc, alloc_hdr, GC_init_headers, GC_install_header): Likewise. * include/private/gc_pmark.h (GC_MARK_FO): Likewise. * malloc.c (GC_alloc_reclaim_list): Likewise. * mark.c (GC_mark_some_inner, alloc_mark_stack): Likewise. * mark_rts.c [DYNAMIC_LOADING || MSWIN32 || MSWINCE || PCR || CYGWIN32] (GC_remove_tmp_roots): Likewise. * mark_rts.c (GC_cond_register_dynamic_libraries, GC_push_roots): Likewise. * obj_map.c [MARK_BIT_PER_GRANULE] (GC_add_map_entry): Likewise. * os_dep.c [NEED_PROC_MAPS && IA64] (backing_store_base_from_proc): Likewise. * os_dep.c [LINUX_STACKBOTTOM && IA64] (GC_get_register_stack_base): Likewise. * os_dep.c [MSWIN32] (GC_register_root_section): Likewise. * os_dep.c [!OS2 && !MSWIN32 && !MSWINCE && !CYGWIN32] (GC_register_data_segments): Likewise. * os_dep.c [GWW_VDB] (GC_gww_dirty_init, GC_gww_read_dirty): Likewise. * os_dep.c (GC_dirty_init): Likewise. * os_dep.c [PROC_VDB] (GC_proc_read_dirty): Likewise. * os_dep.c [SOFT_VDB] (soft_dirty_init, GC_soft_read_dirty): Likewise. * os_dep.c [!GC_DISABLE_INCREMENTAL] (GC_read_dirty): Likewise. * dyn_load.c [IRIX5 || USE_PROC_FOR_LIBRARIES && !LINUX] (GC_register_dynamic_libraries): Round up size of buf local variable to multiple of 8 bytes. * headers.c (GC_install_header): Use EXPECT(). * malloc.c (GC_alloc_reclaim_list): Likewise. * obj_map.c [MARK_BIT_PER_GRANULE] (GC_add_map_entry): Likewise. * mark_rts.c [DYNAMIC_LOADING || MSWIN32 || MSWINCE || PCR || CYGWIN32] (GC_remove_tmp_roots, GC_push_roots): Remove redundant comment. * misc.c [GC_ASSERTIONS && GC_ALWAYS_MULTITHREADED] (GC_init): Wrap calls of GC_get_main_stack_base(), GC_get_register_stack_base(), GC_init_headers(), GC_dirty_init(), GC_register_data_segments(), GC_bl_init(), GC_mark_init() into LOCK/UNLOCK. * os_dep.c [OPENBSD] (GC_skip_hole_openbsd): Move sysconf() call to be after the assertion that the GC lock is held. * os_dep.c [HPUX_STACKBOTTOM] (GC_get_register_stack_base): Add assertion that GC_stackbottom is set.
* Move public header files to include/gc in source treeIvan Maidanski2021-11-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also, include/extra public header files (for the redirection) are moved to include directory. This is have the same directories structure of public headers in the source tree as that of the installed "include" directory. * doc/finalization.md: Remove "include/" prefix for cord.h. * LICENSE: Rename include/gc_allocator.h to gc/gc_allocator.h. * Makefile.direct (CORD_SRCS, CORD_INCLUDE_FILES): Add "gc/" prefix for cord.h, ec.h, cord_pos.h. * CMakeLists.txt [install_headers]: Likewise. * cord/cord.am (pkginclude_HEADERS): Likewise. * Makefile.direct (SRCS, tests/test.o, dyn_load.o, dyn_load_sunos53.o, mark.o, typd_mlc.o, finalize.o, ptr_chck.o, specific.o, alloc.o, pthread_support.o, thread_local_alloc.o, win32_threads.o): Add "gc/" prefix for gc_typed.h, gc_tiny_fl.h, gc_version.h, gc_inline.h, gc_mark.h, gc_disclaim.h, gc_allocator.h, javaxfc.h, gc_backptr.h, gc_gcj.h, leak_detector.h, gc_pthread_redirects.h, gc_config_macros.h. * NT_MAKEFILE (test.obj): Add gc\ prefix for gc_mark.h, gc_disclaim.h. * NT_MAKEFILE (cord\tests\de.obj, cord\tests\de_win.obj): Add gc\ prefix for cord.h, cord_pos.h. * OS2_MAKEFILE (cord\cordbscs.obj, cord\cordxtra.obj, cord\cordprnt.obj, cordtest.exe): Likewise. * cord/cordbscs.c: Add "gc/" prefix in include for cord.h, ec.h; reorder includes. * cord/cordprnt.c: Likewise. * cord/cordxtra.c: Likewise. * cord/tests/cordtest.c: Likewise. * cord/tests/de.c: Likewise. * cord/tests/de_win.c: Likewise. * extra/gc.c: Add "gc/" prefix in include for gc_inline.h, gc_pthread_redirects.h, javaxfc.h, gc_disclaim.h, gc_gcj.h, gc_backptr.h, gc_mark.h, gc_tiny_fl.h, leak_detector.h., gc_typed.h. * finalize.c: Likewise. * fnlz_mlc.c: Likewise. * gcj_mlc.c: Likewise. * include/private/dbg_mlc.h: Likewise. * include/private/gc_pmark.h: Likewise. * include/private/gc_priv.h: Likewise. * include/private/thread_local_alloc.h: Likewise. * malloc.c: Likewise. * mallocx.c: Likewise. * pthread_stop_world.c: Likewise. * pthread_support.c: Likewise. * reclaim.c: Likewise. * tests/disclaim_bench.c: Likewise. * tests/disclaim_test.c: Likewise. * tests/disclaim_weakmap_test.c: Likewise. * tests/leak_test.c: Likewise. * tests/staticrootstest.c: Likewise. * tests/test.c: Likewise. * tests/thread_leak_test.c: Likewise. * tests/trace_test.c: Likewise. * thread_local_alloc.c: Likewise. * typd_mlc.c: Likewise. * tests/test_cpp.cc: Add "gc/" prefix in include for gc_allocator.h. * include/extra/gc.h: Move to include folder; replace include<> to include "". * include/extra/gc_cpp.h: Likewise. * include/cord.h: Move to include/gc folder. * include/cord_pos.h: Likewise. * include/ec.h: Likewise. * include/gc.h: Likewise. * include/gc_allocator.h: Likewise. * include/gc_backptr.h: Likewise. * include/gc_config_macros.h: Likewise. * include/gc_cpp.h: Likewise. * include/gc_disclaim.h: Likewise. * include/gc_gcj.h: Likewise. * include/gc_inline.h: Likewise. * include/gc_mark.h: Likewise. * include/gc_pthread_redirects.h: Likewise. * include/gc_tiny_fl.h: Likewise. * include/gc_typed.h: Likewise. * include/gc_version.h: Likewise. * include/javaxfc.h: Likewise. * include/leak_detector.h: Likewise. * include/include.am (pkginclude_HEADERS): Add "gc/" prefix for gc.h, gc_backptr.h, gc_config_macros.h, gc_inline.h, gc_mark.h, gc_tiny_fl.h, gc_typed.h, gc_version.h, javaxfc.h, leak_detector.h, gc_disclaim.h, gc_gcj.h, gc_pthread_redirects.h, gc_allocator.h, gc_cpp.h. * CMakeLists.txt [install_headers]: Likewise. * include/include.am (include_HEADERS): Remove "extra/" prefix for gc_cpp.h, gc.h. * CMakeLists.txt [install_headers]: Likewise.
* Set GC_collecting hint for GC_collect_a_little_inner calls (pthreads)Ivan Maidanski2019-09-251-1/+4
| | | | | | | | * alloc.c (GC_try_to_collect_inner, GC_collect_a_little): Wrap GC_collect_a_little_inner() call into ENTER/EXIT_GC(). * gc_dlopen.c [!USE_PROC_FOR_LIBRARIES] (disable_gc_for_dlopen): Likewise. * malloc.c (GC_alloc_large): Likewise.
* Workaround 'argument to function is always 1' cppcheck false positivesIvan Maidanski2019-09-111-7/+10
| | | | | | | | | | | | | | | | | * allchblk.c (GC_print_hblkfreelist): Replace "while(p!=0)" with "while(p)"; add a marker that the change is for cppcheck. * allchblk.c (GC_free_block_ending_at, GC_add_to_fl, GC_split_block, GC_allochblk_nth, GC_freehblk): Replace "if(p!=0)" with "if(p)". * alloc.c (GC_set_fl_marks): Likewise. * extra/MacOS.c (GC_MacFreeTemporaryMemory): Likewise. * mallocx.c (GC_generic_malloc_many): Likewise. * allchblk.c (GC_allochblk_nth): Replace "if(0==p)" with "if(p){}else". * malloc.c (GC_free): Likewise. * malloc.c (GC_generic_malloc_uncollectable): Replace "if(0==p)return 0;<code>;return p;" with "if(p){<code>}return p;". * mallocx.c (GC_generic_malloc_many): Replace "p+=v;while((p2=*p)!=0)" with "for(p+=v;(p2=*p)!=0;)". * reclaim.c (GC_continue_reclaim, GC_reclaim_all): Likewise.
* Remove stubborn objects allocation code completelyIvan Maidanski2018-05-151-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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.
* Declare all internal functions in private headers instead of .c filesIvan Maidanski2018-02-281-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (code refactoring) Issue #206 (bdwgc). * include/private/darwin_stop_world.h [MPROTECT_VDB && !GC_NO_THREADS_DISCOVERY] (GC_darwin_register_mach_handler_thread): Declare function. * include/private/gc_priv.h [WRAP_MARK_SOME && PARALLEL_MARK] (GC_push_conditional_eager): Likewise. * include/private/gc_priv.h [!THREADS && TRACE_BUF] (GC_add_trace_entry): Likewise. * include/private/gc_priv.h (GC_collect_or_expand): Likewise. * include/private/gc_priv.h [MPROTECT_VDB && USE_MUNMAP] (GC_mprotect_dirty_init, GC_has_unmapped_memory): Likewise. * include/private/gc_priv.h [CHECKSUMS && MPROTECT_VDB && !DARWIN] (GC_record_fault): Likewise. * include/private/gc_priv.h [CHECKSUMS] (GC_check_dirty): Likewise. * include/private/gc_priv.h [GC_WIN32_THREADS && WRAP_MARK_SOME && !GC_PTHREADS] (GC_started_thread_while_stopped): Likewise. * include/private/gc_priv.h [SEARCH_FOR_DATA_START || NETBSD && __ELF__] (GC_find_limit): Likewise. * include/private/gc_priv.h [NEED_PROC_MAPS && (IA64 || INCLUDE_LINUX_THREAD_DESCR)] (GC_enclosing_mapping): Likewise. * include/private/pthread_support.h (GC_inner_start_routine): Likewise. * include/private/thread_local_alloc.h [GC_ASSERTIONS] (GC_is_thread_tsd_valid, GC_check_tls_for): Likewise. * include/private/thread_local_alloc.h [GC_ASSERTIONS && USE_CUSTOM_SPECIFIC] (GC_check_tsd_marks): Likewise. * include/private/gc_priv.h [HEURISTIC2 || SEARCH_FOR_DATA_START || !STACKBOTTOM && HEURISTIC2 || (SVR4 || AIX || DGUX || LINUX && SPARC) && !PCR] (NEED_FIND_LIMIT): Collapse multiple definitions. * malloc.c (GC_collect_or_expand): Remove prototype. * mark.c [CHECKSUMS] (GC_check_dirty): Likewise. * mark.c [GC_WIN32_THREADS && !GC_PTHREADS] (GC_started_thread_while_stopped): Likewise. * mark_rts.c [WRAP_MARK_SOME && PARALLEL_MARK] (GC_push_conditional_eager): Likewise. * mark_rts.c [!THREADS && TRACE_BUF] (GC_add_trace_entry): Likewise. * os_dep.c [SEARCH_FOR_DATA_START || NETBSD && __ELF__] (GC_find_limit): Likewise. * os_dep.c [CHECKSUMS && MPROTECT_VDB && !DARWIN] (GC_record_fault): Likewise. * os_dep.c [MPROTECT_VDB && USE_MUNMAP] (GC_has_unmapped_memory, GC_mprotect_dirty_init): Likewise. * os_dep.c [MPROTECT_VDB && !GC_NO_THREADS_DISCOVERY] (GC_darwin_register_mach_handler_thread): Likewise. * pthread_support.c [GC_ASSERTIONS] (GC_check_tls_for): Likewise. * pthread_support.c [GC_ASSERTIONS && USE_CUSTOM_SPECIFIC] (GC_check_tsd_marks): Likewise. * pthread_support.c [INCLUDE_LINUX_THREAD_DESCR] (GC_enclosing_mapping): Likewise. * pthread_support.c [!SN_TARGET_ORBIS && !SN_TARGET_PSP2] (GC_inner_start_routine): Likewise. * thread_local_alloc.c [GC_ASSERTIONS] (GC_is_thread_tsd_valid): Likewise. * win32_threads.c [GC_ASSERTIONS] (GC_check_tls_for): Likewise. * win32_threads.c [GC_ASSERTIONS && USE_CUSTOM_SPECIFIC] (GC_check_tsd_marks): Likewise.
* Avoid potential race when accessing size_map tableHans Boehm2018-02-261-2/+3
| | | | | | | | | | | | | | | | | | There is again a data race between GC_extend_size_map and GC_size_map[] readers, though it is again not likely to fail in practice. It is feasible to just move all of the GC_size_map accesses under the lock, and this does not look to incur a substantial penalty. * gcj_mlc.c (GC_gcj_malloc, GC_gcj_malloc_ignore_off_page): Move lg=GC_size_map[lb] to be right after LOCK() instead of preceding it. * malloc.c (GC_malloc_kind_global, GC_generic_malloc_uncollectable): Likewise. * typd_mlc.c (GC_malloc_explicitly_typed_ignore_off_page): Likewise. * include/gc.h (GC_get_size_map_at): Update comment to note that the client should use synchronization when calling the function. * include/private/gc_priv.h (_GC_arrays._size_map): Add comment about synchronization.
* Revert 'Workaround TSan false positives in extend_size_map'Ivan Maidanski2018-02-261-13/+2
| | | | | | | This reverts commit e522d6d791680b55825b5f11a4c082eb4770ecf5. Because there is again a data race here, not a false positive, though it is again not likely to fail in practice.
* Change type of hb_sz field (of hblkhdr) from size_t to wordIvan Maidanski2018-02-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Place no_sanitize attributes in a GCC-compliant wayIvan Maidanski2017-11-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Now the attributes precede the function prototypes (the format is: <attribute> void f(void) <body>). * finalize.c (GC_should_invoke_finalizers): Move GC_ATTR_NO_SANITIZE_THREAD attribute to the beginning of the function prototype (even before GC_API, GC_INNER or static). * malloc.c (fill_size_map): Likewise. * mark.c (GC_noop1, GC_mark_from, GC_push_all_eager): Likewise. * mark.c [WRAP_MARK_SOME && PARALLEL_MARK] (GC_push_conditional_eager): Likewise. * misc.c [THREADS] (next_random_no): Likewise. * os_dep.c [MPROTECT_VDB && THREADS && AO_HAVE_test_and_set_acquire] (async_set_pht_entry_from_index): Likewise. * os_dep.c [MPROTECT_VDB] (is_header_found_async): Likewise. * pthread_stop_world.c [!NACL && !GC_OPENBSD_UTHREADS] (update_last_stop_count): Likewise. * pthread_stop_world.c [!NACL && !GC_OPENBSD_UTHREADS && GC_ENABLE_SUSPEND_THREAD] (set_suspended_ext_flag, GC_resume_thread): Likewise. * pthread_support.c [THREAD_SANITIZER && (USE_SPIN_LOCK || !NO_PTHREAD_TRYLOCK)] (is_collecting): Likewise. * pthread_support.c [USE_SPIN_LOCK] (set_last_spins_and_high_spin_max, reset_spin_max): Likewise. * mark.c (GC_mark_from, GC_push_all_eager): Move GC_ATTR_NO_SANITIZE_ADDR, GC_ATTR_NO_SANITIZE_MEMORY attributes to the beginning of the function prototype. * mach_dep.c (GC_with_callee_saves_pushed): Likewise. * mark.c [WRAP_MARK_SOME && PARALLEL_MARK] (GC_push_conditional_eager): Likewise.
* Workaround TSan false positives in extend_size_mapIvan Maidanski2017-11-161-2/+13
| | | | | | | | | | | | | | | | Thread Sanitizer reports data races between fill_size_map (called from GC_extend_size_map) and GC_gcj_malloc[_ignore_off_page], GC_malloc_kind_global, GC_generic_malloc_uncollectable, GC_malloc_explicitly_typed_ignore_off_page which read a value from GC_size_map before acquiring the allocation lock. These races could be ignored as the value is verified after acquiring the lock. * alloc.c: Refine comment about GC_allocobj (and GC_size_map) usage for the case of a multi-threaded environment. * malloc.c (fill_size_map): New static function (with GC_ATTR_NO_SANITIZE_THREAD attribute). * malloc.c (GC_extend_size_map): Use fill_size_map() to fill in a region of GC_size_map.
* Remove GENERAL_MALLOC internal macroIvan Maidanski2017-11-141-1/+4
| | | | | | | | | | (code refactoring) * alloc.c: Update comment (about GC_allocobj usage). * include/private/gc_priv.h (GENERAL_MALLOC): Remove. * include/private/gc_priv.h (GENERAL_MALLOC_IOP): Move to typd_mlc.c. * malloc.c (GC_malloc_kind_global): Expand GENERAL_MALLOC macro; copy the comment from gc_priv.h.
* Make extend_size_map() staticIvan Maidanski2017-10-251-1/+54
| | | | | | | | | | | | | | (code refactoring) * include/private/gc_priv.h (GC_extend_size_map): Remove prototype. * malloc.c (GC_extend_size_map): Move the function definition from misc.c; change GC_INNER to STATIC; reformat code; remove j and much_smaller_than_i local variables; add assertions that I_HOLD_LOCK and GC_size_map[i]==0; remove comment that GC_size_map[i] is expected to be zero. * malloc.c (GC_generic_malloc_inner): Capitalize the first letter of the description comment. * misc.c (GC_extend_size_map): Remove the definition.