Make classes embedded on 32 bit

Classes are now exactly 80 bytes when embedded, which perfectly fits the
3rd size pool on 32 bit systems.
This commit is contained in:
Peter Zhu 2023-04-14 16:28:14 -04:00
Родитель 24b137336b
Коммит a0d1069e03
4 изменённых файлов: 2 добавлений и 33 удалений

10
class.c
Просмотреть файл

@ -193,22 +193,14 @@ rb_class_detach_module_subclasses(VALUE klass)
static VALUE
class_alloc(VALUE flags, VALUE klass)
{
size_t alloc_size = sizeof(struct RClass);
#if RCLASS_EXT_EMBEDDED
alloc_size += sizeof(rb_classext_t);
#endif
size_t alloc_size = sizeof(struct RClass) + sizeof(rb_classext_t);
flags &= T_MASK;
flags |= FL_PROMOTED1 /* start from age == 2 */;
if (RGENGC_WB_PROTECTED_CLASS) flags |= FL_WB_PROTECTED;
NEWOBJ_OF(obj, struct RClass, klass, flags, alloc_size, 0);
#if RCLASS_EXT_EMBEDDED
memset(RCLASS_EXT(obj), 0, sizeof(rb_classext_t));
#else
obj->ptr = ZALLOC(rb_classext_t);
#endif
/* ZALLOC
RCLASS_CONST_TBL(obj) = 0;

11
gc.c
Просмотреть файл

@ -3513,11 +3513,6 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
xfree(RCLASS_SUPERCLASSES(obj));
}
#if !RCLASS_EXT_EMBEDDED
if (RCLASS_EXT(obj))
xfree(RCLASS_EXT(obj));
#endif
(void)RB_DEBUG_COUNTER_INC_IF(obj_module_ptr, BUILTIN_TYPE(obj) == T_MODULE);
(void)RB_DEBUG_COUNTER_INC_IF(obj_class_ptr, BUILTIN_TYPE(obj) == T_CLASS);
break;
@ -3644,9 +3639,6 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
cc_table_free(objspace, obj, FALSE);
rb_class_remove_from_module_subclasses(obj);
rb_class_remove_from_super_subclasses(obj);
#if !RCLASS_EXT_EMBEDDED
xfree(RCLASS_EXT(obj));
#endif
RB_DEBUG_COUNTER_INC(obj_iclass_ptr);
break;
@ -4905,9 +4897,6 @@ obj_memsize_of(VALUE obj, int use_all_types)
if (FL_TEST_RAW(obj, RCLASS_SUPERCLASSES_INCLUDE_SELF)) {
size += (RCLASS_SUPERCLASS_DEPTH(obj) + 1) * sizeof(VALUE);
}
#if !RCLASS_EXT_EMBEDDED
size += sizeof(rb_classext_t);
#endif
}
break;
case T_ICLASS:

Просмотреть файл

@ -76,21 +76,12 @@ struct RClass {
struct RBasic basic;
VALUE super;
struct rb_id_table *m_tbl;
#if !RCLASS_EXT_EMBEDDED
struct rb_classext_struct *ptr;
#endif
};
#if RCLASS_EXT_EMBEDDED
// Assert that classes can be embedded in size_pools[2] (which has 160B slot size)
STATIC_ASSERT(sizeof_rb_classext_t, sizeof(struct RClass) + sizeof(rb_classext_t) <= 4 * RVALUE_SIZE);
#endif
#if RCLASS_EXT_EMBEDDED
# define RCLASS_EXT(c) ((rb_classext_t *)((char *)(c) + sizeof(struct RClass)))
#else
# define RCLASS_EXT(c) (RCLASS(c)->ptr)
#endif
#define RCLASS_EXT(c) ((rb_classext_t *)((char *)(c) + sizeof(struct RClass)))
#define RCLASS_CONST_TBL(c) (RCLASS_EXT(c)->const_tbl)
#define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
#define RCLASS_IVPTR(c) (RCLASS_EXT(c)->iv_ptr)

Просмотреть файл

@ -189,9 +189,6 @@ struct rb_objspace; /* in vm_core.h */
# define SIZE_POOL_COUNT 5
#endif
// TODO: Make rb_classext_t small enough to fit in 80 bytes on 32 bit
#define RCLASS_EXT_EMBEDDED (SIZEOF_UINT64_T == SIZEOF_VALUE)
typedef struct ractor_newobj_size_pool_cache {
struct RVALUE *freelist;
struct heap_page *using_page;