Skip to content

Fix compilation warnings #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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))
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);

Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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)
{
Expand All @@ -5327,13 +5339,15 @@ objspace_available_slots(rb_objspace_t *objspace)
return total_slots;
#endif
}
#endif

static size_t
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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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)
{
Expand All @@ -6546,6 +6562,7 @@ init_mark_stack(mark_stack_t *stack)
}
stack->unused_cache_size = stack->cache_size;
}
#endif

/* Marking */

Expand Down Expand Up @@ -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)
{
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 |
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down