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

481 Коммитов

Автор SHA1 Сообщение Дата
ko1 9cf6751f83 * method.h, vm_method.c (rb_free_method_entry): constify a parameter.
* vm_method.c (rb_unlink_method_entry): constify a parameter.
* vm_core.h: remove useless declaration about rb_unlink_method_entry().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-30 18:30:42 +00:00
nobu ec0a083d93 proc.c: rb_proc_alloc
* proc.c (rb_proc_alloc, proc_dup): allocate rb_proc_t instead of
  wrapping to get rid of potential memory leak.

* vm.c (rb_proc_create): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-16 12:21:25 +00:00
ko1 633574eee5 * vm_args.c: protect value stack from calling other methods
during complex parameter setting process (splat, kw, and so on).
  [Bug #11027]
* vm_core.h: remove rb_thead_t::mark_stack_len.
  With this modification, we don't need to use th->mark_stack_len.
* test/ruby/test_keyword.rb: add a test.
* cont.c (cont_capture): catch up this fix.
* vm.c (rb_thread_mark): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-06 07:14:28 +00:00
nobu c0bf2c5efe vm_core.h: update for OPT_CALL_CFUNC_WITHOUT_FRAME
* vm_eval.c (vm_call0_cfunc): update invoker arguments.
* vm_insnhelper.c (vm_call_cfunc_latter): ditto.
* vm_insnhelper.c (rb_vm_call_cfunc_push_frame): ditto, and prefix
  with rb_.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-03 02:43:20 +00:00
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
ko1 8578cc337b * include/ruby/debug.h: define rb_trace_arg_t.
* vm_core.h: catch up above changes.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38526 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-21 09:48:15 +00:00
ko1 87d48d14a0 * vm_core.h, vm_trace.c: fix multi-threading bug for tracing.
Move `trace_arg' from rb_tp_t::trace_arg to rb_thread_t::trace_arg.
  `trace_arg' may changed by multiple threads.
  rb_thread_t::trace_arg can represent rb_thread_t::trace_running
  (null or non-null) and rb_thread_t::trace_running is removed.
  After that, `rb_tp_t' is not needed to check tracing or not
  (A running thread knows tracing or not). This is why I remove
  tp_attr_check_active() and make new function get_trace_arg().
  And this modification disable to work the following code:
  TracePoint.trace{|tp|
  Thread.new{p tp.event} # access `tp' from other threads.
  }
  I believe nobody mix threads at trace procedure.
  This is current limitation.
* cont.c (fiber_switch, rb_cont_call): use rb_thread_t::trace_arg
  instead of rb_thread_t::trace_running.
