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

221 Коммитов

Автор SHA1 Сообщение Дата
ko1 4a4627fb0d move "state" to rb_vm_tag.
* vm_core.h (rb_thread_t::tag_state): move to "rb_vm_tag::state".
  Lifetime of "state" should be same as current tag.


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


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-23 08:48:41 +00:00
ko1 2108e55c0b use "enum ruby_tag_type" and TAG_NONE.
Return value of EXEC_TAG() is saved by "int state".
Instead of "int", use "enum ruby_tag_type". First EXEC_TAG()
value should be 0, so that define TAG_NONE (= 0) and use it.

Some code used "status" instead of "state". To make them clear,
rename them to state.

We can change variable name from "state" to "tag_state", but this
ticket doesn't contain it.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-23 07:25:52 +00:00
ko1 478003f6df rename absolute_path to realpath internally and introduce pathobj.
* vm_core.h: rename absolute_path to realpath because it is expected name.
  external APIs (#absolute_path methods) are remained.

* vm_core.h: remove rb_iseq_location_struct::path and
  rb_iseq_location_struct::absolute_path and introduce pathobj.
  if given path equals to given absolute_path (and most of case
  it is true), pathobj is simply given path String. If it is not same,
  pathobj is Array and pathobj[0] is path and pathobj[1] is realpath.

  This size optimization reduce 8 bytes and
  sizeof(struct rb_iseq_constant_body) is 200 bytes -> 192 bytes
  on 64bit CPU.

  To support this change, the following functions are introduced:
    * pathobj_path() (defined in vm_core.h)
    * pathobj_realpath() (ditto)
    * rb_iseq_path() (decl. in vm_core.h)
    * rb_iseq_realpath() (ditto)
    * rb_iseq_pathobj_new() (ditto)
    * rb_iseq_pathobj_set() (ditto)

* vm_core.h (rb_binding_t): use pathobj instead of path. If binding
  is given at eval methods, realpath (absolute_path) was caller's
  realpath. However, they should use binding's realpath.


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

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

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

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

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

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

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

### Test Code
require 'benchmark/ips'

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

Benchmark.ips do |x|

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

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

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

end

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

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58614 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-09 05:06:41 +00:00
shugo 472959f9c2 Add clang volatile fixes from FreeBSD and NetBSD.
Use volatile instead of optnone to avoid optimization which causes
segmentation faults.
Patch by Dimitry Andric.  [ruby-core:78531] [Bug #13014]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-07 23:27:51 +00:00
ktsj 9cbd6ee097 * vm_trace.c (tracepoint_attr_callee_id, rb_tracearg_callee_id):
add TracePoint#callee_id. [ruby-core:77241] [Feature #12747]

* cont.c, eval.c, gc.c, include/ruby/intern.h, insns.def, thread.c,
  vm.c, vm_backtrace.c, vm_core.h, vm_eval.c, vm_insnhelper.c, vm_trace.c: ditto.

* test/ruby/test_settracefunc.rb: tests for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 13:15:27 +00:00
ko1 0cd7f5fe87 * vm_core.h: rename macros and make them inline functions.
* rename VM_FRAME_TYPE_FINISH_P() to VM_FRAME_FINISHED_P().
  * rename VM_FRAME_TYPE_BMETHOD_P() to VM_FRAME_BMETHOD_P().


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55803 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-03 00:28:12 +00:00
ko1 be5564a178 * vm_insnhelper.c: introduce rb_vm_pop_frame() and use it
instead of setting rb_thread_t::cfp directly.

* vm_insnhelper.c (vm_pop_frame): return the result of
  finish frame or not.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55755 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-26 10:28:21 +00:00
nobu 84f94652b0 use TH_JUMP_TAG
* vm_eval.c (rb_eval_cmd, rb_catch_obj): use TH_JUMP_TAG with the
  same rb_thread_t used for TH_PUSH_TAG, instead of JUMP_TAG with
  the current thread global variable.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-05 03:22:20 +00:00
akr 0963d96e52 Add a cast to avoid signed integer overflow.
* vm_trace.c (recalc_remove_ruby_vm_event_flags): Add a cast to
  avoid signed integer overflow.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-01 15:42:52 +00:00
yui-knk 480bcad71d * vm_trace.c: Fix typos. [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 02:18:00 +00:00
hsbt 52cd994814 * enum.c: fix a typo in documentation.
[ci skip][fix GH-1140] Patch by @jutaz
* io.c: ditto.
* iseq.c: ditto.
* numeric.c: ditto.
* process.c: ditto.
* string.c: ditto.
* vm_trace.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53105 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-14 02:52:14 +00:00
ko1 1dd547fe5a * vm_trace.c (exec_hooks_precheck): check need_clean everytime
to clean-up unused hooks.

* vm_trace.c (list->need_clean): use as boolean value.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52483 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-07 23:10:55 +00:00
ko1 2d4bc584ee * vm_trace.c (rb_threadptr_exec_event_hooks_orig):
maintain trace_running counter on internal events.

  This patch is made by Takashi Kokubun <takashikkbn@gmail.com>.
  [Bug #11603] https://github.com/ruby/ruby/pull/1059




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-07 00:55:11 +00:00
nobu 1546ffed49 use rb_source_loc and rb_source_location
* error.c, eval.c, eval_error.c, gc.c, variable.c, vm.c,
  vm_eval.c, vm_trace.c: use rb_source_loc/rb_source_location
  instead of combination of rb_sourcefile/rb_sourcefilename and
  rb_sourceline.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-31 01:02:26 +00:00
ko1 3af5298e8c * include/ruby/ruby.h, cont.c, vm_trace.c: add a new event
fiber_switch. We need more discussion about this feature
  so that I don't write it on NEWS.
  [Feature #11348]
* test/ruby/test_settracefunc.rb: add tests.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-21 09:51:01 +00:00
ko1 e4198a73d4 * make rb_iseq_t T_IMEMO object (type is imemo_iseq).
All contents of previous rb_iseq_t is in rb_iseq_t::body.
  Remove rb_iseq_t::self because rb_iseq_t is an object.
  RubyVM::InstructionSequence is wrapper object points T_IMEMO/iseq.
  So RubyVM::ISeq.of(something) method returns different wrapper
  objects but they point the same T_IMEMO/iseq object.
  This patch is big, but most of difference is replacement of
  iseq->xxx to iseq->body->xxx.
  (previous) rb_iseq_t::compile_data is also located to
  rb_iseq_t::compile_data.
  It was moved from rb_iseq_body::compile_data.
  Now rb_iseq_t has empty two pointers.
  I will split rb_iseq_body data into static data and dynamic data.
* compile.c: rename some functions/macros.
  Now, we don't need to separate iseq and iseqval (only VALUE).
* eval.c (ruby_exec_internal): `n' is rb_iseq_t (T_IMEMO/iseq).
* ext/objspace/objspace.c (count_imemo_objects): count T_IMEMO/iseq.
* gc.c: check T_IMEMO/iseq.
* internal.h: add imemo_type::imemo_iseq.
* iseq.c: define RubyVM::InstructionSequnce as T_OBJECT.
  Methods are implemented by functions named iseqw_....
* load.c (rb_load_internal0): rb_iseq_new_top() returns
  rb_iseq_t (T_IMEMO/iesq).
* method.h (rb_add_method_iseq): accept rb_iseq_t (T_IMEMO/iseq).
* vm_core.h (GetISeqPtr): removed because it is not T_DATA now.
* vm_core.h (struct rb_iseq_body): remove padding for
  [Bug #10037][ruby-core:63721].



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-21 22:52:59 +00:00
normal a0908cb413 remove redundant NULL check in mark functions
gc.c (gc_mark_children)only calls mark_func if the T_DATA ptr is
non-NULL, so avoid redundantly checking for that in each
mark function.

* iseq.c (iseq_mark): remove check for data pointer
* proc.c (binding_mark): ditto
* vm.c (rb_thread_mark): ditto
* vm_trace.c (tp_mark): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-15 08:29:22 +00:00
nobu dc513a13bb vm_trace.c: unified a_call and a_return
* vm_trace.c (symbol2event_flag): use a uniform macro for a_call
  and a_return too.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-25 23:55:34 +00:00
nobu 89a2fd52bd vm_trace.c: not a static variable
* vm_trace.c (symbol2event_flag): should not be static but a mere
  local variable, so that unnecessary race condition does not
  happen.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-25 23:45:02 +00:00
nobu 4489c13657 vm_trace.c: indent
* vm_trace.c (thread_tracepoint): adjust indent.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-25 22:19:46 +00:00
nobu c95b788afc vm_trace.c: unnecessary method undef
* vm_trace.c (Init_vm_trace): remove unnecessary method undef,
  that is overridden just after it.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-25 22:19:17 +00:00
ko1 3004c29afd * vm_trace.c (rb_tracepoint_new): fix documentation.
Commented by @emilsoman.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-15 09:44:38 +00:00
ko1 0e78899591 * vm_trace.c (rb_tracepoint_new): Add documentation for
rb_tracepoint_new C level API [ci skip]
  Provided by @emilsoman. [fix GH-869]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-15 08:40:25 +00:00
nobu 05459d1a33 vm_trace.c: defer interrupts while postponed jobs
* vm_trace.c (rb_postponed_job_flush): mask signal trap interrupt
  too to defer handling after finalizers finished.
  [ruby-core:66825] [Bug #10595]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-13 11:41:57 +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
nobu e580a631be use 0 for reserved
use 0 for rb_data_type_t::reserved instead of NULL, since its type
may be changed in the future and possibly not a pointer type.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-01 06:38:04 +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
akr 7cd76ab0c5 * internal.h: Include ruby.h and ruby/encoding.h to be
includable without prior inclusion.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-15 11:49:06 +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
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 d2efc00b06 vm_trace.c (rb_tp_t): pack 56 => 48 bytes on 64-bit
48 bytes is a common malloc size class on x86-64 machines which
require 16-byte alignment.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47765 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-02 20:59:40 +00:00
ktsj 3b895e8355 * process.c (rlimit_resource_type, rlimit_resource_value):
get rid of inadvertent dynamic symbol pin-down.

* re.c (match_backref_number): ditto.

* signal.c (esignal_init, rb_f_kill, trap_signm): ditto.

* transcode.c (econv_opts): ditto.

* vm_trace.c (symbol2event_flag): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-30 13:17:45 +00:00
ko1 4945572f3c * vm_trace.c: add new method TracePoint.stat to debug
TracePoint mechanism.
  Ruby users should not use this method. So I don't note this method
  in the NEWS file.
* test/runner.rb: detect zombie active TracePoints with
  TracePoint.stat.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-13 09:01:21 +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
usa 6c42f57177 * vm_trace.c, vm.c, thread.c: get rid of (maybe false positive) warnings about
using uninitialized var with VC++.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-29 15:45:25 +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
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
hsbt 4ca7f26d06 * vm_trace.c: fix typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44648 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-19 02:14:45 +00:00
nobu a98e343d39 vm_trace.c: isolate exceptions
* vm_trace.c (rb_postponed_job_flush): isolate exceptions in
  postponed jobs and restore outer ones.  based on a patch by
  tarui.  [ruby-core:58652] [Bug #9168]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-17 07:19:25 +00:00
tmm1 348903a628 * vm_trace.c (rb_suppress_tracing): Fix initialization of stack
allocated rb_trace_arg_t structure. Without this patch, sometimes
  INTERNAL_EVENT_GC would be skipped accidentally inside
  rb_threadptr_exec_event_hooks_orig().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-04 04:05:15 +00:00
ko1 bd26be2b34 * vm_trace.c: skip "exception check" and "reentrant check (only normal
events)  for internal events.
  Reentrant check for internal events are remaining.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-26 09:42:04 +00:00
ko1 5b40cb6a2c * vm_trace.c: prohibit to specify normal events and internal events
simultaneously.
  I will introduce special care for internal events later.
* ext/-test-/tracepoint/tracepoint.c: test this behavior.
* test/-ext-/tracepoint/test_tracepoint.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-26 08:41:44 +00:00
ko1 ac778eb2cf * vm_trace.c (symbol2event_flag): add secret feature.
add a_call/a_return events.
  a_call is call | b_call | c_call, and same as a_return.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-10 18:19:41 +00:00
nobu cf5ef3db5e vm_trace.c: isolate errinfo in trace blocks
* vm_trace.c (rb_threadptr_exec_event_hooks_orig): errinfo should not
  be propagated to trace blocks so that no argument raise does not
  throw internal objects.  [ruby-dev:47793] [Bug #9088]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-07 00:39:56 +00:00
ko1 c5e08b764e * add RUBY_TYPED_FREE_IMMEDIATELY to data types which only use
safe functions during garbage collection such as xfree().
  On default, T_DATA objects are freed at same points as fianlizers.
  This approach protects issues such as reported by [ruby-dev:35578].
  However, freeing T_DATA objects immediately helps heap usage.
  Most of T_DATA (in other words, most of dfree functions) are safe.
  However, we turned off RUBY_TYPED_FREE_IMMEDIATELY by default
  for safety.
* cont.c: ditto.
* dir.c: ditto.
* encoding.c: ditto.
* enumerator.c: ditto.
* error.c: ditto.
* file.c: ditto.
* gc.c: ditto.
* io.c: ditto.
* iseq.c: ditto.
* marshal.c: ditto.
* parse.y: ditto.
* proc.c: ditto.
* process.c: ditto.
* random.c: ditto.
* thread.c: ditto.
* time.c: ditto.
* transcode.c: ditto.
* variable.c: ditto.
* vm.c: ditto.
* vm_backtrace.c: ditto.
* vm_trace.c: ditto.
* ext/bigdecimal/bigdecimal.c: ditto.
* ext/objspace/objspace.c: ditto.
* ext/stringio/stringio.c: ditto.
* ext/strscan/strscan.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-29 11:16:54 +00:00
ko1 5c1b9b38d6 * vm_trace.c (tp_free): remvoed because empty free function.
Use RUBY_TYPED_NEVER_FREE instead.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43464 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-29 09:47:06 +00:00
ko1 f5b15f0e3f * vm_trace.c: exterminate Zombies.
There is a bug that T_ZOMBIE objects are not collected.
  Because there is a pass to miss finalizer postponed job
  with multi-threading. This patch solve this issue.
* vm_trace.c (rb_postponed_job_register_one): set
  RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(th) if another same job
  is registered.
  There is a possibility to remain a postponed job without
  interrupt flag.
* vm_trace.c (rb_postponed_job_register_one): check interrupt
  carefully.
* vm_trace.c (rb_postponed_job_register_one): use additional space
  to avoid buffer full.
* gc.c (gc_finalize_deferred_register): check failure.
* thread.c (rb_threadptr_execute_interrupts): check
  `postponed_job_interrupt' immediately.  There is a possibility
  to miss this flag.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-22 06:24:54 +00:00
ko1 542b31ca27 * vm_trace.c (rb_postponed_job_flush): fix bit operation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-11 09:12:45 +00:00
ko1 76f9281b92 * vm_trace.c (rb_postponed_job_flush): simplify.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-11 07:54:26 +00:00
ko1 19ae2748c7 revert r43248. Should not set interrupt_flag.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-11 06:23:19 +00:00
nobu 12a5525b6f vm_trace.c: use macro
* vm_trace.c (rb_postponed_job_flush): use dedicated macro.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43248 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-10 23:56:15 +00:00
nobu d7de529996 vm_trace.c: suppress warnings
* vm_trace.c (rb_postponed_job_flush): suppress clobbered variable
  warnings on some gcc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-10 23:52:40 +00:00
nobu 53861b8acd vm_trace.c: fix infinite hook
* thread.c (rb_threadptr_execute_interrupts): flush postponed job only
  once at last.
* vm_trace.c (rb_postponed_job_flush): defer calling postponed jobs
  registered while flushing to get rid of infinite reentrance of
  ObjectSpace.after_gc_start_hook.  [ruby-dev:47400] [Bug #8492]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-10 18:36:54 +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
zzak f089ea1cd9 * vm_trace.c: [DOC] Fix TracePoint return values in examples
Based on a patch by @sho-h [Fixes GH-373]
  https://github.com/ruby/ruby/pull/373


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42386 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-05 13:25:02 +00:00
shugo 1f828497d1 * safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4.  $SAFE=4 is now obsolete.
  [ruby-core:55222] [Feature #8468]

* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
  Kernel#untrusted?, untrust, and trust are now deprecated.
  Their behavior is same as tainted?, taint, and untaint,
  respectively.

* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
  and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
  respectively.

* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
  ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
  ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
  ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
  ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
  ext/socket/socket.c, ext/socket/udpsocket.c,
  ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
  ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
  load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
  safe.c, string.c, thread.c, transcode.c, variable.c,
  vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
  $SAFE=4.

* test/dl/test_dl2.rb, test/erb/test_erb.rb,
  test/readline/test_readline.rb,
  test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
  test/ruby/test_array.rb, test/ruby/test_dir.rb,
  test/ruby/test_encoding.rb, test/ruby/test_env.rb,
  test/ruby/test_eval.rb, test/ruby/test_exception.rb,
  test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
  test/ruby/test_io.rb, test/ruby/test_method.rb,
  test/ruby/test_module.rb, test/ruby/test_object.rb,
  test/ruby/test_pack.rb, test/ruby/test_rand.rb,
  test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
  test/ruby/test_struct.rb, test/ruby/test_thread.rb,
  test/ruby/test_time.rb: remove tests for $SAFE=4.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 14:20:51 +00:00
ko1 c180e0d880 * vm_trace.c (rb_postponed_job_register_one): fix iteration bug.
* ext/-test-/postponed_job/postponed_job.c,
  test/-ext-/postponed_job/test_postponed_job.rb: add a test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40967 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-27 17:08:25 +00:00
ko1 eccb729a3f * vm_trace.c (rb_postponed_job_flush): remove a wrong comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-27 15:19:36 +00:00
ko1 f0b6cb6fc7 * include/ruby/ruby.h: rename RUBY_INTERNAL_EVENT_FREE to
RUBY_INTERNAL_EVENT_FREEOBJ.
* ext/-test-/tracepoint/tracepoint.c,
  ext/objspace/object_tracing.c,
  gc.c, vm_trace.c: catch up this change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-27 10:28:25 +00:00
tmm1 084df96eb1 fix typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40954 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-27 07:55:59 +00:00
ko1 a1b1b6f7fb * vm_trace.c (rb_postponed_job_flush, rb_postponed_job_register): use
ruby_xmalloc/xfree. It is safe during GC.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40953 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-27 07:17:30 +00:00
ko1 680f0b5ba4 * include/ruby/ruby.h, gc.c, vm_trace.c: add internal events.
* RUBY_INTERNAL_EVENT_NEWOBJ: object created.
* RUBY_INTERNAL_EVENT_FREE: object freeed.
* RUBY_INTERNAL_EVENT_GC_START: GC started.
  And rename `RUBY_EVENT_SWITCH' to `RUBY_INTERNAL_EVENT_SWITCH'.
  Internal events can not invoke any Ruby program because the tracing
  timing may be critical (under huge restriction).
  These events can be hooked only by C-extensions.
  We recommend to use rb_potponed_job_register() API to call Ruby
  program safely.
  This change is mostly written by Aman Gupta (tmm1).
  https://bugs.ruby-lang.org/issues/8107#note-12
  [Feature #8107]
* include/ruby/debug.h, vm_trace.c: added two new APIs.
* rb_tracearg_event_flag() returns rb_event_flag_t of this event.
* rb_tracearg_object() returns created/freeed object.
* ext/-test-/tracepoint/extconf.rb,
  ext/-test-/tracepoint/tracepoint.c,
  test/-ext-/tracepoint/test_tracepoint.rb: add a test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40946 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-27 00:21:02 +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 97982e823f id.def: predefined IDs
* defs/id.def: add more predefined IDs used in core.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-02 07:54:17 +00:00
nobu 2d1c94a18d prefix global symbols
* iseq.c (rb_insn_operand_intern): prefix global symbols.

* numeric.c (ruby_num_interval_step_size): ditto.

* vm_backtrace.c (rb_vm_backtrace_str_ary),
  (rb_vm_backtrace_location_ary, rb_vm_thread_backtrace),
  (rb_vm_thread_backtrace_locations): ditto.

* vm_trace.c (rb_vm_trace_mark_event_hooks): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39611 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-06 06:30:03 +00:00
zzak 810516ed20 * vm_trace.c: Note about TracePoint events set, and comment on
Kernel#set_trace_func to prefer new TracePoint API


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39168 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-09 04:14:09 +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
nobu 499ca89e24 vm_trace.c: TracePoint safe level check
* vm_trace.c (rb_tracepoint_enable, rb_tracepoint_disable): check safe
  level as well as set_trace_func.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38969 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-29 07:51:00 +00:00
nobu e26c2bc21b vm_trace.c: trace_func safe level check
* vm_trace.c (set_trace_func, thread_{add,set}_trace_func_m): check
  safe level as well as 1.8.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-29 07:50:27 +00:00
ko1 06f2a86f1a * include/ruby/ruby.h (RUBY_EVENT_SPECIFIED_LINE): make it special.
This flag is not contained by RUBY_EVENT_TRACEPOINT_ALL.
  This event is experimental one. It is possible to remove/rename
  flag name after 2.0.1.
* vm_trace.c (get_event_id): return :line if SPECIFIED_LINE was
  occurred. `:specified_line' never been returned.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-07 08:38:25 +00:00
ko1 b8e6fd6ffe * vm_trace.c (rb_threadptr_exec_event_hooks_orig): pop tag before
JUMP_TAG() if frame is `finish' frame.
  Without this patch, there is an inconsistency between control
  frame stack and tags stack.
  [Bug #7668]
* test/ruby/test_settracefunc.rb: add a test for above.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-07 06:24:46 +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 a6c5431156 * vm_trace.c (tracepoint_new): add code to support specified thread.
But not tested and this feature is not supported officially.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38531 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-21 11:22:54 +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
nobu 3763c760fd vm_trace.c: style
* vm_trace.c (rb_suppress_tracing): adjust style.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-21 07:35:42 +00:00
tarui 7764dd9357 * vm_trace.c (rb_suppress_tracing): remove unused variable 'vm_tracing'
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-20 23:58:16 +00:00
tarui fbbb06f803 * vm_trace.c (rb_suppress_tracing): bugfix for vm->trace_running
counter. And if tracing is already true, vm_trace_running ops is
	  skipped to control overflow.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-20 12:02:37 +00:00
tarui e9e4ea981e * vm_trace.c (rb_threadptr_exec_event_hooks): get rid of race
condition. [Bug #7589] [ruby-dev:46763]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38464 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-19 08:54:57 +00:00
naruse 056bdfd2e5 Revert r38371 and r38384. they didn't solve the issue
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-19 02:25:40 +00:00
zzak ec3226d826 * vm_trace.c (tracepoint_attr_defined_class): Clean up rdoc for
TracePoint#defined_class


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-18 04:18:06 +00:00
ko1 6247099f4c * vm_trace.c (fill_id_and_klass): TracePoint#defined_class returns
singleton class. `set_trace_func' passed attached class (which is
  attached/modified by singleton class) by 6th block parameter if it
  is singleton class. Previous behavior follows this spec.
  However, this method named `defined_class' should return singleton
  class directly because singleton methods are defined in singleton
  class. There are no compatible issue because TracePoint is introduced
  after 2.0.
  But compatiblity with `set_trace_func' is brokne. This means that
  you can not replace all `set_trace_func' code with TracePoint
  without consideration of this behavior.
  [Bug #7554]
* test/ruby/test_settracefunc.rb: change a test to catch up
  an above chagne.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-17 20:28:51 +00:00
nobu 688f3ec67d vm_trace.c: suppress warning
* vm_trace.c (exec_hooks): suppress unused-variable warning by
  RB_UNUSED_VAR().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-14 18:59:12 +00:00
naruse 497f8904cb * vm_trace.c (exec_hooks): add volatile to avoid segv.
On test-all with -j, it may crash in TH_POP_TAG.
  Detailed mechanism is not known but this fixes it.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-14 01:38:14 +00:00
nobu 63d0ea4c03 vm.c: pass exceptions while handling an exception
* vm.c (vm_exec): pass exceptions while handling an exception.
* vm_trace.c (rb_threadptr_exec_event_hooks): propagate exceptions.
  revert r38293 partially.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-11 18:45:43 +00:00
nobu 13e83d055f vm_trace.c: exceptions in event hooks
* vm_trace.c (rb_threadptr_exec_event_hooks): exceptions in event
  hooks should not propagate outside.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-10 06:23:44 +00:00
zzak 5ffc1a3aaa Fix typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-06 04:57:20 +00:00
ko1 c2f5a57403 * vm_trace.c: TracePoint#enable should not cause an error
when it is already enabled. TracePoint#disable is too.
  [ruby-core:50561] [ruby-trunk - Bug #7513]
* test/ruby/test_settracefunc.rb: add tests.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-06 03:13:50 +00:00
ko1 921385a644 * vm_trace.c: add TracePoint#inspect.
* test/ruby/test_settracefunc.rb: add a test for this change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38132 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-01 17:47:37 +00:00
nobu e78cf44a99 * vm_trace.c (rb_tracepoint_new): commit miss.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-01 15:26:52 +00:00
nobu 66fd9d44d8 adjust style.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38128 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-01 15:25:28 +00:00
ko1 12f2f7371f [EXPERIMENTAL]
* iseq.c: add following two methods.
* ISeq#line_trace_all returns all line traces (line numbers)
* ISeq#line_trace_specify(pos, set) set `pos'th line event to
  specified_line event (if set is true).
  These features are introduced for debuggers (mainly to make
  breakpoint).
* iseq.h: add decl. of C APIs.
* test/ruby/test_iseq.rb: add tests.
* vm_trace.c: add `specified_line' event.
* include/ruby/ruby.h: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 17:00:30 +00:00
zzak 57540a4932 * vm_trace.c:
tracepoint_attr_return_value (TracePoint#return_value):
    include `:b_return` for method doc
  tracepoint_enable_m, tracepoint_disable_m (#enable/#disable):
    don't have block argument, document block scope


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 10:29:49 +00:00
ko1 6df1b3a9de * vm_trace.c (tracepoint_disable_m, tracepoint_enable_m):
fix block parameter.
  No arugment should be given to a block which is passed
  to TracePoint#enable (and disable).



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 09:55:32 +00:00
zzak f2fee84466 * vm_trace.c: Documentation for TracePoint API
[ruby-core:47243] [Feature #6895]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38045 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 09:25:24 +00:00
zzak 0d672c18cf * vm_trace.c (set_trace_func): Formatting of params and events
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 06:15:59 +00:00
ko1 4db8340398 [EXPERIMENTAL: NEED DISCUSS]
* vm_trace.c: add events
* :thread_begin - hook at thread beggining.
* :thead_end - hook at thread ending.
* :b_call - hook at block enter.
* :b_return - hook at block leave.
  This change slow down block invocation.
  Please try and give us feedback until 2.0 code freeze.
* include/ruby/ruby.h: ditto.
* compile.c (rb_iseq_compile_node): ditto.
* insns.def: ditto.
* thread.c: ditto.
* vm.c: ditto.
* include/ruby/debug.h: add a comment.
* test/ruby/test_settracefunc.rb: add a tests.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-29 22:28:16 +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
ko1 3f606b7063 * include/ruby/debug.h: provide rb_tracearg_*() APIs,
instead of rb_tracepoint_attr_*().
  These APIs are for debuggers/profilers.
  They will be explained in another docs somtime.
* vm_trace.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-29 06:43:31 +00:00
ko1 479e396192 * vm_trace.c (rb_tracepoint_attr_method_id):
rename TracePoint#id to TracePoint#method_id.
* include/ruby/debug.h: ditto.
* test/ruby/test_settracefunc.rb: ditto,



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-29 05:57:35 +00:00
ko1 89c889d4e7 * vm_trace.c (rb_tracepoint_attr_defined_class):
rename TracePoint#klass to TracePoint#defined_class.
  [ruby-core:50187] Re: [ruby-trunk - Feature #6895]
* include/ruby/debug.h: ditto.
* test/ruby/test_settracefunc.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-29 05:52:27 +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
ko1 9d803dfd5f * vm_trace.c (rb_tracepoint_attr_raised_exception): should not check
value before event checking.
* vm_trace.c (rb_tracepoint_attr_return_value): ditto.
* test/ruby/test_settracefunc.rb: add tests for TracePoint#return_value
  and TracePoint#raised_exception.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-24 04:12:30 +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 1da641a16b * vm_trace.c: rename and add TracePoint APIs.
(1) TracePoint.new(...){...} creates a new trace point
  but does not make it enable.
  (2) TracePoint.trace(...){...} creats a new trace point
  and enable it (same as old behavior).
  (3) TracePoint#enable make it enable (renamed from TracePoint#retrace).
  If block given, when enable only in block.
  (4) TracePoint#disable make it disable (renamed from TracePoint#untrace).
  If block given, when disable only in block.
  (5) TracePoint#enabled? returns this trace is enable or not.
* test/ruby/test_settracefunc.rb: addd tests.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37753 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-20 11:05:20 +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
ko1 378041cfbf * eval_error.c (error_print), vm_eval.c (eval_string_with_cref),
vm_trace.c (rb_suppress_tracing): use TH_PUSH_TAG() instead of
  PUSH_TAG().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-23 20:42:45 +00:00
ktsj 811d072dcb * vm_trace.c (rb_threadptr_exec_event_hooks, rb_suppress_tracing):
constified.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37281 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-21 10:14:29 +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
nobu 5fbfc21b67 internal.h: allocator function in rb_classext_t
* internal.h (struct rb_classext_struct): move allocator function into
  rb_classext_t from ordinary method table.  [ruby-dev:46121]
  [Feature #6993]
* object.c (rb_obj_alloc): call allocator function directly.
* vm_method.c (rb_define_alloc_func, rb_undef_alloc_func)
  (rb_get_alloc_func): use allocator function in rb_classext_t.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-09-08 09:52:26 +00:00
nobu dde690bc32 vm_trace.c: freed memory access
* vm_trace.c (clean_hooks): do not access freed memory.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-31 05:03:47 +00:00
nobu 4faf219853 vm_trace.c: uninitialized state
* vm_trace.c (rb_threadptr_exec_event_hooks): fix uninitialized state
  when no events is excuted.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-31 05:02:47 +00:00
nobu d90b023603 vm_trace.c: warning
* vm_trace.c (exec_hooks): supress clobbered warning.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-30 07:20:05 +00:00
ko1 d28e07d57b * vm_trace.c: support TracePoint. [ruby-trunk - Feature #6895]
* test/ruby/test_settracefunc.rb: add tests for above.
* proc.c (rb_binding_new_with_cfp): add an internal function.
* vm.c (rb_vm_control_frame_id_and_class): add an internal function.
* vm_trace.c: add rb_add_event_hook2() and rb_thread_add_event_hook2().
  Give us the good name for them!



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-22 05:12:31 +00:00
nobu 78f8ad683b vm_trace.c: remove meaningless assingments
* vm_trace.c (call_trace_func): remove meaningless assingments to same
  variables.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-17 02:13:31 +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 8eb93103e4 * vm_trace.c: separate trace_func related functions from
thread.c.
* thread.c: ditto.
* common.mk: add vm_trace.o.
* inits.c: call Init_vm_trace().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-15 04:39:10 +00:00