Fix compilation with RGENGC_CHECK_MODE=2

This commit is contained in:
Peter Zhu 2024-07-03 11:04:56 -04:00
Родитель 786cf9db48
Коммит cbc40aca3a
2 изменённых файлов: 23 добавлений и 23 удалений

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

@ -4180,7 +4180,7 @@ const char *
gc_raw_obj_info_basic(char *const buff, const size_t buff_size, VALUE obj) gc_raw_obj_info_basic(char *const buff, const size_t buff_size, VALUE obj)
{ {
asan_unpoisoning_object(obj) { asan_unpoisoning_object(obj) {
size_t pos = rb_raw_obj_info(buff, buff_size, obj); size_t pos = rb_raw_obj_info_common(buff, buff_size, obj);
if (pos >= buff_size) {} // truncated if (pos >= buff_size) {} // truncated
} }

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

@ -1438,7 +1438,7 @@ gc_object_moved_p(rb_objspace_t *objspace, VALUE obj)
else { else {
void *poisoned = asan_unpoison_object_temporary(obj); void *poisoned = asan_unpoison_object_temporary(obj);
int ret = BUILTIN_TYPE(obj) == T_MOVED; int ret = BUILTIN_TYPE(obj) == T_MOVED;
/* Re-poison slot if it's not the one we want */ /* Re-poison slot if it's not the one we want */
if (poisoned) { if (poisoned) {
GC_ASSERT(BUILTIN_TYPE(obj) == T_NONE); GC_ASSERT(BUILTIN_TYPE(obj) == T_NONE);
@ -1674,7 +1674,7 @@ static const struct st_hash_type object_id_hash_type = {
bool bool
rb_gc_impl_garbage_object_p(void *objspace_ptr, VALUE ptr) rb_gc_impl_garbage_object_p(void *objspace_ptr, VALUE ptr)
{ {
rb_objspace_t * objspace = objspace_ptr; rb_objspace_t *objspace = objspace_ptr;
switch (BUILTIN_TYPE(ptr)) { switch (BUILTIN_TYPE(ptr)) {
case T_NONE: case T_NONE:
@ -2331,6 +2331,16 @@ heap_prepare(rb_objspace_t *objspace, rb_size_pool_t *size_pool, rb_heap_t *heap
GC_ASSERT(heap->free_pages != NULL); GC_ASSERT(heap->free_pages != NULL);
} }
static inline VALUE
newobj_fill(VALUE obj, VALUE v1, VALUE v2, VALUE v3)
{
VALUE *p = (VALUE *)obj;
p[2] = v1;
p[3] = v2;
p[4] = v3;
return obj;
}
static inline VALUE static inline VALUE
newobj_init(VALUE klass, VALUE flags, int wb_protected, rb_objspace_t *objspace, VALUE obj) newobj_init(VALUE klass, VALUE flags, int wb_protected, rb_objspace_t *objspace, VALUE obj)
{ {
@ -2352,7 +2362,7 @@ newobj_init(VALUE klass, VALUE flags, int wb_protected, rb_objspace_t *objspace,
#endif #endif
#if RGENGC_CHECK_MODE #if RGENGC_CHECK_MODE
p->as.values.v1 = p->as.values.v2 = p->as.values.v3 = 0; newobj_fill(obj, 0, 0, 0);
int lev = rb_gc_vm_lock_no_barrier(); int lev = rb_gc_vm_lock_no_barrier();
{ {
@ -2451,7 +2461,7 @@ ractor_cache_allocate_slot(rb_objspace_t *objspace, rb_ractor_newobj_cache_t *ca
size_pool_cache->freelist = p->next; size_pool_cache->freelist = p->next;
asan_unpoison_memory_region(p, stride, true); asan_unpoison_memory_region(p, stride, true);
#if RGENGC_CHECK_MODE #if RGENGC_CHECK_MODE
GC_ASSERT(rb_gc_obj_slot_size(obj) == stride); GC_ASSERT(rb_gc_impl_obj_slot_size(obj) == stride);
// zero clear // zero clear
MEMZERO((char *)obj, char, stride); MEMZERO((char *)obj, char, stride);
#endif #endif
@ -2503,16 +2513,6 @@ ractor_cache_set_page(rb_objspace_t *objspace, rb_ractor_newobj_cache_t *cache,
asan_poison_object((VALUE)size_pool_cache->freelist); asan_poison_object((VALUE)size_pool_cache->freelist);
} }
static inline VALUE
newobj_fill(VALUE obj, VALUE v1, VALUE v2, VALUE v3)
{
VALUE *p = (VALUE *)obj;
p[2] = v1;
p[3] = v2;
p[4] = v3;
return obj;
}
static inline size_t static inline size_t
size_pool_idx_for_size(size_t size) size_pool_idx_for_size(size_t size)
{ {
@ -2604,7 +2604,7 @@ newobj_alloc(rb_objspace_t *objspace, rb_ractor_newobj_cache_t *cache, size_t si
} }
} }
size_pool->total_allocated_objects++; RUBY_ATOMIC_SIZE_ADD(size_pool->total_allocated_objects, 1);
return obj; return obj;
} }
@ -3694,15 +3694,15 @@ gc_sweep_plane(rb_objspace_t *objspace, rb_heap_t *heap, uintptr_t p, bits_t bit
gc_report(2, objspace, "page_sweep: free %p\n", (void *)p); gc_report(2, objspace, "page_sweep: free %p\n", (void *)p);
#if RGENGC_CHECK_MODE #if RGENGC_CHECK_MODE
if (!is_full_marking(objspace)) { if (!is_full_marking(objspace)) {
if (RVALUE_OLD_P(vp)) rb_bug("page_sweep: %p - old while minor GC.", (void *)p); if (RVALUE_OLD_P(objspace, vp)) rb_bug("page_sweep: %p - old while minor GC.", (void *)p);
if (RVALUE_REMEMBERED(vp)) rb_bug("page_sweep: %p - remembered.", (void *)p); if (RVALUE_REMEMBERED(objspace, vp)) rb_bug("page_sweep: %p - remembered.", (void *)p);
} }
#endif #endif
if (RVALUE_WB_UNPROTECTED(objspace, vp)) CLEAR_IN_BITMAP(GET_HEAP_WB_UNPROTECTED_BITS(vp), vp); if (RVALUE_WB_UNPROTECTED(objspace, vp)) CLEAR_IN_BITMAP(GET_HEAP_WB_UNPROTECTED_BITS(vp), vp);
#if RGENGC_CHECK_MODE #if RGENGC_CHECK_MODE
#define CHECK(x) if (x(obj) != FALSE) rb_bug("obj_free: " #x "(%s) != FALSE", rb_obj_info(obj)) #define CHECK(x) if (x(objspace, vp) != FALSE) rb_bug("obj_free: " #x "(%s) != FALSE", rb_obj_info(vp))
CHECK(RVALUE_WB_UNPROTECTED); CHECK(RVALUE_WB_UNPROTECTED);
CHECK(RVALUE_MARKED); CHECK(RVALUE_MARKED);
CHECK(RVALUE_MARKING); CHECK(RVALUE_MARKING);
@ -4603,8 +4603,8 @@ static void
gc_grey(rb_objspace_t *objspace, VALUE obj) gc_grey(rb_objspace_t *objspace, VALUE obj)
{ {
#if RGENGC_CHECK_MODE #if RGENGC_CHECK_MODE
if (RVALUE_MARKED(obj) == FALSE) rb_bug("gc_grey: %s is not marked.", rb_obj_info(obj)); if (RVALUE_MARKED(objspace, obj) == FALSE) rb_bug("gc_grey: %s is not marked.", rb_obj_info(obj));
if (RVALUE_MARKING(obj) == TRUE) rb_bug("gc_grey: %s is marking/remembered.", rb_obj_info(obj)); if (RVALUE_MARKING(objspace, obj) == TRUE) rb_bug("gc_grey: %s is marking/remembered.", rb_obj_info(obj));
#endif #endif
if (is_incremental_marking(objspace)) { if (is_incremental_marking(objspace)) {
@ -9303,8 +9303,8 @@ gc_set_auto_compact(VALUE _, VALUE v)
#if RGENGC_CHECK_MODE #if RGENGC_CHECK_MODE
ruby_autocompact_compare_func = NULL; ruby_autocompact_compare_func = NULL;
if (SYMBOL_P(val)) { if (SYMBOL_P(v)) {
ID id = RB_SYM2ID(val); ID id = RB_SYM2ID(v);
if (id == rb_intern("empty")) { if (id == rb_intern("empty")) {
ruby_autocompact_compare_func = compare_free_slots; ruby_autocompact_compare_func = compare_free_slots;
} }