Skip to content

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Aug 29, 2025

This will allow TracePoint events to be triggered when calling previously JITed methods from the interpreter.
I also opened #14420 to find ways to add a new patch point for TracePoint but it's not working atm.

@st0012 st0012 force-pushed the zjit-disable-when-tracepoint-is-enabled branch from 4a292de to 6a4b985 Compare August 29, 2025 20:21
// Do not test the JIT code in HIR tests
if cfg!(test) {
return std::ptr::null();
}

// Check if c_call or c_return tracing is enabled - if so, don't compile
if unsafe { rb_c_method_tracing_currently_enabled(ec) } {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why check that here? If you're trying to mimic what YJIT does, it should be a side exit on HIR instructions for C method calls (or dynamic dispatch that can be C method calls). We generally don't want to fail the compilation (return null()).

@k0kubun
Copy link
Member

k0kubun commented Aug 29, 2025

I think walking through iseqs and call rb_iseq_reset_jit_func on them after TracePoint activation already allows TracePoint to run in some capacity. (I decide to add support for C return and line events separately).

It only impacts JIT entries after TracePoint is enabled, which would miss returning from a non-leaf call to JIT code since we have no such patch points yet, but I guess it's fine to start from supporting just that.

@st0012 st0012 force-pushed the zjit-disable-when-tracepoint-is-enabled branch 3 times, most recently from 82465f8 to 328ef59 Compare September 1, 2025 18:17
@st0012 st0012 changed the title ZJIT: Clear ZJIT compiled code when TracePoint is enabled ZJIT: Clear jit entry from iseqs after TracePoint activation Sep 1, 2025
@st0012 st0012 force-pushed the zjit-disable-when-tracepoint-is-enabled branch from 328ef59 to 07eb3b6 Compare September 1, 2025 18:27
@st0012
Copy link
Member Author

st0012 commented Sep 1, 2025

It only impacts JIT entries after TracePoint is enabled, which would miss returning from a non-leaf call to JIT code since we have no such patch points yet, but I guess it's fine to start from supporting just that.

Thanks for the pointer. I tried to add a new patch point for that in #14420 but it's currently not working 😞 I'll log more info about it there

@st0012 st0012 marked this pull request as ready for review September 1, 2025 18:33
@matzbot matzbot requested a review from a team September 1, 2025 18:33
zjit/src/gc.rs Outdated
@@ -222,3 +222,14 @@ pub fn remove_gc_offsets(payload_ptr: *mut IseqPayload, removed_range: &Range<Co
fn ranges_overlap<T>(left: &Range<T>, right: &Range<T>) -> bool where T: PartialOrd {
left.start < right.end && right.start < left.end
}

/// Iterate over all existing ISEQs
pub fn for_each_iseq<F: FnMut(IseqPtr)>(mut callback: F) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about putting this in cruby.rs? Unless gc.rs uses it by itself, it has nothing to do with GC.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@st0012 st0012 force-pushed the zjit-disable-when-tracepoint-is-enabled branch from 07eb3b6 to 2a5a9bf Compare September 2, 2025 18:47
@k0kubun k0kubun enabled auto-merge (squash) September 2, 2025 18:57
@k0kubun k0kubun merged commit 77a421f into ruby:master Sep 2, 2025
85 checks passed
@k0kubun k0kubun deleted the zjit-disable-when-tracepoint-is-enabled branch September 2, 2025 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants