ruby-changes:48701
From: ko1 <ko1@a...>
Date: Fri, 17 Nov 2017 15:25:00 +0900 (JST)
Subject: [ruby-changes:48701] ko1:r60817 (trunk): remove `trace_` prefix insns lazily.
ko1 2017-11-17 15:24:55 +0900 (Fri, 17 Nov 2017) New Revision: 60817 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60817 Log: remove `trace_` prefix insns lazily. * vm_trace.c (update_global_event_hook): set only when tracing is added. If tracing was off (event flags are decreased), then ignore them. Next `trace_` prefix instruction will trace off itself (lazy tracing off). * vm_insnhelper.c (vm_trace): trace-off for when trace is not needed. * iseq.c (rb_iseq_trace_set): fix trace-off process (it was never off tracing). Modified files: trunk/iseq.c trunk/iseq.h trunk/vm_insnhelper.c trunk/vm_trace.c Index: iseq.c =================================================================== --- iseq.c (revision 60816) +++ iseq.c (revision 60817) @@ -336,8 +336,6 @@ prepare_iseq_build(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L336 return Qtrue; } -static void rb_iseq_trace_set(const rb_iseq_t *iseq, rb_event_flag_t turnon_events); - static VALUE finish_iseq_build(rb_iseq_t *iseq) { @@ -2311,15 +2309,16 @@ rb_iseq_defined_string(enum defined_type https://github.com/ruby/ruby/blob/trunk/iseq.c#L2309 return str; } -#define TRACE_INSN_P(insn) ((insn) >= VM_INSTRUCTION_SIZE/2) #if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE #define INSN_CODE(insn) ((VALUE)table[insn]) +#define TRACE_INSN_P(insn, insn_encoded) ((VALUE)table[insn] != insn_encoded) #else #define INSN_CODE(insn) (insn) +#define TRACE_INSN_P(insn, insn_encoded) ((insn_encoded) >= VM_INSTRUCTION_SIZE/2) #endif -static void +void rb_iseq_trace_set(const rb_iseq_t *iseq, rb_event_flag_t turnon_events) { unsigned int i; @@ -2335,17 +2334,17 @@ rb_iseq_trace_set(const rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L2334 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); + if (events & turnon_events) { - if (!TRACE_INSN_P(insn)) { + if (!TRACE_INSN_P(insn, iseq_encoded[i])) { iseq_encoded[i] = INSN_CODE(insn + VM_INSTRUCTION_SIZE/2); } - else { - /* OK */ - } } - else if (TRACE_INSN_P(insn)) { + else if (TRACE_INSN_P(insn, iseq_encoded[i])) { VM_ASSERT(insn - VM_INSTRUCTION_SIZE/2 >= 0); - iseq_encoded[i] = INSN_CODE(insn - VM_INSTRUCTION_SIZE/2); + iseq_encoded[i] = INSN_CODE(insn); } i += insn_len(insn); } Index: iseq.h =================================================================== --- iseq.h (revision 60816) +++ iseq.h (revision 60817) @@ -116,6 +116,7 @@ VALUE rb_iseq_load(VALUE data, VALUE par https://github.com/ruby/ruby/blob/trunk/iseq.h#L116 VALUE rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc); struct st_table *ruby_insn_make_insn_table(void); unsigned int rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos); +void rb_iseq_trace_set(const rb_iseq_t *iseq, rb_event_flag_t turnon_events); void rb_iseq_trace_set_all(rb_event_flag_t turnon_events); void rb_iseq_trace_on_all(void); Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 60816) +++ vm_insnhelper.c (revision 60817) @@ -3729,9 +3729,16 @@ vm_trace(rb_execution_context_t *ec, rb_ https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3729 { const rb_iseq_t *iseq = reg_cfp->iseq; size_t pos = pc - iseq->body->iseq_encoded; + rb_event_flag_t cur_event_flags = ruby_vm_event_flags; rb_event_flag_t events = rb_iseq_event_flags(iseq, pos); rb_event_flag_t event; + if ((events & cur_event_flags) == 0) { + /* disable trace */ + rb_iseq_trace_set(iseq, cur_event_flags); + return; + } + if (ec->trace_arg != NULL) return; if (0) { Index: vm_trace.c =================================================================== --- vm_trace.c (revision 60816) +++ vm_trace.c (revision 60817) @@ -72,10 +72,14 @@ rb_vm_trace_mark_event_hooks(rb_hook_lis https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L72 static void update_global_event_hook(rb_event_flag_t vm_events) { - if ((vm_events & RUBY_EVENTS_TRACE_BY_ISEQ) != - (ruby_vm_event_flags & RUBY_EVENTS_TRACE_BY_ISEQ)) { - rb_iseq_trace_set_all(vm_events); + rb_event_flag_t new_iseq_events = vm_events & RUBY_EVENTS_TRACE_BY_ISEQ; + rb_event_flag_t cur_iseq_events = ruby_vm_event_flags & RUBY_EVENTS_TRACE_BY_ISEQ; + + if (new_iseq_events > cur_iseq_events) { + /* write all ISeqs iff new events are added */ + rb_iseq_trace_set_all(vm_events); } + ruby_vm_event_flags = vm_events; rb_objspace_set_event_hook(vm_events); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/