1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/internal
Jemma Issroff 9ddfd2ca00 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-26 09:21:30 -07:00
..
array.h Rename rb_ary_tmp_new to rb_ary_hidden_new 2022-07-26 09:12:09 -04:00
bignum.h
bits.h
class.h This commit implements the Object Shapes technique in CRuby. 2022-09-26 09:21:30 -07:00
cmdlineopt.h Rust YJIT 2022-04-27 11:00:22 -04:00
compar.h
compile.h RubyVM.keep_script_lines 2021-10-21 16:17:39 +09:00
compilers.h
complex.h
cont.h Prevent the stack from being marked twice 2022-07-20 13:45:55 -07:00
dir.h
enc.h
encoding.h Remove get_actual_encoding() and the dynamic endian detection for dummy UTF-16/UTF-32 2022-09-12 14:02:34 +02:00
enum.h
enumerator.h
error.h
eval.h
file.h
fixnum.h Fix rb_fix_mul_fix on OpenBSD/mips64 2022-07-03 09:42:44 -07:00
gc.h Increase SIZE_POOL_COUNT to 5 2022-05-09 08:45:24 -04:00
hash.h
imemo.h This commit implements the Object Shapes technique in CRuby. 2022-09-26 09:21:30 -07:00
inits.h
io.h
load.h
loadpath.h
math.h
missing.h
numeric.h Embed bare double if sizeof(double) == sizeof(VALUE) 2021-10-27 02:05:06 +09:00
object.h This commit implements the Object Shapes technique in CRuby. 2022-09-26 09:21:30 -07:00
parse.h
proc.h
process.h process.c: Add Process._fork (#5017) 2021-10-25 20:47:19 +09:00
ractor.h internal/ractor.h: Added 2022-03-30 16:50:46 +09:00
random.h
range.h
rational.h
re.h
sanitizers.h
serial.h
signal.h
static_assert.h
string.h Revert "Revert "error.c: Let Exception#inspect inspect its message"" 2022-09-23 16:40:59 +09:00
struct.h
symbol.h Ensure _id2ref finds symbols with the correct type 2022-07-20 10:38:44 -07:00
thread.h Restore rb_exec_recursive_outer 2022-06-15 16:07:29 -07:00
time.h
transcode.h
util.h
variable.h This commit implements the Object Shapes technique in CRuby. 2022-09-26 09:21:30 -07:00
vm.h Finer-grained constant cache invalidation (take 2) 2022-04-01 14:48:22 -04:00
warnings.h