8149596: Remove java.nio.Bits copy wrapper methods
Reviewed-by: bpb, chegar, psandoz
--- a/jdk/src/java.base/share/classes/java/nio/Bits.java Wed Mar 02 20:36:00 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/nio/Bits.java Wed Mar 02 13:21:20 2016 -0800
@@ -736,202 +736,9 @@
});
}
- // -- Bulk get/put acceleration --
-
// These numbers represent the point at which we have empirically
// determined that the average cost of a JNI call exceeds the expense
// of an element by element copy. These numbers may change over time.
static final int JNI_COPY_TO_ARRAY_THRESHOLD = 6;
static final int JNI_COPY_FROM_ARRAY_THRESHOLD = 6;
-
- // This number limits the number of bytes to copy per call to Unsafe's
- // copyMemory method. A limit is imposed to allow for safepoint polling
- // during a large copy
- static final long UNSAFE_COPY_THRESHOLD = 1024L * 1024L;
-
- // These methods do no bounds checking. Verification that the copy will not
- // result in memory corruption should be done prior to invocation.
- // All positions and lengths are specified in bytes.
-
- /**
- * Copy from given source array to destination address.
- *
- * @param src
- * source array
- * @param srcBaseOffset
- * offset of first element of storage in source array
- * @param srcPos
- * offset within source array of the first element to read
- * @param dstAddr
- * destination address
- * @param length
- * number of bytes to copy
- */
- static void copyFromArray(Object src, long srcBaseOffset, long srcPos,
- long dstAddr, long length)
- {
- long offset = srcBaseOffset + srcPos;
- while (length > 0) {
- long size = (length > UNSAFE_COPY_THRESHOLD) ? UNSAFE_COPY_THRESHOLD : length;
- unsafe.copyMemory(src, offset, null, dstAddr, size);
- length -= size;
- offset += size;
- dstAddr += size;
- }
- }
-
- /**
- * Copy from source address into given destination array.
- *
- * @param srcAddr
- * source address
- * @param dst
- * destination array
- * @param dstBaseOffset
- * offset of first element of storage in destination array
- * @param dstPos
- * offset within destination array of the first element to write
- * @param length
- * number of bytes to copy
- */
- static void copyToArray(long srcAddr, Object dst, long dstBaseOffset, long dstPos,
- long length)
- {
- long offset = dstBaseOffset + dstPos;
- while (length > 0) {
- long size = (length > UNSAFE_COPY_THRESHOLD) ? UNSAFE_COPY_THRESHOLD : length;
- unsafe.copyMemory(null, srcAddr, dst, offset, size);
- length -= size;
- srcAddr += size;
- offset += size;
- }
- }
-
- /**
- * Copy and unconditionally byte swap 16 bit elements from a heap array to off-heap memory
- *
- * @param src
- * the source array, must be a 16-bit primitive array type
- * @param srcPos
- * byte offset within source array of the first element to read
- * @param dstAddr
- * destination address
- * @param length
- * number of bytes to copy
- */
- static void copyFromCharArray(Object src, long srcPos, long dstAddr, long length) {
- unsafe.copySwapMemory(src, unsafe.arrayBaseOffset(src.getClass()) + srcPos, null, dstAddr, length, 2);
- }
-
- /**
- * Copy and unconditionally byte swap 16 bit elements from off-heap memory to a heap array
- *
- * @param srcAddr
- * source address
- * @param dst
- * destination array, must be a 16-bit primitive array type
- * @param dstPos
- * byte offset within the destination array of the first element to write
- * @param length
- * number of bytes to copy
- */
- static void copyToCharArray(long srcAddr, Object dst, long dstPos, long length) {
- unsafe.copySwapMemory(null, srcAddr, dst, unsafe.arrayBaseOffset(dst.getClass()) + dstPos, length, 2);
- }
-
- /**
- * Copy and unconditionally byte swap 16 bit elements from a heap array to off-heap memory
- *
- * @param src
- * the source array, must be a 16-bit primitive array type
- * @param srcPos
- * byte offset within source array of the first element to read
- * @param dstAddr
- * destination address
- * @param length
- * number of bytes to copy
- */
- static void copyFromShortArray(Object src, long srcPos, long dstAddr, long length) {
- unsafe.copySwapMemory(src, unsafe.arrayBaseOffset(src.getClass()) + srcPos, null, dstAddr, length, 2);
- }
-
- /**
- * Copy and unconditionally byte swap 16 bit elements from off-heap memory to a heap array
- *
- * @param srcAddr
- * source address
- * @param dst
- * destination array, must be a 16-bit primitive array type
- * @param dstPos
- * byte offset within the destination array of the first element to write
- * @param length
- * number of bytes to copy
- */
- static void copyToShortArray(long srcAddr, Object dst, long dstPos, long length) {
- unsafe.copySwapMemory(null, srcAddr, dst, unsafe.arrayBaseOffset(dst.getClass()) + dstPos, length, 2);
- }
-
- /**
- * Copy and unconditionally byte swap 32 bit elements from a heap array to off-heap memory
- *
- * @param src
- * the source array, must be a 32-bit primitive array type
- * @param srcPos
- * byte offset within source array of the first element to read
- * @param dstAddr
- * destination address
- * @param length
- * number of bytes to copy
- */
- static void copyFromIntArray(Object src, long srcPos, long dstAddr, long length) {
- unsafe.copySwapMemory(src, unsafe.arrayBaseOffset(src.getClass()) + srcPos, null, dstAddr, length, 4);
- }
-
- /**
- * Copy and unconditionally byte swap 32 bit elements from off-heap memory to a heap array
- *
- * @param srcAddr
- * source address
- * @param dst
- * destination array, must be a 32-bit primitive array type
- * @param dstPos
- * byte offset within the destination array of the first element to write
- * @param length
- * number of bytes to copy
- */
- static void copyToIntArray(long srcAddr, Object dst, long dstPos, long length) {
- unsafe.copySwapMemory(null, srcAddr, dst, unsafe.arrayBaseOffset(dst.getClass()) + dstPos, length, 4);
- }
-
- /**
- * Copy and unconditionally byte swap 64 bit elements from a heap array to off-heap memory
- *
- * @param src
- * the source array, must be a 64-bit primitive array type
- * @param srcPos
- * byte offset within source array of the first element to read
- * @param dstAddr
- * destination address
- * @param length
- * number of bytes to copy
- */
- static void copyFromLongArray(Object src, long srcPos, long dstAddr, long length) {
- unsafe.copySwapMemory(src, unsafe.arrayBaseOffset(src.getClass()) + srcPos, null, dstAddr, length, 8);
- }
-
- /**
- * Copy and unconditionally byte swap 64 bit elements from off-heap memory to a heap array
- *
- * @param srcAddr
- * source address
- * @param dst
- * destination array, must be a 64-bit primitive array type
- * @param dstPos
- * byte offset within the destination array of the first element to write
- * @param length
- * number of bytes to copy
- */
- static void copyToLongArray(long srcAddr, Object dst, long dstPos, long length) {
- unsafe.copySwapMemory(null, srcAddr, dst, unsafe.arrayBaseOffset(dst.getClass()) + dstPos, length, 8);
- }
}
--- a/jdk/src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template Wed Mar 02 20:36:00 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template Wed Mar 02 13:21:20 2016 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, 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
@@ -270,16 +270,22 @@
if (length > rem)
throw new BufferUnderflowException();
+ long dstOffset = arrayBaseOffset + ((long)offset << $LG_BYTES_PER_VALUE$);
#if[!byte]
if (order() != ByteOrder.nativeOrder())
- Bits.copyTo$Memtype$Array(ix(pos), dst,
- (long)offset << $LG_BYTES_PER_VALUE$,
- (long)length << $LG_BYTES_PER_VALUE$);
+ unsafe.copySwapMemory(null,
+ ix(pos),
+ dst,
+ dstOffset,
+ (long)length << $LG_BYTES_PER_VALUE$,
+ (long)1 << $LG_BYTES_PER_VALUE$);
else
#end[!byte]
- Bits.copyToArray(ix(pos), dst, arrayBaseOffset,
- (long)offset << $LG_BYTES_PER_VALUE$,
- (long)length << $LG_BYTES_PER_VALUE$);
+ unsafe.copyMemory(null,
+ ix(pos),
+ dst,
+ dstOffset,
+ (long)length << $LG_BYTES_PER_VALUE$);
position(pos + length);
} else {
super.get(dst, offset, length);
@@ -362,18 +368,22 @@
if (length > rem)
throw new BufferOverflowException();
+ long srcOffset = arrayBaseOffset + ((long)offset << $LG_BYTES_PER_VALUE$);
#if[!byte]
if (order() != ByteOrder.nativeOrder())
- Bits.copyFrom$Memtype$Array(src,
- (long)offset << $LG_BYTES_PER_VALUE$,
- ix(pos),
- (long)length << $LG_BYTES_PER_VALUE$);
+ unsafe.copySwapMemory(src,
+ srcOffset,
+ null,
+ ix(pos),
+ (long)length << $LG_BYTES_PER_VALUE$,
+ (long)1 << $LG_BYTES_PER_VALUE$);
else
#end[!byte]
- Bits.copyFromArray(src, arrayBaseOffset,
- (long)offset << $LG_BYTES_PER_VALUE$,
- ix(pos),
- (long)length << $LG_BYTES_PER_VALUE$);
+ unsafe.copyMemory(src,
+ srcOffset,
+ null,
+ ix(pos),
+ (long)length << $LG_BYTES_PER_VALUE$);
position(pos + length);
} else {
super.put(src, offset, length);