diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-21 22:52:59 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-21 22:52:59 +0000 |
commit | e4198a73d406d9a9f61a6db2d2a243c0f5267679 (patch) | |
tree | e77fa8d9817f9ff7c53864e373784f902b4368c1 /vm_backtrace.c | |
parent | 6053426a669386353a6b7fe11f3d3ea8d3c11e7c (diff) | |
download | ruby-e4198a73d406d9a9f61a6db2d2a243c0f5267679.tar.gz |
* 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
Diffstat (limited to 'vm_backtrace.c')
-rw-r--r-- | vm_backtrace.c | 87 |
1 files changed, 46 insertions, 41 deletions
diff --git a/vm_backtrace.c b/vm_backtrace.c index aabc949f64..077ed5049f 100644 --- a/vm_backtrace.c +++ b/vm_backtrace.c @@ -31,7 +31,7 @@ id2str(ID id) inline static int calc_lineno(const rb_iseq_t *iseq, const VALUE *pc) { - return rb_iseq_line_no(iseq, pc - iseq->iseq_encoded); + return rb_iseq_line_no(iseq, pc - iseq->body->iseq_encoded); } int @@ -87,7 +87,7 @@ location_mark_entry(rb_backtrace_location_t *fi) switch (fi->type) { case LOCATION_TYPE_ISEQ: case LOCATION_TYPE_ISEQ_CALCED: - rb_gc_mark(fi->body.iseq.iseq->self); + rb_gc_mark((VALUE)fi->body.iseq.iseq); break; case LOCATION_TYPE_CFUNC: case LOCATION_TYPE_IFUNC: @@ -157,7 +157,7 @@ location_label(rb_backtrace_location_t *loc) switch (loc->type) { case LOCATION_TYPE_ISEQ: case LOCATION_TYPE_ISEQ_CALCED: - return loc->body.iseq.iseq->location.label; + return loc->body.iseq.iseq->body->location.label; case LOCATION_TYPE_CFUNC: return rb_id2str(loc->body.cfunc.mid); case LOCATION_TYPE_IFUNC: @@ -206,7 +206,7 @@ location_base_label(rb_backtrace_location_t *loc) switch (loc->type) { case LOCATION_TYPE_ISEQ: case LOCATION_TYPE_ISEQ_CALCED: - return loc->body.iseq.iseq->location.base_label; + return loc->body.iseq.iseq->body->location.base_label; case LOCATION_TYPE_CFUNC: return rb_id2str(loc->body.cfunc.mid); case LOCATION_TYPE_IFUNC: @@ -233,7 +233,7 @@ location_path(rb_backtrace_location_t *loc) switch (loc->type) { case LOCATION_TYPE_ISEQ: case LOCATION_TYPE_ISEQ_CALCED: - return loc->body.iseq.iseq->location.path; + return loc->body.iseq.iseq->body->location.path; case LOCATION_TYPE_CFUNC: if (loc->body.cfunc.prev_loc) { return location_path(loc->body.cfunc.prev_loc); @@ -266,7 +266,7 @@ location_absolute_path(rb_backtrace_location_t *loc) switch (loc->type) { case LOCATION_TYPE_ISEQ: case LOCATION_TYPE_ISEQ_CALCED: - return loc->body.iseq.iseq->location.absolute_path; + return loc->body.iseq.iseq->body->location.absolute_path; case LOCATION_TYPE_CFUNC: if (loc->body.cfunc.prev_loc) { return location_absolute_path(loc->body.cfunc.prev_loc); @@ -315,20 +315,20 @@ location_to_str(rb_backtrace_location_t *loc) switch (loc->type) { case LOCATION_TYPE_ISEQ: - file = loc->body.iseq.iseq->location.path; - name = loc->body.iseq.iseq->location.label; + file = loc->body.iseq.iseq->body->location.path; + name = loc->body.iseq.iseq->body->location.label; lineno = loc->body.iseq.lineno.lineno = calc_lineno(loc->body.iseq.iseq, loc->body.iseq.lineno.pc); loc->type = LOCATION_TYPE_ISEQ_CALCED; break; case LOCATION_TYPE_ISEQ_CALCED: - file = loc->body.iseq.iseq->location.path; + file = loc->body.iseq.iseq->body->location.path; lineno = loc->body.iseq.lineno.lineno; - name = loc->body.iseq.iseq->location.label; + name = loc->body.iseq.iseq->body->location.label; break; case LOCATION_TYPE_CFUNC: if (loc->body.cfunc.prev_loc) { - file = loc->body.cfunc.prev_loc->body.iseq.iseq->location.path; + file = loc->body.cfunc.prev_loc->body.iseq.iseq->body->location.path; lineno = location_lineno(loc->body.cfunc.prev_loc); } else { @@ -693,8 +693,8 @@ oldbt_iter_iseq(void *ptr, const rb_control_frame_t *cfp) const rb_iseq_t *iseq = cfp->iseq; const VALUE *pc = cfp->pc; struct oldbt_arg *arg = (struct oldbt_arg *)ptr; - VALUE file = arg->filename = iseq->location.path; - VALUE name = iseq->location.label; + VALUE file = arg->filename = iseq->body->location.path; + VALUE name = iseq->body->location.label; int lineno = arg->lineno = calc_lineno(iseq, pc); (arg->func)(arg->data, file, lineno, name); @@ -1111,7 +1111,7 @@ collect_caller_bindings_iseq(void *arg, const rb_control_frame_t *cfp) rb_ary_store(frame, CALLER_BINDING_SELF, cfp->self); rb_ary_store(frame, CALLER_BINDING_CLASS, get_klass(cfp)); rb_ary_store(frame, CALLER_BINDING_BINDING, GC_GUARDED_PTR(cfp)); /* create later */ - rb_ary_store(frame, CALLER_BINDING_ISEQ, cfp->iseq ? cfp->iseq->self : Qnil); + rb_ary_store(frame, CALLER_BINDING_ISEQ, cfp->iseq ? (VALUE)cfp->iseq : Qnil); rb_ary_store(frame, CALLER_BINDING_CFP, GC_GUARDED_PTR(cfp)); rb_ary_push(data->ary, frame); @@ -1231,7 +1231,9 @@ VALUE rb_debug_inspector_frame_iseq_get(const rb_debug_inspector_t *dc, long index) { VALUE frame = frame_get(dc, index); - return rb_ary_entry(frame, CALLER_BINDING_ISEQ); + VALUE iseq = rb_ary_entry(frame, CALLER_BINDING_ISEQ); + + return RTEST(iseq) ? rb_iseqw_new((rb_iseq_t *)iseq) : Qnil; } VALUE @@ -1261,7 +1263,7 @@ rb_profile_frames(int start, int limit, VALUE *buff, int *lines) buff[i] = (VALUE)cme; } else { - buff[i] = cfp->iseq->self; + buff[i] = (VALUE)cfp->iseq; } if (cfp->iseq && lines) lines[i] = calc_lineno(cfp->iseq, cfp->pc); @@ -1274,24 +1276,27 @@ rb_profile_frames(int start, int limit, VALUE *buff, int *lines) return i; } -static VALUE +static const rb_iseq_t * 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 (frame == Qnil) return NULL; 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; + switch (imemo_type(frame)) { + case imemo_iseq: + return (const rb_iseq_t *)frame; + case imemo_ment: + { + const rb_callable_method_entry_t *cme = (rb_callable_method_entry_t *)frame; + switch (cme->def->type) { + case VM_METHOD_TYPE_ISEQ: + return cme->def->body.iseq.iseqptr; + default: + return NULL; + } + } default: - return Qnil; + break; } } rb_bug("frame2iseq: unreachable"); @@ -1300,36 +1305,36 @@ frame2iseq(VALUE frame) VALUE rb_profile_frame_path(VALUE frame) { - VALUE iseqv = frame2iseq(frame); - return NIL_P(iseqv) ? Qnil : rb_iseq_path(iseqv); + const rb_iseq_t *iseq = frame2iseq(frame); + return iseq ? rb_iseq_path(iseq) : Qnil; } VALUE rb_profile_frame_absolute_path(VALUE frame) { - VALUE iseqv = frame2iseq(frame); - return NIL_P(iseqv) ? Qnil : rb_iseq_absolute_path(iseqv); + const rb_iseq_t *iseq = frame2iseq(frame); + return iseq ? rb_iseq_absolute_path(iseq) : Qnil; } VALUE rb_profile_frame_label(VALUE frame) { - VALUE iseqv = frame2iseq(frame); - return NIL_P(iseqv) ? Qnil : rb_iseq_label(iseqv); + const rb_iseq_t *iseq = frame2iseq(frame); + return iseq ? rb_iseq_label(iseq) : Qnil; } VALUE rb_profile_frame_base_label(VALUE frame) { - VALUE iseqv = frame2iseq(frame); - return NIL_P(iseqv) ? Qnil : rb_iseq_base_label(iseqv); + const rb_iseq_t *iseq = frame2iseq(frame); + return iseq ? rb_iseq_base_label(iseq) : Qnil; } VALUE rb_profile_frame_first_lineno(VALUE frame) { - VALUE iseqv = frame2iseq(frame); - return NIL_P(iseqv) ? Qnil : rb_iseq_first_lineno(iseqv); + const rb_iseq_t *iseq = frame2iseq(frame); + return iseq ? rb_iseq_first_lineno(iseq) : Qnil; } static VALUE @@ -1384,8 +1389,8 @@ rb_profile_frame_singleton_method_p(VALUE frame) VALUE rb_profile_frame_method_name(VALUE frame) { - VALUE iseqv = frame2iseq(frame); - return NIL_P(iseqv) ? Qnil : rb_iseq_method_name(iseqv); + const rb_iseq_t *iseq = frame2iseq(frame); + return iseq ? rb_iseq_method_name(iseq) : Qnil; } VALUE |