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

774 Коммитов

Автор SHA1 Сообщение Дата
k0kubun 2e003f6c87 process.c: don't wait JIT queue flush on rb_f_exec
This wasn't intended in r64253.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64254 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-09 11:39:07 +00:00
k0kubun 212a77ed46 process.c: fix outdated mjit_pause declaration
by sharing it with vm.c in internal.h.

vm.c: ditto
internal.h: ditto
mjit.h: share more.

mjit.c: make sure the third arguemnt is not used

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-09 11:31:41 +00:00
k0kubun 510cd06c78 mjit.c: add :wait option to RubyVM::MJIT.pause
and wait until JIT queue is flushed when wait option is not passed or
`wait: true` is passed.

vm.c: ditto

test/ruby/test_rubyvm_mjit.rb: added test for pause/resume

test/lib/jit_support.rb: allow retrying MJIT on JITSupport level
test/ruby/test_jit.rb: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-09 09:58:07 +00:00
k0kubun ba8413c27c vm.c: simplify the implementation of r64031
because such inconsistency may result in the regression fixed in r64034.

vm_exec is not touched since renaming it may be controversial...

vm_args.c: ditto.
vm_eval.c: ditto.
vm_insnhelper.c: ditto.
vm_method.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-24 15:17:08 +00:00
nobu afba9cd7fe prefix symbols exported for mjit
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-24 12:12:59 +00:00
nobu 7387c08373 const_missing on private constants
* variable.c (rb_const_search): call #const_missing method on
  private constants, as well as uninitialized constants.
  [Feature #14328]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-06 13:56:58 +00:00
nobu aec14b33d4 vm.c: simplified core#hash_merge_kwd
* vm.c (core_hash_merge_kwd): simplified to merge the second hash
  into the first hash.

* compile.c (compile_array): call core#hash_merge_kwd with 2
  hashes always, by passing an new empty hash to at the first
  iteration.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-03 23:56:11 +00:00
normal 18c7978161 vm.c (rb_source_location): check for NULL cfp->iseq
rb_vm_get_sourceline returns zero if cfp->iseq is NULL,
so rb_iseq_path should not try to follow NULL cfp->iseq,
either.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-03 09:06:28 +00:00
k0kubun 06f54f0303 mjit.c: unify the variable name with method name
`RubyVM::MJIT.enabled?`.

It's set to be TRUE even before initialization is finished.
So it was actually not "mjit initialized predicate".

This flag is also used to check whether JIT-ed code should be called
or not, but I'm going to split the responsibility to another flag.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-23 13:41:06 +00:00
ktsj 289dcb30b9 vm.c: fix infinite loop
* vm.c: use EXEC_EVENT_HOOK_AND_POP_FRAME. While exception handling, if an exception
  is raised in hooks, need to pop current frame and raise this raised exception by hook.

[ruby-dev:50582] [Bug #14865]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-23 04:52:58 +00:00
ktsj 3b51b2fa96 vm.c: fix typo in function name
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-23 04:45:57 +00:00
k0kubun 0af19735d7 mjit.c: RubyVM::MJIT.pause / RubyVM::MJIT.resume
[Feature #14830]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63710 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-21 14:04:05 +00:00
ko1 e6ad53beaa remove VM_ENV_DATA_INDEX_ENV_PROC.
* vm_core.h (VM_ENV_DATA_INDEX_ENV_PROC): ep[VM_ENV_DATA_INDEX_ENV_PROC] is
  allocated to mark a Proc which is created from iseq block.
  However, `lep[0]` keeps Proc object itself as a block handler (Proc).
  So we don't need to keep it.

* vm_core.h (VM_ENV_PROCVAL): ditto.

* vm.c (vm_make_env_each): do not need to keep blockprocval as special value.

* vm.c (vm_block_handler_escape): simply return Proc value.

* proc.c (proc_new):  we don't need to check Env because a Proc type block
  handler is a Proc object itself.
  [Bug #14782]

* test/ruby/test_proc.rb: add a test for [Bug #14782]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-23 06:56:08 +00:00
normal 475b4aa40b simplify altstack and enable reuse with thread cache
Instead of allocating and registering the altstack in different
places, do it together to reduce code and improve readability.
When thread cache is enabled, storing altstack in rb_thread_t
is wasteful and we may reuse altstack in the same pthread.

This also lets us clearly allow use of xmalloc to allow GC to
recover from ENOMEM.

[ruby-core:85621] [Feature #14487]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-20 21:38:27 +00:00
ko1 51d227e3a5 refactoring r63073.
* cont.c (root_fiber_alloc): call `ConvertThreadToFiber()` here.

  `rb_fiber_t` for root_fiber is allocated before running Threads.
  Fiber objects wrapping this rb_fiber_t for root_fiber are created
  when root Fiber object is required explicitly (for example, Fiber
  switching and so on). We can put calling `ConvertThreadToFiber()`.
  In other words, we can pending `ConvertThreadToFiber()`
  until Fiber objects are created.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63090 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-04 08:19:28 +00:00
ko1 db3cc675f3 Fix Fiber with Thread issue on Windows [Bug #14642]
* cont.c (rb_threadptr_root_fiber_setup): divide into two functions:
  * rb_threadptr_root_fiber_setup_by_parent(): called by the parent thread.
  * rb_threadptr_root_fiber_setup_by_child(): called by the created thread.

  `rb_threadptr_root_fiber_setup()` is called by the parent thread and
  set fib->fib_handle by ConvertThreadToFiber() on the parent thread on
  Windows enveironment.
  This means that root_fib->fib_handle of child thread is initialized
  with parent thread's Fiber handle. Furthermore, second call of
  `ConvertThreadToFiber()` for the same thread fails.

  This patch solves this weird situateion. However, maybe we can make more
  clean code.

* thread.c (thread_start_func_2): call
  `rb_threadptr_root_fiber_setup_by_child()` at thread initialize routine.

* vm.c (th_init): call `rb_threadptr_root_fiber_setup_by_parent()`.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-03 10:21:47 +00:00
nobu 421a73f51a vm.c: refined error message
* vm.c (kw_check_symbol): refined the error message for non-symbol
  key.  [Feature #14603]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-15 00:12:17 +00:00
ko1 8d9c6e3233 add prefix to the function name.
* vm.c (handle_exception): rename to vm_exce_handle_exception.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-05 01:17:08 +00:00
nobu ae34216021 vm.c: trivial optimization
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62653 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-04 06:24:38 +00:00
nobu ac44ae58c6 vm.c: handle_exception loop
* vm.c (vm_exec): hoist out handle_exception and loop to rewind
  for each catching frames.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-04 02:37:22 +00:00
nobu 76307c9023 vm.c: untangle goto loop
* vm.c (vm_exec): moved code to get rid of cross-jumps across
  branches.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-04 02:09:47 +00:00
k0kubun b7aae52851 vm.c: add mjit_enable_p flag
to count up total calls properly. Some places (especially CALL_METHOD)
invoke mjit_exec twice for one method call. It would be problematic when
debugging, or possibly it would result in a wrong profiling result.

This commit doesn't have impact for performance:

* Optcarrot benchmark

** before

fps: 59.37757770848619
fps: 56.49998488958699
fps: 59.07900362739362
fps: 58.924749807695996
fps: 57.667905665594894
fps: 57.540021018385254
fps: 59.5518055679647
fps: 55.93831555148311
fps: 57.82685112863262
fps: 59.22391754481736
checksum: 59662

** after

fps: 58.461881158098194
fps: 59.32685183081354
fps: 54.11334310279802
fps: 59.2281560439788
fps: 58.60495705318312
fps: 55.696478648491045
fps: 58.49003452654724
fps: 58.387771929393224
fps: 59.24156772816439
fps: 56.68804731968107
checksum: 59662

* Discourse

Your Results: (note for timings- percentile is first, duration is second in millisecs)

** before (without JIT)

categories_admin:
  50: 16
  75: 17
  90: 24
  99: 37
home_admin:
  50: 20
  75: 20
  90: 24
  99: 42
topic_admin:
  50: 16
  75: 16
  90: 18
  99: 28
categories:
  50: 36
  75: 37
  90: 45
  99: 68
home:
  50: 38
  75: 40
  90: 53
  99: 92
topic:
  50: 14
  75: 15
  90: 17
  99: 26

** after (without JIT)

categories_admin:
  50: 16
  75: 16
  90: 24
  99: 36
home_admin:
  50: 19
  75: 20
  90: 23
  99: 41
topic_admin:
  50: 16
  75: 16
  90: 19
  99: 33
categories:
  50: 35
  75: 36
  90: 44
  99: 61
home:
  50: 38
  75: 40
  90: 52
  99: 101
topic:
  50: 14
  75: 15
  90: 15
  99: 24

** before (with JIT)

categories_admin:
  50: 19
  75: 23
  90: 29
  99: 44
home_admin:
  50: 24
  75: 26
  90: 32
  99: 46
topic_admin:
  50: 20
  75: 22
  90: 27
  99: 44
categories:
  50: 41
  75: 43
  90: 51
  99: 66
home:
  50: 46
  75: 49
  90: 56
  99: 68
topic:
  50: 18
  75: 19
  90: 22
  99: 31

** after (with JIT)

categories_admin:
  50: 18
  75: 21
  90: 28
  99: 42
home_admin:
  50: 23
  75: 25
  90: 31
  99: 51
topic_admin:
  50: 19
  75: 20
  90: 24
  99: 31
categories:
  50: 41
  75: 44
  90: 52
  99: 69
home:
  50: 45
  75: 48
  90: 61
  99: 88
topic:
  50: 19
  75: 20
  90: 24
  99: 33

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62641 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-03 04:07:02 +00:00
nobu 35ab341cf2 Fix typo: blcok -> block
Typo in a comment about "evaluator body".

[Fix GH-1824]

From: hkdnet <satoko.itse@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-24 01:02:58 +00:00
nobu 96db72ce38 [DOC] missing docs at toplevel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23 02:18:52 +00:00
nobu 49f52937bd vm.c: disable dtrace in jit source
* vm.c: include dummy dtrace probes header in jit header.

* vm_insnhelper.c: probes headers are included by vm.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62489 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-20 03:15:33 +00:00
k0kubun 288b44328d Export some missing symbols for MJIT
tool/ruby_vm/views/_insn_name_info.erb: on Linux, rb_vm_insn_name_offset
was needed to compile with --jit-debug (Usually --jit-debug requires
more symbols than the situation without --jit-debug because -O2 skips
some functions to compile).

vm.c: when running transform_mjit_header.rb with --jit-wait,
rb_source_location_cstr was repoted to be missing.

string.c: ditto, for rb_str_eql
numeric.c: ditto, for rb_float_eql

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08 13:54:37 +00:00
k0kubun 25a82d7936 vm.c: feedback control frame size change
to VM_ASSERT. r62197 is adding bp.

I'll try to remove bp, but let's pass CI which enables assertion.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04 13:15:28 +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 69d6e7d949 vm.c: remove unnecessary branch
th->altstack is never NULL, and even if it were, POSIX
stipulates free(3) on NULL to be a no-op.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-24 22:40:01 +00:00
shyouhei 39f0269bd1 usage analysis functions marke as static
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-18 09:44:50 +00:00
nobu e9cb552ec9 internal.h: remove dependecy on ruby/encoding.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 06:24:11 +00:00
normal 4c0c299964 use predefined ids in a few more places
Saves a little space on x86:

   text	   data	    bss	    dec	    hex	filename
3684110	  11968	  34240	3730318	 38eb8e	ruby.before
3684086	  11968	  34240	3730294	 38eb76	ruby.after

* enumerator.c: include id.h, define aliases
  (Init_Enumeerator): remove unnecessary rb_intern calls
* gc.c (should_be_callable): use idCall
* vm.c (Init_VM): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 02:45:03 +00:00
nobu 840bfeac81 vm.c: remove extra ifdef
* vm.c (rb_execution_context_mark): VM_ASSERT works only if
  VM_CHECK_MODE > 0.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08 23:35:36 +00:00
ko1 b4960648bf fix a bug only on assertion.
* vm.c (rb_execution_context_mark): check escaped directly
  to skip assertions. Not sure why there is an inconsistency.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08 16:00:38 +00:00
ko1 adc0bf933e fix mark miss of Env (which is pointed by prev_ep).
* vm.c (rb_execution_context_mark): r61624 and r61659 introduce marking miss
  bug for Env objects as a prev_ep which is contained by Proc objects because
  Proc objects can be collected when they should be living and Env objects
  will collected unexpectedly. This patch solves this problem.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08 15:27:56 +00:00
nobu 0948eb62e6 vm.c: respect redefinition of Proc#call
* vm.c (vm_redefinition_check_method_type): hoist out method
  definition type to check redefinition.

* vm.c (rb_vm_check_redefinition_opt_method): should check
  optimized method too.

* vm.c (vm_init_redefined_flag): check Proc#call.

* vm_insnhelper.c (vm_call_opt_block_call): search proper method
  if redefined.  [Bug #14335]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08 09:04:07 +00:00
ko1 7fd1183467 Speedup `block.call` [Feature #14330]
* insns.def (getblockparamproxy): introduce new instruction to return
  the `rb_block_param_proxy` object if possible. This object responds
  to `call` method and invoke given block (completely similar to `yield`).

* method.h (OPTIMIZED_METHOD_TYPE_BLOCK_CALL): add new optimized call type
  which is for `rb_block_param_proxy.cal`.

* vm_insnhelper.c (vm_call_method_each_type): ditto.

* vm_insnhelper.c (vm_call_opt_block_call): ditto.

* vm_core.h (BOP_CALL, PROC_REDEFINED_OP_FLAG): add check for `Proc#call`
  redefinition.

* compile.c (iseq_compile_each0): compile to use new insn
  `getblockparamproxy` for method call.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-07 19:18:49 +00:00
mame 38c62063c0 node.h: remove NODE_PRELUDE
NODE_PRELUDE contains a `BEGIN` node, a main node, and compile_option.
This node is assumed that it must be located immediately under the root
NODE_SCOPE, but this strange assumption is not so good, IMO.

This change removes the assumtion; it integrates the former two nodes by
block_append, and moves compile_option into rb_ast_body_t.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-05 08:59:23 +00:00
mame 92b81dc597 make rb_iseq_new* accept rb_ast_body_t instead of NODE*
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-05 08:59:22 +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
k0kubun 316f58076d vm.c: always export rb_frame_method_id_and_class
Functions declared in include/ruby/backward.h is exported only when
the condition `!defined RUBY_EXPORT && !defined RUBY_NO_OLD_COMPATIBILITY`
is met (i.e. included by include/ruby/ruby.h).

So if it is not the case when ruby is built, this will not be exported.
This was not intentional at r60994.

[Bug #14192]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-16 13:02:25 +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 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
ko1 975e3a19a7 do not disable `trace_` prefix insns.
* vm.c: introduce `ruby_vm_event_enabled_flags` which represents which
  event flags are enabled before.

* vm_trace.c: do not turn off `trace_` prefix instructions because turn on
  overhead is a matter if a program repeats turn on and turn off frequently.

* iseq.c (finish_iseq_build): respect `ruby_vm_event_enabled_flags`.

* vm_insnhelper.c (vm_trace): check `ruby_vm_event_flags` and disable
  lazy trace-off technique (do not disable traces).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-11 19:17:25 +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
k0kubun 857827e3ee vm.c: partially revert r60558
because it was actually used in
https://github.com/tmm1/rbtrace/blob/v0.4.8/ext/rbtrace.c#L329
and deprecated in r60579 AFTER removal in r60558.

ko1 agreed that we should keep just deprecated in Ruby 2.5 and remove it
later, and I'm commiting this because I want to make rbtrace.gem
installation successful.

backward.h: modify r60579 to make rb_frame_method_id_and_class()
compilable.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60964 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-01 12:26:40 +00:00
mame ec3a906bb6 Refactoring out the direct accesses of NODE's u1, u2, and u3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60812 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16 11:03:37 +00:00
ko1 d4a69bb48e make a func static.
* vm.c (rb_proc_create_from_captured): make this func static and renmae
  with vm_ prefix.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60800 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16 07:43:27 +00:00