< 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,10 +28,11 @@
 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,11 +111,11 @@
 
     // Primary constructor
     //
     Direct$Type$Buffer$RW$(int cap) {                   // package-private
 #if[rw]
-        super(-1, 0, cap, cap);
+        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,22 +144,22 @@
 #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);
+    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);
+        super(-1, 0, cap, cap, null);
         address = addr;
         cleaner = null;
         att = null;
     }
 

@@ -167,41 +168,41 @@
     // For memory-mapped buffers -- invoked by FileChannelImpl via reflection
     //
     protected Direct$Type$Buffer$RW$(int cap, long addr,
                                      FileDescriptor fd,
                                      Runnable unmapper,
-                                     boolean isSync)
+                                     boolean isSync, MemorySegmentProxy segment)
     {
 #if[rw]
-        super(-1, 0, cap, cap, fd, isSync);
+        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);
+        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)
+                               int off, MemorySegmentProxy segment)
     {
 #if[rw]
-        super(mark, pos, lim, cap);
+        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);
+        super(db, mark, pos, lim, cap, off, segment);
         this.isReadOnly = true;
 #end[rw]
     }
 
     @Override

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

@@ -262,18 +263,20 @@
         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,10 +291,11 @@
     }
 #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,10 +333,11 @@
 #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,10 +371,11 @@
 #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,10 +385,11 @@
     }
 
     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,10 +398,11 @@
 #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,10 +445,11 @@
 #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,10 +487,11 @@
 #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,11 +585,11 @@
         return new DirectCharBuffer$RW$$BO$(this,
                                             -1,
                                             pos + start,
                                             pos + end,
                                             capacity(),
-                                            offset);
+                                            offset, segment);
     }
 
 #end[char]
 
 
< prev index next >