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

536 Коммитов

Автор SHA1 Сообщение Дата
nobu 5d988300b2 intern instruction
* insns.def (intern): new instruction to turn string into symbol.
  opt_call_c_function can not dump.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59951 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-18 05:16:37 +00:00
nobu df33c063fc literal symbol by intern
* compile.c (iseq_compile_each0): literal symbol should not be
  affected by redefinition of String#intern method.

* vm_insnhelper.c (rb_vm_str_intern): intern a string into a
  symbol directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59946 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-17 09:28:58 +00:00
ko1 b53b37758d store ec instead of thread in rb_context_t.
* cont.c (rb_context_t): introduce saved_ec instaad of saved_thread.
  We only need to transfer ec data (not all of thread data).

  Introduce `thread_value` field to point creation thread.
  To acccess this field, `cont_thread_value()` is introduced.

* vm.c (rb_execution_context_mark): remove `static` and use it
  from cont.c (use this function instead of `rb_thread_mark`).

* vm_insnhelper.c (rb_vm_push_frame): accept ec instead of th.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-10 19:00:08 +00:00
rhe b9801bb8b2 vm_insnhelper.c: fix opt_regexpmatch2 instruction
A fix-up for r58390 ("split insns.def into functions", 2017-04-18) which
accidentally swapped the arguments.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-03 12:35:25 +00:00
nobu 066e9a8b4a signal.c: fatal stack
* signal.c (check_stack_overflow): raise fatal when the last tag
  is in danger zone.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-22 02:46:16 +00:00
nobu b54f535506 vm_core.h: ruby_error_stackfatal
* vm_core.h (ruby_special_exceptions): rename sysstack_gc as
  stackfatal.

* eval.c (Init_eval): modified the message for stackfatal error as
  "critical region".

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-21 06:46:46 +00:00
nobu e3c42f53fb vm_insnhelper.c: vm_cfp_consistent_p
* vm_insnhelper.c (vm_cfp_consistent_p): extracted the conditions
  for cfp consistency.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-18 12:44:30 +00:00
nobu a7bccb20f8 vm_insnhelper.c: raise ruby_error_sysstack_gc
* vm_insnhelper.c (rb_threadptr_stack_overflow): rb_fatal is not
  available during GC.  raise the preallocated fatal error.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59618 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-18 12:17:59 +00:00
