summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-18 09:39:41 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-18 09:39:41 +0000
commit26451ab3bab3aff8cee0113405b3c542c2d59b37 (patch)
tree034ea9f654a88f7a4ca99b889610c131b006e3a7 /iseq.c
parent4f83ca015d7131f0990ca03a295a9d0c816f0192 (diff)
introduce `trace_events' info for iseq.
* vm_core.h (rb_iseq_t::aux): add `trace_events` which represents which events are enabled on this iseq. With this information, we can skip useless trace-on changes for ISeqs. * vm_trace.c (RUBY_EVENTS_TRACE_BY_ISEQ): moved to iseq.h and rename it with ISEQ_TRACE_EVENTS. * iseq.h: introduce ISEQ_USE_COMPILE_DATA iseq (imemo) flag to represent COMPILE_DATA is available. In other words, iseq->aux.trace_events is not available when this flag is set. * ISEQ_COMPILE_DATA() is changed from a macro. * ISEQ_COMPILE_DATA_ALLOC() is added. * ISEQ_COMPILE_DATA_CLEAR() is added. * iseq.c: use them. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/iseq.c b/iseq.c
index a9c3204fad..a4da78496c 100644
--- a/iseq.c
+++ b/iseq.c
@@ -120,7 +120,7 @@ rb_iseq_mark(const rb_iseq_t *iseq)
if (FL_TEST(iseq, ISEQ_NOT_LOADED_YET)) {
rb_gc_mark(iseq->aux.loader.obj);
}
- else if (ISEQ_COMPILE_DATA(iseq) != 0) {
+ else if (ISEQ_COMPILE_DATA(iseq) != NULL) {
const struct iseq_compile_data *const compile_data = ISEQ_COMPILE_DATA(iseq);
RUBY_MARK_UNLESS_NULL(compile_data->mark_ary);
RUBY_MARK_UNLESS_NULL(compile_data->err_info);
@@ -305,7 +305,7 @@ prepare_iseq_build(rb_iseq_t *iseq,
}
RB_OBJ_WRITE(iseq, &iseq->body->mark_ary, iseq_mark_ary_create(0));
- ISEQ_COMPILE_DATA(iseq) = ZALLOC(struct iseq_compile_data);
+ ISEQ_COMPILE_DATA_ALLOC(iseq);
RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->err_info, err_info);
RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->mark_ary, rb_ary_tmp_new(3));
@@ -341,7 +341,7 @@ finish_iseq_build(rb_iseq_t *iseq)
{
struct iseq_compile_data *data = ISEQ_COMPILE_DATA(iseq);
VALUE err = data->err_info;
- ISEQ_COMPILE_DATA(iseq) = 0;
+ ISEQ_COMPILE_DATA_CLEAR(iseq);
compile_data_free(data);
if (RTEST(err)) {
@@ -351,8 +351,9 @@ finish_iseq_build(rb_iseq_t *iseq)
rb_exc_raise(err);
}
- if (ruby_vm_event_flags) {
- rb_iseq_trace_set(iseq, ruby_vm_event_flags);
+ iseq->aux.trace_events = 0;
+ if (ruby_vm_event_flags & ISEQ_TRACE_EVENTS) {
+ rb_iseq_trace_set(iseq, ruby_vm_event_flags & ISEQ_TRACE_EVENTS);
}
return Qtrue;
}
@@ -2321,34 +2322,41 @@ rb_iseq_defined_string(enum defined_type type)
void
rb_iseq_trace_set(const rb_iseq_t *iseq, rb_event_flag_t turnon_events)
{
- unsigned int i;
- VALUE *iseq_encoded = (VALUE *)iseq->body->iseq_encoded;
+ VM_ASSERT((turnon_events & ~ISEQ_TRACE_EVENTS) == 0);
+
+ if (iseq->aux.trace_events == turnon_events) {
+ return;
+ }
+ else {
+ unsigned int i;
+ VALUE *iseq_encoded = (VALUE *)iseq->body->iseq_encoded;
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
- VALUE *code = rb_iseq_original_iseq(iseq);
- const void * const *table = rb_vm_get_insns_address_table();
+ VALUE *code = rb_iseq_original_iseq(iseq);
+ const void * const *table = rb_vm_get_insns_address_table();
#else
- const VALUE *code = iseq->body->iseq_encoded;
+ const VALUE *code = iseq->body->iseq_encoded;
#endif
+ ((rb_iseq_t *)iseq)->aux.trace_events = turnon_events;
- for (i=0; i<iseq->body->iseq_size;) {
- int insn = (int)code[i];
- rb_event_flag_t events = rb_iseq_event_flags(iseq, i);
+ for (i=0; i<iseq->body->iseq_size;) {
+ int insn = (int)code[i];
+ rb_event_flag_t events = rb_iseq_event_flags(iseq, i);
- /* code represents before transformation */
- VM_ASSERT(insn < VM_INSTRUCTION_SIZE/2);
+ /* code represents before transformation */
+ VM_ASSERT(insn < VM_INSTRUCTION_SIZE/2);
- if (events & turnon_events) {
- if (!TRACE_INSN_P(insn, iseq_encoded[i])) {
- iseq_encoded[i] = INSN_CODE(insn + VM_INSTRUCTION_SIZE/2);
+ if (events & turnon_events) {
+ if (!TRACE_INSN_P(insn, iseq_encoded[i])) {
+ iseq_encoded[i] = INSN_CODE(insn + VM_INSTRUCTION_SIZE/2);
+ }
}
+ else if (TRACE_INSN_P(insn, iseq_encoded[i])) {
+ iseq_encoded[i] = INSN_CODE(insn);
+ }
+ i += insn_len(insn);
}
- else if (TRACE_INSN_P(insn, iseq_encoded[i])) {
- iseq_encoded[i] = INSN_CODE(insn);
- }
- i += insn_len(insn);
+ /* clear for debugging: ISEQ_ORIGINAL_ISEQ_CLEAR(iseq); */
}
-
- /* clear for debugging: ISEQ_ORIGINAL_ISEQ_CLEAR(iseq); */
}
static int