< prev index next >
src/java.base/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template
Print this page
rev 57242 : imported patch 8234049.patch
*** 26,35 ****
--- 26,36 ----
#warn This file is preprocessed before being compiled
package java.nio;
import java.util.Objects;
+ import jdk.internal.access.foreign.MemorySegmentProxy;
import jdk.internal.misc.Unsafe;
class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
{
*** 38,75 ****
protected final ByteBuffer bb;
#end[rw]
! ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb) { // package-private
#if[rw]
super(-1, 0,
bb.remaining() >> $LG_BYTES_PER_VALUE$,
! bb.remaining() >> $LG_BYTES_PER_VALUE$);
this.bb = bb;
// enforce limit == capacity
int cap = this.capacity();
this.limit(cap);
int pos = this.position();
assert (pos <= cap);
address = bb.address;
#else[rw]
! super(bb);
#end[rw]
}
ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb,
int mark, int pos, int lim, int cap,
! long addr)
{
#if[rw]
! super(mark, pos, lim, cap);
this.bb = bb;
address = addr;
assert address >= bb.address;
#else[rw]
! super(bb, mark, pos, lim, cap, addr);
#end[rw]
}
@Override
Object base() {
--- 39,76 ----
protected final ByteBuffer bb;
#end[rw]
! ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb, MemorySegmentProxy segment) { // package-private
#if[rw]
super(-1, 0,
bb.remaining() >> $LG_BYTES_PER_VALUE$,
! bb.remaining() >> $LG_BYTES_PER_VALUE$, segment);
this.bb = bb;
// enforce limit == capacity
int cap = this.capacity();
this.limit(cap);
int pos = this.position();
assert (pos <= cap);
address = bb.address;
#else[rw]
! super(bb, segment);
#end[rw]
}
ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb,
int mark, int pos, int lim, int cap,
! long addr, MemorySegmentProxy segment)
{
#if[rw]
! super(mark, pos, lim, cap, segment);
this.bb = bb;
address = addr;
assert address >= bb.address;
#else[rw]
! super(bb, mark, pos, lim, cap, addr, segment);
#end[rw]
}
@Override
Object base() {
*** 80,120 ****
int pos = this.position();
int lim = this.limit();
assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0);
long addr = byteOffset(pos);
! return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, addr);
}
@Override
public $Type$Buffer slice(int index, int length) {
Objects.checkFromIndexSize(index, length, limit());
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
-1,
0,
length,
length,
! byteOffset(index));
}
public $Type$Buffer duplicate() {
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
this.markValue(),
this.position(),
this.limit(),
this.capacity(),
! address);
}
public $Type$Buffer asReadOnlyBuffer() {
#if[rw]
return new ByteBufferAs$Type$BufferR$BO$(bb,
this.markValue(),
this.position(),
this.limit(),
this.capacity(),
! address);
#else[rw]
return duplicate();
#end[rw]
}
--- 81,121 ----
int pos = this.position();
int lim = this.limit();
assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0);
long addr = byteOffset(pos);
! return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, addr, segment);
}
@Override
public $Type$Buffer slice(int index, int length) {
Objects.checkFromIndexSize(index, length, limit());
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
-1,
0,
length,
length,
! byteOffset(index), segment);
}
public $Type$Buffer duplicate() {
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
this.markValue(),
this.position(),
this.limit(),
this.capacity(),
! address, segment);
}
public $Type$Buffer asReadOnlyBuffer() {
#if[rw]
return new ByteBufferAs$Type$BufferR$BO$(bb,
this.markValue(),
this.position(),
this.limit(),
this.capacity(),
! address, segment);
#else[rw]
return duplicate();
#end[rw]
}
*** 128,143 ****
--- 129,146 ----
protected long byteOffset(long i) {
return (i << $LG_BYTES_PER_VALUE$) + address;
}
public $type$ get() {
+ checkSegment();
$memtype$ x = UNSAFE.get$Memtype$Unaligned(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)),
{#if[boB]?true:false});
return $fromBits$(x);
}
*** 151,160 ****
--- 154,164 ----
#end[rw]
public $Type$Buffer put($type$ x) {
#if[rw]
+ checkSegment();
$memtype$ y = $toBits$(x);
UNSAFE.put$Memtype$Unaligned(bb.hb, byteOffset(nextPutIndex()), y,
{#if[boB]?true:false});
return this;
#else[rw]
*** 162,171 ****
--- 166,176 ----
#end[rw]
}
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,
{#if[boB]?true:false});
return this;
#else[rw]
*** 235,245 ****
return new ByteBufferAsCharBuffer$RW$$BO$(bb,
-1,
pos + start,
pos + end,
capacity(),
! address);
}
#end[char]
--- 240,250 ----
return new ByteBufferAsCharBuffer$RW$$BO$(bb,
-1,
pos + start,
pos + end,
capacity(),
! address, segment);
}
#end[char]
< prev index next >