summaryrefslogtreecommitdiff
path: root/mjit_c.rb
AgeCommit message (Collapse)Author
2022-12-24MJIT: Cancel all on disastrous situations (#7019)Takashi Kokubun
I noticed this while running test_yjit with --mjit-call-threshold=1, which redefines `Integer#<`. When Ruby is monkey-patched, MJIT itself could be broken. Similarly, Ruby scripts could break MJIT in many different ways. I prepared the same set of hooks as YJIT so that we could possibly override it and disable it on those moments. Every constant under RubyVM::MJIT is private and thus it's an unsupported behavior though. Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2022-12-22Remove MJIT's private constants from docs [ci skip]Takashi Kokubun
2022-12-10MJIT: Compile methods in batches (#6900)Takashi Kokubun
* MJIT: Compile methods in batches * MJIT: make mjit-bindgen * MJIT: Fix RubyVM::MJIT tests Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2022-12-08MJIT: Clarify jit_unit is only for MJITTakashi Kokubun
2022-12-08MJIT: Convert compact_p flag to an enumTakashi Kokubun
I'm gonna add another type of unit shortly.
2022-12-07Stop transitioning to UNDEF when undefining an instance variableAaron Patterson
Cases like this: ```ruby obj = Object.new loop do obj.instance_variable_set(:@foo, 1) obj.remove_instance_variable(:@foo) end ``` can cause us to use many more shapes than we want (and even run out). This commit changes the code such that when an instance variable is removed, we'll walk up the shape tree, find the shape, then rebuild any child nodes that happened to be below the "targetted for removal" IV. This also requires moving any instance variables so that indexes derived from the shape tree will work correctly. Co-Authored-By: Jemma Issroff <jemmaissroff@gmail.com> Co-authored-by: John Hawthorn <jhawthorn@github.com> Notes: Merged: https://github.com/ruby/ruby/pull/6866
2022-12-06Set max_iv_count (used for object shapes) based on inline cachesJemma Issroff
With this change, we're storing the iv name on an inline cache on setinstancevariable instructions. This allows us to check the inline cache to count instance variables set in initialize and give us an estimate of iv capacity for an object. For the purpose of estimating the number of instance variables required for an object, we're assuming that all initialize methods will call `super`. This change allows us to estimate the number of instance variables required without disassembling instruction sequences. Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/6870
2022-12-01Improve packing of iseq_constant_body structJohn Hawthorn
By moving the two bools into a packing gap above the mark_bits pointer/union we can save 8 bytes in the struct and avoid an extra cache line (328 bytes vs 320 bytes). Co-authored-by: Adam Hess <HParker@github.com> Notes: Merged: https://github.com/ruby/ruby/pull/6847
2022-12-01Introduce `Fiber#storage` for inheritable fiber-scoped variables. (#6612)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-11-29Fix unused variable warningsTakashi Kokubun
builtin seems to be not handling this correctly.
2022-11-29MJIT: Move Primitive helpers to mjit_c.rbTakashi Kokubun
2022-11-29MJIT: Self-contain extern declarationsTakashi Kokubun
I'm trying to get rid of mjit_compiler.c, and this helps that migration.
2022-11-29MJIT: Refactor CDHASH handlingTakashi Kokubun
Converting a CDHASH into a safe Hash is a lot of work, but retrieving just values is much easier.
2022-11-28MJIT: Merge exivar guards as wellTakashi Kokubun
obviating status->merge_ivar_guards_p as refactoring
2022-11-28MJIT: Remove an unused fieldTakashi Kokubun
This has not been used since recent shape-related changes.
2022-11-28MJIT: Get rid of is_entries copyTakashi Kokubun
MJIT worker no longer exists, so we don't need this safeguard anymore.
2022-11-28MJIT: Make it parsable by Solargraph (#6827)Takashi Kokubun
* Revert "Revert "MJIT: Make it parsable by Solargraph"" This reverts commit 8e18761da1932df88bfb6505acbda4740e1b2930. * Call rb_gc_register_mark_object Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2022-11-28Revert "MJIT: Make it parsable by Solargraph"Takashi Kokubun
This reverts commit ccd8dd6ad395bbd9f5290e0fcb7929e5e5d36767. Revert "MJIT: Fix miniruby with MJIT_FORCE_ENABLE" This reverts commit b033775ed9d9226ba73c1d4a197e55ba89575142. GitHub Actions is failing. I ran out of time today to investigate it. will try it again tomorrow.
2022-11-27MJIT: Fix miniruby with MJIT_FORCE_ENABLETakashi Kokubun
2022-11-27MJIT: Make it parsable by SolargraphTakashi Kokubun
2022-11-27MJIT: Get rid of C.fprintfTakashi Kokubun
Faster code generation and cleaner code.
2022-11-18rename SHAPE_BITS to SHAPE_ID_NUM_BITSAaron Patterson
Notes: Merged: https://github.com/ruby/ruby/pull/6737
2022-11-15MJIT: Fix vm_cc_cme(cc).def.type to use bit fieldTakashi Kokubun
access properly. Because the libclang node had two children, it wasn't handled well by the pattern matching for the bit field case. In addition to that, this bit field has a non-1 width. Because we're returning true/false for a width-1 bit field, I added another behavior that works like a char value for bit fields with width 2-8.
2022-11-14MJIT: Remove reference to ROBJECT_EMBED_LEN_MAXTakashi Kokubun
maybe not used since some shape changes?
2022-11-14Rename --mjit-min-calls to --mjit-call-threshold (#6731)Takashi Kokubun
for consistency with YJIT Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2022-11-14Remove USE_RVARGC codeAaron Patterson
We don't need this constant to be exposed anymore, so remove it Notes: Merged: https://github.com/ruby/ruby/pull/6728
2022-11-14Import shape constants with mjit-bindgenTakashi Kokubun
2022-11-14Import class constants with mjit-bindgenTakashi Kokubun
2022-11-10Transition shape when object's capacity changesJemma Issroff
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@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/6699
2022-10-24Remove iv_index_tbl_entryJohn Hawthorn
Notes: Merged: https://github.com/ruby/ruby/pull/6610
2022-10-21Rename `iv_count` on shapes to `next_iv_index`Jemma Issroff
`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. Notes: Merged: https://github.com/ruby/ruby/pull/6608
2022-10-13Only expose Ruby Shape API if VM_CHECK_MODE is enabledAaron Patterson
2022-10-11Make inline cache reads / writes atomic with object shapesJemma Issroff
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>
2022-10-11Revert "Revert "This commit implements the Object Shapes technique in CRuby.""Jemma Issroff
This reverts commit 9a6803c90b817f70389cae10d60b50ad752da48f.
2022-09-30Revert "This commit implements the Object Shapes technique in CRuby."Aaron Patterson
This reverts commit 68bc9e2e97d12f80df0d113e284864e225f771c2.
2022-09-28This commit implements the Object Shapes technique in CRuby.Jemma Issroff
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-26Revert this until we can figure out WB issues or remove shapes from GCAaron Patterson
Revert "* expand tabs. [ci skip]" This reverts commit 830b5b5c351c5c6efa5ad461ae4ec5085e5f0275. Revert "This commit implements the Object Shapes technique in CRuby." This reverts commit 9ddfd2ca004d1952be79cf1b84c52c79a55978f4.
2022-09-26This commit implements the Object Shapes technique in CRuby.Jemma Issroff
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> Notes: Merged: https://github.com/ruby/ruby/pull/6386
2022-09-26Rework vm_core to use `int first_lineno` struct member.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/6430
2022-09-23Skip struct fields whose output differsTakashi Kokubun
across different environments Notes: Merged: https://github.com/ruby/ruby/pull/6418
2022-09-23Swap the positions of offsetof and typeTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/6418
2022-09-23Bindgen offsetof struct and union with builtinTakashi Kokubun
except for bit fields. I made a risky assumption on leading bit fields and just gave up non-leading bit fields for now. I'll change it to let C code access bit fields later. Notes: Merged: https://github.com/ruby/ruby/pull/6418
2022-09-23Bindgen sizeof struct and union with builtinTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/6418
2022-09-23Bindgen immediate types with builtinTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/6418
2022-09-23Drop c_64 and c_32Takashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/6418
2022-09-23Bindgen enum with builtinTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/6418
2022-09-23Builtin needs to be baseruby-compatibleTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/6418
2022-09-23mjit_c.rb doesn't need to be an erbTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/6418