summaryrefslogtreecommitdiff
path: root/thread.c
AgeCommit message (Collapse)Author
2018-02-23[DOC] missing docs at toplevelnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-18thread.c: remove redundant USE_SIGALTSTACK #definenormal
thread.c already includes vm_core.h where USE_SIGALTSTACK is defined, #include it explicitly (eval_intern.h already includes it) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-18thread.c (thread_join_m): handle negative timeouts correctlynormal
Users may subtract and round into negative values when using Thread#join, so clamp the timeout to zero to avoid infinite/long timeouts. Note: other methods such as Kernel#sleep and IO.select will raise on negative values, but Thread#join is an outlier *shrug* This restores Ruby 2.5 (and earlier) behavior. Fixes: r62182 (commit c915390b9530c31b4665aacf27c1adfc114f768e) ("thread.c: avoid FP for Thread#join") git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-18thread.c (double2timespec): adjust to use NULL for infinitynormal
Using: strace ruby -e 'Thread.new { sleep }.join(Float::INFINITY)' Will show a difference in futex() syscall args (not that I'd ever advocate Float::INFINITY as a Thread#join arg :P) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-18thread.c: stop updating timespec when timeout is unspecifiednormal
No need to waste cycles updating timespecs if there's no expiry. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-18thread.c (update_timespec): use timespec_update_expirenormal
Rename "end" as a appropriate for readability. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-18thread.c: introduce timespec_cmp for timespec comparisonsnormal
This hopefully improves readability when comparing timespecs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62456 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-18thread.c (timespec_update_expire): improve namingnormal
Naming the constant timespec as "end" should make it more apparent is is an absolute time. Update callers, too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08thread.c: suppress a warningnobu
* thread.c (do_select): initialize timespec variable to suppress a false positive maybe-uninitialized warning by gcc 7 and 8. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-07thread.c: int32_t instead of suseconds_tnobu
* thread.c (timeval_for): cast to int32_t instead of suseconds_t, which is not defined non-POSIX platforms. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62276 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-07fix up r62272nobu
* thread.c (timeval_for): tv_usec is suseconds_t which may be smaller than long. * thread_pthread.c (native_cond_timeout): ret is now used in CLOCK_MONOTONIC case only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-07thread.c: favor timespec internallynormal
This results in fewer conversion on common modern systems with support for clock_gettime, pthread_cond_timedwait and ppoll. gettimeofday is declared obsolete by POSIX.1-2008, so it is yet another reason to move away from it. This also appears to result in the reduction of compatibility code required for dealing with inconsistent implementations of "struct timeval".tv_sec In the future, this will also result in fewer conversions for kqueue and pselect if we elect to use them. [ruby-core:85416] [Feature #14452] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62272 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04mjit_compile.c: merge initial JIT compilerk0kubun
which has been developed by Takashi Kokubun <takashikkbn@gmail> as YARV-MJIT. Many of its bugs are fixed by wanabe <s.wanabe@gmail.com>. This JIT compiler is designed to be a safe migration path to introduce JIT compiler to MRI. So this commit does not include any bytecode changes or dynamic instruction modifications, which are done in original MJIT. This commit even strips off some aggressive optimizations from YARV-MJIT, and thus it's slower than YARV-MJIT too. But it's still fairly faster than Ruby 2.5 in some benchmarks (attached below). Note that this JIT compiler passes `make test`, `make test-all`, `make test-spec` without JIT, and even with JIT. Not only it's perfectly safe with JIT disabled because it does not replace VM instructions unlike MJIT, but also with JIT enabled it stably runs Ruby applications including Rails applications. I'm expecting this version as just "initial" JIT compiler. I have many optimization ideas which are skipped for initial merging, and you may easily replace this JIT compiler with a faster one by just replacing mjit_compile.c. `mjit_compile` interface is designed for the purpose. common.mk: update dependencies for mjit_compile.c. internal.h: declare `rb_vm_insn_addr2insn` for MJIT. vm.c: exclude some definitions if `-DMJIT_HEADER` is provided to compiler. This avoids to include some functions which take a long time to compile, e.g. vm_exec_core. Some of the purpose is achieved in transform_mjit_header.rb (see `IGNORED_FUNCTIONS`) but others are manually resolved for now. Load mjit_helper.h for MJIT header. mjit_helper.h: New. This is a file used only by JIT-ed code. I'll refactor `mjit_call_cfunc` later. vm_eval.c: add some #ifdef switches to skip compiling some functions like Init_vm_eval. win32/mkexports.rb: export thread/ec functions, which are used by MJIT. include/ruby/defines.h: add MJIT_FUNC_EXPORTED macro alis to clarify that a function is exported only for MJIT. array.c: export a function used by MJIT. bignum.c: ditto. class.c: ditto. compile.c: ditto. error.c: ditto. gc.c: ditto. hash.c: ditto. iseq.c: ditto. numeric.c: ditto. object.c: ditto. proc.c: ditto. re.c: ditto. st.c: ditto. string.c: ditto. thread.c: ditto. variable.c: ditto. vm_backtrace.c: ditto. vm_insnhelper.c: ditto. vm_method.c: ditto. I would like to improve maintainability of function exports, but I believe this way is acceptable as initial merging if we clarify the new exports are for MJIT (so that we can use them as TODO list to fix) and add unit tests to detect unresolved symbols. I'll add unit tests of JIT compilations in succeeding commits. Author: Takashi Kokubun <takashikkbn@gmail.com> Contributor: wanabe <s.wanabe@gmail.com> Part of [Feature #14235] --- * Known issues * Code generated by gcc is faster than clang. The benchmark may be worse in macOS. Following benchmark result is provided by gcc w/ Linux. * Performance is decreased when Google Chrome is running * JIT can work on MinGW, but it doesn't improve performance at least in short running benchmark. * Currently it doesn't perform well with Rails. We'll try to fix this before release. --- * Benchmark reslts Benchmarked with: Intel 4.0GHz i7-4790K with 16GB memory under x86-64 Ubuntu 8 Cores - 2.0.0-p0: Ruby 2.0.0-p0 - r62186: Ruby trunk (early 2.6.0), before MJIT changes - JIT off: On this commit, but without `--jit` option - JIT on: On this commit, and with `--jit` option ** Optcarrot fps Benchmark: https://github.com/mame/optcarrot | |2.0.0-p0 |r62186 |JIT off |JIT on | |:--------|:--------|:--------|:--------|:--------| |fps |37.32 |51.46 |51.31 |58.88 | |vs 2.0.0 |1.00x |1.38x |1.37x |1.58x | ** MJIT benchmarks Benchmark: https://github.com/benchmark-driver/mjit-benchmarks (Original: https://github.com/vnmakarov/ruby/tree/rtl_mjit_branch/MJIT-benchmarks) | |2.0.0-p0 |r62186 |JIT off |JIT on | |:----------|:--------|:--------|:--------|:--------| |aread |1.00 |1.09 |1.07 |2.19 | |aref |1.00 |1.13 |1.11 |2.22 | |aset |1.00 |1.50 |1.45 |2.64 | |awrite |1.00 |1.17 |1.13 |2.20 | |call |1.00 |1.29 |1.26 |2.02 | |const2 |1.00 |1.10 |1.10 |2.19 | |const |1.00 |1.11 |1.10 |2.19 | |fannk |1.00 |1.04 |1.02 |1.00 | |fib |1.00 |1.32 |1.31 |1.84 | |ivread |1.00 |1.13 |1.12 |2.43 | |ivwrite |1.00 |1.23 |1.21 |2.40 | |mandelbrot |1.00 |1.13 |1.16 |1.28 | |meteor |1.00 |2.97 |2.92 |3.17 | |nbody |1.00 |1.17 |1.15 |1.49 | |nest-ntimes|1.00 |1.22 |1.20 |1.39 | |nest-while |1.00 |1.10 |1.10 |1.37 | |norm |1.00 |1.18 |1.16 |1.24 | |nsvb |1.00 |1.16 |1.16 |1.17 | |red-black |1.00 |1.02 |0.99 |1.12 | |sieve |1.00 |1.30 |1.28 |1.62 | |trees |1.00 |1.14 |1.13 |1.19 | |while |1.00 |1.12 |1.11 |2.41 | ** Discourse's script/bench.rb Benchmark: https://github.com/discourse/discourse/blob/v1.8.7/script/bench.rb NOTE: Rails performance was somehow a little degraded with JIT for now. We should fix this. (At least I know opt_aref is performing badly in JIT and I have an idea to fix it. Please wait for the fix.) *** JIT off Your Results: (note for timings- percentile is first, duration is second in millisecs) categories_admin: 50: 17 75: 18 90: 22 99: 29 home_admin: 50: 21 75: 21 90: 27 99: 40 topic_admin: 50: 17 75: 18 90: 22 99: 32 categories: 50: 35 75: 41 90: 43 99: 77 home: 50: 39 75: 46 90: 49 99: 95 topic: 50: 46 75: 52 90: 56 99: 101 *** JIT on Your Results: (note for timings- percentile is first, duration is second in millisecs) categories_admin: 50: 19 75: 21 90: 25 99: 33 home_admin: 50: 24 75: 26 90: 30 99: 35 topic_admin: 50: 19 75: 20 90: 25 99: 30 categories: 50: 40 75: 44 90: 48 99: 76 home: 50: 42 75: 48 90: 51 99: 89 topic: 50: 49 75: 55 90: 58 99: 99 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04mjit.c: merge MJIT infrastructurek0kubun
that allows to JIT-compile Ruby methods by generating C code and using C compiler. See the first comment of mjit.c to know what this file does. mjit.c is authored by Vladimir Makarov <vmakarov@redhat.com>. After he invented great method JIT infrastructure for MRI as MJIT, Lars Kanis <lars@greiz-reinsdorf.de> sent the patch to support MinGW in MJIT. In addition to merging it, I ported pthread to Windows native threads. Now this MJIT infrastructure can be compiled on Visual Studio. This commit simplifies mjit.c to decrease code at initial merge. For example, this commit does not provide multiple JIT threads support. We can resurrect them later if we really want them, but I wanted to minimize diff to make it easier to review this patch. `/tmp/_mjitXXX` file is renamed to `/tmp/_ruby_mjitXXX` because non-Ruby developers may not know the name "mjit" and the file name should make sure it's from Ruby and not from some harmful programs. TODO: it may be better to store this to some temporary directory which Ruby is already using by Tempfile, if it's not bad for performance. mjit.h: New. It has `mjit_exec` interface similar to `vm_exec`, which is for triggering MJIT. This drops interface for AOT compared to the original MJIT. Makefile.in: define macros to let MJIT know the path of MJIT header. Probably we can refactor this to reduce the number of macros (TODO). win32/Makefile.sub: ditto. common.mk: compile mjit.o and mjit_compile.o. Unlike original MJIT, this commit separates MJIT infrastructure and JIT compiler code as independent object files. As initial patch is NOT going to have ultra-fast JIT compiler, it's likely to replace JIT compiler, e.g. original MJIT's compiler or some future JIT impelementations which are not public now. inits.c: define MJIT module. This is added because `MJIT.enabled?` was necessary for testing. test/lib/zombie_hunter.rb: skip if `MJIT.enabled?`. Obviously this wouldn't work with current code when JIT is enabled. test/ruby/test_io.rb: skip this too. This would make no sense with MJIT. ruby.c: define MJIT CLI options. As major difference from original MJIT, "-j:l"/"--jit:llvm" are renamed to "--jit-cc" because I want to support not only gcc/clang but also cl.exe (Visual Studio) in the future. But it takes only "--jit-cc=gcc", "--jit-cc=clang" for now. And only long "--jit" options are allowed since some Ruby committers preferred it at Ruby developers Meeting on January, and some of options are renamed. This file also triggers to initialize MJIT thread and variables. eval.c: finalize MJIT worker thread and variables. test/ruby/test_rubyoptions.rb: fix number of CLI options for --jit. thread_pthread.c: change for pthread abstraction in MJIT. Prefix rb_ for functions which are used by other files. thread_win32.c: ditto, for Windows. Those pthread porting is one of major works that YARV-MJIT created, which is my fork of MJIT, in Feature 14235. thread.c: follow rb_ prefix changes vm.c: trigger MJIT call on VM invocation. Also trigger `mjit_mark` to avoid SEGV by race between JIT and GC of ISeq. The improvement was provided by wanabe <s.wanabe@gmail.com>. In JIT compiler I created and am going to add in my next commit, I found that having `mjit_exec` after `vm_loop_start:` is harmful because the JIT-ed function doesn't proceed other ISeqs on RESTORE_REGS of leave insn. Executing non-FINISH frame is unexpected for my JIT compiler and `exception_handler` triggers executions of such ISeqs. So `mjit_exec` here should be executed only when it directly comes from `vm_exec` call. `RubyVM::MJIT` module and `.enabled?` method is added so that we can skip some tests which don't expect JIT threads or compiler file descriptors. vm_insnhelper.h: trigger MJIT on method calls during VM execution. vm_core.h: add fields required for mjit.c. `bp` must be `cfp[6]` because rb_control_frame_struct is likely to be casted to another struct. The last position is the safest place to add the new field. vm_insnhelper.c: save initial value of cfp->ep as cfp->bp. This is an optimization which are done in both MJIT and YARV-MJIT. So this change is added in this commit. Calculating bp from ep is a little heavy work, so bp is kind of cache for it. iseq.c: notify ISeq GC to MJIT. We should know which iseq in MJIT queue is GCed to avoid SEGV. TODO: unload some GCed units in some safe way. gc.c: add hooks so that MJIT can wait GC, and vice versa. Simultaneous JIT and GC executions may cause SEGV and so we should synchronize them. cont.c: save continuation information in MJIT worker. As MJIT shouldn't unload JIT-ed code which is being used, MJIT wants to know full list of saved execution contexts for continuation and detect ISeqs in use. mjit_compile.c: added empty JIT compiler so that you can reuse this commit to build your own JIT compiler. This commit tries to compile ISeqs but all of them are considered as not supported in this commit. So you can't use JIT compiler in this commit yet while we added --jit option now. Patch author: Vladimir Makarov <vmakarov@redhat.com>. Contributors: Takashi Kokubun <takashikkbn@gmail.com>. wanabe <s.wanabe@gmail.com>. Lars Kanis <lars@greiz-reinsdorf.de>. Part of Feature 12589 and 14235. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04thread.c: timespec_for is used only if poll() is usednobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-03thread.c (thread_join_m): avoid NUM2TIMET for Bignumnormal
Bignums exceed the range of time_t (or long). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-03thread.c: avoid FP in C-API time calculationsnormal
FP arithmetic can lose precision in some cases leading to premature wakeup and wasting CPU cycles. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-03thread.c: avoid FP for Thread#joinnormal
FP arithmetic can lose precision in some cases leading to premature wakeup and wasting CPU cycles. Convert to use timeval_* functions for now. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-03thread.c: extract timeval_sub from timeval_update_expirenormal
It can be useful on its own. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-03thread.c (rb_thread_terminate_all): eliminate double2timeval callnormal
No point for a fixed 1s value, and I plan on eliminating double timeouts from internal API. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-30ia64: update ia64-specific code to use execution contexthsbt
This change follows commit 837fd5e494731d7d44786f29e7d6e8c27029806f in '#ifdef __ia64' branches. Noticed as a build failure by John Paul Adrian Glaubitz: ``` cont.c:502:50: error: 'rb_thread_t {aka struct rb_thread_struct}' has no member named 'machine' size = cont->machine.register_stack_size = th->machine.register_stack_end - th->machine.register_stack_start; ^~ ``` The change is trivial: update 'th->machine' usage to 'th->ec->machine'. Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62106 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-27vm_core: use "int" for living_thread_numnormal
We treat this as "int" through the vm_living_thread_num API anyways, and "pid_t" is still 32-bits with glibc on 64-bit platforms. I expect it'll be a long time before anybody needs more than 2 billion native threads. For now, let's save one cacheline on x86-64 (as reported by pahole(1)): before: size: 1288, cachelines: 21, members: 45 after: size: 1280, cachelines: 20, members: 45 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62075 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-18rb_threadptr_to_kill marked as NORETURNshyouhei
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-17Fix typos.hsbt
* node.c: strucutre -> structure * random.c: acquried -> acquired * thread.c: accross -> across git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-12thread.c (thread_cleanup_func): document small leaknormal
It's minor, I haven't analyzed how fixable it is, but we should at least note it, here. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61779 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09thread.c: threadptr_pending_interrupt_active_p is staticnormal
It's not used elsewhere. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61749 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09Include ruby/{io,encoding}.h before internal.hkazu
because of r61712 and r61713 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09Rename code_range to code_locationmame
Because the name "code_range" is ambiguous with encoding's. Abbreviations ("crange", and "cr") are also renamed to "loc". The traditional "code_location" (a pair of lineno and column) is renamed to "code_position". Abbreviations are also renamed (first_loc to beg_pos, and last_loc to end_pos). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02explicit cast to void* required for %pshyouhei
These functions take variadic arguments so no automatic type promotion is expected. You have to do it by hand. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-28`$SAFE` as a process global state. [Feature #14250]ko1
* vm_core.h (rb_vm_t): move `rb_execution_context_t::safe_level` to `rb_vm_t::safe_level_` because `$SAFE` is a process (VM) global state. * vm_core.h (rb_proc_t): remove `rb_proc_t::safe_level` because `Proc` objects don't need to keep `$SAFE` at the creation. Also make `is_from_method` and `is_lambda` as 1 bit fields. * cont.c (cont_restore_thread): no need to keep `$SAFE` for Continuation. * eval.c (ruby_cleanup): use `rb_set_safe_level_force()` instead of access `vm->safe_level_` directly. * eval_jump.c: End procs `END{}` doesn't keep `$SAFE`. * proc.c (proc_dup): removed and introduce `rb_proc_dup` in vm.c. * safe.c (rb_set_safe_level): don't check `$SAFE` 1 -> 0 changes. * safe.c (safe_setter): use `rb_set_safe_level()`. * thread.c (rb_thread_safe_level): `Thread#safe_level` returns `$SAFE`. It should be obsolete. * transcode.c (load_transcoder_entry): `rb_safe_level()` only returns 0 or 1 so that this check is not needed. * vm.c (vm_proc_create_from_captured): don't need to keep `$SAFE` for Proc. * vm.c (rb_proc_create): renamed to `proc_create`. * vm.c (rb_proc_dup): moved from proc.c. * vm.c (vm_invoke_proc): do not need to set and restore `$SAFE` for `Proc#call`. * vm_eval.c (rb_eval_cmd): rename a local variable to represent clearer meaning. * lib/drb/drb.rb: restore `$SAFE`. * lib/erb.rb: restore `$SAFE`, too. * test/lib/leakchecker.rb: check `$SAFE == 0` at the end of tests. * test/rubygems/test_gem.rb: do not set `$SAFE = 1`. * bootstraptest/test_proc.rb: catch up this change. * spec/ruby/optional/capi/string_spec.rb: ditto. * test/bigdecimal/test_bigdecimal.rb: ditto. * test/fiddle/test_func.rb: ditto. * test/fiddle/test_handle.rb: ditto. * test/net/imap/test_imap_response_parser.rb: ditto. * test/pathname/test_pathname.rb: ditto. * test/readline/test_readline.rb: ditto. * test/ruby/test_file.rb: ditto. * test/ruby/test_optimization.rb: ditto. * test/ruby/test_proc.rb: ditto. * test/ruby/test_require.rb: ditto. * test/ruby/test_thread.rb: ditto. * test/rubygems/test_gem_specification.rb: ditto. * test/test_tempfile.rb: ditto. * test/test_tmpdir.rb: ditto. * test/win32ole/test_win32ole.rb: ditto. * test/win32ole/test_win32ole_event.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-28Fix KeyError#{key,receiver} of Thread#fetchkazu
[ruby-core:84508] [Bug #14247] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-20compile.c: add a RUBY_EVENT_COVERAGE_LINE event for line coveragemame
2.5's line coverage measurement was about two times slower than 2.4 because of two reasons; (1) vm_trace uses rb_iseq_event_flags (which takes O(n) currently where n is the length of iseq) to get an event type, and (2) RUBY_EVENT_LINE uses setjmp to call an event hook. This change adds a special event for line coverage, RUBY_EVENT_COVERAGE_LINE, and adds `tracecoverage` instructions where the event occurs in iseq. `tracecoverage` instruction calls an event hook without vm_trace. And, RUBY_EVENT_COVERAGE_LINE is an internal event which does not use setjmp. This change also cancells lineno change due to the deletion of trace instructions [Feature #14104]. So fixes [Bug #14191]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-17thread.c: adjusted [ci skip]nobu
* thread.c (timeval_add): adjusted indent and parenthesized in braces. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-17thread.c: fix overly long Thread#join w/ timeoutnormal
* test/ruby/test_thread.rb (test_signal_at_join): test with timeout * thread.c (sleep_wait_for_interrupt): remove (thread_join_sleep): use native_sleep directly to avoid extra missing thread status change [Bug #14181] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-17thread.c: hoist out timeval arithmetic functionsnormal
timeval arithmetic may be reused in other places and this makes sleep_timeval easier-to-read. * thread.c (timeval_add): hoist out of sleep_timeval (timeval_update_expire): ditto (sleep_timeval): use new functions git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-15thread.c: fix deadlocknobu
* thread.c (thread_join_sleep): the target thread may exit during `RUBY_VM_CHECK_INTS_BLOCKING`, but `sleep_forever` does not consider the condition change to wait. [ruby-core:84248] [Bug #14181] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-15thread.c: debug messagesnobu
* thread.c (terminate_all): fix funtion name in debug messages. * thread.c (terminate_all, thread_join_sleep, thread_join): show the status of the target thread in debug messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-14The main Thread should have report_on_exception=true for consistencyeregon
* Adapt test and add specs. * See [Feature #14143] [ruby-core:84227] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-13Document how to deal with output created by Thread.report_on_exception.eregon
* Improve and clarify the documentation of Thread.report_on_exception and related methods. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12Set Thread.report_on_exception=true by default to report exceptions in Threadseregon
* [Feature #14143] [ruby-core:83979] * vm.c (vm_init2): Set Thread.report_on_exception to true. * thread.c (thread_start_func_2): Add indication the message is caused by report_on_exception = true. * spec/ruby: Specify the new behavior. * test/ruby/test_thread.rb: Adapt and improve tests for Thread.report_on_exception and Thread#report_on_exception. * test/ruby/test_thread.rb, test/ruby/test_exception.rb: Unset report_on_exception for tests expecting no extra output. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-06vm_core.h (RUBY_EVENT_COVERAGE_BRANCH): renamedmame
This change moves RUBY_EVENT_COVERAGE from include/ruby/ruby.h to vm_core.h and renames it to RUBY_EVENT_COVERAGE_BRANCH. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61049 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-06thread.c (update_branch_coverage): renamed from `update_coverage`mame
Now this function only deals with branch events, so this change renames it and remove complexity that is no longer needed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-06thread.c (update_line_coverage): Use RUBY_EVENT_LINEmame
This change makes coverage use the general event type RUBY_EVENT_LINE instead of a special event type RUBY_EVENT_COVERAGE. Just a refactoring. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-06remove `PUSH_TAG`/`EXEC_AG`/`POP_TAG`/`JUMO_TAG`.ko1
* eval_intern.h: remove non-`EC_` prefix *_TAG() macros. Use `EC_` prefix macros explicitly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-05vm_core.h (rb_iseq_locatoin_t): add a field `code_range`mame
This change makes each ISeq keep NODE's code range. This information is needed for method coverage. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-05Revamp method coverage to support define_methodmame
Traditionally, method coverage measurement was implemented by inserting `trace2` instruction to the head of method iseq. So, it just measured methods defined by `def` keyword. This commit drastically changes the measuring mechanism of method coverage; at `RUBY_EVENT_CALL`, it keeps a hash from rb_method_entry_t* to runs (i.e., it counts the runs per method entry), and at `Coverage.result`, it creates the result hash by enumerating all `rb_method_entry_t*` objects (by `ObjectSpace.each_object`). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-23thread.c: Update documentsyui-knk
* thread.c (rb_default_coverage): Update documents of internal data structures for branch coverage. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16make funcs static.ko1
* thread.c (rb_threadptr_trap_interrupt): make it static and remove `rb_` prefix. * thread.c (rb_threadptr_pending_interrupt_active_p): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-15remove rb_thread_t::event_hooks.ko1
* vm_core.h (rb_thread_t): remove rb_thread_t::event_hooks. * vm_trace.c: all hooks are connected to vm->event_hooks and add rb_event_hook_t::filter::th to filter invoke thread. It will simplify invoking hooks code. * thread.c (thread_start_func_2): clear thread specific trace_func. * test/ruby/test_settracefunc.rb: add a test for Thread#add_trace_func. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-15thread.c: use ecnobu
* thread.c (call_without_gvl): use execution context for RUBY_VM_CHECK_INTS_BLOCKING. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e