< prev index next >
src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template
Print this page
rev 57242 : imported patch 8234049.patch
*** 28,37 ****
--- 28,38 ----
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;
*** 110,120 ****
// Primary constructor
//
Direct$Type$Buffer$RW$(int cap) { // package-private
#if[rw]
! super(-1, 0, cap, cap);
boolean pa = VM.isDirectMemoryPageAligned();
int ps = Bits.pageSize();
long size = Math.max(1L, (long)cap + (pa ? ps : 0));
Bits.reserveMemory(size, cap);
--- 111,121 ----
// Primary constructor
//
Direct$Type$Buffer$RW$(int cap) { // package-private
#if[rw]
! super(-1, 0, cap, cap, null);
boolean pa = VM.isDirectMemoryPageAligned();
int ps = Bits.pageSize();
long size = Math.max(1L, (long)cap + (pa ? ps : 0));
Bits.reserveMemory(size, cap);
*** 143,164 ****
#if[rw]
// 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);
address = addr;
cleaner = null;
att = ob;
}
// Invoked only by JNI: NewDirectByteBuffer(void*, long)
//
private Direct$Type$Buffer(long addr, int cap) {
! super(-1, 0, cap, cap);
address = addr;
cleaner = null;
att = null;
}
--- 144,165 ----
#if[rw]
// 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, MemorySegmentProxy segment) {
! super(-1, 0, cap, cap, segment);
address = addr;
cleaner = null;
att = ob;
}
// Invoked only by JNI: NewDirectByteBuffer(void*, long)
//
private Direct$Type$Buffer(long addr, int cap) {
! super(-1, 0, cap, cap, null);
address = addr;
cleaner = null;
att = null;
}
*** 167,207 ****
// For memory-mapped buffers -- invoked by FileChannelImpl via reflection
//
protected Direct$Type$Buffer$RW$(int cap, long addr,
FileDescriptor fd,
Runnable unmapper,
! boolean isSync)
{
#if[rw]
! super(-1, 0, cap, cap, fd, isSync);
address = addr;
cleaner = Cleaner.create(this, unmapper);
att = null;
#else[rw]
! super(cap, addr, fd, unmapper, isSync);
this.isReadOnly = true;
#end[rw]
}
#end[byte]
// For duplicates and slices
//
Direct$Type$Buffer$RW$$BO$(DirectBuffer db, // package-private
int mark, int pos, int lim, int cap,
! int off)
{
#if[rw]
! super(mark, pos, lim, cap);
address = db.address() + off;
#if[byte]
cleaner = null;
#end[byte]
Object attachment = db.attachment();
att = (attachment == null ? db : attachment);
#else[rw]
! super(db, mark, pos, lim, cap, off);
this.isReadOnly = true;
#end[rw]
}
@Override
--- 168,208 ----
// For memory-mapped buffers -- invoked by FileChannelImpl via reflection
//
protected Direct$Type$Buffer$RW$(int cap, long addr,
FileDescriptor fd,
Runnable unmapper,
! boolean isSync, MemorySegmentProxy segment)
{
#if[rw]
! 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, segment);
this.isReadOnly = true;
#end[rw]
}
#end[byte]
// For duplicates and slices
//
Direct$Type$Buffer$RW$$BO$(DirectBuffer db, // package-private
int mark, int pos, int lim, int cap,
! int off, MemorySegmentProxy segment)
{
#if[rw]
! super(mark, pos, lim, cap, segment);
address = db.address() + off;
#if[byte]
cleaner = null;
#end[byte]
Object attachment = db.attachment();
att = (attachment == null ? db : attachment);
#else[rw]
! super(db, mark, pos, lim, cap, off, segment);
this.isReadOnly = true;
#end[rw]
}
@Override
*** 214,254 ****
int lim = this.limit();
assert (pos <= lim);
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);
}
@Override
public $Type$Buffer slice(int index, int length) {
Objects.checkFromIndexSize(index, length, limit());
return new Direct$Type$Buffer$RW$$BO$(this,
-1,
0,
length,
length,
! index);
}
public $Type$Buffer duplicate() {
return new Direct$Type$Buffer$RW$$BO$(this,
this.markValue(),
this.position(),
this.limit(),
this.capacity(),
! 0);
}
public $Type$Buffer asReadOnlyBuffer() {
#if[rw]
return new Direct$Type$BufferR$BO$(this,
this.markValue(),
this.position(),
this.limit(),
this.capacity(),
! 0);
#else[rw]
return duplicate();
#end[rw]
}
--- 215,255 ----
int lim = this.limit();
assert (pos <= lim);
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, segment);
}
@Override
public $Type$Buffer slice(int index, int length) {
Objects.checkFromIndexSize(index, length, limit());
return new Direct$Type$Buffer$RW$$BO$(this,
-1,
0,
length,
length,
! index, segment);
}
public $Type$Buffer duplicate() {
return new Direct$Type$Buffer$RW$$BO$(this,
this.markValue(),
this.position(),
this.limit(),
this.capacity(),
! 0, segment);
}
public $Type$Buffer asReadOnlyBuffer() {
#if[rw]
return new Direct$Type$BufferR$BO$(this,
this.markValue(),
this.position(),
this.limit(),
this.capacity(),
! 0, segment);
#else[rw]
return duplicate();
#end[rw]
}
*** 262,279 ****
--- 263,282 ----
return address + ((long)i << $LG_BYTES_PER_VALUE$);
}
public $type$ get() {
try {
+ checkSegment();
return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(nextGetIndex()))));
} finally {
Reference.reachabilityFence(this);
}
}
public $type$ get(int i) {
try {
+ checkSegment();
return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(checkIndex(i)))));
} finally {
Reference.reachabilityFence(this);
}
}
*** 288,297 ****
--- 291,301 ----
}
#end[streamableType]
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();
int lim = limit();
assert (pos <= lim);
*** 329,338 ****
--- 333,343 ----
#end[rw]
}
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);
long dstOffset = ARRAY_BASE_OFFSET + ((long)offset << $LG_BYTES_PER_VALUE$);
*** 366,375 ****
--- 371,381 ----
#end[rw]
public $Type$Buffer put($type$ x) {
#if[rw]
try {
+ checkSegment();
UNSAFE.put$Swaptype$(ix(nextPutIndex()), $swap$($toBits$(x)));
} finally {
Reference.reachabilityFence(this);
}
return this;
*** 379,388 ****
--- 385,395 ----
}
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);
}
return this;
*** 391,400 ****
--- 398,408 ----
#end[rw]
}
public $Type$Buffer put($Type$Buffer src) {
#if[rw]
+ checkSegment();
if (src instanceof Direct$Type$Buffer$BO$) {
if (src == this)
throw createSameBufferException();
Direct$Type$Buffer$RW$$BO$ sb = (Direct$Type$Buffer$RW$$BO$)src;
*** 437,446 ****
--- 445,455 ----
#end[rw]
}
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();
int lim = limit();
assert (pos <= lim);
*** 478,487 ****
--- 487,497 ----
#end[rw]
}
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);
*** 575,585 ****
return new DirectCharBuffer$RW$$BO$(this,
-1,
pos + start,
pos + end,
capacity(),
! offset);
}
#end[char]
--- 585,595 ----
return new DirectCharBuffer$RW$$BO$(this,
-1,
pos + start,
pos + end,
capacity(),
! offset, segment);
}
#end[char]
< prev index next >