1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/include/ruby/internal
Jemma Issroff d594a5a8bd
This commit implements the Object Shapes technique in CRuby.
Object Shapes is used for accessing instance variables and representing the
"frozenness" of objects.  Object instances have a "shape" and the shape
represents some attributes of the object (currently which instance variables are
set and the "frozenness").  Shapes form a tree data structure, and when a new
instance variable is set on an object, that object "transitions" to a new shape
in the shape tree.  Each shape has an ID that is used for caching. The shape
structure is independent of class, so objects of different types can have the
same shape.

For example:

```ruby
class Foo
  def initialize
    # Starts with shape id 0
    @a = 1 # transitions to shape id 1
    @b = 1 # transitions to shape id 2
  end
end

class Bar
  def initialize
    # Starts with shape id 0
    @a = 1 # transitions to shape id 1
    @b = 1 # transitions to shape id 2
  end
end

foo = Foo.new # `foo` has shape id 2
bar = Bar.new # `bar` has shape id 2
```

Both `foo` and `bar` instances have the same shape because they both set
instance variables of the same name in the same order.

This technique can help to improve inline cache hits as well as generate more
efficient machine code in JIT compilers.

This commit also adds some methods for debugging shapes on objects.  See
`RubyVM::Shape` for more details.

For more context on Object Shapes, see [Feature: #18776]

Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
Co-Authored-By: Eileen M. Uchitelle <eileencodes@gmail.com>
Co-Authored-By: John Hawthorn <john@hawthorn.email>
2022-09-28 08:26:21 -07:00
..
arithmetic Fix some UBSAN false positives (#6115) 2022-07-12 11:48:10 -07:00
attr typos 2022-08-27 14:42:55 -07:00
compiler_is include/ruby/internal/compiler_is: skip doxygen 2021-09-10 20:00:06 +09:00
core This commit implements the Object Shapes technique in CRuby. 2022-09-28 08:26:21 -07:00
encoding Support Encoding::Converter newline: :lf and :lf_newline options 2022-08-19 20:23:36 -07:00
has Define HAVE___BUILTIN_UNREACHABLE instead of UNREACHABLE 2022-02-19 23:32:52 +09:00
intern [Bug #5317] Use rb_off_t instead of off_t 2022-09-08 23:01:07 +09:00
abi.h Stop defining RUBY_ABI_VERSION if released versions 2022-08-12 15:57:25 +09:00
anyargs.h rb_define_method: dedicated overload for rb_f_notimplement 2022-09-21 11:44:09 +09:00
arithmetic.h Avoid leaving a period alone [ci skip] 2022-08-27 14:48:15 -07:00
assume.h Check if __assume is supported 2022-02-19 23:32:52 +09:00
cast.h include/ruby/internal/cast.h: skip doxygen 2021-09-10 20:00:06 +09:00
compiler_is.h
compiler_since.h
config.h Enable Variable Width Allocation by default 2022-01-12 12:00:55 -05:00
constant_p.h include/ruby/internal/constant_p.h: add doxygen 2021-09-10 20:00:06 +09:00
core.h
ctype.h include/ruby/internal/ctype.h: add doxygen 2021-09-10 20:00:06 +09:00
dllexport.h include/ruby/internal/dllexport.h: add doxygen 2021-09-10 20:00:06 +09:00
dosish.h include/ruby/internal/dosish.h: add doxygen 2021-09-10 20:00:06 +09:00
error.h include/ruby/internal/error.h: name a parameter 2021-09-10 20:00:06 +09:00
eval.h include/ruby/internal/eval.h: add doxygen 2021-09-10 20:00:06 +09:00
event.h include/ruby/internal/event.h: add doxygen 2021-09-10 20:00:06 +09:00
fl_type.h This commit implements the Object Shapes technique in CRuby. 2022-09-28 08:26:21 -07:00
gc.h
glob.h include/ruby/internal/glob.h: add doxygen 2021-09-10 20:00:06 +09:00
globals.h Deprecate include/prepend in refinements and add Refinement#import_methods instead 2021-10-21 16:31:54 +09:00
interpreter.h ruby_cleanup: fix MSVC compile error 2021-09-10 20:00:06 +09:00
iterator.h Suppress deprecated rb_iterate declaration warnings in C++ 2021-09-11 17:54:11 +09:00
memory.h do not define our own version of memcpy 2022-07-07 22:10:53 +09:00
method.h include/ruby/internal/intern/vm.h: add doxygen 2021-09-10 20:00:06 +09:00
module.h include/ruby/internal/module.h: add doxygen 2021-09-10 20:00:06 +09:00
newobj.h include/ruby/internal/newobj.h: add doxygen 2021-09-10 20:00:06 +09:00
rgengc.h include/ruby/internal/rgengc.h: add dosygen 2021-09-10 20:00:06 +09:00
scan_args.h Just a star [ci skip] 2022-09-23 08:52:15 +09:00
special_consts.h include/ruby/internal/special_consts.h: add doxygen 2021-09-10 20:00:06 +09:00
static_assert.h
stdalign.h include/ruby/internal/stdalign.h: add doxygen 2021-09-10 20:00:06 +09:00
stdbool.h Honor if _Bool is available 2022-03-16 17:50:13 +09:00
symbol.h include/ruby/internal/symbol.h: add doxygen 2021-09-10 20:00:06 +09:00
value.h include/ruby/internal/value.h: add doxygen 2021-09-10 20:00:06 +09:00
value_type.h include/ruby/internal/value_type.h: add doxygen 2021-09-10 20:00:06 +09:00
variable.h [DOC] Fix function name in example 2022-03-01 09:59:12 +09:00
warning_push.h include/ruby/internal/warning_push.h: add doxygen 2021-09-10 20:00:06 +09:00
xmalloc.h include/ruby/internal/xmalloc.h: add doxygen 2021-09-10 20:00:06 +09:00