This commit changes the node template to create a dispatcher class,
which can be used to walk an AST an emit events to all registered
listeners
https://github.com/ruby/yarp/commit/03a45f85e6
Co-authored-by: Kevin Newton <kddnewton@users.noreply.github.com>
Since the hashes have a default proc that returns a (new) empty hash, we
can avoid allocating those empty hashes when we are only doing lookups.
Test from running `bundle update --bundler` against a rails app I have
lying around:
```
==> memprof.after.txt <==
Total allocated: 9.71 MB (68282 objects)
Total retained: 4.87 MB (33791 objects)
==> memprof.before.txt <==
Total allocated: 10.83 MB (100596 objects)
Total retained: 5.02 MB (34721 objects)
```
https://github.com/rubygems/rubygems/commit/8f7c9cb23e
Running `bundle update --bundler` on a rails app locally:
```
==> memprof.after.txt <==
Total allocated: 301.90 kB (3794 objects)
Total retained: 73.24 kB (698 objects)
==> memprof.before.txt <==
Total allocated: 14.47 MB (196378 objects)
Total retained: 25.93 kB (202 objects)
```
So for a slight increase in retained memory (all keys are now retained),
we go from about 200k allocations in the settings file to under 4k
https://github.com/rubygems/rubygems/commit/e64debb6ae
Frames pushed by YJIT have an unreliable PC. The PC could be garbage,
and if we try to read the line number with a garbage PC, then the
program can crash.
This commit returns line 0 for programs where there is a `jit_return`
function. If `jit_return` has been set then this frame was pushed by
the JIT, and we cannot trust the PC.
Here is a debugger session for a program that crashed due to a broken
PC:
```
(lldb) p ruby_current_vm_ptr->ractor.main_thread->ec->cfp->iseq->body->iseq_encoded
(VALUE *) $0 = 0x0000000118a30e00
(lldb) p/x ruby_current_vm_ptr->ractor.main_thread->ec->cfp->pc
(const VALUE *) $1 = 0x0000600000b02d00
(lldb) p/x ruby_current_vm_ptr->ractor.main_thread->ec->cfp->jit_return
(void *) $2 = 0x000000010622942c
```
You can see the PC is completely out of range, but there is a
`jit_return` pointer so we can avoid this crash.
It seems not-uncommon for methods to have no IV, ISE, or ICVARC caches.
Calling malloc with 0 will actually allocate something, so if there
aren't any caches (`ISEQ_IS_SIZE(body) == 0`), then we can avoid
allocating memory by not calling malloc. If there are no caches, then
theoretically nobody should be reading from the buffer anyway.
This saves about 1MB on Lobsters benchmark.
* YJIT: Skip Insn::Comment and format!
if disasm is disabled
Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
* YJIT: Get rid of asm.comment
---------
Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
Previously, TestStack#test_machine_stack_size failed pretty consistently
on ARM64 macOS, with Rust code and part of the interpreter used for
per-instruction fallback (rb_vm_invokeblock() and friends) touching the
stack guard page and crashing with SEGV. I've also seen the same test
fail on x64 Linux, though with a different symptom.
This simplifies how we handle multi-targets, and also fixes a bug we
had where for loops were always getting multi-targets, even when there
was only a single target.
https://github.com/ruby/yarp/commit/31eb8b7ad5
This rarely used node holds information about the local variables
that need to get written in the case a regular expression is used on
the left-hand side of a =~ operator and it has named capture groups.
Note that we already "handled" these nodes by adding locals to the
AST, but we didn't actually expose this information, making it
difficult to compile.
The general idea behind this node is that it maintains the ability
for consumers to find all of the call nodes in the tree easily so
it's not flattening down. However, it should be okay because you
hopefully don't need any information in the call node to determine
what to compile because the locals list is on the top level.
https://github.com/ruby/yarp/commit/e136e7f9a8