mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8282191: Implementation of Foreign Function & Memory API (Preview)
Reviewed-by: erikj, jvernee, psandoz, dholmes, mchung
This commit is contained in:
parent
3be394e160
commit
2c5d136260
303 changed files with 33474 additions and 9186 deletions
|
@ -27,15 +27,17 @@ package java.nio;
|
|||
|
||||
import jdk.internal.access.JavaNioAccess;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.access.foreign.MemorySegmentProxy;
|
||||
import jdk.internal.access.foreign.UnmapperProxy;
|
||||
import jdk.internal.foreign.AbstractMemorySegmentImpl;
|
||||
import jdk.internal.foreign.MemorySessionImpl;
|
||||
import jdk.internal.misc.ScopedMemoryAccess;
|
||||
import jdk.internal.misc.ScopedMemoryAccess.Scope;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
import jdk.internal.misc.VM.BufferPool;
|
||||
import jdk.internal.vm.annotation.ForceInline;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.lang.foreign.MemorySegment;
|
||||
import java.lang.foreign.MemorySession;
|
||||
import java.util.Objects;
|
||||
import java.util.Spliterator;
|
||||
|
||||
|
@ -225,12 +227,12 @@ public abstract sealed class Buffer
|
|||
long address;
|
||||
|
||||
// Used by buffers generated by the memory access API (JEP-370)
|
||||
final MemorySegmentProxy segment;
|
||||
final MemorySegment segment;
|
||||
|
||||
|
||||
// Creates a new buffer with given address and capacity.
|
||||
//
|
||||
Buffer(long addr, int cap, MemorySegmentProxy segment) {
|
||||
Buffer(long addr, int cap, MemorySegment segment) {
|
||||
this.address = addr;
|
||||
this.capacity = cap;
|
||||
this.segment = segment;
|
||||
|
@ -239,7 +241,7 @@ public abstract sealed class Buffer
|
|||
// Creates a new buffer with the given mark, position, limit, and capacity,
|
||||
// after checking invariants.
|
||||
//
|
||||
Buffer(int mark, int pos, int lim, int cap, MemorySegmentProxy segment) { // package-private
|
||||
Buffer(int mark, int pos, int lim, int cap, MemorySegment segment) { // package-private
|
||||
if (cap < 0)
|
||||
throw createCapacityException(cap);
|
||||
this.capacity = cap;
|
||||
|
@ -758,20 +760,20 @@ public abstract sealed class Buffer
|
|||
}
|
||||
|
||||
@ForceInline
|
||||
final ScopedMemoryAccess.Scope scope() {
|
||||
final MemorySessionImpl session() {
|
||||
if (segment != null) {
|
||||
return segment.scope();
|
||||
return ((AbstractMemorySegmentImpl)segment).sessionImpl();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final void checkScope() {
|
||||
ScopedMemoryAccess.Scope scope = scope();
|
||||
if (scope != null) {
|
||||
final void checkSession() {
|
||||
MemorySessionImpl session = session();
|
||||
if (session != null) {
|
||||
try {
|
||||
scope.checkValidState();
|
||||
} catch (ScopedMemoryAccess.Scope.ScopedAccessError e) {
|
||||
session.checkValidState();
|
||||
} catch (ScopedMemoryAccess.ScopedAccessError e) {
|
||||
throw new IllegalStateException("This segment is already closed");
|
||||
}
|
||||
}
|
||||
|
@ -787,17 +789,17 @@ public abstract sealed class Buffer
|
|||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer newDirectByteBuffer(long addr, int cap, Object obj, MemorySegmentProxy segment) {
|
||||
public ByteBuffer newDirectByteBuffer(long addr, int cap, Object obj, MemorySegment segment) {
|
||||
return new DirectByteBuffer(addr, cap, obj, segment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer newMappedByteBuffer(UnmapperProxy unmapperProxy, long address, int cap, Object obj, MemorySegmentProxy segment) {
|
||||
public ByteBuffer newMappedByteBuffer(UnmapperProxy unmapperProxy, long address, int cap, Object obj, MemorySegment segment) {
|
||||
return new DirectByteBuffer(address, cap, obj, unmapperProxy.fileDescriptor(), unmapperProxy.isSync(), segment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer newHeapByteBuffer(byte[] hb, int offset, int capacity, MemorySegmentProxy segment) {
|
||||
public ByteBuffer newHeapByteBuffer(byte[] hb, int offset, int capacity, MemorySegment segment) {
|
||||
return new HeapByteBuffer(hb, -1, 0, capacity, capacity, offset, segment);
|
||||
}
|
||||
|
||||
|
@ -821,21 +823,21 @@ public abstract sealed class Buffer
|
|||
}
|
||||
|
||||
@Override
|
||||
public MemorySegmentProxy bufferSegment(Buffer buffer) {
|
||||
public MemorySegment bufferSegment(Buffer buffer) {
|
||||
return buffer.segment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Runnable acquireScope(Buffer buffer, boolean async) {
|
||||
var scope = buffer.scope();
|
||||
if (scope == null) {
|
||||
public Runnable acquireSession(Buffer buffer, boolean async) {
|
||||
var session = buffer.session();
|
||||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
if (async && scope.ownerThread() != null) {
|
||||
throw new IllegalStateException("Confined scope not supported");
|
||||
if (async && session.ownerThread() != null) {
|
||||
throw new IllegalStateException("Confined session not supported");
|
||||
}
|
||||
scope.acquire0();
|
||||
return scope::release0;
|
||||
session.acquire0();
|
||||
return session::release0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue