mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8254162: Implementation of Foreign-Memory Access API (Third Incubator)
Reviewed-by: erikj, psandoz, alanb
This commit is contained in:
parent
c6ab0fdb15
commit
3e70aac5cc
82 changed files with 6038 additions and 2837 deletions
|
@ -106,7 +106,7 @@ class Bits { // package-private
|
|||
// These methods should be called whenever direct memory is allocated or
|
||||
// freed. They allow the user to control the amount of direct memory
|
||||
// which a process may access. All sizes are specified in bytes.
|
||||
static void reserveMemory(long size, int cap) {
|
||||
static void reserveMemory(long size, long cap) {
|
||||
|
||||
if (!MEMORY_LIMIT_SET && VM.initLevel() >= 1) {
|
||||
MAX_MEMORY = VM.maxDirectMemory();
|
||||
|
@ -185,7 +185,7 @@ class Bits { // package-private
|
|||
}
|
||||
}
|
||||
|
||||
private static boolean tryReserveMemory(long size, int cap) {
|
||||
private static boolean tryReserveMemory(long size, long cap) {
|
||||
|
||||
// -XX:MaxDirectMemorySize limits the total capacity rather than the
|
||||
// actual memory usage, which will differ when buffers are page
|
||||
|
@ -203,7 +203,7 @@ class Bits { // package-private
|
|||
}
|
||||
|
||||
|
||||
static void unreserveMemory(long size, int cap) {
|
||||
static void unreserveMemory(long size, long cap) {
|
||||
long cnt = COUNT.decrementAndGet();
|
||||
long reservedMem = RESERVED_MEMORY.addAndGet(-size);
|
||||
long totalCap = TOTAL_CAPACITY.addAndGet(-cap);
|
||||
|
|
|
@ -29,6 +29,7 @@ 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.misc.ScopedMemoryAccess;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
import jdk.internal.misc.VM.BufferPool;
|
||||
import jdk.internal.vm.annotation.ForceInline;
|
||||
|
@ -193,6 +194,8 @@ public abstract class Buffer {
|
|||
// Cached unsafe-access object
|
||||
static final Unsafe UNSAFE = Unsafe.getUnsafe();
|
||||
|
||||
static final ScopedMemoryAccess SCOPED_MEMORY_ACCESS = ScopedMemoryAccess.getScopedMemoryAccess();
|
||||
|
||||
/**
|
||||
* The characteristics of Spliterators that traverse and split elements
|
||||
* maintained in Buffers.
|
||||
|
@ -754,9 +757,18 @@ public abstract class Buffer {
|
|||
}
|
||||
|
||||
@ForceInline
|
||||
final void checkSegment() {
|
||||
final ScopedMemoryAccess.Scope scope() {
|
||||
if (segment != null) {
|
||||
segment.checkValidState();
|
||||
return segment.scope();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final void checkScope() {
|
||||
ScopedMemoryAccess.Scope scope = scope();
|
||||
if (scope != null) {
|
||||
scope.checkValidState();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -827,6 +839,21 @@ public abstract class Buffer {
|
|||
public boolean isLoaded(long address, boolean isSync, long size) {
|
||||
return MappedMemoryUtils.isLoaded(address, isSync, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reserveMemory(long size, long cap) {
|
||||
Bits.reserveMemory(size, cap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unreserveMemory(long size, long cap) {
|
||||
Bits.unreserveMemory(size, cap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int pageSize() {
|
||||
return Bits.pageSize();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package java.nio;
|
||||
|
||||
import jdk.internal.misc.ScopedMemoryAccess;
|
||||
import jdk.internal.util.ArraysSupport;
|
||||
|
||||
/**
|
||||
|
@ -31,12 +32,14 @@ import jdk.internal.util.ArraysSupport;
|
|||
*/
|
||||
final class BufferMismatch {
|
||||
|
||||
final static ScopedMemoryAccess SCOPED_MEMORY_ACCESS = ScopedMemoryAccess.getScopedMemoryAccess();
|
||||
|
||||
static int mismatch(ByteBuffer a, int aOff, ByteBuffer b, int bOff, int length) {
|
||||
int i = 0;
|
||||
if (length > 7) {
|
||||
if (a.get(aOff) != b.get(bOff))
|
||||
return 0;
|
||||
i = ArraysSupport.vectorizedMismatch(
|
||||
i = SCOPED_MEMORY_ACCESS.vectorizedMismatch(a.scope(), b.scope(),
|
||||
a.base(), a.address + aOff,
|
||||
b.base(), b.address + bOff,
|
||||
length,
|
||||
|
@ -60,7 +63,7 @@ final class BufferMismatch {
|
|||
&& a.charRegionOrder() != null && b.charRegionOrder() != null) {
|
||||
if (a.get(aOff) != b.get(bOff))
|
||||
return 0;
|
||||
i = ArraysSupport.vectorizedMismatch(
|
||||
i = SCOPED_MEMORY_ACCESS.vectorizedMismatch(a.scope(), b.scope(),
|
||||
a.base(), a.address + (aOff << ArraysSupport.LOG2_ARRAY_CHAR_INDEX_SCALE),
|
||||
b.base(), b.address + (bOff << ArraysSupport.LOG2_ARRAY_CHAR_INDEX_SCALE),
|
||||
length,
|
||||
|
@ -80,7 +83,7 @@ final class BufferMismatch {
|
|||
if (length > 3 && a.order() == b.order()) {
|
||||
if (a.get(aOff) != b.get(bOff))
|
||||
return 0;
|
||||
i = ArraysSupport.vectorizedMismatch(
|
||||
i = SCOPED_MEMORY_ACCESS.vectorizedMismatch(a.scope(), b.scope(),
|
||||
a.base(), a.address + (aOff << ArraysSupport.LOG2_ARRAY_SHORT_INDEX_SCALE),
|
||||
b.base(), b.address + (bOff << ArraysSupport.LOG2_ARRAY_SHORT_INDEX_SCALE),
|
||||
length,
|
||||
|
@ -100,7 +103,7 @@ final class BufferMismatch {
|
|||
if (length > 1 && a.order() == b.order()) {
|
||||
if (a.get(aOff) != b.get(bOff))
|
||||
return 0;
|
||||
i = ArraysSupport.vectorizedMismatch(
|
||||
i = SCOPED_MEMORY_ACCESS.vectorizedMismatch(a.scope(), b.scope(),
|
||||
a.base(), a.address + (aOff << ArraysSupport.LOG2_ARRAY_INT_INDEX_SCALE),
|
||||
b.base(), b.address + (bOff << ArraysSupport.LOG2_ARRAY_INT_INDEX_SCALE),
|
||||
length,
|
||||
|
@ -119,7 +122,7 @@ final class BufferMismatch {
|
|||
int i = 0;
|
||||
if (length > 1 && a.order() == b.order()) {
|
||||
if (Float.floatToRawIntBits(a.get(aOff)) == Float.floatToRawIntBits(b.get(bOff))) {
|
||||
i = ArraysSupport.vectorizedMismatch(
|
||||
i = SCOPED_MEMORY_ACCESS.vectorizedMismatch(a.scope(), b.scope(),
|
||||
a.base(), a.address + (aOff << ArraysSupport.LOG2_ARRAY_FLOAT_INDEX_SCALE),
|
||||
b.base(), b.address + (bOff << ArraysSupport.LOG2_ARRAY_FLOAT_INDEX_SCALE),
|
||||
length,
|
||||
|
@ -158,7 +161,7 @@ final class BufferMismatch {
|
|||
if (length > 0 && a.order() == b.order()) {
|
||||
if (a.get(aOff) != b.get(bOff))
|
||||
return 0;
|
||||
i = ArraysSupport.vectorizedMismatch(
|
||||
i = SCOPED_MEMORY_ACCESS.vectorizedMismatch(a.scope(), b.scope(),
|
||||
a.base(), a.address + (aOff << ArraysSupport.LOG2_ARRAY_LONG_INDEX_SCALE),
|
||||
b.base(), b.address + (bOff << ArraysSupport.LOG2_ARRAY_LONG_INDEX_SCALE),
|
||||
length,
|
||||
|
@ -176,7 +179,7 @@ final class BufferMismatch {
|
|||
int i = 0;
|
||||
if (length > 0 && a.order() == b.order()) {
|
||||
if (Double.doubleToRawLongBits(a.get(aOff)) == Double.doubleToRawLongBits(b.get(bOff))) {
|
||||
i = ArraysSupport.vectorizedMismatch(
|
||||
i = SCOPED_MEMORY_ACCESS.vectorizedMismatch(a.scope(), b.scope(),
|
||||
a.base(), a.address + (aOff << ArraysSupport.LOG2_ARRAY_DOUBLE_INDEX_SCALE),
|
||||
b.base(), b.address + (bOff << ArraysSupport.LOG2_ARRAY_DOUBLE_INDEX_SCALE),
|
||||
length,
|
||||
|
|
|
@ -130,22 +130,20 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
|
|||
}
|
||||
|
||||
public $type$ get() {
|
||||
checkSegment();
|
||||
$memtype$ x = UNSAFE.get$Memtype$Unaligned(bb.hb, byteOffset(nextGetIndex()),
|
||||
$memtype$ x = SCOPED_MEMORY_ACCESS.get$Memtype$Unaligned(scope(), bb.hb, byteOffset(nextGetIndex()),
|
||||
{#if[boB]?true:false});
|
||||
return $fromBits$(x);
|
||||
}
|
||||
|
||||
public $type$ get(int i) {
|
||||
checkSegment();
|
||||
$memtype$ x = UNSAFE.get$Memtype$Unaligned(bb.hb, byteOffset(checkIndex(i)),
|
||||
$memtype$ x = SCOPED_MEMORY_ACCESS.get$Memtype$Unaligned(scope(), bb.hb, byteOffset(checkIndex(i)),
|
||||
{#if[boB]?true:false});
|
||||
return $fromBits$(x);
|
||||
}
|
||||
|
||||
#if[streamableType]
|
||||
$type$ getUnchecked(int i) {
|
||||
$memtype$ x = UNSAFE.get$Memtype$Unaligned(bb.hb, byteOffset(i),
|
||||
$memtype$ x = SCOPED_MEMORY_ACCESS.get$Memtype$Unaligned(null, bb.hb, byteOffset(i),
|
||||
{#if[boB]?true:false});
|
||||
return $fromBits$(x);
|
||||
}
|
||||
|
@ -155,9 +153,8 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
|
|||
|
||||
public $Type$Buffer put($type$ x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
$memtype$ y = $toBits$(x);
|
||||
UNSAFE.put$Memtype$Unaligned(bb.hb, byteOffset(nextPutIndex()), y,
|
||||
SCOPED_MEMORY_ACCESS.put$Memtype$Unaligned(scope(), bb.hb, byteOffset(nextPutIndex()), y,
|
||||
{#if[boB]?true:false});
|
||||
return this;
|
||||
#else[rw]
|
||||
|
@ -167,9 +164,8 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
|
|||
|
||||
public $Type$Buffer put(int i, $type$ x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
$memtype$ y = $toBits$(x);
|
||||
UNSAFE.put$Memtype$Unaligned(bb.hb, byteOffset(checkIndex(i)), y,
|
||||
SCOPED_MEMORY_ACCESS.put$Memtype$Unaligned(scope(), bb.hb, byteOffset(checkIndex(i)), y,
|
||||
{#if[boB]?true:false});
|
||||
return this;
|
||||
#else[rw]
|
||||
|
|
|
@ -33,8 +33,7 @@ class XXX {
|
|||
|
||||
private $type$ get$Type$(long a) {
|
||||
try {
|
||||
checkSegment();
|
||||
$memtype$ x = UNSAFE.get$Memtype$Unaligned(null, a, bigEndian);
|
||||
$memtype$ x = SCOPED_MEMORY_ACCESS.get$Memtype$Unaligned(scope(), null, a, bigEndian);
|
||||
return $fromBits$(x);
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
|
@ -62,9 +61,8 @@ class XXX {
|
|||
private ByteBuffer put$Type$(long a, $type$ x) {
|
||||
#if[rw]
|
||||
try {
|
||||
checkSegment();
|
||||
$memtype$ y = $toBits$(x);
|
||||
UNSAFE.put$Memtype$Unaligned(null, a, y, bigEndian);
|
||||
SCOPED_MEMORY_ACCESS.put$Memtype$Unaligned(scope(), null, a, y, bigEndian);
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.io.FileDescriptor;
|
|||
import java.lang.ref.Reference;
|
||||
import java.util.Objects;
|
||||
import jdk.internal.access.foreign.MemorySegmentProxy;
|
||||
import jdk.internal.misc.ScopedMemoryAccess.Scope;
|
||||
import jdk.internal.misc.VM;
|
||||
import jdk.internal.ref.Cleaner;
|
||||
import sun.nio.ch.DirectBuffer;
|
||||
|
@ -264,6 +265,17 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
#if[rw]
|
||||
|
||||
public long address() {
|
||||
Scope scope = scope();
|
||||
if (scope != null) {
|
||||
if (scope.ownerThread() == null) {
|
||||
throw new UnsupportedOperationException("ByteBuffer derived from shared segments not supported");
|
||||
}
|
||||
try {
|
||||
scope.checkValidState();
|
||||
} catch (Scope.ScopedAccessError e) {
|
||||
throw new IllegalStateException("This segment is already closed");
|
||||
}
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
|
@ -273,8 +285,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
|
||||
public $type$ get() {
|
||||
try {
|
||||
checkSegment();
|
||||
return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(nextGetIndex()))));
|
||||
return $fromBits$($swap$(SCOPED_MEMORY_ACCESS.get$Swaptype$(scope(), null, ix(nextGetIndex()))));
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
}
|
||||
|
@ -282,8 +293,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
|
||||
public $type$ get(int i) {
|
||||
try {
|
||||
checkSegment();
|
||||
return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(checkIndex(i)))));
|
||||
return $fromBits$($swap$(SCOPED_MEMORY_ACCESS.get$Swaptype$(scope(), null, ix(checkIndex(i)))));
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
}
|
||||
|
@ -292,7 +302,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
#if[streamableType]
|
||||
$type$ getUnchecked(int i) {
|
||||
try {
|
||||
return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(i))));
|
||||
return $fromBits$($swap$(SCOPED_MEMORY_ACCESS.get$Swaptype$(null, null, ix(i))));
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
}
|
||||
|
@ -301,7 +311,6 @@ 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();
|
||||
|
@ -315,7 +324,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
try {
|
||||
#if[!byte]
|
||||
if (order() != ByteOrder.nativeOrder())
|
||||
UNSAFE.copySwapMemory(null,
|
||||
SCOPED_MEMORY_ACCESS.copySwapMemory(scope(), null, null,
|
||||
ix(pos),
|
||||
dst,
|
||||
dstOffset,
|
||||
|
@ -323,7 +332,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
(long)1 << $LG_BYTES_PER_VALUE$);
|
||||
else
|
||||
#end[!byte]
|
||||
UNSAFE.copyMemory(null,
|
||||
SCOPED_MEMORY_ACCESS.copyMemory(scope(), null, null,
|
||||
ix(pos),
|
||||
dst,
|
||||
dstOffset,
|
||||
|
@ -343,7 +352,6 @@ 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);
|
||||
|
@ -352,7 +360,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
try {
|
||||
#if[!byte]
|
||||
if (order() != ByteOrder.nativeOrder())
|
||||
UNSAFE.copySwapMemory(null,
|
||||
SCOPED_MEMORY_ACCESS.copySwapMemory(scope(), null, null,
|
||||
ix(index),
|
||||
dst,
|
||||
dstOffset,
|
||||
|
@ -360,7 +368,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
(long)1 << $LG_BYTES_PER_VALUE$);
|
||||
else
|
||||
#end[!byte]
|
||||
UNSAFE.copyMemory(null,
|
||||
SCOPED_MEMORY_ACCESS.copyMemory(scope(), null, null,
|
||||
ix(index),
|
||||
dst,
|
||||
dstOffset,
|
||||
|
@ -381,8 +389,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)));
|
||||
SCOPED_MEMORY_ACCESS.put$Swaptype$(scope(), null, ix(nextPutIndex()), $swap$($toBits$(x)));
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
}
|
||||
|
@ -395,8 +402,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)));
|
||||
SCOPED_MEMORY_ACCESS.put$Swaptype$(scope(), null, ix(checkIndex(i)), $swap$($toBits$(x)));
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
}
|
||||
|
@ -408,7 +414,6 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
|
||||
public $Type$Buffer put($Type$Buffer src) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
super.put(src);
|
||||
return this;
|
||||
#else[rw]
|
||||
|
@ -418,7 +423,6 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
|
||||
public $Type$Buffer put(int index, $Type$Buffer src, int offset, int length) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
super.put(index, src, offset, length);
|
||||
return this;
|
||||
#else[rw]
|
||||
|
@ -428,7 +432,6 @@ 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();
|
||||
|
@ -442,7 +445,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
try {
|
||||
#if[!byte]
|
||||
if (order() != ByteOrder.nativeOrder())
|
||||
UNSAFE.copySwapMemory(src,
|
||||
SCOPED_MEMORY_ACCESS.copySwapMemory(scope(), null, src,
|
||||
srcOffset,
|
||||
null,
|
||||
ix(pos),
|
||||
|
@ -450,7 +453,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
(long)1 << $LG_BYTES_PER_VALUE$);
|
||||
else
|
||||
#end[!byte]
|
||||
UNSAFE.copyMemory(src,
|
||||
SCOPED_MEMORY_ACCESS.copyMemory(scope(), null, src,
|
||||
srcOffset,
|
||||
null,
|
||||
ix(pos),
|
||||
|
@ -470,7 +473,6 @@ 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);
|
||||
|
@ -480,7 +482,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
try {
|
||||
#if[!byte]
|
||||
if (order() != ByteOrder.nativeOrder())
|
||||
UNSAFE.copySwapMemory(src,
|
||||
SCOPED_MEMORY_ACCESS.copySwapMemory(scope(), null, src,
|
||||
srcOffset,
|
||||
null,
|
||||
ix(index),
|
||||
|
@ -488,11 +490,9 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
(long)1 << $LG_BYTES_PER_VALUE$);
|
||||
else
|
||||
#end[!byte]
|
||||
UNSAFE.copyMemory(src,
|
||||
srcOffset,
|
||||
null,
|
||||
ix(index),
|
||||
(long)length << $LG_BYTES_PER_VALUE$);
|
||||
SCOPED_MEMORY_ACCESS.copyMemory(
|
||||
scope(), null, src,
|
||||
srcOffset, null, ix(index), (long)length << $LG_BYTES_PER_VALUE$);
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
}
|
||||
|
@ -512,7 +512,8 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
assert (pos <= lim);
|
||||
int rem = (pos <= lim ? lim - pos : 0);
|
||||
try {
|
||||
UNSAFE.copyMemory(ix(pos), ix(0), (long)rem << $LG_BYTES_PER_VALUE$);
|
||||
SCOPED_MEMORY_ACCESS.copyMemory(scope(), null, null,
|
||||
ix(pos), null, ix(0), (long)rem << $LG_BYTES_PER_VALUE$);
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
}
|
||||
|
|
|
@ -162,12 +162,10 @@ class Heap$Type$Buffer$RW$
|
|||
#end[byte]
|
||||
|
||||
public $type$ get() {
|
||||
checkSegment();
|
||||
return hb[ix(nextGetIndex())];
|
||||
}
|
||||
|
||||
public $type$ get(int i) {
|
||||
checkSegment();
|
||||
return hb[ix(checkIndex(i))];
|
||||
}
|
||||
|
||||
|
@ -178,7 +176,7 @@ class Heap$Type$Buffer$RW$
|
|||
#end[streamableType]
|
||||
|
||||
public $Type$Buffer get($type$[] dst, int offset, int length) {
|
||||
checkSegment();
|
||||
checkScope();
|
||||
Objects.checkFromIndexSize(offset, length, dst.length);
|
||||
int pos = position();
|
||||
if (length > limit() - pos)
|
||||
|
@ -189,7 +187,7 @@ class Heap$Type$Buffer$RW$
|
|||
}
|
||||
|
||||
public $Type$Buffer get(int index, $type$[] dst, int offset, int length) {
|
||||
checkSegment();
|
||||
checkScope();
|
||||
Objects.checkFromIndexSize(index, length, limit());
|
||||
Objects.checkFromIndexSize(offset, length, dst.length);
|
||||
System.arraycopy(hb, ix(index), dst, offset, length);
|
||||
|
@ -208,7 +206,6 @@ class Heap$Type$Buffer$RW$
|
|||
|
||||
public $Type$Buffer put($type$ x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
hb[ix(nextPutIndex())] = x;
|
||||
return this;
|
||||
#else[rw]
|
||||
|
@ -218,7 +215,6 @@ class Heap$Type$Buffer$RW$
|
|||
|
||||
public $Type$Buffer put(int i, $type$ x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
hb[ix(checkIndex(i))] = x;
|
||||
return this;
|
||||
#else[rw]
|
||||
|
@ -228,7 +224,7 @@ class Heap$Type$Buffer$RW$
|
|||
|
||||
public $Type$Buffer put($type$[] src, int offset, int length) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
checkScope();
|
||||
Objects.checkFromIndexSize(offset, length, src.length);
|
||||
int pos = position();
|
||||
if (length > limit() - pos)
|
||||
|
@ -243,7 +239,7 @@ class Heap$Type$Buffer$RW$
|
|||
|
||||
public $Type$Buffer put($Type$Buffer src) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
checkScope();
|
||||
super.put(src);
|
||||
return this;
|
||||
#else[rw]
|
||||
|
@ -253,7 +249,7 @@ class Heap$Type$Buffer$RW$
|
|||
|
||||
public $Type$Buffer put(int index, $Type$Buffer src, int offset, int length) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
checkScope();
|
||||
super.put(index, src, offset, length);
|
||||
return this;
|
||||
#else[rw]
|
||||
|
@ -263,7 +259,7 @@ class Heap$Type$Buffer$RW$
|
|||
|
||||
public $Type$Buffer put(int index, $type$[] src, int offset, int length) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
checkScope();
|
||||
Objects.checkFromIndexSize(index, length, limit());
|
||||
Objects.checkFromIndexSize(offset, length, src.length);
|
||||
System.arraycopy(src, offset, hb, ix(index), length);
|
||||
|
@ -276,7 +272,7 @@ class Heap$Type$Buffer$RW$
|
|||
#if[char]
|
||||
|
||||
public $Type$Buffer put(String src, int start, int end) {
|
||||
checkSegment();
|
||||
checkScope();
|
||||
int length = end - start;
|
||||
Objects.checkFromIndexSize(start, length, src.length());
|
||||
if (isReadOnly())
|
||||
|
@ -328,20 +324,18 @@ class Heap$Type$Buffer$RW$
|
|||
#if[rw]
|
||||
|
||||
public char getChar() {
|
||||
checkSegment();
|
||||
return UNSAFE.getCharUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian);
|
||||
return SCOPED_MEMORY_ACCESS.getCharUnaligned(scope(), hb, byteOffset(nextGetIndex(2)), bigEndian);
|
||||
}
|
||||
|
||||
public char getChar(int i) {
|
||||
return UNSAFE.getCharUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian);
|
||||
return SCOPED_MEMORY_ACCESS.getCharUnaligned(scope(), hb, byteOffset(checkIndex(i, 2)), bigEndian);
|
||||
}
|
||||
|
||||
#end[rw]
|
||||
|
||||
public $Type$Buffer putChar(char x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
UNSAFE.putCharUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian);
|
||||
SCOPED_MEMORY_ACCESS.putCharUnaligned(scope(), hb, byteOffset(nextPutIndex(2)), x, bigEndian);
|
||||
return this;
|
||||
#else[rw]
|
||||
throw new ReadOnlyBufferException();
|
||||
|
@ -350,8 +344,7 @@ class Heap$Type$Buffer$RW$
|
|||
|
||||
public $Type$Buffer putChar(int i, char x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
UNSAFE.putCharUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
|
||||
SCOPED_MEMORY_ACCESS.putCharUnaligned(scope(), hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
|
||||
return this;
|
||||
#else[rw]
|
||||
throw new ReadOnlyBufferException();
|
||||
|
@ -383,21 +376,18 @@ class Heap$Type$Buffer$RW$
|
|||
#if[rw]
|
||||
|
||||
public short getShort() {
|
||||
checkSegment();
|
||||
return UNSAFE.getShortUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian);
|
||||
return SCOPED_MEMORY_ACCESS.getShortUnaligned(scope(), hb, byteOffset(nextGetIndex(2)), bigEndian);
|
||||
}
|
||||
|
||||
public short getShort(int i) {
|
||||
checkSegment();
|
||||
return UNSAFE.getShortUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian);
|
||||
return SCOPED_MEMORY_ACCESS.getShortUnaligned(scope(), hb, byteOffset(checkIndex(i, 2)), bigEndian);
|
||||
}
|
||||
|
||||
#end[rw]
|
||||
|
||||
public $Type$Buffer putShort(short x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
UNSAFE.putShortUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian);
|
||||
SCOPED_MEMORY_ACCESS.putShortUnaligned(scope(), hb, byteOffset(nextPutIndex(2)), x, bigEndian);
|
||||
return this;
|
||||
#else[rw]
|
||||
throw new ReadOnlyBufferException();
|
||||
|
@ -406,8 +396,7 @@ class Heap$Type$Buffer$RW$
|
|||
|
||||
public $Type$Buffer putShort(int i, short x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
UNSAFE.putShortUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
|
||||
SCOPED_MEMORY_ACCESS.putShortUnaligned(scope(), hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
|
||||
return this;
|
||||
#else[rw]
|
||||
throw new ReadOnlyBufferException();
|
||||
|
@ -439,21 +428,18 @@ class Heap$Type$Buffer$RW$
|
|||
#if[rw]
|
||||
|
||||
public int getInt() {
|
||||
checkSegment();
|
||||
return UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian);
|
||||
return SCOPED_MEMORY_ACCESS.getIntUnaligned(scope(), hb, byteOffset(nextGetIndex(4)), bigEndian);
|
||||
}
|
||||
|
||||
public int getInt(int i) {
|
||||
checkSegment();
|
||||
return UNSAFE.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian);
|
||||
return SCOPED_MEMORY_ACCESS.getIntUnaligned(scope(), hb, byteOffset(checkIndex(i, 4)), bigEndian);
|
||||
}
|
||||
|
||||
#end[rw]
|
||||
|
||||
public $Type$Buffer putInt(int x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), x, bigEndian);
|
||||
SCOPED_MEMORY_ACCESS.putIntUnaligned(scope(), hb, byteOffset(nextPutIndex(4)), x, bigEndian);
|
||||
return this;
|
||||
#else[rw]
|
||||
throw new ReadOnlyBufferException();
|
||||
|
@ -462,8 +448,7 @@ class Heap$Type$Buffer$RW$
|
|||
|
||||
public $Type$Buffer putInt(int i, int x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), x, bigEndian);
|
||||
SCOPED_MEMORY_ACCESS.putIntUnaligned(scope(), hb, byteOffset(checkIndex(i, 4)), x, bigEndian);
|
||||
return this;
|
||||
#else[rw]
|
||||
throw new ReadOnlyBufferException();
|
||||
|
@ -495,21 +480,18 @@ class Heap$Type$Buffer$RW$
|
|||
#if[rw]
|
||||
|
||||
public long getLong() {
|
||||
checkSegment();
|
||||
return UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian);
|
||||
return SCOPED_MEMORY_ACCESS.getLongUnaligned(scope(), hb, byteOffset(nextGetIndex(8)), bigEndian);
|
||||
}
|
||||
|
||||
public long getLong(int i) {
|
||||
checkSegment();
|
||||
return UNSAFE.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian);
|
||||
return SCOPED_MEMORY_ACCESS.getLongUnaligned(scope(), hb, byteOffset(checkIndex(i, 8)), bigEndian);
|
||||
}
|
||||
|
||||
#end[rw]
|
||||
|
||||
public $Type$Buffer putLong(long x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), x, bigEndian);
|
||||
SCOPED_MEMORY_ACCESS.putLongUnaligned(scope(), hb, byteOffset(nextPutIndex(8)), x, bigEndian);
|
||||
return this;
|
||||
#else[rw]
|
||||
throw new ReadOnlyBufferException();
|
||||
|
@ -518,8 +500,7 @@ class Heap$Type$Buffer$RW$
|
|||
|
||||
public $Type$Buffer putLong(int i, long x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), x, bigEndian);
|
||||
SCOPED_MEMORY_ACCESS.putLongUnaligned(scope(), hb, byteOffset(checkIndex(i, 8)), x, bigEndian);
|
||||
return this;
|
||||
#else[rw]
|
||||
throw new ReadOnlyBufferException();
|
||||
|
@ -551,14 +532,12 @@ class Heap$Type$Buffer$RW$
|
|||
#if[rw]
|
||||
|
||||
public float getFloat() {
|
||||
checkSegment();
|
||||
int x = UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian);
|
||||
int x = SCOPED_MEMORY_ACCESS.getIntUnaligned(scope(), hb, byteOffset(nextGetIndex(4)), bigEndian);
|
||||
return Float.intBitsToFloat(x);
|
||||
}
|
||||
|
||||
public float getFloat(int i) {
|
||||
checkSegment();
|
||||
int x = UNSAFE.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian);
|
||||
int x = SCOPED_MEMORY_ACCESS.getIntUnaligned(scope(), hb, byteOffset(checkIndex(i, 4)), bigEndian);
|
||||
return Float.intBitsToFloat(x);
|
||||
}
|
||||
|
||||
|
@ -566,9 +545,8 @@ class Heap$Type$Buffer$RW$
|
|||
|
||||
public $Type$Buffer putFloat(float x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
int y = Float.floatToRawIntBits(x);
|
||||
UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), y, bigEndian);
|
||||
SCOPED_MEMORY_ACCESS.putIntUnaligned(scope(), hb, byteOffset(nextPutIndex(4)), y, bigEndian);
|
||||
return this;
|
||||
#else[rw]
|
||||
throw new ReadOnlyBufferException();
|
||||
|
@ -577,9 +555,8 @@ class Heap$Type$Buffer$RW$
|
|||
|
||||
public $Type$Buffer putFloat(int i, float x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
int y = Float.floatToRawIntBits(x);
|
||||
UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), y, bigEndian);
|
||||
SCOPED_MEMORY_ACCESS.putIntUnaligned(scope(), hb, byteOffset(checkIndex(i, 4)), y, bigEndian);
|
||||
return this;
|
||||
#else[rw]
|
||||
throw new ReadOnlyBufferException();
|
||||
|
@ -611,14 +588,12 @@ class Heap$Type$Buffer$RW$
|
|||
#if[rw]
|
||||
|
||||
public double getDouble() {
|
||||
checkSegment();
|
||||
long x = UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian);
|
||||
long x = SCOPED_MEMORY_ACCESS.getLongUnaligned(scope(), hb, byteOffset(nextGetIndex(8)), bigEndian);
|
||||
return Double.longBitsToDouble(x);
|
||||
}
|
||||
|
||||
public double getDouble(int i) {
|
||||
checkSegment();
|
||||
long x = UNSAFE.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian);
|
||||
long x = SCOPED_MEMORY_ACCESS.getLongUnaligned(scope(), hb, byteOffset(checkIndex(i, 8)), bigEndian);
|
||||
return Double.longBitsToDouble(x);
|
||||
}
|
||||
|
||||
|
@ -626,9 +601,8 @@ class Heap$Type$Buffer$RW$
|
|||
|
||||
public $Type$Buffer putDouble(double x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
long y = Double.doubleToRawLongBits(x);
|
||||
UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), y, bigEndian);
|
||||
SCOPED_MEMORY_ACCESS.putLongUnaligned(scope(), hb, byteOffset(nextPutIndex(8)), y, bigEndian);
|
||||
return this;
|
||||
#else[rw]
|
||||
throw new ReadOnlyBufferException();
|
||||
|
@ -637,9 +611,8 @@ class Heap$Type$Buffer$RW$
|
|||
|
||||
public $Type$Buffer putDouble(int i, double x) {
|
||||
#if[rw]
|
||||
checkSegment();
|
||||
long y = Double.doubleToRawLongBits(x);
|
||||
UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), y, bigEndian);
|
||||
SCOPED_MEMORY_ACCESS.putLongUnaligned(scope(), hb, byteOffset(checkIndex(i, 8)), y, bigEndian);
|
||||
return this;
|
||||
#else[rw]
|
||||
throw new ReadOnlyBufferException();
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.util.Objects;
|
|||
|
||||
import jdk.internal.access.foreign.MemorySegmentProxy;
|
||||
import jdk.internal.access.foreign.UnmapperProxy;
|
||||
import jdk.internal.misc.ScopedMemoryAccess;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -87,6 +88,8 @@ public abstract class MappedByteBuffer
|
|||
// determines the behavior of force operations.
|
||||
private final boolean isSync;
|
||||
|
||||
static final ScopedMemoryAccess SCOPED_MEMORY_ACCESS = ScopedMemoryAccess.getScopedMemoryAccess();
|
||||
|
||||
// This should only be invoked by the DirectByteBuffer constructors
|
||||
//
|
||||
MappedByteBuffer(int mark, int pos, int lim, int cap, // package-private
|
||||
|
@ -173,7 +176,7 @@ public abstract class MappedByteBuffer
|
|||
if (fd == null) {
|
||||
return true;
|
||||
}
|
||||
return MappedMemoryUtils.isLoaded(address, isSync, capacity());
|
||||
return SCOPED_MEMORY_ACCESS.isLoaded(scope(), address, isSync, capacity());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -191,7 +194,7 @@ public abstract class MappedByteBuffer
|
|||
return this;
|
||||
}
|
||||
try {
|
||||
MappedMemoryUtils.load(address, isSync, capacity());
|
||||
SCOPED_MEMORY_ACCESS.load(scope(), address, isSync, capacity());
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
}
|
||||
|
@ -280,7 +283,7 @@ public abstract class MappedByteBuffer
|
|||
if ((address != 0) && (limit != 0)) {
|
||||
// check inputs
|
||||
Objects.checkFromIndexSize(index, length, limit);
|
||||
MappedMemoryUtils.force(fd, address, isSync, index, length);
|
||||
SCOPED_MEMORY_ACCESS.force(scope(), fd, address, isSync, index, length);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -1045,11 +1045,9 @@ public abstract class $Type$Buffer
|
|||
if (this.order() == src.order()) {
|
||||
#end[!byte]
|
||||
try {
|
||||
UNSAFE.copyMemory(srcBase,
|
||||
srcAddr,
|
||||
base,
|
||||
addr,
|
||||
len);
|
||||
SCOPED_MEMORY_ACCESS.copyMemory(
|
||||
scope(), src.scope(), srcBase,
|
||||
srcAddr, base, addr, len);
|
||||
} finally {
|
||||
Reference.reachabilityFence(src);
|
||||
Reference.reachabilityFence(this);
|
||||
|
@ -1057,12 +1055,9 @@ public abstract class $Type$Buffer
|
|||
#if[!byte]
|
||||
} else {
|
||||
try {
|
||||
UNSAFE.copySwapMemory(srcBase,
|
||||
srcAddr,
|
||||
base,
|
||||
addr,
|
||||
len,
|
||||
(long)1 << $LG_BYTES_PER_VALUE$);
|
||||
SCOPED_MEMORY_ACCESS.copySwapMemory(
|
||||
scope(), src.scope(), srcBase,
|
||||
srcAddr, base, addr, len, (long)1 << $LG_BYTES_PER_VALUE$);
|
||||
} finally {
|
||||
Reference.reachabilityFence(src);
|
||||
Reference.reachabilityFence(this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue