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
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
..
backward Check if __assume is supported 2022-02-19 23:32:52 +09:00
fiber [Bug #5317] Use rb_off_t instead of off_t 2022-09-08 23:01:07 +09:00
internal This commit implements the Object Shapes technique in CRuby. 2022-09-28 08:26:21 -07:00
io Fix io/buffer.h header guard. 2022-09-26 20:10:15 +13:00
assert.h typos 2022-08-27 14:42:55 -07:00
atomic.h Align the implementation precedences with rb_atomic_t definition 2021-09-24 10:11:32 +09:00
backward.h Revert "Finer-grained inline constant cache invalidation" 2022-03-25 20:29:09 +09:00
debug.h include/ruby/debug.h: add doxygen 2021-09-10 20:00:06 +09:00
defines.h include/ruby/defines.h: add doxygen 2021-09-10 20:00:06 +09:00
encoding.h split include/ruby/encoding.h 2021-10-05 14:18:23 +09:00
intern.h drop varargs.h support 2020-05-11 14:56:51 +09:00
io.h Move enum definitions out of struct definition 2022-07-22 23:10:24 +09:00
memory_view.h memory_view.c: Add _memory_view_entry member in rb_memory_view_t (#5088) 2021-11-08 12:52:09 +09:00
missing.h [wasm] wasm/missing.{c,h}: add missing libc stubs for wasi-libc 2022-01-19 11:19:06 +09:00
onigmo.h re.c: Add Regexp.timeout= and Regexp.timeout 2022-03-30 16:50:46 +09:00
oniguruma.h
ractor.h Fix typos 2021-11-02 19:17:37 +09:00
random.h include/ruby/random.h: add doxygen 2021-09-10 20:00:06 +09:00
re.h include/ruby/re.h: add doxygen 2021-09-10 20:00:06 +09:00
regex.h include/ruby/regex.h: skip doxygen 2021-09-10 20:00:06 +09:00
ruby.h Expand tabs [ci skip] 2022-07-21 09:42:04 -07:00
st.h Fix typos (#2958) 2020-03-11 00:43:12 -07:00
subst.h include/ruby/subst.h: skip doxygen 2021-09-10 20:00:06 +09:00
thread.h Expand tabs [ci skip] 2022-07-21 09:42:04 -07:00
thread_native.h [wasm] add no thread variant for freestanding environment 2022-01-19 11:19:06 +09:00
util.h Expand tabs [ci skip] 2022-07-21 09:42:04 -07:00
version.h Include JIT information in crash reports 2022-06-20 17:18:29 -04:00
vm.h include/ruby/vm.h: add doxygen 2021-09-10 20:00:06 +09:00
win32.h [Bug #5317] Use rb_off_t instead of off_t 2022-09-08 23:01:07 +09:00