On Tue, 25 Jul 2023 19:17:38 GMT, Jorn Vernee <jver...@openjdk.org> wrote:
> Port of: https://github.com/openjdk/panama-foreign/pull/848 from the > panama-foreign repo. > > Copying the PR body here for convenience: > > Due to a bug in the downcall linker stub generation, we don't save the return > value when capturing call state for trivial functions, and the return value > gets corrupted. > > We try not to save the return register around calls on the return path of a > downcall stub, if it is not needed. Currently we don't save the return > register when we're using a return buffer, since we write the return value to > the return buffer before the calls on the return path, which means it is safe > for those calls to overwrite the return register. But, the current logic also > says we don't need to save the return register if the function is trivial > (_needs_transition == false). The logic behind this was initially that, since > we don't have any calls on the return path, we don't need to save the return > register. But, after adding support for capturing call state, we now also > have a call on the return path for trivial functions that capture call state, > and around that call, we might need to save the return register. > > The fix is to simply save the return register when capturing call state, > regardless of whether the function is trivial or not. In the case of just a > trivial function that doesn't capture call state, we still don't save the > return register around the return path calls for the thread state transition > (which is not needed), since we don't generate those thread state transitions > in the first first place. > > Testing: jdk-tier1, jdk-tier2, jdk-tier5. @TheRealMDoerr @feilongjiang Just a heads up: this patch touches the PPC and RISC-V ports as well, which I'm not able to test. I've just eye-balled the needed changes. I don't think there will be an issue since the code structure is almost identical, but you might want to run the `java/foreign/capturecallstate/TestCaptureCallState.java` test with this patch just to be sure. ------------- PR Comment: https://git.openjdk.org/jdk/pull/15025#issuecomment-1650586454