ruby-changes:74431
From: Jemma <ko1@a...>
Date: Fri, 11 Nov 2022 00:12:01 +0900 (JST)
Subject: [ruby-changes:74431] 5246f4027e (master): Transition shape when object's capacity changes
https://git.ruby-lang.org/ruby.git/commit/?id=5246f4027e From 5246f4027ec574e77809845e1b1f7822cc2a5cef Mon Sep 17 00:00:00 2001 From: Jemma Issroff <jemmaissroff@g...> Date: Tue, 8 Nov 2022 15:35:31 -0500 Subject: Transition shape when object's capacity changes This commit adds a `capacity` field to shapes, and adds shape transitions whenever an object's capacity changes. Objects which are allocated out of a bigger size pool will also make a transition from the root shape to the shape with the correct capacity for their size pool when they are allocated. This commit will allow us to remove numiv from objects completely, and will also mean we can guarantee that if two objects share shapes, their IVs are in the same positions (an embedded and extended object cannot share shapes). This will enable us to implement ivar sets in YJIT using object shapes. Co-Authored-By: Aaron Patterson <tenderlove@r...> --- class.c | 4 +- common.mk | 10 ++ ext/-test-/rational/depend | 1 + ext/pty/depend | 1 + ext/ripper/depend | 1 + ext/socket/depend | 15 +++ gc.c | 67 +++++++++--- gc.h | 2 + gc.rb | 10 -- include/ruby/internal/core/robject.h | 10 ++ inits.c | 1 + internal/class.h | 4 +- internal/gc.h | 5 +- internal/variable.h | 3 +- lib/mjit/compiler.rb | 18 +++- mjit_c.rb | 26 +++++ object.c | 77 +++++++++---- shape.c | 203 +++++++++++++++++++++++++++-------- shape.h | 28 ++++- test/-ext-/string/test_cstr.rb | 6 +- test/objspace/test_objspace.rb | 26 ++--- test/ruby/test_gc_compact.rb | 13 ++- test/ruby/test_shapes.rb | 19 ++-- variable.c | 61 +++++++---- vm.c | 11 -- vm_core.h | 1 - vm_insnhelper.c | 52 ++++----- yjit/src/cruby_bindings.inc.rs | 9 +- 28 files changed, 482 insertions(+), 202 deletions(-) diff --git a/class.c b/class.c index d181fb0b2e..85663ada50 100644 --- a/class.c +++ b/class.c @@ -197,7 +197,7 @@ class_alloc(VALUE flags, VALUE klass) https://github.com/ruby/ruby/blob/trunk/class.c#L197 { size_t alloc_size = sizeof(struct RClass); -#if USE_RVARGC +#if RCLASS_EXT_EMBEDDED alloc_size += sizeof(rb_classext_t); #endif @@ -206,7 +206,7 @@ class_alloc(VALUE flags, VALUE klass) https://github.com/ruby/ruby/blob/trunk/class.c#L206 if (RGENGC_WB_PROTECTED_CLASS) flags |= FL_WB_PROTECTED; RVARGC_NEWOBJ_OF(obj, struct RClass, klass, flags, alloc_size); -#if USE_RVARGC +#if RCLASS_EXT_EMBEDDED memset(RCLASS_EXT(obj), 0, sizeof(rb_classext_t)); #else obj->ptr = ZALLOC(rb_classext_t); diff --git a/common.mk b/common.mk index 81f99b1458..99cda1a98a 100644 --- a/common.mk +++ b/common.mk @@ -6038,6 +6038,7 @@ enumerator.$(OBJEXT): {$(VPATH)}missing.h https://github.com/ruby/ruby/blob/trunk/common.mk#L6038 enumerator.$(OBJEXT): {$(VPATH)}onigmo.h enumerator.$(OBJEXT): {$(VPATH)}oniguruma.h enumerator.$(OBJEXT): {$(VPATH)}ruby_assert.h +enumerator.$(OBJEXT): {$(VPATH)}shape.h enumerator.$(OBJEXT): {$(VPATH)}st.h enumerator.$(OBJEXT): {$(VPATH)}subst.h error.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h @@ -9376,6 +9377,7 @@ memory_view.$(OBJEXT): {$(VPATH)}internal/xmalloc.h https://github.com/ruby/ruby/blob/trunk/common.mk#L9377 memory_view.$(OBJEXT): {$(VPATH)}memory_view.c memory_view.$(OBJEXT): {$(VPATH)}memory_view.h memory_view.$(OBJEXT): {$(VPATH)}missing.h +memory_view.$(OBJEXT): {$(VPATH)}shape.h memory_view.$(OBJEXT): {$(VPATH)}st.h memory_view.$(OBJEXT): {$(VPATH)}subst.h memory_view.$(OBJEXT): {$(VPATH)}util.h @@ -10629,6 +10631,7 @@ object.$(OBJEXT): {$(VPATH)}shape.h https://github.com/ruby/ruby/blob/trunk/common.mk#L10631 object.$(OBJEXT): {$(VPATH)}st.h object.$(OBJEXT): {$(VPATH)}subst.h object.$(OBJEXT): {$(VPATH)}util.h +object.$(OBJEXT): {$(VPATH)}variable.h pack.$(OBJEXT): $(hdrdir)/ruby/ruby.h pack.$(OBJEXT): $(top_srcdir)/internal/array.h pack.$(OBJEXT): $(top_srcdir)/internal/bits.h @@ -10810,6 +10813,7 @@ pack.$(OBJEXT): {$(VPATH)}onigmo.h https://github.com/ruby/ruby/blob/trunk/common.mk#L10813 pack.$(OBJEXT): {$(VPATH)}oniguruma.h pack.$(OBJEXT): {$(VPATH)}pack.c pack.$(OBJEXT): {$(VPATH)}pack.rbinc +pack.$(OBJEXT): {$(VPATH)}shape.h pack.$(OBJEXT): {$(VPATH)}st.h pack.$(OBJEXT): {$(VPATH)}subst.h pack.$(OBJEXT): {$(VPATH)}util.h @@ -11022,6 +11026,7 @@ parse.$(OBJEXT): {$(VPATH)}ractor.h https://github.com/ruby/ruby/blob/trunk/common.mk#L11026 parse.$(OBJEXT): {$(VPATH)}regenc.h parse.$(OBJEXT): {$(VPATH)}regex.h parse.$(OBJEXT): {$(VPATH)}ruby_assert.h +parse.$(OBJEXT): {$(VPATH)}shape.h parse.$(OBJEXT): {$(VPATH)}st.h parse.$(OBJEXT): {$(VPATH)}subst.h parse.$(OBJEXT): {$(VPATH)}symbol.h @@ -11853,6 +11858,7 @@ random.$(OBJEXT): {$(VPATH)}ractor.h https://github.com/ruby/ruby/blob/trunk/common.mk#L11858 random.$(OBJEXT): {$(VPATH)}random.c random.$(OBJEXT): {$(VPATH)}random.h random.$(OBJEXT): {$(VPATH)}ruby_atomic.h +random.$(OBJEXT): {$(VPATH)}shape.h random.$(OBJEXT): {$(VPATH)}siphash.c random.$(OBJEXT): {$(VPATH)}siphash.h random.$(OBJEXT): {$(VPATH)}st.h @@ -12045,6 +12051,7 @@ range.$(OBJEXT): {$(VPATH)}missing.h https://github.com/ruby/ruby/blob/trunk/common.mk#L12051 range.$(OBJEXT): {$(VPATH)}onigmo.h range.$(OBJEXT): {$(VPATH)}oniguruma.h range.$(OBJEXT): {$(VPATH)}range.c +range.$(OBJEXT): {$(VPATH)}shape.h range.$(OBJEXT): {$(VPATH)}st.h range.$(OBJEXT): {$(VPATH)}subst.h rational.$(OBJEXT): $(hdrdir)/ruby/ruby.h @@ -14024,6 +14031,7 @@ shape.$(OBJEXT): {$(VPATH)}constant.h https://github.com/ruby/ruby/blob/trunk/common.mk#L14031 shape.$(OBJEXT): {$(VPATH)}debug_counter.h shape.$(OBJEXT): {$(VPATH)}defines.h shape.$(OBJEXT): {$(VPATH)}encoding.h +shape.$(OBJEXT): {$(VPATH)}gc.h shape.$(OBJEXT): {$(VPATH)}id.h shape.$(OBJEXT): {$(VPATH)}id_table.h shape.$(OBJEXT): {$(VPATH)}intern.h @@ -16007,6 +16015,7 @@ time.$(OBJEXT): {$(VPATH)}missing.h https://github.com/ruby/ruby/blob/trunk/common.mk#L16015 time.$(OBJEXT): {$(VPATH)}onigmo.h time.$(OBJEXT): {$(VPATH)}oniguruma.h time.$(OBJEXT): {$(VPATH)}ruby_assert.h +time.$(OBJEXT): {$(VPATH)}shape.h time.$(OBJEXT): {$(VPATH)}st.h time.$(OBJEXT): {$(VPATH)}subst.h time.$(OBJEXT): {$(VPATH)}time.c @@ -16371,6 +16380,7 @@ transient_heap.$(OBJEXT): {$(VPATH)}internal/warning_push.h https://github.com/ruby/ruby/blob/trunk/common.mk#L16380 transient_heap.$(OBJEXT): {$(VPATH)}internal/xmalloc.h transient_heap.$(OBJEXT): {$(VPATH)}missing.h transient_heap.$(OBJEXT): {$(VPATH)}ruby_assert.h +transient_heap.$(OBJEXT): {$(VPATH)}shape.h transient_heap.$(OBJEXT): {$(VPATH)}st.h transient_heap.$(OBJEXT): {$(VPATH)}subst.h transient_heap.$(OBJEXT): {$(VPATH)}transient_heap.c diff --git a/ext/-test-/rational/depend b/ext/-test-/rational/depend index 8729695886..ce977821b8 100644 --- a/ext/-test-/rational/depend +++ b/ext/-test-/rational/depend @@ -174,5 +174,6 @@ rat.o: $(top_srcdir)/internal/static_assert.h https://github.com/ruby/ruby/blob/trunk/ext/-test-/rational/depend#L174 rat.o: $(top_srcdir)/internal/vm.h rat.o: $(top_srcdir)/internal/warnings.h rat.o: $(top_srcdir)/ruby_assert.h +rat.o: $(top_srcdir)/shape.h rat.o: rat.c # AUTOGENERATED DEPENDENCIES END diff --git a/ext/pty/depend b/ext/pty/depend index c43d3dcf9a..f251caae3f 100644 --- a/ext/pty/depend +++ b/ext/pty/depend @@ -181,5 +181,6 @@ pty.o: $(top_srcdir)/internal/process.h https://github.com/ruby/ruby/blob/trunk/ext/pty/depend#L181 pty.o: $(top_srcdir)/internal/signal.h pty.o: $(top_srcdir)/internal/static_assert.h pty.o: $(top_srcdir)/internal/warnings.h +pty.o: $(top_srcdir)/shape.h pty.o: pty.c # AUTOGENERATED DEPENDENCIES END diff --git a/ext/ripper/depend b/ext/ripper/depend index c77e4e1b7a..85520b032e 100644 --- a/ext/ripper/depend +++ b/ext/ripper/depend @@ -252,6 +252,7 @@ ripper.o: $(top_srcdir)/internal/warnings.h https://github.com/ruby/ruby/blob/trunk/ext/ripper/depend#L252 ripper.o: $(top_srcdir)/node.h ripper.o: $(top_srcdir)/regenc.h ripper.o: $(top_srcdir)/ruby_assert.h +ripper.o: $(top_srcdir)/shape.h ripper.o: $(top_srcdir)/symbol.h ripper.o: ../../probes.h ripper.o: eventids2.c diff --git a/ext/socket/depend b/ext/socket/depend index ffe2fce844..28c5540cd6 100644 --- a/ext/socket/depend +++ b/ext/socket/depend @@ -197,6 +197,7 @@ ancdata.o: $(top_srcdir)/internal/string.h https://github.com/ruby/ruby/blob/trunk/ext/socket/depend#L197 ancdata.o: $(top_srcdir)/internal/thread.h ancdata.o: $(top_srcdir)/internal/vm.h ancdata.o: $(top_srcdir)/internal/warnings.h +ancdata.o: $(top_srcdir)/shape.h ancdata.o: ancdata.c ancdata.o: constdefs.h ancdata.o: rubysocket.h @@ -388,6 +389,7 @@ basicsocket.o: $(top_srcdir)/internal/string.h https://github.com/ruby/ruby/blob/trunk/ext/socket/depend#L389 basicsocket.o: $(top_srcdir)/internal/thread.h basicsocket.o: $(top_srcdir)/internal/vm.h basicsocket.o: $(top_srcdir)/internal/warnings.h +basicsocket.o: $(top_srcdir)/shape.h basicsocket.o: basicsocket.c basicsocket.o: constdefs.h basicsocket.o: rubysocket.h @@ -579,6 +581,7 @@ constants.o: $(top_srcdir)/internal/string.h https://github.com/ruby/ruby/blob/trunk/ext/socket/depend#L581 constants.o: $(top_srcdir)/internal/thread.h constants.o: $(top_srcdir)/internal/vm.h constants.o: $(top_srcdir)/internal/warnings.h +constants.o: $(top_srcdir)/shape.h constants.o: constants.c constants.o: constdefs.c constants.o: constdefs.h @@ -771,6 +774,7 @@ ifaddr.o: $(top_srcdir)/internal/string.h https://github.com/ruby/ruby/blob/trunk/ext/socket/depend#L774 ifaddr. (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/