nobu 0afc8db914 vm_insnhelper.c: cfp error at stack overflow
* vm_insnhelper.c (threadptr_stack_overflow): set stack overflow
  flag until handling execptions, to get rid of cfp consistency
  error when exec tag was rewound.  [ruby-core:80618] [Bug #13412]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-16 07:18:45 +00:00
ko1 6881279149 rename rb_execution_context_t::stack(_size) to vm_stack(_size).
* vm_core.h: Ruby processes run with two stacks, a machine stack and a
  VM stack. To make it clear, this fix renames
  rb_execution_context_t::stack(_size) to vm_stack(_size).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59563 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-10 04:55:12 +00:00
nobu 26aed9c577 splat keyword hash
* compile.c (compile_array_keyword_arg): set keyword splat flag if
  explicitly splatted.  [ruby-core:68124] [Bug #10856]

* vm_args.c (setup_parameters_complex): try keyword hash splat if
  given.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-05 06:58:44 +00:00
nobu 3449d4fa2d visibility of inherited method
* vm_insnhelper.c (vm_call_method_each_type): honor the original
  visibility of inherited methods when a refinement is defined but
  not activated.  [ruby-core:82209] [Bug #13776]

Author:    Mon_Ouie (Mon ouïe) <mon.ouie@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-29 12:42:42 +00:00
nobu 97c977debf adjust indent [ci skip]
* vm_insnhelper.c (vm_call_method_each_type): adjust indent of a
  block in switch.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-29 12:42:41 +00:00
nobu 3bf4c46bb8 vm_insnhelper.c: dump iseq
* vm_insnhelper.c (vm_stack_consistency_error): raise a fatal
  error with the disassembled instruction sequence, in the
  development version, instead of very rarely useful rb_bug in
  such case.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59211 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-30 01:56:53 +00:00
ko1 8dd9c12c58 move fields to ec.
* vm_core.h (rb_thread.h): move errinfo and trace_arg to
  rb_execution_context_t.

* cont.c (fiber_switch, rb_cont_call): do not restore "trace_arg" here.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-28 14:27:49 +00:00
ko1 957d1ccdf9 move fields to ec.
* vm_core.h (rb_thread_t): move root_lep, root_svar and ensure_list
  to rb_execution_context_t.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-28 06:09:06 +00:00
nobu 1474acff3c fix return in toplevel rescue/ensure
* compile.c (iseq_compile_each0): throw TAG_RETURN at return in
  toplevel rescue/ensure to adjust VM stack properly.
  [ruby-core:81777] [Bug #13682]

* vm_insnhelper.c (vm_throw_start): allow return in toplevel
  rescue/ensure.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-27 06:57:34 +00:00
nobu 49160c7115 vm_insnhelper.c: break in once
* vm_insnhelper.c (vm_throw_start): size of catch table has been
  included in iseq_catch_table struct, which could be NULL, since
  2.2.  e.g., proc-closure in `once'.
  [ruby-core:81775] [Bug #13680]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-27 03:45:55 +00:00
ko1 1939d097e6 move several fields from rb_thread_t to rb_execution_context_t.
* vm_core.h (rb_thread_t): move several fields which are copied at cont.c
  to rb_execution_context_t.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-26 07:56:44 +00:00
ko1 4a4627fb0d move "state" to rb_vm_tag.
* vm_core.h (rb_thread_t::tag_state): move to "rb_vm_tag::state".
  Lifetime of "state" should be same as current tag.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-23 09:43:52 +00:00
ko1 a64801c1e9 rename th->state to th->tag_state.
* vm_core.h (rb_thread_t): rename rb_thread_t::state to tag_state
  to make it clear.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-23 08:48:41 +00:00
nobu 02fa3456ce vm_insnhelper.c: vm_stack_consistency_error
* vm_insnhelper.c (vm_stack_consistency_error): extracted from
  insns.def for further info in the future.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59149 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-23 01:43:39 +00:00
ko1 e64e3c4c21 Prohibit SystemStackError while GC.
* vm_insnhelper.c (rb_threadptr_stack_overflow): fatal on GC [Bug #13662]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-15 07:16:17 +00:00
ko1 d7e7f051e4 remove OPT_CALL_CFUNC_WITHOUT_FRAME.
* vm_core.h (OPT_CALL_CFUNC_WITHOUT_FRAME): removed because nobody use it.
  This optimization tries to call C-methods without pushing VM frames,
  however no big improvements compare with this complexity.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-14 02:26:18 +00:00
ko1 7d8a415bc2 check break target correctly.
* compile.c (iseq_compile_each0): save target child_iseq in the catch-table
  for break. This iseq is not for continuation, but for search key at
  vm_throw_start().

* vm_insnhelper.c (vm_throw_start): check saved iseq first.

* iseq.h: add comment for it.

* test/ruby/test_iterator.rb (test_ljump): add a test for the issue:
    def call b; b.call; end
    call(Proc.new{break}){} #=> (1) should raise LocalJumpError
    call(Proc.new{break})   #=> (2) shoudd raies LocalJumpError, too.
  but (1) doesn't raise LocalJumpError.

  This issue is reported by Matz.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-08 04:13:51 +00:00
ko1 1dc7906b17 remove arg_setup_lambda.
* vm_args.c (enum arg_setup_type): remove arg_setup_lambda because it is
  same as arg_setup_method.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-05 05:43:58 +00:00
ko1 26864584d2 * vm_core.h: remove VM_FRAME_MAGIC_LAMBDA and introduce
VM_FRAME_FLAG_LAMBDA. So that lambda block frame is
  VM_FRAME_MAGIC_BLOCK | VM_FRAME_FLAG_LAMBDA.

* vm_core.h: remvoe VM_FRAME_MAGIC_PROC because nobody uses it.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-03 10:07:44 +00:00
watson1978 d0015e4ac6 Improve performance of implicit type conversion
To convert the object implicitly, it has had two parts in convert_type() which are
  1. lookink up the method's id
  2. calling the method

Seems that strncmp() and strcmp() in convert_type() are slightly heavy to look up
the method's id for type conversion.

This patch will add and use internal APIs (rb_convert_type_with_id, rb_check_convert_type_with_id)
to call the method without looking up the method's id when convert the object.

Array#flatten -> 19 % up
Array#+       ->  3 % up

[ruby-dev:50024] [Bug #13341] [Fix GH-1537]

### Before
       Array#flatten    104.119k (± 1.1%) i/s -    525.690k in   5.049517s
             Array#+      1.993M (± 1.8%) i/s -     10.010M in   5.024258s

### After
       Array#flatten    124.005k (± 1.0%) i/s -    624.240k in   5.034477s
             Array#+      2.058M (± 4.8%) i/s -     10.302M in   5.019328s

### Test Code
require 'benchmark/ips'

class Foo
  def to_ary
    [1,2,3]
  end
end

Benchmark.ips do |x|

  ary = []
  100.times { |i| ary << i }
  array = [ary]

  x.report "Array#flatten" do |i|
    i.times { array.flatten }
  end

  x.report "Array#+" do |i|
    obj = Foo.new
    i.times { array + obj }
  end

end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-31 12:30:57 +00:00
ko1 cc50ed4a50 add debug counters for local variable (lavr) access.
* debug_counter.h: add the following counters:
  * lvar_get: counter for lvar get.
  * lvar_get_dynamic: counter for lvar get from upper frames.
  * lvar_set: coutner for lvar set.
  * lvar_set_dynamic: coutner for lvar set from upper frames.
  * lvar_set_slowpath: counter for lavr set using slowpath.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-31 06:46:57 +00:00
nobu 2881374caf Symbol support for opt_eql_func too
* vm_insnhelper.c (comparable_by_identity): extract the condition
  where comparable by identity.  currently both are same types,
  Fixnum, Flonum, or Symbol.

* vm_insnhelper.c (opt_eql_func): support Symbol too.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-26 06:28:38 +00:00
ko1 ad0f8ff76c Symbol support for opt_eq_func.
* vm_insnhelper.c (opt_eq_func): optimize for symbol comparison.
  [Bug #13330] [fix GH-1540]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-26 05:26:57 +00:00
nobu 7e323b5dfe vm_insnhelper.c: remove redefinitions and undefine after used
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-25 07:36:47 +00:00
nobu 7db534a20c vm_insnhelper.c: rb_eql_opt should call eql?
* vm_insnhelper.c (rb_eql_opt): should call #eql? on Float and
  String, not #==.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-25 05:29:35 +00:00
watson1978 b827fdffe6 Improve performance of rb_eql()
This improvement is similar with https://github.com/ruby/ruby/pull/1552

internal.h: add declaration of rb_eql_opt() API.

vm_insnhelper.c (rb_eql_opt): add rb_eql_opt() API which provides optimized
    path for #eql? method such as rb_equal_opt().

object.c (rb_eql): optimize using rb_eql_opt() such as rb_equal().
    Array#eql? and some methods have used rb_eql() and Array#eql? will be faster
    around 20%.

    [ruby-core:80761] [Bug #13447] [Fix GH-#1589]

### Before
       user     system      total        real
   1.570000   0.000000   1.570000 (  1.569754)

### After
       user     system      total        real
   1.300000   0.000000   1.300000 (  1.303624)

### Test code
require 'benchmark'

Benchmark.bmbm do |x|
  ary1 = Array.new(1000) { rand(1000) }
  ary2 = Array.new(1000) { rand(1000) }

  x.report do
    5000000.times do
      ary1.eql?(ary2)
    end
  end

end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-25 04:25:39 +00:00
normal 7469699dce fixup r58614 for raspi3 and maybe other systems with odd compile
[ruby-core:81048]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-09 06:17:01 +00:00
normal 9d09240d9e rb_execution_context_t: move stack, stack_size and cfp from rb_thread_t
The goal is to reduce rb_context_t and rb_fiber_t size
by removing the need to store the entire rb_thread_t in
there.

[ruby-core:81045] Work-in-progress: soon, we will move more fields here.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58614 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-09 05:06:41 +00:00
nobu f0e5e05609 fix infinite recursion
* vm_insnhelper.c (vm_once_dispatch): no guarantee that tail call
  is always optimized away.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-19 15:14:03 +00:00
shyouhei 524fb0138b refactor extract binop dispatcher
Those opt_something instructions are worth refactoring. They tend to
have similar ways of executions.  By extracting the common part,
generated vm_exec_core function shrinks from 26,816 bytes to 26,256
bytes (according to nm(1)).

This changeset introduces negligible performance impact.  3 repeated
runs of optcarrot benchmark on my machine resulted in:

   before this: 28.813363684823557, 27.523907198440366, 27.292766121965400
   after  this: 28.174038497265080, 28.999513875020405, 29.621399800428065

in fps (greater==faster).

----

	* vm_insnhelper.c (vm_opt_binop_dispatch): new function.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58402 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-19 07:27:03 +00:00
nobu 0013fdaaa5 fixup! vm_insnhelper.c: adjust indent [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58399 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-18 13:14:08 +00:00
nobu d939fdc119 vm_insnhelper.c: adjust indent [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-18 13:14:05 +00:00
shyouhei 4a8c235fed tabify (sorry!) [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-18 11:06:58 +00:00
svn ee4ce52d01 * remove trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-18 10:58:50 +00:00
shyouhei 4d21d1f04b split insns.def into functions
Contemporary C compilers are good at function inlining.  They fold
multiple functions into one.  However they are not yet smart enough to
unfold a function into several ones.  So generally speaking, it is
wiser for a C programmer to manually split C functions whenever
possible.  That should make rooms for compilers to optimize at will.

Before this changeset insns.def was converted into single HUGE
function called vm_exec_core().  By moving each instruction's core
into individual functions, generated C source code is reduced from
3,428 lines to 2,847 lines.  Looking at the generated assembly
however, it seems my compiler (gcc 6.2) is extraordinary smart so that
it inlines almost all functions I introduced in this changeset back
into that vm_exec_core.  On my machine compiled machine binary of the
function does not shrink very much in size (28,432 bytes to 26,816
bytes, according to nm(1)).

I believe this change is zero-cost.  Several benchmarks I exercised
showed no significant difference beyond error mergin.  For instance
3 repeated runs of optcarrot benchmark on my machine resulted in:

   before this: 28.330329285707490, 27.513378371065920, 29.40420215754537
   after  this: 27.107195867280414, 25.549324021385907, 30.31581919050884

in fps (greater==faster).

----

	* internal.h (rb_obj_not_equal): used from vm_insnhelper.c
	* insns.def: move vast majority of lines into vm_insnhelper.c
	* vm_insnhelper.c: moved here.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-18 10:58:49 +00:00
nobu e97ac02f84 vm_insnhelper.c: rb_threadptr_stack_overflow
* vm_insnhelper.c (rb_threadptr_stack_overflow): move from
  thread.c and integrate with vm_stackoverflow.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58379 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-17 02:08:41 +00:00
nobu e042dd0ee1 Parenthesized CHECK_CFP_CONSISTENCY [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-11 12:28:51 +00:00
nobu bb66691e7e vm_insnhelper.c: CHECK_CFP_CONSISTENCY
* vm_insnhelper.c (CHECK_CFP_CONSISTENCY): make [BUG] messages
  consistent.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-11 04:17:45 +00:00
nobu 976becf7eb vm_args.c: arity check of lambda
* vm_eval.c (rb_yield_lambda): new function which yields an array
  to a proc and splat to a lambda.  mainly for Enumerable only.

* vm_args.c (setup_parameters_complex): remove special lambda
  splatting for [Bug #9605].  [ruby-core:77065] [Bug #12705]

* vm_insnhelper.c (vm_callee_setup_block_arg): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-19 01:11:12 +00:00
nobu 7768312c1d vm.c: guard arguments [EXPERIMENTAL]
* vm.c (invoke_iseq_block_from_c): guard arguments on stack, not
  to be clobbered during splatting.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58012 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-18 11:29:35 +00:00
nobu c8a3b31bb1 vm_insnhelper.c: adjust indent [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57982 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-15 12:41:56 +00:00
svn 0ddb77a44e * remove trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-15 08:25:59 +00:00