summaryrefslogtreecommitdiff
path: root/win32_threads.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Prevent changing of GC_markers_m1 value while collection in progressIvan Maidanski2022-05-191-0/+3
| | | | | | | | | | | | | | | | | | | | GC_markers_m1 (GC_parallel) value affects some logic in the garbage collector, e.g. GC_clear_fl_marks, so it would be safer to wait for any ongoing collection before proceeding with marker threads creation (in the child). * pthread_support.c [PARALLEL_MARK && CAN_HANDLE_FORK] (GC_wait_for_gc_completion): Declare (before GC_start_mark_threads_inner). * pthread_support.c [PARALLEL_MARK] (GC_start_mark_threads_inner): Add assertion that cancellation is disabled. * win32_threads.c [PARALLEL_MARK] (GC_start_mark_threads_inner): Likewise. * pthread_support.c [PARALLEL_MARK && CAN_HANDLE_FORK] (GC_start_mark_threads_inner): Call GC_wait_for_gc_completion(TRUE) before initialization of mark_cv. * win32_threads.c [PARALLEL_MARK && GC_PTHREADS_PARAMARK && CAN_HANDLE_FORK] (GC_start_mark_threads_inner): Likewise.
* Fix potential race if start_mark_threads called from threads in childIvan Maidanski2022-05-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | There should be no race in setting GC_markers_m1 value even in case of a client calls GC_start_mark_threads() from multiple threads in a child process. * include/gc/gc.h (GC_start_mark_threads): Add comment that the allocation lock is acquired internally. * mark.c [PARALLEL_MARK] (GC_wait_for_markers_init): Change assertion from I_DONT_HOLD_LOCK to I_HOLD_LOCK. * pthread_support.c [PARALLEL_MARK] (GC_start_mark_threads_inner): Likewise. * win32_threads.c [PARALLEL_MARK] (GC_start_mark_threads_inner): Likewise. * mark.c [PARALLEL_MARK] (GC_wait_for_markers_init): Remove LOCK/UNLOCK around GC_add_to_our_memory() call. * misc.c [PARALLEL_MARK && GC_ASSERTIONS && GC_ALWAYS_MULTITHREADED] (GC_init): Remove UNLOCK/LOCK around GC_start_mark_threads_inner call. * misc.c [THREADS && PARALLEL_MARK && CAN_HANDLE_FORK && !THREAD_SANITIZER] (GC_start_mark_threads): Wrap GC_start_mark_threads_inner() call into LOCK/UNLOCK.
* Replace comments about GC is held or not with relevant assertionsIvan Maidanski2022-05-111-15/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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.
* Eliminate 'GC_reset_finalizer_nested defined but not used' compiler warningIvan Maidanski2022-04-221-31/+32
| | | | | | | | | | | | | | | | | | (fix of commit c14335e44) * include/private/gc_priv.h [THREADS] (GC_reset_finalizer_nested, GC_check_finalizer_nested): Do not declare if GC_NO_FINALIZATION. * include/private/pthread_support.h (GC_Thread_Rep.finalizer_skipped, GC_Thread_Rep.finalizer_nested): Do not declare field if GC_NO_FINALIZATION. * win32_threads.c (GC_Thread_Rep.finalizer_skipped, GC_Thread_Rep.finalizer_nested): Likewise. * pthread_support.c (GC_reset_finalizer_nested, GC_check_finalizer_nested): Do not define if GC_NO_FINALIZATION. * win32_threads.c (GC_reset_finalizer_nested, GC_check_finalizer_nested): Likewise. * win32_threads.c (GC_check_finalizer_nested): Remove comment copied from pthread_support.c.
* Fix assertion violation of GC_thread_key alignment if pthread-based TLSIvan Maidanski2022-03-171-1/+1
| | | | | | | | | | | | | | | | (fix of commit d692eb432) It is needed to push GC_thread_key only in case of USE_CUSTOM_SPECIFIC; it could have any alignment otherwise (e.g., if it is of pthread_key_t type). * thread_support.c [THREAD_LOCAL_ALLOC] (GC_push_thread_structures): Push GC_thread_key only if USE_CUSTOM_SPECIFIC. * win32_threads.c [THREAD_LOCAL_ALLOC] (GC_push_thread_structures): Likewise. * thread_local_alloc.c [THREAD_LOCAL_ALLOC] (GC_init_thread_local): Do not assert GC_thread_key is word-aligned unless USE_CUSTOM_SPECIFIC; add comment.
* Fix parallel_initialized assertion violation in initsecondarythread (Win32)Ivan Maidanski2021-12-251-1/+1
| | | | | | * win32_threads.c [!GC_PTHREADS && !GC_NO_THREADS_DISCOVERY] (GC_DllMain): Do not assert parallel_initialized unless GC_win32_dll_threads on DLL_THREAD_DETACH.
* Eliminate 'old_gc_no is initialized but not referenced' MS VC false warningIvan Maidanski2021-12-241-0/+4
| | | | | * win32_threads.c [GC_DISABLE_INCREMENTAL] (GC_wait_for_gc_completion): Define as no-op macro (instead of a static function).
* Fix 'unresolved symbol GetModuleHandle' error in win32_threads.c (UWP)Ivan Maidanski2021-11-141-1/+11
| | | | | | | | | | | | (fix of commit 9d869bcd9) Issue #300 (bdwgc). * win32_threads.c [(!HAVE_PTHREAD_SETNAME_NP_WITH_TID && !MSWINCE && PARALLEL_MARK || WOW64_THREAD_CONTEXT_WORKAROUND) && MSWINRT_FLAVOR] (GC_thr_init): Do not call GetModuleHandle; set hK32 to memInfo.AllocationBase where memInfo is result of VirtualQuery(GetProcAddress).
* Define marker_[b]sp only if neededIvan Maidanski2021-10-141-6/+0
| | | | | | | | | | | | | | | | | | (refactoring) * pthread_support.c [PARALLEL_MARK] (marker_sp): Define only if USE_PROC_FOR_LIBRARIES or IA64 and (HAVE_PTHREAD_ATTR_GET_NP or HAVE_PTHREAD_GETATTR_NP). * pthread_support.c [PARALLEL_MARK && IA64] (marker_bsp): Define only if USE_PROC_FOR_LIBRARIES. * pthread_support.c [PARALLEL_MARK] (GC_mark_thread): Do not set marker_sp unless the variable is defined. * pthread_support.c [PARALLEL_MARK && IA64] (GC_mark_thread): Do not set marker_bsp unless USE_PROC_FOR_LIBRARIES. * win32_threads.c [PARALLEL_MARK && IA64] (marker_bsp): Remove static variable. * win32_threads.c [PARALLEL_MARK && IA64] (GC_mark_thread): Do not set marker_bsp.
* Print thread number on marker thread creation failureIvan Maidanski2021-10-021-5/+5
| | | | | | | | | | | * pthread_support.c [PARALLEL_MARK && DEBUG_THREADS] (GC_mark_thread): Print mark thread number. * win32_threads.c [PARALLEL_MARK && DEBUG_THREADS] (GC_mark_thread): Likewise. * pthread_support.c [PARALLEL_MARK] (GC_start_mark_threads_inner): Print mark thread number in WARN message (if failed to create thread). * win32_threads.c [PARALLEL_MARK] (GC_start_mark_threads_inner): Likewise.
* Adjust spaces around '=' in printed messagesIvan Maidanski2021-09-151-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * checksums.c (GC_check_blocks): Remove space before '=' and add a space (if missing) after '=' in printed message. * darwin_stop_world.c [DEBUG_THREADS_EXTRA] (GC_FindTopOfStack): Likewise. * dbg_mlc.c (GC_print_obj, GC_debug_print_heap_obj_proc): Likewise. * dyn_load.c [IRIX5 || USE_PROC_FOR_LIBRARIES && !LINUX || HPUX] (GC_register_dynamic_libraries): Likewise. [DEBUG_VIRTUALQUERY] (GC_dump_meminfo): Likewise. * os_dep.c [NEED_PROC_MAPS] (GC_get_maps): Likewise. * os_dep.c [PROC_VDB] (GC_proc_read_dirty): Likewise. * os_dep.c [SOFT_VDB] (soft_read_dirty): Likewise. * pthread_support.c (set_marker_thread_name, GC_start_mark_threads_inner): Likewise. * pthread_support.c [DEBUG_THREADS] (GC_delete_thread, GC_unregister_my_thread_inner, GC_unregister_my_thread, GC_thread_exit_proc, GC_start_rtn_prepare_thread): Likewise. * pthread_support.c [GC_LINUX_THREADS] (GC_get_nprocs): Likewise. * tests/disclaim_weakmap_test.c [DEBUG_DISCLAIM_WEAKMAP] (weakmap_add, weakmap_disclaim): Likewise. * tests/subthread_create.c (run_one_test): Likewise. * win32_threads.c (GC_delete_thread, GC_push_stack_for, GC_get_next_stack): Likewise. * darwin_stop_world.c [DEBUG_THREADS] (GC_stack_range_for): Remove '=' in printed message and/or improve message. * mark.c (GC_signal_mark_stack_overflow): Likewise. * mark_rts.c [!NO_DEBUGGING] (GC_print_static_roots): Likewise. * pthread_stop_world.c [DEBUG_THREADS] (GC_push_all_stacks, GC_suspend_all): Likewise. * pthread_support.c (GC_thr_init): Likewise. * tests/disclaim_test.c (pair_dct, pair_new): Likewise. * tests/disclaim_weakmap_test.c (pair_check_rec): Likewise. * tests/initsecondarythread.c (main): Likewise. * tests/subthread_create.c (entry, main): Likewise. * tests/test.c [THREADS] (fork_a_thread, main): Likewise. * tests/test.c [MSWINCE] (thr_window): Likewise. * tests/test.c [NTHREADS>0] (main): Likewise. * tests/threadkey_test.c (main): Likewise. * dyn_load.c [ALPHA && OSF1 && DL_VERBOSE] (GC_register_dynamic_libraries): Reformat printed messages. * tests/disclaim_test.c (main): Remove space after '#' in printed message.
* Update copyright information in alloc.c and other modified files (2021)Ivan Maidanski2021-09-091-1/+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 'retry_cnt is assigned value but never used' cppcheck FPIvan Maidanski2021-08-301-5/+5
| | | | | | | | * win32_threads.c [RETRY_GET_THREAD_CONTEXT] (MAX_SUSPEND_THREAD_RETRIES): Define only unless MSWINCE. * win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_suspend): Declare retry_cnt local variable only unless MSWINCE; move its initialization to for statement.
* New API (GC_set_markers_count) to control number of parallel markersIvan Maidanski2020-08-131-2/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Issue #320 (bdwgc). Note that GC_set_markers_count() has effect only if called before GC initialization. For convenience, alternatively the client could define GC_MARKERS macro with the appropriate value before include of gc.h. * doc/README.macros (GC_MARKERS): Document. * include/gc.h [GC_THREADS] (GC_parallel): Update comment. * include/gc.h [GC_THREADS] (GC_set_markers_count): New API function declaration. * include/gc.h (GC_INIT_CONF_MARKERS): New internal macro (defined to GC_set_markers_count(GC_MARKERS) if GC_THREADS and GC_MARKERS are defined). * include/gc.h (GC_INIT): Call GC_INIT_CONF_MARKERS before GC_init. * pthread_support.c [PARALLEL_MARK] (required_markers_cnt): New static variable (initialized to 0). * win32_threads.c [PARALLEL_MARK] (required_markers_cnt): Likewise. * pthread_support.c (GC_set_markers_count): New API function definition (empty unless PARALLEL_MARK). * win32_threads.c [PARALLEL_MARK] (GC_set_markers_count): Likewise. * pthread_support.c [PARALLEL_MARK] (GC_thr_init): Initialize markers local variable to required_markers_cnt; set markers to GC_nprocs only if markers_string is null and required_markers_cnt (markers) value is zero. * tests/test.c [GC_PTHREADS] (main): Call GC_set_markers_count(0) before GC_COND_INIT(). * win32_threads.c [PARALLEL_MARK] (GC_thr_init): Initialize markers local variable to required_markers_cnt; set markers to ncpu only if markers_string is null and required_markers_cnt (markers) value is 0.
* Update copyright information in alloc.c and other modified files (2020)Ivan Maidanski2020-08-011-0/+1
| | | | | | | | | | | | | | | | | * README.QUICK (Copyright): Update year (2019 to 2020). * README.md (Copyright): Likewise. * alloc.c (Copyright, GC_copyright): Likewise. * gc_badalc.cc (Copyright): Likewise. * include/gc.h (Copyright): Likewise. * finalize.c (Copyright): Update (add Ivan Maidanski). * include/gc_config_macros.h (Copyright): Likewise. * include/private/gc_priv.h (Copyright): Likewise. * mark.c (Copyright): Likewise. * misc.c (Copyright): Likewise. * os_dep.c (Copyright): Likewise. * pthread_stop_world.c (Copyright): Likewise. * pthread_support.c (Copyright): Likewise. * win32_threads.c (Copyright): Likewise.
* Eliminate 'cast between incompatible func types' warnings for FARPROC varsIvan Maidanski2020-04-191-3/+3
| | | | | | | | | | | | | | | | | | | | | Direct conversion of GetProcAddress() result (of FARPROC type) to the required functional type is performed by casting the result to word type first. * misc.c [MSGBOX_ON_ERROR && DONT_USE_USER32_DLL] (GC_win32_MessageBoxA): Cast pfn to word type first. * win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND] (GC_thr_init): Likewise. * misc.c [GC_WIN32_THREADS && !GC_PTHREADS && !MSWINRT_FLAVOR && !MSWINCE] (GC_init): Change pfn type to FARPROC; cast pfn to word type first and, then, to the required functional type. * os_dep.c [!OS2 && GWW_VDB] (GetWriteWatch_func): Change type to FARPROC. * os_dep.c [!OS2 && GWW_VDB] (GC_GWW_AVAILABLE): Compare GetWriteWatch_func to 0 instead of NULL. * os_dep.c [GWW_VDB] (detect_GetWriteWatch, GC_gww_read_dirty): Cast GetWriteWatch_func to word type first and, then, to the required functional type.
* Eliminate 'cast between incompatible function types' gcc-8 warning (Win64)Ivan Maidanski2020-02-131-1/+3
| | | | | | | | | | (fix of commit 9d869bcd9) Issue #300 (bdwgc). * win32_threads.c [!(GC_PTHREADS && HAVE_PTHREAD_SETNAME_NP_WITH_TID) && !MSWINCE] (set_marker_thread_name): Cast setThreadDescription_fn to word type first; add comment.
* Revert 'Call GC_thr_init only once'Ivan Maidanski2020-02-111-1/+2
| | | | | | This reverts commit 03a3fbbdd5cff52360facdfcc9f86adbdc111245. GC_thr_initialized is a static variable on Windows.
* Implement set_marker_thread_name on Windows 10Ivan Maidanski2020-02-111-4/+36
| | | | | | | | | | | | | | | | | | | Issue #300 (bdwgc). Call SetThreadDescription() if available. * win32_threads.c [HAVE_PTHREAD_SETNAME_NP_WITH_TID] (set_marker_thread_name): No-op unless GC_PTHREADS is defined. * win32_threads.c [!(GC_PTHREADS && HAVE_PTHREAD_SETNAME_NP_WITH_TID) && !MSWINCE] (setThreadDescription_fn): New static variable. * win32_threads.c [!(GC_PTHREADS && HAVE_PTHREAD_SETNAME_NP_WITH_TID) && !MSWINCE] (set_marker_thread_name): Compose thread name into WCHAR buffer; call setThreadDescription_fn if non-null. * win32_threads.c [(!HAVE_PTHREAD_SETNAME_NP_WITH_TID && !MSWINCE && PARALLEL_MARK) || WOW64_THREAD_CONTEXT_WORKAROUND] (GC_thr_init): Declare and set hK32 local variable at the beginning of the function. * win32_threads.c [PARALLEL_MARK && !HAVE_PTHREAD_SETNAME_NP_WITH_TID && !MSWINCE] (GC_thr_init): Set setThreadDescription_fn.
* Call GC_thr_init only onceIvan Maidanski2020-02-111-2/+1
| | | | | | | | | | | | | (code refactoring) GC_thr_init() is now called only if GC_thr_initialized; "if(GC_thr_initialized)return" statement is removed from GC_thr_init. * misc.c [GC_PTHREADS || GC_WIN32_THREADS] (GC_init): Do not call GC_thr_init() if GC_thr_initialized. * pthread_support.c (GC_thr_init): Remove return if GC_thr_initialized; add GC_ASSERT that GC_thr_initialized is false. * win32_threads.c (GC_thr_init): Likewise.
* Fix pthread_setname_np detection on Linux and snprintf usage warningIvan Maidanski2020-02-071-7/+12
| | | | | | | | | | | | | | | (fix of commit ab91e4e84) Issue #300 (bdwgc). * configure.ac [$THREADS==posix]: Replace AC_TRY_LINK with AC_TRY_COMPILE to detect pthread_setname_np presence and kind. * pthread_support.c [PARALLEL_MARK && (HAVE_PTHREAD_SETNAME_NP_WITH_TID || HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID)] (set_marker_thread_name): Replace snprintf() with BCOPY() call and manual conversion of an integer (with 1-2 digits) to a string; remove undef name_buf. * win32_threads.c [PARALLEL_MARK && HAVE_PTHREAD_SETNAME_NP_WITH_TID] (set_marker_thread_name): Likewise.
* Set name of GC marker threadsIvan Maidanski2020-02-061-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | Issue #300 (bdwgc). The threads are named as "GC-marker-<n>". For now, the detection of pthread_setname_np availability and kind is implemented in configure only. On Darwin, the GC mprotect thread name is set too. * configure.ac [$THREADS==posix] (HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID, HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG, HAVE_PTHREAD_SETNAME_NP_WITH_TID): Check for pthread_setname_np; set the relevant HAVE_x macro. * include/private/gc_priv.h [__CYGWIN__ && GC_THREADS && !_GNU_SOURCE] (_GNU_SOURCE): Define. * os_dep.c [MPROTECT_VDB && DARWIN && HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID] (GC_mprotect_thread): Call pthread_setname_np(). * pthread_support.c [PARALLEL_MARK] (set_marker_thread_name): Define. * win32_threads.c [PARALLEL_MARK] (set_marker_thread_name): Likewise. * pthread_support.c [PARALLEL_MARK] (GC_mark_thread): Call set_marker_thread_name(id). * win32_threads.c [PARALLEL_MARK] (GC_mark_thread): Likewise.
* Check thread is alive on each SuspendThread loop iteration (Win32)Ivan Maidanski2019-10-041-21/+32
| | | | | | | | | | | | (fix of commit 449eda034) * win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_delete_gc_thread_no_free): Reset suspended if GC_win32_dll_threads. * win32_threads.c [!MSWINCE] (GC_suspend): Move comment near exitCode declaration to be near GetExitCodeThread() call; adjust comment. * win32_threads.c [!MSWINCE && RETRY_GET_THREAD_CONTEXT] (GC_suspend): Call GetExitCodeThread() on each iteration of the suspend loop; refine ABORT message on ResumeThread failure.
* Do not hold GC_fault_handler_lock when in Sleep (Win32)Ivan Maidanski2019-10-041-6/+15
| | | | | | | | | | | | | | (fix of commits 0c0e4cd0b, 449eda034) Also, reduce a period between GetExitCodeThread and SuspendThread. * win32_threads.c [DEBUG_THREADS] (GC_suspend): Call GC_log_printf() before UNPROTECT_THREAD(). * win32_threads.c [DEBUG_THREADS && !MSWINCE] (GC_suspend): Call GC_acquire_dirty_lock() before GetExitCodeThread(); call GC_release_dirty_lock() immediately if GetExitCodeThread() failed. * win32_threads.c [MSWINCE || RETRY_GET_THREAD_CONTEXT] (GC_suspend): Wrap Sleep() call with GC_release/acquire_dirty_lock().
* Prevent use of unsaved thread context registers in incremental GC (Windows)Ivan Maidanski2019-09-251-10/+31
| | | | | | | | | | | | | | | | | | | | | | | | | (fix of commits 449eda034, 190e18c75) During incremental collection GC_push_all_stacks() may be called when the world is not stopped. If the context registers and sp value are saved during thread suspension then GC_push_all_stacks() gets these values of the previous GC cycle or, even, gets all zeros instead the context registers and sp on the first GC after the thread creation. This commit fixes this by calling GetThreadContext in GC_push_stack_for if thread is not suspended. * win32_threads.c (first_thread): Refine the comment. * win32_threads.c [!GC_NO_THREADS_DISCOVERY && RETRY_GET_THREAD_CONTEXT] (GC_delete_gc_thread_no_free): Reset context_sp if GC_win32_dll_threads. * win32_threads.c (GC_push_stack_for): Change the assertion expression from thread->suspended to thread->suspended||!GC_world_stopped (the assertion is off unless THREAD_LOCAL_ALLOC). * win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_push_stack_for): If thread is not suspended then call GetThreadContext(), if it fails then use sp value and the context registers saved during the latest stop-the-world; add comments. * win32_threads.c (GC_push_all_stacks): Add the title comment (copied from pthread_stop_world.c).
* Add assertion that thread is suspended when using context registersIvan Maidanski2019-09-161-0/+2
| | | | | | * win32_threads.c (GC_push_stack_for): Add assertion that thread is suspended (before using context registers) if thread is not self and not blocked.
* Add debug messages on thread suspend/resume (Win32)Ivan Maidanski2019-09-161-0/+15
| | | | | | | | | | The messages are similar to the ones for Darwin. * win32_threads.c [DEBUG_THREADS] (GC_suspend): Log a message that the thread is going to be suspended. * win32_threads.c [DEBUG_THREADS] (GC_start_world): Log a message whether the thread is going to be resumed or it cannot be resumed because it is not suspended.
* Collapse multiple includes of windows.hIvan Maidanski2019-09-141-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | (code refactoring) * dyn_load.c [MSWIN32 || MSWINCE || CYGWIN32]: Do not define WIN32_LEAN_AND_MEAN and NOSERVICE macros; do not include windows.h. * include/private/gc_locks.h [GC_WIN32_THREADS && !USE_PTHREAD_LOCKS]: Likewise. * include/private/gc_priv.h [!NO_CLOCK && !BSD_TIME && (MSWIN32 || MSWINCE || WINXP_USE_PERF_COUNTER)]: Likewise. * include/private/thread_local_alloc.h [!USE_PTHREAD_SPECIFIC && !USE_COMPILER_TLS && !USE_WIN32_COMPILER_TLS && USE_WIN32_SPECIFIC]: Likewise. * mallocx.c [MSWINCE]: Likewise. * misc.c [MSWIN32 || MSWINCE || CYGWIN32 && GC_READ_ENV_FILE]: Likewise. * os_dep.c [MSWIN32 || MSWINCE || CYGWIN32]: Likewise. * tests/test.c [MSWIN32 || MSWINCE]: Likewise. * tools/setjmp_t.c [!OS2 && (MSWIN32 || MSWINCE || CYGWIN32)]: Likewise. * win32_threads.c [GC_WIN32_THREADS]: Likewise. * include/private/gc_priv.h [MSWIN32 || MSWINCE || CYGWIN32] (WIN32_LEAN_AND_MEAN, NOSERVICE): Define macro (before include windows.h). * include/private/gc_priv.h [MSWIN32 || MSWINCE || CYGWIN32]: Inclde windows.h and winbase.h before include gc_locks.h (instead of just before GC_sysinfo declaration).
* New macro (CONSOLE_LOG) to enable logging to console on Win32Ivan Maidanski2019-09-121-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The macro is effective only on the Win32 (MSWIN32) target. It changes the logging facility to be the same as on Cygwin and other Unix-like targets. * doc/README.macros (CONSOLE_LOG): Document new macro. * include/private/gc_priv.h [THREADS && MSWIN32 && CONSOLE_LOG] (GC_write_cs): Do not declare. * include/private/gc_priv.h [THREADS && MSWIN32 && CONSOLE_LOG && GC_ASSERTIONS] (GC_write_disabled): Likewise. * misc.c [CONSOLE_LOG && MSWIN32]: Include fcntl.h, sys/types.h, sys/stat.h. * misc.c [GC_WIN32_THREADS && MSWIN32 && CONSOLE_LOG] (GC_write_cs): Do not define. * win32_threads.c [GC_ASSERTIONS && MSWIN32 && CONSOLE_LOG] (GC_write_disabled): Likewise. * misc.c [MSWIN32 && CONSOLE_LOG] (GC_stdout, GC_stderr, GC_log): Define STATIC variable (of int type). * misc.c [GC_WIN32_THREADS && MSWIN32 && CONSOLE_LOG] (GC_init): Do not call InitializeCriticalSection(&GC_write_cs); handle GC_LOG_FILE and GC_ONLY_LOG_TO_FILE environment variables. * misc.c [GC_WIN32_THREADS && MSWIN32 && CONSOLE_LOG] (GC_deinit): Do not call DeleteCriticalSection(&GC_write_cs). * misc.c [MSWIN32 && CONSOLE_LOG] (IF_NEED_TO_LOCK, getWinRTLogPath, GC_CreateLogFile): Do not define. * misc.c [!PCR && !SMALL_CONFIG && !GC_ANDROID_LOG && GC_WIN32_THREADS && GC_ASSERTIONS MSWIN32 && CONSOLE_LOG] (GC_default_on_abort): Do not use GC_write_disabled. * win32_threads.c [MSWIN32 && CONSOLE_LOG] (GC_stop_world): Do not use GC_write_disabled and GC_write_cs.
* Do not define GC_write_cs for Xbox One targetIvan Maidanski2019-09-111-11/+9
| | | | | | | | | | | | | | | (fix of commit d16debf3e) Issue #173 (bdwgc). GC_write_cs is not used in GC_write thus there is no need to define and use it in GC_stop_world. * include/private/gc_priv.h [THREADS && MSWIN_XBOX1] (GC_write_cs): Do not declare. * misc.c [THREADS && MSWIN_XBOX1] (GC_write_cs): Do not define. * win32_threads.c (GC_stop_world): Call EnterCriticalSection() and LeaveCriticalSection() only if MSWIN32 or MSWINCE.
* Workaround 'cnt var assigned but not used' cppcheck FP in copy_ptr_regsIvan Maidanski2019-09-101-1/+3
| | | | | | | | (fix of commit 912ec408d) * win32_threads.c [!I386 && !X86_64 && !ARM32 && !AARCH64 && !SHx && !MIPS && !PPC && !ALPHA && CPPCHECK] (copy_ptr_regs): Set sp to cnt value (with a cast); add comment.
* Replace push_one calls with push_many_regs one for Win32 thread contextIvan Maidanski2019-09-101-7/+5
| | | | | | | | | | | | | | | | | | | | (code refactoring) Also, do not define GC_push_one except for Darwin (and some ancient targets that use the function). * include/private/gc_priv.h [MSWIN32 || MSWINCE] (GC_push_one): Do not declare. * include/private/gc_priv.h [!MSWIN32 && !MSWINCE] (GC_push_one): Declare only if AMIGA or MACOS or GC_DARWIN_THREADS. * include/private/gc_priv.h [GC_WIN32_THREADS] (GC_push_many_regs): Declare function; add comment. * mark.c (GC_push_one): Define only if AMIGA or MACOS or GC_DARWIN_THREADS. * mark.c [GC_WIN32_THREADS] (GC_push_many_regs): New GC_INNER function. * win32_threads.c (GC_push_stack_for): Remove i local variable; call GC_push_many_regs() instead of a loop with GC_push_one() calls (ignore 2 first registers if WOW64_THREAD_CONTEXT_WORKAROUND).
* Fix incorrect code generation by MS VC caused by excessive Thread_Rep sizeIvan Maidanski2019-09-101-83/+134
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (fix of commit 449eda034) The gctest crashes were observed in debug builds produced by MS VC. In addition, this change greatly reduces memory usage by GC_threads[] and dll_thread_table[] (compared to the solution that stores the full CONTEXT in GC_Thread_Rep). * win32_threads.c (copy_ptr_regs): Declare static function. * win32_threads.c (PUSHED_REGS_COUNT): Define macro. * win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_Thread_Rep.saved_context): Move down to be the last field; change type from CONTEXT to word[PUSHED_REGS_COUNT]; rename to context_regs. * win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_Thread_Rep.context_sp): New field. * win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_suspend): Declare context local variable and use it for GetThreadContext() call; if the latter succeeds then call copy_ptr_regs(); update comment. * win32_threads.c (copy_ptr_regs): Define static function (move PUSH-related part of GC_push_stack_for code here); change PUSH1(reg) to store reg to regs[]; define context as *pcontext; add assertion that number of stored registers is equal to PUSHED_REGS_COUNT. * win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND] (copy_ptr_regs): Store ContextFlags and SegFs as the first elements of regs[]. * win32_threads.c (GC_push_stack_for): Declare i local variable (set to 0). * win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_push_stack_for): Replace pcontext and context with word *regs; set sp from thread->context_sp; remove undef context. * win32_threads.c [!RETRY_GET_THREAD_CONTEXT] (GC_push_stack_for): Declare regs[PUSHED_REGS_COUNT]; call copy_ptr_regs() to initialize regs[] and sp; limit context scope to GetThreadContext() and copy_ptr_regs() calls only. * win32_threads.c (GC_push_stack_for): Call GC_push_one() for each regs[] element (except for the first 2 ones if WOW64_THREAD_CONTEXT_WORKAROUND). * win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND] (GC_push_stack_for): Define ContextFlags, SegFs local variables (the values are obtained from regs[]); use these variables instead of context one; do not overwrite sp local variable value so that not to use context.Esp directly (i.e. not to use context out of its scope).
* Prevent GetThreadContext failure (Windows)Jonathan Chambers2019-09-051-6/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | (a cherry-pick of commits 3f39ea8, ab3699da from 'unity-master') Calls to GetThreadContext may fail. Work around this by putting access in suspend/resume loop to advance thread past problematic areas where suspend fails. Capture context in per thread structure at suspend time rather than retreiving it during the push logic. * include/private/gcconfig.h [(I386 || X86_64) && (CYGWIN32 || MSWIN32)] (RETRY_GET_THREAD_CONTEXT): Define macro. * win32_threads.c [RETRY_GET_THREAD_CONTEXT] (MAX_SUSPEND_THREAD_RETRIES): Likewise. * include/private/gcconfig.h [NO_RETRY_GET_THREAD_CONTEXT] (RETRY_GET_THREAD_CONTEXT): Undefine macro (for test purposes). * win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_Thread_Rep): Add saved_context field; add comment. * win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_suspend): Define retry_cnt local variable; set ContextFlags and call GetThreadContext() after invocation of SuspendThread(); call ResumeThread() and proceed to SuspendThread() if GetThreadContext() failed (the limit of iterations is MAX_SUSPEND_THREAD_RETRIES); call Sleep(0) after ResumeThread() or failed SuspendThread() except for the first 2 iterations. * win32_threads.c [RETRY_GET_THREAD_CONTEXT] (GC_push_stack_for): Declare pcontext local variable (which refers to thread->saved_context); define context as a macro (to *pcontext) instead of a local variable; add comment; do not set ContextFlags and do not call GetThreadContext(); undefine context after last use of PUSHn().
* Refactoring of WoW64 workaround (Win32)Ivan Maidanski2019-09-051-71/+69
| | | | | | | | | | | | | | | | | | | | | | | | (code refactoring of commit 9483d5bba) Issue #262 (bdwgc). * include/private/gcconfig.h [I386 && (CYGWIN32 || MSWIN32)] (WOW64_THREAD_CONTEXT_WORKAROUND): Define macro. * win32_threads.c [!CONTEXT_EXCEPTION_ACTIVE] (CONTEXT_EXCEPTION_ACTIVE, CONTEXT_EXCEPTION_REQUEST, CONTEXT_EXCEPTION_REPORTING): Move macro definition upper to be before GC_suspend(); define only if WOW64_THREAD_CONTEXT_WORKAROUND is defined (instead of I386). * win32_threads.c (isWow64): Move static variable upper to be before GC_suspend(); define only if WOW64_THREAD_CONTEXT_WORKAROUND. * win32_threads.c (GET_THREAD_CONTEXT_FLAGS): New macro. * win32_threads.c (GC_push_stack_for): Always set context.ContextFlags to GET_THREAD_CONTEXT_FLAGS. * win32_threads.c [I386] (GC_push_stack_for): Always store context.Esp to sp (as the initial value). * win32_threads.c (GC_push_stack_for): Use WoW64 workaround only if WOW64_THREAD_CONTEXT_WORKAROUND (instead of I386). * win32_threads.c (GC_thr_init): Set isWow64 only if WOW64_THREAD_CONTEXT_WORKAROUND (instead of I386).
* Add API functions to get and set the stack bottom of each threadBrian J. Cardiff2019-05-061-1/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Issue #277 (bdwgc). This API is useful to support coroutines. * include/gc.h (GC_get_my_stackbottom, GC_set_stackbottom): New API function declaration. * misc.c [!THREADS] (GC_set_stackbottom, GC_get_my_stackbottom): New function definition. * pthread_support.c [GC_PTHREADS && !GC_WIN32_THREADS] (GC_set_stackbottom, GC_get_my_stackbottom): Likewise. * win32_threads.c [GC_WIN32_THREADS] (GC_set_stackbottom, GC_get_my_stackbottom): Likewise. * tests/test.c (struct thr_hndl_sb_s): Define. * tests/test.c (set_stackbottom): New function (which calls GC_set_stackbottom). * tests/test.c (run_one_test): Define thr_hndl_sb local variable; call GC_get_my_stackbottom() and set_stackbottom(). * win32_threads.c [GC_WIN32_THREADS && I386] (struct GC_Thread_Rep): Add initial_stack_base field. * win32_threads.c [GC_WIN32_THREADS && I386] (GC_record_stack_base, GC_call_with_gc_active): Set initial_stack_base field. * win32_threads.c [GC_WIN32_THREADS && I386] (GC_push_stack_for): Handle the case when GetThreadContext() might return stale register values, thread stack_base != initial_stack_base but the stack is not inside the TIB stack (use context.Esp but call WARN); add TODO.
* Fix first_thread stack_base initialzation if custom GC_stackbottom (Win32)Ivan Maidanski2019-04-291-8/+5
| | | | | | | | | | | Stack bottom value of the primordial thread should be obtained from GC_stackbottom. * win32_threads.c [GC_ASSERTIONS] (GC_thr_init): Remove sb_result local variable. * win32_threads.c (GC_thr_init): Initalize sb mem_base and reg_base fields with GC_stackbottom and GC_register_stackbottom, respectively; do not call GC_get_stack_base().
* Replace 'stack base' with 'stack bottom' in the documentationIvan Maidanski2019-04-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | * README.md (The C Interface to the Allocator): Outline that stack base means its bottom; remove a note that client should set GC_stackbottom on HP PA machines manually. * doc/README.macros (USE_GET_STACKBASE_FOR_MAIN): Rename "stack base" to "stack bottom". * doc/porting.md (Adding Platforms to gcconfig.h): Likewise. * doc/porting.md (Adding Platforms to gcconfig.h): Rename "cool end of the stack" to "cold end of the stack"; refine documentation about STACKBOTTOM. * include/private/gcconfig.h (STACKBOTTOM): Rename "cool end" to "cold end" in comment. * include/gc.h (GC_stackbottom): Likewise. * include/private/gcconfig.h (LINUX_STACKBOTTOM): Rename "stack base" to "stack bottom" in comment. * include/gc.h (GC_stack_base, GC_call_with_stack_base): Likewise. * include/gc.h [GC_THREADS] (GC_register_my_thread): Likewise. * misc.c [!THREADS] (GC_call_with_gc_active): Likewise. * os_dep.c [LINUX_STACKBOTTOM] (GC_linux_main_stack_base): Likewise. * os_dep.c (GC_get_stack_base): Likewise. * pthread_support.c (GC_call_with_gc_active): Likewise. * win32_threads.c (GC_call_with_gc_active): Likewise.
* Remove Win32 main_thread static variable if threads discovery is disabledIvan Maidanski2019-04-191-15/+15
| | | | | | | | | | | (code refactoring) * win32_threads.c (GC_main_thread): Do not define static variable if GC_NO_THREADS_DISCOVERY. * win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_attached_thread): Reformat comment; move the definition to be near GC_please_stop. * win32_threads.c [GC_NO_THREADS_DISCOVERY] (GC_thr_init): Define GC_main_thread as a macro (and undefine it at the end of the function).
* Enable true incremental collection even if parallel marker is onIvan Maidanski2019-04-171-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Issue #151 (bdwgc). Because of the current limitation of the parallel marker implementation, it is not possible to interrupt the collection when performed by the parallel marker. This change allows to have the true incremental mode at the expense of disabling the parallel marker during most collection phases. By default, the old behavior (a generational collection with the parallel marker enabled) is preserved unless the client sets GC_time_limit to a value other than GC_TIME_UNLIMITED. * alloc.c [(!GC_TIME_LIMIT || CPPCHECK) && PARALLEL_MARK] (GC_time_limit): Set to GC_TIME_UNLIMITED; add comment. * alloc.c [PARALLEL_MARK] (GC_collect_a_little_inner): Temporarily set GC_parallel_mark_disabled to TRUE before GC_mark_some repeated invocation if GC_time_limit is not GC_TIME_UNLIMITED. * alloc.c [PARALLEL_MARK] (GC_stopped_mark): Temporarily set GC_parallel_mark_disabled to TRUE before GC_mark_some repeated invocation if stop_func is not GC_never_stop_func; add verbose logging if parallel marking is disabled temporarily. * doc/README.environment (GC_PAUSE_TIME_TARGET): Update the description (remove the limitation for the case when parallel marking is on). * doc/scale.md (The Parallel Marking Algorithm): Update the documentation regarding incremental mode. * include/gc.h (GC_parallel, GC_enable_incremental): Update the comment (remove the limitation on the incremental mode when parallel marking is on). * include/private/gc_priv.h [PARALLEL_MARK] (GC_parallel_mark_disabled): Declare global variable. * mark.c [PARALLEL_MARK] (GC_parallel_mark_disabled): Define. * mark.c [PARALLEL_MARK] (GC_mark_some_inner): Do not call GC_do_parallel_mark() if GC_parallel_mark_disabled; update comment. * pthread_support.c [PARALLEL_MARK] (GC_thr_init): Do not set GC_time_limit to GC_TIME_UNLIMITED if available_markers_m1 > 0; remove comment. * win32_threads.c [PARALLEL_MARK] (GC_thr_init): Likewise.
* Remove documentation specific to particular old BDWGC releasesIvan Maidanski2019-03-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * doc/README.Mac: Remove mentioning of particular GC versions; adjust the information (if needed) to match the current GC functionality. * doc/README.amiga: Likewise. * doc/README.arm.cross: Likewise. * doc/README.autoconf: Likewise. * doc/README.linux: Likewise. * doc/README.macros (FINALIZE_ON_DEMAND, JAVA_FINALIZATION): Likewise. * doc/README.sgi: Likewise. * doc/README.solaris2 (SOLARIS THREADS): Likewise. * doc/README.symbian: Likewise. * doc/README.win32 (Threads): Likewise. * doc/README.win64: Likewise. * doc/gcdescr.md (Allocation, Thread support, Thread-local allocation): Likewise. * doc/gcinterface.md (GC_INIT): Likewise. * doc/leak.md: Likewise. * doc/porting.md (Additional requirements for a basic port, Thread support): Likewise. * doc/scale.md (Options for enhanced scalability, Performance): Likewise. * doc/simple_example.md (Debugging): Do not mention removed `--enable-full-debug` option of configure. * include/gc.h (GC_parallel, GC_dont_gc, GC_use_entire_heap, GC_set_handle_fork): Remove comment that the behavior has changed in a particular GC version. * include/gc_inline.h (GC_MALLOC_WORDS_KIND): Likewise. * include/gc.h (GC_set_free_space_divisor, GC_warn_proc): Reword comment about ABI incompatible change in some GC version. * include/gc.h (GC_get_heap_usage_safe): Remove comment that the API was introduced in a particular GC version. * include/gc_cpp.h (UseGC): Likewise. * os_dep.c [LINUX_STACKBOTTOM && IA64] (GC_get_register_stack_base): Remove mentioning of a particular GC version (and of an old behavior on an ancient kernel) in a comment. * win32_threads.c [!GC_PTHREADS && !GC_NO_THREADS_DISCOVERY] (GC_DllMain): Likewise. * OS2_MAKEFILE: Likewise.
* Fix GetThreadContext stale register values use if WoW64 (Win32)Hamayama2019-02-081-2/+73
| | | | | | | | | | | | | | | | | | | | | Issue #262 (bdwgc). * misc.c [MSWIN32 && !MSWINRT_FLAVOR && !MSWIN_XBOX1] (GC_win32_MessageBoxA): Do not define unless SMALL_CONFIG. * misc.c [MSWIN32 && !_WIN64 && GC_WIN32_THREADS && CHECK_NOT_WOW64] (GC_init): Do not call IsWow64Process() and GC_win32_MessageBoxA(). * win32_threads.c [I386] (isWow64): New static variable. * win32_threads.c [I386] (GC_push_stack_for): If isWow64 then set also CONTEXT_EXCEPTION_REQUEST and CONTEXT_SEGMENTS bits in ContextFlags; if isWow64, and CONTEXT_EXCEPTION_REPORTING and CONTEXT_EXCEPTION_ACTIVE are set on return from GetThreadContext then call GetThreadSelectorEntry and use StackLimit of FS selector to set sp local variable (instead of context.Esp); add comment. * win32_threads.c [I386 && DEBUG_THREADS] (GC_push_stack_for): Call GC_log_printf() to report TIB stack limit/base and the case when CONTEXT_EXCEPTION_REQUEST is not supported. * win32_threads.c [I386] (GC_thr_init): Set isWow64 by IsWow64Process() if the later is available.
* Workaround 'me assigned value never used' cppcheck FP in register_my_threadIvan Maidanski2018-12-291-0/+3
| | | | | | | * pthread_support.c [CPPCHECK] (GC_register_my_thread): Call GC_noop1(me->flags) after reassigning me to the result of GC_register_my_thread_inner(sb,self). * win32_threads.c [CPPCHECK] (GC_register_my_thread): Likewise.
* Fix 'collecting from unknown thread' abort in leak-finding mode for Win32Ivan Maidanski2018-11-231-1/+1
| | | | | | | | | | | (fix of commit 8e6460052) * include/private/gc_priv.h [THREADS] (GC_in_thread_creation): Declare not only for pthreads. * misc.c [!DONT_USE_ATEXIT && THREADS] (GC_exit_check): Set GC_in_thread_creation to true before calling GC_gcollect for windows threads as well. * win32_threads.c (GC_in_thread_creation): Change STATIC to GC_INNER.
* Workaround 'local address assignment to a global variable' CSA warningIvan Maidanski2018-11-131-1/+1
| | | | | | | | | | | | | | | * include/gc.h [(!__GNUC__ || __INTEL_COMPILER) && LINT2] (GC_reachable_here): Transform ptr in the same way as COVERT_DATAFLOW() does. * mach_dep.c (GC_with_callee_saves_pushed): Transform the argument of GC_noop1() by COVERT_DATAFLOW(). * misc.c [!ASM_CLEAR_CODE] (GC_clear_stack_inner): Likewise. * misc.c (GC_call_with_stack_base, GC_call_with_gc_active): Likewise. * pthread_support.c (GC_call_with_gc_active): Likewise. * win32_threads.c (GC_call_with_gc_active): Likewise. * misc.c (GC_call_with_gc_active): Transform &stacksect by COVERT_DATAFLOW() when storing to GC_stackbottom. * pthread_support.c (GC_call_with_gc_active): Likewise.
* Adjust #error messages formatIvan Maidanski2018-11-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (code refactoring) Remove double quotes, "-->" prefix and the trailing dot from the error messages. * include/private/gcconfig.h [hp9000s300 && !CPPCHECK]: Adjust #error message format. * include/private/gcconfig.h [ibm032 && !CPPCHECK]: Likewise. * include/private/gcconfig.h [!mach_type_known && !CPPCHECK]: Likewise. * include/private/gcconfig.h [HEXAGON && (!__GLIBC__ || __GLIBC__ < 2 || !__ELF__ && !CPPCHECK || !LINUX)]: Likewise. * include/private/gcconfig.h [!ALIGNMENT && !CPPCHECK]: Likewise. * include/private/gcconfig.h [!STACKBOTTOM && (ECOS || NOSYS) && !CPPCHECK]: Likewise. * include/private/gcconfig.h [!CPPCHECK && (GC_IRIX_THREADS || GC_LINUX_THREADS || GC_NETBSD_THREADS || GC_FREEBSD_THREADS || GC_SOLARIS_THREADS || GC_HPUX_THREADS || GC_AIX_THREADS || GC_WIN32_THREADS || GC_WIN32_PTHREADS)]: Likewise. * include/private/gcconfig.h [PARALLEL_MARK && !THREADS && !CPPCHECK]: Likewise. * include/private/gcconfig.h [!CPPCHECK && (MARK_BIT_PER_GRANULE && MARK_BIT_PER_OBJ || STACK_GROWS_UP && STACK_GROWS_DOWN || !STACK_GROWS_UP && !STACK_GROWS_DOWN || REDIRECT_MALLOC && THREADS && !LINUX && !REDIRECT_MALLOC_IN_HEADER)]: Likewise. * os_dep.c [(MMAP_SUPPORTED || ADD_HEAP_GUARD_PAGES) && USE_MUNMAP && !USE_MMAP && !CPPCHECK]: Likewise. * win32_threads.c [!I386 && !X86_64 && !ARM32 && !AARCH64 && !SHx !MIPS && !PPC && !ALPHA && !CPPCHECK] (GC_push_stack_for): Likewise.
* Reduce scope of local variables in GC_remove_all_threads_but_meIvan Maidanski2018-11-091-1/+3
| | | | | | | | | | This eliminates 'the scope of the variable can be reduced' cppcheck warning in GC_remove_all_threads_but_me. * pthread_support.c [CAN_HANDLE_FORK] (GC_remove_all_threads_but_me): Move p, next, me local variables to an inner scope there they are used. * win32_threads.c [CAN_HANDLE_FORK] (GC_remove_all_threads_but_me): Move p, next local variables to an inner scope.
* Use GC_WORD_MAX macro across all C source filesIvan Maidanski2018-11-071-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | (code refactoring) * alloc.c (GC_collect_at_heapsize, GC_compute_heap_usage_percent, GC_add_to_heap, GC_expand_hp_inner): Use GC_WORD_MAX instead of (word)-1. * dyn_load.c [DATASTART_IS_FUNC] (GC_register_dynamic_libraries_dl_iterate_phdr): Likewise. * finalize.c [KEEP_BACK_PTRS] (GC_notify_or_invoke_finalizers): Likewise. * headers.c (GC_install_counts): Likewise. * include/private/thread_local_alloc.h [GC_GCJ_SUPPORT] (ERROR_FL): Likewise. * os_dep.c [NEED_FIND_LIMIT || USE_PROC_FOR_LIBRARIES] (GC_find_limit): Likewise. * os_dep.c [MPROTECT_VDB && DARWIN] (GC_mprotect_thread): Likewise. * pthread_support.c [PARALLEL_MARK] (GC_mark_thread): Likewise. * win32_threads.c (ADDR_LIMIT): Likewise. * win32_threads.c [PARALLEL_MARK] (GC_mark_thread): Likewise. * alloc.c (GC_least_plausible_heap_addr): Use GC_WORD_MAX instead of ONES macro. * include/private/gc_priv.h [STACK_GROWS_DOWN] (MAKE_COOLER): Likewise. * mark.c (GC_set_hdr_marks): Likewise. * alloc.c (GC_WORD_MAX): Remove definition (in this file). * headers.c (GC_install_counts): Reformat code. * include/private/gc_priv.h (ONES): Rename to GC_WORD_MAX.