Skip to content

ZJIT: Write a callee frame on JIT-to-JIT calls #13579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 13, 2025

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Jun 11, 2025

This PR changes JIT-to-JIT calls to actually write a callee frame that is about to be pushed.

When JIT code makes a non-leaf call, it may dispatch an arbitrary method that looks at caller frames. When that happens, the method may read the locals, PC, ISEQ, and other things of the frame. Because that happens before the frame side-exits, we need to somehow make them available when needed.

As a first implementation to make that work, this PR writes them when a JIT frame is pushed. ZJIT should ideally optimize away the overhead, but I think it's nice to make things work first as we're onboarding more people to work on ZJIT.

@k0kubun k0kubun changed the title ZJIT: Write a callee frame on JIT-to-JIT calls (WIP) ZJIT: Write a callee frame on JIT-to-JIT calls Jun 11, 2025
@k0kubun k0kubun marked this pull request as ready for review June 11, 2025 23:26
@matzbot matzbot requested a review from a team June 11, 2025 23:26
Copy link
Contributor

@tekknolagi tekknolagi left a comment

Choose a reason for hiding this comment

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

After our conversation, overall it looks good.

I look forward to making this much lazier in the future.

I feel like we should have more tests, and more rigorous tests, for this new feature. Can we add some more to exercise this?

k0kubun and others added 4 commits June 12, 2025 16:00
Co-authored-by: Max Bernstein <tekknolagi@gmail.com>
Co-authored-by: Max Bernstein <tekknolagi@gmail.com>
@k0kubun
Copy link
Member Author

k0kubun commented Jun 12, 2025

I feel like we should have more tests, and more rigorous tests, for this new feature. Can we add some more to exercise this?

I added tests that dump non-argument locals on side exits 5b621b1 and one that checks cfp->pc 7916f3d.

Another test target would be the content of dumped locals. But to test the content of locals from a callee, we'd need to load a C extension in test/-ext-/debug/test_debug.rb like YJIT does. We're still not ready for running the current make test-all with ZJIT enabled.

Do you have other things you want to be tested in mind? We could just "have more tests" as you said, but I generally try to avoid bloating the number of tests by adding meaningless/duplicated test cases.

Copy link

launchable-app bot commented Jun 12, 2025

Tests Failed

✖️no tests failed ✔️61994 tests passed(1 flake)

@tekknolagi
Copy link
Contributor

I don't mean to bloat the tests but did not (at the time of comment) have a good set of recommendations for things to test. 2 tests for a bunch of new functionality just seemed a bit light. I can imagine having a bunch of dark untested corner cases

@k0kubun
Copy link
Member Author

k0kubun commented Jun 13, 2025

I think we should aim for enabling make btest, make test-all, and make test-spec on CI with ZJIT as soon as possible. They would test more corner cases than we can think of and write in test_zjit.rb. Even then, you'd encounter dark untested corner cases though. Anything we can come up with today is probably not a dark corner case.

This project should have got the test setup much earlier, but we were so focused on keeping generated code optimal that we never had the "rigorous tests" we could have got for free. This PR should bring us much closer to having it.

@k0kubun
Copy link
Member Author

k0kubun commented Jun 13, 2025

You approved the PR and the CI passed, so I'll merge this PR to unblock your stacked PR. We can add more tests as we come up with untested scenarios that are worth testing.

@k0kubun k0kubun merged commit 7fa3e1a into ruby:master Jun 13, 2025
89 of 92 checks passed
@k0kubun k0kubun deleted the zjit-push-frame branch June 13, 2025 00:18
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