diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-26 18:16:39 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-26 18:16:39 +0000 |
commit | 96990203b71184003cf8a9bad5cc177645820fd4 (patch) | |
tree | 002653edece27aa30772c373cc6a83c0de928cc8 /vm_method.c | |
parent | 2c9259e6e01726234360a2e432ffc882b52ff793 (diff) | |
download | ruby-96990203b71184003cf8a9bad5cc177645820fd4.tar.gz |
Support targetting TracePoint [Feature #15289]
* vm_trace.c (rb_tracepoint_enable_for_target): support targetting
TracePoint. [Feature #15289]
Tragetting TracePoint is only enabled on specified method, proc
and so on, example: `tp.enable(target: code)`.
`code` should be consisted of InstructionSeuqnece (iseq)
(RubyVM::InstructionSeuqnece.of(code) should not return nil)
If code is a tree of iseq, TracePoint is enabled on all of
iseqs in a tree.
Enabled tragetting TracePoints can not enabled again with
and without target.
* vm_core.h (rb_iseq_t): introduce `rb_iseq_t::local_hooks`
to store local hooks.
`rb_iseq_t::aux::trace_events` is renamed to
`global_trace_events` to contrast with `local_hooks`.
* vm_core.h (rb_hook_list_t): add `rb_hook_list_t::running`
to represent how many Threads/Fibers are used this list.
If this field is 0, nobody using this hooks and we can
delete it.
This is why we can remove code from cont.c.
* vm_core.h (rb_vm_t): because of above change, we can eliminate
`rb_vm_t::trace_running` field.
Also renamed from `rb_vm_t::event_hooks` to `global_hooks`.
* vm_core.h, vm.c (ruby_vm_event_enabled_global_flags): renamed
from `ruby_vm_event_enabled_flags.
* vm_core.h, vm.c (ruby_vm_event_local_num): added to count
enabled targetting TracePoints.
* vm_core.h, vm_trace.c (rb_exec_event_hooks): accepts
hook list.
* vm_core.h (rb_vm_global_hooks): added for convinience.
* method.h (rb_method_bmethod_t): added to maintain Proc
and `rb_hook_list_t` for bmethod (defined by define_method).
* prelude.rb (TracePoint#enable): extracet a keyword parameter
(because it is easy than writing in C).
It calls `TracePoint#__enable` internal method written in C.
* vm_insnhelper.c (vm_trace): check also iseq->local_hooks.
* vm.c (invoke_bmethod): check def->body.bmethod.hooks.
* vm.c (hook_before_rewind): check iseq->local_hooks
and def->body.bmethod.hooks before rewind by exception.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_method.c')
-rw-r--r-- | vm_method.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/vm_method.c b/vm_method.c index 0aeac2869e..13580939bf 100644 --- a/vm_method.c +++ b/vm_method.c @@ -152,7 +152,9 @@ rb_method_definition_release(rb_method_definition_t *def, int complemented) VM_ASSERT(complemented_count >= 0); if (alias_count + complemented_count == 0) { - if (METHOD_DEBUG) fprintf(stderr, "-%p-%s:%d,%d (remove)\n", (void *)def, rb_id2name(def->original_id), alias_count, complemented_count); + if (METHOD_DEBUG) fprintf(stderr, "-%p-%s:%d,%d (remove)\n", (void *)def, + rb_id2name(def->original_id), alias_count, complemented_count); + VM_ASSERT(def->type == VM_METHOD_TYPE_BMETHOD ? def->body.bmethod.hooks == NULL : TRUE); xfree(def); } else { @@ -277,7 +279,7 @@ rb_method_definition_set(const rb_method_entry_t *me, rb_method_definition_t *de return; } case VM_METHOD_TYPE_BMETHOD: - RB_OBJ_WRITE(me, &def->body.proc, (VALUE)opts); + RB_OBJ_WRITE(me, &def->body.bmethod.proc, (VALUE)opts); return; case VM_METHOD_TYPE_NOTIMPLEMENTED: setup_method_cfunc_struct(UNALIGNED_MEMBER_PTR(def, body.cfunc), rb_f_notimplement, -1); @@ -318,7 +320,9 @@ method_definition_reset(const rb_method_entry_t *me) RB_OBJ_WRITTEN(me, Qundef, def->body.attr.location); break; case VM_METHOD_TYPE_BMETHOD: - RB_OBJ_WRITTEN(me, Qundef, def->body.proc); + RB_OBJ_WRITTEN(me, Qundef, def->body.bmethod.proc); + /* give up to check all in a list */ + if (def->body.bmethod.hooks) rb_gc_writebarrier_remember((VALUE)me); break; case VM_METHOD_TYPE_REFINED: RB_OBJ_WRITTEN(me, Qundef, def->body.refined.orig_me); @@ -579,7 +583,7 @@ rb_method_entry_make(VALUE klass, ID mid, VALUE defined_class, rb_method_visibil iseq = def_iseq_ptr(old_def); break; case VM_METHOD_TYPE_BMETHOD: - iseq = rb_proc_get_iseq(old_def->body.proc, 0); + iseq = rb_proc_get_iseq(old_def->body.bmethod.proc, 0); break; default: break; @@ -1521,7 +1525,7 @@ rb_method_definition_eq(const rb_method_definition_t *d1, const rb_method_defini case VM_METHOD_TYPE_IVAR: return d1->body.attr.id == d2->body.attr.id; case VM_METHOD_TYPE_BMETHOD: - return RTEST(rb_equal(d1->body.proc, d2->body.proc)); + return RTEST(rb_equal(d1->body.bmethod.proc, d2->body.bmethod.proc)); case VM_METHOD_TYPE_MISSING: return d1->original_id == d2->original_id; case VM_METHOD_TYPE_ZSUPER: @@ -1555,7 +1559,7 @@ rb_hash_method_definition(st_index_t hash, const rb_method_definition_t *def) case VM_METHOD_TYPE_IVAR: return rb_hash_uint(hash, def->body.attr.id); case VM_METHOD_TYPE_BMETHOD: - return rb_hash_proc(hash, def->body.proc); + return rb_hash_proc(hash, def->body.bmethod.proc); case VM_METHOD_TYPE_MISSING: return rb_hash_uint(hash, def->original_id); case VM_METHOD_TYPE_ZSUPER: |