* test/ruby/test_settracefunc.rb: add a multi-threading test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38524 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-21 09:33:44 +00:00
shugo ea01ffa569 * vm_core.h (rb_vm_defineclass_type_t),
compile.c (iseq_compile_each), insns.def (defineclass): change the
  meaning of the third operand of defineclass as follows:
    lower 3bits: the type of the defineclass
                   0 = class, 1 = singleton class, 2 = module
    4th bit: a flag represents whether the defineclass is scoped
               0 = not scoped (e.g., class Foo)
	       1 = scoped (e.g., class Bar::Baz)
    5th bit: a flag represents whether the superclass is specified
               0 = not specified (e.g., class Foo)
               1 = specified (e.g., class Bar < Foo)
  If the superclass is specified and is not a class, a TypeError
  should be raised.  [ruby-dev:46747] [Bug #7572]

* test/ruby/test_class.rb: related test.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-20 08:13:53 +00:00
ko1 87e1616048 * vm.c: support variable VM/Machine stack sizes.
Specified by the following environment variaables:
  - RUBY_THREAD_VM_STACK_SIZE: vm stack size used at thread creation.
  default: 128KB (32bit CPU) or 256KB (64bit CPU).
  - RUBY_THREAD_MACHINE_STACK_SIZE: machine stack size used at thread
  creation. default: 512KB or 1024KB.
  - RUBY_FIBER_VM_STACK_SIZE: vm stack size used at fiber creation.
  default: 64KB or 128KB.
  - RUBY_FIBER_MACHINE_STACK_SIZE: machine stack size used at fiber
  creation. default: 256KB or 256KB.
  This values are specified at launched timing. You can not change
  these values at running time.
  Environ variables are only *hints* because:
  - They are aligned to 4KB.
  - They have minimum values (depend on OSs).
  - Machine stack settings are ignored by some OSs.
  Default values especially fiber stack sizes are increased.
  This change affect Fiber's behavior:
  (1) You can run more complex program on a Fiber.
  (2) You can not make many (thousands) Fibers because of
  lack of address space (on 32bit CPU).
  If (2) bothers you,
  (a) Use 64bit CPU with big memory, or
  (b) Specify RUBY_FIBER_(VM|MACHINE)_STACK_SIZE correctly.
  You need to choose correct stack size carefully. These values
  are completely rely on systems (OS/compiler and so on).
* vm_core.h (rb_vm_t::default_params): add to record above settings.
* vm.c (RubyVM::DEFAULT_PARAMS): add new constant to see
  above setting.
* thread_pthread.c: support RUBY_THREAD_MACHINE_STACK_SIZE.
* cont.c: support RUBY_FIBER_(VM|MACHINE)_STACK_SIZE.
* test/ruby/test_fiber.rb: add tests for above.
* test/ruby/test_thread.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-19 22:29:18 +00:00
kosaki aff9dff46d * signal.c (rb_sigaltstack_size): new. calculate stack size for
sigsegv handler. enlarge value when x86 or x86_64 on Linux.
  Linux has very small MINSIGSTKSZ size (2048 bytes) and
  our sigsegv routine need 5KiB at least. [Bug #7141]
* internal.h: add declaration of rb_sigaltstack_size().
* vm_core.h: remove ALT_STACK_SIZE definition.

* signal.c (rb_register_sigaltstack): replace ALT_STACK_SIZE with
  rb_sigaltstack_size();
* gc.c (Init_heap): ditto.
* vm.c (th_init): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-15 14:20:12 +00:00
eregon 0314f93ef4 * iseq.c (rb_iseq_parameters): fix limit for optional arguments.
* test/ruby/test_keyword.rb: tests for above.
* vm_core.h (struct rb_iseq_struct): update documentation
  with keyword arguments. [Bug #7540] [ruby-core:50735]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-11 21:44:49 +00:00
tarui 64f634f1de * vm_core.h (RUBY_VM_CHECK_INTS_BLOCKING): check async queue everytime.
* thread.c (sleep_forever): check RUBY_VM_CHECK_INTS_BLOCKING first.
        * thread.c (sleep_timeval): ditto.
        * test/ruby/test_thread.rb (test_async_interrupt_blocking): add a test
          exceptions are correctly defared and raised on :on_blocking context.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-04 18:38:21 +00:00
tarui c1e6052bfe * thread.c (RB_GC_SAVE_MACHINE_CONTEXT, rb_gc_save_machine_context):
extract rb_gc_save_machine_context to RB_GC_SAVE_MACHINE_CONTEXT.
	  NOTE: machine_regs and machine_stack_end must be set in current scope.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38144 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-02 10:28:27 +00:00
kosaki 15b25acd25 * vm_core.h (rb_vm_struct): add thread_destruct_lock field.
* thread.c (Init_Thread): ditto.
* thread.c (rb_vm_gvl_destroy): ditto.

* thread.c (thread_start_func_2): make sure vm->running_thread
  don't point to dead thread.
* thread.c (timer_thread_function): close a race against thead
  destruction. [Bug #4911][ruby-dev:43859]

* vm_core.h (rb_thread_set_current): reset running time of
  current thread instead of previous thread. We no longer
  assume previous running thread still live.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 13:52:34 +00:00
kosaki 2e72d1c323 revert r35486 (add rb_thread_t#yeiling field). because it doesn't help
to close a race.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 13:52:24 +00:00
ko1 585ac7f1a2 * include/ruby/debug.h: add rb_debug_inspector_* APIs.
* vm_backtrace.c: ditto.
* common.mk: add dpendency from vm_backtrace.o to
  include/ruby/debug.h.
* proc.c (rb_binding_new_with_cfp): constify.
* vm.c (rb_vm_get_ruby_level_next_cfp): consitify.
* vm_core.h, vm_trace.c: move decls.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-29 07:05:27 +00:00
tarui f5dc27aa77 * thread.c (thread_join_sleep): check spurious wakeup by itself for
corresponding status change in trap context.
	* vm_core.h (struct rb_thread_struct): add rb_thread_list_t and use as join_list for
	reentry by trap context.
	* thread.c (thread_start_func_2): ditto.
	* thread.c (remove_from_join_list): ditto.
	* thread.c (rb_thread_atfork): ditto.
	* thread.c (thread_join): ditto. & remove trap handler check.
	* thread.c (sleep_forever): add argument : spurious_check.
	* thread.c (sleep_timeval): ditto.
	* thread.c (rb_thread_sleep_forever): set spurious_check.
	* thread.c (rb_thread_sleep_deadly): ditto.
	* thread.c (sleep_for_polling): ditto.
	* thread.c (rb_thread_wait_for): ditto.
	* thread.c (sleep_wait_for_interrupt): bypass spurious_check.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 12:34:15 +00:00
kosaki 9cbf473287 * vm_core.h (enum rb_thread_status): remove THREAD_TO_KILL
* vm_core.h (struct rb_thread_struct): add to_kill field
* thread.c (terminate_i): convert THREAD_TO_KILL to to_kill.
* thread.c (rb_threadptr_to_kill): ditto.
* thread.c (rb_thread_kill): ditto.
* thread.c (rb_thread_wakeup_alive): ditto.
* thread.c (thread_list_i): ditto.
* thread.c (static const char): ditto.
* thread.c (thread_status_name): ditto.
* thread.c (rb_thread_status): ditto.
* thread.c (rb_thread_inspect): ditto.
* vm_backtrace.c (thread_backtrace_to_ary): ditto.

* thread.c (rb_threadptr_execute_interrupts): fix thread status
  overwritten issue. [Bug #7450] [ruby-core:50249]

* test/ruby/test_thread.rb (test_hread_status_raise_after_kill):
  test for the above.
* test/ruby/test_thread.rb (test_thread_status_in_trap): test for
  thread status in trap.
* test/ruby/test_thread.rb (test_status_and_stop_p): remove
  Thread.control_interrupt unsafe test. Thread#kill no longer
  changes thread status. Instead of, Thread#kill receiver changes
  their own status when receiving kill signal.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 08:31:03 +00:00
kosaki 8111b32d68 * thread.c (thread_s_new): uses main_thread->status instead of
th->inhibit_thread_creation for preventing thread creation.
* vm_core.h (rb_vm_struct): remove inhibit_thread_creation field.
* thread.c (rb_thread_terminate_all): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 04:43:15 +00:00
ko1 d187f4bc21 * vm_trace.c: rename TracePoint#file and TracePoint#line
to TracePoint#path and TracePoint#lineno respectively.
  They are consistent to RubyVM::Backtrace::Location.
* include/ruby/debug.h: ditto.
* vm_core.h: ditto.
* test/ruby/test_settracefunc.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 23:25:21 +00:00
ko1 8c138db3d2 * vm_core.h: add members to rb_trace_arg_t:
* `klass_solved' represents klass and id is checked.
* `line' represents line calculated from cfp.
* `file' represents line calculated from cfp.
* vm_trace.c: fix to use above data stractures.
  No need to calculate klass and id, line and file
  pairs for each trace points.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 23:01:45 +00:00
kosaki 66e2e6ee69 * vm_core.h (RUBY_VM_SET_TIMER_INTERRUPT, RUBY_VM_SET_INTERRUPT)
(RUBY_VM_SET_FINALIZER_INTERRUPT, RUBY_VM_SET_TRAP_INTERRUPT)
(RUBY_VM_INTERRUPTED): use enum symbol instead of immediate value.
* thread.c (thread_join_m, rb_threadptr_execute_interrupts): ditto.
* signal.c (signal_exec): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 12:17:10 +00:00
kosaki 58543f00b6 * thread.c (thread_join_m): use th->interrupt_mask instead of
th->in_trap.

* vm_core.h (struct rb_thread_struct): remove in_trap member.
* signal.c (signal_exec): ditto.
* thread.c (thread_create_core): ditto.
* thread.c (Init_Thread): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 11:45:39 +00:00
kosaki 6190bb4d8a * ruby_atomic.h (ATOMIC_CAS): new macro for compare-and-exchange.
* vm_core.h (struct rb_thread_struct): add interrupt_mask member.
* thread.c (thread_create_core, Init_Thread): initialize
  th->thread_mask.

* vm_core.h (RUBY_VM_INTERRUPTED_ANY): new macro for avoiding
  bare th->interrupt_flag.
* vm_core.h (RUBY_VM_INTERRUPTED, RUBY_VM_INTERRUPTED): check
  th->interrupt_mask.
* thread.c (set_unblock_function, rb_thread_schedule): replace
  th->interrupt_flag with RUBY_VM_INTERRUPTED_ANY()

* signal.c (signal_exec): set up thread->interrupt_mask for
  preventing recursive trap handler.
* vm_core.h (RUBY_VM_CHECK_INTS, RUBY_VM_CHECK_INTS_BLOCKING): ditto.

* thread.c (rb_threadptr_execute_interrupts):
  don't process interrupt if it is masked.
  [Bug #6009] [ruby-core:42524]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 10:57:39 +00:00
kosaki 7087153156 split trap interrupt and async interrupt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 09:22:01 +00:00
kosaki f150ed1532 * vm_core.h (rb_thread_struct): added 'in_trap' member for marking
running trap handler.
* signal.c (signal_exec): turn on in_trap when running trap.
* thread.c (Init_Thread, thread_create_core): initialize in_trap
  when creating new threads.
* thread.c (thread_join_m): raise ThreadError when running trap
  handler.Bug [#6416][ruby-core:44956]
* test/ruby/test_thread.rb (test_thread_join_in_trap): new test
  for the above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37852 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 08:05:49 +00:00
naruse 1dec7384d1 * Makefile.in (probes.o): add -C to ignore #include in probes.d.
* probes.d: include vm_opts.h instead of vm_core.h.

* vm_opts.h (VM_COLLECT_USAGE_DETAILS): move definition from vm_core.h.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37801 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-22 09:03:43 +00:00
kosaki 4d7e8b7305 * Makefile.in: run preprocessor when making probe.h
* probes.d: define probe insn and insn__operand only when
  VM_COLLECT_USAGE_DETAILS is 1. [Bug #7370]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-22 08:01:49 +00:00
ko1 cea7600b52 * include/ruby/debug.h: introdudced.
Debugging/profiling features will be located.
* vm_trace.c: expose C-level TracePoint APIs.
  Note that they are experimental.
* vm_trace.c, include/ruby/debug.h: rename `rb_hook_flag_t'
  to `rb_event_hook_flag_t'.
  Macro names `RUBY_HOOK_FLAG_*' are also renamed to
  `RUBY_EVENT_HOOK_FLAG_*'.
* debug.h, vm_debug.h: rename debug.h to vm_debug.h.
* common.mk: ditto.
* debug.c, main.c, vm_core.h: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37765 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-20 12:57:49 +00:00
ko1 553931962a * vm_trace.c: add two methods:
(1) TracePoint#return_value which returns return
  value on the :return and :c_return event.
  (2) TracePoint#raised_exception which returns raised exception
  value on the :raise event.
  Eeach methods raise RuntimeError if it is called at unsupported
  event.
  Please review and give us feedback until next preview
  release (Dec/2012) of Ruby 2.0.0.
* insns.def, vm.c, vm_eval.c, vm_insnhelper.c, eval.c, thread.c:
  ditto.
* vm_trace.c, vm_core.h: move definition of rb_trace_arg_t from
  vm_trace.c to vm_core.h.
  Caller fills rb_trace_arg_t and pass the pointer of this variable.
* test/ruby/test_settracefunc.rb: fix tests to test this change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-20 09:48:24 +00:00
kosaki b74e1b21db revert r37730
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37740 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-20 01:21:19 +00:00
kosaki 212150c2e1 * thread.c, vm_core.h: big rename th to cur_th when works only
th is current thread.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19 11:10:24 +00:00
ngoto 979dff3ee4 * vm_core.h, probes_helper.h (RUBY_DTRACE_FUNC_ENTRY_HOOK,
RUBY_DTRACE_FUNC_RETURN_HOOK): move from vm_core.h to new file
  probes_helper.h for narrowing dependency to probes.h.
* common.mk (VM_CORE_H_INCLUDES): remove dependency to probes.h.
* common.mk (vm.$(OBJEXT)): add dependency to probes_helper.h.
* vm.c, vm_insnhelper.c: include probes_helper.h.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37711 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-18 16:30:10 +00:00
tenderlove 4c740bae97 * probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.

* compile.c (rb_insns_name): allowing DTrace probes to access
  instruction sequence name.

* Makefile.in: translate probes.d file to appropriate header file.

* common.mk: declare dependencies on the DTrace header.

* configure.in: add a test for existence of DTrace.

* eval.c (setup_exception): add a probe for when an exception is
  raised.

* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
  end.

* hash.c (empty_hash_alloc): Add a probe for hash allocation.

* insns.def: Add probes for function entry and return.

* internal.h: function declaration for compile.c change.

* load.c (rb_f_load): add probes for `load` entry and exit, require
  entry and exit, and wrapping search_required for load path search.

* object.c (rb_obj_alloc): added a probe for general object creation.

* parse.y (yycompile0): added a probe around parse and compile phase.

* string.c (empty_str_alloc, str_new): DTrace probes for string
  allocation.

* test/dtrace/*: tests for DTrace probes.

* vm.c (vm_invoke_proc): add probes for function return on exception
  raise, hash create, and instruction sequence execution.

* vm_core.h: add probe declarations for function entry and exit.

* vm_dump.c: add probes header file.

* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
  function entry and return.

* vm_exec.c: expose instruction number to instruction name function.

* vm_insnshelper.c: add function entry and exit probes for cfunc
  methods.

* vm_insnhelper.h: vm usage information is always collected, so
  uncomment the functions.

12 19:14:50 2012  Akinori MUSHA  <knu@iDaemons.org>

* configure.in (isinf, isnan): isinf() and isnan() are macros on
  DragonFly which cannot be found by AC_REPLACE_FUNCS().  This
  workaround enforces the fact that they exist on DragonFly.

12 15:59:38 2012  Shugo Maeda  <shugo@ruby-lang.org>

* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
  vm_insnhelper.c (vm_search_method): revert r37616 because it's too
  slow.  [ruby-dev:46477]

* test/ruby/test_refinement.rb (test_inline_method_cache): skip
  the test until the bug is fixed efficiently.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-12 21:52:12 +00:00
shugo afdfbde4e7 * vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
  slow.  [ruby-dev:46477]

* test/ruby/test_refinement.rb (test_inline_method_cache): skip
  the test until the bug is fixed efficiently.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-12 07:00:12 +00:00
shugo ba5ea548ce * vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo):
add a new field for inline method cache.

* vm_insnhelper.c (vm_search_method): check rb_call_info_t::refinements
  not to confuse inline method cache when module_eval is used with
  refinements.

* test/ruby/test_refinement.rb: related test.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37616 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-11 02:42:04 +00:00
ngoto 05a05cc62b * ruby_atomic.h: renamed from atomic.h to avoid header file name conflict
on Solaris 10. [ruby-dev:46414] [Bug #7287]
* gc.c, signal.c, vm_core.h, common.mk: reflect the rename from atomic.h
  to ruby_atomic.h.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37604 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-09 16:05:07 +00:00
shirosaki d33b9a8a72 Fix compatibility of cached expanded load path
* file.c (rb_get_path_check_to_string): extract from
  rb_get_path_check(). We change the spec not to call to_path of
  String object.

* file.c (rb_get_path_check_convert): extract from rb_get_path_check().

* file.c (rb_get_path_check): follow the above change.

* file.c (rb_file_expand_path_fast): remove check_expand_path_args().
  Instead we call it in load.c.

* file.c (rb_find_file_ext_safe): use rb_get_expanded_load_path() to
  reduce expand cost.

* file.c (rb_find_file_safe): ditto.

* internal.h (rb_get_expanded_load_path): add a declaration.

* internal.h (rb_get_path_check_to_string, rb_get_path_check_convert):
  add declarations.

* load.c (rb_construct_expanded_load_path): fix for compatibility.
  Same checks in rb_get_path_check() are added. We don't replace
  $LOAD_PATH and ensure that String object of $LOAD_PATH are frozen.
  We don't freeze non String object and expand it every times. We add
  arguments for expanding load path partially and checking if load path
  have relative paths or non String objects.

* load.c (load_path_getcwd): get current working directory for checking
  if it's changed when getting load path.

* load.c (rb_get_expanded_load_path): fix for rebuilding cache properly.
  We check if current working directory is changed and rebuild expanded
  load path cache. We expand paths which start with ~ (User HOME) and
  non String objects every times for compatibility. We make this
  accessible from other source files.

* load.c (rb_feature_provided): call rb_get_path() since we changed
  rb_file_expand_path_fast() not to call it.

* load.c (Init_load): initialize vm->load_path_check_cache.

* vm.c (rb_vm_mark): mark vm->load_path_check_cache for GC.

* vm_core.h (rb_vm_struct): add vm->load_path_check_cache to store data
  to check load path cache validity.

* test/ruby/test_require.rb (TestRequire): add tests for require
  compatibility related to cached expanded load path.
  [ruby-core:47970] [Bug #7158]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37482 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-05 15:27:08 +00:00
shirosaki 9823c46189 Cache the expanded load path
* load.c (rb_get_expanded_load_path): cache the expanded load
  path.  This saves 4KB of allocation and some stats for every
  element of the load path (so nearly a MB in my Rails app)
  on every require.

* load.c (rb_construct_expanded_load_path): ensure that $LOAD_PATH
  entries are frozen strings.  The user must mutate $LOAD_PATH
  itself rather than its individual entries.

* vm_core.h (rb_vm_struct): add fields.

* vm.c (rb_vm_mark): mark new fields.

* ruby.c (process_options): modify $LOAD_PATH directly rather than
  its elements.
  Patch by Greg Price.
  [ruby-core:47970] [Bug #7158]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37481 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-05 15:27:05 +00:00
shirosaki b56a2afc14 Index $LOADED_FEATURES so that require isn't so slow
* load.c (rb_feature_p, rb_provide_feature): index $LOADED_FEATURES
  so that require isn't so slow.

* load.c (rb_provide_feature, get_loaded_features_index): ensure
  that $LOADED_FEATURES entries are frozen strings.  The user
  must mutate $LOADED_FEATURES itself rather than its individual
  entries.

* load.c (reset_loaded_features_snapshot): add a new function to reset
  vm->loaded_features_snapshot.

* load.c (get_loaded_features_index_raw): add a new function to get
  the loaded-features index.

* load.c (features_index_add_single): add a new function to add to the
  loaded-features index a single feature.

* load.c (features_index_add): add a new function to add to the
  loaded-features index all the required entries for `feature`.

* vm_core.h (rb_vm_struct): add fields.

* vm.c (rb_vm_mark): mark new fields.

* include/ruby/intern.h (rb_hash_clear): declare function.

* hash.c (rb_hash_clear): make function non-static.
  Patch by Greg Price.
  [ruby-core:47970] [Bug #7158]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-05 15:27:01 +00:00
ktsj 65b746bec0 * vm.c (rb_vm_rewrite_ep_in_errinfo, vm_rewrite_ep_in_errinfo):
merge code and remove `rb_vm_rewrite_ep_in_errinfo'.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-03 09:41:38 +00:00
ko1 9eba45a72a * vm_core.h, vm_insnhelper.c, vm_eval.c (OPT_CALL_CFUNC_WITHOUT_FRAME):
add a new otpimization and its macro `OPT_CALL_CFUNC_WITHOUT_FRAME'.
  This optimization makes all cfunc method calls `frameless', which
  is fster than ordinal cfunc method call.
  If `frame' is needed (for example, it calls another method with
  `rb_funcall()'), then build a frame. In other words, this
  optimization delays frame building.
  However, to delay the frame building, we need additional overheads:
  (1) Store the last call information.
  (2) Check the delayed frame buidling before the frame is needed.
  (3) Overhead to build a delayed frame.
  rb_thread_t::passed_ci is storage of delayed cfunc call information.
  (1) is lightweight because it is only 1 assignment to `passed_ci'.
  To achieve (2), we modify GET_THREAD() to check `passed_ci' every
  time. It causes 10% overhead on my envrionment.
  This optimization only works for cfunc methods which do not need
  their `frame'.
  After evaluation on my environment, this optimization does not
  effective every time. Because of this evaluation results, this
  optimization is disabled at default.
* vm_insnhelper.c, vm.c: add VM_PROFILE* macros to measure behaviour
  of VM internals. I will extend this feature.
* vm_method.c, method.h: change parameters of the `invoker' function.
  Receive `func' pointer as the first parameter.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-23 04:22:31 +00:00
ktsj f21d7d9831 * vm_core.h (rb_vm_t::trace_running): add a new field
`trace_running' to store vm global tracing status.

* vm_trace.c: fix SEGV bug. event_hook was free'd
  even when the hook is still used in another thread.
  [ruby-dev:46141] [Bug #7032]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-21 10:14:26 +00:00
ktsj 93184600c8 * vm_core.h (rb_vm_t::trace_flag): remove `trace_flag'
which is no longer used.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37279 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-21 10:14:24 +00:00
ko1 f4dbc7a384 * method.h (rb_method_cfunc_t::invoker): add new field (func ptr)
`invoker'. `invoker' function invoke cfunc body
  (rb_method_cfunc_t::func).
  `invoker' is set at method definition timing.
  With this change, the big `switch' (branch) in `call_cfunc()'
  is no longer needed.
  However, the performance benefit is only a bit.
* vm_core.h (rb_call_info_t::aux::func): add a new field to store
  cfunc body function pointer.
* vm_method.c (call_cfunc_invoker_func): add a new function which
  returns a suitable invoke function.
* vm_method.c (setup_method_cfunc_struct): added.
* vm_method.c (rb_add_method): fix to set `invoker'.
* vm_eval.c (vm_call0_body): catch up above changes.
* vm_insnhelper.c (call_cfunc): removed.
* vm_insnhelper.c (vm_call_cfunc): fix to call cfunc body
  with `invoker' function.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-19 10:38:30 +00:00
ko1 9a82db49eb * vm_insnhelper.c (vm_call_method_missing): make a refactoring
about method_missing process. Use `vm_call_method()' to invoke
  `method_missing' method instead of `rb_funcall2()'.
  In `vm_call_method()', set fastpath to `vm_call_method_missing()'
  if it can be cached.
* vm_core.h (rb_call_info_t): add new field
  `rb_call_info_t::aux::missing_reasion' to pass the reason to
  `vm_call_method_missing()'.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-17 07:12:40 +00:00
ko1 db1e99cdad * vm_insnhelper.c (vm_getivar, vm_setivar): support index inline cache
with rb_call_info_t to speedup `attr' getter and setter.
  Cached index is stored in rb_call_info_t::aux::index.
  `index' == 0 means not cached. `index' > 0 means cached and cached
  index is `index - 1'.
* insns.def ((get|set)instancevariable): use new wrapper functions
  vm_(get|set)instancevariable() defined in vm_insnhelper.c.
* vm_core.h (rb_call_info_t::aux): introduce new union data because
  opt_pc can share with index.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-16 17:07:23 +00:00
ko1 a91e91c537 * vm_core.h (VM_CALL_*): rename VM_CALL_*_BIT
to VM_CALL_* (remove `_BIT' suffix).
  Add comments on each macros.
  Remove unused macro VM_CALL_TAILRECURSION_BIT.
* compile.c, iseq.c, insns.def, vm_insnhelper.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-15 17:22:57 +00:00
ko1 8f08e61bad * vm_insnhelper.c: refactoring.
- move all `call' related functions to the last of file.
  - make functions for respective method types in vm_call_method().
  (all functions have same function parameters)
* vm_core.h: add `opt_pc' filed in `rb_call_info_t'
  as temporal variable.
* vm_eval.c (vm_call0_body): catch up above cahnges.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37185 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 19:58:59 +00:00
ko1 cbd597e9bc * insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
  parameters such as `op_id', 'op_argc', `blockiseq' and flag.
  These information are stored in rb_call_info_t at the compile
  time.
  This technique simplifies parameter passings at related
  function calls (~10% speedups for simple mehtod invocation at
  my machine).
  `rb_call_info_t' also has new function pointer variable `call'.
  This `call' variable enables to customize method (block)
  invocation process for each place. However, it always call
  `vm_call_general()' at this changes.
  `rb_call_info_t' also has temporary variables for method
  (block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
  VM_CALL macro.  This flag indicates that this call can skip
  caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
  parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 16:59:05 +00:00
ko1 7ea3edc409 * vm_core.h (rb_call_info_t): add new type `rb_call_inf_t'.
This data structure contains information including inline method
  cache. After that, `struct iseq_inline_cache_entry' does not
  need to contain inline cache for method invocation.
  Other information will be added to this data structure.
* vm_core.h (rb_iseq_t): add `callinfo_entries' and `callinfo_size'
  members to `rb_iseq_t'.
* insns.def, compile.c: Use CALL_INFO instead of IC.
* tool/instruction.rb: support CALL_INFO as operand type.
* vm_insnhelper.c, vm_insnhelper.h: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-09 05:33:54 +00:00
ko1 64f5b6aedc * vm_core.h: now VM_DEBUG_BP_CHECK should be 1.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-09-28 04:16:59 +00:00
ko1 d50483df23 * vm_core.h: remove rb_control_frame_t::bp (bp: base pointer).
`bp' can be calculate by `sp' (stack pointer) of previous frame.
  Now, `bp_check' field is remained for debug.  You can eliminate
  this field by setting  VM_DEBUG_BP_CHECK as 0.
* vm_insnhelper.c (vm_base_ptr): add `vm_base_ptr(cfp).
  This function calculates base pointer from cfp.
* vm_insnhelper.c (vm_setup_method): push `recv' value on top of
  value stack (before method parameters).
  This change is for keeping consistency with normal method dispatch.
* insns.def: fix to use vm_base_ptr().
* vm.c (vm_exec): ditto.
* vm_dump.c: remove `bp' related dumps.
* cont.c (fiber_init): fix to check VM_DEBUG_BP_CHECK.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-09-28 04:05:36 +00:00
nobu 2314b80d4c Feature #7035
* compile.c (defined_expr), insns.def (defined): share single frozen
  strings.  [EXPERIMENTAL] [ruby-core:47558][Feature #7035]
* iseq.c (rb_iseq_defined_string): make expression strings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-09-24 08:36:53 +00:00
nobu 68f3ece33f suppress warnings
* insns.def (checkmatch): suppress warnings.  [ruby-core:47310]
  [Bug #6930]
* vm_core.h (VM_FRAME_TYPE_FINISH_P): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-26 07:53:21 +00:00
nobu ceece4650a vm_insnhelper.c: iclass as klass in cfp
* vm_insnhelper.c (vm_call_method): follow iclasses as klass in cfp
  but not included modules.  [ruby-core:47241] [Bug #6891]
* vm_insnhelper.c (vm_call_bmethod): pass defined_class to follow
  proper ancestors.  [ruby-core:47241] [Bug #6891]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-20 11:36:34 +00:00
ko1 4a4a702e61 * vm_trace.c, vm_core.h: simplify tracing mechanism.
(1) add rb_hook_list_t data structure which includes
  hooks, events (flag) and `need_clean' flag.
  If the last flag is true, then clean the hooks list.
  In other words, deleted hooks are contained by `hooks'.
  Cleanup process should run before traversing the list.
  (2) Change check mechanism
  See EXEC_EVENT_HOOK() in vm_core.h.
  (3) Add `raw' hooks APIs
  Normal hooks are guarded from exception by rb_protect().
  However, this protection is overhead for too simple
  functions which never cause exceptions.  `raw' hooks
  are executed without protection and faster.
  Now, we only provide registration APIs.  All `raw'
  hooks are kicked under protection (same as normal hooks).
* include/ruby/ruby.h: remove internal data definition and
  macros.
* internal.h (ruby_suppress_tracing), vm_trace.c: rename
  ruby_suppress_tracing() to rb_suppress_tracing()
  and remove unused function parameter.
* parse.y: fix to use renamed rb_suppress_tracing().
* thread.c (thread_create_core): no need to set RUBY_VM_VM.
* vm.c (mark_event_hooks): move definition to vm_trace.c.
* vm.c (ruby_vm_event_flags): add a global variable.
  This global variable represents all of Threads and VM's
  event masks (T1#events | T2#events | ... | VM#events).
  You can check the possibility kick trace func or not
  with ruby_vm_event_flags.
  ruby_vm_event_flags is maintained by vm_trace.c.
* cont.c (fiber_switch, rb_cont_call): restore tracing status.
  [Feature #4347]
* test/ruby/test_continuation.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-16 11:41:24 +00:00
ko1 93b6f8d619 * compile.c, insns.def (checkmatch):
remove checkincludearray instruction and
  add new instruction checkmatch.
  This change is to solve
  [Bug #4438] "rescue args type check omitted".
* iseq.c: increment ISEQ_MAJOR_VERSION because removal of
  checkincludearray instruction.
* vm_core.h: add several definitions for
  the checkmatch instruction.
* vm_insnhelper.c (check_match): added.
* bootstraptest/test_exception.rb: add a test.
* test/ruby/test_exception.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-08 07:52:19 +00:00
ko1 0d1a905edb * vm_exec.c, insns.def (leave): solve problems on
OPT_CALL_THREADED_CODE.
  Catch up finish frame structure on OPT_CALL_THREADED_CODE.
* vm_core.h: add rb_thread_t#retval for temporary space on
  OPT_CALL_THREADED_CODE.
* vm.c (th_init): clear rb_thread_t#retval as Qundef.
* vm_dump.c (rb_vmdebug_debug_print_pre): fix debug print format.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-07 11:13:57 +00:00
shugo 319088e9c7 * class.c, insns.def, method.h, proc.c, vm.c, vm_core.h, vm_eval.c,
vm_insnhelper.c, vm_insnhelper.h, vm_method.c: add klass to
  rb_control_frame_t to implement super correctly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-02 11:08:44 +00:00
ko1 f4a8db647a * thread.c (rb_thread_s_control_interrupt,
rb_thread_s_check_interrupt): added for
  Thread.control_intgerrupt and Thread.check_interrupt.
  See details on rdoc.
  I'll make an ticket for this feature.
* test/ruby/test_thread.rb: add a test for Thread.control_intgerrupt.
* thread.c (rb_threadptr_raise): make a new exception object
  even if argc is 0.
* thread.c (rb_thread_kill): kill thread immediately if target thread
  is current thread.
* vm_core.h (RUBY_VM_CHECK_INTS_BLOCKING): added.
  CHECK_INTS while/after blocking operation.
* vm_core.h (RUBY_VM_CHECK_INTS): require rb_thread_t ptr.
* cont.c (fiber_switch): use replaced RUBY_VM_CHECK_INTS().
* eval.c (ruby_cleanup): ditto.
* insns.def: ditto.
* process.c (rb_waitpid): ditto.
* vm_eval.c (vm_call0): ditto.
* vm_insnhelper.c (vm_call_method): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36470 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-19 14:19:40 +00:00
ko1 28144433b2 * thread.c (rb_threadptr_async_errinfo_*): manage async errors queue.
Async events such as an exception throwed by Thread#raise,
  Thread#kill and thread termination (after main thread termination)
  will be queued to th->async_errinfo_queue.
  - clear: clear the queue.
  - enque: enque err object into queue.
  - deque: deque err object from queue.
  - active_p: return 1 if the queue should be checked.
  rb_thread_t#thrown_errinfo was removed.
* vm_core.h: add declarations of rb_threadptr_async_errinfo_*.
  remove rb_thread_t#thrown_errinfo field and
  add rb_thread_t#async_errinfo_queue (queue body: Array),
  rb_thread_t#async_errinfo_queue_checked (flag),
  rb_thread_t#async_errinfo_mask_stack(Array, not used yet).
* vm.c (rb_thread_mark): fix a mark function.
* cont.c (rb_fiber_start): enque an error.
* process.c (after_fork): clear async errinfo queue.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-18 05:46:40 +00:00
ko1 c4bc9b5758 * iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
  and (c) setting up the frame to execute the program passed by
  `eval' method.  For example, (1) parser need to know up-level
  variables to detect it is variable or method without paren.
  Befor (a), (b) and (c), VM set th->base_block by passed bindng
  (or previous frame information).  After execute (a), (b) and (c),
  VM should clear th->base_block.  However, if (a), (b) or (c)
  raises an exception, then th->base_block is not cleared.
  Problem is that the uncleared value th->balo_block is used for
  irrelevant iseq compilation.  It causes SEGV or critical error.
  I tried to solve this problem: to clear them before exception,
  but finally I found out that it is difficult to do it (Ruby
  program can be run in many places).
  Because of this background, I set th->base_block before
  compiling iseq and restore it after compiling.
  Basically, th->base_block is dirty hack (similar to global
  variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
  set th->base_block before compation and restore it after
  compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
  setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 09:32:56 +00:00
ko1 745c23b2d9 * vm_core.h: remove VM_FRAME_MAGIC_FINISH (finish frame type).
Before this commit:
  `finish frame' was place holder which indicates that VM loop
  needs to return function.
  If a C method calls a Ruby methods (a method written by Ruby),
  then VM loop will be (re-)invoked.  When the Ruby method returns,
  then also VM loop should be escaped.  `finish frame' has only
  one instruction `finish', which returns VM loop function.
  VM loop function executes `finish' instruction, then VM loop
  function returns itself.
  With such mechanism, `leave' instruction (which returns one
  frame from current scope) doesn't need to check that this `leave'
  should also return from VM loop function.
  Strictly, one branch can be removed from `leave' instructon.
  Consideration:
  However, pushing the `finish frame' needs costs because
  it needs several memory accesses.  The number of pushing
  `finish frame' is greater than I had assumed.  Of course,
  pushing `finish frame' consumes additional control frame.
  Moreover, recent processors has good branch prediction,
  with which we can ignore such trivial checking.
  After this commit:
  Finally, I decide to remove `finish frame' and `finish'
  instruction.  Some parts of VM depend on `finish frame',
  so the new frame flag VM_FRAME_FLAG_FINISH is introduced.
  If this frame should escape from VM function loop, then
  the result of VM_FRAME_TYPE_FINISH_P(cfp) is true.
  `leave' instruction checks this flag every time.
  I measured performance on it.  However on my environments,
  it improves some benchmarks and slows some benchmarks down.
  Maybe it is because of C compiler optimization parameters.
  I'll re-visit here if this cause problems.
* insns.def (leave, finish): remove finish instruction.
* vm.c, vm_eval.c, vm_exec.c, vm_backtrace.c, vm_dump.c:
  apply above changes.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-15 10:22:34 +00:00
nobu 073297789a fix r36079
* include/ruby/ruby.h: public symbols must have default visibility.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-14 03:03:48 +00:00
yugui f8601bd903 * eval.c: Add doxygen comments.
* ruby.c: ditto.

* thread_pthread.c: ditto

* version.c: ditto.

* vm_core.h: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36078 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-14 02:21:51 +00:00
ko1 0a71db8a74 * vm_core.h: remove lfp (local frame pointer) and rename
dfp (dynamic frame pointer) to ep (environment pointer).
  This change make VM `normal' (similar to other interpreters).
  Before this commit:
  Each frame has two env pointers lfp and dfp.  lfp points
  local environment which is method/class/toplevel frame.
  lfp[0] is block pointer.
  dfp is block local frame. dfp[0] points previous (parent)
  environment pointer.
  lfp == dfp when frame is method/class/toplevel.
  You can get lfp from dfp by traversing previous environment
  pointers.
  After this commit:
  Each frame has only `ep' to point respective enviornoment.
  If there is parent environment, then ep[0] points parent
  envioenment (as dfp).  If there are no more environment,
  then ep[0] points block pointer (as lfp).  We call such ep
  as `LEP' (local EP).  We add some macros to get LEP and to
  detect LEP or not.
  In short, we replace dfp and lfp with ep and LEP.
  rb_block_t and rb_binding_t member `lfp' and `dfp' are removed
  and member `ep' is added.
  rename rb_thread_t's member `local_lfp' and `local_svar' to
  `root_lep' and `root_svar'.
  (VM_EP_PREV_EP(ep)): get previous environment pointer.  This macro
  assume that ep is not LEP.
  (VM_EP_BLOCK_PTR(ep)): get block pointer.  This macro assume
  that ep is LEP.
  (VM_EP_LEP_P(ep)): detect ep is LEP or not.
  (VM_ENVVAL_BLOCK_PTR(ptr)): make block pointer.
  (VM_ENVVAL_BLOCK_PTR_P(v)): detect v is block pointer.
  (VM_ENVVAL_PREV_EP_PTR(ptr)): make prev environment pointer.
  (VM_ENVVAL_PREV_EP_PTR_P(v)): detect v is prev env pointer.
* vm.c: apply above changes.
  (VM_EP_LEP(ep)): get LEP.
  (VM_CF_LEP(cfp)): get LEP of cfp->ep.
  (VM_CF_PREV_EP(cfp)): utility function VM_EP_PREV_EP(cfp->ep).
  (VM_CF_BLOCK_PTR(cfp)): utility function VM_EP_BLOCK_PTR(cfp->ep).
* vm.c, vm_eval.c, vm_insnhelper.c, vm_insnhelper.h, insns.def:
  apply above changes.
* cont.c: ditto.
* eval.c, eval_intern.h: ditto.
* proc.c: ditto.
* thread.c: ditto.
* vm_dump.c: ditto.
* vm_exec.h: fix function name (on vm debug mode).



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-11 03:14:59 +00:00
ko1 06513cc1cf * vm_insnhelper.h: remove magical code "lfp[0] & 0x02".
Current VM doesn't use this bit.
* vm_core.h (RUBY_VM_GET_BLOCK_PTR): added.
* eval.c (rb_block_given_p): use RUBY_VM_GET_BLOCK_PTR().
* vm_eval.c (rb_f_block_given_p): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-04 07:24:44 +00:00
ko1 bac9f65f70 * vm_core.h (rb_location_t): fix type and field name.
(1) rename rb_location_t to rb_iseq_location_t.
  (2) rename field names of rb_iseq_location_t to adjust
  RubyVM::Backtrace::Location methods.
  (2-1) filename -> path
  (2-2) filepath -> absolute_path
  (2-3) basename -> base_label
  (2-4) name -> label
  (3) rename filed name rb_iseq_location_t#line_no to
  rb_iseq_location_t#first_lineno to clear purpose of this field.
  (4) The field names rb_binding_t#(filename|line_no) are also renamed
  to rb_binding_t#(path|first_lineno).
* compile.c: apply above changes.
* iseq.c: ditto.
* proc.c: ditto.
* vm*.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-04 02:49:37 +00:00
ko1 b57c81ae3e * common.mk: fix to build vm_backtrace.c only itself (vm_backtrace.c
is no longer included from vm.c).  I hope this separation reduce
  compile time of vm.c.
* internal.h: ditto.
* vm.c, vm_core.h, vm_dump.c, vm_eval.c: ditto.
* vm_eval.c: some functions (callee, etc) moved to vm_backtrace.c.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-02 15:59:37 +00:00
ko1 1f3142a447 * vm.c: refactoring backtrace related funcitons.
(1) unify similar functions (rb_backtrace_each() and
  backtrace_object()).  backtrace_each() is a unified function.
  variation:
  a) backtrace_object(): create backtrace object.
  b) vm_backtrace_str_ary(): create bt as an array of string.
  c) vm_backtrace_print(): print backtrace to specified file.
  d) rb_backtrace_print_as_bugreport(): print backtrace on
  bugreport style.
  (2) remove rb_backtrace_each().  Use backtrace_each() instead.
  (3) chang the type of lev parameter to size_t.
  a) lev == 0 means current frame (exception, etc use it).
  b) lev == 1 means upper frame (caller(0) use it).
* vm_core.h, vm_dump.c, vm_eval.c: ditto.
* vm.c (backtrace_object(), vm_backtrace_str_ary()): fix to return a
  correct size of caller(lev) array.
  Let n be a "caller(0).size" then ln as caller(lev).size should be
  (n - lev).  However, the previous implementation returns a wrong
  size array (ln > n - lev).  [ruby-dev:45673]
* test/ruby/test_backtrace.rb: add tests for backtrace.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35787 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-25 04:50:10 +00:00
nobu cb61ea5ef3 remove trailing spaces
* vm_core.h (rb_iseq_struct): remove trailing spaces.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-22 13:20:52 +00:00
ko1 8bcf7fc402 * vm_core.h: add a data type rb_location_t to store iseq location
information.
  rb_location_t#filename, filepath, name and line_no was moved from
  rb_iseq_t.  rb_location_t#basename is a new field which is
  similar to `name' field without any decoration.
  `name' field contains some decoration such as `block in foo'.
  `basename' only contains `foo'.
  rb_iseq_t contains memory object of rb_location_t.
* iseq.c: setup rb_location_t for each rb_iseq_t memory objects.
* compile.c, proc.c, vm.c, vm_dump.c, vm_eval.c, vm_insnhelper.c,
  vm_method.c: support about it.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-22 08:31:38 +00:00
yugui 76bc2d1ed7 Imports Ruby's port to NativeClient (a.k.a NaCl).
Patch by Google Inc. [ruby-core:45073].

* configure.in (RUBY_NACL): New M4 func to configure variables for
  NaCl.
  (RUBY_NACL_CHECK_PEPPER_TYPES): New M4 func to check the old names
  of Pepper interface types.
  (BTESTRUBY): New variable to specify which ruby should be run on
  "make btest". NaCl can run the built binary by sel_ldr, but it need
  rbconfig.rb. So this variable is distinguished from $MINIRUBY.
  
* thread_pthread.c: Disabled some features on NaCl.

* io.c: ditto.

* process.c: ditto.

* signal.c: ditto.

* file.c: ditto.

* missing/flock.c: ditto.

* nacl/pepper_main.c: An example implementation of Pepper application
  that embeds Ruby.

* nacl/example.html: An example of web page that uses the Pepper
  application.

* nacl/nacl-config.rb: Detects variants of NaCl SDK.

* nacl/GNUmakefile.in: Makefile template for NaCl specific build
  process.

* nacl/package.rb: script for packaging a NaCl-Ruby embedding
  application. 

* nacl/reate_nmf.rb: Wrapper script of create_nmf.py

* dln.c (dln_load): Added a hack to call on NaCl.

* util.c (ruby_getcwd): Path to the current directort is not available
  on NaCl.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-17 02:48:59 +00:00
ko1 6978b8ca67 * vm_core.h (rb_thread_t#yielding): add a field.
* thread.c (rb_thread_schedule_limits): set th#yielding while
  release GVL to yield CPU time.
* thread.c (timer_thread_function): skip timer interrupt when
  th#yielding is true.  This patch fixes r35480.
* thread.c (rb_threadptr_execute_interrupts_common): revert
  a patch of r35480.
* ChangeLog: add an extended memo of r35480.
  http://bugs.ruby-lang.org/projects/ruby-trunk/wiki/R35480_ExtendedMemo



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-04-28 09:59:44 +00:00
nobu e2ca7837d1 * iseq.c (rb_iseq_first_lineno): constified.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35051 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-16 03:00:00 +00:00
marcandre 6c38e611e4 * vm_core.h: Fix comment about arg_opts of iseq and some typos
* doc/re.rdoc: Rdoc small fixes

* iseq.c: Fix comment

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-30 05:55:37 +00:00
mame d0baa0dd52 * vm_core.h (struct rb_iseq_struct), compile.c (iseq_set_arguments), iseq.c (rb_iseq_parameters), vm_insnhelper.c (vm_callee_setup_arg_complex): support Method#parameters for keyword arguments. The provisional spec is what Benoit Daloze proposed. [ruby-core:40518]
* test/ruby/test_keyword.rb: add a test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-26 14:20:15 +00:00
mame a0a2c144b8 * vm_core.h (struct rb_iseq_struct), compile.c (iseq_set_arguments, iseq_compile_each), vm_insnhelper.c (vm_callee_setup_arg_complex): implement keyword arguments. See [ruby-core:40290] The feature is promised to be included in 2.0, but the detail spec is still under discussion; this commit is a springboard for further discussion. Please try it and give us feedback. This commit includes fixes for some problems reported by Benoit Daloze <eregontp AT gmail.com> [ruby-core:40518] and Marc-Andre Lafortune <ruby-core-mailing-list AT marc-andre.ca> [ruby-core:41772].
* iseq.c (iseq_free, prepare_iseq_build): bookkeeping.

* test/ruby/test_keyword.rb: add tests for keyword arguments.

* test/ripper/dummyparser.rb (class DummyParser): temporal fix for
  ripper test.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34136 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-26 14:20:09 +00:00
nobu eb21db77c0 * vm_core.h (ruby_current_thread): probeprofiler has been removed
long ago.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33475 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-10-18 14:07:32 +00:00
ktsj 0971109e3d * vm.c (rb_vm_rewrite_dfp_in_errinfo): change return type
to suppress a warning.

* vm_core.h: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-08-27 11:51:02 +00:00
ktsj a09e7139a3 * proc.c (proc_new): force to rewrite errinfo when calling Proc.new in ensure.
[Bug #5234] [ruby-core:39125]
  This code will be removed after changing throw mechanism (see r33064).

* vm.c (rb_vm_rewrite_dfp_in_errinfo): new function.

* vm.c (vm_make_env_each): changed accordingly.

* vm_core.h: ditto.

* bootstraptest/test_flow.rb: add tests for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-08-27 09:59:48 +00:00
ko1 5d486bec61 * vm_core.h: add a decl. of rb_autoloading_value().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-08-26 19:03:21 +00:00
ko1 7049d9c80d * iseq.h, iseq.c, compile.c: Change the line number data structure
to solve an issue reported at [ruby-dev:44413] [Ruby 1.9 - Bug #5217].
  Before this fix, each instruction has an information including
  line number (iseq::iseq_insn_info_table).  Instead of this data
  structure, recording only line number changing places
  (iseq::iseq_line_info_table).
  The order of entries in iseq_line_info_table is ascending order of
  iseq_line_info_table_entry::position.  You can get a line number
  by an iseq and a program counter with this data structure.
  This fix reduces memory consumption of iseq (bytecode).
  On my measurement, a rails application consumes 21.8MB for
  iseq with this fix on the 32bit CPU.  Without this fix, it
  consumes 24.7MB for iseq [ruby-dev:44415].
* proc.c: ditto.
* vm_insnhelper.c: ditto.
* vm_method.c: ditto.
* vm.c (rb_vm_get_sourceline): change to use rb_iseq_line_no().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-08-24 06:31:15 +00:00
nobu 0dee7247a7 * vm.c (ruby_threadptr_data_type): rename to hide.
[ruby-core:38972]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-08-16 09:56:56 +00:00
kosaki ac397a9eee * vm_core.h (ALT_STACK_SIZE): use MINSIGSTKSZ*2 instead of SIGSTKSZ*2.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-30 02:22:51 +00:00
kosaki 18bc6c31a1 * vm.c (th_init): preallocate alternative stack.
NoMemoryError is better than rb_bug, of course.
  Patch by Eric Wong. [ruby-core:38572][ruby-core:38594].

* signal.c (rb_register_sigaltstack): ditto.

* vm_core.h: moved ALT_STACK_SIZE definition from signal.c.
* vm.c (thread_free): use xfree() instead of free().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32749 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-30 01:57:06 +00:00
mame 9a27239558 * proc.c (struct METHOD), gc.c (gc_marks), vm_method.c
(rb_gc_mark_unlinked_live_method_entries): fix SEGV bug.
  rb_method_entry_t was free'd even when the method is still on the
  stack if it is BMETHOD (i.e., Method#call).  This is because
  rb_method_entry_t is embedded in struct METHOD.  This commit
  separates them and marks the live method entries.
  See [ruby-core:38449] in detail.  fix [Bug #5047] [ruby-core:38171]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32669 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-25 14:29:28 +00:00
kosaki 74b339e938 * thread_pthread.c (rb_thread_create_timer_thread): removed
rb_disable_interrupt()/rb_enable_interrupt().
* vm_core.h: ditto.
* process.c (static void before_exec): ditto.
* process.c (static void after_exec): ditto.
  [Bug #4765] [ruby-dev:43571]

* eval_intern.h: removed rb_trap_restore_mask().
* vm_eval.c (rb_throw_obj): ditto.
* eval.c (setup_exception): ditto.

* signal.c: removed trap_last_mask.
* signal.c (trap_restore_mask): removed.
* signal.c (init_sigchld): comment clarification why signal block
  is needed. and removed trap_last_mask operation.
* signal.c (trap_ensure): removed trap_last_mask operation.

* signal.c (rb_disable_interrupt, rb_enable_interrupt): made
  static and removed sigdelset(SIGVTALARM) and sigdelset(SIGSEGV).

* process.c (rb_syswait): removed implicit signal handler change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-10 17:04:40 +00:00
kosaki a119b9d146 * vm_core.h (typedef struct rb_vm_struct): create a new
'inhibit_thread_createion' field.
* thread.c (rb_thread_terminate_all): set inhibit_thread_creation.
* thread.c (thread_s_new): don't permit to create new thread
  if the VM is under destruction. Otherwise evil finalizer code
  can make SEGV. [Bug #4992][ruby-core:37858]

* bootstraptest/test_objectspace.rb: new test for this fix.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-10 07:46:00 +00:00
kosaki 8741274529 * thread.c (thread_unlock_all_locking_mutexes): rename to
rb_threadptr_unlock_all_locking_mutexes and remove static.
* vm_core.h: add rb_threadptr_unlock_all_locking_mutexes declaration.
* thread.c (thread_start_func_2): adjust the above rename.

* eval.c (ruby_cleanup): call rb_threadptr_unlock_all_locking_mutexes
  again after finalizer. [Bug #4988] [ruby-dev:44049]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-08 04:40:01 +00:00
ko1 fa4514e4fe * thread.c (rb_threadptr_check_signal): only wake up main thread.
* thread.c (rb_threadptr_execute_interrupts_common): check signal
  deliverly if it is main thread.
  fixes [ruby-dev:44005] [Ruby 1.9 - Bug #4950]
* bootstraptest/test_fork.rb: add a test for above.
* signal.c (rb_get_next_signal): skip if signal_buff is empty.
  (check signal_buff.size first)
* vm_core.h: remove unused variable rb_thread_t::exec_signal.
* thread.c (rb_thread_check_trap_pending): check
  rb_signal_buff_size() because rb_thread_t::exec_signal
  is no longer available.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32345 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-30 22:29:34 +00:00
ko1 d1d5d5e798 * thread_pthread.c: Stop polling in the timer thread when there are
no waiting thread.  If there are 2 or more runnable threads,
  the timer thread does polling.  Avoid polling makes power save
  for several computers (0.2W per a Ruby process, when I measured).
  If outside-event such as signal or Thread#kill was occuerred
  when the timer thread does not do polling, then wake-up
  the timer thread using communication-pipe (the timer thread
  waits this communication-pipe with select(2)).
  The discussion about this modification can be found from the post
  [ruby-core:33456] and other related posts.
  Note that Eric Wong and KOSAKI Motohiro give us the huge
  contributions for this modification.  Thanks.
* thread_pthread.c (rb_thread_wakeup_timer_thread): add a function.
  This function wakes up the timer thread using communication-pipe.
* thread.c (rb_thread_stop_timer_thread): add a parameter which
  specify closing communication-pipe or not.
* thread.c (rb_thread_terminate_all): do not stop timer thread here
  (ruby_cleanup() terminate timer thread).
* signal.c: wake up timer thread using
  rb_thread_wakeup_timer_thread() from signal handler.
* eval.c (ruby_cleanup): use rb_thread_stop_timer_thread(1).
* process.c: use rb_thread_stop_timer_thread(0)
  (reuse communication-pipe).
* thread_win32.c (rb_thread_wakeup_timer_thread): add a dummy
  function.
* vm_core.h: add and fix decl. of functions.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-27 00:30:41 +00:00
kosaki ef86308a2c * vm.c, vm_core.h (rb_vm_stack_to_heap): remove const.
It makes compilations warnings.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-18 12:32:57 +00:00
ko1 4368104146 * vm.c, vm_core.h (rb_vm_stack_to_heap): fix "const" place.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-18 09:56:01 +00:00
akr 5ed8c08aa0 * eval.c, hash.c, load.c, proc.c, range.c, thread.c, time.c: don't
declare internal functions.

* internal.h, vm_core.h: declare internal functions.

* array.c: include internal.h.

* common.mk: update dependency for array.o.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-18 08:26:19 +00:00
akr e7996eb3cc * internal.h: declare internal functions here.
* node.h: declare NODE dependent internal functions here.

* iseq.h: declare rb_iseq_t dependent internal functions here.

* vm_core.h: declare rb_thread_t dependent internal functions here.

* bignum.c, class.c, compile.c, complex.c, cont.c, dir.c, encoding.c,
  enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c, io.c,
  iseq.c, load.c, marshal.c, math.c, numeric.c, object.c, parse.y,
  proc.c, process.c, range.c, rational.c, re.c, ruby.c, string.c,
  thread.c, time.c, transcode.c, variable.c, vm.c,
  tool/compile_prelude.rb: don't declare internal functions declared
  in above headers.  include above headers if required.

  Note that rb_thread_mark() was declared as
  void rb_thread_mark(rb_thread_t *th) in cont.c but defined as
  void rb_thread_mark(void *ptr) in vm.c.  Now it is declared as
  the later in internal.h.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-17 22:43:38 +00:00
kosaki bcfc22b10e * thread_pthread.c: rewrite GVL completely.
* thread_win32.c: ditto.
* thread_pthread.h: ditto.
* vm_core.h: ditto.
* thread.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-13 14:14:53 +00:00
ko1 038ef3f05c * vm_core.h, vm_insnhelper.h: move decl. of
ruby_vm_global_state_version and related macros
  from vm_core.h to vm_insnhelper.h.
* vm.c (vm_clear_all_cache): added.  This function is called
  when ruby_vm_global_state_version overflows.
  TODO: vm_clear_all_inline_method_cache() is only place holder.
  We need to implement it ASAP.
* vm_method.c (vm_clear_global_method_cache): added.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32056 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-13 11:25:44 +00:00
kosaki f0041fa0fd * thread.c: remove th->transition_for_lock. It's thread unsafe.
[Bug #4723][ruby-dev:43563]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-12 06:58:15 +00:00
kosaki 9d4e471cf9 * vm_core.h (RUBY_VM_SET_TIMER_INTERRUPT, RUBY_VM_SET_INTERRUPT,
RUBY_VM_SET_FINALIZER_INTERRUPT): use atomic ops for preventing
  interrupt_flag bit lost.
* thread.c (rb_threadptr_execute_interrupts_rec): ditto.
* vm_core.h (typedef struct rb_thread_struct): change type of
  interrupt_flag to rb_atomic_t.
* atomic.h: move atomic ops definition from signal.c.
* signal.c: remove atomic ops definition.
* common.mk (gc, signal, thread, cont): add to dependency to atomic.h.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-11 14:27:08 +00:00