mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8234049: Implementation of Memory Access API (Incubator)
Co-authored-by: Vlaidmir Ivanov <vladimir.x.ivanov@oracle.com> Reviewed-by: alanb, psandoz, chegar, rriggs, plevart, briangoetz, jrose, adinn, vlivanov
This commit is contained in:
parent
7cdecd8981
commit
8f4f088a12
59 changed files with 7849 additions and 147 deletions
|
@ -28,7 +28,9 @@ package java.nio;
|
|||
import jdk.internal.HotSpotIntrinsicCandidate;
|
||||
import jdk.internal.access.JavaNioAccess;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.access.foreign.MemorySegmentProxy;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
import jdk.internal.vm.annotation.ForceInline;
|
||||
|
||||
import java.util.Spliterator;
|
||||
|
||||
|
@ -213,13 +215,26 @@ public abstract class Buffer {
|
|||
// NOTE: hoisted here for speed in JNI GetDirectBufferAddress
|
||||
long address;
|
||||
|
||||
// Used by buffers generated by the memory access API (JEP-370)
|
||||
final MemorySegmentProxy segment;
|
||||
|
||||
|
||||
// Creates a new buffer with given address and capacity.
|
||||
//
|
||||
Buffer(long addr, int cap, MemorySegmentProxy segment) {
|
||||
this.address = addr;
|
||||
this.capacity = cap;
|
||||
this.segment = segment;
|
||||
}
|
||||
|
||||
// Creates a new buffer with the given mark, position, limit, and capacity,
|
||||
// after checking invariants.
|
||||
//
|
||||
Buffer(int mark, int pos, int lim, int cap) { // package-private
|
||||
Buffer(int mark, int pos, int lim, int cap, MemorySegmentProxy segment) { // package-private
|
||||
if (cap < 0)
|
||||
throw createCapacityException(cap);
|
||||
this.capacity = cap;
|
||||
this.segment = segment;
|
||||
limit(lim);
|
||||
position(pos);
|
||||
if (mark >= 0) {
|
||||
|
@ -731,6 +746,13 @@ public abstract class Buffer {
|
|||
mark = -1;
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
final void checkSegment() {
|
||||
if (segment != null) {
|
||||
segment.checkValidState();
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
// setup access to this package in SharedSecrets
|
||||
SharedSecrets.setJavaNioAccess(
|
||||
|
@ -739,6 +761,31 @@ public abstract class Buffer {
|
|||
public JavaNioAccess.BufferPool getDirectBufferPool() {
|
||||
return Bits.BUFFER_POOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer newDirectByteBuffer(long addr, int cap, Object obj, MemorySegmentProxy segment) {
|
||||
return new DirectByteBuffer(addr, cap, obj, segment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer newHeapByteBuffer(byte[] hb, int offset, int capacity, MemorySegmentProxy segment) {
|
||||
return new HeapByteBuffer(hb, offset, capacity, segment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getBufferBase(ByteBuffer bb) {
|
||||
return bb.base();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBufferAddress(ByteBuffer bb) {
|
||||
return bb.address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkSegment(Buffer buffer) {
|
||||
buffer.checkSegment();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue