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
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
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
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
* 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
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
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
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
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
* 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
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
* 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
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
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
* 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
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
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
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
* 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
* 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
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
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
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
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
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
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