1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test
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
..
-ext- ruby.h: relax rb_funcall check on extra args for clang 2018-01-30 23:55:49 +00:00
base64
benchmark
bigdecimal $SAFE as a process global state. [Feature #14250] 2017-12-28 20:09:24 +00:00
cgi
coverage
csv
date
dbm skip some tests so that no failure occurs in root privilege 2018-01-10 10:39:09 +00:00
digest
drb drb: use \A and \z 2017-12-30 12:10:43 +00:00
dtrace
erb erb.rb: preserve the behavior for invalid syntax 2017-12-27 12:40:03 +00:00
etc
excludes
fiddle $SAFE as a process global state. [Feature #14250] 2017-12-28 20:09:24 +00:00
fileutils
gdbm Fix indent and use as skipped message instead of comment 2018-01-11 13:56:04 +00:00
io test_io_console.rb: get rid of sporadic failures 2017-12-23 14:31:56 +00:00
irb skip some tests so that no failure occurs in root privilege 2018-01-10 10:39:09 +00:00
json
lib mjit.c: merge MJIT infrastructure 2018-02-04 06:58:09 +00:00
logger
matrix
minitest
misc
mkmf
monitor
net net/pop: make modified strings mutable 2018-01-30 00:22:22 +00:00
nkf
objspace
open-uri
openssl
optparse optparse.rb: froze string literals 2018-01-26 03:41:04 +00:00
ostruct
pathname skip some tests so that no failure occurs in root privilege 2018-01-10 10:39:09 +00:00
psych
rdoc skip some tests so that no failure occurs in root privilege 2018-01-10 10:39:09 +00:00
readline $SAFE as a process global state. [Feature #14250] 2017-12-28 20:09:24 +00:00
resolv fix for IPv6 env 2018-01-11 19:41:49 +00:00
rexml
rinda
ripper
rss
ruby mjit.c: merge MJIT infrastructure 2018-02-04 06:58:09 +00:00
rubygems skip some tests so that no failure occurs in root privilege 2018-01-10 10:39:09 +00:00
scanf
sdbm skip some tests so that no failure occurs in root privilege 2018-01-10 10:39:09 +00:00
shell
socket init.c: encode socket error message 2018-01-23 15:31:22 +00:00
stringio
strscan
syslog
testunit
thread
uri
webrick webrick: add test for WEBrick::HTTPServlet::ERBHandler 2017-12-22 01:07:50 +00:00
win32ole $SAFE as a process global state. [Feature #14250] 2017-12-28 20:09:24 +00:00
yaml
zlib
colors
runner.rb
test_abbrev.rb
test_cmath.rb
test_delegate.rb
test_extlibs.rb
test_find.rb Fix indent and use as skipped message instead of comment 2018-01-11 13:56:04 +00:00
test_forwardable.rb Add test for Forwardable#def_delegator with r55366. 2018-02-01 09:07:16 +00:00
test_ipaddr.rb
test_mutex_m.rb
test_observer.rb
test_open3.rb
test_pp.rb
test_prettyprint.rb
test_prime.rb
test_pstore.rb
test_pty.rb
test_rbconfig.rb
test_securerandom.rb
test_set.rb
test_shellwords.rb
test_singleton.rb
test_syslog.rb
test_tempfile.rb $SAFE as a process global state. [Feature #14250] 2017-12-28 20:09:24 +00:00
test_time.rb
test_timeout.rb
test_tmpdir.rb $SAFE as a process global state. [Feature #14250] 2017-12-28 20:09:24 +00:00
test_tracer.rb
test_tsort.rb
test_unicode_normalize.rb
test_weakref.rb
test_win32api.rb