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

377 Коммитов

Автор SHA1 Сообщение Дата
ko1 7790f37efd * node.h: remove NODE_IFUNC, NEW_IFUNC.
* internal.h: use T_IMEMO for IFUNC.
  rename `struct IFUNC' to `struct vm_ifunc' and move the definition
  from vm_insnhelper.h. Add imemo_ifunc.
* gc.c (gc_mark_children): mark imemo_ifunc type T_IMEMO object.
* compile.c: catch up these changes.
* proc.c: ditto.
* vm_core.h (RUBY_VM_IFUNC_P): ditto.
* vm_eval.c (rb_iterate): ditto.
* vm_insnhelper.c: ditto.
* ext/objspace/objspace.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-11 13:31:11 +00:00
ko1 ed130faf28 * proc.c: use RUBY_VM_IFUNC_P() to recognize IFUNC or not.
* vm.c: ditto.
* vm_dump.c: ditto.
* vm_insnhelper.c: ditto.
* vm_core.h: use RB_TYPE_P() instead of BUILTIN_TYPE().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-10 18:50:15 +00:00
ko1 8dced4d2c0 * internal.h: define rb_cref_t and change to use it.
rb_cref_t is data type of CREF. Now, the body is still NODE.
  It is easy to understand what is CREF and what is pure NODE.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-08 21:22:43 +00:00
