summaryrefslogtreecommitdiff
path: root/finalize.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Add assertions to ensure ADD_CALL_CHAIN is called holding the lockIvan Maidanski2018-03-151-0/+1
| | | | | | | | | | | | | | | (code refactoring) * alloc.c (GC_collect_a_little_inner, GC_allocobj): Add assertion that the allocation lock is held. * dbg_mlc.c (GC_store_debug_info_inner): Likewise. * dbg_mlc.c [DBG_HDRS_ALL] (GC_debug_generic_malloc_inner, GC_debug_generic_malloc_inner_ignore_off_page): Likewise. * finalize.c [!GC_TOGGLE_REFS_NOT_NEEDED] (ensure_toggleref_capacity): Likewise. * specific.c [USE_CUSTOM_SPECIFIC] (GC_key_create_inner): Likewise. * alloc.c (GC_allocobj): Remove comment (about the lock). * dbg_mlc.c [DBG_HDRS_ALL] (GC_debug_generic_malloc_inner): Likewise.
* Access finalize_now atomically to avoid TSan warning without no-sanitizeIvan Maidanski2018-03-141-6/+19
| | | | | | | | | | | | | | * finalize.c (SET_FINALIZE_NOW): New macro (which uses AO_store if available). * finalize.c (GC_finalize): Use SET_FINALIZE_NOW(fo) instead of GC_fnlz_roots.finalize_now=fo. * finalize.c [!JAVA_FINALIZATION_NOT_NEEDED] (GC_enqueue_all_finalizers): Likewise. * finalize.c [THREADS] (GC_invoke_finalizers): Likewise. * finalize.c (GC_should_invoke_finalizers): Remove GC_ATTR_NO_SANITIZE_THREAD. * finalize.c [AO_HAVE_load] (GC_should_invoke_finalizers): Use AO_load to get GC_fnlz_roots.finalize_now value.
* Fix linkage of javaxfc.h symbols for the case of compilation as C++ codeIvan Maidanski2018-03-011-0/+1
| | | | | | | | | Issue #206 (bdwgc). The functions should be declared (as extern "C") before the definition. * finalize.c [!GC_NO_FINALIZATION]: Include javaxfc.h. * pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD]: Likewise.
* Eliminate C++ warnings about deprecated register keyword (GC source)Jay Krell2018-02-221-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Issue #206 (bdwgc). * blacklst.c (GC_number_stack_black_listed, total_stack_black_listed): Remove register keyword for local variables. * dyn_load.c [IRIX5 || USE_PROC_FOR_LIBRARIES && !LINUX] (GC_register_dynamic_libraries): Likewise. * extra/pcr_interface.c [PCR] (GC_enumerate_block): Likewise. * finalize.c (GC_grow_table): Likewise. * headers.c (alloc_hdr, GC_init_headers, GC_remove_counts, GC_prev_block): Likewise. * include/private/gc_pmark.h (PUSH_OBJ): Likewise. * mach_dep.c [!HAVE_PUSH_REGS && !HAVE_BUILTIN_UNWIND_INIT] (GC_with_callee_saves_pushed): Likewise. * mark.c (clear_marks_for_block): Likewise. * mark_rts.c [MSWIN32 || MSWINCE || CYGWIN32] (GC_add_roots_inner): Likewise. * mark_rts.c [!NO_DEBUGGING] (GC_is_tmp_root): Likewise. * os_dep.c [GWW_VDB || MPROTECT_VDB || PROC_VDB || MANUAL_VDB] (GC_page_was_dirty): Likewise. * os_dep.c [CHECKSUMS && GWW_VDB || PROC_VDB] (GC_or_pages, GC_page_was_ever_dirty): Likewise. * os_dep.c (GC_write_fault_handler): Likewise. * os_dep.c [PROC_VDB] (GC_read_dirty): Likewise. * os_dep.c [MPROTECT_VDB && DARWIN] (catch_exception_raise): Likewise. * os_dep.c [SAVE_CALL_CHAIN && NARGS>0] (GC_save_callers): Likewise. * pthread_stop_world.c [!NACL] (GC_start_world): Likewise. * pthread_support.c (GC_delete_thread, GC_delete_gc_thread): Likewise. * typd_mlc.c (GC_push_complex_descriptor): Likewise. * win32_threads.c (GC_delete_gc_thread_no_free, GC_delete_thread): Likewise.
* Fix 'anonymous type with no linkage used to declare variable' in GC sourceIvan Maidanski2018-02-201-1/+1
| | | | | | | | | Issue #206 (bdwgc). * dyn_load.c [DARWIN] (GC_dyld_sections): Provide some name to struct. * finalize.c (GC_fnlz_roots): Likewise. * os_dep.c [MPROTECT_VDB && DARWIN] (GC_ports, GC_mprotect_thread_notify, GC_mprotect_thread): Likewise.
* Convert GC source files to valid C++ codeIvan Maidanski2018-02-161-13/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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*.
* 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 positive in invoke_finalizersIvan Maidanski2017-11-011-1/+9
| | | | | | | | * finalize.c [THREADS && !THREAD_SANITIZER] (GC_invoke_finalizers): Do not compare bytes_freed_before to GC_bytes_freed without the lock; add comment. * include/private/gc_priv.h (_GC_arrays._finalizer_bytes_freed): Replace "mem." to "memory" in a comment.
* Workaround Thread Sanitizer (TSan) false positive warnings (partially)Ivan Maidanski2017-10-201-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch covers only data race false positive warnings reported in async_set_pht_entry_from_index, GC_clear_stack, GC_invoke_finalizers, GC_lock, GC_noop1, GC_notify_or_invoke_finalizers, GC_pthread_create, GC_suspend_handler_inner, I_DONT_HOLD_LOCK. * finalize.c (GC_should_invoke_finalizers): Add GC_ATTR_NO_SANITIZE_THREAD. * mark.c (GC_noop1): Likewise. * os_dep.c [MPROTECT_VDB && THREADS && AO_HAVE_test_and_set_acquire] (async_set_pht_entry_from_index): Likewise. * finalize.c (GC_invoke_finalizers, GC_notify_or_invoke_finalizers): Call GC_should_invoke_finalizers() instead of GC_fnlz_roots.finalize_now!=NULL. * include/private/gc_locks.h [(GC_WIN32_THREADS && !USE_PTHREAD_LOCKS || GC_PTHREADS) && GC_ASSERTIONS && THREAD_SANITIZER] (I_DONT_HOLD_LOCK): Define to TRUE; add comment. * include/private/gc_locks.h [!GC_ALWAYS_MULTITHREADED && THREAD_SANITIZER] (set_need_to_lock): Do not set GC_need_to_lock if already set; add comment. * include/private/gc_priv.h [!GC_ATTR_NO_SANITIZE_THREAD] (GC_ATTR_NO_SANITIZE_THREAD): New macro. * include/private/gcconfig.h [__has_feature && __has_feature(thread_sanitizer)] (THREAD_SANITIZER): Define. * misc.c [THREADS] (next_random_no): New static function (with GC_ATTR_NO_SANITIZE_THREAD). * pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL] (update_last_stop_count): 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. * misc.c [THREADS] (GC_clear_stack): Remove random_no static variable; use next_random_no() instead of ++random_no%13. * pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL] (GC_suspend_handler_inner): Call update_last_stop_count() instead of me->stop_info.last_stop_count=my_stop_count. * pthread_support.c [USE_SPIN_LOCK || !NO_PTHREAD_TRYLOCK] (SPIN_MAX): Define only if not yet. * pthread_support.c [USE_SPIN_LOCK || !NO_PTHREAD_TRYLOCK] (GC_collecting): Initialize to FALSE instead of 0. * pthread_support.c [!(THREAD_SANITIZER && (USE_SPIN_LOCK || !NO_PTHREAD_TRYLOCK))] (is_collecting): Define as a macro. * pthread_support.c [USE_SPIN_LOCK] (low_spin_max, high_spin_max, spin_max, last_spins): Move definition out of GC_lock(). * pthread_support.c (GC_lock): Use is_collecting(), set_last_spins_and_high_spin_max() and reset_spin_max().
* Eliminate 'non-null arg compared to null' warning in toggleref_add (GCC)Ivan Maidanski2017-09-271-1/+1
| | | | | | | | (fix commit 86991cb) * finalize.c [!GC_TOGGLE_REFS_NOT_NEEDED] (GC_toggleref_add): Use NONNULL_ARG_NOT_NULL to check pointer argument marked as non-null (in the function declaration) is actually non-null.
* Do not call BCOPY and BZERO if size is zeroIvan Maidanski2017-08-091-2/+3
| | | | | | | | | | | | | | | | | | | | * dbg_mlc.c (GC_debug_strndup): Do not call BCOPY() if elements count is zero. * dbg_mlc.c (GC_debug_realloc): Likewise. * finalize.c [!GC_TOGGLE_REFS_NOT_NEEDED] (ensure_toggleref_capacity): Likewise. * malloc.c [REDIRECT_MALLOC && !strndup] (strndup): Likewise. * mallocx.c (GC_strndup): Likewise. * misc.c [!GC_GET_HEAP_USAGE_NOT_NEEDED] (GC_get_prof_stats): Likewise. * os_dep.c [SAVE_CALL_CHAIN && GC_HAVE_BUILTIN_BACKTRACE] (GC_save_callers): Likewise. * reclaim.c (GC_print_all_errors): Likewise. * malloc.c (GC_free): Do not call BZERO() if elements count is zero. * malloc.c [THREADS] (GC_free_inner): Likewise. * reclaim.c (GC_print_all_errors): Likewise. * misc.c [!GC_GET_HEAP_USAGE_NOT_NEEDED && THREADS] (GC_get_prof_stats_unsafe): Do not call fill_prof_stats() and BCOPY() if stats_sz is zero.
* Fix SIGSEGV in GC_is_marked when gc_cleanup is used in leak-finding modeIvan Maidanski2017-07-141-0/+2
| | | | | | | | | | | | | | | Issue #162 (bdwgc). Now finalizers and disappearing links registration is a no-op in case of the leak-finding mode. * finalize.c (GC_register_disappearing_link_inner): Do nothing (return GC_UNIMPLEMENTED) if GC_find_leak. * finalize.c (GC_register_finalizer_inner): Do nothing if GC_find_leak. * include/gc.h (GC_find_leak): More verbose comment. * include/gc.h (GC_debug_register_finalizer, GC_general_register_disappearing_link): Document the case of GC_find_leak.
* Workaround 'int shift by negative amount' false defect in GC_finalizeIvan Maidanski2017-05-241-1/+4
| | | | | | | (fix commits eeb118d, d46fbe0) * finalize.c [GC_ASSERTIONS || LINT2] (GC_finalize): Replace GC_ASSERT (for curr_fo and log_fo_table_size) with a conditional ABORT.
* Workaround 'int shift by negative amount' false code defect in finalizeIvan Maidanski2017-05-171-2/+6
| | | | | | | | (fix commit eeb118d) * finalize.c (GC_register_disappearing_link_inner, GC_register_finalizer_inner): Replace GC_ASSERT (for log_size) with a conditional ABORT if LINT2.
* Eliminate 'integer shift by a negative amount' code defect in finalizeIvan Maidanski2016-12-171-1/+11
| | | | | | | | | | | | | | * finalize.c (GC_register_disappearing_link_inner): Add assertion that dl_hashtbl->log_size is non-negative after GC_grow_table() call. * finalize.c (GC_unregister_disappearing_link_inner): If dl_hashtbl->log_size is negative then return immediately (to avoid an integer value shift by log_size==-1 in HASH2). * finalize.c [!GC_MOVE_DISAPPEARING_LINK_NOT_NEEDED] (GC_move_disappearing_link_inner): Likewise. * finalize.c (GC_register_finalizer_inner): Add assertion that log_fo_table_size is non-negative after GC_grow_table() call. * finalize.c (GC_finalize): Add assertion that log_fo_table_size is non-negative unless GC_fnlz_roots.finalize_now is null.
* Eliminate 'null dereference' code defect warning in register_finalizerIvan Maidanski2016-10-291-1/+5
| | | | | | | | * finalize.c (GC_register_finalizer_inner): Add GC_ASSERT that fn is non-zero (instead of specifying this in a comment) for the case when new_fo is non-NULL (new_fo is returned by GC_oom_fn). * finalize.c [LINT2] (GC_register_finalizer_inner): Call ABORT if hhdr is NULL (for the case when new_fo is non-NULL).
* Revert "Eliminate 'deref-of-null' static analyzer warning in register_finalizer"Ivan Maidanski2016-10-291-2/+1
| | | | | | This reverts commit 7547c377153ddd859bef6a2dd14c42e9f12aa0be. Because it requires -D GC_ASSERTIONS.
* Export GC_dump_finalization/regions()Ivan Maidanski2016-10-291-1/+1
| | | | | | | | | | Note: these 2 functions are not used by GC itself. * allchblk.c [!NO_DEBUGGING] (GC_dump_regions): Turn into a public definition (add GC_API+GC_CALL). * finalize.c [!NO_DEBUGGING] (GC_dump_finalization): Likewise. * include/gc.h (GC_dump_regions, GC_dump_finalization): New public API prototype.
* Eliminate redundant local variable in register_finalizerIvan Maidanski2016-10-281-7/+5
| | | | | | | | The variable caused a report about a code defect which is a false positive. * finalize.c (GC_register_finalizer_inner): Remove "base" local variable (use "obj" argument instead).
* Eliminate 'printf format specifies type void*' GCC pedantic warningsIvan Maidanski2016-10-211-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Explicitly cast pointer arguments (passed to printf and ABORT_ARGn) to void* to match %p format specifier. * allchblk.c [!NO_DEBUGGING] (GC_dump_regions): Cast arguments to void* those printf format specifier is %p. * alloc.c [!NO_DEBUGGING] (GC_print_heap_sects): Likewise. * backgraph.c [MAKE_BACK_GRAPH] (backwards_height): Likewise. * blacklst.c (GC_default_print_heap_obj_proc): Likewise. * blacklst.c [PRINT_BLACK_LIST] (GC_print_blacklisted_ptr): Likewise. * cord/cordbscs.c (CORD_dump_inner): Likewise. * darwin_stop_world.c [DEBUG_THREADS_EXTRA] (GC_FindTopOfStack): Likewise. * darwin_stop_world.c [DEBUG_THREADS] (GC_stack_range_for): Likewise. * dbg_mlc.c (GC_print_obj): Likewise. * dbg_mlc.c [!SHORT_DBG_HDRS] (GC_print_smashed_obj): Likewise. * dyn_load.c [HAVE_DL_ITERATE_PHDR] (GC_register_dynamic_libraries_dl_iterate_phdr): Likewise. * dyn_load.c [IRIX5] (GC_register_dynamic_libraries): Likewise. * finalize.c [!NO_DEBUGGING] (GC_dump_finalization_links, GC_dump_finalization): Likewise. * include/private/gc_pmark.h [MARK_BIT_PER_GRANULE || MARK_BIT_PER_OBJ] (PUSH_CONTENTS_HDR): Likewise. * mark.c [ENABLE_TRACE] (GC_mark_from): Likewise. * mark_rts.c [!NO_DEBUGGING] (GC_print_static_roots): Likewise. * mark_rts.c [DEBUG_ADD_DEL_ROOTS] (GC_add_roots_inner, GC_remove_root_at_pos): Likewise. * misc.c [ENABLE_TRACE] (GC_init): Likewise. * os_dep.c [LINUX || HURD] (GC_init_linux_data_start): Likewise. * os_dep.c [!OS2 && !MSWIN32] (GC_register_data_segments): Likewise. * os_dep.c [USE_MUNMAP && !USE_WINALLOC && !NACL] (GC_remap): Likewise. * os_dep.c [!DARWIN && !MSWIN32 && !MSWINCE] (GC_write_fault_handler): Likewise. * os_dep.c [PROC_VDB && DEBUG_DIRTY_BITS] (GC_read_dirty): Likewise. * os_dep.c [MPROTECT_VDB && DARWIN && BROKEN_EXCEPTION_HANDLING] (catch_exception_raise): Likewise. * pthread_stop_world.c [DEBUG_THREADS] (GC_push_all_stacks): Likewise. * pthread_support.c [DEBUG_THREADS] (GC_unregister_my_thread_inner, GC_unregister_my_thread, GC_start_rtn_prepare_thread): Likewise. * reclaim.c [!NO_DEBUGGING] (GC_print_free_list): Likewise. * specific.c [USE_CUSTOM_SPECIFIC && GC_ASSERTIONS] (GC_check_tsd_marks): Likewise. * win32_threads.c [DEBUG_THREADS] (GC_push_stack_for): Likewise. * win32_threads.c [GC_PTHREADS && DEBUG_THREADS] (GC_pthread_join, GC_pthread_create, GC_pthread_start_inner, GC_thread_exit_proc): Likewise. * dbg_mlc.c: Remove duplicate check of SHORT_DBG_HDRS. * include/private/gc_pmark.h [MARK_BIT_PER_GRANULE || MARK_BIT_PER_OBJ] (PUSH_CONTENTS_HDR): Add missing parentheses around "source" argument when casting it to ptr_t.
* Eliminate more 'scope of variable can be reduced' cppcheck style warningsIvan Maidanski2016-10-041-20/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | * allchblk.c (GC_compute_large_free_bytes, GC_print_hblkfreelist, free_list_index_of, GC_dump_regions, GC_add_to_fl, GC_unmap_old, GC_allochblk_nth): Move local variable declaration to the inner scope where the variable is actually used. * alloc.c (GC_maybe_gc, GC_collect_a_little_inner, GC_set_fl_marks, GC_clear_fl_marks): Likewise. * dyn_load.c (GC_register_dynamic_libraries): Likewise. * finalize.c (GC_ignore_self_finalize_mark_proc, GC_register_finalizer_inner, GC_dump_finalization_links, GC_dump_finalization, GC_make_disappearing_links_disappear, GC_remove_dangling_disappearing_links, GC_invoke_finalizers): Likewise. * headers.c (GC_install_counts): Likewise. * malloc.c (GC_malloc_kind_global, GC_generic_malloc_uncollectable, GC_free): Likewise. * mark.c (GC_push_all_eager, GC_push_marked1, GC_push_marked2, GC_push_marked4): Likewise. * mark_rts.c (GC_next_exclusion, GC_exclude_static_roots_inner, GC_push_conditional_with_exclusions): Likewise. * misc.c (GC_base, GC_parse_mem_size_arg, GC_write): Likewise. * os_dep.c (GC_repeat_read, GC_get_maps, GC_least_described_address, GC_register_root_section, GC_register_data_segments): Likewise. * reclaim.c (GC_reclaim_block, GC_start_reclaim): Likewise. * finalize.c (ITERATE_DL_HASHTBL_BEGIN): Declare prev_dl local variable.
* Eliminate 'comparison is always false' static analyzer warning in finalizeIvan Maidanski2016-09-281-10/+4
| | | | | | | | | | | | | | | GC_enqueue_all_finalizers code refactoring is done (removal of the unreachable statement) to eliminate the warning. * finalize.c (GC_enqueue_all_finalizers): Remove "prev_fo" local variable; remove "register" keyword for local variables; remove the pointer to the chain of hash table entries from the roots (i.e. setting the roots pointer to null) at the beginning of processing the chain (instead of updating the roots pointer on deletion of each entry and finally setting it to null); remove fo_set_next(prev_fo) as it is never called (because prev_fo was always null); update GC_fo_entries only when the whole table processed (i.e. all items removed).
* Eliminate 'deref-of-null' static analyzer warning in register_finalizerIvan Maidanski2016-09-271-1/+2
| | | | | | * finalize.c (GC_register_finalizer_inner): Add GC_ASSERT that fn and hhdr are non-NULL (instead of specifying this in a comment) if new_fo is non-NULL (new_fo is returned by GC_oom_fn).
* Remove code commented out by 'ifdef UNDEFINED'Ivan Maidanski2016-07-251-6/+3
| | | | | | | * finalize.c [UNDEFINED] (GC_invoke_finalizers): Remove GC_free(curr_fo) call; update comment. * include/private/gcconfig.h [UNDEFINED] (_etext, DATASTART): Remove. * typd_mlc.c [UNDEFINED] (GC_make_complex_array_descriptor): Likewise.
* Fix potential left shift overflows in finalize.c (64-bit targets)Ivan Maidanski2016-02-161-6/+8
| | | | | | | | * finalize.c (HASH2, GC_grow_table): Cast 1 to word before shift to avoid overflow. * finalize.c (GC_dump_finalization_links, GC_dump_finalization, ITERATE_DL_HASHTBL_BEGIN, GC_finalize): Cast 1 to size_t before shift to avoid overflow.
* Add assertion on lock status to GC_alloc_large and its callersIvan Maidanski2015-10-221-3/+6
| | | | | | | | | | | | (code refactoring) * alloc.c (GC_try_to_collect_inner): Remove comment about expected lock status; add assertion about holding the allocation lock. * finalize.c (GC_grow_table): Likewise. * malloc.c (GC_alloc_large, GC_alloc_large_and_clear, GC_generic_malloc_inner, GC_generic_malloc_inner_ignore_off_page): Likewise. * misc.c (GC_new_free_list_inner): Likewise.
* Fix abort message in GC_move_long_linkIvan Maidanski2015-09-111-1/+1
| | | | * finalize.c (GC_move_long_link): Fix function name in abort message.
* Fix 'comparison of non-null parameter is always false' warning (Clang)Ivan Maidanski2015-09-101-4/+6
| | | | | | | | | | | * alloc.c (GC_set_stop_func, GC_try_to_collect): Use NONNULL_ARG_NOT_NULL to check argument marked as non-null (in function declaration) is actually non-null. * finalize.c (GC_general_register_disappearing_link, GC_register_long_link, GC_move_disappearing_link, GC_move_long_link): Likewise. * misc.c (GC_set_warn_proc, GC_set_abort_func, GC_set_oom_fn): Likewise. * include/private/gc_priv.h (NONNULL_ARG_NOT_NULL): New macro.
* Reduce GCToggleRef size twice (convert struct to union)Ivan Maidanski2015-08-281-21/+14
| | | | | | | | | | * finalize.c (GCToggleRef): Replace struct with union; update comment. * finalize.c (GC_process_togglerefs): Check lowest bit of strong_ref to select between strong_ref and weak_ref. * finalize.c (GC_mark_togglerefs, GC_clear_togglerefs): Likewise. * finalize.c (GC_process_togglerefs): Store only strong_ref or weak_ref to GC_toggleref_arr elements. * finalize.c (GC_toggleref_add): Likewise.
* Code refactoring of toggle-ref supportIvan Maidanski2015-08-281-134/+149
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * alloc.c (GC_stopped_mark): Move GC_process_togglerefs() call from GC_stop_world; do not call it if GC_NO_FINALIZATION or GC_TOGGLE_REFS_NOT_NEEDED. * darwin_stop_world.c (GC_stop_world): Remove GC_process_togglerefs() call. * pthread_stop_world.c (GC_stop_world): Likewise. * doc/README.macros (GC_TOGGLE_REFS_NOT_NEEDED): Document. * finalize.c (GCToggleRef, GC_process_togglerefs, push_and_mark_object, GC_clear_togglerefs, GC_toggleref_add): Replace GC_PTR with void*. * include/gc.h (GC_toggleref_add): Likewise. * finalize.c (GCToggleRef, GC_toggleref_callback, GC_toggleref_arr, GC_toggleref_array_size, GC_toggleref_array_capacity, GC_process_togglerefs, push_and_mark_object, GC_mark_togglerefs, GC_clear_togglerefs, GC_set_toggleref_func, ensure_toggleref_capacity, GC_toggleref_add): Do not defined if GC_TOGGLE_REFS_NOT_NEEDED. * finalize.c (GCToggleRef): Add comment. * finalize.c (GC_toggleref_array): Rename to GC_toggleref_arr. * finalize.c (GC_toggleref_callback, GC_toggleref_array, GC_toggleref_array_size, GC_toggleref_array_capacity): Make it STATIC (instead "static"). * finalize.c (GC_process_togglerefs): Decorate with GC_INNER; remove "toggle_ref_counts", "res" local variables; rename "w" local variable to "new_size"; add assertion on lock state; use GC_TOGGLE_REF_* enum element in switch statement; use BZERO to clear moved elements of GC_toggleref_arr. * finalize.c (GC_normal_finalize_mark_proc): Declare (before use). * finalize.c (push_and_mark_object): Replace PUSH_OBJ with GC_normal_finalize_mark_proc call. * finalize.c (GC_mark_togglerefs, GC_clear_togglerefs): Remove "object" local variable. * finalize.c (GC_toggleref_register_callback): Rename to GC_set_toggleref_func; change argument to GC_toggleref_func (which returns GC_ToggleRefStatus instead of int). * finalize.c (GC_toggleref_register_callback, GC_toggleref_add): Decorate with GC_API and GC_CALL. * include/gc.h (GC_toggleref_register_callback): Likewise. * finalize.c (GC_set_toggleref_func): Acquire allocation lock. * finalize.c (GC_get_toggleref_func): New API function. * finalize.c (ensure_toggleref_capacity): Rename "capacity" argument to "capacity_inc"; add assertion on argument value; rename "tmp" local variable to "new_array"; remove unused "old_capacity" variable; replace memcpy() with BCOPY() call. * finalize.c (GC_toggleref_add): Rename "strong_ref" argument to "is_strong_ref". * finalize.c (GC_finalize): Do not call GC_clear_togglerefs and GC_mark_togglerefs if GC_TOGGLE_REFS_NOT_NEEDED. * include/gc.h (GC_ToggleRefStatus, GC_toggleref_func): New type. * include/gc.h (GC_toggleref_register_callback): Add comment (including about locking). * include/gc.h (GC_get_toggleref_func): New API function declaration. * include/gc.h (GC_toggleref_add): Decorate with GC_CALL; add comment; add GC_ATTR_NONNULL attribute. * include/private/gc_priv.h (GC_process_togglerefs): Do not declare if GC_TOGGLE_REFS_NOT_NEEDED; decorate with GC_INNER.
* Fix out-of-memory handling in GC_toggleref_addIvan Maidanski2015-08-261-5/+19
| | | | | | | | | | | * finalize.c (ensure_toggleref_capacity): Change return type from void to GC_bool; return FALSE on allocation failure (or desired capacity value overflow). * finalize.c (GC_toggleref_add): Change return type from void to int. * include/gc.h (GC_toggleref_add): Likewise. * finalize.c (GC_toggleref_add): Return GC_NO_MEMORY if ensure_toggleref_capacity failed, GC_SUCCESS otherwise (including the case of no callback).
* Fix clearing of moved toggle-refs array elementsIvan Maidanski2015-08-261-2/+2
| | | | | * finalize.c (GC_process_togglerefs): Replace "w" to "i" local variable in the loop which clears unused part of GC_toggleref_array.
* Fix memory management for toggle-refRodrigo Kumpera2015-08-261-3/+3
| | | | | | | | | | (Apply commit 960f233 from 'mono_libgc' branch.) Replace GC_free with GC_INTERNAL_FREE. The former might take the GC lock and deadlock us. Replace GC_INTERNAL_MALLOC with GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE as we don't need the rest of the GC messing around with the toggleref array.
* Add toggle-ref supportRodrigo Kumpera2015-08-261-0/+154
| | | | | | | | | | | | | | | | (Apply commit af75406 from 'mono_libgc' branch.) GC backed toggleref machinery. This enables an embedder to support toggleref style of external memory management without hooking up to the host retain/release machinery. The API export two entry points. The first let the caller register a callback that decides the state of a given object, by probably inspecting its native state. The second allows registration of objects with the toggleref machinery. The idea of toggleref is that we keep an external reference to an object and it can be either a strong or weak reference. We use a weak reference when the external peer has no interest into the object and a strong otherwise.
* Mark fo_head, finalize_now with a single GC_push_all callIvan Maidanski2015-08-261-51/+52
| | | | | | | | | | | | | | | | | (code refactoring) * finalize.c (GC_fnlz_roots): New static variable. * finalize.c (GC_fo_head, GC_finalize_now): Move into GC_fnlz_roots (remove "GC_" prefix for field names). * finalize.c (GC_push_finalizer_structures): Replace GC_ASSERT and GC_PUSH_ALL_SYM for GC_fo_head, GC_finalize_now with a single GC_ASSERT and GC_PUSH_ALL_SYM for GC_fnlz_roots. * finalize.c (GC_register_finalizer_inner, GC_register_finalizer_unreachable, GC_finalize, GC_should_invoke_finalizers, GC_invoke_finalizers, GC_notify_or_invoke_finalizers): Replace access to GC_fo_head, GC_finalize_now with access to the corresponding field of GC_fnlz_roots.
* Code refactoring of GC_push_finalizer/thread/typed_structuresIvan Maidanski2015-08-261-12/+7
| | | | | | | | | | * finalize.c (GC_push_finalizer_structures): Replace GC_push_all with GC_PUSH_ALL_SYM invocation. * pthread_support.c (GC_push_thread_structures): Likewise. * typd_mlc.c (GC_push_typed_structures_proc): Likewise. * win32_threads.c (GC_push_thread_structures): Likewise. * include/private/gc_priv.h (GC_PUSH_ALL_SYM): New macro (handy one to push a symbol content).
* Fix exporting of GC_push_finalizer_structuresIvan Maidanski2015-08-071-1/+1
| | | | | * finalize.c (GC_push_finalizer_structures): Use GC_API, GC_CALL instead of GC_INNER (to match that of gc_mark.h).
* Distinct long-link table growth log messageIvan Maidanski2015-08-051-4/+6
| | | | | | | | * finalize.c (GC_register_disappearing_link_inner): Add tbl_log_name argument and pass it to GC_COND_LOG_PRINTF (instead of "dl" name). * finalize.c (GC_general_register_disappearing_link, GC_register_long_link): Pass corresponding link hashtable short name ("dl" or "long dl") to GC_register_disappearing_link_inner.
* Replace non-API occurrences of GC_word to wordIvan Maidanski2015-07-281-1/+1
| | | | | | | | | | | | | | | | (code refactoring) * finalize.c (last_finalizer_notification): Use "word" type instead of GC_word. * include/private/dbg_mlc.h (HIDE_BACK_PTR): Likewise. * include/private/gc_priv.h (WARN): Likewise. * include/private/gcconfig.h (POINTER_MASK): Likewise. * mark.c (GC_push_marked): Likewise. * misc.c (GC_init, GC_set_max_retries): Likewise. * os_dep.c (GC_unmap, GC_remap, GC_unmap_gap): Likewise. * typd_mlc.c (GC_add_ext_descriptor): Likewise. * include/private/gcconfig.h (GC_amiga_get_mem, ps3_get_mem): Rename argument to bytes.
* Code refactoring of 'finalization extension API'Ivan Maidanski2015-07-191-7/+20
| | | | | | | | | | | | | | | | | | * finalize.c (GC_object_finalized_proc, GC_set_finalizer_notify_proc): Use GC_await_finalize_proc type. * finalize.c (GC_object_finalized_proc): Use STATIC instead of "static". * finalize.c (GC_set_finalizer_notify_proc): Rename to GC_set_await_finalize_proc. * include/gc.h (GC_set_finalizer_notify_proc): Likewise. * finalize.c (GC_set_await_finalize_proc): Add LOCK/UNLOCK. * finalize.c (GC_set_await_finalize_proc): Decorate with GC_CALL. * include/gc.h (GC_set_await_finalize_proc): Likewise. * finalize.c (GC_get_await_finalize_proc): New API function. * include/gc.h (GC_await_finalize_proc): New type. * include/gc.h (GC_set_await_finalize_proc): Document. * include/gc.h (GC_get_await_finalize_proc): New API function declaration.
* Implement the finalization extension APIRodrigo Kumpera2015-07-171-0/+13
| | | | | | | | | (Apply commit c429e9f from 'mono_libgc' branch.) Conflicts: finalize.c include/gc.h
* Fix typos in commentsOndrej Bilka2013-07-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | * blacklst.c: Fix typo ("even though"). * cord/cordbscs.c: Fix typo ("exponentially"). * cord/cordxtra.c: Fix typo ("represented"). * dyn_load.c: Fix typos ("uncollectible", "occurred"). * extra/AmigaOS: Fix typos ("specific", "necessary", "always", "effectiveness"). * finalize.c: Fix typo ("descendants"). * include/cord.h: Fix typo ("idiosyncrasies"). * include/gc.h: Fix typo ("collectible"). * include/gc_allocator.h: Fix typos ("allocator", "[un]collectible"). * mach_dep.c: Fix typo ("erroneously"). * malloc.c: Fix typos ("[un]collectible", "pointer-free", "initialization"). * mallocx.c: Fix typos ("largely", "pointer-free", "uncollectible"). * mark.c: Fix typos ("[un]collectible", "even though"). * misc.c: Fix typo ("erroneously"). * os_dep.c: Fix typos ("non-addressable", "happening", "pointer-free"). * tests/test.c: Fix typos ("uncollectible", "reversed"). * tests/test_cpp.cc: Fix typos ("[un]collectible"). * typd_mlc.c: Fix typo ("copyright"). * win32_threads.c: Fix typos ("optimization", "uncollectible").
* Replace '`' symbol with double-quote in commentsIvan Maidanski2012-12-151-1/+1
| | | | | | | | | * doc/README.win32: Replace "`" symbol (and paring single-quote) with double-quote symbol. * dyn_load.c (GC_register_dynlib_callback): Likewise. * finalize.c (GC_should_invoke_finalizers): Likewise. * include/private/gc_priv (GC_INLINE, ptr_t): Likewise. * include/private/gcconfig.h (DATAEND): Likewise.
* Replace GC_stats_log_printf with GC_DBG/INFOLOG_PRINTFIvan Maidanski2012-12-121-10/+10
| | | | | | | | | | | | | | | | | | | | | | | (minimize logging for Android when print_stats is off) * alloc.c (GC_try_to_collect_inner, GC_stopped_mark, GC_finish_collection): Use GC_log_printf instead of GC_stats_log_printf. * finalize.c (GC_print_finalization_stats): Likewise. * include/private/gc_priv.h (GC_COND_LOG_PRINTF): Likewise. * alloc.c (GC_stopped_mark): Use GC_DBGLOG_PRINTF instead of GC_COND_LOG_PRINTF (useful for Android). * alloc.c (GC_expand_hp_inner): Reformat comment. * alloc.c (GC_expand_hp_inner): Use GC_INFOLOG_PRINTF instead of GC_COND_LOG_PRINTF (useful for Android). * include/private/gc_priv.h (GC_stats_log_printf): Remove (macro and prototype). * include/private/gc_priv.h (GC_DBGLOG_PRINTF, GC_INFOLOG_PRINTF): New macro (redirecting either to GC_COND_LOG_PRINTF or to GC_log_printf/GC_info_log_printf if GC_ANDROID_LOG). * include/private/gc_priv.h (GC_info_log_printf): New prototype (only if GC_ANDROID_LOG). * misc.c (GC_stats_log_printf): Rename to GC_info_log_printf.
* Merge branch 'master' into add-long-weakrefadd-long-weakrefIvan Maidanski2012-12-091-10/+10
|\ | | | | | | | | Conflicts: finalize.c
| * Call GC_stats/verbose_log_printf instead of GC_log_printf if print_statsIvan Maidanski2012-11-151-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (code refactoring) * alloc.c (GC_try_to_collect_inner, GC_stopped_mark, GC_finish_collection): Use GC_stats_log_printf instead of GC_log_printf inside "if (GC_print_stats)" blocks. * include/private/gc_priv.h (GC_COND_LOG_PRINTF): Likewise. * finalize.c (GC_print_finalization_stats): Use GC_stats_log_printf instead of GC_log_printf (since the function is invoked only inside "if (GC_print_stats)" blocks). * include/private/gc_priv.h (GC_printf, GC_log_printf): Refine comment. * include/private/gc_priv.h (GC_stats_log_printf, GC_verbose_log_printf): New macro (redirected to GC_log_printf). * reclaim.c (GC_reclaim_all): Use GC_verbose_log_printf instead of GC_log_printf inside "if (GC_print_stats==VERBOSE)" blocks. * include/private/gc_priv.h (GC_COND_LOG_PRINTF): Likewise. * misc.c (GC_LOG_PRINTF_IMPL): New macro (only if GC_ANDROID_LOG, copy most code from GC_log_printf). * misc.c (GC_log_printf): Define separately for Android using GC_LOG_PRINTF_IMPL macro (only if GC_ANDROID_LOG).
* | Minor code refactoring of dumping routines related to 'long' linksIvan Maidanski2012-11-241-60/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * finalize.c (struct disappearing_link): Remove STATIC. * finalize.c (GC_dl_hashtbl, GC_ll_hashtbl): Define separately from dl_hashtbl_s definition. * finalize.c (GC_grow_table): Reformat comment. * finalize.c (GC_dump_finalization_links): Pass 'dl_hashtbl' argument as pointer to constant struct. * finalize.c (GC_dump_finalization_links, GC_dump_finalization): Adjust printed message. * finalize.c (GC_old_ll_entries): Do not define if GC_LONG_REFS_NOT_NEEDED. * finalize.c (IF_LONG_REFS_PRESENT_ELSE): New macro (only if not SMALL_CONFIG). * finalize.c (GC_print_finalization_stats): Use IF_LONG_REFS_PRESENT_ELSE (instead of testing GC_LONG_REFS_NOT_NEEDED); make printed messages more compact.
* | Added GC_LONG_REFS_NOT_NEEDED ifdefs to exclude long linkZach Saw2012-11-201-32/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | functionality and other minor changes. * finalize.c (GC_push_finalizer_structures, GC_register_long_link, GC_unregister_long_link, GC_move_long_link, GC_finalize): GC_LONG_REFS_NOT_NEEDED ifdefs to exclude long link functionality. * finalize.c (GC_dump_finalization_links, GC_register_disappearing_link_inner, GC_move_disappearing_link_inner): Changed from GC_INLINE to STATIC function declaration. * include/gc.h: use 2 spaces as a sentence delimiter in comment added in previous commit.
* | Added long weakref support.Zach Saw2012-11-191-16/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * include/gc.h: Added 3 GC_API functions for long weakref support: GC_register_long_link, GC_unregister_long_link and GC_move_long_link. * include/gc.h: Added corresponding GC_REGISTER_LONG_LINK macros. * finalize.c: Add implementation of the above functions, GC_ll_hashtbl for long links and GC_old_ll_entries. * finalize.c (GC_push_finalizer_structures): GC_push_all long link hash table entries as well. * finalize.c (GC_dump_finalization): Refactored dump disappearing link code out to GC_dump_finalization_links accepting an argument of pointer to struct dl_hashtbl_s. * finalize.c (GC_print_finalization_stats): Added long link stats print out. * finalize.c (GC_finalize): Added saving current GC_ll_hashtbl entry count to GC_old_ll_entries, GC_make_disappearing_links_disappear and GC_remove_dangling_disappearing_links for long links.
* | Move LOCK/UNLOCK from GC_unregister_disappearing_link_inner outerIvan Maidanski2012-11-171-15/+20
| | | | | | | | | | | | | | | | | | | | * finalize.c (GC_unregister_disappearing_link_inner): Add comment; change return type (return entry of unregistered linked or NULL); do not check link alignment; do not acquire the lock and do not free the unregistered entry. * finalize.c (GC_unregister_disappearing_link): Check link alignment, invoke GC_unregister_disappearing_link_inner holding the allocation lock and free found entry (if any).