aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gc.c40
-rw-r--r--internal/gc.h1
-rw-r--r--internal/object.h1
-rw-r--r--object.c31
-rw-r--r--yjit/bindgen/src/main.rs5
-rw-r--r--yjit/src/cruby_bindings.inc.rs2
6 files changed, 38 insertions, 42 deletions
diff --git a/gc.c b/gc.c
index d8df0278fd..2e99911bf4 100644
--- a/gc.c
+++ b/gc.c
@@ -2970,43 +2970,11 @@ rb_newobj(void)
return newobj_of(GET_RACTOR(), 0, T_NONE, 0, 0, 0, FALSE, RVALUE_SIZE);
}
-static VALUE
-rb_class_instance_allocate_internal(VALUE klass, VALUE flags, bool wb_protected)
-{
- GC_ASSERT((flags & RUBY_T_MASK) == T_OBJECT);
- GC_ASSERT(flags & ROBJECT_EMBED);
-
- size_t size;
- uint32_t index_tbl_num_entries = RCLASS_EXT(klass)->max_iv_count;
-
- size = rb_obj_embedded_size(index_tbl_num_entries);
- if (!rb_gc_size_allocatable_p(size)) {
- size = sizeof(struct RObject);
- }
-
- VALUE obj = newobj_of(GET_RACTOR(), klass, flags, 0, 0, 0, wb_protected, size);
- RUBY_ASSERT(rb_shape_get_shape(obj)->type == SHAPE_ROOT);
-
- // Set the shape to the specific T_OBJECT shape which is always
- // SIZE_POOL_COUNT away from the root shape.
- ROBJECT_SET_SHAPE_ID(obj, ROBJECT_SHAPE_ID(obj) + SIZE_POOL_COUNT);
-
-#if RUBY_DEBUG
- RUBY_ASSERT(!rb_shape_obj_too_complex(obj));
- VALUE *ptr = ROBJECT_IVPTR(obj);
- for (size_t i = 0; i < ROBJECT_IV_CAPACITY(obj); i++) {
- ptr[i] = Qundef;
- }
-#endif
-
- return obj;
-}
-
VALUE
rb_newobj_of(VALUE klass, VALUE flags)
{
if ((flags & RUBY_T_MASK) == T_OBJECT) {
- return rb_class_instance_allocate_internal(klass, (flags | ROBJECT_EMBED) & ~FL_WB_PROTECTED, flags & FL_WB_PROTECTED);
+ return rb_class_allocate_instance(klass);
}
else {
return newobj_of(GET_RACTOR(), klass, flags & ~FL_WB_PROTECTED, 0, 0, 0, flags & FL_WB_PROTECTED, RVALUE_SIZE);
@@ -3116,12 +3084,6 @@ rb_imemo_new_debug(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0,
}
#endif
-VALUE
-rb_class_allocate_instance(VALUE klass)
-{
- return rb_class_instance_allocate_internal(klass, T_OBJECT | ROBJECT_EMBED, RGENGC_WB_PROTECTED_OBJECT);
-}
-
static inline void
rb_data_object_check(VALUE klass)
{
diff --git a/internal/gc.h b/internal/gc.h
index 2537671855..c2f3b61deb 100644
--- a/internal/gc.h
+++ b/internal/gc.h
@@ -237,7 +237,6 @@ RUBY_ATTR_MALLOC void *rb_xcalloc_mul_add_mul(size_t, size_t, size_t, size_t);
static inline void *ruby_sized_xrealloc_inlined(void *ptr, size_t new_size, size_t old_size) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2));
static inline void *ruby_sized_xrealloc2_inlined(void *ptr, size_t new_count, size_t elemsiz, size_t old_count) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2, 3));
static inline void ruby_sized_xfree_inlined(void *ptr, size_t size);
-VALUE rb_class_allocate_instance(VALUE klass);
void rb_gc_ractor_newobj_cache_clear(rb_ractor_newobj_cache_t *newobj_cache);
size_t rb_gc_obj_slot_size(VALUE obj);
bool rb_gc_size_allocatable_p(size_t size);
diff --git a/internal/object.h b/internal/object.h
index 903e2d29a5..92ad37fdc8 100644
--- a/internal/object.h
+++ b/internal/object.h
@@ -12,6 +12,7 @@
/* object.c */
size_t rb_obj_embedded_size(uint32_t numiv);
+VALUE rb_class_allocate_instance(VALUE klass);
VALUE rb_class_search_ancestor(VALUE klass, VALUE super);
NORETURN(void rb_undefined_alloc(VALUE klass));
double rb_num_to_dbl(VALUE val);
diff --git a/object.c b/object.c
index 7d4b11ee48..63fa6b1a99 100644
--- a/object.c
+++ b/object.c
@@ -118,6 +118,37 @@ rb_obj_reveal(VALUE obj, VALUE klass)
}
VALUE
+rb_class_allocate_instance(VALUE klass)
+{
+ uint32_t index_tbl_num_entries = RCLASS_EXT(klass)->max_iv_count;
+
+ size_t size = rb_obj_embedded_size(index_tbl_num_entries);
+ if (!rb_gc_size_allocatable_p(size)) {
+ size = sizeof(struct RObject);
+ }
+
+ NEWOBJ_OF(o, struct RObject, klass,
+ T_OBJECT | ROBJECT_EMBED | (RGENGC_WB_PROTECTED_OBJECT ? FL_WB_PROTECTED : 0), size, 0);
+ VALUE obj = (VALUE)o;
+
+ RUBY_ASSERT(rb_shape_get_shape(obj)->type == SHAPE_ROOT);
+
+ // Set the shape to the specific T_OBJECT shape which is always
+ // SIZE_POOL_COUNT away from the root shape.
+ ROBJECT_SET_SHAPE_ID(obj, ROBJECT_SHAPE_ID(obj) + SIZE_POOL_COUNT);
+
+#if RUBY_DEBUG
+ RUBY_ASSERT(!rb_shape_obj_too_complex(obj));
+ VALUE *ptr = ROBJECT_IVPTR(obj);
+ for (size_t i = 0; i < ROBJECT_IV_CAPACITY(obj); i++) {
+ ptr[i] = Qundef;
+ }
+#endif
+
+ return obj;
+}
+
+VALUE
rb_obj_setup(VALUE obj, VALUE klass, VALUE type)
{
VALUE ignored_flags = RUBY_FL_PROMOTED | RUBY_FL_SEEN_OBJ_ID;
diff --git a/yjit/bindgen/src/main.rs b/yjit/bindgen/src/main.rs
index 0824e80cd0..ffe56619cc 100644
--- a/yjit/bindgen/src/main.rs
+++ b/yjit/bindgen/src/main.rs
@@ -38,6 +38,7 @@ fn main() {
.clang_args(filtered_clang_args)
.header("encindex.h")
.header("internal.h")
+ .header("internal/object.h")
.header("internal/re.h")
.header("include/ruby/ruby.h")
.header("shape.h")
@@ -375,8 +376,10 @@ fn main() {
// From include/ruby/internal/intern/vm.h
.allowlist_function("rb_get_alloc_func")
- // From gc.h and internal/gc.h
+ // From internal/object.h
.allowlist_function("rb_class_allocate_instance")
+
+ // From gc.h and internal/gc.h
.allowlist_function("rb_obj_info")
.allowlist_function("ruby_xfree")
diff --git a/yjit/src/cruby_bindings.inc.rs b/yjit/src/cruby_bindings.inc.rs
index 54cd51b61e..d7bfc2a0c9 100644
--- a/yjit/src/cruby_bindings.inc.rs
+++ b/yjit/src/cruby_bindings.inc.rs
@@ -1007,6 +1007,7 @@ extern "C" {
pub fn rb_ivar_defined(obj: VALUE, name: ID) -> VALUE;
pub fn rb_attr_get(obj: VALUE, name: ID) -> VALUE;
pub fn rb_obj_info_dump(obj: VALUE);
+ pub fn rb_class_allocate_instance(klass: VALUE) -> VALUE;
pub fn rb_reg_new_ary(ary: VALUE, options: ::std::os::raw::c_int) -> VALUE;
pub fn rb_ary_tmp_new_from_values(
arg1: VALUE,
@@ -1036,7 +1037,6 @@ extern "C" {
cfp: *const rb_control_frame_t,
) -> *const rb_callable_method_entry_t;
pub fn rb_obj_info(obj: VALUE) -> *const ::std::os::raw::c_char;
- pub fn rb_class_allocate_instance(klass: VALUE) -> VALUE;
pub fn rb_ec_stack_check(ec: *mut rb_execution_context_struct) -> ::std::os::raw::c_int;
pub fn rb_shape_id_offset() -> i32;
pub fn rb_shape_get_shape_by_id(shape_id: shape_id_t) -> *mut rb_shape_t;