@@ -375,11 +375,11 @@ rb_gc_shutdown_call_finalizer_p(VALUE obj)
375375}
376376
377377void
378- rb_gc_obj_changed_pool (VALUE obj , size_t heap_id )
378+ rb_gc_obj_changed_slot_size (VALUE obj , size_t slot_size )
379379{
380380 RUBY_ASSERT (RB_TYPE_P (obj , T_OBJECT ));
381381
382- RBASIC_SET_SHAPE_ID (obj , rb_obj_shape_transition_heap (obj , heap_id ));
382+ RBASIC_SET_SHAPE_ID_WITH_CAPACITY (obj , rb_obj_shape_transition_capacity (obj , rb_shape_capacity_for_slot_size ( slot_size ) ));
383383}
384384
385385void rb_vm_update_references (void * ptr );
@@ -604,7 +604,6 @@ typedef struct gc_function_map {
604604 void * (* ractor_cache_alloc )(void * objspace_ptr , void * ractor );
605605 void (* set_params )(void * objspace_ptr );
606606 void (* init )(void );
607- size_t * (* heap_sizes )(void * objspace_ptr );
608607 // Shutdown
609608 void (* shutdown_free_objects )(void * objspace_ptr );
610609 void (* objspace_free )(void * objspace_ptr );
@@ -622,9 +621,9 @@ typedef struct gc_function_map {
622621 VALUE (* stress_get )(void * objspace_ptr );
623622 struct rb_gc_vm_context * (* get_vm_context )(void * objspace_ptr );
624623 // Object allocation
625- VALUE (* new_obj )(void * objspace_ptr , void * cache_ptr , VALUE klass , VALUE flags , bool wb_protected , size_t alloc_size );
624+ VALUE (* new_obj )(void * objspace_ptr , void * cache_ptr , VALUE klass , VALUE flags , bool wb_protected , size_t alloc_size , size_t * actual_alloc_size );
626625 size_t (* obj_slot_size )(VALUE obj );
627- size_t (* heap_id_for_size )(void * objspace_ptr , size_t size );
626+ size_t (* size_slot_size )(void * objspace_ptr , size_t size );
628627 bool (* size_allocatable_p )(size_t size );
629628 // Malloc
630629 void * (* malloc )(void * objspace_ptr , size_t size , bool gc_allowed );
@@ -783,7 +782,6 @@ ruby_modular_gc_init(void)
783782 load_modular_gc_func (ractor_cache_alloc );
784783 load_modular_gc_func (set_params );
785784 load_modular_gc_func (init );
786- load_modular_gc_func (heap_sizes );
787785 // Shutdown
788786 load_modular_gc_func (shutdown_free_objects );
789787 load_modular_gc_func (objspace_free );
@@ -803,7 +801,7 @@ ruby_modular_gc_init(void)
803801 // Object allocation
804802 load_modular_gc_func (new_obj );
805803 load_modular_gc_func (obj_slot_size );
806- load_modular_gc_func (heap_id_for_size );
804+ load_modular_gc_func (size_slot_size );
807805 load_modular_gc_func (size_allocatable_p );
808806 // Malloc
809807 load_modular_gc_func (malloc );
@@ -871,7 +869,6 @@ ruby_modular_gc_init(void)
871869# define rb_gc_impl_ractor_cache_alloc rb_gc_functions.ractor_cache_alloc
872870# define rb_gc_impl_set_params rb_gc_functions.set_params
873871# define rb_gc_impl_init rb_gc_functions.init
874- # define rb_gc_impl_heap_sizes rb_gc_functions.heap_sizes
875872// Shutdown
876873# define rb_gc_impl_shutdown_free_objects rb_gc_functions.shutdown_free_objects
877874# define rb_gc_impl_objspace_free rb_gc_functions.objspace_free
@@ -891,7 +888,7 @@ ruby_modular_gc_init(void)
891888// Object allocation
892889# define rb_gc_impl_new_obj rb_gc_functions.new_obj
893890# define rb_gc_impl_obj_slot_size rb_gc_functions.obj_slot_size
894- # define rb_gc_impl_heap_id_for_size rb_gc_functions.heap_id_for_size
891+ # define rb_gc_impl_size_slot_size rb_gc_functions.size_slot_size
895892# define rb_gc_impl_size_allocatable_p rb_gc_functions.size_allocatable_p
896893// Malloc
897894# define rb_gc_impl_malloc rb_gc_functions.malloc
@@ -1033,7 +1030,11 @@ rb_newobj(rb_execution_context_t *ec, VALUE klass, VALUE flags, shape_id_t shape
10331030{
10341031 GC_ASSERT ((flags & FL_WB_PROTECTED ) == 0 );
10351032 rb_ractor_t * cr = rb_ec_ractor_ptr (ec );
1036- VALUE obj = rb_gc_impl_new_obj (rb_gc_get_objspace (), cr -> newobj_cache , klass , flags , wb_protected , size );
1033+ size_t actual_alloc_size ;
1034+ VALUE obj = rb_gc_impl_new_obj (rb_gc_get_objspace (), cr -> newobj_cache , klass , flags , wb_protected , size , & actual_alloc_size );
1035+
1036+ GC_ASSERT (actual_alloc_size >= size );
1037+ shape_id = (shape_id & ~SHAPE_ID_CAPACITY_MASK ) | rb_shape_id_with_capacity (rb_shape_capacity_for_slot_size (actual_alloc_size ));
10371038
10381039#if RACTOR_CHECK_MODE
10391040 void rb_ractor_setup_belonging (VALUE obj );
@@ -1092,7 +1093,7 @@ rb_newobj_of(VALUE klass, VALUE flags, size_t size)
10921093static
10931094VALUE class_allocate_complex_instance (VALUE klass , uint32_t capacity )
10941095{
1095- shape_id_t initial_shape_id = rb_shape_id_with_robject_layout (rb_shape_root ( rb_gc_heap_id_for_size ( sizeof ( struct RObject ))) );
1096+ shape_id_t initial_shape_id = rb_shape_id_with_robject_layout (0 );
10961097 VALUE obj = rb_newobj_of_with_shape (klass , T_OBJECT , initial_shape_id , sizeof (struct RObject ));
10971098 rb_obj_init_complex (obj , rb_st_init_numtable_with_size (capacity ));
10981099 return obj ;
@@ -1105,8 +1106,8 @@ rb_class_allocate_instance(VALUE klass)
11051106 VALUE obj ;
11061107
11071108 // Directly start as COMPLEX if we know we're over the limit.
1108- RUBY_ASSERT (rb_shape_tree . max_capacity > 0 );
1109- if (RB_UNLIKELY (index_tbl_num_entries > rb_shape_tree . max_capacity )) {
1109+ RUBY_ASSERT (SHAPE_MAX_CAPACITY > 0 );
1110+ if (RB_UNLIKELY (index_tbl_num_entries > SHAPE_MAX_CAPACITY )) {
11101111 obj = class_allocate_complex_instance (klass , index_tbl_num_entries );
11111112 }
11121113 else {
@@ -1117,7 +1118,7 @@ rb_class_allocate_instance(VALUE klass)
11171118
11181119 // There might be a NEWOBJ tracepoint callback, and it may set fields.
11191120 // So the shape must be passed to `NEWOBJ_OF`.
1120- obj = rb_newobj_of_with_shape (klass , T_OBJECT , rb_shape_id_with_robject_layout (rb_shape_root ( rb_gc_heap_id_for_size ( size )) ), size );
1121+ obj = rb_newobj_of_with_shape (klass , T_OBJECT , rb_shape_id_with_robject_layout (0 ), size );
11211122
11221123 #if RUBY_DEBUG
11231124 VALUE * ptr = ROBJECT_FIELDS (obj );
@@ -2187,7 +2188,6 @@ object_id0(VALUE obj)
21872188 id = generate_next_object_id ();
21882189 rb_obj_field_set (obj , object_id_shape_id , 0 , id );
21892190
2190- RUBY_ASSERT (RBASIC_SHAPE_ID (obj ) == object_id_shape_id );
21912191 RUBY_ASSERT (rb_obj_shape_has_id (obj ));
21922192
21932193 if (RB_UNLIKELY (id2ref_tbl )) {
@@ -3989,9 +3989,9 @@ rb_gc_prepare_heap(void)
39893989}
39903990
39913991size_t
3992- rb_gc_heap_id_for_size (size_t size )
3992+ rb_gc_size_slot_size (size_t size )
39933993{
3994- return rb_gc_impl_heap_id_for_size (rb_gc_get_objspace (), size );
3994+ return rb_gc_impl_size_slot_size (rb_gc_get_objspace (), size );
39953995}
39963996
39973997bool
@@ -4704,12 +4704,6 @@ rb_gc_initial_stress_set(VALUE flag)
47044704 initial_stress = flag ;
47054705}
47064706
4707- size_t *
4708- rb_gc_heap_sizes (void )
4709- {
4710- return rb_gc_impl_heap_sizes (rb_gc_get_objspace ());
4711- }
4712-
47134707VALUE
47144708rb_gc_enable (void )
47154709{
0 commit comments