summaryrefslogtreecommitdiff
path: root/reclaim.c
Commit message (Collapse)AuthorAgeFilesLines
* Suppress a data race report in debug-related GC_n_set_marksIvan Maidanski2023-04-271-0/+3
| | | | | | | | There could be a race between GC_clear_hdr_marks and GC_n_set_marks but the latter is for a debug purpose. * reclaim.c [USE_MARK_BYTES] (GC_n_set_marks): Add GC_ATTR_NO_SANITIZE_THREAD attribute; update comment.
* Add assertion that GC lock is held in start/continue_reclaim, reclaim_allIvan Maidanski2023-04-101-12/+9
| | | | | | | | | (refactoring) * reclaim.c (GC_reclaim_generic, GC_continue_reclaim): Reformat comment. * reclaim.c (GC_start_reclaim, GC_continue_reclaim, GC_reclaim_all): Add assertion that the GC lock is held.
* Refine comment of GC_print_free_list regarding GC lockIvan Maidanski2023-04-101-1/+2
| | | | | | | | (documentation) * include/gc/gc_inline.h (GC_print_free_list): Add comment about assumption about the GC lock. * reclaim.c (GC_print_free_list): Likewise.
* Do not prohibit zero proc argument in GC_register_disclaim_procIvan Maidanski2023-04-101-0/+1
| | | | | | | | | | | (fix of commit 1d3675499) * fnlz_mlc.c [ENABLE_DISCLAIM] (GC_register_disclaim_proc): Do not check that proc is non-zero. * include/gc/gc_disclaim.h (GC_register_disclaim_proc): Remove GC_ATTR_NONNULL(2) attribute. * reclaim.c [ENABLE_DISCLAIM] (GC_disclaim_and_reclaim): Add assertion that disclaim is non-zero.
* Consistent naming of variables of obj_kind typeIvan Maidanski2023-04-101-29/+24
| | | | | | | | | | | | | | | | | | | | (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.
* Remove unused DCL_LOCK_STATEIvan Maidanski2023-01-301-1/+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.
* Remove unneeded n_blocks local variable in malloc.c and reclaim.cIvan Maidanski2023-01-181-16/+10
| | | | | | | | | | | (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.
* 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.
* Include gc_inline.h from gc_priv.hIvan Maidanski2022-10-111-2/+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-2/+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.
* New GC_count_set_marks_in_hblk API functionIvan Maidanski2022-08-051-0/+4
| | | | | | | | | | | Issue #460 (bdwgc). Note: available on if the collector is built without NO_DEBUGGING. * include/gc/gc_mark.h (GC_count_set_marks_in_hblk): New API function. * reclaim.c [!NO_DEBUGGING] (GC_count_set_marks_in_hblk): Implement. * tests/gctest.c [!PCR && !GC_WIN32_THREADS && !GC_PTHREADS && CPPCHECK && !NO_DEBUGGING] (main): Call UNTESTED(GC_count_set_marks_in_hblk).
* Fix 'passing arg 1 of GC_apply_to_all_blocks from incompatible type' errorIvan Maidanski2022-08-051-4/+6
| | | | | | | | | | | | | | | | | | (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-1/+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-5/+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.
* Ensure GC lock is held in add_leaked/smashed and check_heap_procIvan Maidanski2022-04-011-0/+1
| | | | | | | | | | (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-7/+11
| | | | | | | | | | | | | | | | | * 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.
* Relax assertion of hb_n_marks in reclaim_block if more than two markersIvan Maidanski2022-03-121-2/+3
| | | | | | | | | | (fix of commit c9be25027) Issue #412 (bdwgc). * reclaim.c [PARALLEL_MARK] (GC_reclaim_block): Use min(3,GC_markers_m1+1) (instead of hard-coded 2) multiplier in the assertion about hb_n_marks maximum value; update the relevant comment.
* Eliminate 'conversion from size_t to unsigned' VC warning in n_set_marksIvan Maidanski2022-03-061-1/+1
| | | | | | | (fix of commit 83e6b4196) * reclaim.c [!USE_MARK_BYTES && !MARK_BIT_PER_OBJ] (GC_n_set_marks): Change type of ngranules local variable from size_t to unsigned.
* Ensure GC_n_set_marks() does not count extra bits in hb_marksIvan Maidanski2022-03-061-10/+23
| | | | | | | | | | | | | * reclaim.c [!USE_MARK_BYTES] (GC_n_set_marks): Decrement result by one (i.e. do not count the bit set past the end as in USE_MARK_BYTES case); add assertion that the bit past the end is set. * reclaim.c [!USE_MARK_BYTES && !MARK_BIT_PER_OBJ] (GC_n_set_marks): Divide result by BYTES_TO_GRANULES(sz) with the assertion that the reminder is zero; add comment. * reclaim.c [!PARALLEL_MARK] (GC_print_block_descr): Add assertion that n_marks is equal to hhdr->hb_n_marks. * reclaim.c (GC_print_block_descr): Add assertion that max(n_objs,1) is not less than n_marks; do not print hhdr->hb_n_marks value.
* Print objs_in_block as zero for large objects in GC_print_block_listIvan Maidanski2022-03-061-1/+0
| | | | | * reclaim.c (GC_print_block_descr): Do not change n_objs to 1 if it is zero.
* Always set only one bit past end in GC_set_hdr_marksIvan Maidanski2022-03-061-6/+2
| | | | | | | * mark.c [!USE_MARK_BYTES] (GC_set_hdr_marks): Add comments; do not put bits beyond a single one past FINAL_MARK_BIT(sz). * reclaim.c [!USE_MARK_BYTES && MARK_BIT_PER_OBJ] (GC_n_set_marks): Do not ignore part of last hb_marks[] element passed to count_ones().
* Refactoring of GC_n_set_marks and GC_print_block_descrIvan Maidanski2022-03-051-33/+26
| | | | | | | | | | | | * reclaim.c [USE_MARK_BYTES] (GC_n_set_marks): Remove sz local variable; add comment about assertion. * reclaim.c [!USE_MARK_BYTES] (set_bits): Rename to count_ones; remove m local variable; change while() to for() statement. * reclaim.c [!USE_MARK_BYTES] (GC_n_set_marks): Declare and use n_mark_words local variable only if MARK_BIT_PER_OBJ. * reclaim.c (GC_print_block_descr): Rename bytes to sz local variable and change its type to word; initialize ps at the moment of its declaration.
* Refine column names output by GC_print_block_listIvan Maidanski2022-03-051-5/+4
| | | | | | * reclaim.c (GC_print_block_list): Change printed column names of the table; avoid commas in a printed column name; use BZERO() to initialize pstats local variable (instead of initialization of each field).
* Eliminate division-by-zero FP warning in GC_ASSERT in reclaim_blockIvan Maidanski2022-01-121-1/+1
| | | | | * reclaim.c [PARALLEL_MARK] (GC_reclaim_block): Assert sz is not zero (before HBLKSIZE/sz).
* Move public header files to include/gc in source treeIvan Maidanski2021-11-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Update copyright information in alloc.c and other modified files (2021)Ivan Maidanski2021-09-091-0/+1
| | | | | | | | | | | | | | | | | | | | | * README.QUICK (Copyright): Update year (2019 to 2020). * README.md (Copyright): Likewise. * alloc.c (Copyright, GC_copyright): Likewise. * configure.ac (Copyright): Likewise. * include/private/gc_priv.h (Copyright): Likewise. * mark.c (Copyright): Likewise. * misc.c (Copyright): Likewise. * os_dep.c (Copyright): Likewise. * pthread_support.c (Copyright): Likewise. * win32_threads.c (Copyright): Likewise. * CMakeLists.txt: Update (add Ivan Maidanski). * dyn_load.c (Copyright): Likewise. * include/private/gc_alloc_ptrs.h (Copyright): Likewise. * include/private/gcconfig.h (Copyright): Likewise. * mallocx.c (Copyright): Likewise. * mark_rts.c (Copyright): Likewise. * reclaim.c (Copyright): Likewise. * tests/test.c (Copyright): Likewise.
* Eliminate code duplication in reclaim_clear and disclaim_and_reclaimIvan Maidanski2021-07-161-63/+46
| | | | | | | | | * reclaim.c (GC_clear_block): New inline function (code copied from GC_reclaim_clear and GC_disclaim_and_reclaim). * reclaim.c (GC_reclaim_clear): Remove q, n_bytes_found local variables; change type of p and plim to ptr_t; remove extra casts; use GC_clear_block(). * reclaim.c [ENABLE_DISCLAIM] (GC_disclaim_and_reclaim): Likewise.
* Workaround 'blocks>1 is always true' cppcheck FP in reclaim_blockIvan Maidanski2020-01-251-0/+3
| | | | * reclaim.c [CPPCHECK] (GC_reclaim_block): Call GC_noop1(&blocks).
* Workaround 'argument to function is always 1' cppcheck false positivesIvan Maidanski2019-09-111-5/+5
| | | | | | | | | | | | | | | | | * 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.
* Avoid potential race in hb_sz access between realloc and reclaim_blockIvan Maidanski2019-02-271-15/+33
| | | | | | | | | | | | | | | | | | | | | | | | | Issue #240 (bdwgc). GC_realloc might be changing the block size while GC_reclaim_block is examining it. The change to the size field is benign, i.e. GC_reclaim would work correctly with either value, since we are not changing the number of objects in the block. But seeing a half-updated value (though unlikely to occur in practice) could be probably bad. Using unordered atomic fetch of hb_sz field should solve the issue. * reclaim.c (GC_block_nearly_full, GC_reclaim_small_nonempty_block): Add sz argument; use sz instead of hhdr->hb_sz. * reclaim.c (GC_reclaim_clear, GC_reclaim_uninit, GC_reclaim_check): Skip the assertion about hhdr->hb_sz if THREADS. * reclaim.c [ENABLE_DISCLAIM] (GC_disclaim_and_reclaim): Likewise. * reclaim.c [AO_HAVE_load] (GC_reclaim_block): Use AO_load to access hhdr->hb_sz; add comments. * reclaim.c (GC_reclaim_block): Pass sz to GC_reclaim_small_nonempty_block() and GC_block_nearly_full(). * reclaim.c (GC_continue_reclaim, GC_reclaim_all): Pass hhdr->hb_sz to GC_reclaim_small_nonempty_block(). * reclaim.c [!EAGER_SWEEP && ENABLE_DISCLAIM] (GC_reclaim_unconditionally_marked): Likewise.
* Report time with a nanosecond precision where availableIvan Maidanski2019-01-141-2/+4
| | | | | | | | | | | | | | | | | | Issue #258 (bdwgc). * alloc.c [!NO_CLOCK] (GC_time_lim_nsec): Update comment. * alloc.c [!NO_CLOCK && !GC_DISABLE_INCREMENTAL] (GC_timeout_stop_func): Declare nsec_diff local variable; use GC_time_lim_nsec. * alloc.c [!NO_CLOCK && !GC_DISABLE_INCREMENTAL] (GC_timeout_stop_func): Use NS_FRAC_TIME_DIFF(); print "ns" value after "ms" one. * alloc.c [!NO_CLOCK] (GC_try_to_collect_inner, GC_stopped_mark, GC_finish_collection): Likewise. * reclaim.c [!NO_CLOCK] (GC_reclaim_all): Likewise. * include/private/gc_priv.h [!NO_CLOCK && BSD_TIME] (MS_TIME_DIFF): Always round the result of division toward minus infinity. * include/private/gc_priv.h [!NO_CLOCK] (NS_FRAC_TIME_DIFF): New macro.
* Replace "msecs" with "ms" in all comments and messagesIvan Maidanski2019-01-061-1/+1
| | | | | | | | | | | | | | | | | | * README.md (Bugs): Replace "msecs" with "ms". * doc/README.environment (GC_PAUSE_TIME_TARGET): Likewise. * doc/gcdescr.md (Generational Collection and Dirty Bits): Likewise. * alloc.c [!NO_CLOCK] (full_gc_total_time): Replace "msecs" with "ms" in comment. * cord/tests/de.c [WIN32] (beep): Likewise. * pthread_support.c [USE_SPIN_LOCK] (GC_lock): Likewise. * alloc.c [!GC_DISABLE_INCREMENTAL && !NO_CLOCK] (GC_timeout_stop_func): Replace "msecs" with "ms" in the printed string. * alloc.c [!NO_CLOCK] (GC_try_to_collect_inner, GC_stopped_mark, GC_finish_collection): Likewise. * misc.c [!NO_CLOCK] (GC_dump_named): Likewise. * reclaim.c [!NO_CLOCK] (GC_reclaim_all): Likewise. * tests/test.c [!NO_CLOCK] (check_heap_stats): Likewise.
* Fix invalid initializer of CLOCK_TYPE variables if BSD_TIMEIvan Maidanski2019-01-051-1/+1
| | | | | | | | | | | | | | (fix of commits 7e59301c1, 06ecaefca) * alloc.c [!NO_CLOCK] (GC_start_time): Initialize to CLOCK_TYPE_INITIALIZER (instead of 0). * alloc.c [!NO_CLOCK] (GC_try_to_collect_inner, GC_stopped_mark, GC_finish_collection): Initialize local variable of CLOCK_TYPE type to CLOCK_TYPE_INITIALIZER (instead of 0); remove comment (duplicating that in gc_priv.h). * reclaim.c [!NO_CLOCK] (GC_reclaim_all): Likewise. * include/private/gc_priv.h [!NO_CLOCK] (CLOCK_TYPE_INITIALIZER): Define macro.
* New macro to suppress printing of leaked objectsIvan Maidanski2018-11-221-1/+3
| | | | | | | | The macro (SKIP_LEAKED_OBJECTS_PRINTING) might be useful for running GC general tests in the find-leak mode. * reclaim.c (GC_print_all_errors): Do not call GC_print_heap_obj if SKIP_LEAKED_OBJECTS_PRINTING is defined.
* Fix marks and hb_n_marks consistency when disclaim returns truePetter A. Urkedal2018-11-021-0/+1
| | | | | | | | * reclaim.c [ENABLE_DISCLAIM] (GC_disclaim_and_reclaim): When a disclaim callback returns 1 to protect an object from being reclaimed, mark it to skip it on repeated scans within the cycle. In particular, this fixes sz*hhdr->hb_n_marks<=HBLKSIZE assertion failure due to excessive increments of hb_n_marks.
* Replace some FIXME items with TODO onesIvan Maidanski2018-08-311-1/+1
| | | | | | | | | | | | | | | | | | (code refactoring) * alloc.c (GC_maybe_gc, GC_collect_a_little_inner, GC_finish_collection): Replace FIXME item with TODO one. * gcj_mlc.c (maybe_finalize): Likewise. * include/gc.h [!GC_DEBUG || !__GNUC__] (GC_PTR_ADD): Likewise. * include/private/gcconfig.h [X86_64 && LINUX && __GLIBC__ && !__UCLIBC__] (GETCONTEXT_FPU_EXCMASK_BUG): Likewise. * mach_dep.c (GC_with_callee_saves_pushed): Likewise. * mark_rts.c (GC_push_current_stack): Likewise. * misc.c [MSWIN32 || MSWINCE] (WRITE): Likewise. * os_dep.c [ECOS] (ecos_gc_memory): Likewise. * os_dep.c (GC_get_stack_base, GC_page_was_ever_dirty): Likewise. * reclaim.c (GC_reclaim_clear): Likewise. * include/private/gcconfig.h [OPENBSD && m68k]: Remove FIXME item.
* Remove duplicate local variable in reclaim_blockIvan Maidanski2018-06-191-1/+0
| | | | | | | | (fix of commit 6c1a92445) * reclaim.c [ENABLE_DISCLAIM] (GC_reclaim_block): Remove duplicate ok local variable definition (which hides the one in the outermost block and has the same value).
* Fix result computation in n_set_marksIvan Maidanski2018-06-141-1/+1
| | | | | * reclaim.c [!USE_MARK_BYTES] (GC_n_set_marks): Do not decrement the result variable on return; add comment.
* Remove unnecessary type casts in n_set_marksIvan Maidanski2018-06-141-12/+12
| | | | | | | | | | (code refactoring) * reclaim.c (GC_n_set_marks): Change return type from int to unsigned; change type of result local variable to unsigned. * reclaim.c [!USE_MARK_BYTES] (set_bits): Likewise. * reclaim.c (GC_n_set_marks): Change type of i, offset, limit, n_mark_words, n_objs local variables to word; remove redundant casts.
* Eliminate 'comparing signed and unsigned values' compiler warnings (bcc)Ivan Maidanski2018-05-291-1/+2
| | | | | | | * allchblk.c (GC_allochblk_nth): Cast HBLKSIZE to signed_word in comparison to size_needed. * reclaim.c (GC_reclaim_all): Cast hhdr->hb_last_reclaimed to word in comparison to GC_gc_no-1.
* Convert GC source files to valid C++ codeIvan Maidanski2018-02-161-8/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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*.
* Avoid potential race between realloc and clear_hdr_marks/reclaim_genericHans Boehm2018-02-121-9/+18
| | | | | | | | | | | | | | | | | | | | | | GC_realloc might be changing the block size while GC_reclaim_block or GC_clear_hdr_marks is examining it. The change to the size field is benign, in that GC_reclaim (and GC_clear_hdr_marks) would work correctly with either value, since we are not changing the number of objects in the block. But seeing a half-updated value (though unlikely to occur in practice) could be probably bad. Using unordered atomic accesses on the size and hb_descr fields would solve the issue. * mallocx.c [AO_HAVE_store] (GC_realloc): Use AO_store() to update hhdr->hb_sz and hhdr->hb_descr; add static assert that size of hhdr->hb_sz matches that of AO_t; add comment. * mallocx.c [!AO_HAVE_store] (GC_realloc): Add LOCK/UNLOCK around hb_sz and hb_descr fields assignment. * mark.c [AO_HAVE_load] (GC_clear_hdr_marks): Use AO_load() to get hhdr->hb_sz value; add comment. * reclaim.c (IS_PTRFREE_SAFE): New macro (uses AO_load() if available). * reclaim.c (GC_reclaim_generic, GC_reclaim_block): Replace (hhdr)->hb_descr==0 with IS_PTRFREE_SAFE(hhdr).
* Change type of hb_sz field (of hblkhdr) from size_t to wordIvan Maidanski2018-02-081-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Do not use system clock consistently if NO_CLOCKIvan Maidanski2017-10-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | Issue #139 (bdwgc). * alloc.c (GC_try_to_collect_inner, world_stopped_total_time, world_stopped_total_divisor, MAX_TOTAL_TIME_DIVISOR, GC_stopped_mark): Replace "ifndef SMALL_CONFIG" with "ifndef NO_CLOCK". * reclaim.c (GC_reclaim_all): Likewise. * alloc.c (GC_finish_collection): Replace "ifndef SMALL_CONFIG" with "ifndef NO_CLOCK" except for GC_print_finalization_stats invocation. * doc/README.macros (NO_CLOCK): Document. * include/private/gc_priv.h (CLOCK_TYPE, GET_TIME, MS_TIME_DIFF): Do not define if NO_CLOCK. * include/private/gc_priv.h (GC_print_stats): Define as a macro (to 0) only if both NO_CLOCK and SMALL_CONFIG are defined. * misc.c (GC_print_stats): Do not define if both NO_CLOCK and SMALL_CONFIG are defined. * misc.c (GC_init): Do not set GC_print_stats only if both NO_CLOCK and SMALL_CONFIG are defined. * tests/test.c (run_one_test): Do not define start_time, reverse_time, time_diff local variables (and do not use GET_TIME, MS_TIME_DIFF) if NO_CLOCK is defined.
* Eliminate unsigned fl_builder_count underflow in mark_threadIvan Maidanski2017-08-221-2/+3
| | | | | | | | | | | | | | | (refactor commit 0ca6d3f) * include/private/gc_priv.h [PARALLEL_MARK] (GC_fl_builder_count): Change type from word to signed_word. * reclaim.c [PARALLEL_MARK] (GC_fl_builder_count): Likewise. * mark.c [PARALLEL_MARK] (GC_wait_for_markers_init): Change type of count local variable to signed_word; add assertion that count is non-negative. * pthread_support.c [PARALLEL_MARK] (GC_mark_thread): Add comment that GC_fl_builder_count can be negative here. * win32_threads.c [PARALLEL_MARK] (GC_mark_thread): Likewise. * reclaim.c [PARALLEL_MARK] (GC_fl_builder_count): Refine comment.
* Do not call BCOPY and BZERO if size is zeroIvan Maidanski2017-08-091-4/+6
| | | | | | | | | | | | | | | | | | | | * 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.
* Eliminate CSA warning about incorrect cast applied to HBLK_OBJSIvan Maidanski2017-07-211-1/+1
| | | | | | | | HBLK_OBJS() expects the argument value and has the result value of size_t type. * reclaim.c (GC_print_block_descr): Cast result of HBLK_OBJS() to unsigned int instead of casting its argument.
* Fix null dereference in reclaim_block if DONT_ADD_BYTE_AT_ENDHamayama2017-06-201-3/+6
| | | | | | | Issue #167 (bdwgc). * reclaim.c (GC_reclaim_block): If ok->ok_reclaim_list is null then do not update hhdr->hb_next (and *rlh).