Skip to content
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
24 changes: 24 additions & 0 deletions gc/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,33 @@
* first introduced for [Feature #20470].
*/
#include "ruby/ruby.h"
#include "ruby/assert.h"

#include "ruby/thread_native.h"

#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
void rb_ractor_setup_belonging(VALUE obj);

struct rb_gc_obj_suffix {
uint32_t _ractor_belonging_id;
};

# define RB_GC_OBJ_HAS_SUFFIX 1
# define RB_GC_OBJ_SUFFIX_SIZE (sizeof(struct rb_gc_obj_suffix))
#else
# define RB_GC_OBJ_HAS_SUFFIX 0
# define RB_GC_OBJ_SUFFIX_SIZE 0
#endif

struct rb_gc_vm_context {
rb_nativethread_lock_t lock;

Expand Down
23 changes: 4 additions & 19 deletions gc/mmtk/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@
#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)
#else
# define RVALUE_SUFFIX_SIZE 0
#endif

struct objspace {
bool measure_gc_time;
bool gc_stress;
Expand Down Expand Up @@ -575,7 +560,7 @@ rb_gc_impl_objspace_alloc(void)
{
MMTk_Builder *builder = rb_mmtk_builder_init();
MMTk_RubyBindingOptions binding_options = {
.suffix_size = RVALUE_SUFFIX_SIZE,
.suffix_size = RB_GC_OBJ_SUFFIX_SIZE,
};
mmtk_init_binding(builder, &binding_options, &ruby_upcalls);

Expand Down Expand Up @@ -913,16 +898,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);
}

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

VALUE *alloc_obj = (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, alloc_size, MMTk_MIN_OBJ_ALIGN);
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) - RVALUE_SUFFIX_SIZE;
alloc_obj[-1] = alloc_size - sizeof(VALUE) - RB_GC_OBJ_SUFFIX_SIZE;
alloc_obj[0] = flags;
alloc_obj[1] = klass;

Expand Down
Loading