From 02d5868962417298cf041ce723d406e16a635693 Mon Sep 17 00:00:00 2001 From: ko1 Date: Mon, 6 Jul 2015 18:44:54 +0000 Subject: * vm_core.h: remove rb_iseq_t::klass to reduce dynamic data. * internal.h, iseq.c (rb_iseq_klass): remove it because rb_iseq_t::klass is removed. * vm_insnhelper.c (vm_super_outside): do not see cfp->iseq, but check callable method entry on a frame. This fix simplify the logic to search super class. * test/ruby/test_method.rb: support super() from Proc. Now, [Bug #4881] and [Bug #3136] was solved. * proc.c (rb_mod_define_method): catch up this change. * vm.c (vm_define_method): ditto. * vm_backtrace.c (rb_profile_frames): now, each `frame' objects are rb_callable_method_entry_t data or iseq VALUEs. This fix introduce minor compatibility issue that rb_profile_frame_label() always returns rb_profile_frame_base_label(). * test/-ext-/debug/test_profile_frames.rb: catch up this change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- vm_backtrace.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 13 deletions(-) (limited to 'vm_backtrace.c') diff --git a/vm_backtrace.c b/vm_backtrace.c index 99d3e7f3d3..3d4322cd4d 100644 --- a/vm_backtrace.c +++ b/vm_backtrace.c @@ -9,6 +9,8 @@ **********************************************************************/ +#define VM_CHECK_MODE 2 + #include "internal.h" #include "ruby/debug.h" @@ -1248,15 +1250,24 @@ rb_profile_frames(int start, int limit, VALUE *buff, int *lines) rb_control_frame_t *cfp = th->cfp, *end_cfp = RUBY_VM_END_CONTROL_FRAME(th); for (i=0; iiseq && cfp->pc) { /* should be NORMAL_ISEQ */ + const rb_callable_method_entry_t *cme = rb_vm_frame_method_entry(cfp); + + if ((cme && cme->def->type == VM_METHOD_TYPE_ISEQ) || (cfp->iseq && cfp->pc)) { if (start > 0) { start--; continue; } /* record frame info */ - buff[i] = cfp->iseq->self; - if (lines) lines[i] = calc_lineno(cfp->iseq, cfp->pc); + if (cme) { + buff[i] = (VALUE)cme; + } + else { + buff[i] = cfp->iseq->self; + } + + if (cfp->iseq && lines) lines[i] = calc_lineno(cfp->iseq, cfp->pc); + i++; } cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); @@ -1265,42 +1276,83 @@ rb_profile_frames(int start, int limit, VALUE *buff, int *lines) return i; } -#define frame2iseq(frame) frame +static VALUE +frame2iseq(VALUE frame) +{ + if (frame == Qnil) return Qnil; + + if (RB_TYPE_P(frame, T_DATA)) { + VM_ASSERT(strcmp(rb_objspace_data_type_name(frame), "iseq") == 0); + return frame; + } + + if (RB_TYPE_P(frame, T_IMEMO)) { + const rb_callable_method_entry_t *cme = (rb_callable_method_entry_t *)frame; + VM_ASSERT(imemo_type(frame) == imemo_ment); + switch (cme->def->type) { + case VM_METHOD_TYPE_ISEQ: + return cme->def->body.iseq.iseqptr->self; + default: + return Qnil; + } + } + rb_bug("frame2iseq: unreachable"); +} VALUE rb_profile_frame_path(VALUE frame) { - return rb_iseq_path(frame2iseq(frame)); + VALUE iseqv = frame2iseq(frame); + return NIL_P(iseqv) ? Qnil : rb_iseq_path(iseqv); } VALUE rb_profile_frame_absolute_path(VALUE frame) { - return rb_iseq_absolute_path(frame2iseq(frame)); + VALUE iseqv = frame2iseq(frame); + return NIL_P(iseqv) ? Qnil : rb_iseq_absolute_path(iseqv); } VALUE rb_profile_frame_label(VALUE frame) { - return rb_iseq_label(frame2iseq(frame)); + VALUE iseqv = frame2iseq(frame); + return NIL_P(iseqv) ? Qnil : rb_iseq_label(iseqv); } VALUE rb_profile_frame_base_label(VALUE frame) { - return rb_iseq_base_label(frame2iseq(frame)); + VALUE iseqv = frame2iseq(frame); + return NIL_P(iseqv) ? Qnil : rb_iseq_base_label(iseqv); } VALUE rb_profile_frame_first_lineno(VALUE frame) { - return rb_iseq_first_lineno(frame2iseq(frame)); + VALUE iseqv = frame2iseq(frame); + return NIL_P(iseqv) ? Qnil : rb_iseq_first_lineno(iseqv); +} + +static VALUE +frame2klass(VALUE frame) +{ + if (frame == Qnil) return Qnil; + + if (RB_TYPE_P(frame, T_IMEMO)) { + const rb_callable_method_entry_t *cme = (rb_callable_method_entry_t *)frame; + VM_ASSERT(imemo_type(frame) == imemo_ment); + return cme->defined_class; + } + else { + return Qnil; + } } VALUE rb_profile_frame_classpath(VALUE frame) { - VALUE klass = rb_iseq_klass(frame2iseq(frame)); + VALUE klass = frame2klass(frame); if (klass && !NIL_P(klass)) { if (RB_TYPE_P(klass, T_ICLASS)) { @@ -1321,7 +1373,8 @@ rb_profile_frame_classpath(VALUE frame) VALUE rb_profile_frame_singleton_method_p(VALUE frame) { - VALUE klass = rb_iseq_klass(frame2iseq(frame)); + VALUE klass = frame2klass(frame); + if (klass && !NIL_P(klass) && FL_TEST(klass, FL_SINGLETON)) { return Qtrue; } @@ -1333,13 +1386,15 @@ rb_profile_frame_singleton_method_p(VALUE frame) VALUE rb_profile_frame_method_name(VALUE frame) { - return rb_iseq_method_name(frame2iseq(frame)); + VALUE iseqv = frame2iseq(frame); + return NIL_P(iseqv) ? Qnil : rb_iseq_method_name(iseqv); } VALUE rb_profile_frame_qualified_method_name(VALUE frame) { - VALUE method_name = rb_iseq_method_name(frame2iseq(frame)); + VALUE method_name = rb_profile_frame_method_name(frame); + if (method_name != Qnil) { VALUE classpath = rb_profile_frame_classpath(frame); VALUE singleton_p = rb_profile_frame_singleton_method_p(frame); -- cgit v1.2.3