@@ -37,8 +37,6 @@ static ID id_frozen;
37
37
static ID id_t_object ;
38
38
ID ruby_internal_object_id ; // extern
39
39
40
- static const attr_index_t * shape_capacities = NULL ;
41
-
42
40
#define LEAF 0
43
41
#define BLACK 0x0
44
42
#define RED 0x1
@@ -497,7 +495,7 @@ redblack_cache_ancestors(rb_shape_t *shape)
497
495
static attr_index_t
498
496
shape_grow_capa (attr_index_t current_capa )
499
497
{
500
- const attr_index_t * capacities = shape_capacities ;
498
+ const attr_index_t * capacities = GET_SHAPE_TREE () -> capacities ;
501
499
502
500
// First try to use the next size that will be embeddable in a larger object slot.
503
501
attr_index_t capa ;
@@ -532,7 +530,6 @@ rb_shape_alloc_new_child(ID id, rb_shape_t *shape, enum shape_type shape_type)
532
530
}
533
531
break ;
534
532
case SHAPE_ROOT :
535
- case SHAPE_T_OBJECT :
536
533
rb_bug ("Unreachable" );
537
534
break ;
538
535
}
@@ -858,7 +855,6 @@ shape_get_iv_index(rb_shape_t *shape, ID id, attr_index_t *value)
858
855
* value = shape -> next_field_index - 1 ;
859
856
return true;
860
857
case SHAPE_ROOT :
861
- case SHAPE_T_OBJECT :
862
858
return false;
863
859
case SHAPE_OBJ_ID :
864
860
rb_bug ("Ivar should not exist on transition" );
@@ -1070,7 +1066,7 @@ rb_shape_id_offset(void)
1070
1066
static rb_shape_t *
1071
1067
shape_traverse_from_new_root (rb_shape_t * initial_shape , rb_shape_t * dest_shape )
1072
1068
{
1073
- RUBY_ASSERT (initial_shape -> type == SHAPE_T_OBJECT );
1069
+ RUBY_ASSERT (initial_shape -> type == SHAPE_ROOT );
1074
1070
rb_shape_t * next_shape = initial_shape ;
1075
1071
1076
1072
if (dest_shape -> type != initial_shape -> type ) {
@@ -1107,7 +1103,6 @@ shape_traverse_from_new_root(rb_shape_t *initial_shape, rb_shape_t *dest_shape)
1107
1103
}
1108
1104
break ;
1109
1105
case SHAPE_ROOT :
1110
- case SHAPE_T_OBJECT :
1111
1106
break ;
1112
1107
}
1113
1108
@@ -1133,7 +1128,7 @@ shape_rebuild(rb_shape_t *initial_shape, rb_shape_t *dest_shape)
1133
1128
{
1134
1129
rb_shape_t * midway_shape ;
1135
1130
1136
- RUBY_ASSERT (initial_shape -> type == SHAPE_T_OBJECT || initial_shape -> type == SHAPE_ROOT );
1131
+ RUBY_ASSERT (initial_shape -> type == SHAPE_ROOT );
1137
1132
1138
1133
if (dest_shape -> type != initial_shape -> type ) {
1139
1134
midway_shape = shape_rebuild (initial_shape , RSHAPE (dest_shape -> parent_id ));
@@ -1151,7 +1146,6 @@ shape_rebuild(rb_shape_t *initial_shape, rb_shape_t *dest_shape)
1151
1146
break ;
1152
1147
case SHAPE_OBJ_ID :
1153
1148
case SHAPE_ROOT :
1154
- case SHAPE_T_OBJECT :
1155
1149
break ;
1156
1150
}
1157
1151
@@ -1279,8 +1273,18 @@ rb_shape_verify_consistency(VALUE obj, shape_id_t shape_id)
1279
1273
}
1280
1274
1281
1275
uint8_t flags_heap_index = rb_shape_heap_index (shape_id );
1282
- if (flags_heap_index != shape -> heap_index ) {
1283
- rb_bug ("shape_id heap_index flags mismatch: flags=%u, transition=%u\n" , flags_heap_index , shape -> heap_index );
1276
+ if (RB_TYPE_P (obj , T_OBJECT )) {
1277
+ size_t shape_id_slot_size = GET_SHAPE_TREE ()-> capacities [flags_heap_index - 1 ] * sizeof (VALUE ) + sizeof (struct RBasic );
1278
+ size_t actual_slot_size = rb_gc_obj_slot_size (obj );
1279
+
1280
+ if (shape_id_slot_size != actual_slot_size ) {
1281
+ rb_bug ("shape_id heap_index flags mismatch: shape_id_slot_size=%lu, gc_slot_size=%lu\n" , shape_id_slot_size , actual_slot_size );
1282
+ }
1283
+ }
1284
+ else {
1285
+ if (flags_heap_index ) {
1286
+ rb_bug ("shape_id indicate heap_index > 0 but objet is not T_OBJECT: %s" , rb_obj_info (obj ));
1287
+ }
1284
1288
}
1285
1289
1286
1290
return true;
@@ -1339,7 +1343,7 @@ shape_id_t_to_rb_cShape(shape_id_t shape_id)
1339
1343
INT2NUM (shape -> next_field_index ),
1340
1344
INT2NUM (shape -> heap_index ),
1341
1345
INT2NUM (shape -> type ),
1342
- INT2NUM (shape -> capacity ));
1346
+ INT2NUM (RSHAPE_CAPACITY ( shape_id ) ));
1343
1347
rb_obj_freeze (obj );
1344
1348
return obj ;
1345
1349
}
@@ -1509,7 +1513,7 @@ Init_default_shapes(void)
1509
1513
for (index = 0 ; index < heaps_count ; index ++ ) {
1510
1514
capacities [index ] = (heap_sizes [index ] - sizeof (struct RBasic )) / sizeof (VALUE );
1511
1515
}
1512
- shape_capacities = capacities ;
1516
+ GET_SHAPE_TREE () -> capacities = capacities ;
1513
1517
1514
1518
#ifdef HAVE_MMAP
1515
1519
size_t shape_list_mmap_size = rb_size_mul_or_raise (SHAPE_BUFFER_SIZE , sizeof (rb_shape_t ), rb_eRuntimeError );
@@ -1568,33 +1572,12 @@ Init_default_shapes(void)
1568
1572
root_with_obj_id -> next_field_index ++ ;
1569
1573
root_with_obj_id -> heap_index = 0 ;
1570
1574
RUBY_ASSERT (raw_shape_id (root_with_obj_id ) == ROOT_SHAPE_WITH_OBJ_ID );
1571
-
1572
- // Make shapes for T_OBJECT
1573
- size_t * sizes = rb_gc_heap_sizes ();
1574
- int i ;
1575
- for (i = 0 ; sizes [i ] > 0 ; i ++ ) {
1576
- rb_shape_t * t_object_shape = rb_shape_alloc_with_parent_id (0 , INVALID_SHAPE_ID );
1577
- t_object_shape -> type = SHAPE_T_OBJECT ;
1578
- t_object_shape -> heap_index = i + 1 ;
1579
- t_object_shape -> capacity = (uint32_t )((sizes [i ] - offsetof(struct RObject , as .ary )) / sizeof (VALUE ));
1580
- t_object_shape -> edges = rb_managed_id_table_new (256 );
1581
- t_object_shape -> ancestor_index = LEAF ;
1582
- RUBY_ASSERT (t_object_shape == RSHAPE (rb_shape_root (i )));
1583
- }
1584
-
1585
- // Prebuild all ROOT + OBJ_ID shapes so that even when we run out of shape we can always transtion to
1586
- // COMPLEX + OBJ_ID.
1587
- bool dont_care ;
1588
- for (i = 0 ; sizes [i ] > 0 ; i ++ ) {
1589
- get_next_shape_internal (RSHAPE (rb_shape_root (i )), ruby_internal_object_id , SHAPE_OBJ_ID , & dont_care , true);
1590
- }
1591
1575
}
1592
1576
1593
1577
void
1594
1578
rb_shape_free_all (void )
1595
1579
{
1596
- xfree ((void * )shape_capacities );
1597
- shape_capacities = NULL ;
1580
+ xfree ((void * )GET_SHAPE_TREE ()-> capacities );
1598
1581
xfree (GET_SHAPE_TREE ());
1599
1582
}
1600
1583
@@ -1624,11 +1607,9 @@ Init_shape(void)
1624
1607
1625
1608
rb_define_const (rb_cShape , "SHAPE_ROOT" , INT2NUM (SHAPE_ROOT ));
1626
1609
rb_define_const (rb_cShape , "SHAPE_IVAR" , INT2NUM (SHAPE_IVAR ));
1627
- rb_define_const (rb_cShape , "SHAPE_T_OBJECT" , INT2NUM (SHAPE_T_OBJECT ));
1628
1610
rb_define_const (rb_cShape , "SHAPE_ID_NUM_BITS" , INT2NUM (SHAPE_ID_NUM_BITS ));
1629
1611
rb_define_const (rb_cShape , "SHAPE_FLAG_SHIFT" , INT2NUM (SHAPE_FLAG_SHIFT ));
1630
1612
rb_define_const (rb_cShape , "SPECIAL_CONST_SHAPE_ID" , INT2NUM (SPECIAL_CONST_SHAPE_ID ));
1631
- rb_define_const (rb_cShape , "FIRST_T_OBJECT_SHAPE_ID" , INT2NUM (FIRST_T_OBJECT_SHAPE_ID ));
1632
1613
rb_define_const (rb_cShape , "SHAPE_MAX_VARIATIONS" , INT2NUM (SHAPE_MAX_VARIATIONS ));
1633
1614
rb_define_const (rb_cShape , "SIZEOF_RB_SHAPE_T" , INT2NUM (sizeof (rb_shape_t )));
1634
1615
rb_define_const (rb_cShape , "SIZEOF_REDBLACK_NODE_T" , INT2NUM (sizeof (redblack_node_t )));
0 commit comments