< prev index next >

src/java.base/share/classes/java/nio/Heap-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; /** #if[rw] * A read/write Heap$Type$Buffer. #else[rw]
*** 56,106 **** protected final $type$[] hb; protected final int offset; #end[rw] */ ! Heap$Type$Buffer$RW$(int cap, int lim) { // package-private #if[rw] ! super(-1, 0, lim, cap, new $type$[cap], 0); /* hb = new $type$[cap]; offset = 0; */ this.address = ARRAY_BASE_OFFSET; #else[rw] ! super(cap, lim); this.isReadOnly = true; #end[rw] } ! Heap$Type$Buffer$RW$($type$[] buf, int off, int len) { // package-private #if[rw] ! super(-1, off, off + len, buf.length, buf, 0); /* hb = buf; offset = 0; */ this.address = ARRAY_BASE_OFFSET; #else[rw] ! super(buf, off, len); this.isReadOnly = true; #end[rw] } protected Heap$Type$Buffer$RW$($type$[] buf, int mark, int pos, int lim, int cap, ! int off) { #if[rw] ! super(mark, pos, lim, cap, buf, off); /* hb = buf; offset = off; */ this.address = ARRAY_BASE_OFFSET + off * ARRAY_INDEX_SCALE; #else[rw] ! super(buf, mark, pos, lim, cap, off); this.isReadOnly = true; #end[rw] } public $Type$Buffer slice() { --- 57,107 ---- protected final $type$[] hb; protected final int offset; #end[rw] */ ! Heap$Type$Buffer$RW$(int cap, int lim, MemorySegmentProxy segment) { // package-private #if[rw] ! super(-1, 0, lim, cap, new $type$[cap], 0, segment); /* hb = new $type$[cap]; offset = 0; */ this.address = ARRAY_BASE_OFFSET; #else[rw] ! super(cap, lim, segment); this.isReadOnly = true; #end[rw] } ! Heap$Type$Buffer$RW$($type$[] buf, int off, int len, MemorySegmentProxy segment) { // package-private #if[rw] ! super(-1, off, off + len, buf.length, buf, 0, segment); /* hb = buf; offset = 0; */ this.address = ARRAY_BASE_OFFSET; #else[rw] ! super(buf, off, len, segment); this.isReadOnly = true; #end[rw] } protected Heap$Type$Buffer$RW$($type$[] buf, int mark, int pos, int lim, int cap, ! int off, MemorySegmentProxy segment) { #if[rw] ! super(mark, pos, lim, cap, buf, off, segment); /* hb = buf; offset = off; */ this.address = ARRAY_BASE_OFFSET + off * ARRAY_INDEX_SCALE; #else[rw] ! super(buf, mark, pos, lim, cap, off, segment); this.isReadOnly = true; #end[rw] } public $Type$Buffer slice() {
*** 108,148 **** return new Heap$Type$Buffer$RW$(hb, -1, 0, rem, rem, ! this.position() + offset); } @Override public $Type$Buffer slice(int index, int length) { Objects.checkFromIndexSize(index, length, limit()); return new Heap$Type$Buffer$RW$(hb, -1, 0, length, length, ! index + offset); } public $Type$Buffer duplicate() { return new Heap$Type$Buffer$RW$(hb, this.markValue(), this.position(), this.limit(), this.capacity(), ! offset); } public $Type$Buffer asReadOnlyBuffer() { #if[rw] return new Heap$Type$BufferR(hb, this.markValue(), this.position(), this.limit(), this.capacity(), ! offset); #else[rw] return duplicate(); #end[rw] } --- 109,149 ---- return new Heap$Type$Buffer$RW$(hb, -1, 0, rem, rem, ! this.position() + offset, segment); } @Override public $Type$Buffer slice(int index, int length) { Objects.checkFromIndexSize(index, length, limit()); return new Heap$Type$Buffer$RW$(hb, -1, 0, length, length, ! index + offset, segment); } public $Type$Buffer duplicate() { return new Heap$Type$Buffer$RW$(hb, this.markValue(), this.position(), this.limit(), this.capacity(), ! offset, segment); } public $Type$Buffer asReadOnlyBuffer() { #if[rw] return new Heap$Type$BufferR(hb, this.markValue(), this.position(), this.limit(), this.capacity(), ! offset, segment); #else[rw] return duplicate(); #end[rw] }
*** 157,190 **** --- 158,195 ---- return address + i; } #end[byte] public $type$ get() { + checkSegment(); return hb[ix(nextGetIndex())]; } public $type$ get(int i) { + checkSegment(); return hb[ix(checkIndex(i))]; } #if[streamableType] $type$ getUnchecked(int i) { return hb[ix(i)]; } #end[streamableType] public $Type$Buffer get($type$[] dst, int offset, int length) { + checkSegment(); Objects.checkFromIndexSize(offset, length, dst.length); int pos = position(); if (length > limit() - pos) throw new BufferUnderflowException(); System.arraycopy(hb, ix(pos), dst, offset, length); position(pos + length); return this; } public $Type$Buffer get(int index, $type$[] dst, int offset, int length) { + checkSegment(); Objects.checkFromIndexSize(index, length, limit()); Objects.checkFromIndexSize(offset, length, dst.length); System.arraycopy(hb, ix(index), dst, offset, length); return this; }
*** 199,226 **** --- 204,234 ---- return {#if[rw]?false:true}; } public $Type$Buffer put($type$ x) { #if[rw] + checkSegment(); hb[ix(nextPutIndex())] = x; return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw] } public $Type$Buffer put(int i, $type$ x) { #if[rw] + checkSegment(); hb[ix(checkIndex(i))] = x; return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw] } public $Type$Buffer put($type$[] src, int offset, int length) { #if[rw] + checkSegment(); Objects.checkFromIndexSize(offset, length, src.length); int pos = position(); if (length > limit() - pos) throw new BufferOverflowException(); System.arraycopy(src, offset, hb, ix(pos), length);
*** 231,240 **** --- 239,249 ---- #end[rw] } public $Type$Buffer put($Type$Buffer src) { #if[rw] + checkSegment(); if (src instanceof Heap$Type$Buffer) { if (src == this) throw createSameBufferException(); Heap$Type$Buffer sb = (Heap$Type$Buffer)src; int pos = position();
*** 262,271 **** --- 271,281 ---- #end[rw] } public $Type$Buffer put(int index, $type$[] src, int offset, int length) { #if[rw] + checkSegment(); Objects.checkFromIndexSize(index, length, limit()); Objects.checkFromIndexSize(offset, length, src.length); System.arraycopy(src, offset, hb, ix(index), length); return this; #else[rw]
*** 274,283 **** --- 284,294 ---- } #if[char] public $Type$Buffer put(String src, int start, int end) { + checkSegment(); int length = end - start; Objects.checkFromIndexSize(start, length, src.length()); if (isReadOnly()) throw new ReadOnlyBufferException(); int pos = position();
*** 325,334 **** --- 336,346 ---- // char #if[rw] public char getChar() { + checkSegment(); return UNSAFE.getCharUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian); } public char getChar(int i) { return UNSAFE.getCharUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian);
*** 336,354 **** --- 348,368 ---- #end[rw] public $Type$Buffer putChar(char x) { #if[rw] + checkSegment(); UNSAFE.putCharUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw] } public $Type$Buffer putChar(int i, char x) { #if[rw] + checkSegment(); UNSAFE.putCharUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw]
*** 362,406 **** ? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this, -1, 0, size, size, ! addr)) : (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this, -1, 0, size, size, ! addr))); } // short #if[rw] public short getShort() { return UNSAFE.getShortUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian); } public short getShort(int i) { return UNSAFE.getShortUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian); } #end[rw] public $Type$Buffer putShort(short x) { #if[rw] UNSAFE.putShortUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw] } public $Type$Buffer putShort(int i, short x) { #if[rw] UNSAFE.putShortUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw] --- 376,424 ---- ? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this, -1, 0, size, size, ! addr, segment)) : (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this, -1, 0, size, size, ! addr, segment))); } // short #if[rw] public short getShort() { + checkSegment(); return UNSAFE.getShortUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian); } public short getShort(int i) { + checkSegment(); return UNSAFE.getShortUnaligned(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); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw] } public $Type$Buffer putShort(int i, short x) { #if[rw] + checkSegment(); UNSAFE.putShortUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw]
*** 414,458 **** ? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this, -1, 0, size, size, ! addr)) : (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this, -1, 0, size, size, ! addr))); } // int #if[rw] public int getInt() { return UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian); } public int getInt(int i) { return UNSAFE.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian); } #end[rw] public $Type$Buffer putInt(int x) { #if[rw] UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw] } public $Type$Buffer putInt(int i, int x) { #if[rw] UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw] --- 432,480 ---- ? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this, -1, 0, size, size, ! addr, segment)) : (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this, -1, 0, size, size, ! addr, segment))); } // int #if[rw] public int getInt() { + checkSegment(); return UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian); } public int getInt(int i) { + checkSegment(); return UNSAFE.getIntUnaligned(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); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw] } public $Type$Buffer putInt(int i, int x) { #if[rw] + checkSegment(); UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw]
*** 466,510 **** ? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this, -1, 0, size, size, ! addr)) : (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(this, -1, 0, size, size, ! addr))); } // long #if[rw] public long getLong() { return UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian); } public long getLong(int i) { return UNSAFE.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian); } #end[rw] public $Type$Buffer putLong(long x) { #if[rw] UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw] } public $Type$Buffer putLong(int i, long x) { #if[rw] UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw] --- 488,536 ---- ? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this, -1, 0, size, size, ! addr, segment)) : (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(this, -1, 0, size, size, ! addr, segment))); } // long #if[rw] public long getLong() { + checkSegment(); return UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian); } public long getLong(int i) { + checkSegment(); return UNSAFE.getLongUnaligned(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); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw] } public $Type$Buffer putLong(int i, long x) { #if[rw] + checkSegment(); UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw]
*** 518,565 **** ? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this, -1, 0, size, size, ! addr)) : (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(this, -1, 0, size, size, ! addr))); } // float #if[rw] public float getFloat() { int x = UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian); return Float.intBitsToFloat(x); } public float getFloat(int i) { int x = UNSAFE.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian); return Float.intBitsToFloat(x); } #end[rw] public $Type$Buffer putFloat(float x) { #if[rw] int y = Float.floatToRawIntBits(x); UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), y, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw] } public $Type$Buffer putFloat(int i, float x) { #if[rw] int y = Float.floatToRawIntBits(x); UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), y, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); --- 544,595 ---- ? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this, -1, 0, size, size, ! addr, segment)) : (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(this, -1, 0, size, size, ! addr, segment))); } // float #if[rw] public float getFloat() { + checkSegment(); int x = UNSAFE.getIntUnaligned(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); return Float.intBitsToFloat(x); } #end[rw] public $Type$Buffer putFloat(float x) { #if[rw] + checkSegment(); int y = Float.floatToRawIntBits(x); UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), y, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[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); return this; #else[rw] throw new ReadOnlyBufferException();
*** 574,621 **** ? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this, -1, 0, size, size, ! addr)) : (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this, -1, 0, size, size, ! addr))); } // double #if[rw] public double getDouble() { long x = UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian); return Double.longBitsToDouble(x); } public double getDouble(int i) { long x = UNSAFE.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian); return Double.longBitsToDouble(x); } #end[rw] public $Type$Buffer putDouble(double x) { #if[rw] long y = Double.doubleToRawLongBits(x); UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), y, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[rw] } public $Type$Buffer putDouble(int i, double x) { #if[rw] long y = Double.doubleToRawLongBits(x); UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), y, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); --- 604,655 ---- ? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this, -1, 0, size, size, ! addr, segment)) : (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this, -1, 0, size, size, ! addr, segment))); } // double #if[rw] public double getDouble() { + checkSegment(); long x = UNSAFE.getLongUnaligned(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); return Double.longBitsToDouble(x); } #end[rw] public $Type$Buffer putDouble(double x) { #if[rw] + checkSegment(); long y = Double.doubleToRawLongBits(x); UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), y, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); #end[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); return this; #else[rw] throw new ReadOnlyBufferException();
*** 630,646 **** ? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this, -1, 0, size, size, ! addr)) : (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this, -1, 0, size, size, ! addr))); } #end[byte] --- 664,680 ---- ? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this, -1, 0, size, size, ! addr, segment)) : (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this, -1, 0, size, size, ! addr, segment))); } #end[byte]
*** 664,674 **** return new HeapCharBuffer$RW$(hb, -1, pos + start, pos + end, capacity(), ! offset); } #end[char] --- 698,708 ---- return new HeapCharBuffer$RW$(hb, -1, pos + start, pos + end, capacity(), ! offset, segment); } #end[char]
< prev index next >