Skip to content
Open
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
4 changes: 1 addition & 3 deletions gc/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ MODULAR_GC_FN void rb_gc_mark_roots(void *objspace, const char **categoryp);
MODULAR_GC_FN void rb_gc_ractor_newobj_cache_foreach(void (*func)(void *cache, void *data), void *data);
MODULAR_GC_FN bool rb_gc_multi_ractor_p(void);
MODULAR_GC_FN bool rb_gc_shutdown_call_finalizer_p(VALUE obj);
MODULAR_GC_FN uint32_t rb_gc_get_shape(VALUE obj);
MODULAR_GC_FN void rb_gc_set_shape(VALUE obj, uint32_t shape_id);
MODULAR_GC_FN uint32_t rb_gc_rebuild_shape(VALUE obj, size_t heap_id);
MODULAR_GC_FN void rb_gc_obj_changed_pool(VALUE obj, size_t heap_id);
MODULAR_GC_FN void rb_gc_prepare_heap_process_object(VALUE obj);
MODULAR_GC_FN bool rb_memerror_reentered(void);
MODULAR_GC_FN bool rb_obj_id_p(VALUE);
Expand Down
31 changes: 28 additions & 3 deletions gc/mmtk/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
#include <sys/sysctl.h>
#endif

#ifndef VM_CHECK_MODE
# define VM_CHECK_MODE RUBY_DEBUG
#endif

// From ractor_core.h
#ifndef RACTOR_CHECK_MODE
# define RACTOR_CHECK_MODE (VM_CHECK_MODE || RUBY_DEBUG) && (SIZEOF_UINT64_T == SIZEOF_VALUE)
#endif

#if RACTOR_CHECK_MODE
# define RVALUE_SUFFIX_SIZE sizeof(VALUE)
void rb_ractor_setup_belonging(VALUE obj);
#else
# define RVALUE_SUFFIX_SIZE 0
#endif

struct objspace {
bool measure_gc_time;
bool gc_stress;
Expand Down Expand Up @@ -557,7 +573,11 @@ void *
rb_gc_impl_objspace_alloc(void)
{
MMTk_Builder *builder = rb_mmtk_builder_init();
mmtk_init_binding(builder, NULL, &ruby_upcalls);
MMTk_RubyBindingOptions binding_options = {
.ractor_check_mode = RACTOR_CHECK_MODE != 0,
.suffix_size = RVALUE_SUFFIX_SIZE,
};
mmtk_init_binding(builder, &binding_options, &ruby_upcalls);

return calloc(1, sizeof(struct objspace));
}
Expand Down Expand Up @@ -885,15 +905,16 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags
mmtk_handle_user_collection_request(ractor_cache, false, false);
}

alloc_size += sizeof(VALUE);
// Layout: [hidden size header (sizeof(VALUE))][payload (alloc_size)][suffix (RVALUE_SUFFIX_SIZE)]
alloc_size += sizeof(VALUE) + RVALUE_SUFFIX_SIZE;

VALUE *alloc_obj = (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, alloc_size);
if (!alloc_obj) {
alloc_obj = mmtk_alloc(ractor_cache->mutator, alloc_size, MMTk_MIN_OBJ_ALIGN, 0, MMTK_ALLOCATION_SEMANTICS_DEFAULT);
}

alloc_obj++;
alloc_obj[-1] = alloc_size - sizeof(VALUE);
alloc_obj[-1] = alloc_size - sizeof(VALUE) - RVALUE_SUFFIX_SIZE;
alloc_obj[0] = flags;
alloc_obj[1] = klass;

Expand All @@ -905,6 +926,10 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags

objspace->total_allocated_objects++;

#if RACTOR_CHECK_MODE
rb_ractor_setup_belonging((VALUE)alloc_obj);
#endif

return (VALUE)alloc_obj;
}

Expand Down
2 changes: 1 addition & 1 deletion gc/mmtk/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ bool mmtk_is_reachable(MMTk_ObjectReference object);
MMTk_Builder *mmtk_builder_default(void);

void mmtk_init_binding(MMTk_Builder *builder,
const struct MMTk_RubyBindingOptions *_binding_options,
const struct MMTk_RubyBindingOptions *binding_options,
const struct MMTk_RubyUpcalls *upcalls);

void mmtk_initialize_collection(MMTk_VMThread tls);
Expand Down
7 changes: 2 additions & 5 deletions gc/mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub extern "C" fn mmtk_builder_default() -> *mut MMTKBuilder {
#[no_mangle]
pub unsafe extern "C" fn mmtk_init_binding(
builder: *mut MMTKBuilder,
_binding_options: *const RubyBindingOptions,
binding_options: *const RubyBindingOptions,
upcalls: *const RubyUpcalls,
) {
crate::MUTATOR_THREAD_PANIC_HANDLER
Expand All @@ -191,10 +191,7 @@ pub unsafe extern "C" fn mmtk_init_binding(
crate::set_panic_hook();

let builder: Box<MMTKBuilder> = unsafe { Box::from_raw(builder) };
let binding_options = RubyBindingOptions {
ractor_check_mode: false,
suffix_size: 0,
};
let binding_options = unsafe { (*binding_options).clone() };
let mmtk_boxed = mmtk_init(&builder);
let mmtk_static = Box::leak(Box::new(mmtk_boxed));

Expand Down
Loading