Граф коммитов

47 Коммитов

Автор SHA1 Сообщение Дата
Takashi Kokubun d0c0d7fa5b MJIT: Revert FL_EXIVAR check optimization
It seems to slow down optcarrot. I'll revisit this later.
2022-11-29 22:35:26 -08:00
Takashi Kokubun 8a0acbea4c MJIT: Refactor CDHASH handling
Converting a CDHASH into a safe Hash is a lot of work, but retrieving
just values is much easier.
2022-11-29 00:12:33 -08:00
Takashi Kokubun 2329cbeb5b MJIT: Merge exivar guards as well
obviating status->merge_ivar_guards_p as refactoring
2022-11-28 23:32:27 -08:00
Takashi Kokubun bb6f933d51 MJIT: Get rid of is_entries copy
MJIT worker no longer exists, so we don't need this safeguard anymore.
2022-11-28 22:03:16 -08:00
Takashi Kokubun 9c13fc614c
MJIT: Make it parsable by Solargraph (#6827)
* Revert "Revert "MJIT: Make it parsable by Solargraph""

This reverts commit 8e18761da1.

* Call rb_gc_register_mark_object
2022-11-28 21:33:55 -08:00
Takashi Kokubun 8e18761da1
Revert "MJIT: Make it parsable by Solargraph"
This reverts commit ccd8dd6ad3.

Revert "MJIT: Fix miniruby with MJIT_FORCE_ENABLE"

This reverts commit b033775ed9.

GitHub Actions is failing. I ran out of time today to investigate it.
will try it again tomorrow.
2022-11-28 00:13:23 -08:00
Takashi Kokubun ccd8dd6ad3 MJIT: Make it parsable by Solargraph 2022-11-27 23:46:59 -08:00
Takashi Kokubun fb599523cd MJIT: Do not document a dynamic type [ci skip]
Solargraph complains about it
2022-11-27 23:29:44 -08:00
Takashi Kokubun 2c1c0d3df0 MJIT: Get rid of C.fprintf
Faster code generation and cleaner code.
2022-11-27 22:47:46 -08:00
Takashi Kokubun a22c684c59 MJIT: Refactor invokebuiltin_delegate_leave
You shouldn't assume bf->compiler is always non-zero. While struct
aref/aset is no longer a builtin function since
https://github.com/ruby/ruby/pull/5131, it seems like you could still
load such an iseq binary.

The refactored code fallbacks to compile_insn_default correctly when
bf->compiler is zero.
2022-11-27 21:44:28 -08:00
Takashi Kokubun 6844bcc6b4 MJIT: Use a String buffer in builtin compilers
instead of FILE*.

Using C.fprintf is slower than String manipulation on memory. I'm going
to change the way MJIT writes files, and this is a prerequisite for it.
2022-11-27 21:11:33 -08:00
Takashi Kokubun e3de723043 MJIT: Move some private declarations
and clean up legacy comments for the Ruby migration
2022-11-27 14:50:20 -08:00
Takashi Kokubun 73e42ef856 MJIT: Remove a duplicated rescue
`#compile` has a catch-call rescue, so compile_insn_entry shouldn't do
that. It was a temporary code needed during the migration.
2022-11-26 15:39:53 -08:00
Takashi Kokubun 3c16f33ffd MJIT: Refactor source_shape_id extraction
I'm not comfortable indenting code that deeply.
2022-11-25 15:27:27 -08:00
Takashi Kokubun 89a98ee1e1 MJIT: Remove obsoleted variable
no longer used after 4ea9d7d7c2
2022-11-25 15:23:43 -08:00
Takashi Kokubun 4ea9d7d7c2 MJIT: Remove the code to optimize shape transition
because this code crashes on railsbench. I'll try adding a repro for it
later, but I don't know shapes enough to craft it right away.
2022-11-25 15:18:34 -08:00
Takashi Kokubun cd2da09410 MJIT: Refactor BitField dereference a little 2022-11-15 21:59:38 -08:00
Takashi Kokubun 1a9e87fe3a
MJIT: Fix vm_cc_cme(cc).def.type to use bit field
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-15 00:34:00 -08:00
Takashi Kokubun f500ca9b8a
Handle more MJIT compilation failures
NotImplementedError is not part StandardError, for example. When that
kind of exception happens, current_cc_unit remains not NULL, and
mjit_finish ends up waiting for 5 seconds, which is inconvenient.
2022-11-15 00:18:13 -08:00
Takashi Kokubun 69e47b7fa6
MJIT: Remove reference to ROBJECT_EMBED_LEN_MAX
maybe not used since some shape changes?
2022-11-14 23:39:38 -08:00
Aaron Patterson b7d591643a Remove USE_RVARGC code
We don't need this constant to be exposed anymore, so remove it
2022-11-14 15:42:11 -08:00
Takashi Kokubun 96d29dff66
Fix invokebuiltin in Ruby MJIT
45fe7f7575/tool/ruby_vm/views/_mjit_compile_invokebuiltin.erb (L21)
has not been ported correctly.
2022-11-13 21:14:47 -08:00
Jemma Issroff c726c48a3d Remove numiv from RObject
Since object shapes store the capacity of an object, we no longer
need the numiv field on RObjects. This gives us one extra slot which
we can use to give embedded objects one more instance variable (for a
total of 3 ivs). This commit removes the concept of numiv from RObject.
2022-11-10 10:11:34 -05:00
Jemma Issroff 5246f4027e Transition shape when object's capacity changes
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>
2022-11-10 10:11:34 -05:00
Aaron Patterson e5058b58c2
Only expose Ruby Shape API if VM_CHECK_MODE is enabled 2022-10-13 13:11:01 -07:00
Jemma Issroff 913979bede
Make inline cache reads / writes atomic with object shapes
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-11 08:40:56 -07:00
Jemma Issroff ad63b668e2
Revert "Revert "This commit implements the Object Shapes technique in CRuby.""
This reverts commit 9a6803c90b.
2022-10-11 08:40:56 -07:00
Aaron Patterson 9a6803c90b
Revert "This commit implements the Object Shapes technique in CRuby."
This reverts commit 68bc9e2e97d12f80df0d113e284864e225f771c2.
2022-09-30 16:01:50 -07:00
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
Aaron Patterson 06abfa5be6
Revert this until we can figure out WB issues or remove shapes from GC
Revert "* expand tabs. [ci skip]"

This reverts commit 830b5b5c35.

Revert "This commit implements the Object Shapes technique in CRuby."

This reverts commit 9ddfd2ca00.
2022-09-26 16:10:11 -07:00
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
Samuel Williams 22af2e9084 Rework vm_core to use `int first_lineno` struct member. 2022-09-26 00:41:16 +13:00
Takashi Kokubun 0c9dc01a2a Skip struct fields whose output differs
across different environments
2022-09-23 06:44:28 +09:00
Takashi Kokubun dfc311c0b3 Swap the positions of offsetof and type 2022-09-23 06:44:28 +09:00
Takashi Kokubun 4c6e1556b1 Bindgen immediate types with builtin 2022-09-23 06:44:28 +09:00
Takashi Kokubun 280ff1707e Drop c_64 and c_32 2022-09-23 06:44:28 +09:00
Takashi Kokubun 5cda5938f8 Bindgen enum with builtin 2022-09-23 06:44:28 +09:00
Takashi Kokubun 00c441ce7a Bindgen macro with builtin 2022-09-23 06:44:28 +09:00
Takashi Kokubun f2bea691cd Builtin RubyVM::MJIT::C 2022-09-23 06:44:28 +09:00
Aaron Patterson ec93d09c94 add rb_execution_context 2022-09-21 22:20:35 -07:00
Aaron Patterson 083b4bb655 add rb_control_frame_t 2022-09-21 22:20:35 -07:00
Takashi Kokubun 472e7b8518
MJIT: Use the built-in PACK_MAP
106744107b made this possible.
2022-09-11 15:39:40 +09:00
Aaron Patterson 56e5210cde
More robust macro parser (#6343)
I want to use more complicated macros with MJIT.  For example:

```
  # define SHAPE_MASK (((unsigned int)1 << SHAPE_BITS) - 1)
```

This commit adds a simple recursive descent parser that produces an AST
and a small visitor that converts the AST to Ruby.
2022-09-09 15:19:23 +09:00
Takashi Kokubun 03ae415d50
Fix typo 2022-09-06 16:22:43 +09:00
Takashi Kokubun 3f9125aaba
Update c_32.rb 2022-09-06 16:09:29 +09:00
Takashi Kokubun 4214023309
Run mjit-bindgen again
I'm thinking about Ruby builtin code instead of doing this.
It'll be hopefully more portable and easier because the same C code could
handle both 32bit and 64bit.
2022-09-06 15:59:08 +09:00
Takashi Kokubun 3767c6a90d
Ruby MJIT (#6028) 2022-09-04 21:53:46 -07:00