8304265: Implementation of Foreign Function and Memory API (Third Preview)

Co-authored-by: Maurizio Cimadamore <mcimadamore@openjdk.org>
Co-authored-by: Jorn Vernee <jvernee@openjdk.org>
Co-authored-by: Paul Sandoz <psandoz@openjdk.org>
Co-authored-by: Feilong Jiang <fjiang@openjdk.org>
Co-authored-by: Per Minborg <pminborg@openjdk.org>
Reviewed-by: erikj, jvernee, vlivanov, psandoz
This commit is contained in:
Per Minborg 2023-04-27 09:00:58 +00:00
parent 41d58533ac
commit cbccc4c817
267 changed files with 6947 additions and 8029 deletions

View file

@ -815,7 +815,9 @@ public abstract sealed class Buffer
@Override
public ByteBuffer newMappedByteBuffer(UnmapperProxy unmapperProxy, long address, int cap, Object obj, MemorySegment segment) {
return new DirectByteBuffer(address, cap, obj, unmapperProxy.fileDescriptor(), unmapperProxy.isSync(), segment);
return unmapperProxy == null
? new DirectByteBuffer(address, cap, obj, segment)
: new DirectByteBuffer(address, cap, obj, unmapperProxy.fileDescriptor(), unmapperProxy.isSync(), segment);
}
@Override

View file

@ -26,8 +26,8 @@
package java.nio.channels;
import java.io.IOException;
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.SegmentScope;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.spi.AbstractInterruptibleChannel;
@ -1004,11 +1004,15 @@ public abstract class FileChannel
/**
* Maps a region of this channel's file into a new mapped memory segment,
* with the given offset, size and memory session.
* with the given offset, size and arena.
* The {@linkplain MemorySegment#address() address} of the returned memory
* segment is the starting address of the mapped off-heap region backing
* the segment.
*
* <p>
* The lifetime of the returned segment is controlled by the provided arena.
* For instance, if the provided arena is a closeable arena,
* the returned segment will be unmapped when the provided closeable arena
* is {@linkplain Arena#close() closed}.
* <p> If the specified mapping mode is
* {@linkplain FileChannel.MapMode#READ_ONLY READ_ONLY}, the resulting
* segment will be read-only (see {@link MemorySegment#isReadOnly()}).
@ -1049,8 +1053,8 @@ public abstract class FileChannel
* The size (in bytes) of the mapped memory backing the memory
* segment.
*
* @param session
* The segment memory session.
* @param arena
* The segment arena.
*
* @return A new mapped memory segment.
*
@ -1059,13 +1063,11 @@ public abstract class FileChannel
* {@code offset + size} overflows the range of {@code long}.
*
* @throws IllegalStateException
* If the {@code session} is not
* {@linkplain SegmentScope#isAlive() alive}.
* If {@code arena.isAlive() == false}.
*
* @throws WrongThreadException
* If this method is called from a thread other than the thread
* {@linkplain SegmentScope#isAccessibleBy(Thread) owning} the
* {@code session}.
* If {@code arena} is a confined scoped arena, and this method is called from a
* thread {@code T}, other than the scoped arena's owner thread.
*
* @throws NonReadableChannelException
* If the {@code mode} is {@link MapMode#READ_ONLY READ_ONLY} or
@ -1087,7 +1089,7 @@ public abstract class FileChannel
* @since 19
*/
@PreviewFeature(feature=PreviewFeature.Feature.FOREIGN)
public MemorySegment map(MapMode mode, long offset, long size, SegmentScope session)
public MemorySegment map(MapMode mode, long offset, long size, Arena arena)
throws IOException
{
throw new UnsupportedOperationException();