summaryrefslogtreecommitdiff
path: root/tool/ruby_vm
AgeCommit message (Collapse)Author
2018-09-20fix typo [ci skip]shyouhei
This error does not happen right now so this typo is not serious, unless you locally edit insns.def. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64791 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-18vm_insnhelper.h: rename CI_SET_FASTPATH to CC_SET_FASTPATHk0kubun
because it's actually setting fastpath to cc instead of ci since r51903. vm_insnhelper.c: ditto mjit_compile.c: ditto tool/ruby_vm/views/_mjit_compile_send.erb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-14move ADD_PC around (take 2)shyouhei
Now that we can say for sure if an instruction calls a method or not internally, it is now possible to reroute the bugs that forced us to revert the "move PC around" optimization. First try: r62051 Reverted: r63763 See also: r63999 ---- trunk: ruby 2.6.0dev (2018-09-13 trunk 64736) [x86_64-darwin15] ours: ruby 2.6.0dev (2018-09-13 trunk 64736) [x86_64-darwin15] last_commit=move ADD_PC around (take 2) Calculating ------------------------------------- trunk ours so_ackermann 1.884 2.278 i/s - 1.000 times in 0.530926s 0.438935s so_array 1.178 1.157 i/s - 1.000 times in 0.848786s 0.864467s so_binary_trees 0.176 0.177 i/s - 1.000 times in 5.683895s 5.657707s so_concatenate 0.220 0.221 i/s - 1.000 times in 4.546896s 4.518949s so_count_words 6.729 6.470 i/s - 1.000 times in 0.148602s 0.154561s so_exception 3.324 3.688 i/s - 1.000 times in 0.300872s 0.271147s so_fannkuch 0.546 0.968 i/s - 1.000 times in 1.831328s 1.033376s so_fasta 0.541 0.547 i/s - 1.000 times in 1.849923s 1.827091s so_k_nucleotide 0.800 0.777 i/s - 1.000 times in 1.250635s 1.286295s so_lists 2.101 1.848 i/s - 1.000 times in 0.475954s 0.541095s so_mandelbrot 0.435 0.408 i/s - 1.000 times in 2.299328s 2.450535s so_matrix 1.946 1.912 i/s - 1.000 times in 0.513872s 0.523076s so_meteor_contest 0.311 0.317 i/s - 1.000 times in 3.219297s 3.152052s so_nbody 0.746 0.703 i/s - 1.000 times in 1.339815s 1.423441s so_nested_loop 0.899 0.901 i/s - 1.000 times in 1.111767s 1.109555s so_nsieve 0.559 0.579 i/s - 1.000 times in 1.787763s 1.726552s so_nsieve_bits 0.435 0.428 i/s - 1.000 times in 2.296282s 2.333852s so_object 1.368 1.442 i/s - 1.000 times in 0.731237s 0.693684s so_partial_sums 0.616 0.546 i/s - 1.000 times in 1.623592s 1.833097s so_pidigits 0.831 0.832 i/s - 1.000 times in 1.203117s 1.202334s so_random 2.934 2.724 i/s - 1.000 times in 0.340791s 0.367150s so_reverse_complement 0.583 0.866 i/s - 1.000 times in 1.714144s 1.154615s so_sieve 1.829 2.081 i/s - 1.000 times in 0.546607s 0.480562s so_spectralnorm 0.524 0.558 i/s - 1.000 times in 1.908716s 1.792382s git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64737 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-13Revert "vm_insnhelper.h: simplify EXEC_EC_CFP implementation"k0kubun
This reverts commit r64711, because EXEC_EC_CFP on JIT-ed code does not call jit_func with the patch when catch_except_p is true. It wasn't intentional. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-13vm_insnhelper.h: simplify EXEC_EC_CFP implementationk0kubun
and possibly memory access for iseq->body may be reduced. No significant impact for performance on Optcarrot. * before fps: 55.03865935187656 fps: 57.16854675983188 fps: 57.672458407661765 fps: 58.28989837869383 fps: 58.80503815099268 fps: 59.068054176528534 fps: 59.55736806358244 fps: 61.01018920533034 fps: 63.34167049232186 fps: 65.20575018321766 fps: 65.46758316561318 * after fps: 55.21860411005677 fps: 55.34840351179166 fps: 58.23666596747484 fps: 59.71987124578901 fps: 61.131485120234935 fps: 61.279905164649485 fps: 61.66060774175459 fps: 64.11215576508765 fps: 64.63699742853154 fps: 65.28260058920769 fps: 65.85447796482678 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64711 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-13move canary-related statements into macrosshyouhei
This is mostly cosmetic. Should generate a slightly readable vm.inc output. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-12_mjit_compile_pc_and_sp.erb: forget about memcpy [ci skip]k0kubun
because using memcpy here actually made performance worse. In Optcarrot, * for loop fps: 55.90428960597268 fps: 57.21690379342434 fps: 58.41751168279789 fps: 58.7317470613203 fps: 62.81371000202459 fps: 63.02541045417479 fps: 63.77324026366317 fps: 65.48067818347447 fps: 66.02324323831398 fps: 66.3816048847424 fps: 66.54526488660156 * memcpy fps: 54.98389812126847 fps: 57.96524857391357 fps: 57.974918725327946 fps: 58.285987089087364 fps: 58.639003211333225 fps: 59.03244214601948 fps: 59.89964772199603 fps: 60.809490242786175 fps: 62.462070790624146 fps: 62.534599002918306 fps: 63.787312566163756 That's probably because the copied size is very small. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64699 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-11_mjit_compile_insn.erb: move pc on JIT cancelk0kubun
if and only if it's not moved yet, to avoid potential bugs in the future. _mjit_compile_send.erb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-11bare_instructions.rb: use Hash#fetch to read attrk0kubun
to raise descriptive KeyError instead of NoMethodError in case these attrs are accidentally removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-11_mjit_compile_insn.erb: prefer insn.always_leaf?k0kubun
rather than `trace_enablable_insns` which is hard to maintain. This would make performance bad because new branches for tracepoint will be added. Optcarrot before: fps: 56.885371547337655 fps: 60.02493636060194 fps: 63.051028327122076 fps: 63.78463316242535 fps: 64.20391937940403 fps: 64.55990344731123 fps: 64.56771099162921 fps: 64.95991277629723 fps: 65.15120708973232 fps: 65.90558702393933 fps: 66.29579283026303 Optcarrot after: fps: 52.7647027470875 fps: 53.67404855529564 fps: 58.40514319229468 fps: 60.90736996487708 fps: 62.83487236283472 fps: 63.01386139447994 fps: 63.42395443471596 fps: 63.78328559878602 fps: 64.58432081229746 fps: 64.78720429848532 fps: 65.48720618907552 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64684 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-11_mjit_compile_pc_and_sp.erb: skip moving pck0kubun
when catch_except_p is false and insn.always_leaf? is true (never makes arbitrary method call in the insn). On Optcarrot, unfortunately this didn't have measureable performance impact. But still this is a good direction since it becomes much faster when marking all insns as always leaf. bare_instructions.rb: add `#always_leaf?` that indicates the insn can always be considered as leaf. Using dynamic leaf for JIT would be hard since it requires to discard outdated code somehow. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-11add new instruction attribute called leafshyouhei
An instruction is leaf if it has no rb_funcall inside. In order to check this property, we introduce stack canary which is a random number collected at runtime. Stack top is always filled with this number and checked for stack smashing operations, when VM_CHECK_MODE. [GH-1947] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-12vm_insnhelper.c: revert r64280k0kubun
This commit caused test-all failure with --jit-wait. I don't know the reason yet, but let me revert it to normalize CI. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-11_mjit_compile_pc_and_sp.erb: update the commentk0kubun
about the pc motion reason git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64284 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-11_mjit_compile_pc_and_sp.erb: always move pck0kubun
to fix the wrong line number on #caller_locations or rb_profile_frames. Actually we would be able to move it only when method call (of caller_locations) or C extension invocation (calling rb_profile_frames) can happen. This degrades performance. Optcarrot fps becomes... before: 71.78976052783555 after: 67.65429356624131 I think I can lazily move it and fix the performance issue, even improving the performance for the situation catch table exists. But let me fix this bug first... git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-11vm_args.c: stop requiring `calling` in vm_caller_setup_arg_blockk0kubun
_mjit_compile_send.erb: simplify code using the change insns.def: adapt to the interface change git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64281 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-11_mjit_compile_send.erb: refactor to share vm_call_iseq_setup_normalk0kubun
implementation. This had no major performance impact by effort to keep them inlined. vm_insnhelper.c: ditto mjit_compile.c: just update the comment about opt_pc=0 assumption git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-25insns.def: s/handles_frame/handles_sp/k0kubun
because it's more suitable to describe the current behavior now. tool/ruby_vm/models/bare_instructions.rb: ditto. tool/ruby_vm/views/_insn_entry.erb: ditto. tool/ruby_vm/views/_mjit_compile_insn_body.erb: ditto. tool/ruby_vm/views/_mjit_compile_pc_and_sp.erb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-19mjit_compile.c: reduce sp motion on JITk0kubun
This retries r62655, which was reverted at r63863 for r63763. tool/ruby_vm/views/_mjit_compile_insn.erb: revert the revert. tool/ruby_vm/views/_mjit_compile_insn_body.erb: ditto. tool/ruby_vm/views/_mjit_compile_pc_and_sp.erb: ditto. tool/ruby_vm/views/_mjit_compile_send.erb: ditto. tool/ruby_vm/views/mjit_compile.inc.erb: ditto. tool/ruby_vm/views/_insn_entry.erb: revert half of r63763. The commit was originally reverted since changing pc motion was bad for tracing, but changing sp motion was totally fine. For JIT, I wanna resurrect the sp motion change in r62051. tool/ruby_vm/models/bare_instructions.rb: ditto. insns.def: ditto. vm_insnhelper.c: ditto. vm_insnhelper.h: ditto. * benchmark $ benchmark-driver benchmark.yml --rbenv 'before;after;before --jit;after --jit' --repeat-count 12 -v before: ruby 2.6.0dev (2018-07-19 trunk 63998) [x86_64-linux] after: ruby 2.6.0dev (2018-07-19 add-sp 63998) [x86_64-linux] last_commit=mjit_compile.c: reduce sp motion on JIT before --jit: ruby 2.6.0dev (2018-07-19 trunk 63998) +JIT [x86_64-linux] after --jit: ruby 2.6.0dev (2018-07-19 add-sp 63998) +JIT [x86_64-linux] last_commit=mjit_compile.c: reduce sp motion on JIT Calculating ------------------------------------- before after before --jit after --jit Optcarrot Lan_Master.nes 51.354 50.238 70.010 72.139 fps Comparison: Optcarrot Lan_Master.nes after --jit: 72.1 fps before --jit: 70.0 fps - 1.03x slower before: 51.4 fps - 1.40x slower after: 50.2 fps - 1.44x slower git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-17revert r63988k0kubun
Due to trunk-mjit CI failures: http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1130097 http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1130196 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63991 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-17mjit_compile.c: resurrect local variable stackk0kubun
This optimization was reverted on r63863, but this commit resurrects the optimization to skip some sp motions on JIT execution. tool/ruby_vm/views/_mjit_compile_insn_body.erb: ditto tool/ruby_vm/views/_mjit_compile_insn.erb: ditto insns.def: resurrect handles_frame as handles_stack, which was deleted on r63763. tool/ruby_vm/models/bare_instructions.rb: ditto vm_insnhelper.c: prevent moving sp outside insns.def to allow modifying it by JIT. * Optcarrot benchmark $ benchmark-driver benchmark.yml --rbenv 'before --jit;after --jit' --repeat-count 12 -v before --jit: ruby 2.6.0dev (2018-07-17 trunk 63987) +JIT [x86_64-linux] after --jit: ruby 2.6.0dev (2018-07-17 local-stack 63987) +JIT [x86_64-linux] last_commit=mjit_compile.c: resurrect local variable stack Calculating ------------------------------------- before --jit after --jit Optcarrot Lan_Master.nes 70.518 72.144 fps Comparison: Optcarrot Lan_Master.nes after --jit: 72.1 fps before --jit: 70.5 fps - 1.02x slower git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-07_mjit_compile_insn_body: rollback pc correctlyk0kubun
for catch_except_p case Partially solving Bug#14892 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-05revert r62655 for r63763k0kubun
r63655 was tightly coupled to handle_frames and some assumptions seems to have been broken by r63763. To partially resolve Bug#14892, this reverts the optimization for now. I want to make MJIT CI happy first and then I'll probably retry r63655 by partially reverting r63763 for sp changes. The skipped test is not fixed yet. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-27give up insn attr handles_frameshyouhei
I introduced this mechanism in r62051 to speed things up. Later it was reported that the change causes problems. I searched for workarounds but nothing seemed appropriate. I hereby officially give it up. The idea to move ADD_PC around was a mistake. Fixes [Bug #14809] and [Bug #14834]. Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-25mjit_compile.inc.erb: drop unnecessary variablek0kubun
It never becomes `dispatched: true` with the current code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-17_mjit_compile_send.erb: disable attr_reader inlinek0kubun
for now, which was committed in r63333. Currently trunk's JIT seems to have some wrong behaviors, and this is the most suspicious culprit of them for now. In the future, I may have a strict test environment to detect the cause, but there's no enough time to test this until preview2. So let me revert this and see how it goes after this. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-09_mjit_compile_pc_and_sp: re-commit r63360k0kubun
reverting r63379 (revert of r63360). The cause of error seems to be r63350. See r63382. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-09_mjit_compile_send.erb: revert r63350k0kubun
Revert "_mjit_compile_send.erb: inline recursive call" I reverted r63360 in r63379, but the errors were reproductive from r63350. So I need to revert this. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-09_mjit_compile_pc_and_sp.erb: revert r63360k0kubun
Revert "_mjit_compile_pc_and_sp.erb: make sure no uninitialized" This triggered some `NoMethodError`s which seem to be caused by the commit like: https://travis-ci.org/k0kubun/mjit-test/builds/376416934 I'll add tests and fix it later... git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63379 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-08_mjit_compile_pc_and_sp.erb: make sure no uninitializedk0kubun
area on VM stack to prevent SEGV on GC. GC may mark every value in VM stack. Unfortunately I couldn't write a test for it... So let me explain the situation. SEGV example: https://gist.github.com/k0kubun/c7cea2b5761ffdff29ec79ea1a8f7f91 ``` $ ruby --dump=insns -e 'def oct(num, len); "%0#{len}o" % num; end' == disasm: #<ISeq:oct@-e:1 (1,0)-(1,41)> (catch: FALSE) local table (size: 2, argc: 2 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 2] num@0<Arg> [ 1] len@1<Arg> 0000 putobject "%0" ( 1)[LiCa] 0002 getlocal_WC_0 len@1 0004 dup 0005 checktype T_STRING 0007 branchif 14 0009 dup 0010 opt_send_without_block <callinfo!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>, <callcache> 0013 tostring 0014 putobject "o" 0016 concatstrings 3 0018 getlocal_WC_0 num@0 0020 opt_mod <callinfo!mid:%, argc:1, ARGS_SIMPLE>, <callcache> 0023 leave [Re] ``` Prior to this commit, after arguments are pushed on 0010, stacks were: VM stack: [uninitialized, uninitialized, len] JIT stack: ["%0", len, len] And then, when GC is invoked on 0016, VM stack will be [uninitialized, uninitialized] and those uninitialized values will be marked by GC. With this commit, after arguments are pushed on 0010, stacks will be: VM stack: [len] JIT stack: ["%0", len, len] And VM stack will be [] on 0016. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-07_mjit_compile_send.erb: inline recursive callk0kubun
mjit_compile.c: propagate funcname to compile_insn test_jit.rb: add test covering this behavior * Benchmark ``` require 'benchmark_driver' Benchmark.driver(runner: :time, repeat_count: 4) do |x| x.prelude %{ def fib(x) return x if x == 0 || x == 1 fib(x-1) + fib(x-2) end } x.report 'fib(40)' x.loop_count 1 x.rbenv( 'before,--jit', 'before', 'after,--jit', 'after', ) x.verbose end ``` ``` before,--jit: ruby 2.6.0dev (2018-05-08 trunk 63349) +JIT [x86_64-linux] before: ruby 2.6.0dev (2018-05-08 trunk 63349) [x86_64-linux] after,--jit: ruby 2.6.0dev (2018-05-08 trunk 63349) +JIT [x86_64-linux] last_commit=_mjit_compile_send.erb: inline recursive call after: ruby 2.6.0dev (2018-05-08 trunk 63349) [x86_64-linux] last_commit=_mjit_compile_send.erb: inline recursive call Calculating ------------------------------------- before,--jit before after,--jit after fib(40) 2.886 8.685 2.562 8.800 s - 1.000 times Comparison: fib(40) after,--jit: 2.6 s before,--jit: 2.9 s - 1.13x slower before: 8.7 s - 3.39x slower after: 8.8 s - 3.44x slower ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-03_mjit_compile_send.erb: retry inlining attr_readerk0kubun
This reverts r63249 (revert r63212) and fixes a bug in it. The test to prevent the bug is added as well. vm_insnhelper.c: add `index` argument to vm_getivar. The argument is created so that MJIT can pass the value of `cc->aux.index` on compilation time. The cache invalidation in _mjit_compile_send_guard.erb is only working for the cache value on compilation time. Note: As `index` is always passed as constant and it's force-inlined, the performance of `vm_getivar` won't be degraded in VM. _mjit_compile_send_guard.erb: New. Used to invalidate inlined values of cc. common.mk: update dependencies for _mjit_compile_send_guard.erb git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-03mjit_compile.c: verify stack size agreementk0kubun
between branches. mjit_compile.inc.erb: move the compiled_for_pos reference to mjit_compile.c git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-03mjit_compile.inc.erb: verify stack consistencyk0kubun
on JIT compilation. r63092 was risky without this check. mjit_compile.c: update comment about stack consistency check git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-02tool/ruby_vm/views/_insn_name_info.erb: Auto-detect the longest insn namemame
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63318 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-29_mjit_compile_send.erb: fix pointer conversion warningk0kubun
/var/folders/b0/9hgj_tyx10zgkcbyx3_j2dlr0000gn/T//_ruby_mjit_p72619u0.c:37:58: warning: incompatible integer to pointer conversion passing 'long' to parameter of type 'const struct rb_call_info *' [-Wint-conversion] vm_caller_setup_arg_block(ec, reg_cfp, &calling, 0x7ff6b2e10ca0, 0x7ff6b3847108, FALSE); ^~~~~~~~~~~~~~ /Users/kokubun/.rbenv/versions/ruby-svn/include/ruby-2.6.0/x86_64-darwin16/rb_mjit_min_header-2.6.0.h:15613:66: note: passing argument to parameter 'ci' here struct rb_calling_info *calling, const struct rb_call_info *ci, rb_iseq_t *blockiseq, const int is_super) ^ /var/folders/b0/9hgj_tyx10zgkcbyx3_j2dlr0000gn/T//_ruby_mjit_p72619u0.c:37:74: warning: incompatible integer to pointer conversion passing 'long' to parameter of type 'rb_iseq_t *' (aka 'struct rb_iseq_struct *') [-Wint-conversion] vm_caller_setup_arg_block(ec, reg_cfp, &calling, 0x7ff6b2e10ca0, 0x7ff6b3847108, FALSE); ^~~~~~~~~~~~~~ /Users/kokubun/.rbenv/versions/ruby-svn/include/ruby-2.6.0/x86_64-darwin16/rb_mjit_min_header-2.6.0.h:15613:81: note: passing argument to parameter 'blockiseq' here struct rb_calling_info *calling, const struct rb_call_info *ci, rb_iseq_t *blockiseq, const int is_super) ^ 2 warnings generated. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-23revert r63212k0kubun
except test_jit.rb. In some situations, this generates a wrong code. I'll add a test for it later but let me revert this to make it work for now. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-20_mjit_compile_send.erb: inline attr_reader callk0kubun
_mjit_compile_send_guard.erb: carve out the shared logic to invalidate inlined method call common.mk: update dependency for this change test_jit.rb: add test for attr_reader optimization * Benchmark ``` require 'benchmark_driver' Benchmark.driver do |x| x.prelude %{ class C attr_reader :a def initialize @a = 1 end end o = C.new def l o i = 0 while i < 1000000 o.a i += 1 end end } x.report 'aread', %{ l o } x.loop_count 1000 x.rbenv 'before', 'before,--jit', 'after,--jit' x.verbose end ``` ``` before: ruby 2.6.0dev (2018-04-20 trunk 63211) [x86_64-linux] before,--jit: ruby 2.6.0dev (2018-04-20 trunk 63211) +JIT [x86_64-linux] after,--jit: ruby 2.6.0dev (2018-04-20 trunk 63211) +JIT [x86_64-linux] last_commit=_mjit_compile_send.erb: inline attr_reader call Calculating ------------------------------------- before before,--jit after,--jit aread 54.597 122.894 218.574 i/s - 1.000k times in 18.316102s 8.137089s 4.575106s Comparison: aread after,--jit: 218.6 i/s before,--jit: 122.9 i/s - 1.78x slower before: 54.6 i/s - 4.00x slower ``` * Optcarrot A little made faster? fps: 71.35 -> 72.11 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-19_mjit_compile_send.erb: simplify control flowk0kubun
to introduce additional optimization for another `cc->me->def->type` later. I carved out the `cc->me->def->type == VM_METHOD_TYPE_ISEQ` part because I wanted to check other types as well. mjit_compile.c: drop get_iseq_if_available and define simplified version of it, has_valid_method_type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-06tool/ruby_vm/scripts/insns2vm.rb: fix typo in r62064stomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-19Reverting r62775, this should fix i686 buildstenderlove
We need to mark default values for kwarg methods. This also fixes Bootsnap. IBF iseq loading needed to mark iseqs as "having markable objects". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62851 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-16Revert "Add direct marking on iseq operands"naruse
This reverts commit r62706. It causes SEGV on i686-linux (debian) and armv7l-linux-eabihf: http://www.rubyist.net/~akr/chkbuild/debian/ruby-trunk/log/20180309T204300Z.diff.html.gz http://rubyci.s3.amazonaws.com/scw-9d6766/ruby-trunk/log/20180309T211706Z.diff.html.gz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-09Add direct marking on iseq operandstenderlove
Directly marking iseq operands allows us to eliminate the "mark array" stored on ISEQ objects, which will reduce the amount of memory ISEQ objects consume. This patch changes the iseq mark function to: * Directly marks ISEQ operands * Iterate over and mark child ISEQs It also introduces two flags on the ISEQ object. In order to mark instruction operands, we have to disassemble the instructions and find the instruction parameters and types. Instructions may also be translated to jump addresses. Instruction sequences may get marked by the GC *while* they're mid flight (being compiled). The `ISEQ_TRANSLATED` flag is used to indicate whether or not the instructions have been translated to jump addresses so that when we decode the instructions we know whether or not we need to go from jump location back to original instruction or not. Not all ISEQ objects have any markable objects embedded in their instructions. We can detect whether or not an ISEQ has markable objects in the instructions at compile time. If the instructions contain markable objects, we set a flag `ISEQ_MARKABLE_ISEQ` on the ISEQ object. This means that during the mark phase, we can skip decompilation if the flag is *not* set. In other words, we can avoid decompilation of we know in advance there is nothing to mark. `once` instructions have an operand that contains the result of a one-time compilation of a regex. Before this patch, that operand was called an "inline cache", even though the struct was actually an "inline storage". This patch changes the operand to be an "inline storage" so that we can differentiate between caches that need marking (the inline storage) and caches that don't need marking (inline cache). [ruby-core:84909] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-06_mjit_compile_pc_and_sp.erb: skip moving pck0kubun
on !body->catch_except_p. We need to move pc only when JIT execution is canceled if the frame does not catch an exception. _mjit_compile_insn.erb: lazily move pc for such optimized case _mjit_compile_insn_body.erb: ditto _mjit_compile_send.erb: ditto * Optcarrot benchmark (--jit) Before: 65.31 fps After: 67.82 fps git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-04mjit_compile.c: use local variables for stackk0kubun
if catch_except_p is FALSE. If catch_except_p is TRUE, stack values should be on VM's stack when exception is thrown and the JIT-ed frame is re-executed by VM's exception handler. If it's FALSE, the JIT-ed frame won't be re-executed and don't need to keep values on VM's stack. Using local variables allows us to reduce cfp->sp motion. Moving cfp->sp is needed only for insns whose handles_frame? is false. So it improves performance. _mjit_compile_insn.erb: Prepare `stack_size` variable for GET_SP, STACK_ADDR_FROM_TOP, TOPN macros. Share pc and sp motion partial view. Use cancel handler created in mjit_compile.c. _mjit_compile_send.erb: ditto. Also, when iseq->body->catch_except_p is TRUE, this stops to call mjit_exec directly. I described the reason in vm_insnhelper.h's comment for EXEC_EC_CFP. _mjit_compile_pc_and_sp.erb: Shared logic for moving sp and pc. As you can see from thsi file, when status->local_stack_p is TRUE and insn.handles_frame? is false, moving sp is skipped. But if insn.handles_frame? is true, values should be rolled back to VM's stack. common.mk: add dependency for the file _mjit_compile_insn_body.erb: Set sp value before canceling JIT on DISPATCH_ORIGINAL_INSN. Replace GET_SP, STACK_ADDR_FROM_TOP, TOPN macros for the case ocal_stack_p is TRUE and insn.handles_frame? is false. In that case, values are not available on VM's stack and those macros should be replaced. mjit_compile.inc.erb: updated comments of macros which are supported by JIT compiler. All references to `cfp->sp` should be replaced and thus INC_SP, SET_SV, PUSH are no longer supported for now, because they are not used now. vm_exec.h: moved EXEC_EC_CFP definition to vm_insnhelper.h because it's tighly coupled to CALL_METHOD. vm_insnhelper.h: Have revised EXEC_EC_CFP definition moved from vm_exec.h. Now it triggers mjit_exec for VM, and has the guard for catch_except_p on JIT-ed code. See comments for details. CALL_METHOD delegates triggering mjit_exec to EXEC_EC_CFP. insns.def: Stopped using EXEC_EC_CFP for the case we don't want to trigger mjit_exec. Those insns (defineclass, opt_call_c_function) are not supported by JIT and it's safe to use RESTORE_REGS(), NEXT_INSN(). expandarray is changed to pass GET_SP() to replace the macro in _mjit_compile_insn_body.erb. vm_insnhelper.c: change to take sp for the above reason. [close https://github.com/ruby/ruby/pull/1828] This patch resurrects the performance which was attached in [Feature #14235]. * Benchmark Optcarrot (with configuration for benchmark_driver.gem) https://github.com/benchmark-driver/optcarrot $ benchmark-driver benchmark.yml --verbose 1 --rbenv 'before;before+JIT::before,--jit;after;after+JIT::after,--jit' --repeat-count 10 before: ruby 2.6.0dev (2018-03-04 trunk 62652) [x86_64-linux] before+JIT: ruby 2.6.0dev (2018-03-04 trunk 62652) +JIT [x86_64-linux] after: ruby 2.6.0dev (2018-03-04 local-variable.. 62652) [x86_64-linux] last_commit=mjit_compile.c: use local variables for stack after+JIT: ruby 2.6.0dev (2018-03-04 local-variable.. 62652) +JIT [x86_64-linux] last_commit=mjit_compile.c: use local variables for stack Calculating ------------------------------------- before before+JIT after after+JIT optcarrot 53.552 59.680 53.697 63.358 fps Comparison: optcarrot after+JIT: 63.4 fps before+JIT: 59.7 fps - 1.06x slower after: 53.7 fps - 1.18x slower before: 53.6 fps - 1.18x slower git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-03vm.c: add mjit_enable_p flagk0kubun
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-02-27Refactor ERB version checking for keyword argumentsk0kubun
Improving code like r62590. See r62529 for details. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-26tool/ruby_vm/helpers/dumper.rb: check ERB versionk0kubun
I could not `make` trunk (62585) without this patch. ``` $ make -j4 && make install BASERUBY = /home/pocke/.rbenv/shims/ruby --disable=gems CC = gcc LD = ld LDSHARED = gcc -shared CFLAGS = -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Werror=implicit-int -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=implicit-function-declaration -Werror=deprecated-declarations -Werror=misleading-indentation -Wno-overlength-strings -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wmissing-noreturn -Wimplicit-fallthrough=0 -Werror=duplicated-cond -Werror=restrict -std=gnu99 -fPIC XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -DRUBY_DEVEL=1 -fvisibility=hidden -fexcess-precision=standard -DRUBY_EXPORT CPPFLAGS = -I. -I.ext/include/x86_64-linux -I./include -I. -I./enc/unicode/10.0.0 DLDFLAGS = -Wl,--compress-debug-sections=zlib -Wl,-soname,libruby.so.2.6 -fstack-protector SOLIBS = -lpthread -lgmp -ldl -lcrypt -lm LANG = en_GB.UTF-8 LC_ALL = LC_CTYPE = gcc (GCC) 7.3.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. generating opt_sc.inc generating optunifs.inc generating insns.inc generating insns_info.inc Traceback (most recent call last): 6: from ./tool/insns2vm.rb:9:in `<main>' 5: from ./tool/insns2vm.rb:9:in `each' 4: from ./tool/insns2vm.rb:10:in `block in <main>' 3: from /home/pocke/ghq/github.com/ruby/ruby/tool/ruby_vm/helpers/dumper.rb:98:in `generate' 2: from /home/pocke/ghq/github.com/ruby/ruby/tool/ruby_vm/helpers/dumper.rb:76:in `do_render' 1: from /home/pocke/.rbenv/versions/trunk/lib/ruby/2.6.0/erb.rb:873:in `result' /home/pocke/.rbenv/versions/trunk/lib/ruby/2.6.0/erb.rb:869:in `block in result': no implicit conversion of Hash into Integer (TypeError) make: *** [Makefile:534: opt_sc.inc] Error 1 make: *** Waiting for unfinished jobs.... Traceback (most recent call last): 6: from ./tool/insns2vm.rb:9:in `<main>' 5: from ./tool/insns2vm.rb:9:in `each' 4: from ./tool/insns2vm.rb:10:in `block in <main>' 3: from /home/pocke/ghq/github.com/ruby/ruby/tool/ruby_vm/helpers/dumper.rb:98:in `generate' 2: from /home/pocke/ghq/github.com/ruby/ruby/tool/ruby_vm/helpers/dumper.rb:76:in `do_render' 1: from /home/pocke/.rbenv/versions/trunk/lib/ruby/2.6.0/erb.rb:873:in `result' /home/pocke/.rbenv/versions/trunk/lib/ruby/2.6.0/erb.rb:869:in `block in result': no implicit conversion of Hash into Integer (TypeError) make: *** [Makefile:534: optunifs.inc] Error 1 Traceback (most recent call last): 6: from ./tool/insns2vm.rb:9:in `<main>' 5: from ./tool/insns2vm.rb:9:in `each' 4: from ./tool/insns2vm.rb:10:in `block in <main>' 3: from /home/pocke/ghq/github.com/ruby/ruby/tool/ruby_vm/helpers/dumper.rb:98:in `generate' 2: from /home/pocke/ghq/github.com/ruby/ruby/tool/ruby_vm/helpers/dumper.rb:76:in `do_render' 1: from /home/pocke/.rbenv/versions/trunk/lib/ruby/2.6.0/erb.rb:873:in `result' /home/pocke/.rbenv/versions/trunk/lib/ruby/2.6.0/erb.rb:869:in `block in result': no implicit conversion of Hash into Integer (TypeError) Traceback (most recent call last): 6: from ./tool/insns2vm.rb:9:in `<main>' 5: from ./tool/insns2vm.rb:9:in `each' 4: from ./tool/insns2vm.rb:10:in `block in <main>' 3: from /home/pocke/ghq/github.com/ruby/ruby/tool/ruby_vm/helpers/dumper.rb:98:in `generate' 2: from /home/pocke/ghq/github.com/ruby/ruby/tool/ruby_vm/helpers/dumper.rb:76:in `do_render' 1: from /home/pocke/.rbenv/versions/trunk/lib/ruby/2.6.0/erb.rb:873:in `result' /home/pocke/.rbenv/versions/trunk/lib/ruby/2.6.0/erb.rb:869:in `block in result': no implicit conversion of Hash into Integer (TypeError) make: *** [Makefile:534: insns.inc] Error 1 make: *** [Makefile:534: insns_info.inc] Error 1 ``` I guess this issue is same as https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/62531 So I applied the same change to tool/ruby_vm/helpers/dumper.rb also. close https://github.com/ruby/ruby/pull/1826 Co-authored-by: Masataka Pocke Kuwabara <kuwabara@pocke.me> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-22erb.rb: deprecate safe_level of ERB.newk0kubun
Also, as it's in the middle of the list of 4 arguments, 3rd and 4th arguments (trim_mode, eoutvar) are changed to keyword arguments. Old ways to specify arguments are deprecated and warned now. bin/erb: deprecate -S option. We'll remove all of deprecated ones at Ruby 2.7+. enc/make_encmake.rb: stopped using deprecated interface ext/etc/mkconstants.rb: ditto ext/socket/mkconstants.rb: ditto sample/ripper/ruby2html.rb: ditto spec/ruby/library/erb/defmethod/def_erb_method_spec.rb: ditto spec/ruby/library/erb/new_spec.rb: ditto test/erb/test_erb.rb: ditto test/erb/test_erb_command.rb: ditto tool/generic_erb.rb: ditto tool/ruby_vm/helpers/dumper.rb: ditto tool/transcode-tblgen.rb: ditto lib/rdoc/erbio.rb: ditto lib/rdoc/generator/darkfish.rb: ditto [Feature #14256] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62529 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-13mjit_compile.inc.erb: replace opt_key insnk0kubun
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