summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-23 08:32:31 (GMT)
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-23 08:32:31 (GMT)
commit5b72097225797dfb91d4e3cbd4983bedf0eadb26 (patch)
tree8a1c8ca5e11d831cfb1021c495df5b4fc1ea2335 /iseq.c
parentd574683c40d42c1ec834c99c2717cbd8de442353 (diff)
iseq.c (rb_iseq_trace_set): refactoring by using encoded_insn_data
Now it uses encoded_insn_data to identify and replace each encoded insn. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c36
1 files changed, 13 insertions, 23 deletions
diff --git a/iseq.c b/iseq.c
index 424771c..112f588 100644
--- a/iseq.c
+++ b/iseq.c
@@ -2914,14 +2914,20 @@ rb_vm_insn_addr2insn(const void *addr)
rb_bug("rb_vm_insn_addr2insn: invalid insn address: %p", addr);
}
+static inline int
+encoded_iseq_trace_instrument(VALUE *iseq_encoded_insn, rb_event_flag_t turnon)
+{
+ st_data_t key = (st_data_t)*iseq_encoded_insn;
+ st_data_t val;
-#define TRACE_INSN_P(insn) ((insn) >= VM_INSTRUCTION_SIZE/2)
+ if (st_lookup(encoded_insn_data, key, &val)) {
+ insn_data_t *e = (insn_data_t *)val;
+ *iseq_encoded_insn = (VALUE) (turnon ? e->trace_encoded_insn : e->notrace_encoded_insn);
+ return e->insn_len;
+ }
-#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
-#define INSN_CODE(insn) ((VALUE)table[insn])
-#else
-#define INSN_CODE(insn) (insn)
-#endif
+ rb_bug("trace_instrument: invalid insn address: %p", (void *)*iseq_encoded_insn);
+}
void
rb_iseq_trace_set(const rb_iseq_t *iseq, rb_event_flag_t turnon_events)
@@ -2939,27 +2945,11 @@ rb_iseq_trace_set(const rb_iseq_t *iseq, rb_event_flag_t turnon_events)
unsigned int i;
const struct rb_iseq_constant_body *const body = iseq->body;
VALUE *iseq_encoded = (VALUE *)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();
-#else
- const VALUE *code = body->iseq_encoded;
-#endif
((rb_iseq_t *)iseq)->aux.trace_events = turnon_events;
for (i=0; i<body->iseq_size;) {
- int insn = (int)code[i];
rb_event_flag_t events = rb_iseq_event_flags(iseq, i);
-
- if (events & turnon_events) {
- if (!TRACE_INSN_P(insn)) {
- iseq_encoded[i] = INSN_CODE(insn + VM_INSTRUCTION_SIZE/2);
- }
- }
- else if (TRACE_INSN_P(insn)) {
- iseq_encoded[i] = INSN_CODE(insn - VM_INSTRUCTION_SIZE/2);
- }
- i += insn_len(insn);
+ i += encoded_iseq_trace_instrument(&iseq_encoded[i], events & turnon_events);
}
/* clear for debugging: ISEQ_ORIGINAL_ISEQ_CLEAR(iseq); */
}