summaryrefslogtreecommitdiff
path: root/yjit_core.c
AgeCommit message (Collapse)Author
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-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-20Remove a few more uses of the global cb/ocbMaxime Chevalier-Boisvert
2021-10-20Step 2 to remove the global cb/ocb objects.Maxime Chevalier-Boisvert
2021-10-20Add counters for tracking invalidationsAlan Wu
2021-10-20Store block callee_cme in darrayJohn Hawthorn
This allows a block version to have dependencies on multiple CMEs.
2021-10-20Only clear the JIT function when we invalidate the entry blockAaron Patterson
We should only clear the JIT function when the entry point is invalidated. Right now we only support compiling functions with a PC offset of zero (functions that take optional parameters can start at non-zero PC), so this patch just checks that the index is 0 before clearing the jit function
2021-10-20TracePoint supportAlan Wu
This change fixes some cases where YJIT fails to fire tracing events. Most of the situations YJIT did not handle correctly involves enabling tracing while running inside generated code. A new operation to invalidate all generated code is added, which uses patching to make generated code exit at the next VM instruction boundary. A new routine called `jit_prepare_routine_call()` is introduced to facilitate this and should be used when generating code that could allocate, or could otherwise use `RB_VM_LOCK_ENTER()`. The `c_return` event is fired in the middle of an instruction as opposed to at an instruction boundary, so it requires special handling. C method call return points are patched to go to a fucntion which does everything the interpreter does, including firing the `c_return` event. The generated code for C method calls normally does not fire the event. Invalided code should not change after patching so the exits are not clobbered. A new variable is introduced to track the region of code that should not change.
2021-10-20Allow to compile with --yjit-stats support but not the full RUBY_DEBUGJean Boussier
RUBY_DEBUG have a very significant performance overhead. Enough that YJIT with RUBY_DEBUG is noticeably slower than the interpreter without RUBY_DEBUG. This makes it hard to collect yjit-stats in production environments. By allowing to collect JIT statistics without the RUBy_DEBUG overhead, I hope to make such use cases smoother.
2021-10-20Use callee-saved regs for REG_SP, REG_EP, REG_CFPJohn Hawthorn
2021-10-20Detach mapping to local in ctx_set_local_typeJohn Hawthorn
Similar to the previous fix to ctx_clear_local_types, we must detach mappings to a local if we are changing its value.
2021-10-20Fix stack size check for ctx_get_opnd_typeJohn Hawthorn
Previously all stack operands would become unknown once the stack grew beyond a certain size. This worked, but unnecessarily hid available information.
2021-10-20Move yjit_type_of_value into yjit_core.cJohn Hawthorn
2021-10-20Implement verify_ctx for debuggingJohn Hawthorn
2021-10-20Don't generate entry point when PC != 0John Hawthorn
If we hit this at PC > 0 (ie. with an optional argument) the provided types and context are likely incorrect and it is likely this block can't be used.
2021-10-20Allow upgrading first N types when stack is largeJohn Hawthorn
2021-10-20Improve comments for mapping functionsJohn Hawthorn
2021-10-20Fix ctx_clear_local_typesJohn Hawthorn
2021-10-20Make ctx_diff aware of mappingsJohn Hawthorn
2021-10-20Introduce ctx_{get,set}_opnd_mappingJohn Hawthorn
2021-10-20Rename to ctx_upgrade_opnd_typeJohn Hawthorn
2021-10-20Make sure we can still compile with the JIT disabledAaron Patterson
If `--disable-jit-support` is passed to configure, then `jit_func` is removed from the iseq body and we can't compile YJIT. This commit detects when the JIT function pointer is gone and disables YJIT in that case.
2021-10-20Fix BOP invalidationAaron Patterson
Instead of mutating the iseqs, just clear the JIT function.
2021-10-20Add a guard that we start executing on the first PCAaron Patterson
Methods with optional parameters don't always start executing at the first PC, but we compile all methods assuming that they do. This commit adds a guard to ensure that we're actually starting at the first PC for methods with optional params
2021-10-20fix alignmentAaron Patterson
2021-10-20Flatten mappings when clearing localsJohn Hawthorn
We clear locals when we know their values might change (ex. when performing a method call). However previously values on the stack which were originally pushed from a local would still point back to that local. With this commit, when clearing locals, we'll now iterate over the mappings of the stack and copy the known type from the local to the stack mapping, removing the association to the local. This should mean both that we'll retain any information we already know about the local type, and that if a local is modified we won't incorrectly infer it's new type from the existing value on the stack.
2021-10-20Convert yjit static stat variables to countersNoah Gibbs
2021-10-20Try running with more YJIT options in CI to surface more bugsMaxime Chevalier-Boisvert
2021-10-20Update commentMaxime Chevalier-Boisvert
2021-10-20Remove #define MAX_VERSIONS, now using command-line optionMaxime Chevalier-Boisvert
2021-10-20Fix issue in yjit_free_block causing segfaultMaxime Chevalier-Boisvert
This addresses issue #55
2021-10-20Fix assertions in `invalidate_block_version()`, add small repro (#14)Maxime Chevalier-Boisvert
* Fix block invalidation assertions * Add Alan's small repro for double invalidation bug
2021-10-20Implement greedy versioning. Refactor versioning logic. (#10)Maxime Chevalier-Boisvert
* Implement eager versioning. Refactor versioning logic. * Add --version-limit and --greedy-versioning command-line args
2021-10-20Pass self type through method callsMaxime Chevalier-Boisvert
2021-10-20Malloc branch entries (#112)Maxime Chevalier-Boisvert
* Malloc branch entries * Add ASM comment for stack overflow check * WIP * Fix branch GC code. Add rb_darray_remove_unordered(). * Fix block end_pos after branch rewriting. Remove dst_patched bits.
2021-10-20Temporarily increase MAX_BRANCHES until we have a better solutionMaxime Chevalier-Boisvert
2021-10-20Diff the local types in ctx_diff()Maxime Chevalier-Boisvert
2021-10-20move assert. opnd.idx doesn't make sense for OPND_SELFAlan Wu
2021-10-20Fix bug in ctx_set_local_type()Maxime Chevalier-Boisvert
2021-10-20Re-enable local type tracking, until first callMaxime Chevalier-Boisvert
2021-10-20Assert for running out of branches in all buildsAlan Wu
2021-10-20Introduce concept of YJIT instruction operandsMaxime Chevalier-Boisvert
2021-10-20YJIT: Fancier opt_getinlinecacheAlan Wu
Make sure `opt_getinlinecache` is in a block all on its own, and invalidate it from the interpreter when `opt_setinlinecache`. It will recompile with a filled cache the second time around. This lets YJIT runs well when the IC for constant is cold.
2021-10-20Fix stack-use-after-scope in gen_direct_jump()Alan Wu
ASAN can catch these type of things for us, but the scraper can't handle ASAN :/. To be more resilient to refactoring, extend the lifetime of `generic_ctx` in branch_stub_hit() too.
2021-10-20Add flag bits to avoid compiling stubs multiple times.Maxime Chevalier-Boisvert
Fixes bug involving ractors and branch stubs.
2021-10-20Keep track of local types in the contextMaxime Chevalier-Boisvert
2021-10-20Add ctcx_stack_push_local()Maxime Chevalier-Boisvert
2021-10-20Add comments and asserts for clarityMaxime Chevalier-Boisvert