summaryrefslogtreecommitdiff
path: root/shape.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Rename `iv_count` on shapes to `next_iv_index`Jemma Issroff2022-10-211-11/+11
| | | | | | `iv_count` is a misleading name because when IVs are unset, the new shape doesn't decrement this value. `next_iv_count` is an accurate, and more descriptive name.
* Transition frozen string to frozen root shapeJemma Issroff2022-10-191-8/+0
| | | | Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
* Only expose Ruby Shape API if VM_CHECK_MODE is enabledAaron Patterson2022-10-131-9/+13
|
* Unwrap shape id as unsigned intAaron Patterson2022-10-121-2/+2
| | | | | | Shape IDs are unsigned. This commit unwraps the shape id as an unsigned int, which will automatically raise an argument error and also eliminate a compilation warning.
* Adjust indents [ci skip]Nobuyoshi Nakada2022-10-121-51/+75
|
* Make inline cache reads / writes atomic with object shapesJemma Issroff2022-10-111-39/+43
| | | | | | | | | | | | | | Prior to this commit, we were reading and writing ivar index and shape ID in inline caches in two separate instructions when getting and setting ivars. This meant there was a race condition with ractors and these caches where one ractor could change a value in the cache while another was still reading from it. This commit instead reads and writes shape ID and ivar index to inline caches atomically so there is no longer a race condition. Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org> Co-Authored-By: John Hawthorn <john@hawthorn.email>
* Revert "Revert "This commit implements the Object Shapes technique in CRuby.""Jemma Issroff2022-10-111-0/+523
| | | | This reverts commit 9a6803c90b817f70389cae10d60b50ad752da48f.
* Revert "This commit implements the Object Shapes technique in CRuby."Aaron Patterson2022-09-301-523/+0
| | | | This reverts commit 68bc9e2e97d12f80df0d113e284864e225f771c2.
* Fix frozen object inspecteileencodes2022-09-301-2/+1
| | | | | | | | | | | | | In the rails/rails CI build for Ruby master we found that some tests were failing due to inspect on a frozen object being incorrect. An object's instance variable count was incorrect when frozen causing the object's inspect to not splat out the object. This fixes the issue and adds a test for inspecting frozen objects. Co-Authored-By: Jemma Issroff <jemmaissroff@gmail.com> Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
* Shapes wrappers shouldn't mark the shapeAaron Patterson2022-09-281-7/+1
| | | | | We don't allocate shapes out of the GC anymore, so we shouldn't mark those pointers.
* This commit implements the Object Shapes technique in CRuby.Jemma Issroff2022-09-281-0/+530
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Revert this until we can figure out WB issues or remove shapes from GCAaron Patterson2022-09-261-571/+0
| | | | | | | | | | Revert "* expand tabs. [ci skip]" This reverts commit 830b5b5c351c5c6efa5ad461ae4ec5085e5f0275. Revert "This commit implements the Object Shapes technique in CRuby." This reverts commit 9ddfd2ca004d1952be79cf1b84c52c79a55978f4.
* This commit implements the Object Shapes technique in CRuby.Jemma Issroff2022-09-261-0/+571
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>