On Mon, 14 Jul 2025 15:33:35 GMT, Jorn Vernee <jver...@openjdk.org> wrote:
> Issue copied from the JBS issue: > > When an upcall stub accepts a by-value struct, and the struct is passed by > the underlying ABI as a pointer to a temporary copy on the caller's stack > (for instance on Windows when the struct doesn't fit into a single register), > a scope is created for the duration of the upcall, to which the memory > segment for this struct is attached. > > However, if such a scope is created for the upcall, any other unrelated > pointer argument will _also_ be attached to the same scope. This is > incorrect, as unrelated pointer arguments should be attached to the global > scope. The underlying issue is that, when deciding whether a particular > argument needs to be attached to the scope, we check if _any_ of the argument > needs to be attached to the created scope. > > This PR fixes the issue by calling `boxAddress.needsScope()` in > `BindingSpecializer::emitBoxAddress`, which checks only if that particular > argument needs to be attached to the upcall scope. > > I've also renamed the 'global' `needsScope` method, which checks whether > _any_ of the arguments need a scope, to `anyArgNeedsScope` for clarity. > > Testing: `jdk_foreign` test suite on Mac/Windows/Linux x64, and Mac/Linux > aarch64 This pull request has now been integrated. Changeset: 9dc62825 Author: Jorn Vernee <jver...@openjdk.org> URL: https://git.openjdk.org/jdk/commit/9dc62825b5e7300542d22df0b87b79116f3562d3 Stats: 44 lines in 3 files changed: 39 ins; 0 del; 5 mod 8362169: Pointer passed to upcall may get wrong scope Reviewed-by: mcimadamore ------------- PR: https://git.openjdk.org/jdk/pull/26295