69262 Commits

Author SHA1 Message Date
Alan Wu
d355bf17ba Style fix in ruby.c 2021-10-20 18:19:42 -04:00
Alan Wu
34f1595405 Enable leaked global tests in YJIT workflows 2021-10-20 18:19:42 -04:00
Alan Wu
99facbc070 Correct workflow name for YJIT Ubuntu 2021-10-20 18:19:42 -04:00
Noah Gibbs
4705db6a37 Try turning off test-bundler-parallel to see if that fixes all the build errors 2021-10-20 18:19:42 -04:00
Noah Gibbs
21e58acef3 Don't enable YJIT by default. More tests on both Ubuntu and MacOS.
Add RUBY_YJIT_ENABLE env var and YJIT_FORCE_ENABLE compile-time constant.
Rename YJIT_STATS to RUBY_YJIT_STATS.
2021-10-20 18:19:42 -04:00
Alan Wu
7c08538aa3 Cleanup diff against upstream. Add comments
I did a `git diff --stat` against upstream and looked at all the files
that are outside of YJIT to come up with these minor changes.
2021-10-20 18:19:42 -04:00
Alan Wu
884b6f3dbb Move YJIT internal macros away from yjit.h. Tweak style
Since this file is exposed to the rest of the codebase and they don't
really need to know about things like PLATFORM_SUPPORTED_P.
2021-10-20 18:19:42 -04:00
Alan Wu
ed723ca76f Remove yjit_backend to help with upstreaming
The new backend isn't used at the moment and adds to our diff against
upstream so remove it for now. We can reverse the removal later with git
history.
2021-10-20 18:19:42 -04:00
Alan Wu
506c037a16 Cleanup iseq.c minimize diff with upstream
Most of these are vestiges of our old setup where we hack into the
interpreter loop.
2021-10-20 18:19:42 -04:00
Alan Wu
735b3a7748 Tweak mjit_exec() to remove YJIT symbol exports
We were exporting a couple of symbols in yjit.h because they could be
used by code generated by MJIT. We don't want MJIT calling into YJIT
code anyways so let's stop exporting them to libruby.so.

Also adjust indentation and comments in mjit_exec().
2021-10-20 18:19:42 -04:00
Alan Wu
b242ea87da Re-enable leaked global check
YJIT should be able to pass this check now.
2021-10-20 18:19:42 -04:00
Alan Wu
f6da559d5b Put YJIT into a single compilation unit
For upstreaming, we want functions we export either prefixed with "rb_"
or made static. Historically we haven't been following this rule, so we
were "leaking" a lot of symbols as `make leak-globals` would tell us.

This change unifies everything YJIT into a single compilation unit,
yjit.o, and makes everything unprefixed static to pass `make leak-globals`.
This manual "unified build" setup is similar to that of vm.o.

Having everything in one compilation unit allows static functions to
be visible across YJIT files and removes the need for declarations in
headers in some cases. Unnecessary declarations were removed.

Other changes of note:
  - switched to MJIT_SYMBOL_EXPORT_BEGIN which indicates stuff as being
    off limits for native extensions
  - the first include of each YJIT file is change to be "internal.h"
  - undefined MAP_STACK before explicitly redefining it since it
    collide's with a definition in system headers. Consider renaming?
2021-10-20 18:19:42 -04:00
Alan Wu
25eed28483 Remove unused function 2021-10-20 18:19:42 -04:00
Alan Wu
7eea96c780 Fix gen_getclassvariable
We need to reconstruct interpreter state before calling into the
routines to be able to raise exceptions. I'm getting a crash in
debug build with:
    make test-all 'TESTS=test/ruby/variable.rb' RUN_OPTS='--yjit-call-threshold=1 --yjit-max-versions=1'
2021-10-20 18:19:42 -04:00
Maxime Chevalier-Boisvert
70c5bbf84b Fix counter names for getblockparamproxy. Print in --yjit-stats. 2021-10-20 18:19:42 -04:00
Noah Gibbs
f021b35273 Reduce line length for YJIT option descriptions 2021-10-20 18:19:42 -04:00
Noah Gibbs
fab469b678 Document YJIT options in --help 2021-10-20 18:19:42 -04:00
eileencodes
c8e157bb5c Implement getclassvariable in yjit
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-10-20 18:19:42 -04:00
Noah Gibbs
4fc20a8c91 Move Ruby's README back where it was 2021-10-20 18:19:42 -04:00
Noah Gibbs
3dd4abfcd0 Move YJIT's README into doc/yjit/yjit.md 2021-10-20 18:19:42 -04:00
Noah Gibbs
6392702375 Incorporate feedback from the PR into yjit_hacking.md 2021-10-20 18:19:42 -04:00
Noah Gibbs
d4a75dd976 Add a YJIT hacking doc with some internals; change the README text a bit to reflect its current condition 2021-10-20 18:19:42 -04:00
eileencodes
f911e264a1 Add counted side exit to getblockparamproxy
This is so we know the specific reason we're exiting this instruction.

