-
Bug
-
Resolution: Fixed
-
P4
-
26
-
None
-
master
See discussion here: https://mail.openjdk.org/pipermail/panama-dev/2025-July/021078.html
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. The STRUCT_REFERENCE case in CallArranger), 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 pointer argument will be attached to the same scope. This is incorrect, as any pointer argument should be attached to the global scope.
When running the attached reproducer, the following exception is observed:
Exception in thread "main" java.lang.RuntimeException: java.lang.IllegalStateException: Already closed
at CCB.main(CCB.java:81)
Caused by: java.lang.IllegalStateException: Already closed
at java.base/jdk.internal.foreign.MemorySessionImpl.alreadyClosed(MemorySessionImpl.java:310)
at java.base/jdk.internal.misc.ScopedMemoryAccess$ScopedAccessError.newRuntimeException(ScopedMemoryAccess.java:113)
at java.base/jdk.internal.misc.ScopedMemoryAccess.getLongUnaligned(ScopedMemoryAccess.java:2573)
at java.base/java.lang.invoke.VarHandleSegmentAsLongs.get(VarHandleSegmentAsLongs.java:108)
at java.base/jdk.internal.foreign.AbstractMemorySegmentImpl.get(AbstractMemorySegmentImpl.java:800)
at java.base/jdk.internal.foreign.StringSupport.chunkedStrlenByte(StringSupport.java:140)
at java.base/jdk.internal.foreign.StringSupport.readByte(StringSupport.java:65)
at java.base/jdk.internal.foreign.StringSupport.read(StringSupport.java:50)
at java.base/jdk.internal.foreign.AbstractMemorySegmentImpl.getString(AbstractMemorySegmentImpl.java:967)
at java.base/jdk.internal.foreign.AbstractMemorySegmentImpl.getString(AbstractMemorySegmentImpl.java:961)
at CCB.main(CCB.java:79)
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. The STRUCT_REFERENCE case in CallArranger), 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 pointer argument will be attached to the same scope. This is incorrect, as any pointer argument should be attached to the global scope.
When running the attached reproducer, the following exception is observed:
Exception in thread "main" java.lang.RuntimeException: java.lang.IllegalStateException: Already closed
at CCB.main(CCB.java:81)
Caused by: java.lang.IllegalStateException: Already closed
at java.base/jdk.internal.foreign.MemorySessionImpl.alreadyClosed(MemorySessionImpl.java:310)
at java.base/jdk.internal.misc.ScopedMemoryAccess$ScopedAccessError.newRuntimeException(ScopedMemoryAccess.java:113)
at java.base/jdk.internal.misc.ScopedMemoryAccess.getLongUnaligned(ScopedMemoryAccess.java:2573)
at java.base/java.lang.invoke.VarHandleSegmentAsLongs.get(VarHandleSegmentAsLongs.java:108)
at java.base/jdk.internal.foreign.AbstractMemorySegmentImpl.get(AbstractMemorySegmentImpl.java:800)
at java.base/jdk.internal.foreign.StringSupport.chunkedStrlenByte(StringSupport.java:140)
at java.base/jdk.internal.foreign.StringSupport.readByte(StringSupport.java:65)
at java.base/jdk.internal.foreign.StringSupport.read(StringSupport.java:50)
at java.base/jdk.internal.foreign.AbstractMemorySegmentImpl.getString(AbstractMemorySegmentImpl.java:967)
at java.base/jdk.internal.foreign.AbstractMemorySegmentImpl.getString(AbstractMemorySegmentImpl.java:961)
at CCB.main(CCB.java:79)
- links to
-
Commit(master) openjdk/jdk/9dc62825
-
Review(master) openjdk/jdk/26295