Skip to content

Commit 4005335

Browse files
committed
Move rb_gc_obj_suffix to gc.h
1 parent 843ec06 commit 4005335

2 files changed

Lines changed: 28 additions & 19 deletions

File tree

gc/gc.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,33 @@
1010
* first introduced for [Feature #20470].
1111
*/
1212
#include "ruby/ruby.h"
13+
#include "ruby/assert.h"
1314

1415
#include "ruby/thread_native.h"
1516

17+
#ifndef VM_CHECK_MODE
18+
# define VM_CHECK_MODE RUBY_DEBUG
19+
#endif
20+
21+
// From ractor_core.h
22+
#ifndef RACTOR_CHECK_MODE
23+
# define RACTOR_CHECK_MODE (VM_CHECK_MODE || RUBY_DEBUG) && (SIZEOF_UINT64_T == SIZEOF_VALUE)
24+
#endif
25+
26+
#if RACTOR_CHECK_MODE
27+
void rb_ractor_setup_belonging(VALUE obj);
28+
29+
struct rb_gc_obj_suffix {
30+
uint32_t _ractor_belonging_id;
31+
};
32+
33+
# define RB_GC_OBJ_HAS_SUFFIX 1
34+
# define RB_GC_OBJ_SUFFIX_SIZE (sizeof(struct rb_gc_obj_suffix))
35+
#else
36+
# define RB_GC_OBJ_HAS_SUFFIX 0
37+
# define RB_GC_OBJ_SUFFIX_SIZE 0
38+
#endif
39+
1640
struct rb_gc_vm_context {
1741
rb_nativethread_lock_t lock;
1842

gc/mmtk/mmtk.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,6 @@
1616
#include <sys/sysctl.h>
1717
#endif
1818

19-
#ifndef VM_CHECK_MODE
20-
# define VM_CHECK_MODE RUBY_DEBUG
21-
#endif
22-
23-
// From ractor_core.h
24-
#ifndef RACTOR_CHECK_MODE
25-
# define RACTOR_CHECK_MODE (VM_CHECK_MODE || RUBY_DEBUG) && (SIZEOF_UINT64_T == SIZEOF_VALUE)
26-
#endif
27-
28-
#if RACTOR_CHECK_MODE
29-
# define RVALUE_SUFFIX_SIZE sizeof(VALUE)
30-
#else
31-
# define RVALUE_SUFFIX_SIZE 0
32-
#endif
33-
3419
struct objspace {
3520
bool measure_gc_time;
3621
bool gc_stress;
@@ -575,7 +560,7 @@ rb_gc_impl_objspace_alloc(void)
575560
{
576561
MMTk_Builder *builder = rb_mmtk_builder_init();
577562
MMTk_RubyBindingOptions binding_options = {
578-
.suffix_size = RVALUE_SUFFIX_SIZE,
563+
.suffix_size = RB_GC_OBJ_SUFFIX_SIZE,
579564
};
580565
mmtk_init_binding(builder, &binding_options, &ruby_upcalls);
581566

@@ -913,16 +898,16 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags
913898
mmtk_handle_user_collection_request(ractor_cache, false, false);
914899
}
915900

916-
// Layout: [hidden size header (sizeof(VALUE))][payload (alloc_size)][suffix (RVALUE_SUFFIX_SIZE)]
917-
alloc_size += sizeof(VALUE) + RVALUE_SUFFIX_SIZE;
901+
// Layout: [hidden size header (sizeof(VALUE))][payload (alloc_size)][suffix (RB_GC_OBJ_SUFFIX_SIZE)]
902+
alloc_size += sizeof(VALUE) + RB_GC_OBJ_SUFFIX_SIZE;
918903

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

924909
alloc_obj++;
925-
alloc_obj[-1] = alloc_size - sizeof(VALUE) - RVALUE_SUFFIX_SIZE;
910+
alloc_obj[-1] = alloc_size - sizeof(VALUE) - RB_GC_OBJ_SUFFIX_SIZE;
926911
alloc_obj[0] = flags;
927912
alloc_obj[1] = klass;
928913

0 commit comments

Comments
 (0)