ZJIT: Decouple gen_function_stub and gen_function_stub_hit_trampoline#16249
Merged
tenderlove merged 1 commit intoruby:masterfrom Feb 25, 2026
Merged
ZJIT: Decouple gen_function_stub and gen_function_stub_hit_trampoline#16249tenderlove merged 1 commit intoruby:masterfrom
tenderlove merged 1 commit intoruby:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
71205b3 to
1dc0fe9
Compare
k0kubun
reviewed
Feb 25, 2026
k0kubun
approved these changes
Feb 25, 2026
Before this change, gen_function_stub and gen_function_stub_hit_trampoline communicated via a scratch register. We would like gen_function_stub_hit_trampoline to have more freedom with regard to the registers it uses, especially for the CCall in to function_stub_hit. Instead of communicating via scratch register, we'll communicate via stack. Practically speaking, this means: * Stop using x15 (scratch reg) to communicate iseq call addr from call stub to function sub hit trampoline; use stack instead * Don't try to CCall with x15 as first argument; can't use scratch reg in parallel move of arguments Here is pseudo assembly of before this commit: ``` some_send_direct_in_a_ruby_method(JIT code): mov x15, gen_function_stub mov x0, self mov x1, 1 blr x15 gen_function_stub: mov x15, 0xISEQADDR (the address of the ISEQ we _want_ to compile) jmp function_stub_hit_trampoline function_stub_hit_trampoline: function prologue cpush ALL_JIT_REGS mov x0, x15 # currently x15 is 0xISEQADDR mov x1, CFP mov x2, SP blr function_stub_hit mov x15, x0 # write jump address to x15 (code pointer for compiled iseq) cpop ALL_JIT_REGS function epilogue jmp x15 ``` Here is pseudo assembly of after this commit: ``` some_send_direct_in_a_ruby_method(JIT code): mov x15, gen_function_stub mov x0, self mov x1, 1 blr x15 gen_function_stub: mov x15, 0xISEQADDR (the address of the ISEQ we _want_ to compile) push x15 jmp function_stub_hit_trampoline function_stub_hit_trampoline: pop x15 # get the ISEQ addr from gen_function_stub function prologue cpush ALL_JIT_REGS mov x0, x15 # currently x15 is 0xISEQADDR mov x1, CFP mov x2, SP blr function_stub_hit mov x15, x0 # write jump address to x15 (code pointer for compiled iseq) cpop ALL_JIT_REGS function epilogue jmp x15 ```
1dc0fe9 to
61e31cb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before this change, gen_function_stub and
gen_function_stub_hit_trampoline communicated via a scratch register. We would like gen_function_stub_hit_trampoline to have more freedom with regard to the registers it uses, especially for the CCall in to function_stub_hit. Instead of communicating via scratch register, we'll communicate via stack.
Practically speaking, this means:
Here is pseudo assembly of before this commit:
Here is pseudo assembly of after this commit: