зеркало из https://github.com/github/ruby.git
[Feature #18239] Refactor RVARGC alloc functions
The allocation functions no longer assume that one RVALUE needs to be allocated.
This commit is contained in:
Родитель
46b66eb9e8
Коммит
6374be5a81
8
class.c
8
class.c
|
@ -167,16 +167,16 @@ rb_class_detach_module_subclasses(VALUE klass)
|
|||
static VALUE
|
||||
class_alloc(VALUE flags, VALUE klass)
|
||||
{
|
||||
size_t payload_size = 0;
|
||||
size_t alloc_size = sizeof(struct RClass);
|
||||
|
||||
#if USE_RVARGC
|
||||
payload_size = sizeof(rb_classext_t);
|
||||
alloc_size += sizeof(rb_classext_t);
|
||||
#endif
|
||||
|
||||
RVARGC_NEWOBJ_OF(obj, struct RClass, klass, (flags & T_MASK) | FL_PROMOTED1 /* start from age == 2 */ | (RGENGC_WB_PROTECTED_CLASS ? FL_WB_PROTECTED : 0), payload_size);
|
||||
RVARGC_NEWOBJ_OF(obj, struct RClass, klass, (flags & T_MASK) | FL_PROMOTED1 /* start from age == 2 */ | (RGENGC_WB_PROTECTED_CLASS ? FL_WB_PROTECTED : 0), alloc_size);
|
||||
|
||||
#if USE_RVARGC
|
||||
obj->ptr = (rb_classext_t *)rb_gc_rvargc_object_data((VALUE)obj);
|
||||
obj->ptr = (rb_classext_t *)((char *)obj + sizeof(struct RClass));
|
||||
#else
|
||||
obj->ptr = ZALLOC(rb_classext_t);
|
||||
#endif
|
||||
|
|
4
gc.c
4
gc.c
|
@ -4577,7 +4577,9 @@ obj_memsize_of(VALUE obj, int use_all_types)
|
|||
if (RCLASS_CC_TBL(obj)) {
|
||||
size += cc_table_memsize(RCLASS_CC_TBL(obj));
|
||||
}
|
||||
#if !USE_RVARGC
|
||||
size += sizeof(rb_classext_t);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case T_ICLASS:
|
||||
|
@ -4666,7 +4668,7 @@ obj_memsize_of(VALUE obj, int use_all_types)
|
|||
BUILTIN_TYPE(obj), (void*)obj);
|
||||
}
|
||||
|
||||
return size + sizeof(RVALUE);
|
||||
return size + GET_HEAP_PAGE(obj)->slot_size;
|
||||
}
|
||||
|
||||
size_t
|
||||
|
|
|
@ -28,16 +28,18 @@ struct rb_objspace; /* in vm_core.h */
|
|||
# undef RB_OBJ_WRITE
|
||||
#endif
|
||||
|
||||
#define RVALUE_SIZE (sizeof(struct RBasic) + sizeof(VALUE[RBIMPL_RVALUE_EMBED_LEN_MAX]))
|
||||
|
||||
/* optimized version of NEWOBJ() */
|
||||
#define RB_NEWOBJ_OF(var, T, c, f) \
|
||||
T *(var) = (T *)(((f) & FL_WB_PROTECTED) ? \
|
||||
rb_wb_protected_newobj_of((c), (f) & ~FL_WB_PROTECTED, 0) : \
|
||||
rb_wb_unprotected_newobj_of((c), (f), 0))
|
||||
rb_wb_protected_newobj_of((c), (f) & ~FL_WB_PROTECTED, RVALUE_SIZE) : \
|
||||
rb_wb_unprotected_newobj_of((c), (f), RVALUE_SIZE))
|
||||
|
||||
#define RB_EC_NEWOBJ_OF(ec, var, T, c, f) \
|
||||
T *(var) = (T *)(((f) & FL_WB_PROTECTED) ? \
|
||||
rb_ec_wb_protected_newobj_of((ec), (c), (f) & ~FL_WB_PROTECTED, 0) : \
|
||||
rb_wb_unprotected_newobj_of((c), (f), 0))
|
||||
rb_ec_wb_protected_newobj_of((ec), (c), (f) & ~FL_WB_PROTECTED, RVALUE_SIZE) : \
|
||||
rb_wb_unprotected_newobj_of((c), (f), RVALUE_SIZE))
|
||||
|
||||
#define RB_RVARGC_NEWOBJ_OF(var, T, c, f, s) \
|
||||
T *(var) = (T *)(((f) & FL_WB_PROTECTED) ? \
|
||||
|
@ -100,7 +102,6 @@ static inline void *ruby_sized_xrealloc2_inlined(void *ptr, size_t new_count, si
|
|||
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);
|
||||
void *rb_gc_rvargc_object_data(VALUE obj);
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
/* gc.c (export) */
|
||||
|
|
Загрузка…
Ссылка в новой задаче