diff options
author | Maxime Chevalier-Boisvert <[email protected]> | 2020-09-17 11:49:53 -0400 |
---|---|---|
committer | Alan Wu <[email protected]> | 2021-10-20 18:19:23 -0400 |
commit | 038f5d964ffdfcce7c1acbeb4c6ae4ad01a09014 (patch) | |
tree | 2c45b161943ed8d0e0cf0801179dcc3c6846889f /compile.c | |
parent | 1665bbacc16d7ea18625f5a8b5c7474a873dffb4 (diff) |
Avoid recompiling overlapping instruction sequences in ujit
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -862,22 +862,30 @@ rb_iseq_translate_threaded_code(rb_iseq_t *iseq) { #if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE const void * const *table = rb_vm_get_insns_address_table(); - unsigned int i; VALUE *encoded = (VALUE *)iseq->body->iseq_encoded; - for (i = 0; i < iseq->body->iseq_size; /* */ ) + unsigned int insn_idx; + unsigned int next_ujit_idx = 0; + + bool ujit_disabled = false /*get_cmdline_flag()*/; + + for (insn_idx = 0; insn_idx < iseq->body->iseq_size; /* */) { - int insn = (int)iseq->body->iseq_encoded[i]; + int insn = (int)iseq->body->iseq_encoded[insn_idx]; int len = insn_len(insn); - uint8_t* native_code_ptr = ujit_compile_insn(iseq, i); + uint8_t* native_code_ptr = NULL; + + // If ujit is enabled and hasn't already compiled this instruction + if (!ujit_disabled && insn_idx >= next_ujit_idx) + native_code_ptr = ujit_compile_insn(iseq, insn_idx, &next_ujit_idx); if (native_code_ptr) - encoded[i] = (VALUE)native_code_ptr; + encoded[insn_idx] = (VALUE)native_code_ptr; else - encoded[i] = (VALUE)table[insn]; + encoded[insn_idx] = (VALUE)table[insn]; - i += len; + insn_idx += len; } FL_SET((VALUE)iseq, ISEQ_TRANSLATED); |