From c726c48a3dacd9ca1cb0d96fee98890cb74b37d3 Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Tue, 8 Nov 2022 14:09:43 -0500 Subject: Remove numiv from RObject Since object shapes store the capacity of an object, we no longer need the numiv field on RObjects. This gives us one extra slot which we can use to give embedded objects one more instance variable (for a total of 3 ivs). This commit removes the concept of numiv from RObject. --- variable.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'variable.c') diff --git a/variable.c b/variable.c index bdde4d9607..2fed1e3512 100644 --- a/variable.c +++ b/variable.c @@ -1346,7 +1346,7 @@ rb_obj_transient_heap_evacuate(VALUE obj, int promote) if (ROBJ_TRANSIENT_P(obj)) { assert(!RB_FL_TEST_RAW(obj, ROBJECT_EMBED)); - uint32_t len = ROBJECT_NUMIV(obj); + uint32_t len = ROBJECT_IV_CAPACITY(obj); const VALUE *old_ptr = ROBJECT_IVPTR(obj); VALUE *new_ptr; @@ -1378,7 +1378,6 @@ rb_ensure_iv_list_size(VALUE obj, uint32_t current_capacity, uint32_t new_capaci else { newptr = obj_ivar_heap_realloc(obj, current_capacity, new_capacity); } - ROBJECT_SET_NUMIV(obj, new_capacity); } struct gen_ivtbl * @@ -1405,21 +1404,14 @@ rb_ensure_generic_iv_list_size(VALUE obj, uint32_t newsize) rb_shape_t * rb_grow_iv_list(VALUE obj) { - uint32_t len = ROBJECT_NUMIV(obj); + rb_shape_t * initial_shape = rb_shape_get_shape(obj); + uint32_t len = initial_shape->capacity; RUBY_ASSERT(len > 0); uint32_t newsize = (uint32_t)(len * 2); rb_ensure_iv_list_size(obj, len, newsize); - rb_shape_t * res; -#if USE_RVARGC - ROBJECT_SET_NUMIV(obj, newsize); -#else - ROBJECT(obj)->as.heap.numiv = newsize; -#endif - - res = rb_shape_transition_shape_capa(rb_shape_get_shape(obj), newsize); + rb_shape_t * res = rb_shape_transition_shape_capa(initial_shape, newsize); rb_shape_set_shape(obj, res); - RUBY_ASSERT(!RB_TYPE_P(obj, T_OBJECT) || ROBJECT_IV_CAPACITY(obj) == ROBJECT_NUMIV(obj)); return res; } @@ -1437,12 +1429,10 @@ obj_ivar_set(VALUE obj, ID id, VALUE val) found = false; } - uint32_t len = ROBJECT_NUMIV(obj); - // Reallocating can kick off GC. We can't set the new shape // on this object until the buffer has been allocated, otherwise // GC could read off the end of the buffer. - if (len <= index) { + if (shape->capacity <= index) { shape = rb_grow_iv_list(obj); } -- cgit v1.2.3