@@ -2895,8 +2895,7 @@ rb_class_instance_allocate_internal(VALUE klass, VALUE flags, bool wb_protected)
28952895 GC_ASSERT ((flags & RUBY_T_MASK ) == T_OBJECT );
28962896 GC_ASSERT (flags & ROBJECT_EMBED );
28972897
2898- st_table * index_tbl = RCLASS_IV_INDEX_TBL (klass );
2899- uint32_t index_tbl_num_entries = index_tbl == NULL ? 0 : (uint32_t )index_tbl -> num_entries ;
2898+ uint32_t index_tbl_num_entries = RCLASS_EXT (klass )-> max_iv_count ;
29002899
29012900 size_t size ;
29022901 bool embed = true;
@@ -2931,7 +2930,7 @@ rb_class_instance_allocate_internal(VALUE klass, VALUE flags, bool wb_protected)
29312930#endif
29322931 }
29332932 else {
2934- rb_init_iv_list (obj );
2933+ rb_ensure_iv_list_size (obj , 0 , index_tbl_num_entries );
29352934 }
29362935
29372936 return obj ;
@@ -3206,20 +3205,6 @@ rb_free_const_table(struct rb_id_table *tbl)
32063205 rb_id_table_free (tbl );
32073206}
32083207
3209- static int
3210- free_iv_index_tbl_free_i (st_data_t key , st_data_t value , st_data_t data )
3211- {
3212- xfree ((void * )value );
3213- return ST_CONTINUE ;
3214- }
3215-
3216- static void
3217- iv_index_tbl_free (struct st_table * tbl )
3218- {
3219- st_foreach (tbl , free_iv_index_tbl_free_i , 0 );
3220- st_free_table (tbl );
3221- }
3222-
32233208// alive: if false, target pointers can be freed already.
32243209// To check it, we need objspace parameter.
32253210static void
@@ -3435,6 +3420,16 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
34353420 RB_DEBUG_COUNTER_INC (obj_obj_transient );
34363421 }
34373422 else {
3423+ rb_shape_t * shape = rb_shape_get_shape_by_id (ROBJECT_SHAPE_ID (obj ));
3424+ if (shape ) {
3425+ VALUE klass = RBASIC_CLASS (obj );
3426+
3427+ // Increment max_iv_count if applicable, used to determine size pool allocation
3428+ uint32_t num_of_ivs = shape -> iv_count ;
3429+ if (RCLASS_EXT (klass )-> max_iv_count < num_of_ivs ) {
3430+ RCLASS_EXT (klass )-> max_iv_count = num_of_ivs ;
3431+ }
3432+ }
34383433 xfree (RANY (obj )-> as .object .as .heap .ivptr );
34393434 RB_DEBUG_COUNTER_INC (obj_obj_ptr );
34403435 }
@@ -3449,9 +3444,6 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
34493444 if (RCLASS_CONST_TBL (obj )) {
34503445 rb_free_const_table (RCLASS_CONST_TBL (obj ));
34513446 }
3452- if (RCLASS_IV_INDEX_TBL (obj )) {
3453- iv_index_tbl_free (RCLASS_IV_INDEX_TBL (obj ));
3454- }
34553447 if (RCLASS_CVC_TBL (obj )) {
34563448 rb_id_table_foreach_values (RCLASS_CVC_TBL (obj ), cvar_table_free_i , NULL );
34573449 rb_id_table_free (RCLASS_CVC_TBL (obj ));
@@ -4873,10 +4865,6 @@ obj_memsize_of(VALUE obj, int use_all_types)
48734865 if (RCLASS_CVC_TBL (obj )) {
48744866 size += rb_id_table_memsize (RCLASS_CVC_TBL (obj ));
48754867 }
4876- if (RCLASS_IV_INDEX_TBL (obj )) {
4877- // TODO: more correct value
4878- size += st_memsize (RCLASS_IV_INDEX_TBL (obj ));
4879- }
48804868 if (RCLASS_EXT (obj )-> iv_tbl ) {
48814869 size += st_memsize (RCLASS_EXT (obj )-> iv_tbl );
48824870 }
@@ -10408,27 +10396,13 @@ update_subclass_entries(rb_objspace_t *objspace, rb_subclass_entry_t *entry)
1040810396 }
1040910397}
1041010398
10411- static int
10412- update_iv_index_tbl_i (st_data_t key , st_data_t value , st_data_t arg )
10413- {
10414- rb_objspace_t * objspace = (rb_objspace_t * )arg ;
10415- struct rb_iv_index_tbl_entry * ent = (struct rb_iv_index_tbl_entry * )value ;
10416- UPDATE_IF_MOVED (objspace , ent -> class_value );
10417- return ST_CONTINUE ;
10418- }
10419-
1042010399static void
1042110400update_class_ext (rb_objspace_t * objspace , rb_classext_t * ext )
1042210401{
1042310402 UPDATE_IF_MOVED (objspace , ext -> origin_ );
1042410403 UPDATE_IF_MOVED (objspace , ext -> includer );
1042510404 UPDATE_IF_MOVED (objspace , ext -> refined_class );
1042610405 update_subclass_entries (objspace , ext -> subclasses );
10427-
10428- // ext->iv_index_tbl
10429- if (ext -> iv_index_tbl ) {
10430- st_foreach (ext -> iv_index_tbl , update_iv_index_tbl_i , (st_data_t )objspace );
10431- }
1043210406}
1043310407
1043410408static void
0 commit comments