Skip to content

Commit 13bd617

Browse files
Remove unused class serial
Before object shapes, we were using class serial to invalidate inline caches. Now that we use shape_id for inline cache keys, the class serial is unnecessary. Co-Authored-By: Aaron Patterson <[email protected]>
1 parent 87bb0be commit 13bd617

File tree

7 files changed

+3
-57
lines changed

7 files changed

+3
-57
lines changed

class.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ class_alloc(VALUE flags, VALUE klass)
208208

209209
#if USE_RVARGC
210210
memset(RCLASS_EXT(obj), 0, sizeof(rb_classext_t));
211-
# if SIZEOF_SERIAL_T != SIZEOF_VALUE
212-
RCLASS(obj)->class_serial_ptr = ZALLOC(rb_serial_t);
213-
# endif
214211
#else
215212
obj->ptr = ZALLOC(rb_classext_t);
216213
#endif
@@ -226,7 +223,6 @@ class_alloc(VALUE flags, VALUE klass)
226223
RCLASS_MODULE_SUBCLASSES(obj) = NULL;
227224
*/
228225
RCLASS_SET_ORIGIN((VALUE)obj, (VALUE)obj);
229-
RCLASS_SERIAL(obj) = rb_next_class_serial();
230226
RB_OBJ_WRITE(obj, &RCLASS_REFINED_CLASS(obj), Qnil);
231227
RCLASS_ALLOCATOR(obj) = 0;
232228

@@ -2143,9 +2139,7 @@ singleton_class_of(VALUE obj)
21432139
klass = METACLASS_OF(obj);
21442140
if (!(FL_TEST(klass, FL_SINGLETON) &&
21452141
rb_attr_get(klass, id_attached) == obj)) {
2146-
rb_serial_t serial = RCLASS_SERIAL(klass);
21472142
klass = rb_make_metaclass(obj, klass);
2148-
RCLASS_SERIAL(klass) = serial;
21492143
}
21502144

21512145
RB_FL_SET_RAW(klass, RB_OBJ_FROZEN_RAW(obj));

gc.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3463,9 +3463,6 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
34633463
if (FL_TEST_RAW(obj, RCLASS_SUPERCLASSES_INCLUDE_SELF)) {
34643464
xfree(RCLASS_SUPERCLASSES(obj));
34653465
}
3466-
#if SIZEOF_SERIAL_T != SIZEOF_VALUE && USE_RVARGC
3467-
xfree(RCLASS(obj)->class_serial_ptr);
3468-
#endif
34693466

34703467
#if !USE_RVARGC
34713468
if (RCLASS_EXT(obj))

