Граф коммитов

786 Коммитов

Автор SHA1 Сообщение Дата
nobu c4d09fb299 thread.c: suppress a warning
* 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-08 07:49:42 +00:00
nobu 76c5787c38 thread.c: int32_t instead of suseconds_t
* 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-07 06:49:32 +00:00
nobu b0cf1c234c fix up r62272
* 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-07 06:14:56 +00:00
normal 0abd9b7f25 thread.c: favor timespec internally
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-07 01:57:14 +00:00
k0kubun ed935aa5be mjit_compile.c: merge initial JIT compiler
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-04 11:22:28 +00:00
k0kubun fd44a5777f mjit.c: merge MJIT infrastructure
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-04 06:58:09 +00:00
nobu 0718f53bca thread.c: timespec_for is used only if poll() is used
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04 01:31:48 +00:00
normal 05c18139a1 thread.c (thread_join_m): avoid NUM2TIMET for Bignum
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-03 22:24:17 +00:00
normal c0e2f98f9b thread.c: avoid FP in C-API time calculations
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-03 19:59:21 +00:00
normal c915390b95 thread.c: avoid FP for Thread#join
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-03 19:59:16 +00:00
normal 712439b530 thread.c: extract timeval_sub from timeval_update_expire
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-03 19:59:11 +00:00
normal 076d886398 thread.c (rb_thread_terminate_all): eliminate double2timeval call
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-02-03 19:59:05 +00:00
hsbt 5af43b1ec2 ia64: update ia64-specific code to use execution context
This change follows commit 837fd5e494
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-30 05:43:42 +00:00
normal 72b7bd0af5 vm_core: use "int" for living_thread_num
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-27 21:04:36 +00:00
shyouhei 3b787be52f rb_threadptr_to_kill marked as NORETURN
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-18 09:44:46 +00:00
hsbt 9869ec7a7d Fix typos.
* 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-17 13:15:13 +00:00
normal 99886a9121 thread.c (thread_cleanup_func): document small leak
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-12 00:15:28 +00:00
normal 3e8b9f85ff thread.c: threadptr_pending_interrupt_active_p is static
It's not used elsewhere.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61749 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 22:59:58 +00:00
kazu 51edb30042 Include ruby/{io,encoding}.h before internal.h
because of r61712 and r61713

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 12:35:12 +00:00
mame 4928900814 Rename code_range to code_location
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-09 08:45:35 +00:00
shyouhei b6a2d63eb3 explicit cast to void* required for %p
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
2018-01-02 06:41:40 +00:00
ko1 c39bdb798d `$SAFE` as a process global state. [Feature #14250]
* 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-28 20:09:24 +00:00
kazu 220d2a7182 Fix KeyError#{key,receiver} of Thread#fetch
[ruby-core:84508] [Bug #14247]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-28 00:00:05 +00:00
mame c08e8886ba compile.c: add a RUBY_EVENT_COVERAGE_LINE event for line coverage
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-20 04:24:14 +00:00
nobu cb26d0d9bb thread.c: adjusted [ci skip]
* 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-17 09:40:19 +00:00
normal db9523ef47 thread.c: fix overly long Thread#join w/ timeout
* 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-17 08:26:17 +00:00
normal 78cc1491d5 thread.c: hoist out timeval arithmetic functions
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-17 08:26:12 +00:00
nobu f5183827dc thread.c: fix deadlock
* 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-15 07:27:04 +00:00
nobu 20c3237d14 thread.c: debug messages
* 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-15 03:07:10 +00:00
eregon 2e315baf48 The main Thread should have report_on_exception=true for consistency
* 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-14 13:08:02 +00:00
eregon 186732f46f Document how to deal with output created by Thread.report_on_exception.
* 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-13 15:59:26 +00:00
eregon 5a3c024df0 Set Thread.report_on_exception=true by default to report exceptions in Threads
* [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-12 18:43:42 +00:00
mame 55f93cb63f vm_core.h (RUBY_EVENT_COVERAGE_BRANCH): renamed
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-06 07:19:17 +00:00
mame c3c0c0745f thread.c (update_branch_coverage): renamed from `update_coverage`
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-06 07:04:48 +00:00
mame ec02c4861b thread.c (update_line_coverage): Use RUBY_EVENT_LINE
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-06 06:39:05 +00:00
ko1 0e34638f79 remove `PUSH_TAG`/`EXEC_AG`/`POP_TAG`/`JUMO_TAG`.
* 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-06 03:16:08 +00:00
mame a5e02f249d vm_core.h (rb_iseq_locatoin_t): add a field `code_range`
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-05 08:56:50 +00:00
mame 0a6816ecd7 Revamp method coverage to support define_method
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-12-05 07:16:42 +00:00
yui-knk 4a73890189 thread.c: Update documents
* 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-23 11:52:36 +00:00
ko1 f4cb93adca make funcs static.
* 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-16 08:48:59 +00:00
ko1 a3071ea4e3 remove rb_thread_t::event_hooks.
* 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-15 13:21:24 +00:00
nobu e5b968f571 thread.c: use ec
* 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
2017-11-15 05:50:10 +00:00
mame a798e49f57 Symptomatic treatment for `rb_thread_terminate_all` freeze
Under uncertain condition, `rb_thread_terminate_all` gets stuck.  `make
test-all TESTOPTS="test/ruby/test_gc.rb -n test_interrupt_in_finalizer`
fails very rarely (only once every thousand runs).  This IS a bug, but
seems difficult to fix it soon.

This commit makes `rb_thread_terminate_all` wake up every one second,
instead of waiting forever, which mitigates the unuseful freeze.
This is not an essential solution for the bug, though.  I'll create a
ticket with how to reproduce the original issue.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60694 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-07 06:36:07 +00:00
ko1 f6c102e6a5 th->ec: rb_threadptr_setup_exception
* eval.c (rb_threadptr_setup_exception): renamed to rb_ec_setup_exception().


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60692 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-07 06:09:47 +00:00
ko1 ee189904f0 rename to rb_ec_set_raised().
* thread.c (rb_threadptr_set_raised): rename to rb_ec_set_raised
  and accepts `ec`


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-07 05:12:39 +00:00
ko1 b6ecdf5fc8 th->ec: rb_threadptr_reset_raised()
* thread.c (rb_threadptr_reset_raised): rename to `rb_ec_reset_raised`
  and accepts `ec`.

* vm_trace.c: the following functions accept `ec` instead of `th`
  * exec_hooks_body
  * exec_hooks_precheck
  * exec_hooks_unprotected
  * exec_hooks_protected


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-07 04:01:13 +00:00
ko1 5dfdaa9299 move rb_thread_t::interrupt_flag and mask
to rb_execution_context_t.

* vm_core.h (rb_thread_t): move
  `rb_thread_t::interrupt_flag` and
  `rb_thread_t::interrupt_mask` to rb_execution_context_t.

  RUBY_VM_CHECK_INTS() accepts `ec` instead of `th`.

* cont.c (rb_fiber_terminate): to propagate interrupt information,
  add new parameter `need_interrupt`.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-06 07:44:28 +00:00
ko1 e5e735549d renmae ec::fiber to ec::fiber_ptr.
* vm_core.h (rb_execution_context_t): renmae ec::fiber to
  ec::fiber_ptr make consistent with ec::thread_ptr.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-06 05:41:48 +00:00
ko1 a93c650312 `rb_ec_error_print()`.
* eval_error.c (rb_threadptr_error_print): renamed to
  rb_ec_error_print() and it accepts `ec`.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-29 14:06:58 +00:00
ko1 a288b87c4c EXEC_EVENT_HOOK(ec, ...)
* vm_core.h (EXEC_EVENT_HOOK): accepts `ec` instead of `th`.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-29 13:19:14 +00:00