BUG: withOwnerThread closes MappedMemorySegment
sundararajan.athijegannathan at oracle.com
sundararajan.athijegannathan at oracle.com
Wed Sep 23 05:00:21 UTC 2020
javadoc of MemorySegment.withOwnerThread starts as follows:
" * Obtains a new memory segment backed by the same underlying memory
region as this segment,
* but with different owner thread. As a side-effect, this segment
will be marked as <em>not alive</em>,
* and subsequent operations on this segment will result in runtime
errors.
"
So the behavior seen is as the specification.
-Sundar
On 23/09/20 7:36 am, Ty Young wrote:
> A bug seems to have been introduced wherein using withOwnerThread
> causes a MappedMemorySegment to close:
>
>
> File file = new File("./test");
>
> if(file.exists())
> file.delete();
>
> file.createNewFile();
>
> MappedMemorySegment nativeFile =
> MemorySegment.mapFromPath(file.toPath(), 0, 4096,
> FileChannel.MapMode.READ_WRITE);
>
> System.out.println(nativeFile.isAlive());
>
> MappedMemorySegment segment =
> (MappedMemorySegment)nativeFile.asSlice(4);
> segment = (MappedMemorySegment)nativeFile.asSlice(4);
> segment =
> (MappedMemorySegment)nativeFile.asSlice(4).withOwnerThread(null);
>
> System.out.println(nativeFile.isAlive());
> System.out.println(segment.isAlive());
>
>
> which prints true, false, and then true. The original
> MappedMemorySegment was never closed, so this is unexpected.
>
More information about the panama-dev
mailing list