internal/class.h

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ struct rb_cvar_class_tbl_entry {
4040

4141
struct rb_classext_struct {
4242
struct st_table *iv_tbl;
43-
#if SIZEOF_SERIAL_T == SIZEOF_VALUE /* otherwise m_tbl is in struct RClass */
44-
struct rb_id_table *m_tbl;
45-
#endif
4643
struct rb_id_table *const_tbl;
4744
struct rb_id_table *callable_m_tbl;
4845
struct rb_id_table *cc_tbl; /* ID -> [[ci, cc1], cc2, ...] */
@@ -57,9 +54,6 @@ struct rb_classext_struct {
5754
* included. Hopefully that makes sense.
5855
*/
5956
struct rb_subclass_entry *module_subclass_entry;
60-
#if SIZEOF_SERIAL_T != SIZEOF_VALUE && !USE_RVARGC /* otherwise class_serial is in struct RClass */
61-
rb_serial_t class_serial;
62-
#endif
6357
const VALUE origin_;
6458
const VALUE refined_class;
6559
rb_alloc_func_t allocator;
@@ -73,19 +67,10 @@ struct rb_classext_struct {
7367
struct RClass {
7468
struct RBasic basic;
7569
VALUE super;
70+
struct rb_id_table *m_tbl;
7671
#if !USE_RVARGC
7772
struct rb_classext_struct *ptr;
7873
#endif
79-
#if SIZEOF_SERIAL_T == SIZEOF_VALUE
80-
/* Class serial is as wide as VALUE. Place it here. */
81-
rb_serial_t class_serial;
82-
#else
83-
/* Class serial does not fit into struct RClass. Place m_tbl instead. */
84-
struct rb_id_table *m_tbl;
85-
# if USE_RVARGC
86-
rb_serial_t *class_serial_ptr;
87-
# endif
88-
#endif
8974
};
9075

9176
typedef struct rb_subclass_entry rb_subclass_entry_t;
@@ -98,25 +83,12 @@ typedef struct rb_classext_struct rb_classext_t;
9883
#endif
9984
#define RCLASS_IV_TBL(c) (RCLASS_EXT(c)->iv_tbl)
10085
#define RCLASS_CONST_TBL(c) (RCLASS_EXT(c)->const_tbl)
101-
#if SIZEOF_SERIAL_T == SIZEOF_VALUE
102-
# define RCLASS_M_TBL(c) (RCLASS_EXT(c)->m_tbl)
103-
#else
104-
# define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
105-
#endif
86+
#define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
10687
#define RCLASS_CALLABLE_M_TBL(c) (RCLASS_EXT(c)->callable_m_tbl)
10788
#define RCLASS_CC_TBL(c) (RCLASS_EXT(c)->cc_tbl)
10889
#define RCLASS_CVC_TBL(c) (RCLASS_EXT(c)->cvc_tbl)
10990
#define RCLASS_ORIGIN(c) (RCLASS_EXT(c)->origin_)
11091
#define RCLASS_REFINED_CLASS(c) (RCLASS_EXT(c)->refined_class)
111-
#if SIZEOF_SERIAL_T == SIZEOF_VALUE
112-
# define RCLASS_SERIAL(c) (RCLASS(c)->class_serial)
113-
#else
114-
# if USE_RVARGC
115-
# define RCLASS_SERIAL(c) (*RCLASS(c)->class_serial_ptr)
116-
# else
117-
# define RCLASS_SERIAL(c) (RCLASS_EXT(c)->class_serial)
118-
# endif
119-
#endif
12092
#define RCLASS_INCLUDER(c) (RCLASS_EXT(c)->includer)
12193
#define RCLASS_SUBCLASS_ENTRY(c) (RCLASS_EXT(c)->subclass_entry)
12294
#define RCLASS_MODULE_SUBCLASS_ENTRY(c) (RCLASS_EXT(c)->module_subclass_entry)

internal/vm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ enum method_missing_reason {
4040
};
4141

4242
/* vm_insnhelper.h */
43-
rb_serial_t rb_next_class_serial(void);
4443
VALUE rb_vm_push_frame_fname(struct rb_execution_context_struct *ec, VALUE fname);
4544

4645
/* vm.c */

test/ruby/test_rubyvm.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
class TestRubyVM < Test::Unit::TestCase
55
def test_stat
66
assert_kind_of Hash, RubyVM.stat
7-
assert_kind_of Integer, RubyVM.stat[:class_serial]
87

98
RubyVM.stat(stat = {})
109
assert_not_empty stat
11-
assert_equal stat[:class_serial], RubyVM.stat(:class_serial)
1210
end
1311

1412
def test_stat_unknown

vm.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,6 @@ jit_exec(rb_execution_context_t *ec)
488488

489489
#define PROCDEBUG 0
490490

491-
rb_serial_t
492-
rb_next_class_serial(void)
493-
{
494-
rb_serial_t class_serial = NEXT_CLASS_SERIAL();
495-
return class_serial;
496-
}
497-
498491
VALUE rb_cRubyVM;
499492
VALUE rb_cThread;
500493
VALUE rb_mRubyVMFrozenCore;
@@ -532,7 +525,6 @@ unsigned int ruby_vm_event_local_num;
532525

533526
rb_serial_t ruby_vm_constant_cache_invalidations = 0;
534527
rb_serial_t ruby_vm_constant_cache_misses = 0;
535-
rb_serial_t ruby_vm_class_serial = 1;
536528
rb_serial_t ruby_vm_global_cvar_state = 1;
537529

538530
static const struct rb_callcache vm_empty_cc = {
@@ -612,7 +604,6 @@ rb_dtrace_setup(rb_execution_context_t *ec, VALUE klass, ID id,
612604
* {
613605
* :constant_cache_invalidations=>2,
614606
* :constant_cache_misses=>14,
615-
* :class_serial=>546,
616607
* :global_cvar_state=>27
617608
* }
618609
*
@@ -624,7 +615,7 @@ rb_dtrace_setup(rb_execution_context_t *ec, VALUE klass, ID id,
624615
static VALUE
625616
vm_stat(int argc, VALUE *argv, VALUE self)
626617
{
627-
static VALUE sym_constant_cache_invalidations, sym_constant_cache_misses, sym_class_serial, sym_global_cvar_state;
618+
static VALUE sym_constant_cache_invalidations, sym_constant_cache_misses, sym_global_cvar_state;
628619
VALUE arg = Qnil;
629620
VALUE hash = Qnil, key = Qnil;
630621

@@ -644,7 +635,6 @@ vm_stat(int argc, VALUE *argv, VALUE self)
644635
#define S(s) sym_##s = ID2SYM(rb_intern_const(#s))
645636
S(constant_cache_invalidations);
646637
S(constant_cache_misses);
647-
S(class_serial);
648638
S(global_cvar_state);
649639
#undef S
650640

@@ -656,7 +646,6 @@ vm_stat(int argc, VALUE *argv, VALUE self)
656646

657647
SET(constant_cache_invalidations, ruby_vm_constant_cache_invalidations);
658648
SET(constant_cache_misses, ruby_vm_constant_cache_misses);
659-
SET(class_serial, ruby_vm_class_serial);
660649
SET(global_cvar_state, ruby_vm_global_cvar_state);
661650
#undef SET
662651

vm_insnhelper.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ MJIT_SYMBOL_EXPORT_BEGIN
1616
RUBY_EXTERN VALUE ruby_vm_const_missing_count;
1717
RUBY_EXTERN rb_serial_t ruby_vm_constant_cache_invalidations;
1818
RUBY_EXTERN rb_serial_t ruby_vm_constant_cache_misses;
19-
RUBY_EXTERN rb_serial_t ruby_vm_class_serial;
2019
RUBY_EXTERN rb_serial_t ruby_vm_global_cvar_state;
2120

2221
MJIT_SYMBOL_EXPORT_END
@@ -182,8 +181,6 @@ CC_SET_FASTPATH(const struct rb_callcache *cc, vm_call_handler func, bool enable
182181
} while (0)
183182
#endif
184183

185-
#define PREV_CLASS_SERIAL() (ruby_vm_class_serial)
186-
#define NEXT_CLASS_SERIAL() (++ruby_vm_class_serial)
187184
#define GET_GLOBAL_CVAR_STATE() (ruby_vm_global_cvar_state)
188185
#define INC_GLOBAL_CVAR_STATE() (++ruby_vm_global_cvar_state)
189186

0 commit comments

Comments
 (0)