Skip to content

Commit 14d56b1

Browse files
committed
Fix bug when marking iseq before instruction have been translated
If an instruction sequence gets marked before instructions have been translated, the we need to *not* translate back instructions in the mark function.
1 parent 6de83af commit 14d56b1

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

compile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ rb_iseq_translate_threaded_code(rb_iseq_t *iseq)
740740
encoded[i] = (VALUE)table[insn];
741741
i += len;
742742
}
743+
FL_SET(iseq, ISEQ_TRANSLATED);
743744
#endif
744745
return COMPILE_OK;
745746
}

iseq.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,19 @@ rb_vm_insn_addr2insn2(const void *addr)
129129
}
130130
#endif
131131

132+
static int
133+
rb_vm_insn_null_translator(const void *addr)
134+
{
135+
return (int)addr;
136+
}
137+
132138
typedef void iseq_value_itr_t(void *ctx, VALUE obj);
139+
typedef int rb_vm_insns_translator_t(const void *addr);
133140

134141
static int
135-
iseq_extract_values(const VALUE *code, size_t pos, iseq_value_itr_t * func, void *data)
142+
iseq_extract_values(const VALUE *code, size_t pos, iseq_value_itr_t * func, void *data, rb_vm_insns_translator_t * translator)
136143
{
137-
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
138-
VALUE insn = rb_vm_insn_addr2insn2((void *)code[pos]);
139-
#else
140-
VALUE insn = code[pos];
141-
#endif
144+
VALUE insn = translator((void *)code[pos]);
142145
int len = insn_len(insn);
143146
int op_no;
144147
const char *types = insn_op_types(insn);
@@ -170,12 +173,23 @@ rb_iseq_each_value(const rb_iseq_t *iseq, iseq_value_itr_t * func, void *data)
170173
unsigned int size;
171174
const VALUE *code;
172175
size_t n;
176+
rb_vm_insns_translator_t * translator;
173177

174178
size = iseq->body->iseq_size;
175179
code = iseq->body->iseq_encoded;
176180

181+
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
182+
if (FL_TEST(iseq, ISEQ_TRANSLATED)) {
183+
translator = rb_vm_insn_addr2insn2;
184+
} else {
185+
translator = rb_vm_insn_null_translator;
186+
}
187+
#else
188+
translator = rb_vm_insn_null_translator;
189+
#endif
190+
177191
for (n = 0; n < size;) {
178-
n += iseq_extract_values(code, n, func, data);
192+
n += iseq_extract_values(code, n, func, data, translator);
179193
}
180194
}
181195

iseq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ ISEQ_ORIGINAL_ISEQ_ALLOC(const rb_iseq_t *iseq, long size)
9494

9595
#define ISEQ_NOT_LOADED_YET IMEMO_FL_USER1
9696
#define ISEQ_USE_COMPILE_DATA IMEMO_FL_USER2
97+
#define ISEQ_TRANSLATED IMEMO_FL_USER3
9798

9899
struct iseq_compile_data {
99100
/* GC is needed */

0 commit comments

Comments
 (0)