< 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,10 +26,11 @@
 #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,38 +39,38 @@
 
     protected final ByteBuffer bb;
 
 #end[rw]
 
-    ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb) {   // package-private
+    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$);
+              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);
+        super(bb, segment);
 #end[rw]
     }
 
     ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb,
                                      int mark, int pos, int lim, int cap,
-                                     long addr)
+                                     long addr, MemorySegmentProxy segment)
     {
 #if[rw]
-        super(mark, pos, lim, cap);
+        super(mark, pos, lim, cap, segment);
         this.bb = bb;
         address = addr;
         assert address >= bb.address;
 #else[rw]
-        super(bb, mark, pos, lim, cap, addr);
+        super(bb, mark, pos, lim, cap, addr, segment);
 #end[rw]
     }
 
     @Override
     Object base() {

@@ -80,41 +81,41 @@
         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);
+        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));
+                                                    byteOffset(index), segment);
     }
 
     public $Type$Buffer duplicate() {
         return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
                                                     this.markValue(),
                                                     this.position(),
                                                     this.limit(),
                                                     this.capacity(),
-                                                    address);
+                                                    address, segment);
     }
 
     public $Type$Buffer asReadOnlyBuffer() {
 #if[rw]
         return new ByteBufferAs$Type$BufferR$BO$(bb,
                                                  this.markValue(),
                                                  this.position(),
                                                  this.limit(),
                                                  this.capacity(),
-                                                 address);
+                                                 address, segment);
 #else[rw]
         return duplicate();
 #end[rw]
     }
 

@@ -128,16 +129,18 @@
     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,10 +154,11 @@
 
 #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,10 +166,11 @@
 #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,11 +240,11 @@
         return new ByteBufferAsCharBuffer$RW$$BO$(bb,
                                                   -1,
                                                   pos + start,
                                                   pos + end,
                                                   capacity(),
-                                                  address);
+                                                  address, segment);
     }
 
 #end[char]
 
 
< prev index next >