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).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2017-11-17 06:24:55 +00:00
Родитель 80facdd93a
Коммит 1a96057626
4 изменённых файлов: 24 добавлений и 13 удалений

19
iseq.c
Просмотреть файл

@ -336,8 +336,6 @@ prepare_iseq_build(rb_iseq_t *iseq,
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 type)
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, rb_event_flag_t turnon_events)
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);
}

1
iseq.h
Просмотреть файл

@ -116,6 +116,7 @@ VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt);
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);

Просмотреть файл

@ -3729,9 +3729,16 @@ vm_trace(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, const VALUE *p
{
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) {

Просмотреть файл

@ -72,10 +72,14 @@ rb_vm_trace_mark_event_hooks(rb_hook_list_t *hooks)
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);
}