Feature #10185 » iseq-iseq-diet.patch
compile.c | ||
---|---|---|
const void * const *table = rb_vm_get_insns_address_table();
|
||
unsigned int i;
|
||
iseq->iseq_encoded = ALLOC_N(VALUE, iseq->iseq_size);
|
||
MEMCPY(iseq->iseq_encoded, iseq->iseq, VALUE, iseq->iseq_size);
|
||
for (i = 0; i < iseq->iseq_size; /* */ ) {
|
||
int insn = (int)iseq->iseq_encoded[i];
|
||
int len = insn_len(insn);
|
||
iseq->iseq_encoded[i] = (VALUE)table[insn];
|
||
i += len;
|
||
}
|
||
xfree(iseq->iseq);
|
||
iseq->iseq = 0;
|
||
#else
|
||
iseq->iseq_encoded = iseq->iseq;
|
||
#endif
|
||
return COMPILE_OK;
|
||
}
|
||
... | ... | |
VALUE *
|
||
rb_iseq_untranslate_threaded_code(rb_iseq_t *iseq) /* cold path */
|
||
{
|
||
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
|
||
unsigned int i;
|
||
VALUE *iseq_raw = ALLOC_N(VALUE, iseq->iseq_size);
|
||
if (iseq->iseq)
|
||
return iseq->iseq;
|
||
MEMCPY(iseq_raw, iseq->iseq_encoded, VALUE, iseq->iseq_size);
|
||
iseq->iseq = ALLOC_N(VALUE, iseq->iseq_size);
|
||
MEMCPY(iseq->iseq, iseq->iseq_encoded, VALUE, iseq->iseq_size);
|
||
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
|
||
{
|
||
unsigned int i;
|
||
for (i = 0; i < iseq->iseq_size; /* */ ) {
|
||
int insn = (VALUE)rb_vm_addr2insn((const void *)iseq->iseq[i]);
|
||
for (i = 0; i < iseq->iseq_size; /* */ ) {
|
||
int insn = (VALUE)rb_vm_addr2insn((const void *)iseq_raw[i]);
|
||
iseq->iseq[i] = insn;
|
||
i += insn_len(insn);
|
||
iseq_raw[i] = insn;
|
||
i += insn_len(insn);
|
||
}
|
||
}
|
||
#else
|
||
iseq->iseq = iseq->iseq_encoded;
|
||
#endif
|
||
return iseq->iseq;
|
||
return iseq_raw;
|
||
}
|
||
/*********************************************/
|
||
... | ... | |
}
|
||
#endif
|
||
iseq->iseq = (void *)generated_iseq;
|
||
iseq->iseq_encoded = (void *)generated_iseq;
|
||
iseq->iseq_size = pos;
|
||
iseq->stack_max = stack_max;
|
||
iseq.c | ||
---|---|---|
RSTRING_PTR(iseq->location.path));
|
||
}
|
||
if (iseq->iseq != iseq->iseq_encoded) {
|
||
RUBY_FREE_UNLESS_NULL(iseq->iseq_encoded);
|
||
}
|
||
RUBY_FREE_UNLESS_NULL(iseq->iseq);
|
||
RUBY_FREE_UNLESS_NULL(iseq->iseq_encoded);
|
||
RUBY_FREE_UNLESS_NULL(iseq->line_info_table);
|
||
RUBY_FREE_UNLESS_NULL(iseq->local_table);
|
||
RUBY_FREE_UNLESS_NULL(iseq->is_entries);
|
||
... | ... | |
if (ptr) {
|
||
iseq = ptr;
|
||
if (!iseq->orig) {
|
||
if (iseq->iseq && iseq->iseq != iseq->iseq_encoded) {
|
||
size += iseq->iseq_size * sizeof(VALUE);
|
||
}
|
||
size += iseq->iseq_size * sizeof(VALUE);
|
||
size += iseq->line_info_size * sizeof(struct iseq_line_info_entry);
|
||
size += iseq->local_table_size * sizeof(ID);
|
||
... | ... | |
* Iseq -> Iseq inspect object
|
||
*/
|
||
int
|
||
rb_iseq_disasm_insn(VALUE ret, const VALUE *iseq, size_t pos,
|
||
rb_iseq_disasm_insn(VALUE ret, const VALUE *iseq_raw, size_t pos,
|
||
const rb_iseq_t *iseqdat, VALUE child)
|
||
{
|
||
VALUE insn = iseq[pos];
|
||
VALUE insn = iseq_raw[pos];
|
||
int len = insn_len(insn);
|
||
int j;
|
||
const char *types = insn_op_types(insn);
|
||
... | ... | |
for (j = 0; types[j]; j++) {
|
||
const char *types = insn_op_types(insn);
|
||
VALUE opstr = rb_insn_operand_intern(iseqdat, insn, j, iseq[pos + j + 1],
|
||
len, pos, &iseq[pos + j + 2],
|
||
VALUE opstr = rb_insn_operand_intern(iseqdat, insn, j,
|
||
iseq_raw[pos + j + 1],
|
||
len, pos, &iseq_raw[pos + j + 2],
|
||
child);
|
||
rb_str_concat(str, opstr);
|
||
... | ... | |
rb_iseq_disasm(VALUE self)
|
||
{
|
||
rb_iseq_t *iseqdat = iseq_check(self);
|
||
VALUE *iseq;
|
||
VALUE *iseq_raw;
|
||
VALUE str = rb_str_new(0, 0);
|
||
VALUE child = rb_ary_new();
|
||
unsigned int size;
|
||
... | ... | |
rb_secure(1);
|
||
iseq = rb_iseq_untranslate_threaded_code(iseqdat);
|
||
size = iseqdat->iseq_size;
|
||
rb_str_cat2(str, "== disasm: ");
|
||
... | ... | |
}
|
||
/* show each line */
|
||
iseq_raw = rb_iseq_untranslate_threaded_code(iseqdat);
|
||
for (n = 0; n < size;) {
|
||
n += rb_iseq_disasm_insn(str, iseq, n, iseqdat, child);
|
||
n += rb_iseq_disasm_insn(str, iseq_raw, n, iseqdat, child);
|
||
}
|
||
xfree(iseq_raw);
|
||
for (i = 0; i < RARRAY_LEN(child); i++) {
|
||
VALUE isv = rb_ary_entry(child, i);
|
||
... | ... | |
size_t ti;
|
||
unsigned int pos;
|
||
unsigned int line = 0;
|
||
VALUE *seq;
|
||
VALUE *seq, *iseq_raw;
|
||
VALUE val = rb_ary_new();
|
||
VALUE type; /* Symbol */
|
||
... | ... | |
}
|
||
/* body */
|
||
rb_iseq_untranslate_threaded_code(iseq);
|
||
iseq_raw = rb_iseq_untranslate_threaded_code(iseq);
|
||
for (seq = iseq->iseq; seq < iseq->iseq + iseq->iseq_size; ) {
|
||
for (seq = iseq_raw; seq < iseq_raw + iseq->iseq_size; ) {
|
||
VALUE insn = *seq++;
|
||
int j, len = insn_len(insn);
|
||
VALUE *nseq = seq + len - 1;
|
||
... | ... | |
for (j=0; j<len-1; j++, seq++) {
|
||
switch (insn_op_type(insn, j)) {
|
||
case TS_OFFSET: {
|
||
unsigned long idx = nseq - iseq->iseq + *seq;
|
||
unsigned long idx = nseq - iseq_raw + *seq;
|
||
rb_ary_push(ary, register_label(labels_table, idx));
|
||
break;
|
||
}
|
||
... | ... | |
for (i=0; i<RARRAY_LEN(val); i+=2) {
|
||
VALUE pos = FIX2INT(rb_ary_entry(val, i+1));
|
||
unsigned long idx = nseq - iseq->iseq + pos;
|
||
unsigned long idx = nseq - iseq_raw + pos;
|
||
rb_ary_store(val, i+1,
|
||
register_label(labels_table, idx));
|
||
... | ... | |
}
|
||
rb_ary_push(body, ary);
|
||
}
|
||
xfree(iseq_raw);
|
||
nbody = body;
|
||
... | ... | |
RB_OBJ_WRITE(iseq->self, &iseq->mark_ary, 0);
|
||
iseq->self = iseqval;
|
||
iseq->iseq = ALLOC_N(VALUE, iseq->iseq_size);
|
||
iseq->iseq_encoded = ALLOC_N(VALUE, iseq->iseq_size);
|
||
for (i=0; i<iseq->iseq_size; i+=2) {
|
||
iseq->iseq[i] = BIN(opt_call_c_function);
|
||
iseq->iseq[i+1] = (VALUE)func;
|
||
iseq->iseq_encoded[i] = BIN(opt_call_c_function);
|
||
iseq->iseq_encoded[i+1] = (VALUE)func;
|
||
}
|
||
rb_iseq_translate_threaded_code(iseq);
|
||
... | ... | |
size_t insn;
|
||
rb_iseq_t *iseq;
|
||
int cont = 1;
|
||
VALUE *iseq_raw;
|
||
GetISeqPtr(iseqval, iseq);
|
||
rb_iseq_untranslate_threaded_code(iseq);
|
||
iseq_raw = rb_iseq_untranslate_threaded_code(iseq);
|
||
for (pos = 0; cont && pos < iseq->iseq_size; pos += insn_len(insn)) {
|
||
insn = iseq->iseq[pos];
|
||
insn = iseq_raw[pos];
|
||
if (insn == BIN(trace)) {
|
||
rb_event_flag_t current_events = (VALUE)iseq->iseq[pos+1];
|
||
rb_event_flag_t current_events = (VALUE)iseq_raw[pos+1];
|
||
if (current_events & RUBY_EVENT_LINE) {
|
||
rb_event_flag_t events = current_events & RUBY_EVENT_SPECIFIED_LINE;
|
||
... | ... | |
/* printf("line: %d\n", line); */
|
||
cont = (*func)(line, &events, data);
|
||
if (current_events != events) {
|
||
iseq->iseq[pos+1] = iseq->iseq_encoded[pos+1] =
|
||
iseq_raw[pos+1] = iseq->iseq_encoded[pos+1] =
|
||
(VALUE)(current_events | (events & RUBY_EVENT_SPECIFIED_LINE));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
xfree(iseq_raw);
|
||
return trace_num;
|
||
}
|
||
vm_core.h | ||
---|---|---|
rb_iseq_location_t location;
|
||
VALUE *iseq; /* iseq (insn number and operands) */
|
||
VALUE *iseq_encoded; /* encoded iseq */
|
||
VALUE *iseq_encoded; /* encoded iseq (insn addr and operands) */
|
||
unsigned int iseq_size;
|
||
unsigned int line_info_size;
|
||
vm_dump.c | ||
---|---|---|
rb_iseq_t *iseq = cfp->iseq;
|
||
if (iseq != 0) {
|
||
VALUE *seq = rb_iseq_untranslate_threaded_code(iseq);
|
||
ptrdiff_t pc = _pc - iseq->iseq_encoded;
|
||
int i;
|
||
... | ... | |
/* printf("%3"PRIdPTRDIFF" ", VM_CFP_CNT(th, cfp)); */
|
||
if (pc >= 0) {
|
||
rb_iseq_disasm_insn(0, seq, (size_t)pc, iseq, 0);
|
||
VALUE *iseq_raw = rb_iseq_untranslate_threaded_code(iseq);
|
||
rb_iseq_disasm_insn(0, iseq_raw, (size_t)pc, iseq, 0);
|
||
xfree(iseq_raw);
|
||
}
|
||
}
|
||
-
|