Skip to content

Conversation

@dalehamel
Copy link
Member

@dalehamel dalehamel commented Nov 3, 2025

What

Detect JIT frames produced by ruby's yjit / zjit to enable the ruby interpreter to still work if jit is in use.

Screenshot 2025-11-06 at 11 10 10 AM

Why

yjit is a substantial improvement to performance, but currently breaks the ruby interpreter as it will never run, since the PC for the interpreter is never called - the whole point of JIT is to avoid the interpreter after all.

How

We use the SynchronizeMappings hook to detect the ruby JIT address range, and if the PC is in this range we will push a dummy frame to indicate that the leaf is some JIT code.

In the future, we can support the linux jit interface to symbolize these, but for now we just push a dummy frame.

Since Ruby's jit works by just running native code replacing the ISEQ of the leaf CME, we can just switch to unwinding the ruby stack once we detect a JIT frame.

However, since we cannot be guaranteed base pointers are available (and even if they are, we don't seem to be able to further unwind correctly with the native unwinder), we can't switch back to native unwinding once we have detected a JIT frame on the stack. This means that if JIT is enabled, we don't get the "interleaved" native and ruby stacks anymore, but we do still get the native frames on the edge of the stack which are probably the most interesting:

Screenshot 2025-11-06 at 11 15 32 AM

@dalehamel dalehamel changed the title BPF side of jit handling Handle JIT frames Nov 4, 2025
@dalehamel dalehamel changed the title Handle JIT frames Handle JIT PC with JIT frame type Nov 4, 2025
@dalehamel dalehamel changed the title Handle JIT PC with JIT frame type Handle Ruby JIT PC with JIT frame type Nov 4, 2025
@dalehamel dalehamel changed the base branch from fix-leaf-lineno to main November 4, 2025 01:42
@dalehamel dalehamel changed the base branch from main to fix-leaf-lineno November 4, 2025 01:42
@dalehamel dalehamel force-pushed the ruby-jit-frames branch 3 times, most recently from a2aa0f6 to 089be93 Compare November 5, 2025 23:07
@github-actions
Copy link

github-actions bot commented Jan 8, 2026

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jan 8, 2026
@dalehamel dalehamel removed the Stale label Jan 8, 2026
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.

1 participant