summaryrefslogtreecommitdiff
path: root/mjit.c
AgeCommit message (Collapse)Author
2019-08-22* expand tabs. [ci skip]git
Tabs are expanded because previously the file did not have any tab indentation. Please update your editor config, and use misc/expand_tabs.rb in the pre-commit hook.
2019-08-22Improve the description of MJIT cancel-all [ci skip]Takashi Kokubun
2019-05-18Rename rb_gc_new_location to rb_gc_locationAaron Patterson
The function will return new or existing locations depending on whether or not the object actually moved, so give it a more appropriate name.
2019-05-15Rename mjit_gc_finish_hook to mjit_gc_exit_hookTakashi Kokubun
because @ko1 said "gc_finish" is confusing like a finish of entire GC process
2019-04-29glibc says memcpy cannot take NULLUrabe, Shyouhei
At least since 2004, glibc's <string.h> annotates memcpy as __attribute__((__nonnull__)). This basedir is passed to it. When LOAD_RELATIVE is not defined and MJIT_SEARCH_BUILD_DIR is not set, this variable is never updated. Should initialize with meaningful default value.
2019-04-20Fix wrong critical section labelk0kubun
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67644 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20Prefix rb_ to MJIT wait call since it's exportedk0kubun
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20Revert "Revert "Skip ISeq reference for stale_units for debugging""k0kubun
This reverts commit b79899b56a9ebadf5c493c4df2419ebf63934381. I wanted to test r67638 first. Now let me try this as well. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20Invalidate JIT-ed code if ISeq is moved by GC.compactk0kubun
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67638 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20Revert "Skip ISeq reference for stale_units for debugging"k0kubun
This reverts commit 4bd4d4e4cfd164f767e88f844cf10b06faee14b9. Sorry, let me test another one first git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67637 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20Skip ISeq reference for stale_units for debuggingk0kubun
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20Check ISeq references in stale_units took0kubun
This is a possible bug from recent "JIT recompile" introduction. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20Update ISeq references in stale_units as wellk0kubun
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20fix strict compile errorstenderlove
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20Update MJIT referencestenderlove
ISeq can move, so we need to tell MJIT where the new location is. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-14Do not execute MJIT copy job when ISeq is GC-edk0kubun
I assumed that ISeq is never GC-ed by `in_jit` + `mjit_mark` on copy job ISeq, but unfortunately I found SEGV on `mjit_copy_job_handler` in which iseq->body was somehow Qnil. And it seems to be fixed by disabling the job when `mjit_free_iseq` is called for the ISeq. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-14Prefer uintptr_t over ptrdiff_t for i686k0kubun
as debugged in PR [close https://github.com/ruby/ruby/pull/2130] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-14Revert "Try to set false explicitly"k0kubun
This reverts commit a1b5d20068a9b1859b383b249e510cd33d196e4a. Revert "Revert "Skip recompiling tests on i686 Linux"" This reverts commit 7b88a9207b97b94bc3c3be35084c742296f4aff2. Revert "Simplify matrix for debugging" This reverts commit e85d6c5c5e62dde37c6f6ffdb7125b9008b9ebfa. Sorry, these 3 commits were under debugging in https://github.com/ruby/ruby/pull/2129 but accidentally merged by using `git svn dcommit` instead of `git push` to the topic branch :bow: git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67538 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-14Try to set false explicitlyk0kubun
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-14Unify comment styles across MJIT sourcesk0kubun
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
2019-04-14Recompile JIT-ed code without optimizationk0kubun
based on inline cache when JIT cancel happens by that. This feature was in the original MJIT implementation by Vladimir, but on merging MJIT to Ruby it was removed for simplification. This commit adds the functionality again for the following benchmark: https://github.com/benchmark-driver/misc/blob/52f05781f65467baf895bf6ba79d172c9b0826fd/concurrent-map/bench.rb (shown float is duration seconds. shorter is better) * Before ``` $ INHERIT=0 ruby -v bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux] -- 1.6507579649914987 $ INHERIT=0 ruby -v --jit bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux] -- 1.5091587850474752 $ INHERIT=1 ruby -v bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux] -- 1.6124781150138006 $ INHERIT=1 ruby --jit -v bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux] -- 1.7495657080435194 # <-- this ``` * After ``` $ INHERIT=0 ruby -v bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux] last_commit=Recompile JIT-ed code without optimization -- 1.653559010999743 $ INHERIT=0 ruby --jit -v bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux] last_commit=Recompile JIT-ed code without optimization -- 1.4738391840364784 $ INHERIT=1 ruby -v bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux] last_commit=Recompile JIT-ed code without optimization -- 1.645227018976584 $ INHERIT=1 ruby --jit -v bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux] last_commit=Recompile JIT-ed code without optimization -- 1.523708809982054 # <-- this ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-29Prevent mjit length counters from being 0k0kubun
It seems that `debug_counter_show_results_at_exit` could be called earlier than `mjit_finish` sometimes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-29Add debug counter for rb_mjit_unit_listk0kubun
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67378 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-17Drop rb_mjit_unit from mjit_copy_jobk0kubun
and guard iseq from GC by marking iseq in mjit_copy_job. This is a refactoring for implementing inlining later and should not be fixing or introducing any bugs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67286 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-17Fix typos [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-17Change defaults of --jit optionsk0kubun
* --jit-min-calls: 5 -> 10000 --jit-min-calls=5 obviously can compile non hotspot. This was not a problem for MJIT-benchmarks and Optcarrot because the former has very few hot optimiziable methods and the latter is likely to trigger compilation of hotspot by its intensive calls to optimizable hotspot methods and has a very short window to allow limited compilations. In real-world applications, it has more time to compile more methods and it pressures computer's limited resources like icache. We should avoid compiling too many methods. Also compiling many methods exhausts time budget for compilation in one ruby process lifetime and delays the "JIT compaction" of Ruby 2.6. JVM is known to use 1,500 for C1 (client) compiler and 10,000 for C2 (server) compiler for -XX:CompileThreshold by default. https://docs.oracle.com/javase/8/embedded/develop-apps-platforms/codecache.htm When things are called X,000 times, requiring 10,000 can eliminate compilation of methods which are called only once in these X,000 iterations and obviously not hotspot. And in fact things like unicorn-worker-killer restarts unicorn process every 4096 requests. So I felt 10,000 is good for such an environment. * --jit-max-cache: 1000 -> 100 By the same reason stated above, we should not allow compiling many methods especially on MJIT which has a larger overhead due to poor code locality by dlopen and whose code is also likely to be bigger by just inlining many VM instructions with -O3 rather than directly generating low-level code. In JVM -XX:ReservedCodeCacheSize is 32M for reserved and 48M for maximum. --jit-max-cache=1,000 could be closer to it, but in this case MJIT's compilation is slow due to data synchronization between threads (to be improved in Ruby 2.7 though) and we do not want to delay the "JIT compaction" for a long time. So I chose a really conservative number for this, but by having method inlining in the future, wider range could be optimized even with this value. * Optcarrot --disable-gems, --benchmark Lan_Master.nes 12 attempts. No significant impact. | r67276 | r67276 --jit | after --jit | |:-------------------|:------------------|:------------------| | 50.44369263063978 | 72.87390680773056 | 73.47873485047297 | | 50.58788746124193 | 78.06820808947026 | 78.29723420171945 | | 50.77509250801378 | 80.29010348842613 | 78.94689404460769 | | 50.935361702064405 | 80.42796829926374 | 80.39539527351525 | | 51.27352672981195 | 81.98758158033202 | 81.6754198664817 | | 51.720715743242124 | 82.00118535811626 | 82.22960569251283 | | 51.89643169822524 | 82.2290091613556 | 82.5013636146388 | | 51.95895898113868 | 82.37318990939565 | 82.74002377794454 | | 52.10124886807968 | 82.48796686037502 | 83.23354941183932 | | 52.292280637519376 | 83.0265226541066 | 84.01552618012572 | | 52.51856237784144 | 83.8797360318052 | 84.8588319093393 | | 52.65076845986818 | 84.80037351256634 | 85.13577756273656 | * Railsbench `WARMUP=20000 BENCHMARK=1000 bin/bench` of https://github.com/k0kubun/railsbench. It gets closer to --disable=jit. | | r67276 | r67276 | after | | | | --jit | --jit | |:----------|:-------|:-------|:-------| | req/s | 891.3 | 742.2 | 841.5 | |:----------|:-------|:-------|:-------| | 50%ile ms | 1.00 | 1.21 | 1.08 | | 66%ile ms | 1.02 | 1.24 | 1.09 | | 75%ile ms | 1.03 | 1.28 | 1.10 | | 80%ile ms | 1.03 | 1.30 | 1.11 | | 90%ile ms | 1.09 | 1.42 | 1.15 | | 95%ile ms | 1.32 | 1.65 | 1.27 | | 98%ile ms | 4.79 | 2.23 | 1.81 | | 99%ile ms | 5.68 | 7.52 | 6.64 | |100%ile ms | 6.52 | 9.69 | 8.59 | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10mjit.c: use boolean type for boolean variablesk0kubun
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
2019-01-10Revert "mjit.c: use boolean type for boolean variables"k0kubun
This reverts commit bb1a1aeab0f2a5fe437c89b841a887ba56653453. 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
2019-01-10mjit.c: use boolean type for boolean variablesk0kubun
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
2018-12-09Removed never-happening casenobu
get_uniq_filename never returns NULL but raises an exception on failure. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-08Duplicate header name only if foundnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66284 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-08Fix compile error at r66280nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-08Give the MJIT header path namenobu
Give the whole MJIT header path name by preloaded shared library mjit_build_dir.so, than building the path from a given directory name and the embedded base name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-07Fix memory leak when failed to build pch pathnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-04mjit.c: remove init_listnormal
It is not needed since we have LIST_HEAD_INIT initializer in mjit_worker.c git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-04unconstify cast to get rid of VC++ warningsusa
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03mjit.c: eliminate -save-temps flagk0kubun
in a new variable cc_common_args. `cflags=-save-temps=obj` makes MJIT fail like: https://rubyci.org/logs/www.rubyist.net/~akr/chkbuild/debian/ruby-trunk/log/20181203T095000Z.log.html.gz This rubyci specifies -save-temps=obj in CFLAGS to use update-deps, and the flag is harmful when we want to use -pipe flag. mjit_worker.c: prefer cc_common_args over CC_COMMON_ARGS git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03mjit_worker.c: undefine CC_PATHk0kubun
because we mostly use cc_path now and the comment is obsolete (CC_PATH is now absolute path and the TODO is already resolved). mjit.c: use CC_COMMON_ARGS[0] directly git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-30vm_trace.c: workqueue as thread-safe version of postponed_jobnormal
postponed_job is safe to use in signal handlers, but is not thread-safe for MJIT. Implement a workqueue for MJIT thread-safety. [Bug #15316] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66100 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27mjit_worker.c: promote mjit_copy_job from functionk0kubun
-local variable to global variable. Consider this case: 1. MJIT worker: dequeue ISeq (stop_worker_p was still FALSE) 2. Ruby thread: call Kernel#exec, which calls mjit_finish(FALSE), sets `stop_worker_p = TRUE`, and fires RUBY_VM_CHECK_INTS() once 3. MJIT worker: register copy job, but found stop_worker_p is TRUE. set `worker_stopped = TRUE` and the thread stops. 4. Function-local job variable expires by the thread stop (this is eliminated by this commit) 5. Ruby thread: find `worker_stopped` becamse TRUE, start Kernel#exec. Kernel#exec fails but exception is rescued. 6. Ruby thread: call RUBY_VM_CHECK_INTS. copy job is dispatched but job variable is already expired. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26vm_trace.c: MJIT-limited thread-safety for postponed_jobk0kubun
[Bug #15316] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26process.c: avoid dlclose before execk0kubun
because JIT-ed code may still be on stack at this time, unlike in ruby_cleanup(). This hopes to fix: (take 2) http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/1480207 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26Revert "process.c: try to workaroun SEGV by r65994"k0kubun
This reverts commit 0e6aba22c6b876a36adc39cac5314ce6e626954c. because it didn't help, at all. http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/1480207 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65998 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26process.c: try to workaroun SEGV by r65994k0kubun
http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/1480173 It tries to print C backtrace but fails. And core file on the server seems to be stopping on the irrelevant place due to its own signal handler for the dump. And I failed to reproduce this SEGV on my machine. I don't know why it's broken, so let me try this change to investigate the reason of SEGV. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22mjit.c: avoid running copy job handler after ISeq GCk0kubun
like this http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1471633 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20mjit.c: fix typos [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-19revert r65807k0kubun
it didn't work. http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1468677 and skips broken tests for now. But this issue should be fixed soon. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-19process.c: do not run signal handler before forkk0kubun
to prevent from proceeding one for MJIT while it's not safe yet. By that situation, MJIT worker could be waiting for compiler process forever http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1468033 [Bug #15320] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-18mjit.c: fix deadlock introduced by r65785k0kubun
in mjit_pause() fired by before_fork_ruby(). When calling RUBY_VM_CHECK_INTS() in mjit_pause()'s loop, other threads may call start_worker() which sets `stop_worker_p = FALSE` and it could wait for MJIT worker stop forever even while `stop_worker_p` is FALSE. http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1466333 https://gist.github.com/ko1/a57ef1a03e1c7cfd22f1495e0864b63d http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/1466335 https://gist.github.com/ko1/96e867e36e6b75559b3d926f8c0bdaeb https://app.wercker.com/ruby/ruby/runs/mjit-test1/5bf1221c183106002855989c?step=5bf1225987436a0006192c31 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65790 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-18mjit_worker.c: support MJIT in forked Ruby processk0kubun
by launching MJIT worker thread in child Ruby process. See the comment before `mjit_child_after_fork` for details. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e