< prev index next >

src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -27,10 +27,11 @@
 
 package java.nio;
 
 import java.io.FileDescriptor;
 import java.lang.ref.Reference;
+import java.util.Objects;
 import jdk.internal.misc.VM;
 import jdk.internal.ref.Cleaner;
 import sun.nio.ch.DirectBuffer;
 
 

@@ -323,10 +324,45 @@
 #else[rw]
         throw new ReadOnlyBufferException();
 #end[rw]
     }
 
+    public $Type$Buffer get(int index, $type$[] dst, int offset, int length) {
+        //System.out.println("Direct absolute bulk get");
+#if[rw]
+        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$);
+            try {
+#if[!byte]
+                if (order() != ByteOrder.nativeOrder())
+                    UNSAFE.copySwapMemory(null,
+                                          ix(index),
+                                          dst,
+                                          dstOffset,
+                                          (long)length << $LG_BYTES_PER_VALUE$,
+                                          (long)1 << $LG_BYTES_PER_VALUE$);
+                else
+#end[!byte]
+                    UNSAFE.copyMemory(null,
+                                      ix(index),
+                                      dst,
+                                      dstOffset,
+                                      (long)length << $LG_BYTES_PER_VALUE$);
+            } finally {
+                Reference.reachabilityFence(this);
+            }
+        } else {
+            super.get(index, dst, offset, length);
+        }
+        return this;
+#else[rw]
+        throw new ReadOnlyBufferException();
+#end[rw]
+    }
 #end[rw]
 
     public $Type$Buffer put($type$ x) {
 #if[rw]
         try {

@@ -438,10 +474,76 @@
 #else[rw]
         throw new ReadOnlyBufferException();
 #end[rw]
     }
 
+    public $Type$Buffer put(int index, $type$[] src, int offset, int length) {
+        //System.out.println("Direct absolute bulk put array");
+#if[rw]
+        if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
+            Objects.checkFromIndexSize(index, length, limit());
+            Objects.checkFromIndexSize(offset, length, src.length);
+
+            long srcOffset = ARRAY_BASE_OFFSET + ((long)offset << $LG_BYTES_PER_VALUE$);
+            try {
+#if[!byte]
+                if (order() != ByteOrder.nativeOrder())
+                    UNSAFE.copySwapMemory(src,
+                                          srcOffset,
+                                          null,
+                                          ix(index),
+                                          (long)length << $LG_BYTES_PER_VALUE$,
+                                          (long)1 << $LG_BYTES_PER_VALUE$);
+                else
+#end[!byte]
+                    UNSAFE.copyMemory(src,
+                                      srcOffset,
+                                      null,
+                                      ix(index),
+                                      (long)length << $LG_BYTES_PER_VALUE$);
+            } finally {
+                Reference.reachabilityFence(this);
+            }
+        } else {
+            super.put(index, src, offset, length);
+        }
+        return this;
+#else[rw]
+        throw new ReadOnlyBufferException();
+#end[rw]
+    }
+
+    public $Type$Buffer put(int index, $Type$Buffer src, int offset,
+        int length) {
+        //System.out.println("Direct absolute bulk buffer");
+#if[rw]
+        if (src instanceof Direct$Type$Buffer$BO$) {
+            Direct$Type$Buffer$RW$$BO$ sb = (Direct$Type$Buffer$RW$$BO$)src;
+
+            Objects.checkFromIndexSize(index, length, limit());
+            Objects.checkFromIndexSize(offset, length, sb.limit());
+            try {
+                UNSAFE.copyMemory(sb.ix(offset), ix(index),
+                    (long)length << $LG_BYTES_PER_VALUE$);
+            } finally {
+                Reference.reachabilityFence(sb);
+                Reference.reachabilityFence(this);
+            }
+        } else if (src.hb != null) {
+            Objects.checkFromIndexSize(index, length, limit());
+            Objects.checkFromIndexSize(offset, length, src.limit());
+
+            put(index, src.hb, offset, length);
+        } else {
+            super.put(index, src, offset, length);
+        }
+        return this;
+#else[rw]
+        throw new ReadOnlyBufferException();
+#end[rw]
+    }
+
     public $Type$Buffer compact() {
 #if[rw]
         int pos = position();
         int lim = limit();
         assert (pos <= lim);
< prev index next >