2006-12-31 18:02:22 +03:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
insnhelper.h - helper macros to implement each instructions
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: 04/01/01 15:50:34 JST
|
|
|
|
|
* blockinlining.c, compile.c, compile.h, debug.c, debug.h,
id.c, insnhelper.h, insns.def, thread.c, thread_pthread.ci,
thread_pthread.h, thread_win32.ci, thread_win32.h, vm.h,
vm_dump.c, vm_evalbody.ci, vm_opts.h: fix comments and
copyright year.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-14 01:13:04 +03:00
|
|
|
Copyright (C) 2004-2007 Koichi Sasada
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
2008-01-18 11:56:11 +03:00
|
|
|
#ifndef RUBY_INSNHELPER_H
|
|
|
|
#define RUBY_INSNHELPER_H
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2017-10-21 09:22:43 +03:00
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
|
|
|
|
2009-01-15 18:31:43 +03:00
|
|
|
extern VALUE ruby_vm_const_missing_count;
|
2017-10-21 09:57:04 +03:00
|
|
|
extern rb_serial_t ruby_vm_global_method_state;
|
|
|
|
extern rb_serial_t ruby_vm_global_constant_state;
|
|
|
|
extern rb_serial_t ruby_vm_class_serial;
|
* common.mk: clean up
- remove blockinlining.$(OBJEXT) to built
- make ENCODING_H_INCLDUES variable (include/ruby/encoding.h)
- make VM_CORE_H_INCLUDES variable (vm_core.h)
- simplify rules.
- make depends rule to output depend status using gcc -MM.
* include/ruby/mvm.h, include/ruby/vm.h: rename mvm.h to vm.h.
* include/ruby.h: ditto.
* load.c: add inclusion explicitly.
* enumerator.c, object.c, parse.y, thread.c, vm_dump.c:
remove useless inclusion.
* eval_intern.h: cleanup inclusion.
* vm_core.h: rb_thread_t should be defined in this file.
* vm_evalbody.c, vm_exec.c: rename vm_evalbody.c to vm_exec.c.
* vm.h, vm_exec.h: rename vm.h to vm_exec.h.
* insnhelper.h, vm_insnhelper.h: rename insnhelper.h to vm_insnhelper.h.
* vm.c, vm_insnhelper.c, vm_insnhelper.h:
- rename vm_eval() to vm_exec_core().
- rename vm_eval_body() to vm_exec().
- cleanup include order.
* vm_method.c: fix comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 04:20:28 +04:00
|
|
|
|
2017-10-21 09:22:43 +03:00
|
|
|
RUBY_SYMBOL_EXPORT_END
|
|
|
|
|
2012-11-22 10:28:17 +04:00
|
|
|
#if VM_COLLECT_USAGE_DETAILS
|
2012-10-04 16:31:05 +04:00
|
|
|
#define COLLECT_USAGE_INSN(insn) vm_collect_usage_insn(insn)
|
|
|
|
#define COLLECT_USAGE_OPERAND(insn, n, op) vm_collect_usage_operand((insn), (n), ((VALUE)(op)))
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
|
2012-10-04 16:31:05 +04:00
|
|
|
#define COLLECT_USAGE_REGISTER(reg, s) vm_collect_usage_register((reg), (s))
|
|
|
|
#else
|
2012-11-22 10:28:17 +04:00
|
|
|
#define COLLECT_USAGE_INSN(insn) /* none */
|
|
|
|
#define COLLECT_USAGE_OPERAND(insn, n, op) /* none */
|
2012-10-04 16:31:05 +04:00
|
|
|
#define COLLECT_USAGE_REGISTER(reg, s) /* none */
|
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
/**********************************************************/
|
|
|
|
/* deal with stack */
|
|
|
|
/**********************************************************/
|
|
|
|
|
|
|
|
#define PUSH(x) (SET_SV(x), INC_SP(1))
|
|
|
|
#define TOPN(n) (*(GET_SP()-(n)-1))
|
2007-06-05 21:39:52 +04:00
|
|
|
#define POPN(n) (DEC_SP(n))
|
|
|
|
#define POP() (DEC_SP(1))
|
2007-06-01 08:05:46 +04:00
|
|
|
#define STACK_ADDR_FROM_TOP(n) (GET_SP()-(n))
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
#define GET_TOS() (tos) /* dummy */
|
|
|
|
|
|
|
|
/**********************************************************/
|
|
|
|
/* deal with registers */
|
|
|
|
/**********************************************************/
|
|
|
|
|
2016-11-05 19:31:25 +03:00
|
|
|
#define VM_REG_CFP (reg_cfp)
|
|
|
|
#define VM_REG_PC (VM_REG_CFP->pc)
|
|
|
|
#define VM_REG_SP (VM_REG_CFP->sp)
|
|
|
|
#define VM_REG_EP (VM_REG_CFP->ep)
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-06-24 14:33:00 +04:00
|
|
|
#define RESTORE_REGS() do { \
|
2017-10-27 09:21:50 +03:00
|
|
|
VM_REG_CFP = ec->cfp; \
|
2007-06-24 14:33:00 +04:00
|
|
|
} while (0)
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
#define REG_A reg_a
|
|
|
|
#define REG_B reg_b
|
|
|
|
|
2012-06-11 07:14:59 +04:00
|
|
|
enum vm_regan_regtype {
|
|
|
|
VM_REGAN_PC = 0,
|
|
|
|
VM_REGAN_SP = 1,
|
|
|
|
VM_REGAN_EP = 2,
|
|
|
|
VM_REGAN_CFP = 3,
|
|
|
|
VM_REGAN_SELF = 4,
|
2018-01-02 09:41:46 +03:00
|
|
|
VM_REGAN_ISEQ = 5
|
2012-06-11 07:14:59 +04:00
|
|
|
};
|
|
|
|
enum vm_regan_acttype {
|
|
|
|
VM_REGAN_ACT_GET = 0,
|
2018-01-02 09:41:46 +03:00
|
|
|
VM_REGAN_ACT_SET = 1
|
2012-06-11 07:14:59 +04:00
|
|
|
};
|
|
|
|
|
2012-10-04 16:31:05 +04:00
|
|
|
#if VM_COLLECT_USAGE_DETAILS
|
|
|
|
#define COLLECT_USAGE_REGISTER_HELPER(a, b, v) \
|
|
|
|
(COLLECT_USAGE_REGISTER((VM_REGAN_##a), (VM_REGAN_ACT_##b)), (v))
|
2006-12-31 18:02:22 +03:00
|
|
|
#else
|
2012-10-04 16:31:05 +04:00
|
|
|
#define COLLECT_USAGE_REGISTER_HELPER(a, b, v) (v)
|
2006-12-31 18:02:22 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* PC */
|
2016-11-05 19:31:25 +03:00
|
|
|
#define GET_PC() (COLLECT_USAGE_REGISTER_HELPER(PC, GET, VM_REG_PC))
|
|
|
|
#define SET_PC(x) (VM_REG_PC = (COLLECT_USAGE_REGISTER_HELPER(PC, SET, (x))))
|
2006-12-31 18:02:22 +03:00
|
|
|
#define GET_CURRENT_INSN() (*GET_PC())
|
|
|
|
#define GET_OPERAND(n) (GET_PC()[(n)])
|
2016-11-05 19:31:25 +03:00
|
|
|
#define ADD_PC(n) (SET_PC(VM_REG_PC + (n)))
|
2017-11-14 15:58:36 +03:00
|
|
|
#define JUMP(dst) (SET_PC(VM_REG_PC + (dst)))
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2012-06-11 07:14:59 +04:00
|
|
|
/* frame pointer, environment pointer */
|
2016-11-05 19:31:25 +03:00
|
|
|
#define GET_CFP() (COLLECT_USAGE_REGISTER_HELPER(CFP, GET, VM_REG_CFP))
|
|
|
|
#define GET_EP() (COLLECT_USAGE_REGISTER_HELPER(EP, GET, VM_REG_EP))
|
|
|
|
#define SET_EP(x) (VM_REG_EP = (COLLECT_USAGE_REGISTER_HELPER(EP, SET, (x))))
|
2012-06-11 07:14:59 +04:00
|
|
|
#define GET_LEP() (VM_EP_LEP(GET_EP()))
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
/* SP */
|
2016-11-05 19:31:25 +03:00
|
|
|
#define GET_SP() (COLLECT_USAGE_REGISTER_HELPER(SP, GET, VM_REG_SP))
|
|
|
|
#define SET_SP(x) (VM_REG_SP = (COLLECT_USAGE_REGISTER_HELPER(SP, SET, (x))))
|
|
|
|
#define INC_SP(x) (VM_REG_SP += (COLLECT_USAGE_REGISTER_HELPER(SP, SET, (x))))
|
|
|
|
#define DEC_SP(x) (VM_REG_SP -= (COLLECT_USAGE_REGISTER_HELPER(SP, SET, (x))))
|
2006-12-31 18:02:22 +03:00
|
|
|
#define SET_SV(x) (*GET_SP() = (x))
|
|
|
|
/* set current stack value as x */
|
2018-01-29 09:56:56 +03:00
|
|
|
#define ADJ_SP(x) INC_SP(x)
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
/* instruction sequence C struct */
|
|
|
|
#define GET_ISEQ() (GET_CFP()->iseq)
|
|
|
|
|
|
|
|
/**********************************************************/
|
|
|
|
/* deal with variables */
|
|
|
|
/**********************************************************/
|
|
|
|
|
2016-07-28 14:02:30 +03:00
|
|
|
#define GET_PREV_EP(ep) ((VALUE *)((ep)[VM_ENV_DATA_INDEX_SPECVAL] & ~0x03))
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2011-01-24 15:51:13 +03:00
|
|
|
#define GET_GLOBAL(entry) rb_gvar_get((struct rb_global_entry*)(entry))
|
|
|
|
#define SET_GLOBAL(entry, val) rb_gvar_set((struct rb_global_entry*)(entry), (val))
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2009-07-13 08:44:20 +04:00
|
|
|
#define GET_CONST_INLINE_CACHE(dst) ((IC) * (GET_PC() + (dst) + 2))
|
2007-07-01 22:16:02 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/**********************************************************/
|
|
|
|
/* deal with values */
|
|
|
|
/**********************************************************/
|
|
|
|
|
2012-10-04 16:31:05 +04:00
|
|
|
#define GET_SELF() (COLLECT_USAGE_REGISTER_HELPER(SELF, GET, GET_CFP()->self))
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
/**********************************************************/
|
|
|
|
/* deal with control flow 2: method/iterator */
|
|
|
|
/**********************************************************/
|
|
|
|
|
2015-09-19 20:59:58 +03:00
|
|
|
#define CALL_METHOD(calling, ci, cc) do { \
|
2017-10-27 09:21:50 +03:00
|
|
|
VALUE v = (*(cc)->call)(ec, GET_CFP(), (calling), (ci), (cc)); \
|
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 09:58:09 +03:00
|
|
|
if (v == Qundef && (v = mjit_exec(ec)) == Qundef) { \
|
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 14:22:28 +03:00
|
|
|
EXEC_EC_CFP(); \
|
2007-06-30 22:27:20 +04:00
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
val = v; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2012-10-15 00:59:21 +04:00
|
|
|
/* set fastpath when cached method is *NOT* protected
|
|
|
|
* because inline method cache does not care about receiver.
|
|
|
|
*/
|
2012-10-15 21:40:50 +04:00
|
|
|
|
|
|
|
#ifndef OPT_CALL_FASTPATH
|
|
|
|
#define OPT_CALL_FASTPATH 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if OPT_CALL_FASTPATH
|
2015-09-19 20:59:58 +03:00
|
|
|
#define CI_SET_FASTPATH(cc, func, enabled) do { \
|
|
|
|
if (LIKELY(enabled)) ((cc)->call = (func)); \
|
2012-10-15 00:59:21 +04:00
|
|
|
} while (0)
|
2012-10-15 21:40:50 +04:00
|
|
|
#else
|
|
|
|
#define CI_SET_FASTPATH(ci, func, enabled) /* do nothing */
|
|
|
|
#endif
|
2012-10-15 00:59:21 +04:00
|
|
|
|
2016-07-28 14:02:30 +03:00
|
|
|
#define GET_BLOCK_HANDLER() (GET_LEP()[VM_ENV_DATA_INDEX_SPECVAL])
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
/**********************************************************/
|
|
|
|
/* deal with control flow 3: exception */
|
|
|
|
/**********************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************/
|
|
|
|
/* others */
|
|
|
|
/**********************************************************/
|
|
|
|
|
|
|
|
/* optimize insn */
|
2012-08-23 11:22:40 +04:00
|
|
|
#define FIXNUM_2_P(a, b) ((a) & (b) & 1)
|
|
|
|
#if USE_FLONUM
|
|
|
|
#define FLONUM_2_P(a, b) (((((a)^2) | ((b)^2)) & 3) == 0) /* (FLONUM_P(a) && FLONUM_P(b)) */
|
|
|
|
#else
|
|
|
|
#define FLONUM_2_P(a, b) 0
|
|
|
|
#endif
|
2017-01-13 08:49:43 +03:00
|
|
|
#define FLOAT_HEAP_P(x) (!SPECIAL_CONST_P(x) && RBASIC_CLASS(x) == rb_cFloat)
|
|
|
|
#define FLOAT_INSTANCE_P(x) (FLONUM_P(x) || FLOAT_HEAP_P(x))
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2009-09-07 00:42:50 +04:00
|
|
|
#ifndef USE_IC_FOR_SPECIALIZED_METHOD
|
|
|
|
#define USE_IC_FOR_SPECIALIZED_METHOD 1
|
|
|
|
#endif
|
|
|
|
|
2013-11-09 07:34:49 +04:00
|
|
|
#define NEXT_CLASS_SERIAL() (++ruby_vm_class_serial)
|
2013-12-09 14:51:02 +04:00
|
|
|
#define GET_GLOBAL_METHOD_STATE() (ruby_vm_global_method_state)
|
|
|
|
#define INC_GLOBAL_METHOD_STATE() (++ruby_vm_global_method_state)
|
|
|
|
#define GET_GLOBAL_CONSTANT_STATE() (ruby_vm_global_constant_state)
|
|
|
|
#define INC_GLOBAL_CONSTANT_STATE() (++ruby_vm_global_constant_state)
|
2011-06-13 15:25:44 +04:00
|
|
|
|
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 14:22:28 +03:00
|
|
|
extern VALUE make_no_method_exception(VALUE exc, VALUE format, VALUE obj,
|
2016-02-28 07:41:38 +03:00
|
|
|
int argc, const VALUE *argv, int priv);
|
2011-10-06 11:29:33 +04:00
|
|
|
|
2015-03-11 15:49:27 +03:00
|
|
|
static inline struct vm_throw_data *
|
2016-07-28 14:02:30 +03:00
|
|
|
THROW_DATA_NEW(VALUE val, const rb_control_frame_t *cf, VALUE st)
|
2015-03-10 21:39:46 +03:00
|
|
|
{
|
2015-03-11 15:49:27 +03:00
|
|
|
return (struct vm_throw_data *)rb_imemo_new(imemo_throw_data, val, (VALUE)cf, st, 0);
|
2015-03-10 21:39:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE
|
2015-03-11 15:49:27 +03:00
|
|
|
THROW_DATA_VAL(const struct vm_throw_data *obj)
|
2015-03-10 21:39:46 +03:00
|
|
|
{
|
2017-04-07 10:50:30 +03:00
|
|
|
VM_ASSERT(THROW_DATA_P(obj));
|
2015-03-10 21:39:46 +03:00
|
|
|
return obj->throw_obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const rb_control_frame_t *
|
2015-03-11 15:49:27 +03:00
|
|
|
THROW_DATA_CATCH_FRAME(const struct vm_throw_data *obj)
|
2015-03-10 21:39:46 +03:00
|
|
|
{
|
2017-04-07 10:50:30 +03:00
|
|
|
VM_ASSERT(THROW_DATA_P(obj));
|
2015-03-10 21:39:46 +03:00
|
|
|
return obj->catch_frame;
|
|
|
|
}
|
|
|
|
|
2017-04-06 05:56:23 +03:00
|
|
|
static inline int
|
2015-03-11 15:49:27 +03:00
|
|
|
THROW_DATA_STATE(const struct vm_throw_data *obj)
|
2015-03-10 21:39:46 +03:00
|
|
|
{
|
2017-04-07 10:50:30 +03:00
|
|
|
VM_ASSERT(THROW_DATA_P(obj));
|
2015-03-11 00:28:09 +03:00
|
|
|
return (int)obj->throw_state;
|
2015-03-10 21:39:46 +03:00
|
|
|
}
|
|
|
|
|
2017-04-06 05:56:23 +03:00
|
|
|
static inline int
|
|
|
|
THROW_DATA_CONSUMED_P(const struct vm_throw_data *obj)
|
|
|
|
{
|
|
|
|
VM_ASSERT(THROW_DATA_P(obj));
|
|
|
|
return obj->flags & THROW_DATA_CONSUMED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
THROW_DATA_CATCH_FRAME_SET(struct vm_throw_data *obj, const rb_control_frame_t *cfp)
|
|
|
|
{
|
2017-04-07 10:50:30 +03:00
|
|
|
VM_ASSERT(THROW_DATA_P(obj));
|
2017-04-06 05:56:23 +03:00
|
|
|
obj->catch_frame = cfp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
THROW_DATA_STATE_SET(struct vm_throw_data *obj, int st)
|
|
|
|
{
|
2017-04-07 10:50:30 +03:00
|
|
|
VM_ASSERT(THROW_DATA_P(obj));
|
2017-04-06 05:56:23 +03:00
|
|
|
obj->throw_state = (VALUE)st;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
THROW_DATA_CONSUMED_SET(struct vm_throw_data *obj)
|
|
|
|
{
|
|
|
|
if (THROW_DATA_P(obj) &&
|
|
|
|
THROW_DATA_STATE(obj) == TAG_BREAK) {
|
|
|
|
obj->flags |= THROW_DATA_CONSUMED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-18 11:56:11 +03:00
|
|
|
#endif /* RUBY_INSNHELPER_H */
|