ko1 d84f9b1694 * fix namespace issue on singleton class expressions. [Bug #10943]
* vm_core.h, method.h: remove rb_iseq_t::cref_stack. CREF is stored
  to rb_method_definition_t::body.iseq_body.cref.
* vm_insnhelper.c: modify SVAR usage.
  When calling ISEQ type method, push CREF information onto method
  frame, SVAR located place. Before this fix, SVAR is simply nil.
  After this patch, CREF (or NULL == Qfalse for not iseq methods)
  is stored at the method invocation.
  When SVAR is requierd, then put NODE_IF onto SVAR location,
  and NDOE_IF::nd_reserved points CREF itself.
* vm.c (vm_cref_new, vm_cref_dump, vm_cref_new_toplevel): added.
* vm_insnhelper.c (vm_push_frame): accept CREF.
* method.h, vm_method.c (rb_add_method_iseq): added. This function
  accepts iseq and CREF.
* class.c (clone_method): use rb_add_method_iseq().
* gc.c (mark_method_entry): mark method_entry::body.iseq_body.cref.
* iseq.c: remove CREF related codes.
* insns.def (getinlinecache/setinlinecache): CREF should be cache key
  because a different CREF has a different namespace.
* node.c (rb_gc_mark_node): mark NODE_IF::nd_reserved for SVAR.
* proc.c: catch up changes.
* struct.c: ditto.
* insns.def: ditto.
* vm_args.c (raise_argument_error): ditto.
* vm_eval.c: ditto.
* test/ruby/test_class.rb: add a test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-06 12:24:58 +00:00
ko1 ca6b174078 * vm_core.h: define vm_svar_index.
* vm_insnhelper.c, vm.c, compile.c: use vm_svar_index names.
* iseq.h: remove DEFAULT_SPECIAL_VAR_COUNT.
  use VM_SVAR_FLIPFLOP_START instead.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-27 08:10:04 +00:00
ktsj e660f776c0 * vm_insnhelper.c (rb_vm_rewrite_cref_stack): copy nd_refinements
of orignal crefs. It fixes segmentation fault when calling
  refined method in duplicate module. [ruby-dev:48878] [Bug #10885]

* vm_core.h, class.c: change accordingly.

* test/ruby/test_refinement.rb: add a test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-22 07:05:14 +00:00
nobu b4f61ad610 vm_core.h: fix symbols leak
* vm_core.h (rb_call_info_kw_arg_struct): make keywords a symbols
  list to get rid of inadvertent creation by variable keyword
  arguments.  [ruby-core:68031] [Bug #10831]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-06 01:31:53 +00:00
ko1 c7124d811f vm.c, vm_core.h: constify VM_CF_LEP, VM_CF_PREV_EP, VM_CF_BLOCK_PTR
and rb_vm_control_frame_block_ptr.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49279 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-16 08:21:49 +00:00
normal b5e321138c vm_core.h: preserve thread ordering
I'm hesitant to consider this as spec, but this causes a
user-visible change which could break user code.

* vm_core.h (rb_vm_living_threads_insert): preserve order
  [Bug #10660] [ruby-core:67154] [ruby-core:67159]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49036 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-27 06:11:10 +00:00
nobu fd639a4c3b vm.c: constify
* vm.c (rb_vm_get_binding_creatable_next_cfp): constify arguments.
  (rb_vm_get_ruby_level_next_cfp): ditto.
  (vm_get_ruby_level_caller_cfp): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-17 03:08:20 +00:00
ko1 1de3e801c4 * vm_core.h: introduce new field
rb_thread_t::local_storage_recursive_hash_for_trace to store
  recursive hash to avoid creating new recursive (nested) hashes
  for each trace events.
  [Bug #10511]
* vm_trace.c (rb_threadptr_exec_event_hooks_orig): use it.
* cont.c: catch up this fix.
* vm.c (rb_thread_mark): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48765 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 19:35:07 +00:00
ko1 9c6deac2d1 * vm_core.h: add rb_thread_t::local_storage_recursive_hash
to speed up Thread#[:__recursive_key__] access.
  [Bug #10511]
* thread.c (threadptr_local_aref): add fast path for
  :__recursive_data__.
* thread.c (threadptr_recursive_hash, threadptr_recursive_hash_set):
  add special accessor for recursive hash.
* cont.c: store/restore local_storage_recursive_hash.
* vm.c: init and mark local_storage_recursive_hash.
* vm_trace.c (rb_threadptr_exec_event_hooks_orig): clear and restore
  local_storage_recursive_hash directly.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-27 01:56:38 +00:00
nobu 2a754a7330 proc.c: make lambda directly
* vm.c (rb_vm_make_proc_lambda): similar to rb_vm_make_proc() with
  is_lambda argument.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-13 09:10:40 +00:00
ko1 ef25be7391 * vm_core.h: change semantics of opt_num and opt_table.
`opt_num' was the number of optional parameters + 1.
  `opt_table' has "opt_num" entries.
  Change them to:
  `opt_num' is the number of optional parameters.
  `opt_talbe' has "opt_num + 1" entries.
  This change simplify parameter fitting logics.
* compile.c: catch up this change.
* iseq.c: ditto.
* proc.c: ditto.
* vm_args.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-03 04:43:07 +00:00
ko1 831e33c780 * vm_core.h: change iseq parameter data structure.
https://bugs.ruby-lang.org/issues/10440#change-49694
  * change terminology `arg' to `param'.
  * move rb_iseq_t::arg_* to rb_iseq_t::param.
  * move rb_iseq_t::arg_size to rb_iseq_t::param::size.
  * move rb_iseq_t::argc to rb_iseq_t::param::lead_num.
  * move rb_iseq_t::arg_opts to rb_iseq_t::param::opt_num.
  * move rb_iseq_t::arg_rest to rb_iseq_t::param::rest_start.
  * move rb_iseq_t::arg_post_num to rb_iseq_t::param::post_num.
  * move rb_iseq_t::arg_post_start to rb_iseq_t::param::post_start.
  * move rb_iseq_t::arg_block to rb_iseq_t::param::block_start.
  * move rb_iseq_t::arg_keyword* to rb_iseq_t::param::keyword.
    rb_iseq_t::param::keyword is allocated only when keyword
    parameters are available.
  * introduce rb_iseq_t::param::flags to represent parameter
    availability. For example, rb_iseq_t::param:🎏:has_kw
    represents that this iseq has keyword parameters and
    rb_iseq_t::param::keyword is allocated.
    We don't need to compare with -1 to check availability.
  * remove rb_iseq_t::arg_simple.
* compile.c: catch up this change.
* iseq.c: ditto.
* proc.c: ditto.
* vm.c, vm_args.c, vm_dump.c, vm_insnhelper.c: ditto.
* iseq.c (iseq_data_to_ary): support keyword argument.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 23:14:21 +00:00
ko1 fbebd502f9 * rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument.
  [Feature #10440] (Details are described in this ticket)
  Most of complex part is moved to vm_args.c.
  Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
  * introduce rb_call_info_kw_arg_t to represent keyword arguments.
  * add rb_call_info_t::kw_arg.
  * rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
  * rename rb_iseq_t::arg_keywords to arg_keyword_num.
  * rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
    to represent keyword bitmap parameter index.
    This bitmap parameter shows that which keyword parameters are given
    or not given (0 for given).
    It is refered by `checkkeyword' instruction described bellow.
  * rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
    to represent keyword rest parameter index.
  * add rb_iseq_t::arg_keyword_default_values to represent default
    keyword values.
  * rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
    to represent
      (ci->flag & (SPLAT|BLOCKARG)) &&
      ci->blockiseq == NULL &&
      ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
  * rewrite splat argument code.
  * rewrite keyword arguments/parameters code.
  * merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
  not. If Hash object and all keys are Symbol literals, they are
  compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
  This instruction check the availability of corresponding keyword.
  For example, a method "def foo k1: 'v1'; end" is cimpiled to the
  following instructions.
    0000 checkkeyword     2, 0  # check k1 is given.
    0003 branchif         9     # if given, jump to address #9
    0005 putstring        "v1"
    0007 setlocal_OP__WC__0 3   # k1 = 'v1'
    0009 trace            8
    0011 putnil
    0012 trace            16
    0014 leave
* insns.def (opt_send_simple): removed and add new instruction
  "opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
  Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
  has parameter variables "k1, kr1, k2, &b, internal_id, krest",
  but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
  (locate a block variable at last)
* parse.y (vtable_pop): added.
  This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 18:02:55 +00:00
ktsj a2608f293d * vm_core.h, proc.c, vm_backtrace.c, vm_trace.c:
remove rb_binding_new_with_cfp, and use rb_vm_make_binding instead.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-18 11:46:41 +00:00
ktsj 231f45ad36 * vm_core.h, vm.c, proc.c: fix GC mark miss on bindings.
[ruby-dev:48616] [Bug #10368]

* test/ruby/test_eval.rb: add a test code.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-18 11:46:31 +00:00
akr 1efb3c31b7 * Avoid undefined behaviors found by gcc -fsanitize=undefined.
gcc (Debian 4.9.1-16) 4.9.1

* include/ruby/ruby.h (INT2FIX): Avoid undefined behavior.

* node.h (nd_set_line): Ditto.

* pack.c (encodes): Ditto.
  (pack_unpack): Ditto.

* regint.h (BIT_STATUS_AT): Ditto.
  (BS_BIT): Ditto.

* time.c (time_mdump): Ditto.
  (time_mload): Ditto.

* vm_core.h (VM_FRAME_MAGIC_MASK): Ditto.

* vm_trace.c (recalc_add_ruby_vm_event_flags): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-17 08:50:01 +00:00
normal 5c8c88a3e9 cont.c: Optimize fiber_switch callees
Remove some unnecessary VALUE/struct conversions and aggressively inline
functions used during fiber_switch. Either of these changes alone does
not yield significant performance increase, but in combination they
improve performance by ~6%.

Arguably, removal of separate VALUE/rb_fiber_t* variables also makes the
code more readable in a few places.

* vm_core.h: declare rb_fiber_t typedef
  (rb_thread_t): fiber and root_fiber become rb_fiber_t * (from VALUE)
* vm.c (rb_thread_mark): use rb_fiber_mark_self
* cont.c (rb_fiber_t): prev becomes rb_fiber_t * (from VALUE)
  (cont_mark, cont_free): simplify conditions
  (rb_fiber_mark_self): new function
  (fiber_mark): use rb_fiber_mark_self
  (cont_save_thread, cont_restore_thread): inline
  (cont_restore_thread): simplify
  (fiber_setcontext): simplify conditions
  (rb_cont_call): remove dereference
  (fiber_t_alloc): update for rb_fiber_t->prev type change
  (rb_fiber_start): ditto
  (fiber_current): extract from rb_fiber_current
  (return_fiber): move, simplify type checks
  (rb_fiber_current): use fiber_current
  (fiber_store): simplify type checks
  (fiber_switch): ditto, simplify call to fiber_setcontext,
   use fiber_current
  (rb_fiber_transfer): update for type changes
  (rb_fiber_terminate): move, use fiber_switch
  (rb_fiber_resume): update for type changes
  (rb_fiber_reset_root_local_storage): ditto
  (rb_fiber_yield): use rb_fiber_switch instead of rb_fiber_transfer
  (rb_fiber_m_transfer): ditto
  [ruby-core:65518] [Feature #10341]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47964 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-15 22:35:08 +00:00
normal ec475ab32d proc.c (rb_proc_alloc): inline and move to vm.c
* proc.c (rb_proc_alloc): inline and move to vm.c
  (rb_proc_wrap): new wrapper function used by rb_proc_alloc
  (proc_dup): simplify alloc + copy + wrap operation
  [ruby-core:64994]

* vm.c (rb_proc_alloc): new inline function
  (rb_vm_make_proc): call rb_proc_alloc

* vm_core.h: remove rb_proc_alloc, add rb_proc_wrap

* benchmark/bm_vm2_newlambda.rb: short test to show difference

First we allocate and populate an rb_proc_t struct inline to avoid
unnecessary zeroing of the large struct.  Inlining speeds up callers as
this takes many parameters to ensure correctness.  We then call the new
rb_proc_wrap function to create the object.

rb_proc_wrap - wraps a rb_proc_t pointer as a Ruby object, but
we only use it inside rb_proc_alloc.  We must call this before
the compiler may clobber VALUE parameters passed to rb_proc_alloc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-12 20:57:45 +00:00
normal f0c968a778 iseq_inline_storage_entry: 24=>16 bytes on 64-bit
We may tag the running_thread pointer to avoid making the "once" struct
bigger than "struct iseq_inline_cache_entry".

This only saves a small amount with "valgrind ruby -e exit"
before:
  total heap usage: 48,122 allocs, 19,248 frees, 8,110,149 bytes allocated
after:
  total heap usage: 48,122 allocs, 19,253 frees, 8,099,197 bytes allocated

* insns.def (once): define and use fake RUNNING_THREAD_ONCE_DONE
  pointer to indicate is->once.running_thread is done.

* vm_core.h (iseq_inline_storage_entry): remove done field,
  allowing the union to be reduced from 24=>16 bytes on 64-bit

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-11 19:25:32 +00:00
ko1 8c6c9c46d8 * vm.c (rb_vm_register_special_exception): make new function to
make and register special exceptions.
* vm.c (rb_vm_mark): do not need to mark special exceptions
  because they are registerd by rb_gc_register_mark_object().
* eval.c (Init_eval): use rb_vm_register_special_exception().
* gc.c (Init_GC): ditto.
* proc.c (Init_Proc): ditto.
* thread.c (Init_Thread): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-11 10:53:48 +00:00
normal b3a4367ce4 rb_call_info_t: shrink to 96 bytes from 104 bytes on 64-bit
This keeps ci->flag and ci->aux.index consistent across 32-bit
and 64-bit platforms.

ci->flag: VM_CALL_* flags only use 9 bits, currently
ci->aux.index: 2 billion ivars per class should be enough for anybody

This saves around 50K allocations on "valgrind ruby -e exit" on x86-64
before:
  total heap usage: 48,122 allocs, 19,253 frees, 8,099,197 bytes allocated
after:
  total heap usage: 48,069 allocs, 19,214 frees, 8,047,266 bytes allocated

* vm_core.h (rb_call_info_t): ci->flag becomes 32-bit unsigned int
  ci->index becomes a 32-bit signed int (from signed long).
  Reorder for better packing on 64-bit, giving an 8 byte reduction
  from 104 to 96 bytes for each ci.

* compile.c (new_callinfo, setup_args, iseq_compile_each,
  iseq_build_from_ary_body): adjust for type changes

* vm_insnhelper.c (vm_getivar): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 06:32:44 +00:00
normal ea4c97904e compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:

before:
	:malloc_increase=>118784,
	:oldmalloc_increase=>1178736,

after:
	:malloc_increase=>99832,
	:oldmalloc_increase=>1031976,

For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).

before:
  total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
  total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated

(numbers from x86-64)

v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
  cache new iseq->iseq_original field.

* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
  (rb_vm_addr2insn): new function for debug
  (rb_iseq_original_iseq): ditto
  (iseq_set_sequence): assign iseq_encoded directly
  [Feature #10185]

* vm_core (rb_iseq_t): move original ->iseq to bottom

* iseq.c (iseq_free, iseq_free): adjust for new layout
  (rb_iseq_disasm): use original iseq for dump
  (iseq_data_to_ary): ditto
  (rb_iseq_line_trace_each): ditto
  (rb_iseq_build_for_ruby2cext): use iseq_encoded directly

* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 06:14:07 +00:00
normal 27f9e70795 vm_core.h (rb_env_t): use flexible array
* vm_core.h (rb_env_t): use flexible array
  This reduces allocations and speeds up the lambda calculus
  fizzbuzz (bm_app_lc_fizzbuzz.rb) benchmark [ruby-core:64858]
* proc.c (get_local_variable_ptr): deconst to adjust for flex array
* vm.c (env_mark, env_free, env_memsize): remove check for env->env
* vm.c (env_alloc): single allocation for flex array
* vm.c (vm_make_env_each): adjust env_alloc call

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47453 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-08 19:38:22 +00:00
ko1 68f55c4b35 * dir.c (glob_helper): use #ifdef instead of #if.
gcc's -Wundef option shows warning for undefined macro.
* numeric.c (flo_is_finite_p): ditto.
* vm_dump.c (rb_vmdebug_thread_dump_state): ditto.
* vm_core.h: define VM_DEBUG_VERIFY_METHOD_CACHE to 0.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-04 08:50:31 +00:00
normal a1e95636ac string.c: move frozen_strings table to rb_vm_t
Cleanup in case MVM development proceeds.

* string.c: remove static frozen_strings
* string.c (Init_frozen_strings): new function
* string.c (rb_fstring): remove check for frozen strings,
  use per-VM table
* string.c (rb_str_free): use per-VM table
* string.c (Init_String): use per-VM table
* vm_core.h (rb_vm_t): add frozen_strings table
* internal.h (Init_frozen_strings): new function prototype
* eval.c (ruby_setup): call Init_frozen_strings
  [Feature #10182]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47310 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-29 06:30:03 +00:00
normal 0ae8dd168e rb_iseq_location_t: change first_lineno type to VALUE
Nearly all current uses of iseq->location.first_lineno are as a
VALUE, not a size_t.  The only exception was the experimental
(and currently unused) rb_iseq_build_for_ruby2cext function.

* vm_core.h (rb_iseq_location_t): change first_lineno type to VALUE
* iseq.c (rb_iseq_build_for_ruby2cext): update based on argument

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-25 02:24:10 +00:00
normal 90037145dd rb_{thread,context,fiber}_struct: trivial packing
* vm_core.h (rb_thread_struct): reorder to pack
* cont.c (rb_context_struct, rb_fiber_struct): ditto
  On x86-64, these changes reduces:
  rb_thread_struct to 1000 bytes (from 1016)
  rb_context_struct to 1288 bytes (from 1312)
  rb_fiber_struct to 2272 bytes (from 2304)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-15 00:25:34 +00:00
normal a9c7629ece rb_iseq_t: reduce to (280 bytes from 288 bytes) on 64-bit
iseq_size and line_info_size may be 32-bit.

4GB instruction sequences should be big enough for anyone.
Other existing line info counters are 32-bit, and nobody
should need all that.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-26 07:30:26 +00:00
nobu 975dcbbcf9 vm_core.h: fix comment
* vm_core.h (rb_proc_t): fix comment.  safe_level is upto 3 now.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-20 12:28:48 +00:00
normal 44c32c22b8 rb_proc_t: reduce to 64 bytes from 72 on 64-bit
* vm_core.h (rb_proc_t): reduce to 64 bytes from 72 on 64-bit

This allows rb_proc_t to fit inside a single cache line on x86-64

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46886 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-20 05:34:32 +00:00
nobu e23d173679 revert r46859 and r46860
revert "enum.c: optimize any? object allocations for Array and Hash"

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-18 13:16:37 +00:00
nobu 0d0fc55122 enum.c: optimize any? object allocations for Array and Hash
* enum.c (enum_any): optimize object allocations for Array and
  Hash when `each` is not redefined, always false if empty and the
  case without a block.  [fix GH-617]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-18 02:10:37 +00:00
nobu c317e978f7 vm_core.h: redefined_flag in rb_vm_t
* vm_core.h (struct rb_vm_struct): move redefined_flag from
  ruby_vm_redefined_flag.

* vm_core.h (BASIC_OP_UNREDEFINED_P): move from vm_insnhelper.h.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-18 01:53:18 +00:00
ngoto e54e53f355 * vm_core.h (struct rb_iseq_struct): stack_max is changed to int
because all calculations related to stack_max in compile.c
  (iseq_set_sequence) and vm_insnhelper.c (vm_push_frame) are
  conducted by using int. This partly reverts r23945.
* vm_insnhelper.c (vm_push_frame): ditto. This reverts r42401.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-16 11:46:06 +00:00
ngoto e49a7bed21 * vm_core.h (struct rb_iseq_struct): temporal workaround of [Bug 10037].
Add padding on big-endian 64-bit architecture (e.g. sparc64).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-16 11:04:01 +00:00
ko1 239c98553d revert r46834 because it does not pass tests
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-16 10:16:34 +00:00
ko1 01dc0a7104 * vm_core.h: remove rb_vm_t::trap_list[RUBY_NSIG], but add
rb_vm_t::trap_list_cmds (an array) and
  rb_vm_t::trap_list_safes[RUBY_NSIG]
  (separate to two different array).
  This modification reduce root objects.
* signal.c: ditto.
* vm.c (rb_vm_mark): remove marking code for rb_vm_t::trap_list.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-16 09:39:09 +00:00
normal ff9046ad0b vm_core.h (struct rb_iseq_struct): reduce to 288 bytes on 64-bit
* vm_core.h (struct rb_iseq_struct): reduce to 288 bytes on 64-bit
  (found with pahole, from the dwarves package)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-14 07:42:13 +00:00
normal e91ae784bc vm_core.h (struct rb_iseq_struct): reduce to 296 bytes on 64-bit
Most iseq do not have a catch_table, so avoid needlessly adding
4-8 bytes to the struct for the common case.

Changes from v2:
- iseq_catch_table_size removed, use if (...) for (;...;)

Changes from v1:
- renamed iseq->_catch_table to iseq->catch_table
- iseq_catch_table_bytes: made a static inline function
- iseq_catch_table_size: new function replaces the
  iseq_catch_table_each iterator macro

* iseq.h (struct iseq_catch_table): new flexible array struct
         (iseq_catch_table_bytes): allocated size function
* vm_core.h (struct rb_iseq_struct): uupdate catch_table member
* compile.c (iseq_set_exception_table): update for struct changes
* iseq.c (iseq_free): ditto
* iseq.c (iseq_memsize): ditto
* iseq.c (rb_iseq_disasm): ditto
* iseq.c (iseq_data_to_ary): ditto
* iseq.c (rb_iseq_build_for_ruby2cext): ditto (untested)
* vm.c (vm_exec): ditto
* vm_core.h (struct rb_iseq_struct): ditto
* vm_insnhelper.c (vm_throw): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46811 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-14 07:06:26 +00:00
normal c7fbc29605 vm_core.h (struct rb_call_info_struct): improve packing
* vm_core.h (struct rb_call_info_struct): improve packing
  On x86-64, it goes from 112 to 104 bytes.  This results in
  ~20K of savings from just "./ruby -e exit"

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46800 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-13 07:46:46 +00:00
normal 499f6d62c7 vm_core.h (struct rb_iseq_struct): stack_max is uint32_t
* vm_core.h (struct rb_iseq_struct): stack_max is uint32_t
  No program will ever need more than a few megabytes of stack,
  so there's no sense in using a 64-bit counter for stack
  accounting.  Packing this with the 32-bit type enum reduces
  rb_iseq_struct from 312 to 304 bytes on 64-bit systems.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-13 07:01:09 +00:00
nobu 1a2b90d5e6 vm.c: rb_vm_env_local_variables
* vm.c (rb_vm_env_local_variables): returns array of local
  variable name symbols in the environment by envval.
* proc.c (bind_local_variables): use rb_vm_env_local_variables.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46648 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-01 17:57:37 +00:00
ko1 bef2e29aab * vm.c (rb_vm_rewind_cfp): add new function to rewind specified cfp
with invoking RUBY_EVENT_C_RETURN.
  [Bug #9961]
* vm_core.h: ditto.
* eval.c (rb_protect): use it.
* eval.c (rb_rescue2): ditto.
* vm_eval.c (rb_iterate): ditto.
* test/ruby/test_settracefunc.rb: add a test.
* vm_core.h (rb_name_err_mesg_new):



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46465 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-19 12:43:48 +00:00
ko1 59bdf7eac8 * vm_core.h: add VM_FRAME_MAGIC_RESCUE to recognize normal block or
rescue clause.
* vm.c (vm_exec): use VM_FRAME_MAGIC_RESCUE on at rescue/ensure.
* test/ruby/test_settracefunc.rb: should not invoke b_return at rescue
  clause.
  [Bug #9957]
* vm_dump.c (control_frame_dump): check VM_FRAME_MAGIC_RESCUE.
* vm_dump.c (vm_stack_dump_each): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-19 09:17:21 +00:00
nobu e99ee55abc constify parameters
* include/ruby/intern.h: constify `argv` parameters.

* include/ruby/ruby.h: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-18 06:16:39 +00:00
ko1 ddae6a05d7 * vm_trace.c: clear and restore recursive checking thread local data
to avoid unexpected throw from TracePoint.
  [Bug #9940]
* test/ruby/test_settracefunc.rb: add a test.
* thread.c: adde
  * rb_threadptr_reset_recursive_data(rb_thread_t *th);
  * rb_threadptr_restore_recursive_data(rb_thread_t *th, VALUE old);
* vm_core.h: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-13 08:50:11 +00:00
nobu dfd8c5d402 thread.c: fix for non-scalar pthread_t
* configure.in (rb_cv_scalar_pthread_t): pthread_t is not required
  to be a scalar type.
* thread.c (fill_thread_id_string, thread_id_str): dump pthread_t
  in hexadecimal form if it is not a scalar type, assume it can be
  represented in a pointer form otherwise.  based on the patch by
  Rei Odaira at [ruby-core:62867].  [ruby-core:62857] [Bug #9884]
* thread_pthread.c (Init_native_thread, thread_start_func_1),
  (native_thread_create): set thread_id_str if needed.
* vm_core.h (rb_thread_t): add thread_id_string if needed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-11 08:38:09 +00:00
normal 1142249713 vm.c: remove rb_vm_living_threads_foreach function
Shorter code with fewer callbacks and casts should be more readable.

* vm.c (rb_vm_living_threads_foreach): remove function
  [ruby-core:62745]
* thread.c (terminate_i): remove
* thread.c (terminate_all): implement (inlines old terminate_i)
* thread.c (rb_thread_terminate_all): use terminate_all
* thread.c (rb_thread_fd_close_i): remove
* thread.c (rb_thread_fd_close): iterate inline
* thread.c (thread_list_i): remove
* thread.c (rb_thread_list): iterate inline
* thread.c (rb_thread_atfork_internal): iterate inline
* thread.c (terminate_atfork_i): update types to remove casts
* thread.c (terminate_atfork_before_exec_i): ditto
* thread.c (struct thgroup_list_params): remove definition
* thread.c (thgroup_list_i): remove
* thread.c (thgroup_list): iterate inline
* thread.c (check_deadlock_i): remove
* thread.c (debug_deadlock_check): implement (inlines check_deadlock_i)
* thread.c (debug_i): remove
* thread.c (rb_check_deadlock): iterate inline
* vm.c (vm_mark_each_thread_func): remove
* vm.c (rb_vm_mark): iterate inline
* vm_core.h (rb_vm_living_threads_remove): remove
* vm_trace.c (clear_trace_func_i): remove
* vm_trace.c (rb_clear_trace_func): iterate inline

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-28 01:48:11 +00:00
nobu 82f4c4d4d7 report bug with machine regisiters
* error.c (rb_bug_context): new function to report bug with
  context.
* vm_dump.c (rb_vm_bugreport): accepts `ucontext_t` argument to
  dump machine regisiters.  based on [GH-584].
* signal.c (sigbus, sigsegv): dump machine regisiters if available.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46106 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-25 03:46:55 +00:00
ko1 7093a2cb5b * ext/openssl/depend: remove dependency from internal headers.
[Feature #9612]
* ext/openssl/ossl.c (ossl_fips_mode_set): ditto.
* ext/coverage/depend: ditto.
* include/ruby/thread_native.h: added.
  This header file only provides wrapper functions to control
  native threads. These wrapper functions are used by MRI
  implementation.
* vm_core.h: use include/ruby/thread_native.h.
* thread.c: ditto.
* thread_pthread.h: ditto.
* thread_win32.h: ditto.
* thread_native.h: removed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-14 10:55:38 +00:00
normal f11db2a605 vm*: doubly-linked list from ccan to manage vm->living_threads
A doubly-linked list for tracking living threads guarantees
constant-time insert/delete performance with no corner cases of a
hash table.  I chose this ccan implementation of doubly-linked
lists over the BSD sys/queue.h implementation since:

1) insertion and removal are both branchless
2) locality is improved if a struct may be a member of multiple lists
   (0002 patch in Feature 9632 will introduce a secondary list
   for waiting FDs)

This also increases cache locality during iteration: improving
performance in a new IO#close benchmark with many sleeping threads
while still scanning the same number of threads.

	vm_thread_close 1.762

* vm_core.h (rb_vm_t): list_head and counter for living_threads
  (rb_thread_t): vmlt_node for living_threads linkage
  (rb_vm_living_threads_init): new function wrapper
  (rb_vm_living_threads_insert): ditto
  (rb_vm_living_threads_remove): ditto
* vm.c (rb_vm_living_threads_foreach): new function wrapper
* thread.c (terminate_i, thread_start_func_2, thread_create_core,
  thread_fd_close_i, thread_fd_close): update to use new APIs
* vm.c (vm_mark_each_thread_func, rb_vm_mark, ruby_vm_destruct,
  vm_memsize, vm_init2, Init_VM): ditto
* vm_trace.c (clear_trace_func_i, rb_clear_trace_func): ditto
* benchmark/bm_vm_thread_close.rb: added to show improvement
* ccan/build_assert/build_assert.h: added as a dependency of list.h
* ccan/check_type/check_type.h: ditto
* ccan/container_of/container_of.h: ditto
* ccan/licenses/BSD-MIT: ditto
* ccan/licenses/CC0: ditto
* ccan/str/str.h: ditto (stripped of unused macros)
* ccan/list/list.h: ditto
* common.mk: add CCAN_LIST_INCLUDES
  [ruby-core:61871][Feature 9632 (part 1)]

Apologies for the size of this commit, but I think a good
doubly-linked list will be useful for future features, too.
This may be used to add ordering to a container_of-based hash
table to preserve compatibility if required (e.g. feature 9614).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-10 23:48:51 +00:00
ko1 ba6b0acdb6 * vm.c (invoke_block_from_c): add VM_FRAME_FLAG_BMETHOD to record
it is bmethod frame.
* vm.c (vm_exec): invoke RUBY_EVENT_RETURN event if rollbacked frame
  is VM_FRAME_FLAG_BMETHOD.
  [Bug #9759]
* test/ruby/test_settracefunc.rb: add a test for TracePoint/set_trace_func.
* vm_core.h: renmae rb_thread_t::passed_me to
  rb_thread_t::passed_bmethod_me to clarify the usage.
* vm_insnhelper.c (vm_call_bmethod_body): use renamed member.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-30 09:08:10 +00:00
ko1 1ccaa4756a * internal.h, vm_core.h: move LIKELY/UNLIKELY/UNINITIALIZED_VAR()
macros from vm_core.h to internal.h.
* string.c: remove dependency to "vm_core.h".
* common.mk: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-05 04:58:00 +00:00
nobu 628f75b752 vm_core.h: rb_thread_struct::machine
* vm_core.h (rb_thread_struct): aggregate cpu stuff into a struct,
  so that a debugger can show its content at once.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-28 06:09:58 +00:00
charliesome 7df9798126 * compile.c, insns.def, test/ruby/test_rubyvm.rb, vm.c, vm_core.h,
vm_insnhelper.c, vm_insnhelper.h, vm_method.c: Rename method_serial
  to global_method_state and constant_serial to global_constant_state
  after discussion with ko1.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-09 10:51:02 +00:00
tarui 44cb6eaef9 * vm_dump.c (rb_vmdebug_debug_print_pre): Bugfix. Get PC directly.
PC is cached into local stack and cfp->pc is incorrent at next of
	  branch or jump.
	* vm_exec.h (DEBUG_ENTER_INSN): catch up this change.
	* vm_core.h: update signature of rb_vmdebug_debug_print_pre.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43916 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-29 12:01:18 +00:00
nobu 52e35469f0 vm_core.h: extract VM_STACK_OVERFLOWED_P
* vm_core.h (VM_STACK_OVERFLOWED_P, WHEN_VM_STACK_OVERFLOWED): extract
  condition from CHECK_VM_STACK_OVERFLOW.

* vm_exec.c (vm_stack_overflow_for_insn): move rb_bug call.

* vm_exec.h (CHECK_VM_STACK_OVERFLOW_FOR_INSN): share the condition
  with CHECK_VM_STACK_OVERFLOW.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-18 02:29:58 +00:00
tarui 28a1c4f33e * cont.c : Introdule ensure rollback mechanism. Please see below.
* internal.h (ruby_register_rollback_func_for_ensure): catch up above change.
	  Add rollback mechanism API.

	* vm_core.h (typedef struct rb_vm_struct): catch up above change.
	  Introdule ensure-rollback relation table.

	* vm_core.h (typedef struct rb_thread_struct): catch up above change.
	  Introdule ensure stack.

	* eval.c (rb_ensure): catch up above change.
	  Introdule ensure stack.

	* hash.c : New function for rollback ensure, and register it to
	  ensure-rollback relation table. [ruby-dev:47803] [Bug #9105]

	Ensure Rollback Mechanism:
	A rollback's function is a function to rollback a state before ensure's
	function execution.
	When the jump of callcc is across the scope of rb_ensure,
	ensure's functions and rollback's functions are executed appropriately
	for keeping consistency.

	Current API is unstable, and only internal use.

	ruby_register_rollback_func_for_ensure(ensure_func,rollback_func)
	This API create relation ensure's function to rollback's function.
	By registered rollback's function, it is executed When jumpping into
	corresponding rb_ensure scope.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-15 17:15:31 +00:00
charliesome 1546fb6c00 * insns.def: unify ic_constant_serial and ic_class_serial into one field
ic_serial. This is possible because these fields are only ever used
  exclusively with each other.

* insns.def: ditto
* vm_core.h: ditto
* vm_insnhelper.c: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-09 03:46:48 +00:00
charliesome 8b0771b014 * class.c: unify names of vm state version counters to 'serial'.
This includes renaming 'vm_state_version_t' to 'rb_serial_t',
  'method_state' to 'method_serial', 'seq' to 'class_serial',
  'vmstat' to 'constant_serial', etc.

* insns.def: ditto
* internal.h: ditto
* vm.c: ditto
* vm_core.h: ditto
* vm_insnhelper.c: ditto
* vm_insnhelper.h: ditto
* vm_method.c: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-09 03:34:49 +00:00
charliesome 7fafa8f376 * insns.def, vm.c, vm_insnhelper.c, vm_insnhelper.h, vm_method.c: split
ruby_vm_global_state_version into two separate counters - one for the
  global method state and one for the global constant state. This means
  changes to constants do not affect method caches, and changes to
  methods do not affect constant caches. In particular, this means
  inclusions of modules containing constants no longer globally
  invalidate the method cache.

* class.c, eval.c, include/ruby/intern.h, insns.def, vm.c, vm_method.c:
  rename rb_clear_cache_by_class to rb_clear_method_cache_by_class

* class.c, include/ruby/intern.h, variable.c, vm_method.c: add
  rb_clear_constant_cache

* compile.c, vm_core.h, vm_insnhelper.c: rename vmstat field in
  rb_call_info_struct to method_state

* vm_method.c: rename vmstat field in struct cache_entry to method_state

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-29 00:52:38 +00:00
shyouhei ec6f077809 * vm_core.h (enum): avoid syntax error.
* method.h: ditto.

	* internal.h: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-22 12:59:27 +00:00
ko1 52c1331763 * class.c, variable.c, gc.c (rb_class_tbl): removed.
* vm.c, vm_core.h (rb_vm_add_root_module): added to register as a
  defined root module or class.
  This guard helps mark miss from defined classes/modules they are
  only refered from C's global variables in C-exts.
  Basically, it is extension's bug.
  Register to hash object VM has.
  Marking a hash objects allows generational GC supports.
* gc.c (RGENGC_PRINT_TICK): disable (revert).



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-11 18:27:18 +00:00
ko1 fa7bf880b4 * vm_trace.c (postponed_job): use preallocated buffer.
Pre-allocate MAX_POSTPONED_JOB (1024) sized buffer
  and use it.
  If rb_postponed_job_register() cause overflow, simply it
  fails and returns 0.
  And maybe rb_postponed_job_register() is signal safe.
* vm_core.h: change data structure.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-10 04:56:32 +00:00
ko1 12f368d6a4 * iseq.c, internal.h: change to public (but internal) functions
* VALUE rb_iseq_path(VALUE iseqval);
* VALUE rb_iseq_absolute_path(VALUE iseqval);
* VALUE rb_iseq_label(VALUE iseqval);
* VALUE rb_iseq_base_label(VALUE iseqval);
* VALUE rb_iseq_first_lineno(VALUE iseqval);
  And new (temporary) function:
* VALUE rb_iseq_klass(VALUE iseqval);
* iseq.c. vm_core.h (int rb_iseq_first_lineno): remove
  function `int rb_iseq_first_lineno(const rb_iseq_t *iseq)'.
  Use `VALUE rb_iseq_first_lineno(VALUE iseqval)' instead.
* proc.c. vm_insnhelper.c, vm_method.c: catch up this change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-07 05:12:08 +00:00
naruse d748f5b6eb * vm_core.h: use __has_attribute() instead of __clang__major__ because
clang says "Note that marketing version numbers should not be used
  to check for language features, as different vendors use different
  numbering schemes. Instead, use the Feature Checking Macros."
  http://clang.llvm.org/docs/LanguageExtensions.html

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-02 06:50:47 +00:00
charliesome d60c6c8642 * vm_core.h: use __attribute__((unused)) in UNINTIALIZED_VAR on clang
4.0+ instead of just on 4.2. Clang has supported the unused attribute
  since before version 4, so this should be safe.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-01 14:45:27 +00:00
charliesome 2f522b9cc6 * class.c, compile.c, eval.c, gc.h, insns.def, internal.h, method.h,
variable.c, vm.c, vm_core.c, vm_insnhelper.c, vm_insnhelper.h,
  vm_method.c: Implement class hierarchy method cache invalidation.

  [ruby-core:55053] [Feature #8426] [GH-387]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-04 05:25:06 +00:00
ko1 30b1947df2 * insns.def: fix regexp's once option behavior.
fix [ruby-trunk - Bug #6701]
* insns.def: remove `onceinlinecache' and introduce `once' instruction.
  `once' doesn't use `setinlinecache' insn any more.
* vm_core.h: `union iseq_inline_storage_entry' to store once data.
* compile.c: catch up above changes.
* iseq.c: ditto.
* vm.c, vm_insnhelper.c: ditto. fix `m_core_set_postexe()' which
  is depend on `onceinlinecache' insn.
* test/ruby/test_regexp.rb: add tests.
* iseq.c: ISEQ_MINOR_VERSION to 1 (should increment major?)



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42637 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-20 17:41:13 +00:00
ko1 568c5a8193 * proc.c: add Binding#local_variable_get/set/defined?
to access local variables which a binding contains.
  Most part of implementation by nobu.
* test/ruby/test_proc.rb: add a tests for above.
* vm.c, vm_core.h (rb_binding_add_dynavars): add a new function
  to add a new environment to create space for new local variables.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42464 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-09 09:51:00 +00:00
knu d5ecd17aee Add Process.argv0.
* ruby.c (Process.argv0): New method to return the original value
  of $0. [Feature #8696]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-07 14:12:08 +00:00
ko1 22468a4f92 * vm_insnhelper.c (vm_push_frame): fix stack overflow check codes.
Stack overflow check should be done *after* pushing a stack frame.
  However, some stack overflow checking codes checked *before*
  pushing a stack frame with iseq->stack_max.
  To solve this problem, add a new parameter `stack_max' to specify
  a possible consuming stack size.
* vm_core.h (CHECK_VM_STACK_OVERFLOW0): add to share the stack overflow
  checking code.
* insns.def: catch up this change.
* vm.c, vm_eval.c: ditto.
* test/ruby/test_exception.rb: add a stack overflow test.
  This code is reported by nobu.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-06 08:33:05 +00:00
ko1 4d3feac974 * thread_(pthread|win32).h: rename rb_thread_cond_t to
rb_nativethread_cond_t.
* thread.c, thread_pthread.c, thread_win32.c, vm_core.h: catch up
  renaming.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-23 10:50:32 +00:00
ko1 2b1088c89f * thread_pthread.h, thread_win32.h: rename rb_thread_id_t to
rb_nativethread_id_t.
* thread_pthread.c, vm_core.h: use rb_nativethread_id_t.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42136 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-23 10:38:36 +00:00
ko1 bd058912da * thread_native.h: added.
Move native thread related lines from vm_core.h.
  And declare several functions "rb_nativethread_lock_*",
  manipulate locking.
* common.mk: add thread_native.h.
* thread.c: add functions "rb_nativethread_lock_*".
* thraed.c, thread_[pthread,win32].[ch]: rename rb_thread_lock_t
  to rb_nativethread_lock_t to make it clear that this lock is for
  native thraeds, not for ruby threads.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-23 09:53:14 +00:00
nobu 03813f6dac vm_eval.c: Check_TypedStruct
* vm_eval.c (eval_string_with_cref): check by Check_TypedStruct
  instead of rb_obj_is_kind_of.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-22 07:32:52 +00:00
ko1 9b47ec04a8 * include/ruby/ruby.h (struct rb_data_type_struct), gc.c: add
rb_data_type_struct::flags. Now, this flags is passed
  at T_DATA object creation. You can specify FL_WB_PROTECTED
  on this flag.
* iseq.c: making non-shady iseq objects.
* class.c, compile.c, proc.c, vm.c: add WB for iseq objects.
* vm_core.h, iseq.h: constify fields to detect WB insertion.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41412 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-19 06:26:01 +00:00
ko1 e2793a908e * include/ruby/debug.h, vm_trace.c: add rb_postponed_job API.
Postponed jobs are registered with this API. Registered jobs
  are invoked at `ruby-running-safe-point' as soon as possible.
  This timing is completely same as finalizer timing.
  There are two APIs:
* rb_postponed_job_register(flags, func, data): register a
  postponed job with data. flags are reserved.
* rb_postponed_job_register_one(flags, func, data): same as
  `rb_postponed_job_register', but only one `func' job is
  registered (skip if `func' is already registered).
  This change is mostly written by Aman Gupta (tmm1).
  https://bugs.ruby-lang.org/issues/8107#note-15
  [Feature #8107]
* gc.c: use postponed job API for finalizer.
* common.mk: add dependency from vm_trace.c to debug.h.
* ext/-test-/postponed_job/extconf.rb, postponed_job.c,
  test/-ext-/postponed_job/test_postponed_job.rb: add a test.
* thread.c: implement postponed API.
* vm_core.h: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-26 21:30:44 +00:00
nobu 3e8bba2fc1 vm_core.h: move jmpbuf between tag and prev
* vm_core.h (rb_vm_tag): move jmpbuf between tag and prev so ensure to
  be accessible.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-18 06:49:19 +00:00
nobu bff997e02b defines.h: RUBY_SYMBOL_EXPORT_{BEGIN,END}
* include/ruby/defines.h (RUBY_SYMBOL_EXPORT_{BEGIN,END}): visibility
  control macros.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-05 10:29:38 +00:00
nobu 228b29a697 load.c: loaded_features_index st_table
* load.c (rb_feature_p), vm_core.h (rb_vm_struct): turn
  loaded_features_index into st_table.  patches by tmm1 (Aman Gupta)
  in [ruby-core:53251] and [ruby-core:53274] [Bug #8048]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-22 08:38:51 +00:00
nobu 7f7621e734 revert r39861
* include/ruby/ruby.h: revert r39861 because RB_UNUSED_VAR() is used
  for array variables in extension libraries.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-21 14:32:17 +00:00
nobu 042594bb50 ruby.h: RB_UNUSED_VAR from UNINITIALIZED_VAR
* include/ruby/ruby.h (RB_UNUSED_VAR): move code from
  UNINITIALIZED_VAR() in vm_core.h.
* vm_core.h (UNINITIALIZED_VAR): use RB_UNUSED_VAR().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-21 14:14:19 +00:00
nobu 69d5f4ab53 vm_core.h: suppress warnings
* vm_core.h (UNINITIALIZED_VAR): suppress warnings by clang 4.2.
  [ruby-core:51742] [Bug #7756]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-21 04:50:52 +00:00
kosaki 4ea96ece84 * internal.h: added a declaration of ruby_kill().
* thread.c (ruby_kill): helper function of kill().

* signal.c (rb_f_kill): use ruby_kill() instead of kill().
* signal.c (rb_f_kill): call rb_thread_execute_interrupts()
  to ensure that make SignalException if sent a signal
  to myself. [Bug #7951] [ruby-core:52864]

* vm_core.h (typedef struct rb_thread_struct): added
  th->interrupt_cond.
* thread.c (rb_threadptr_interrupt_common): added to
  initialization of th->interrupt_cond.
* thread.c (thread_create_core): ditto.

* test/ruby/test_signal.rb (TestSignal#test_hup_me): test for
  the above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-19 04:40:22 +00:00
nobu 34a95669da required keyword arguments
* compile.c (iseq_set_arguments, iseq_compile_each): support required
  keyword arguments.   [ruby-core:51454] [Feature #7701]
* iseq.c (rb_iseq_parameters): ditto.
* parse.y (f_kw, f_block_kw): ditto.  this syntax is still
  experimental, the notation may change.
* vm_core.h (rb_iseq_struct): ditto.
* vm_insnhelper.c (vm_callee_setup_keyword_arg): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39735 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-12 13:20:50 +00:00
nobu 8efeb603fe * remove trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-05 06:24:16 +00:00
ko1 88101695ab * proc.c (rb_binding_new_with_cfp): permit to create binding object
of IFUNC frame.
  When `rb_binding_new_with_cfp()' is called, VM finds out the first
  normal (has iseq) frame and create a binding object of this frame
  and create Env objects. `ep's of related frames are updated
  (`ep's point Env object managed spaces).
  However, `ep' of skipped IFUNC frame was not updated and
  old invalid `ep' was remained. It causes serious problems.
  To solve this issue, permit IFUNC to create binding.
  (Maybe there is no problem on it)
  [ruby-dev:46908] [ruby-trunk - Bug #7774]
* test/ruby/test_settracefunc.rb: add a test.
* vm.c (rb_vm_get_binding_creatable_next_cfp), vm_core.h: added.
* vm_trace.c: fix to use `rb_vm_get_binding_creatable_next_cfp()'.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39067 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-05 06:04:59 +00:00
ko1 18e01f6381 * vm_backtrace.c: fix issue of rb_debug_inspector_open().
The order of making binding should be stack (frame) top to bottom.
  [Bug #7635]
  And also fix issue of collecting klass. Collecting klass is same
  as TracePoint#defined_class.
  (previous version, it returns T_ICLASS (internal objects).
* test/-ext-/debug/test_debug.rb: add a test.
* ext/-test-/debug/extconf.rb, init.c, inspector.c: ditto.
* vm_backtrace.c: remove magic number and add enum CALLER_BINDING_*.
* vm_backtrace.c, include/ruby/debug.h: add new C api (experimental)
  rb_debug_inspector_frame_self_get().
* vm.c, vm_core.h, vm_trace.c: move decl. of
  rb_vm_control_frame_id_and_class() and constify first parameter.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-29 08:25:32 +00:00
ko1 d50bd4939a * vm_core.h: modify a comment about rb_iseq_t::local_size.
A patch by davidbalbert (David Albert) [Bug #6750]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-25 03:03:50 +00:00
ko1 5849920066 * vm_core.h (VM_DEBUG_BP_CHECK): set 0 as default.
This flag specifies checking BP consistency on each frame popping.
  Now, we don't have any trouble on it, so I remove it.
  If you feel any bugs about VM execution, then set it to 1.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-10 13:03:39 +00:00
nobu 69b716111f vm_core.h: flip_cnt in rb_iseq_t
* vm_core.h (rb_iseq_t): move flip_cnt from struct iseq_compile_data,
  because it has same life span as enclosing iseq.  [Bug #7671]
  [ruby-core:51296]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-08 05:41:44 +00:00
charliesome 22691e7f6b * vm_core.h (VM_DEFINECLASS_TYPE): explicit cast to enum type to avoid 64->32
shorten warning

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-27 12:09:33 +00:00
ko1 c2693f8bd6 * vm_trace.c (rb_threadptr_exec_event_hooks_and_pop_frame):
pop a frame before JUMP_TAG() if exception occurred.
  This change fix bug of Ruby 1.9.
  [ruby-core:51128] [ruby-trunk - Bug #7624]
* vm_core.h (EXEC_EVENT_HOOK_AND_POP_FRAME): add to use
  `rb_threadptr_exec_event_hooks_and_pop_frame()'.
* vm.c (vm_exec): use EXEC_EVENT_HOOK_AND_POP_FRAME() while
  exception handling. While exception hadnling, if an exception
  is raised in hooks, need to pop current frame and raise this
  raised exception by hook.
* test/ruby/test_settracefunc.rb: add a test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-25 13:24:17 +00:00
ko1 270fbd9c05 * vm_core.h, eval_intern.h (CHECK_STACK_OVERFLOW): move
CHECK_STACK_OVERFLOW() to vm_core.h and rename to
  CHECK_VM_STACK_OVERFLOW().
  This change is only move and rename.
* tool/instruction.rb: catch up above changes.
* vm.c, vm_insnhelper.c: ditto.
* vm_insnhelper.c (vm_stackoverflow): add a function to unify
  raising vm stackoverflow exception.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-25 09:57:07 +00:00
ko1 59e1e822a1 * vm_core.h (RUBY_VM_THREAD_VM_STACK_SIZE): change default
VM stack size (128 KB or  256 KB -> 512 KB or 1024 KB).
  This re-sizing corrects smaller value introduced at r38478.
  Newer value is same VM stack size of Ruby 1.9.
  [ruby-dev:46797] [ruby-trunk - Bug #7603]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-25 07:29:36 +00:00
ko1 0f9b33c793 * thread.c: rename methods:
from Thread.async_interrupt_timing to Thread.handle_interrupt,
  from Thread.async_interrupted? to Thread.pending_interrupt?.
  Also rename option from `defer' to `never'.
  [ruby-core:51074] [ruby-trunk - Feature #6762]
* vm_core.c, thread.c: rename functions and data structure
  `async_errinfo' to `pending_interrupt'.
* thread.c: add global variables sym_immediate, sym_on_blocking and
  sym_never.
* cont.c, process.c, vm.c, signal.c: ditto.
* lib/sync.rb, lib/thread.rb: catch up this renaming.
* test/ruby/test_thread.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38577 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-23 10:18:58 +00:00