< 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,10 +26,11 @@
 #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,51 +57,51 @@
     protected final $type$[] hb;
     protected final int offset;
 #end[rw]
     */
 
-    Heap$Type$Buffer$RW$(int cap, int lim) {            // package-private
+    Heap$Type$Buffer$RW$(int cap, int lim, MemorySegmentProxy segment) {            // package-private
 #if[rw]
-        super(-1, 0, lim, cap, new $type$[cap], 0);
+        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);
+        super(cap, lim, segment);
         this.isReadOnly = true;
 #end[rw]
     }
 
-    Heap$Type$Buffer$RW$($type$[] buf, int off, int len) { // package-private
+    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);
+        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);
+        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)
+                                   int off, MemorySegmentProxy segment)
     {
 #if[rw]
-        super(mark, pos, lim, cap, buf, off);
+        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);
+        super(buf, mark, pos, lim, cap, off, segment);
         this.isReadOnly = true;
 #end[rw]
     }
 
     public $Type$Buffer slice() {

@@ -108,41 +109,41 @@
         return new Heap$Type$Buffer$RW$(hb,
                                         -1,
                                         0,
                                         rem,
                                         rem,
-                                        this.position() + offset);
+                                        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);
+                                        index + offset, segment);
     }
 
     public $Type$Buffer duplicate() {
         return new Heap$Type$Buffer$RW$(hb,
                                         this.markValue(),
                                         this.position(),
                                         this.limit(),
                                         this.capacity(),
-                                        offset);
+                                        offset, segment);
     }
 
     public $Type$Buffer asReadOnlyBuffer() {
 #if[rw]
         return new Heap$Type$BufferR(hb,
                                      this.markValue(),
                                      this.position(),
                                      this.limit(),
                                      this.capacity(),
-                                     offset);
+                                     offset, segment);
 #else[rw]
         return duplicate();
 #end[rw]
     }
 

@@ -157,34 +158,38 @@
         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,28 +204,31 @@
         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,10 +239,11 @@
 #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,10 +271,11 @@
 #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,10 +284,11 @@
     }
 
 #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,10 +336,11 @@
     // 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,19 +348,21 @@
 
 #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,45 +376,49 @@
                 ? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this,
                                                                -1,
                                                                0,
                                                                size,
                                                                size,
-                                                               addr))
+                                                               addr, segment))
                 : (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this,
                                                                -1,
                                                                0,
                                                                size,
                                                                size,
-                                                               addr)));
+                                                               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,45 +432,49 @@
                 ? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this,
                                                                  -1,
                                                                  0,
                                                                  size,
                                                                  size,
-                                                                 addr))
+                                                                 addr, segment))
                 : (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this,
                                                                  -1,
                                                                  0,
                                                                  size,
                                                                  size,
-                                                                 addr)));
+                                                                 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,45 +488,49 @@
                 ? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this,
                                                              -1,
                                                              0,
                                                              size,
                                                              size,
-                                                             addr))
+                                                             addr, segment))
                 : (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(this,
                                                              -1,
                                                              0,
                                                              size,
                                                              size,
-                                                             addr)));
+                                                             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,48 +544,52 @@
                 ? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this,
                                                                -1,
                                                                0,
                                                                size,
                                                                size,
-                                                               addr))
+                                                               addr, segment))
                 : (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(this,
                                                                -1,
                                                                0,
                                                                size,
                                                                size,
-                                                               addr)));
+                                                               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,48 +604,52 @@
                 ? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this,
                                                                  -1,
                                                                  0,
                                                                  size,
                                                                  size,
-                                                                 addr))
+                                                                 addr, segment))
                 : (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this,
                                                                  -1,
                                                                  0,
                                                                  size,
                                                                  size,
-                                                                 addr)));
+                                                                 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,17 +664,17 @@
                 ? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this,
                                                                    -1,
                                                                    0,
                                                                    size,
                                                                    size,
-                                                                   addr))
+                                                                   addr, segment))
                 : (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this,
                                                                    -1,
                                                                    0,
                                                                    size,
                                                                    size,
-                                                                   addr)));
+                                                                   addr, segment)));
     }
 
 
 #end[byte]
 

@@ -664,11 +698,11 @@
         return new HeapCharBuffer$RW$(hb,
                                       -1,
                                       pos + start,
                                       pos + end,
                                       capacity(),
-                                      offset);
+                                      offset, segment);
     }
 
 #end[char]
 
 
< prev index next >