summaryrefslogtreecommitdiff
path: root/yjit_codegen.c
AgeCommit message (Collapse)Author
2021-10-21YJIT: don't compile attr_accessor methods when tracing (#4998)Alan Wu
2d98593bf54a37397c6e4886ccc7e3654c2eaf85 made it so that attr_accessor methods fire C method tracing events. Previously, we weren't checking for whether we are tracing before compiling, leading to missed events. Since global invalidation invalidates all code, and that attr_accessor methods can never enable tracing while running, events are only dropped when YJIT tries to compile when tracing is already enabled. Factor out the code for checking tracing and check it before generating code for attr_accessor methods. This change fixes TestSetTraceFunc#test_tracepoint_attr when it's ran in isolation. Notes: Merged-By: maximecb
2021-10-20Fix non RUBY_DEBUG build warningsAlan Wu
On non RUBY_DEBUG builds, assert() compiles to nothing and the compiler warns about uninitialized variables in those code paths. Replace those asserts with rb_bug() to fix the warnings and do the assert in all builds. Since yjit_asm_tests.c compiles outside of Ruby, it needed a distinct version of rb_bug(). Also put YJIT_STATS check for function delcaration that is only defined in YJIT_STATS builds.
2021-10-20Do kwarg shuffle after checking for interruptsAlan Wu
Previously, we were shuffling keyword arguments before checking for interrupts. In the case that we side exit in the interrupt check, we left the interpreter with an already-shuffled argument list for the call, resulting in a double shuffle, leaving the locals in the wrong order for the callee. Do keyword shuffling after all the possible side exits. Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2021-10-20Extract yjit_force_iv_index and make it work when object is frozenAlan Wu
In an effort to simplify the logic YJIT generates for accessing instance variable, YJIT ensures that a given name-to-index mapping exists at compile time. In the case that the mapping doesn't exist, it was created by using rb_ivar_set() with Qundef on the sample object we see at compile time. This hack isn't fine if the sample object happens to be frozen, in which case YJIT would raise a FrozenError unexpectedly. To deal with this, make a new function that only reserves the mapping but doesn't touch the object. This is rb_obj_ensure_iv_index_mapping(). This new function superceeds the functionality of rb_iv_index_tbl_lookup() so it was removed. Reported by and includes a test case from John Hawthorn <john@hawthorn.email> Fixes: GH-282
2021-10-20Expand tabsAlan Wu
2021-10-20Add String#bytesizeeileencodes
Fixes: https://github.com/Shopify/yjit/issues/258 Co-authored-by: Aaron Patterson tenderlove@ruby-lang.org
2021-10-20else if styleAlan Wu
2021-10-20Update yjit_codegen.cMaxime Chevalier-Boisvert
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2021-10-20Update yjit_codegen.cMaxime Chevalier-Boisvert
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2021-10-20Feedback, tests, and rebase for kwargsKevin Newton
2021-10-20Bail out if passing keyword arguments to only positional and/or optional methodsKevin Newton
2021-10-20Set up the callee stack pointer properly taking into account the bits objectKevin Newton
2021-10-20Correct for positional required argumentsKevin Newton
2021-10-20Push the unspecified_bits_value onto the stackKevin Newton
2021-10-20Reuse stack swapping logicKevin Newton
2021-10-20Get kwargs reordering workingKevin Newton
2021-10-20Get kwargs working for all passed in the correct orderKevin Newton
2021-10-20Put YJIT into a single compilation unitAlan Wu
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-20Fix gen_getclassvariableAlan Wu
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-20Fix counter names for getblockparamproxy. Print in --yjit-stats.Maxime Chevalier-Boisvert
2021-10-20Implement getclassvariable in yjiteileencodes
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-10-20Add counted side exit to getblockparamproxyeileencodes
This is so we know the specific reason we're exiting this instruction. Co-authored-by: Aaron Patterson tenderlove@ruby-lang.org
2021-10-20Fix changes from rebaseNoah Gibbs
2021-10-20style: line break before "else"Alan Wu
2021-10-20style: switch statements indentAlan Wu
Case labels get half an indent and the opening brace is on the same line as "switch".
2021-10-20style: align pointer "*" to the rightAlan Wu
2021-10-20Add optimized Thread.currentJohn Hawthorn
2021-10-20Use jit_guard_known_klass() for hashes in opt_arefAlan Wu
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-20Also do String#strAlan Wu
2021-10-20Comment edits and moving functions around in the fileAlan Wu
2021-10-20Add specialization for String#to_s on plain stringsAlan Wu
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-20Try to get getblockparamproxy to support level > 0Maxime Chevalier-Boisvert
2021-10-20Reconstruct interpreter state before calling rb_ivar_get()Alan Wu
It could raise ractor exceptions. The included test didn't run properly before this change.
2021-10-20Remove a memory load in gen_send_iseqAlan Wu
Instead of loading from meory for REG_SP, do a register rename instead. It's cheaper.
2021-10-20Add counters for version invalidation reasonsAlan Wu
I noticed that there were two st_table iterators that do exactly the same thing so I merged them into one.
2021-10-20Fix counter namesNoah Gibbs
2021-10-20Fix typo in commentNoah Gibbs
2021-10-20Break up callsite_not_simple into multiple cases.Noah Gibbs
2021-10-20Remove a few more uses of the global cb/ocbMaxime Chevalier-Boisvert
2021-10-20Add a slowpath for opt_getinlinecacheAlan Wu
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-20Step 2 to remove the global cb/ocb objects.Maxime Chevalier-Boisvert
2021-10-20Pass the global cb through codegen functionsMaxime Chevalier-Boisvert
2021-10-20Fix excessive invalidation for opt_getinlinecacheAlan Wu
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-20Correct margin for stack overflow testAlan Wu
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-20Add jit_obj_info_dumpJohn Hawthorn
2021-10-20Add comment explaining argc + 2John Hawthorn
2021-10-20Implement invokebuiltinJohn Hawthorn
2021-10-20Implement generic setlocalJohn Hawthorn
2021-10-20Extract gen_get_epJohn Hawthorn
2021-10-20Fix opt_aset comptime_key checkJohn Hawthorn