diff --git a/gc.c b/gc.c index 7fcfdbcccbec4b..3d61b062a34b5f 100644 --- a/gc.c +++ b/gc.c @@ -158,10 +158,10 @@ RubyUpcalls ruby_upcalls; #endif #ifdef USE_THIRD_PARTY_HEAP -static char *mmtk_env_plan = NULL; -static char *mmtk_pre_arg_plan = NULL; -static char *mmtk_post_arg_plan = NULL; -static char *mmtk_chosen_plan = NULL; +static const char *mmtk_env_plan = NULL; +static const char *mmtk_pre_arg_plan = NULL; +static const char *mmtk_post_arg_plan = NULL; +static const char *mmtk_chosen_plan = NULL; #endif static inline struct rbimpl_size_mul_overflow_tag @@ -1124,6 +1124,7 @@ heap_allocatable_slots(rb_objspace_t *objspace) return count; } +#ifndef USE_THIRD_PARTY_HEAP static inline size_t total_allocated_pages(rb_objspace_t *objspace) { @@ -1145,6 +1146,7 @@ total_freed_pages(rb_objspace_t *objspace) } return count; } +#endif #define gc_mode(objspace) gc_mode_verify((enum gc_mode)(objspace)->flags.mode) #define gc_mode_set(objspace, mode) ((objspace)->flags.mode = (unsigned int)gc_mode_verify(mode)) @@ -1212,7 +1214,6 @@ NORETURN(static void *gc_vraise(void *ptr)); NORETURN(static void gc_raise(VALUE exc, const char *fmt, ...)); NORETURN(static void negative_size_allocation_error(const char *)); -static void init_mark_stack(mark_stack_t *stack); static int ready_to_gc(rb_objspace_t *objspace); @@ -1252,7 +1253,10 @@ static void gc_sweep_continue(rb_objspace_t *objspace, rb_size_pool_t *size_pool static inline void gc_mark(rb_objspace_t *objspace, VALUE ptr); static inline void gc_pin(rb_objspace_t *objspace, VALUE ptr); static inline void gc_mark_and_pin(rb_objspace_t *objspace, VALUE ptr); +#ifndef USE_THIRD_PARTY_HEAP +static void init_mark_stack(mark_stack_t *stack); static void gc_mark_ptr(rb_objspace_t *objspace, VALUE ptr); +#endif NO_SANITIZE("memory", static void gc_mark_maybe(rb_objspace_t *objspace, VALUE ptr)); static void gc_mark_children(rb_objspace_t *objspace, VALUE ptr); @@ -1528,7 +1532,9 @@ check_rvalue_consistency_force(const VALUE obj, int terminate) bp(); fprintf(stderr, "check_rvalue_consistency: %p is not a Ruby object.\n", (void *)obj); err++; +#ifndef USE_THIRD_PARTY_HEAP skip: +#endif ; } else { @@ -1812,6 +1818,7 @@ RVALUE_AGE_RESET_RAW(VALUE obj) RBASIC(obj)->flags = RVALUE_FLAGS_AGE_SET(RBASIC(obj)->flags, 0); } +#ifndef USE_THIRD_PARTY_HEAP static inline void RVALUE_AGE_RESET(VALUE obj) { @@ -1821,6 +1828,7 @@ RVALUE_AGE_RESET(VALUE obj) RVALUE_AGE_RESET_RAW(obj); check_rvalue_consistency(obj); } +#endif static inline int RVALUE_BLACK_P(VALUE obj) @@ -3201,6 +3209,7 @@ rb_objspace_data_type_name(VALUE obj) } } +#ifndef USE_THIRD_PARTY_HEAP static int ptr_in_page_body_p(const void *ptr, const void *memb) { @@ -3237,6 +3246,7 @@ heap_page_for_ptr(rb_objspace_t *objspace, uintptr_t ptr) return NULL; } } +#endif PUREFUNC(static inline int is_pointer_to_heap(rb_objspace_t *objspace, void *ptr);) static inline int @@ -4581,6 +4591,7 @@ struct force_finalize_list { struct force_finalize_list *next; }; +#ifndef USE_THIRD_PARTY_HEAP static int force_chain_object(st_data_t key, st_data_t val, st_data_t arg) { @@ -4592,6 +4603,7 @@ force_chain_object(st_data_t key, st_data_t val, st_data_t arg) *prev = curr; return ST_CONTINUE; } +#endif bool rb_obj_is_main_ractor(VALUE gv); @@ -4691,7 +4703,6 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace) while ((resurrected = mmtk_poll_finalizable(true)) != NULL) { VALUE obj = (VALUE)resurrected; if (USE_RUBY_DEBUG_LOG) { - VALUE klass = CLASS_OF(obj); RUBY_DEBUG_LOG("Resurrected for obj_free: %p: %s %s", resurrected, rb_type_str(RB_BUILTIN_TYPE(obj)), @@ -5312,6 +5323,7 @@ count_objects(int argc, VALUE *argv, VALUE os) /* Sweeping */ +#ifndef USE_THIRD_PARTY_HEAP static size_t objspace_available_slots(rb_objspace_t *objspace) { @@ -5327,6 +5339,7 @@ objspace_available_slots(rb_objspace_t *objspace) return total_slots; #endif } +#endif static size_t objspace_live_slots(rb_objspace_t *objspace) @@ -5334,6 +5347,7 @@ objspace_live_slots(rb_objspace_t *objspace) return (objspace->total_allocated_objects - objspace->profile.total_freed_objects) - heap_pages_final_slots; } +#ifndef USE_THIRD_PARTY_HEAP static size_t objspace_free_slots(rb_objspace_t *objspace) { @@ -5343,6 +5357,7 @@ objspace_free_slots(rb_objspace_t *objspace) return objspace_available_slots(objspace) - objspace_live_slots(objspace) - heap_pages_final_slots; #endif } +#endif //USE_THIRD_PARTY_HEAP static void gc_setup_mark_bits(struct heap_page *page) @@ -6533,6 +6548,7 @@ pop_mark_stack(mark_stack_t *stack, VALUE *data) return TRUE; } +#ifndef USE_THIRD_PARTY_HEAP static void init_mark_stack(mark_stack_t *stack) { @@ -6546,6 +6562,7 @@ init_mark_stack(mark_stack_t *stack) } stack->unused_cache_size = stack->cache_size; } +#endif /* Marking */ @@ -6953,6 +6970,7 @@ mark_current_machine_context(rb_objspace_t *objspace, rb_execution_context_t *ec #else // !defined(__wasm__) +#ifndef USE_THIRD_PARTY_HEAP static void mark_current_machine_context(rb_objspace_t *objspace, rb_execution_context_t *ec) { @@ -6977,6 +6995,7 @@ mark_current_machine_context(rb_objspace_t *objspace, rb_execution_context_t *ec each_stack_location(objspace, ec, stack_start, stack_end, gc_mark_maybe); } +#endif // USE_THIRD_PARTY_HEAP #endif static void @@ -7162,6 +7181,8 @@ gc_aging(rb_objspace_t *objspace, VALUE obj) objspace->marked_slots++; } + +#ifndef USE_THIRD_PARTY_HEAP NOINLINE(static void gc_mark_ptr(rb_objspace_t *objspace, VALUE obj)); static void reachable_objects_from_callback(VALUE obj); @@ -7194,6 +7215,7 @@ gc_mark_ptr(rb_objspace_t *objspace, VALUE obj) reachable_objects_from_callback(obj); } } +#endif static inline void gc_pin(rb_objspace_t *objspace, VALUE obj) @@ -7206,11 +7228,13 @@ gc_pin(rb_objspace_t *objspace, VALUE obj) } } +#ifdef USE_THIRD_PARTY_HEAP static inline void rb_mmtk_mark_movable(VALUE obj); static inline void rb_mmtk_mark_pin(VALUE obj); +#endif static inline void gc_mark_and_pin(rb_objspace_t *objspace, VALUE obj) @@ -7628,8 +7652,10 @@ show_mark_ticks(void) #endif /* PRINT_ROOT_TICKS */ +#ifdef USE_THIRD_PARTY_HEAP static void rb_mmtk_assert_mmtk_worker(); +#endif static void gc_mark_roots(rb_objspace_t *objspace, const char **categoryp) @@ -9932,6 +9958,9 @@ static VALUE gc_start_internal(rb_execution_context_t *ec, VALUE self, VALUE full_mark, VALUE immediate_mark, VALUE immediate_sweep, VALUE compact) { rb_objspace_t *objspace = &rb_objspace; +#ifdef USE_THIRD_PARTY_HEAP + mmtk_handle_user_collection_request(GET_THREAD()); +#else unsigned int reason = (GPR_FLAG_FULL_MARK | GPR_FLAG_IMMEDIATE_MARK | GPR_FLAG_IMMEDIATE_SWEEP | @@ -9949,9 +9978,6 @@ gc_start_internal(rb_execution_context_t *ec, VALUE self, VALUE full_mark, VALUE if (!RTEST(immediate_sweep)) reason &= ~GPR_FLAG_IMMEDIATE_SWEEP; } -#ifdef USE_THIRD_PARTY_HEAP - mmtk_handle_user_collection_request(GET_THREAD()); -#else garbage_collect(objspace, reason); #endif // USE_THIRD_PARTY_HEAP @@ -11890,12 +11916,14 @@ ruby_gc_set_params(void) #endif } +#ifndef USE_THIRD_PARTY_HEAP static void reachable_objects_from_callback(VALUE obj) { rb_ractor_t *cr = GET_RACTOR(); cr->mfd->mark_func(obj, cr->mfd->data); } +#endif void rb_objspace_reachable_objects_from(VALUE obj, void (func)(VALUE, void *), void *data) @@ -14997,6 +15025,7 @@ rb_mmtk_scan_vm_specific_roots(void) gc_mark_roots(vm->objspace, &phase); } +RBIMPL_ATTR_NORETURN() static void rb_mmtk_scan_thread_roots(void) { @@ -15013,7 +15042,7 @@ rb_mmtk_scan_thread_root(MMTk_VMMutatorThread mutator, MMTk_VMWorkerThread worke RUBY_DEBUG_LOG("[Worker: %p] We will scan thread root for thread: %p, ec: %p", worker, thread, ec); - rb_execution_context_mark(thread->ec); + rb_execution_context_mark(ec); RUBY_DEBUG_LOG("[Worker: %p] Finished scanning thread for thread: %p, ec: %p", worker, thread, ec); } @@ -15179,7 +15208,7 @@ void rb_mmtk_pre_process_opts(int argc, char **argv) { #define opt_match_arg(s, l, name) \ opt_match(s, l, name) && (*(s) ? 1 : (rb_raise(rb_eRuntimeError, "--mmtk-" name " needs an argument"), 0)) -void rb_mmtk_post_process_opts(char *s) { +void rb_mmtk_post_process_opts(const char *s) { const size_t l = strlen(s); if (l == 0) { return; diff --git a/gc.h b/gc.h index ad3296d457a49b..171b07fdb34dd2 100644 --- a/gc.h +++ b/gc.h @@ -122,7 +122,7 @@ struct rb_thread_struct; #define MMTK_DEFAULT_PLAN "MarkSweep" void rb_gc_init_collection(); void rb_mmtk_pre_process_opts(int argc, char **argv); -void rb_mmtk_post_process_opts(char *arg); +void rb_mmtk_post_process_opts(const char *arg); void rb_mmtk_post_process_opts_finish(void); #endif // USE_THIRD_PARTY_HEAP diff --git a/mmtk.h b/mmtk.h index 654a818f9b2e11..daf7a35030b798 100644 --- a/mmtk.h +++ b/mmtk.h @@ -63,7 +63,7 @@ extern void* mmtk_alloc_slow(MMTk_Mutator mutator, size_t size, size_t align, ssize_t offset, int semantics); extern void mmtk_post_alloc(MMTk_Mutator mutator, void* refer, - int bytes, int semantics); + size_t bytes, int semantics); /** * Tracing diff --git a/string.c b/string.c index 02acddd9322b9d..8b0f0561fdecae 100644 --- a/string.c +++ b/string.c @@ -462,7 +462,7 @@ fstr_update_callback(st_data_t *key, st_data_t *value, st_data_t data, int exist RBASIC(str)->flags |= RSTRING_FSTR; #ifdef USE_THIRD_PARTY_HEAP - mmtk_register_finalizable(str); + mmtk_register_finalizable((void *)str); #endif // USE_THIRD_PARTY_HEAP *key = *value = arg->fstr = str;