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 ------------- Commit messages: - fix - fix test - add test Changes: https://git.openjdk.org/jdk/pull/26295/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=26295&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8362169 Stats: 44 lines in 3 files changed: 39 ins; 0 del; 5 mod Patch: https://git.openjdk.org/jdk/pull/26295.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/26295/head:pull/26295 PR: https://git.openjdk.org/jdk/pull/26295