Java 17 bug (?) on Windows with MemorySegment.asSlice and offset = 3705032704
erel at eth.gl
erel at eth.gl
Thu May 12 05:38:16 UTC 2022
Hi,
It doesn’t happen on Linux. I’ve tested it with Oracle Java 17.0.3.1 and OpenJDK 17.0.2.
Code:
package test.test;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel.MapMode;
import java.nio.file.Path;
import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.ResourceScope;
public class Test {
public static void main(String[] args) throws Exception {
System.out.println(System.getProperty("sun.arch.data.model"));
System.out.println(System.getProperty("os.arch"));
System.out.println(System.getProperty("java.version"));
Path p = Path.of("test.dat");
RandomAccessFile raf = new RandomAccessFile("test.dat", "rw");
raf.setLength(8000000000L); //~8gb
raf.close();
MemorySegment mappedMemorySegment = MemorySegment.mapFile(p, 0, p.toFile().length(), MapMode.READ_WRITE, ResourceScope.newSharedScope());
System.out.println("byteSize: " + mappedMemorySegment.byteSize());
long offset = 3705032702L;
while (true) {
System.out.println("offset: " + offset);
MemorySegment target = mappedMemorySegment.asSlice(offset, 1);
offset = offset + 1;
try {
target.force();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
}
}
Output:
WARNING: Using incubator modules: jdk.incubator.foreign
64
amd64
17.0.3.1
byteSize: 8000000000
offset: 3705032702
offset: 3705032703
offset: 3705032704
java.io.UncheckedIOException: java.io.IOException: Attempt to access invalid address
at java.base/java.nio.MappedMemoryUtils.force(MappedMemoryUtils.java:102)
at java.base/java.nio.Buffer$1.force(Buffer.java:839)
at java.base/jdk.internal.misc.ScopedMemoryAccess.forceInternal(ScopedMemoryAccess.java:337)
at java.base/jdk.internal.misc.ScopedMemoryAccess.force(ScopedMemoryAccess.java:325)
at jdk.incubator.foreign/jdk.internal.foreign.MappedMemorySegmentImpl.force(MappedMemorySegmentImpl.java:104)
at test.test.Test.main(Test.java:30)
Caused by: java.io.IOException: Attempt to access invalid address
at java.base/java.nio.MappedMemoryUtils.force0(Native Method)
at java.base/java.nio.MappedMemoryUtils.force(MappedMemoryUtils.java:100)
... 5 more
This is a blocking issue for us. Suggestions will be welcomed.
Thanks,
Erel
More information about the panama-dev
mailing list