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
|
@ -30,6 +30,7 @@ package java.nio;
|
|||
import java.io.FileDescriptor;
|
||||
import java.lang.ref.Reference;
|
||||
import java.util.Objects;
|
||||
import jdk.internal.access.foreign.MemorySegmentProxy;
|
||||
import jdk.internal.misc.VM;
|
||||
import jdk.internal.ref.Cleaner;
|
||||
import sun.nio.ch.DirectBuffer;
|
||||
|
@ -112,7 +113,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
//
|
||||
Direct$Type$Buffer$RW$(int cap) { // package-private
|
||||
#if[rw]
|
||||
super(-1, 0, cap, cap);
|
||||
super(-1, 0, cap, cap, null);
|
||||
boolean pa = VM.isDirectMemoryPageAligned();
|
||||
int ps = Bits.pageSize();
|
||||
long size = Math.max(1L, (long)cap + (pa ? ps : 0));
|
||||
|
@ -145,8 +146,8 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
// Invoked to construct a direct ByteBuffer referring to the block of
|
||||
// memory. A given arbitrary object may also be attached to the buffer.
|
||||
//
|
||||
Direct$Type$Buffer(long addr, int cap, Object ob) {
|
||||
super(-1, 0, cap, cap);
|
||||
Direct$Type$Buffer(long addr, int cap, Object ob, MemorySegmentProxy segment) {
|
||||
super(-1, 0, cap, cap, segment);
|
||||
address = addr;
|
||||
cleaner = null;
|
||||
att = ob;
|
||||
|
@ -156,7 +157,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
// Invoked only by JNI: NewDirectByteBuffer(void*, long)
|
||||
//
|
||||
private Direct$Type$Buffer(long addr, int cap) {
|
||||
super(-1, 0, cap, cap);
|
||||
super(-1, 0, cap, cap, null);
|
||||
address = addr;
|
||||
cleaner = null;
|
||||
att = null;
|
||||
|
@ -169,15 +170,15 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
protected Direct$Type$Buffer$RW$(int cap, long addr,
|
||||
FileDescriptor fd,
|
||||
Runnable unmapper,
|
||||
boolean isSync)
|
||||
boolean isSync, MemorySegmentProxy segment)
|
||||
{
|
||||
#if[rw]
|
||||
super(-1, 0, cap, cap, fd, isSync);
|
||||
super(-1, 0, cap, cap, fd, isSync, segment);
|
||||
address = addr;
|
||||
cleaner = Cleaner.create(this, unmapper);
|
||||
att = null;
|
||||
#else[rw]
|
||||
super(cap, addr, fd, unmapper, isSync);
|
||||
super(cap, addr, fd, unmapper, isSync, segment);
|
||||
this.isReadOnly = true;
|
||||
#end[rw]
|
||||
}
|
||||
|
@ -188,10 +189,10 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
//
|
||||
Direct$Type$Buffer$RW$$BO$(DirectBuffer db, // package-private
|
||||
int mark, int pos, int lim, int cap,
|
||||
int off)
|
||||
int off, MemorySegmentProxy segment)
|
||||
{
|
||||
#if[rw]
|
||||
super(mark, pos, lim, cap);
|
||||
super(mark, pos, lim, cap, segment);
|
||||
address = db.address() + off;
|
||||
#if[byte]
|
||||
cleaner = null;
|
||||
|
@ -199,7 +200,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
Object attachment = db.attachment();
|
||||
att = (attachment == null ? db : attachment);
|
||||
#else[rw]
|
||||
super(db, mark, pos, lim, cap, off);
|
||||
super(db, mark, pos, lim, cap, off, segment);
|
||||
this.isReadOnly = true;
|
||||
#end[rw]
|
||||
}
|
||||
|
@ -216,7 +217,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
int rem = (pos <= lim ? lim - pos : 0);
|
||||
int off = (pos << $LG_BYTES_PER_VALUE$);
|
||||
assert (off >= 0);
|
||||
return new Direct$Type$Buffer$RW$$BO$(this, -1, 0, rem, rem, off);
|
||||
return new Direct$Type$Buffer$RW$$BO$(this, -1, 0, rem, rem, off, segment);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -227,7 +228,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
0,
|
||||
length,
|
||||
length,
|
||||
index);
|
||||
index, segment);
|
||||
}
|
||||
|
||||
public $Type$Buffer duplicate() {
|
||||
|
@ -236,7 +237,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
this.position(),
|
||||
this.limit(),
|
||||
this.capacity(),
|
||||
0);
|
||||
0, segment);
|
||||
}
|
||||
|
||||
public $Type$Buffer asReadOnlyBuffer() {
|
||||
|
@ -246,7 +247,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
this.position(),
|
||||
this.limit(),
|
||||
this.capacity(),
|
||||
0);
|
||||
0, segment);
|
||||
#else[rw]
|
||||
return duplicate();
|
||||
#end[rw]
|
||||
|
@ -264,6 +265,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
|
||||
public $type$ get() {
|
||||
try {
|
||||
checkSegment();
|
||||
return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(nextGetIndex()))));
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
|
@ -272,6 +274,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
|
||||
public $type$ get(int i) {
|
||||
try {
|
||||
checkSegment();
|
||||
return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(checkIndex(i)))));
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
|
@ -290,6 +293,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
|
||||
public $Type$Buffer get($type$[] dst, int offset, int length) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
|
||||
Objects.checkFromIndexSize(offset, length, dst.length);
|
||||
int pos = position();
|
||||
|
@ -331,6 +335,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
|
||||
public $Type$Buffer get(int index, $type$[] dst, int offset, int length) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
|
||||
Objects.checkFromIndexSize(index, length, limit());
|
||||
Objects.checkFromIndexSize(offset, length, dst.length);
|
||||
|
@ -368,6 +373,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
public $Type$Buffer put($type$ x) {
|
||||
#if[rw]
|
||||
try {
|
||||
checkSegment();
|
||||
UNSAFE.put$Swaptype$(ix(nextPutIndex()), $swap$($toBits$(x)));
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
|
@ -381,6 +387,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
public $Type$Buffer put(int i, $type$ x) {
|
||||
#if[rw]
|
||||
try {
|
||||
checkSegment();
|
||||
UNSAFE.put$Swaptype$(ix(checkIndex(i)), $swap$($toBits$(x)));
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
|
@ -393,6 +400,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
|
||||
public $Type$Buffer put($Type$Buffer src) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
if (src instanceof Direct$Type$Buffer$BO$) {
|
||||
if (src == this)
|
||||
throw createSameBufferException();
|
||||
|
@ -439,6 +447,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
|
||||
public $Type$Buffer put($type$[] src, int offset, int length) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
|
||||
Objects.checkFromIndexSize(offset, length, src.length);
|
||||
int pos = position();
|
||||
|
@ -480,6 +489,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
|
||||
public $Type$Buffer put(int index, $type$[] src, int offset, int length) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
|
||||
Objects.checkFromIndexSize(index, length, limit());
|
||||
Objects.checkFromIndexSize(offset, length, src.length);
|
||||
|
@ -577,7 +587,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
pos + start,
|
||||
pos + end,
|
||||
capacity(),
|
||||
offset);
|
||||
offset, segment);
|
||||
}
|
||||
|
||||
#end[char]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue