src/java.base/share/classes/java/nio/Bits.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Cdiff src/java.base/share/classes/java/nio/Bits.java

src/java.base/share/classes/java/nio/Bits.java

Print this page

        

*** 734,937 **** buf.truncate(); } }); } - // -- 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); - } } --- 734,744 ----
src/java.base/share/classes/java/nio/Bits.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File