summaryrefslogtreecommitdiff
path: root/mjit_worker.c
AgeCommit message (Collapse)Author
2019-04-14Avoid crash on logging GC-ed ISeqk0kubun
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67552 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-14Add debug counter for MJIT stale_unitsk0kubun
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67546 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-04-10Adjusted stylesnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10Reverting all commits from r67479 to r67496 because of CI failureskazu
Because hard to specify commits related to r67479 only. So please commit again. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10Adjusted stylesnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-29mjit_worker.c: explicitly ignore the unused result of RB_DEBUG_COUNTER_INC_IFmame
By adding `(void)`. This makes Coverity Scan happy. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-29Add mjit_compile_failures debug counterk0kubun
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67382 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-18Use alloca again instead of malloc and freek0kubun
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
2019-03-18Resurrect r67287 and r67288k0kubun
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
2019-03-18Revert "Eliminate mjit_copy_job_t reference from mjit_worker"k0kubun
This reverts commit ba51ae0109ee1d1fa7ca90b43da115ea68d7214a. CI is failing again... git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-18Eliminate mjit_copy_job_t reference from mjit_workerk0kubun
Take 2 of r67287. For some reasons, passing pointer of pointer on stack to a function and assigning an addresse to a pointer dereferenced from the pointer seems not working on mswin. So I achieved to return multiple values by returning struct instead of taking pointers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-18Revert "Request inline cache values from mjit_compile"k0kubun
This reverts commit 4161674b2fbea6bdd01783ac5d3b39d88db22972. Revert "Eliminate mjit_copy_job_t reference from mjit_worker" This reverts commit d86a1aa045959dfbf5cd472eae0d043180259727. Reverting them because of CI failures git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67291 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-17Request inline cache values from mjit_compilek0kubun
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
2019-03-17Eliminate mjit_copy_job_t reference from mjit_workerk0kubun
and make `copy_cache_from_main_thread` easier to use. For implementing inlining later, I'll use `copy_cache_from_main_thread` inside `mjit_compile`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67287 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 a typo [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-19Revert "mjit_worker.c: try to simplify CC_DLDFLAGS_ARGS"k0kubun
This reverts commit 405940234eb7876a063eb7129ca61fcc318a633c. Not working on MinGW https://ci.appveyor.com/project/ruby/ruby/builds/21737578/job/09a2tr94vof6fstt git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-19mjit_worker.c: try to simplify CC_DLDFLAGS_ARGSk0kubun
assuming that -nostartfiles is just optional for mingw, cygwin, and AIX. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-19mjit_worker.c: do not use GCC_NOSTDLIB_FLAGS for OpenBSDk0kubun
OpenBSD's GCC compiler has local extensions that break when `-nostartfiles -nodefaultlibs -nostdlib` is used. From: Jeremy Evans <merch-redmine@jeremyevans.net> [Bug #15548] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-15Revert "mjit_worker.c: try passing -nostdlib to AIX"k0kubun
This reverts commit b32fb23083912c37a2601c66531ed786a7c9f3e5. This didn't work on AIX. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-14mjit_worker.c: pass -nostdlib when making pch as wellk0kubun
[Bug #15513] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-14mjit_worker.c: try passing -nostdlib to AIXk0kubun
r66812 might have allowed this. Testing. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66816 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-14mjit_worker.c: pass -lgcc to GCC platformsk0kubun
using `-nodefaultlibs -nostdlib`. I assume libgcc is needed when we use -nostdlib, and it's linked on some platforms but not linked on some platforms (like aarch64, and possibly AIX as well) as said in https://wiki.osdev.org/Libgcc : > You can link with libgcc by passing -lgcc when linking your kernel with your compiler. You don't need to do this unless you pass the -nodefaultlibs option (implied by -nostdlib) Also note that -nostdlib is not strictly needed (rather implied -nodefaultlibs is problematic for Gentoo like Bug#15513, which will be approached later) but helpful for performance. So I want to keep it for now. [Bug #15522] I'm not trying to add `-nodefaultlibs -nostdlib` for AIX in this commit because AIX RubyCI is dead right now, but I'll try to add them again once RubyCI is fixed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66812 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-14mjit_worker.c: untangle CC_LIBS nestingk0kubun
This should have no impact. The CC_LIBS was too hard to read for human. I don't remember whether the order of -lmsvcrt and -lgcc matters or not, but I kept that for the best safety. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66811 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-12trivial fix r66778 [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66798 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
2019-01-09Fix styles [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-04Enable MJIT on AIXodaira
* configure.ac: disable using __builtin_setjmp to avoid errors when execution globally jumps out of JITted code. Specify -std=gnu99 to JIT compilation to avoid errors regarding the "restrict" keyword in the precompiled header. Specify -shared in addition to -Wl,-G when building shared libraries to make mjit_build_dir.so expose the MJIT_BUILD_DIR symbol. Use LDR_PRELOAD to load mjit_build_dir.so. * mjit_worker.c: do not specify -nodefaultlibs or -nostdlibs because on AIX JITted code internally refers to the memcpy function. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66202 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-26Support targetting TracePoint [Feature #15289]ko1
* vm_trace.c (rb_tracepoint_enable_for_target): support targetting TracePoint. [Feature #15289] Tragetting TracePoint is only enabled on specified method, proc and so on, example: `tp.enable(target: code)`. `code` should be consisted of InstructionSeuqnece (iseq) (RubyVM::InstructionSeuqnece.of(code) should not return nil) If code is a tree of iseq, TracePoint is enabled on all of iseqs in a tree. Enabled tragetting TracePoints can not enabled again with and without target. * vm_core.h (rb_iseq_t): introduce `rb_iseq_t::local_hooks` to store local hooks. `rb_iseq_t::aux::trace_events` is renamed to `global_trace_events` to contrast with `local_hooks`. * vm_core.h (rb_hook_list_t): add `rb_hook_list_t::running` to represent how many Threads/Fibers are used this list. If this field is 0, nobody using this hooks and we can delete it. This is why we can remove code from cont.c. * vm_core.h (rb_vm_t): because of above change, we can eliminate `rb_vm_t::trace_running` field. Also renamed from `rb_vm_t::event_hooks` to `global_hooks`. * vm_core.h, vm.c (ruby_vm_event_enabled_global_flags): renamed from `ruby_vm_event_enabled_flags. * vm_core.h, vm.c (ruby_vm_event_local_num): added to count enabled targetting TracePoints. * vm_core.h, vm_trace.c (rb_exec_event_hooks): accepts hook list. * vm_core.h (rb_vm_global_hooks): added for convinience. * method.h (rb_method_bmethod_t): added to maintain Proc and `rb_hook_list_t` for bmethod (defined by define_method). * prelude.rb (TracePoint#enable): extracet a keyword parameter (because it is easy than writing in C). It calls `TracePoint#__enable` internal method written in C. * vm_insnhelper.c (vm_trace): check also iseq->local_hooks. * vm.c (invoke_bmethod): check def->body.bmethod.hooks. * vm.c (hook_before_rewind): check iseq->local_hooks and def->body.bmethod.hooks before rewind by exception. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26mjit_worker.c: disable running copy jobk0kubun
after MJIT worker stop. r65928 didn't fix the SEGV. This commit hopes to fix http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/1478576 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65993 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_worker.c: avoid GC when modifying ISeqk0kubun
This is hoped to fix the SEGV: https://app.wercker.com/ruby/ruby/runs/mjit-test1/5bf392cf183106002856c1f0?step=5bf3bddc87436a0006292535 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65883 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
2018-11-18mjit_worker.c: fix typo [ci skip]k0kubun
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65783 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-07mjit_worker.c: stop expanding already-absolute MJIT_CCk0kubun
r65577 seems to have made MJIT_CC (MJIT_CC_COMMONA) become an absolute path. So start_process doesn't need to find that from PATH by dln_find_exe_r. This commit is motivated by the msys2 AppVeyor CI failure: https://ci.appveyor.com/project/ruby/ruby/builds/20084104/job/1pg15os4dtttyl0q git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-06mjit_worker.c: don't use _one for nowk0kubun
I'm planning to use _one later, but it may be doubly registered by switching `stop_worker_p` now and so we should not use _one for now. Otherwise stale job may reject new job registration and copy_cache_from_main_thread may wait forever. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-06mjit_worker.c: strictly control MJIT copy jobk0kubun
-available region. reducing risk of SEGV in mjit_copy_job_handler() like http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1446117 I'm not sure which exact part is causing "[BUG] Segmentation fault at 0x0000000000000008" on `(mjit_copy_job_handler+0x12) [0x564a6c4ce632] /home/ko1/ruby/src/trunk-mjit/mjit.c:26`... mjit.c: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-02mjit_worker.c: do no access pointer after freek0kubun
When we return there, `unit` is already freed. This is detected by coverity scan. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-01mjit_worker.c: emphasize free_list of compact_units [ci skip]k0kubun
In https://bugs.ruby-lang.org/issues/14867#note-98, it's considered useless at once. So I emphasized the necessity of it in the comment. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-31mjit: get rid of rb_mjit_unit_node and use ccan/listnormal
rb_mjit_unit can either exist in unit_queue or active_units, but not both. This will make state transitions for event-based MJIT process management easier. v2: recheck unit->iseq after GC wakeup The iseq may be GC-ed while we were waiting for it since we delete the unit from unit_queue during get_from_list git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65475 b2dd03c8-39d4-4d8f-98ff-823fe69b080e