8130891: (bf) More direct buffering
authorbpb
Thu, 06 Aug 2015 10:13:46 -0700
changeset 33300 bb014fdf246b
parent 33299 78f5508cde89
child 33301 9ee33abf5b4c
8130891: (bf) More direct buffering Summary: Improve non-byte direct buffering. Reviewed-by: alanb, jeff, ahgross, robm, rriggs
jdk/src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template
--- a/jdk/src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template	Wed Jul 29 11:04:39 2015 -0700
+++ b/jdk/src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template	Thu Aug 06 10:13:46 2015 -0700
@@ -242,7 +242,7 @@
     }
 
     private long ix(int i) {
-        return address + (i << $LG_BYTES_PER_VALUE$);
+        return address + ((long)i << $LG_BYTES_PER_VALUE$);
     }
 
     public $type$ get() {
@@ -261,7 +261,7 @@
 
     public $Type$Buffer get($type$[] dst, int offset, int length) {
 #if[rw]
-        if ((length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
+        if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
             checkBounds(offset, length, dst.length);
             int pos = position();
             int lim = limit();
@@ -273,13 +273,13 @@
 #if[!byte]
             if (order() != ByteOrder.nativeOrder())
                 Bits.copyTo$Memtype$Array(ix(pos), dst,
-                                          offset << $LG_BYTES_PER_VALUE$,
-                                          length << $LG_BYTES_PER_VALUE$);
+                                          (long)offset << $LG_BYTES_PER_VALUE$,
+                                          (long)length << $LG_BYTES_PER_VALUE$);
             else
 #end[!byte]
                 Bits.copyToArray(ix(pos), dst, arrayBaseOffset,
-                                 offset << $LG_BYTES_PER_VALUE$,
-                                 length << $LG_BYTES_PER_VALUE$);
+                                 (long)offset << $LG_BYTES_PER_VALUE$,
+                                 (long)length << $LG_BYTES_PER_VALUE$);
             position(pos + length);
         } else {
             super.get(dst, offset, length);
@@ -329,7 +329,7 @@
 
             if (srem > rem)
                 throw new BufferOverflowException();
-            unsafe.copyMemory(sb.ix(spos), ix(pos), srem << $LG_BYTES_PER_VALUE$);
+            unsafe.copyMemory(sb.ix(spos), ix(pos), (long)srem << $LG_BYTES_PER_VALUE$);
             sb.position(spos + srem);
             position(pos + srem);
         } else if (src.hb != null) {
@@ -353,7 +353,7 @@
 
     public $Type$Buffer put($type$[] src, int offset, int length) {
 #if[rw]
-        if ((length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
+        if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
             checkBounds(offset, length, src.length);
             int pos = position();
             int lim = limit();
@@ -364,12 +364,16 @@
 
 #if[!byte]
             if (order() != ByteOrder.nativeOrder())
-                Bits.copyFrom$Memtype$Array(src, offset << $LG_BYTES_PER_VALUE$,
-                                            ix(pos), length << $LG_BYTES_PER_VALUE$);
+                Bits.copyFrom$Memtype$Array(src,
+                                            (long)offset << $LG_BYTES_PER_VALUE$,
+                                            ix(pos),
+                                            (long)length << $LG_BYTES_PER_VALUE$);
             else
 #end[!byte]
-                Bits.copyFromArray(src, arrayBaseOffset, offset << $LG_BYTES_PER_VALUE$,
-                                   ix(pos), length << $LG_BYTES_PER_VALUE$);
+                Bits.copyFromArray(src, arrayBaseOffset,
+                                   (long)offset << $LG_BYTES_PER_VALUE$,
+                                   ix(pos),
+                                   (long)length << $LG_BYTES_PER_VALUE$);
             position(pos + length);
         } else {
             super.put(src, offset, length);
@@ -387,7 +391,7 @@
         assert (pos <= lim);
         int rem = (pos <= lim ? lim - pos : 0);
 
-        unsafe.copyMemory(ix(pos), ix(0), rem << $LG_BYTES_PER_VALUE$);
+        unsafe.copyMemory(ix(pos), ix(0), (long)rem << $LG_BYTES_PER_VALUE$);
         position(rem);
         limit(capacity());
         discardMark();