Move rvalue_overhead out of RVALUE

Since we cannot read the rvalue_overhead out of the RVALUE anyways (since
it is at the end of the slot), it makes more sense to move it out of
the RVALUE.
This commit is contained in:
Peter Zhu 2024-05-01 16:46:51 -04:00
Родитель e34c131ce8
Коммит 6d605f1e50
1 изменённых файлов: 24 добавлений и 21 удалений

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

@ -689,29 +689,32 @@ typedef struct RVALUE {
VALUE v3;
} values;
} as;
/* Start of RVALUE_OVERHEAD.
* Do not directly read these members from the RVALUE as they're located
* at the end of the slot (which may differ in size depending on the size
* pool). */
#if RACTOR_CHECK_MODE
uint32_t _ractor_belonging_id;
#endif
#if GC_DEBUG
const char *file;
int line;
#endif
} RVALUE;
#if RACTOR_CHECK_MODE
# define RVALUE_OVERHEAD (sizeof(RVALUE) - offsetof(RVALUE, _ractor_belonging_id))
#elif GC_DEBUG
# define RVALUE_OVERHEAD (sizeof(RVALUE) - offsetof(RVALUE, file))
/* These members ae located at the end of the slot that the object is in. */
#if RACTOR_CHECK_MODE || GC_DEBUG
struct rvalue_overhead {
# if RACTOR_CHECK_MODE
uint32_t _ractor_belonging_id;
# endif
# if GC_DEBUG
const char *file;
int line;
# endif
};
// Make sure that RVALUE_OVERHEAD aligns to sizeof(VALUE)
# define RVALUE_OVERHEAD (sizeof(struct { \
union { \
struct rvalue_overhead overhead; \
VALUE value; \
}; \
}))
#else
# define RVALUE_OVERHEAD 0
#endif
STATIC_ASSERT(sizeof_rvalue, sizeof(RVALUE) == (SIZEOF_VALUE * 5) + RVALUE_OVERHEAD);
STATIC_ASSERT(sizeof_rvalue, sizeof(RVALUE) == (SIZEOF_VALUE * 5));
STATIC_ASSERT(alignof_rvalue, RUBY_ALIGNOF(RVALUE) == SIZEOF_VALUE);
typedef uintptr_t bits_t;
@ -955,7 +958,7 @@ typedef struct rb_objspace {
#define HEAP_PAGE_ALIGN_LOG 16
#endif
#define BASE_SLOT_SIZE sizeof(RVALUE)
#define BASE_SLOT_SIZE (sizeof(RVALUE) + RVALUE_OVERHEAD)
#define CEILDIV(i, mod) roomof(i, mod)
enum {
@ -3476,7 +3479,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
}
#define OBJ_ID_INCREMENT (sizeof(RVALUE))
#define OBJ_ID_INCREMENT (BASE_SLOT_SIZE)
#define OBJ_ID_INITIAL (OBJ_ID_INCREMENT)
static int
@ -8194,7 +8197,7 @@ gc_compact_plane(rb_objspace_t *objspace, rb_size_pool_t *size_pool, rb_heap_t *
do {
VALUE vp = (VALUE)p;
GC_ASSERT(vp % sizeof(RVALUE) == 0);
GC_ASSERT(vp % BASE_SLOT_SIZE == 0);
if (bitset & 1) {
objspace->rcompactor.considered_count_table[BUILTIN_TYPE(vp)]++;
@ -13652,7 +13655,7 @@ Init_GC(void)
rb_hash_aset(gc_constants, ID2SYM(rb_intern("DEBUG")), RBOOL(GC_DEBUG));
rb_hash_aset(gc_constants, ID2SYM(rb_intern("BASE_SLOT_SIZE")), SIZET2NUM(BASE_SLOT_SIZE - RVALUE_OVERHEAD));
rb_hash_aset(gc_constants, ID2SYM(rb_intern("RVALUE_OVERHEAD")), SIZET2NUM(RVALUE_OVERHEAD));
rb_hash_aset(gc_constants, ID2SYM(rb_intern("RVALUE_SIZE")), SIZET2NUM(sizeof(RVALUE)));
rb_hash_aset(gc_constants, ID2SYM(rb_intern("RVALUE_SIZE")), SIZET2NUM(BASE_SLOT_SIZE));
rb_hash_aset(gc_constants, ID2SYM(rb_intern("HEAP_PAGE_OBJ_LIMIT")), SIZET2NUM(HEAP_PAGE_OBJ_LIMIT));
rb_hash_aset(gc_constants, ID2SYM(rb_intern("HEAP_PAGE_BITMAP_SIZE")), SIZET2NUM(HEAP_PAGE_BITMAP_SIZE));
rb_hash_aset(gc_constants, ID2SYM(rb_intern("HEAP_PAGE_SIZE")), SIZET2NUM(HEAP_PAGE_SIZE));