Co-authored-by: Aaron Patterson tenderlove@ruby-lang.org
2021-10-20 18:19:42 -04:00
Noah Gibbs
be06112d48 Fix changes from rebase 2021-10-20 18:19:42 -04:00
Alan Wu
f36a5a98c0 style: line break before "else" 2021-10-20 18:19:41 -04:00
Alan Wu
ec4998bd69 style: switch statements indent
Case labels get half an indent and the opening brace is on the same line
as "switch".
2021-10-20 18:19:41 -04:00
Alan Wu
a10cf74e5c style: align pointer "*" to the right 2021-10-20 18:19:41 -04:00
John Hawthorn
5b68d14c2f Add optimized Thread.current 2021-10-20 18:19:41 -04:00
Alan Wu
5c15850ea6 Use jit_guard_known_klass() for hashes in opt_aref
The old heap object check is not as efficient as the one in
jit_guard_known_klass(). Also, the old code saves cfp->sp after popping
the operands off the stack, which might cause the operands to be not
marked by the GC in some circumstances.
2021-10-20 18:19:41 -04:00
Alan Wu
9dce2d5132 Also do String#str 2021-10-20 18:19:41 -04:00
Alan Wu
1a5109cb5f Comment edits and moving functions around in the file 2021-10-20 18:19:41 -04:00
Alan Wu
a09adac2d7 Add specialization for String#to_s on plain strings
When calling "to_s" on an instance of String, the method simply returns
self. In this situation most of the work comes from setting up the
method call. It turns out that both railsbench and liquid-render do this
a lot.

When generating code for opt_send_without_block, we already generate a
known class guard, so we can detect when the receiver is a String
instance. Since gen_send_cfunc() is also used for gen_invokesuper(), and
gen_invokesuper() doesn't generate a known class guard, a new nullable
parameter for specialized codegen function is added.

Closes GH-245
2021-10-20 18:19:41 -04:00
Maxime Chevalier-Boisvert
79015926eb Try to get getblockparamproxy to support level > 0 2021-10-20 18:19:41 -04:00
Alan Wu
8edb29e5a0 Reconstruct interpreter state before calling rb_ivar_get()
It could raise ractor exceptions. The included test didn't run properly
before this change.
2021-10-20 18:19:41 -04:00
Alan Wu
d0a213b30d Remove a memory load in gen_send_iseq
Instead of loading from meory for REG_SP, do a register rename instead.
It's cheaper.
2021-10-20 18:19:41 -04:00
Alan Wu
0a108601ef Add counters for version invalidation reasons
I noticed that there were two st_table iterators that do exactly the
same thing so I merged them into one.
2021-10-20 18:19:41 -04:00
Noah Gibbs
e48fc07d11 Fix counter names 2021-10-20 18:19:41 -04:00
Noah Gibbs
7704a6990a Fix typo in comment 2021-10-20 18:19:41 -04:00
Noah Gibbs
a0790e6335 Break up callsite_not_simple into multiple cases. 2021-10-20 18:19:41 -04:00
Maxime Chevalier-Boisvert
0c1aa17556 Remove a few more uses of the global cb/ocb 2021-10-20 18:19:41 -04:00
Alan Wu
78b5e95e41 Add a slowpath for opt_getinlinecache
Before this change, when we encounter a constant cache that is specific
to a lexical scope, we unconditionally exit. This change falls back to
the interpreter's cache in this situation.

This should help constant expressions in `class << self`, which is popular
at Shopify due to the style guide.

This change relies on the cache being warm while compiling to detect the
need for checking the lexical scope for simplicity.
2021-10-20 18:19:41 -04:00
Maxime Chevalier-Boisvert
f1eb48cb23 Step 2 to remove the global cb/ocb objects. 2021-10-20 18:19:41 -04:00
Maxime Chevalier-Boisvert
c55d4cafc2 Pass the global cb through codegen functions 2021-10-20 18:19:41 -04:00
Maxime Chevalier-Boisvert
0385ca2e97 Try to break the code page refactoring into smaller steps 2021-10-20 18:19:41 -04:00
Alan Wu
c46bda6f19 Fix excessive invalidation for opt_getinlinecache
YJIT expects the VM to invalidate opt_getinlinecache when updating the
constant cache, and the invalidation used to happen even when YJIT can't
use the cached value.

Once the first invalidation happens, the block for opt_getinlinecache
becomes a stub. When the stub is hit, YJIT fails to compile the
instruction as the cache is not usable. The stub becomes a block that
exits for opt_getinlinecache which can be invalidated again. Some
workloads that bust the interpreter's constant cache can create an
invalidation loop with this behavior.

Check if the cache is usable become doing invalidation to fix this
problem.

In the test harness, evaluate the test script in a lambda instead of a
proc so `return` doesn't return out of the harness.
2021-10-20 18:19:41 -04:00
Alan Wu
6ef1609fab Correct margin for stack overflow test
In vm_push_frame(), the stack overflow test is done against a
decremented cfp. YJIT wasn't accounting for that in its stack overflow
tests.
2021-10-20 18:19:41 -04:00
John Hawthorn
7482744e04 Add jit_obj_info_dump 2021-10-20 18:19:41 -04:00
John Hawthorn
561882e96e Add comment explaining argc + 2 2021-10-20 18:19:41 -04:00
John Hawthorn
9951a9a8ec Implement invokebuiltin 2021-10-20 18:19:41 -04:00
Maxime Chevalier-Boisvert
6055078b24 Update README.md 2021-10-20 18:19:41 -04:00