summaryrefslogtreecommitdiff
path: root/zjit.c
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2025-04-04 09:06:56 -0700
committerTakashi Kokubun <[email protected]>2025-04-18 21:53:01 +0900
commit8b72e07359488ebc4af2a23e44919c56f7013399 (patch)
tree988786c9057abb9fb7220316eda1b262c5868633 /zjit.c
parent2915806820f6fd0686a8a2c4484c961266dcc817 (diff)
Disable ZJIT profiling at call-threshold (https://github.com/Shopify/zjit/pull/99)
* Disable ZJIT profiling at call-threshold * Stop referencing ZJIT instructions in codegen
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13131
Diffstat (limited to 'zjit.c')
-rw-r--r--zjit.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/zjit.c b/zjit.c
index f188eceb1f..81c285f095 100644
--- a/zjit.c
+++ b/zjit.c
@@ -168,12 +168,17 @@ rb_RSTRING_PTR(VALUE str)
return RSTRING_PTR(str);
}
+void rb_zjit_profile_disable(const rb_iseq_t *iseq);
+
void
rb_zjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception)
{
RB_VM_LOCK_ENTER();
rb_vm_barrier();
+ // Convert ZJIT instructions back to bare instructions
+ rb_zjit_profile_disable(iseq);
+
// Compile a block version starting at the current instruction
uint8_t *rb_zjit_iseq_gen_entry_point(const rb_iseq_t *iseq, rb_execution_context_t *ec); // defined in Rust
uintptr_t code_ptr = (uintptr_t)rb_zjit_iseq_gen_entry_point(iseq, ec);
@@ -652,7 +657,7 @@ rb_RCLASS_ORIGIN(VALUE c)
// Convert a given ISEQ's instructions to zjit_* instructions
void
-rb_zjit_profile_iseq(const rb_iseq_t *iseq)
+rb_zjit_profile_enable(const rb_iseq_t *iseq)
{
// This table encodes an opcode into the instruction's address
const void *const *insn_table = rb_vm_get_insns_address_table();
@@ -660,7 +665,7 @@ rb_zjit_profile_iseq(const rb_iseq_t *iseq)
unsigned int insn_idx = 0;
while (insn_idx < iseq->body->iseq_size) {
int insn = rb_vm_insn_decode(iseq->body->iseq_encoded[insn_idx]);
- int zjit_insn = vm_insn_to_zjit_insn(insn);
+ int zjit_insn = vm_bare_insn_to_zjit_insn(insn);
if (insn != zjit_insn) {
iseq->body->iseq_encoded[insn_idx] = (VALUE)insn_table[zjit_insn];
}
@@ -668,6 +673,24 @@ rb_zjit_profile_iseq(const rb_iseq_t *iseq)
}
}
+// Convert a given ISEQ's ZJIT instructions to bare instructions
+void
+rb_zjit_profile_disable(const rb_iseq_t *iseq)
+{
+ // This table encodes an opcode into the instruction's address
+ const void *const *insn_table = rb_vm_get_insns_address_table();
+
+ unsigned int insn_idx = 0;
+ while (insn_idx < iseq->body->iseq_size) {
+ int insn = rb_vm_insn_decode(iseq->body->iseq_encoded[insn_idx]);
+ int bare_insn = vm_zjit_insn_to_bare_insn(insn);
+ if (insn != bare_insn) {
+ iseq->body->iseq_encoded[insn_idx] = (VALUE)insn_table[bare_insn];
+ }
+ insn_idx += insn_len(insn);
+ }
+}
+
// Get profiling information for ISEQ
void *
rb_iseq_get_zjit_payload(const rb_iseq_t *iseq)