8000 Reduce OBJ_TOO_COMPLEX_SHAPE_ID usage · ruby/ruby@af67723 · GitHub
[go: up one dir, main page]

Skip to content

Commit af67723

Browse files
committed
Reduce OBJ_TOO_COMPLEX_SHAPE_ID usage
Right now everything assume only one shape is too_complex. In the near future I'd like to have more than one complex shape, e.g. frozen and too_complex.
1 parent 9231df3 commit af67723

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

gc.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,13 @@ rb_gc_set_shape(VALUE obj, uint32_t shape_id)
379379
uint32_t
380380
rb_gc_rebuild_shape(VALUE obj, size_t heap_id)
381381
{
382-
rb_shape_t *orig_shape = rb_shape_get_shape(obj);
382+
shape_id_t orig_shape_id = rb_shape_get_shape_id(obj);
383383

384-
if (rb_shape_obj_too_complex(obj)) return (uint32_t)OBJ_TOO_COMPLEX_SHAPE_ID;
384+
if (rb_shape_id_too_complex_p(orig_shape_id)) {
385+
return (uint32_t)orig_shape_id;
386+
}
385387

388+
rb_shape_t *orig_shape = rb_shape_get_shape_by_id(orig_shape_id);
386389
rb_shape_t *initial_shape = rb_shape_get_shape_by_id((shape_id_t)(heap_id + FIRST_T_OBJECT_SHAPE_ID));
387390
rb_shape_t *new_shape = rb_shape_traverse_from_new_root(initial_shape, orig_shape);
388391

object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ rb_obj_copy_ivar(VALUE dest, VALUE obj)
357357
RUBY_ASSERT(initial_shape->type == SHAPE_T_OBJECT);
358358

359359
shape_to_set_on_dest = rb_shape_rebuild_shape(initial_shape, src_shape);
360-
if (UNLIKELY(rb_shape_id(shape_to_set_on_dest) == OBJ_TOO_COMPLEX_SHAPE_ID)) {
360+
if (UNLIKELY(rb_shape_too_complex_p(shape_to_set_on_dest))) {
361361
st_table * table = rb_st_init_numtable_with_size(src_num_ivs);
362362
rb_obj_copy_ivs_to_hash_table(obj, table);
363363
rb_obj_init_too_complex(dest, table);
@@ -366,7 +366,7 @@ rb_obj_copy_ivar(VALUE dest, VALUE obj)
366366
}
367367
}
368368

369-
RUBY_ASSERT(src_num_ivs <= shape_to_set_on_dest->capacity || rb_shape_id(shape_to_set_on_dest) == OBJ_TOO_COMPLEX_SHAPE_ID);
369+
RUBY_ASSERT(src_num_ivs <= shape_to_set_on_dest->capacity || rb_shape_too_complex_p(shape_to_set_on_dest));
370370
if (initial_shape->capacity < shape_to_set_on_dest->capacity) {
371371
rb_ensure_iv_list_size(dest, initial_shape->capacity, shape_to_set_on_dest->capacity);
372372
dest_buf = ROBJECT_IVPTR(dest);

shape.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ get_next_shape_internal(rb_shape_t *shape, ID id, enum shape_type shape_type, bo
507507
rb_shape_t *res = NULL;
508508

509509
// There should never be outgoing edges from "too complex"
510-
RUBY_ASSERT(rb_shape_id(shape) != OBJ_TOO_COMPLEX_SHAPE_ID);
510+
RUBY_ASSERT(!rb_shape_too_complex_p(shape));
511511

512512
*variation_created = false;
513513

shape.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,18 @@ rb_shape_canonical_p(rb_shape_t *shape)
181181
return !shape->flags;
182182
}
183183

184+
static inline bool
185+
rb_shape_id_too_complex_p(shape_id_t shape_id)
186+
{
187+
return shape_id == OBJ_TOO_COMPLEX_SHAPE_ID;
188+
}
189+
190+
static inline bool
191+
rb_shape_too_complex_p(rb_shape_t *shape)
192+
{
193+
return shape == rb_shape_get_shape_by_id(OBJ_TOO_COMPLEX_SHAPE_ID);
194+
}
195+
184196
static inline uint32_t
185197
ROBJECT_FIELDS_CAPACITY(VALUE obj)
186198
{

vm_insnhelper.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_call
12891289
}
12901290

12911291
if (LIKELY(cached_id == shape_id)) {
1292-
RUBY_ASSERT(cached_id != OBJ_TOO_COMPLEX_SHAPE_ID);
1292+
RUBY_ASSERT(!rb_shape_id_too_complex_p(cached_id));
12931293

12941294
if (index == ATTR_INDEX_NOT_SET) {
12951295
return default_value;
@@ -1330,7 +1330,7 @@ vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_call
13301330
}
13311331
#endif
13321332

1333-
if (shape_id == OBJ_TOO_COMPLEX_SHAPE_ID) {
1333+
if (rb_shape_id_too_complex_p(shape_id)) {
13341334
st_table *table = NULL;
13351335
switch (BUILTIN_TYPE(obj)) {
13361336
case T_CLASS:
@@ -1408,7 +1408,7 @@ vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_call
14081408
static void
14091409
populate_cache(attr_index_t index, shape_id_t next_shape_id, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_callcache *cc, bool is_attr)
14101410
{
1411-
RUBY_ASSERT(next_shape_id != OBJ_TOO_COMPLEX_SHAPE_ID);
1411+
RUBY_ASSERT(!rb_shape_id_too_complex_p(next_shape_id));
14121412

14131413
// Cache population code
14141414
if (is_attr) {
@@ -1436,7 +1436,7 @@ vm_setivar_slowpath(VALUE obj, ID id, VALUE val, const rb_iseq_t *iseq, IVC ic,
14361436

14371437
shape_id_t next_shape_id = ROBJECT_SHAPE_ID(obj);
14381438

1439-
if (next_shape_id != OBJ_TOO_COMPLEX_SHAPE_ID) {
1439+
if (!rb_shape_id_too_complex_p(next_shape_id)) {
14401440
populate_cache(index, next_shape_id, id, iseq, ic, cc, is_attr);
14411441
}
14421442

@@ -1517,7 +1517,7 @@ vm_setivar(VALUE obj, ID id, VALUE val, shape_id_t dest_shape_id, attr_index_t i
15171517
VM_ASSERT(!rb_ractor_shareable_p(obj) || rb_obj_frozen_p(obj));
15181518

15191519
shape_id_t shape_id = ROBJECT_SHAPE_ID(obj);
1520-
RUBY_ASSERT(dest_shape_id != OBJ_TOO_COMPLEX_SHAPE_ID);
1520+
RUBY_ASSERT(!rb_shape_id_too_complex_p(dest_shape_id));
15211521

15221522
if (LIKELY(shape_id == dest_shape_id)) {
15231523
RUBY_ASSERT(dest_shape_id != INVALID_SHAPE_ID && shape_id != INVALID_SHAPE_ID);

0 commit comments

Comments
 (0)
0