Prior to this changeset, majority of inline cache mishits resulted
into the same method entry when rb_callable_method_entry() resolves
a method search. Let's not call the function at the first place on
such situations.
In doing so we extend the struct rb_call_cache from 44 bytes (in
case of 64 bit machine) to 64 bytes, and fill the gap with
secondary class serial(s). Call cache's class serials now behavies
as a LRU cache.
Calculating -------------------------------------
ours 2.7 2.6
vm2_poly_same_method 2.339M 1.744M 1.369M i/s - 6.000M times in 2.565086s 3.441329s 4.381386s
Comparison:
vm2_poly_same_method
ours: 2339103.0 i/s
2.7: 1743512.3 i/s - 1.34x slower
2.6: 1369429.8 i/s - 1.71x slower
To perform a regular method call, the VM needs two structs,
`rb_call_info` and `rb_call_cache`. At the moment, we allocate these two
structures in separate buffers. In the worst case, the CPU needs to read
4 cache lines to complete a method call. Putting the two structures
together reduces the maximum number of cache line reads to 2.
Combining the structures also saves 8 bytes per call site as the current
layout uses separate two pointers for the call info and the call cache.
This saves about 2 MiB on Discourse.
This change improves the Optcarrot benchmark at least 3%. For more
details, see attached bugs.ruby-lang.org ticket.
Complications:
- A new instruction attribute `comptime_sp_inc` is introduced to
calculate SP increase at compile time without using call caches. At
compile time, a `TS_CALLDATA` operand points to a call info struct, but
at runtime, the same operand points to a call data struct. Instruction
that explicitly define `sp_inc` also need to define `comptime_sp_inc`.
- MJIT code for copying call cache becomes slightly more complicated.
- This changes the bytecode format, which might break existing tools.
[Misc #16258]
for ISeq including only leaf and no-handles_sp insns except leaf.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67574 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This refactoring is needed for implementing inlining later.
I've had this since long ago and it has conflicted sometimes. So let me
just commit this now.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67566 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
I'm writing `//` comments in newer MJIT code after C99 enablement
(because I write 1-line comments more often than multi-line comments
and `//` requires fewer chars on 1-line) and then they are mixed
with `/* */` now.
For consistency and to avoid the conversion in future changes, let me
finish the rewrite in MJIT-related code.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
cfp->bp was (re-)introduced by Kokubun san, but VM doesn't use it
because I (ko1) want to remove it in a future. But using it make
leave instruction fast because of sp consisntency check.
So now VM uses cfp->bp.
To use cfp->bp, I checked the value and I found that it is not a
"initial value of sp" but a "initial value of ep". Fix this problem
and fix all bp references (this is why bp is renamed to bp_).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
to avoid inlining a method call when it becomes argument_arity_error,
fixing a potential bug.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67330 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
to make it easier to understand what values are grouped.
Just cosmetic changes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
by changing interface of `mjit_copy_cache_from_main_thread`.
This is also fixing deadlock introduced by r67299.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67300 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
I noticed that r67287 was illegal because memory allocated by `alloca`
was used after the stack is expired.
So I just replaced that with `malloc` and `free` for now.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This reverts commit 4161674b2f.
Revert "Eliminate mjit_copy_job_t reference from mjit_worker"
This reverts commit d86a1aa045.
Reverting them because of CI failures
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67291 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
rather than preparing beforehand.
By having this change, implementing inlining by calling
`mjit_copy_cache_from_main_thread` for inlined methods was made
possible.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
and functions to clarify the intention and make sure it's not used in a
surprising way (like using 2, 3, ... other than 0, 1 even while it seems
to be a boolean).
This is a retry of r66775. It included some typos...
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66778 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This reverts commit bb1a1aeab0.
We hit something on ci.rvm.jp, reverting until investigation is done.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
and functions to clarify the intention and make sure it's not used in a
surprising way (like using 2, 3, ... other than 0, 1 even while it seems
to be a boolean).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
on VM_CHECK_INTS. Letting MJIT worker directly see inline cache which
may be being updated could result in inconsistent IC index and serial.
mjit_worker.c: request the copy job after dequeue, and receive the
result synchronously.
tool/ruby_vm/views/_mjit_compile_ivar.erb: use the copied IC
mjit_compile.c: change the interface to pass is_entries
mjit.h: ditto
=== Optcarrot Benchmark ===
Thankfully this didn't have major performance regression.
$ benchmark-driver benchmark.yml --rbenv 'before::before --disable-gems --jit;after::after --disable-gems --jit' -v --repeat-count 24
before: ruby 2.6.0dev (2018-10-21 trunk 65263) +JIT [x86_64-linux]
after: ruby 2.6.0dev (2018-10-21 trunk 65263) +JIT [x86_64-linux]
last_commit=mjit.c: copy inline cache values to MJIT worker
Calculating -------------------------------------
before after
Optcarrot Lan_Master.nes 85.421 85.454 fps
Comparison:
Optcarrot Lan_Master.nes
after: 85.5 fps
before: 85.4 fps - 1.00x slower
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* configure.ac: introduce new configure option `--enable-mjit` and
`--disable-mjit`. Default is "enable".
`--disable-mjit` disables all of MJIT features so that `ruby --jit`
can't enable MJIT.
This option affect a macro `USE_MJIT`.
This change remove `--enable/disable-install-mjit-header` option.
* Makefile.in: introduce the `ENABLE_MJIT` variable.
* common.mk: use `ENABLE_MJIT` option.
* internal.h: respect `USE_MJIT`. Same as other *.c, *.h.
* test/ruby/test_jit.rb: check `ENABLE_MJIT` key of rbconfg.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
intentionally inserting tab to this line to test svn bot.
Also expanding the all tabs in this file, since this file does not exist
in old versions and so there's no risk of conflict on backport.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
because it's actually setting fastpath to cc instead of ci since r51903.
vm_insnhelper.c: ditto
mjit_compile.c: ditto
tool/ruby_vm/views/_mjit_compile_send.erb: ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
on MJIT worker. That may trigger GC. And handled strdup failure instead.
mjit_compile.c: update comment about GC
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
from mjit.c because it's executed only on MJIT worker thread.
Instead of that, `valid_class_serials` is shared with mjit_ prefix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
The motivation of this change is to make sure rb_funcall or GC-related
functions are not called on worker-related code. Currently such
functions are used in some places and I believe it's partly because it's
hard to identify which part is called on MJIT worker thread.
Now, mjit.c is safe to use them but we know we need to safely deal with
mjit_compile.c, mjit_worker.c and mjit_internal.h.
mjit_compile.c: update the comment about it
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
implementation. This had no major performance impact by effort to keep
them inlined.
vm_insnhelper.c: ditto
mjit_compile.c: just update the comment about opt_pc=0 assumption
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
which was missing in r64033.
Prior to r64033, memory allocation failure had been checked by
TRY_WITH_GC and handled by rb_memerror. But calling rb_memerror on MJIT
worker is problematic since it does EC_JUMP_TAG in the end. Threads
except Ruby's main thread must not use it.
mjit_compile.c: ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
mjit_compile.c: ditto.
REALLOC_N, ALLOC_N and xmalloc trigger GC but it's not expected.
Other allocation calls in mjit.c are executed on Ruby's main thread and
thus fine.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64033 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This optimization was reverted on r63863, but this commit resurrects the
optimization to skip some sp motions on JIT execution.
tool/ruby_vm/views/_mjit_compile_insn_body.erb: ditto
tool/ruby_vm/views/_mjit_compile_insn.erb: ditto
insns.def: resurrect handles_frame as handles_stack, which was deleted
on r63763.
tool/ruby_vm/models/bare_instructions.rb: ditto
vm_insnhelper.c: prevent moving sp outside insns.def to allow modifying
it by JIT.
* Optcarrot benchmark
$ benchmark-driver benchmark.yml --rbenv 'before --jit;after --jit' --repeat-count 12 -v
before --jit: ruby 2.6.0dev (2018-07-17 trunk 63987) +JIT [x86_64-linux]
after --jit: ruby 2.6.0dev (2018-07-17 local-stack 63987) +JIT [x86_64-linux]
last_commit=mjit_compile.c: resurrect local variable stack
Calculating -------------------------------------
before --jit after --jit
Optcarrot Lan_Master.nes 70.518 72.144 fps
Comparison:
Optcarrot Lan_Master.nes
after --jit: 72.1 fps
before --jit: 70.5 fps - 1.02x slower
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
r63655 was tightly coupled to handle_frames and some assumptions seems
to have been broken by r63763.
To partially resolve Bug#14892, this reverts the optimization for now. I
want to make MJIT CI happy first and then I'll probably retry r63655 by
partially reverting r63763 for sp changes.
The skipped test is not fixed yet.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
The loop for `vm_exce_handle_exception` doesn't trigger `mjit_exec`, so
I don't think this code is no longer needed.
This was needed in development of original version of this JIT, but it
seems not needed from the beginning (r62189) at Ruby repository.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Revert "_mjit_compile_send.erb: inline recursive call"
I reverted r63360 in r63379, but the errors were reproductive from
r63350. So I need to revert this.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
after return or longjmp. This is mainly for skipping the check of stack
size in such cases, which shouldn't be checked because it does never
happen.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63332 b2dd03c8-39d4-4d8f-98ff-823fe69b080e