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

10604 Коммитов

Автор SHA1 Сообщение Дата
mame 0efd8bbd34 test/io/console/test_io_console.rb (test_oflush): Avoid race condition
Add a ad-hoc wait.  Follows test_ioflush2.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62411 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-15 05:34:20 +00:00
normal 7606806cd9 compile.c: drop freezestring insn on String#-@
Followup to r62039 and remove the redundant freezestring
insn which was preventing deduplication from String#-@

* compile.c (iseq_peephole_optimize): drop freezestring insn on String#-@
  [ruby-core:85542] [Bug #14475]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-14 22:35:13 +00:00
normal dc9ce32864 test/ruby/test_optimization.rb: fix compile kwarg
Fixes: r62177 ("compile.c: fix string Range optimization with FSL")

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-14 22:35:08 +00:00
ko1 381650ea58 skip "TestException#test_thread_signal_location" as a known bug [Bug #14474]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-14 01:50:59 +00:00
k0kubun ddb65f0b03 mjit_compile.inc.erb: replace opt_key insn
with opt_send_without_block insn if call cache has valid ISeq.
If the receiver is not optimized target of opt_key (i.e. Hash or Array),
it triggers JIT cancel and it would be slow.

This change allows JIT to drop the check for Hash/Array and continue to
execute JIT even if the receiver is not Hash or Array.

See the following benchmark results. It's not improved so much, but it
would be effective when we achieve Ruby method inlining in
_mjit_compile_send.erb.

* Micro benchmark

Given the following bench.rb,

```
class HashWithIndifferentAccess < Hash
  def []=(key, value)
    super(key.to_s, value)
  end

  def [](key)
    super(key.to_s)
  end
end

indhash = HashWithIndifferentAccess.new
indhash[:foo] = 'bar'
key = 'foo'

100000000.times do
  indhash[key]
end
```

** before

```
$ time ./ruby --disable-gems --jit-verbose=1 /tmp/bench.rb
JIT success (31.4ms): block in <main>@/tmp/bench.rb:15 -> /tmp/_ruby_mjit_p18206u0.c
JIT success (669.3ms): []@/tmp/bench.rb:6 -> /tmp/_ruby_mjit_p18206u1.c
Successful MJIT finish
./ruby --disable-gems --jit-verbose=1 /tmp/bench.rb  12.21s user 0.04s system 107% cpu 11.394 total
```

** after

```
$ time ./ruby --disable-gems --jit-verbose=1 /tmp/bench.rb
JIT success (41.0ms): block in <main>@/tmp/bench.rb:15 -> /tmp/_ruby_mjit_p17293u0.c
JIT success (679.0ms): []@/tmp/bench.rb:6 -> /tmp/_ruby_mjit_p17293u1.c
Successful MJIT finish
./ruby --disable-gems --jit-verbose=1 /tmp/bench.rb  11.54s user 0.06s system 108% cpu 10.726 total
```

The execution time is shortened.

* optcarrot benchmark

Optcarrot has no room to be improved by this change. Almost nothing is changed.

fps: 59.54 (before) -> 59.51 (after)

* discourse benchmark

I expected this to be improved a little, but it isn't too.

** before (JIT)

```
categories_admin:
  50: 12
  75: 13
  90: 14
  99: 22
home_admin:
  50: 12
  75: 13
  90: 16
  99: 22
topic_admin:
  50: 12
  75: 13
  90: 15
  99: 21
categories:
  50: 18
  75: 19
  90: 23
  99: 27
home:
  50: 3
  75: 4
  90: 4
  99: 12
topic:
  50: 11
  75: 11
  90: 14
  99: 20
```

** after (JIT)

```
categories_admin:
  50: 12
  75: 12
  90: 16
  99: 24
home_admin:
  50: 12
  75: 12
  90: 14
  99: 21
topic_admin:
  50: 12
  75: 13
  90: 16
  99: 21
categories:
  50: 17
  75: 18
  90: 23
  99: 32
home:
  50: 3
  75: 4
  90: 4
  99: 10
topic:
  50: 11
  75: 12
  90: 13
  99: 20
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-13 15:58:38 +00:00
nobu 248ff4f1b1 variable.c: flags at autoloading
* variable.c (const_tbl_update): flags by deprecate_constant /
  private_constant set during autoloading should be preserved
  after required.  [ruby-core:85516] [Bug #14469]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-13 09:36:35 +00:00
usa 66652bb632 revert r62392
check the declaration of `rb_autoloading_value()` in vm_core.h and the call in
vm_insnhelper.c, and retry it.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-13 09:34:37 +00:00
nobu a6a596a5bd variable.c: flags at autoloading
* variable.c (const_tbl_update): flags by deprecate_constant /
  private_constant set during autoloading should be preserved
  after required.  [ruby-core:85516] [Bug #14469]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-13 09:11:02 +00:00
k0kubun 7a0bc1f350 test_jit.rb: prettify script in message
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62381 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-12 04:35:16 +00:00
k0kubun 48e4f02fcb test_jit.rb: explicitly skip for unsupported ones
MSP-Greg watches this metrics and this would be helpful for him.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-12 04:00:45 +00:00
nobu 30bcbfd339 test_jit.rb: split test_compile_insns
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62378 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-12 03:33:00 +00:00
nobu aea14e68fb insns.def: cache nil const
* insns.def (getinlinecache): Qnil is a valid value as a constant.
  this can be observable when accessing a deprecated constant
  which is nil.  non-nil constant is warned just once for each
  location, but every time if it is nil.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-10 16:54:47 +00:00
k0kubun 92413440bd test_jit.rb: cover most insn compilations
test_compile_insns has only basic tests to improve coverage.

Other severer tests should be added with different names.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-10 16:09:55 +00:00
nobu 63abedabf8 compile.c: popped hash
* compile.c (compile_array): skip creating new hash if preceeding
  elements are popped all.  [ruby-core:85486] [Bug #14459]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-09 14:09:58 +00:00
k0kubun bf618557b1 .travis.yml: force to execute JIT test on Travis
test_jit.rb: with environment variable RUBY_FORCE_TEST_JIT, we can force
to test JIT availability.

I wanted to have such CI, but Travis was the only option which I can
modify easily.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-09 00:32:55 +00:00
k0kubun 5e09125581 test_jit.rb: don't force to test --jit-wait
for platforms which can't use JIT. Such platforms can time out with
eval_with_jit.

http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/509911
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/509904

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08 13:56:32 +00:00
k0kubun 7c3887408a test_jit.rb: fix typo
This is notified by zns-san.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08 13:40:47 +00:00
k0kubun 1491ef544d test_jit.rb: add forgotten check
I was going to check this in r62310...

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62311 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08 13:01:43 +00:00
k0kubun 7e57ff99e5 test_jit.rb: check JIT support more conservatively
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62310 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08 12:58:27 +00:00
k0kubun 0468f13606 test_jit.rb: remove unnecessary require
At first I was going to check the name of `RbConfig::CONFIG['CC']` and
use shellwords for it, but I decided not to do so.

Thus removing obsoleted require in r62307.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08 12:43:09 +00:00
k0kubun 1b83975a8a test_jit.rb: try to test JIT again
This commit reverts r62297, revising the check if JIT is supported or
not.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08 12:40:33 +00:00
usa db0a4df62c revert r62302 and force to define the version constant
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08 07:34:41 +00:00
usa db52886028 no need to set bundled bundler unless Gem::USE_BUNDLER_FOR_GEMDEPS
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08 07:23:21 +00:00
nobu 7410e17f07 test_gem_commands_setup_command.rb: BUNDLER_VERS
* test/rubygems/test_gem_commands_setup_command.rb: run bundled
  gem command, instead of installed one.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08 07:14:52 +00:00
k0kubun 571bb73410 revert r62291 for now
While some of CIs are succeeding and the test succeeds on my laptop,
some other CIs are failing. As I don't have time to fix it until I come
back to home, reverting this for now.

Failures:
https://rubyci.org/logs/www.rubyist.net/~akr/chkbuild/debian/ruby-trunk/log/20180208T000401Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/scw-9d6766/ruby-trunk/log/20180207T201706Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/ubuntu1604/ruby-trunk/log/20180207T183004Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/gentoo/ruby-trunk/log/20180207T213004Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/centos6/ruby-trunk/log/20180207T213003Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/fedora25/ruby-trunk/log/20180207T213003Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/fedora26/ruby-trunk/log/20180207T213003Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/opensuseleap/ruby-trunk/log/20180207T213001Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/rhel_zlinux/ruby-trunk/log/20180207T223303Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/osx1011/ruby-trunk/log/20180207T234501Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/osx1012/ruby-trunk/log/20180207T234501Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/icc-x64/ruby-trunk/log/20180207T210002Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/unstable10x/ruby-trunk/log/20180207T231805Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/unstable11x/ruby-trunk/log/20180207T232403Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/unstable10s/ruby-trunk/log/20180207T171914Z.fail.html.gz
https://rubyci.org/logs/rubyci.s3.amazonaws.com/unstable11s/ruby-trunk/log/20180207T232503Z.fail.html.gz
https://rubyci.org/logs/mswinci.japaneast.cloudapp.azure.com/vc12-x64/ruby-trunk/log/20180207T172813Z.fail.html.gz

http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/506100
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/506114
http://ci.rvm.jp/results/trunk_clang_40@silicon-docker/506119
http://ci.rvm.jp/results/trunk_clang_39@silicon-docker/506170
http://ci.rvm.jp/results/trunk-nopara@silicon-docker/506176
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/506192
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/506202
http://ci.rvm.jp/results/trunk_clang_39@silicon-docker/506244
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/506271
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/506280
http://ci.rvm.jp/results/trunk-nopara@silicon-docker/506323
http://ci.rvm.jp/results/trunk_clang_50@silicon-docker/506325
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/506342
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/506354
http://ci.rvm.jp/results/trunk_clang_39@silicon-docker/506385
http://ci.rvm.jp/results/trunk_clang_40@silicon-docker/506389
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/506409
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/506425
http://ci.rvm.jp/results/trunk_clang_40@silicon-docker/506471
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/506484
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/506495
http://ci.rvm.jp/results/trunk-test@x2/506524
http://ci.rvm.jp/results/trunk-vm-asserts@silicon-docker/506547
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/506556
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/506579
http://ci.rvm.jp/results/trunk-nopara@silicon-docker/506582
http://ci.rvm.jp/results/trunk_clang_50@silicon-docker/506634
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/506638
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/506663
http://ci.rvm.jp/results/trunk-test@frontier/506690
http://ci.rvm.jp/results/trunk_clang_40@silicon-docker/506718
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/506728
http://ci.rvm.jp/results/trunk-nopara@silicon-docker/506752
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/506754
http://ci.rvm.jp/results/trunk-gc-asserts@silicon-docker/506782
http://ci.rvm.jp/results/trunk_clang_38@silicon-docker/506799
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/506816
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/506835
http://ci.rvm.jp/results/trunk-nopara@silicon-docker/506879
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/506903
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/506920
http://ci.rvm.jp/results/trunk-test@frontier/506955
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/506994
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/507012
http://ci.rvm.jp/results/trunk-vm-asserts@silicon-docker/507036
http://ci.rvm.jp/results/trunk_clang_40@silicon-docker/507037
http://ci.rvm.jp/results/trunk-nopara@silicon-docker/507053
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/507081
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/507097
http://ci.rvm.jp/results/trunk_clang_40@silicon-docker/507136
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/507165
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/507178
http://ci.rvm.jp/results/trunk-nopara@silicon-docker/507180
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/507257
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/507268
http://ci.rvm.jp/results/trunk-gc-asserts@silicon-docker/507303
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/507342
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/507355
http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/507434
http://ci.rvm.jp/results/trunk_gcc4@silicon-docker/507448

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08 00:55:33 +00:00
k0kubun 686424ea3e test_jit.rb: make JIT count test optional
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-07 16:28:17 +00:00
k0kubun af278e8aa8 test_jit.rb: add initial test for JIT
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62291 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-07 16:15:21 +00:00
marcandre b16eaf8632 lib/ostruct.rb: Use `FrozenError` instead of `RuntimeError`.
Patch by Yuuji Yaginuma. [Fixes GH-1808]

In other classes, `FrozenError` will be raised if change the frozen
object.
In order to match the behavior, I think that `FrozenError` should
use in `OpenStruct`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62271 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-06 23:52:30 +00:00
nobu 422cf1095f test_gem_util.rb: fix broken test
* test/rubygems/test_gem_util.rb: no guarantee that tmpdir is
  always underneath the root directory at all.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62246 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-06 07:42:44 +00:00
hsbt 7112c6a1c1 Merge RubyGems-2.7.5 from upstream.
Please see its details: http://blog.rubygems.org/2018/02/06/2.7.5-released.html

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-06 02:58:35 +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
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 bd5406dfa9 compile.c: fix string Range optimization with FSL
The optimization in [Feature #13355] needs to be detected
differently to work with "frozen_string_literal: true"

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-03 07:25:21 +00:00
nobu 28490dd1fd process.c: command_name encoding
* process.c (rb_exec_fillarg): share subsequence of argv_buf for
  command_name, and copy the encoding from the command string.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-03 03:50:28 +00:00
nobu 8b242a0d09 test_system.rb: tests without shell
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62168 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-02 16:44:22 +00:00
nobu 0d829c4af4 test_system.rb: exit by abort for portability
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-02 16:39:16 +00:00
kazu 59f502295f Fix test
Followup to r62158

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-02 11:21:12 +00:00
hsbt 499658abff Add test for Forwardable#def_delegator with r55366.
Patch by @aycabta
  [Bug #12837][ruby-core:77611]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62153 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-01 09:07:16 +00:00
nobu 044e6f12be win32.c: EPIPE for ERROR_NO_DATA
* win32/win32.c (rb_w32_write): writing to closed pipe fails with
  ERROR_NO_DATA but msvcrt maps it to EINVAL.  map it to EPIPE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-01 02:56:28 +00:00
nobu 4057ee5e8e io.c: fptr_copy_finalizer
* io.c (fptr_copy_finalizer): remove fptr from pipe_list when pipe
  became ordinary file, to fix access after free.  to be finalized
  by pipe_finalize and being in pipe_list must match.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62123 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-31 08:17:16 +00:00
nobu 1d5847d1af io.c: pipe_register_fptr
* io.c (pipe_register_fptr): get rid of double registration which
  causes access after free and segfault.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-31 04:24:57 +00:00
nobu e97cc46460 trick ruby-mode.el by heredocs
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-31 04:02:17 +00:00
normal 3ce9a14040 ruby.h: relax rb_funcall check on extra args for clang
clang 5.+ (tested clang 7.0.0) seems to be attempting division-by-zero
and giving a very large number for static args to rb_funcall.

* include/ruby/ruby.h (rb_varargs_bad_length): relax check for clang
* ext/-test-/funcall/funcall.c: renamed from passing_block.c
  define extra_args_name function
* test/-ext-/funcall/test_funcall.rb: new test
  [ruby-core:85266] [Bug #14425]

From: Eric Wong <e@80x24.org>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-30 23:55:49 +00:00
normal b10b51225e proc: fix super_method segfault after bind
* proc.c: handle undefined iclass
  [ruby-core:85231] [Bug #14421]

From: Eric Wong <e@80x24.org>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-30 19:35:12 +00:00
nobu 3f7221ad3d force fixable
* complex.c (nucomp_hash): force hash values fixable.
  [ruby-core:85224] [Bug #14420]

* rational.c (nurat_hash): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-30 05:48:28 +00:00
normal 7830a950ef net/pop: make modified strings mutable
Thanks to Michael Zimmerman for the bug report

* lib/net/pop.rb: make modified strings mutable
  [ruby-core:85210] [Bug #14416]
* test/net/pop/test_pop.rb: new test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-30 00:22:22 +00:00
nobu 7ea65f9be2 compile.c: try to convert in massign `for`
* compile.c (compile_for_masgn): try to convert to an Array if an
  element of massign `for` is not an Array.
  [ruby-core:84931] [Bug #14374]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-27 10:41:43 +00:00
nobu 9473f86fb0 defined? returns nil for toplevel constant lookup
* variable.c (rb_const_defined_0): toplevel constant lookup has
  been removed, should return nil too.
  [ruby-core:85142] [Bug #14407] [Fix GH-1800]

From: Gonzalo <grzuy0@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-27 06:12:09 +00:00
nobu c30aed0817 error.c: receiver kwarg
* error.c (name_err_initialize_options): NameError#initialize
  accepts receiver.  [Feature #14313]

* error.c (nometh_err_initialize_options): pass keyword arguments
  to the super method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62057 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-26 10:55:47 +00:00