summaryrefslogtreecommitdiff
path: root/vm_insnhelper.c
AgeCommit message (Collapse)Author
2019-08-05merge revision(s) 5e018214e7435030727a97ac49db038d96438e74: [Backport #15720]nagachika
Fix SystemStackError when calling a method in an unused refinement Fixes [Bug #15720] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67729 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-25merge revision(s) 66538:naruse
vm_insnhelper.c: use COLDFUNC COLDFUNC is introduced in r66228. Use it for pre-existing __attribute__((__cold__)) usages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@66544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-18* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66437 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-18should use defined_class.ko1
* vm_insnhelper.c (vm_call_method_each_type): we should use me->defined_class instead of me->owner because me->owner doesn't has correct ancestors list. [Bug #15427] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66436 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06Return same ISeq object for one src.ko1
* iseq.c: before this patch, RubyVM::InstructionSequence.of(src) (ISeq in short) returns different ISeq (wrapper) objects point to one ISeq internal object. This patch changes this behavior to cache created ISeq (wrapper) objects and return same ISeq object for an internal ISeq object. * iseq.h (ISEQ_EXECUTABLE_P): introduced to check executable ISeq objects. * iseq.h (ISEQ_COMPILE_DATA_ALLOC): reordr setting flag line to avoid ISEQ_USE_COMPILE_DATA but compiled_data == NULL case. * vm_core.h (rb_iseq_t): introduce `rb_iseq_t::wrapper` and `rb_iseq_t::aux::exec`. Move `rb_iseq_t::local_hooks` to `rb_iseq_t::aux::exec::local_hooks`. * test/ruby/test_iseq.rb: add ISeq.of() tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66246 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26Support targetting TracePoint [Feature #15289]ko1
* vm_trace.c (rb_tracepoint_enable_for_target): support targetting TracePoint. [Feature #15289] Tragetting TracePoint is only enabled on specified method, proc and so on, example: `tp.enable(target: code)`. `code` should be consisted of InstructionSeuqnece (iseq) (RubyVM::InstructionSeuqnece.of(code) should not return nil) If code is a tree of iseq, TracePoint is enabled on all of iseqs in a tree. Enabled tragetting TracePoints can not enabled again with and without target. * vm_core.h (rb_iseq_t): introduce `rb_iseq_t::local_hooks` to store local hooks. `rb_iseq_t::aux::trace_events` is renamed to `global_trace_events` to contrast with `local_hooks`. * vm_core.h (rb_hook_list_t): add `rb_hook_list_t::running` to represent how many Threads/Fibers are used this list. If this field is 0, nobody using this hooks and we can delete it. This is why we can remove code from cont.c. * vm_core.h (rb_vm_t): because of above change, we can eliminate `rb_vm_t::trace_running` field. Also renamed from `rb_vm_t::event_hooks` to `global_hooks`. * vm_core.h, vm.c (ruby_vm_event_enabled_global_flags): renamed from `ruby_vm_event_enabled_flags. * vm_core.h, vm.c (ruby_vm_event_local_num): added to count enabled targetting TracePoints. * vm_core.h, vm_trace.c (rb_exec_event_hooks): accepts hook list. * vm_core.h (rb_vm_global_hooks): added for convinience. * method.h (rb_method_bmethod_t): added to maintain Proc and `rb_hook_list_t` for bmethod (defined by define_method). * prelude.rb (TracePoint#enable): extracet a keyword parameter (because it is easy than writing in C). It calls `TracePoint#__enable` internal method written in C. * vm_insnhelper.c (vm_trace): check also iseq->local_hooks. * vm.c (invoke_bmethod): check def->body.bmethod.hooks. * vm.c (hook_before_rewind): check iseq->local_hooks and def->body.bmethod.hooks before rewind by exception. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20vm_insnhelper.c: fix indent [ci skip]shyouhei
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20vm_insnhelper.c: recv -1 + 3 overflowsshyouhei
Here, recv can be INT2FIX(-1), which is 0xFFFF_FFFFul. INT2FIX(1) is 3ul. So `recv - 1 + INT2FIX(1)` is: recv 0xFFFF_FFFFul recv-1 0xFFFF_FFFEul (note: unsigned) recv-1+INT2FIX(1) 0x0000_0001ul Here is the overflow. Given recv is a Fixnum, it can never be 0xFFFF_FFFD. 0xFFFF_FFFF is the only value that can overflow this way, so special-casing this value should just suffice. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-13suppress integer overflow warningsshyouhei
* random.c: annotate rb_hash_start with NO_SANITIZE (seed.key.hash + h overflows and that seems intentional) * bignum.c: avoid (size_t)-- * cont.c: ditto * util.c: ditto * vm_insnhelper.c: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-12vm_insnhelper.c: avoid nevative spshyouhei
space_size can be zero here, under the following script. We would better bail out before bptr calculation. % ./miniruby --dump=i -e '* = nil' == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,7)> (catch: FALSE) 0000 putnil ( 1)[Li] 0001 dup 0002 expandarray 0, 0 0005 leave git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-12* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-12vm_insnhelper.c: avoid division by zeroshyouhei
same as r65642. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-09* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-09There is a path to use bmethod with ifunc.ko1
* vm_insnhelper.c (vm_yield_with_cfunc): use passed me as bmethod. We also need to set `VM_FRAME_FLAG_BMETHOD` if needed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-09fix passing wrong `passed_bmethod_me`.ko1
* vm_core.h: remove `rb_execution_context_t::passed_bmethod_me` and fix functions to pass the `me` directly. `passed_bmethod_me` was used to make bmethod (methods defined by `defined_method`). `rb_vm_invoke_bmethod` invoke `Proc` with `me` information as method frame (`lambda` frame, actually). If the proc call is not bmethod call, `passed_bmethod_me` should be NULL. However, there is a bug which passes wrong `me` for normal block call. http://ci.rvm.jp/results/trunk-asserts@silicon-docker/1449470 This is because wrong `me` was remained in `passed_bmethod_me` (and used incorrectly it after collected by GC). We need to clear `passed_bmethod_me` just after bmethod call, but clearing is not enough. To solve this issue, I removed `passed_bmethod_me` and pass `me` information as a function parameter of `rb_vm_invoke_bmethod`, `invoke_block_from_c_proc` and `invoke_iseq_block_from_c` in vm.c. * vm.c (invoke_iseq_block_from_c): the number of parameters is too long so that I try to specify `ALWAYS_INLINE`. * vm.c (invoke_block_from_c_proc): ditto. * vm_insnhelper.c (vm_yield_with_cfunc): now there are no pathes to use bmethod here. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30* remove trailing spaces, expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30support theap for T_HASH. [Feature #14989]ko1
* hash.c, internal.h: support theap for small Hash. Introduce RHASH_ARRAY (li_table) besides st_table and small Hash (<=8 entries) are managed by an array data structure. This array data can be managed by theap. If st_table is needed, then converting array data to st_table data. For st_table using code, we prepare "stlike" APIs which accepts hash value and are very similar to st_ APIs. This work is based on the GSoC achievement by tacinight <tacingiht@gmail.com> and refined by ko1. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30introduce TransientHeap. [Bug #14858]ko1
* transient_heap.c, transient_heap.h: implement TransientHeap (theap). theap is designed for Ruby's object system. theap is like Eden heap on generational GC terminology. theap allocation is very fast because it only needs to bump up pointer and deallocation is also fast because we don't do anything. However we need to evacuate (Copy GC terminology) if theap memory is long-lived. Evacuation logic is needed for each type. See [Bug #14858] for details. * array.c: Now, theap for T_ARRAY is supported. ary_heap_alloc() tries to allocate memory area from theap. If this trial sccesses, this array has theap ptr and RARRAY_TRANSIENT_FLAG is turned on. We don't need to free theap ptr. * ruby.h: RARRAY_CONST_PTR() returns malloc'ed memory area. It menas that if ary is allocated at theap, force evacuation to malloc'ed memory. It makes programs slow, but very compatible with current code because theap memory can be evacuated (theap memory will be recycled). If you want to get transient heap ptr, use RARRAY_CONST_PTR_TRANSIENT() instead of RARRAY_CONST_PTR(). If you can't understand when evacuation will occur, use RARRAY_CONST_PTR(). (re-commit of r65444) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30revert r65444 and r65446 because of commit missko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30introduce TransientHeap. [Bug #14858]ko1
* transient_heap.c, transient_heap.h: implement TransientHeap (theap). theap is designed for Ruby's object system. theap is like Eden heap on generational GC terminology. theap allocation is very fast because it only needs to bump up pointer and deallocation is also fast because we don't do anything. However we need to evacuate (Copy GC terminology) if theap memory is long-lived. Evacuation logic is needed for each type. See [Bug #14858] for details. * array.c: Now, theap for T_ARRAY is supported. ary_heap_alloc() tries to allocate memory area from theap. If this trial sccesses, this array has theap ptr and RARRAY_TRANSIENT_FLAG is turned on. We don't need to free theap ptr. * ruby.h: RARRAY_CONST_PTR() returns malloc'ed memory area. It menas that if ary is allocated at theap, force evacuation to malloc'ed memory. It makes programs slow, but very compatible with current code because theap memory can be evacuated (theap memory will be recycled). If you want to get transient heap ptr, use RARRAY_CONST_PTR_TRANSIENT() instead of RARRAY_CONST_PTR(). If you can't understand when evacuation will occur, use RARRAY_CONST_PTR(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30_mjit_compile_send.erb: do not inline tailcall ISeqk0kubun
because it's not supported by this file. Also, shared `def_iseq_ptr` instead of copying the main definition of it. vm_core.h: moved `def_iseq_ptr` to this place. added `inline` to avoid compiler warnings since it's not used in some files including vm_core.h. vm_insnhelper.c: moved `def_iseq_ptr` to vm_core.h. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65226 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20Remove tracecoverage instructionsmame
The instructions were used only for branch coverage. Instead, it now uses a trace framework [Feature #14104]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65223 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20revert r65213 and r65215k0kubun
as we didn't agree on the actual implementation yet git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20vm_insnhelper.c: never cache setinstancevariable twicek0kubun
same as r65213 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65215 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20vm_insnhelper.c: never cache getinstancevariable twicek0kubun
We have several options to ensure there's no race condition between main thread and MJIT thead about IC reference: 1) Give up caching ivar for multiple classes (or multiple versions of the same class) in the same getinstancevariable (This commit's approach) 2) Allocate new inline cache every time Other ideas we could think of couldn't eliminate possibilities of race condition. In 2, it's memory allocation would be slow and it may trigger JIT cancellation frequently. So 1 would be fast for both VM and JIT situations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-19check before access.ko1
* vm_insnhelper.c (vm_push_frame): validate prev_frame because prev_frame can be the end of frame. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-17* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-17Remove the level information from throw instructionmame
It is no longer used. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-14vm_opts.h: share USE_IC_FOR_IVAR as OPT_IC_FOR_IVARk0kubun
with mjit_compile.c (tool/ruby_vm/views/_mjit_compile_getivar.erb). mjit_compile.c: ditto tool/ruby_vm/views/_mjit_compile_getivar.erb: ditto vm_opts.h: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-14vm_insnhelper.c: remove obsoleted comment [ci skip]k0kubun
see also: r65061 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65072 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-13vm_insinhelper.c: prefer using inlinable functionk0kubun
No major performance impact, but just in case for some platform that matters. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-13vm_insnhelper.c: finish reverting r63333k0kubun
That optimization is already reverted and we're not retrying the optimization soon. Let me simplify the code of vm_getivar. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65061 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-07mjit.h: introduce MJIT_STATIC for full mswin JIT supportk0kubun
This change resolves most of major remaining MJIT bugs on mswin. Since Visual Studio doesn't support generating pre-processed code preserving macros, we can't use transform_mjit_header approach for mswin. So we need to transform MJIT header using macro like this. vm.c: use MJIT_STATIC for non-static functions that exist on MJIT header and cause conflict on link. vm_insnhelper.c: ditto test_jit.rb: remove many skips for mswin. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-01remove old VM profile counters.ko1
* vm_insnhelper.c: remove `vm_profile_counter` because it is replaced with debug_counters. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64890 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-28add debug counters more.ko1
* debug_counter.h: add debug counters to count frame state transitions: * frame_R2R: Ruby frame to Ruby frame * frame_R2C: Ruby frame to C frame * frame_C2C: C frame to C frame * frame_C2R: C frame to Ruby frame * vm_insnhelper.c (vm_push_frame): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-28add debug counters more.ko1
* debug_counter.h: add the following counters. * frame_push: control frame counts (total counts). * frame_push_*: control frame counts per every frame type. * obj_*: add free'ed counts for each type. * gc.c: ditto. * vm_insnhelper.c (vm_push_frame): ditto. * debug_counter.c (rb_debug_counter_show_results): widen counts field to show >10G numbers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64867 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-26revert r64847, r64846 and r64839k0kubun
because r64849 seems to fix issues which we were confused about. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-26revert r64838 and r64839k0kubun
because some build failures persisted git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-25Revert "Revert r64824 to fix build failure on AppVeyor"k0kubun
This reverts commit r64829. I'll prepare another temporary fix, but I'll separately commit that to make it easier to revert that later. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-25Revert r64824 to fix build failure on AppVeyork0kubun
AppVeyor msys2/MinGW build started to fail like: https://ci.appveyor.com/project/ruby/ruby/build/9722/job/b94kixi004klmye3 Until I can investigate that, I revert this for now. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-24insns.def: optimize & and | of Integer [experimental]k0kubun
not optimizing Array#& and Array#| because vm_insnhelper.c can't easily inline it (large amount of array.c code would be needed in vm_insnhelper.c) and the method body is a little complicated compared to Integer's ones. So I thought only Integer#& and Integer#| have a significant impact, and eliminating unnecessary branches would contribute to JIT's performance. vm_insnhelper.c: ditto tool/transform_mjit_header.rb: make sure these instructions are inlined on JIT. compile.c: compile vm_opt_and and vm_opt_or. id.def: define id for them to be used in compile.c and vm*.c vm.c: track redefinition of Integer#& and Integer#| vm_core.h: allow detecting redefinition of & and | test/ruby/test_jit.rb: test new insns test/ruby/test_optimization.rb: ditto * Optcarrot benchmark This is a kind of experimental thing but I'm committing this since the performance impact is significant especially on Optcarrot with JIT. $ benchmark-driver benchmark.yml --rbenv 'before::before --disable-gems;before+JIT::before --disable-gems --jit;after::after --disable-gems;after+JIT::after --disable-gems --jit' -v --repeat-count 24 before: ruby 2.6.0dev (2018-09-24 trunk 64821) [x86_64-linux] before+JIT: ruby 2.6.0dev (2018-09-24 trunk 64821) +JIT [x86_64-linux] after: ruby 2.6.0dev (2018-09-24 opt_and 64821) [x86_64-linux] last_commit=opt_or after+JIT: ruby 2.6.0dev (2018-09-24 opt_and 64821) +JIT [x86_64-linux] last_commit=opt_or Calculating ------------------------------------- before before+JIT after after+JIT Optcarrot Lan_Master.nes 51.460 66.315 53.023 71.173 fps Comparison: Optcarrot Lan_Master.nes after+JIT: 71.2 fps before+JIT: 66.3 fps - 1.07x slower after: 53.0 fps - 1.34x slower before: 51.5 fps - 1.38x slower [close https://github.com/ruby/ruby/pull/1963] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-24_mjit_compile_send.erb: refactor code to setup iseqk0kubun
by sharing vm_call_iseq_setup_normal. This is a retry of r64280. vm_insnhelper.c: Remove unused argument `ci` and pass `me` instead of `cc` to share this with JIT. Declare this with ALWAYS_INLINE to make sure this function is inlined in JIT. tool/mk_call_iseq_optimized.rb: deal with the interface change of vm_call_iseq_setup_normal. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64820 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-21* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-21Remove -Wno-parentheses flag.nobu
[Fix GH-1958] From: Jun Aruga <jaruga@redhat.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e