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

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

Print this page
rev 13675 : imported patch unsafecopyswap
rev 13676 : [mq]: unsafecopyswap2
   1 /*
   2  * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 791      *          offset of first element of storage in destination array
 792      * @param   dstPos
 793      *          offset within destination array of the first element to write
 794      * @param   length
 795      *          number of bytes to copy
 796      */
 797     static void copyToArray(long srcAddr, Object dst, long dstBaseOffset, long dstPos,
 798                             long length)
 799     {
 800         long offset = dstBaseOffset + dstPos;
 801         while (length > 0) {
 802             long size = (length > UNSAFE_COPY_THRESHOLD) ? UNSAFE_COPY_THRESHOLD : length;
 803             unsafe.copyMemory(null, srcAddr, dst, offset, size);
 804             length -= size;
 805             srcAddr += size;
 806             offset += size;
 807         }
 808     }
 809 
 810     /**
 811      * Copy and byte swap 16 bit elements from a heap array to off-heap memory
 812      *
 813      * @param src
 814      *        the source array, must be a 16-bit primitive array type
 815      * @param srcPos
 816      *        byte offset within source array of the first element to read
 817      * @param dstAddr
 818      *        destination address
 819      * @param length
 820      *        number of bytes to copy
 821      */
 822     static void copyFromCharArray(Object src, long srcPos, long dstAddr, long length) {
 823         unsafe.copySwapMemory(src, unsafe.arrayBaseOffset(src.getClass()) + srcPos, null, dstAddr, length, 2);
 824     }
 825 
 826     /**
 827      * Copy and byte swap 16 bit elements from off-heap memory to a heap array
 828      *
 829      * @param srcAddr
 830      *        source address
 831      * @param dst
 832      *        destination array, must be a 16-bit primitive array type
 833      * @param dstPos
 834      *        byte offset within the destination array of the first element to write
 835      * @param length
 836      *        number of bytes to copy
 837      */
 838     static void copyToCharArray(long srcAddr, Object dst, long dstPos, long length) {
 839         unsafe.copySwapMemory(null, srcAddr, dst, unsafe.arrayBaseOffset(dst.getClass()) + dstPos, length, 2);
 840     }
 841 
 842     /**
 843      * Copy and byte swap 16 bit elements from a heap array to off-heap memory
 844      *
 845      * @param src
 846      *        the source array, must be a 16-bit primitive array type
 847      * @param srcPos
 848      *        byte offset within source array of the first element to read
 849      * @param dstAddr
 850      *        destination address
 851      * @param length
 852      *        number of bytes to copy
 853      */
 854     static void copyFromShortArray(Object src, long srcPos, long dstAddr, long length) {
 855         unsafe.copySwapMemory(src, unsafe.arrayBaseOffset(src.getClass()) + srcPos, null, dstAddr, length, 2);
 856     }
 857 
 858     /**
 859      * Copy and byte swap 16 bit elements from off-heap memory to a heap array
 860      *
 861      * @param srcAddr
 862      *        source address
 863      * @param dst
 864      *        destination array, must be a 16-bit primitive array type
 865      * @param dstPos
 866      *        byte offset within the destination array of the first element to write
 867      * @param length
 868      *        number of bytes to copy
 869      */
 870     static void copyToShortArray(long srcAddr, Object dst, long dstPos, long length) {
 871         unsafe.copySwapMemory(null, srcAddr, dst, unsafe.arrayBaseOffset(dst.getClass()) + dstPos, length, 2);
 872     }
 873 
 874     /**
 875      * Copy and byte swap 32 bit elements from a heap array to off-heap memory
 876      *
 877      * @param src
 878      *        the source array, must be a 32-bit primitive array type
 879      * @param srcPos
 880      *        byte offset within source array of the first element to read
 881      * @param dstAddr
 882      *        destination address
 883      * @param length
 884      *        number of bytes to copy
 885      */
 886     static void copyFromIntArray(Object src, long srcPos, long dstAddr, long length) {
 887         unsafe.copySwapMemory(src, unsafe.arrayBaseOffset(src.getClass()) + srcPos, null, dstAddr, length, 4);
 888     }
 889 
 890     /**
 891      * Copy and byte swap 32 bit elements from off-heap memory to a heap array
 892      *
 893      * @param srcAddr
 894      *        source address
 895      * @param dst
 896      *        destination array, must be a 32-bit primitive array type
 897      * @param dstPos
 898      *        byte offset within the destination array of the first element to write
 899      * @param length
 900      *        number of bytes to copy
 901      */
 902     static void copyToIntArray(long srcAddr, Object dst, long dstPos, long length) {
 903         unsafe.copySwapMemory(null, srcAddr, dst, unsafe.arrayBaseOffset(dst.getClass()) + dstPos, length, 4);
 904     }
 905 
 906     /**
 907      * Copy and byte swap 64 bit elements from a heap array to off-heap memory
 908      *
 909      * @param src
 910      *        the source array, must be a 64-bit primitive array type
 911      * @param srcPos
 912      *        byte offset within source array of the first element to read
 913      * @param dstAddr
 914      *        destination address
 915      * @param length
 916      *        number of bytes to copy
 917      */
 918     static void copyFromLongArray(Object src, long srcPos, long dstAddr, long length) {
 919         unsafe.copySwapMemory(src, unsafe.arrayBaseOffset(src.getClass()) + srcPos, null, dstAddr, length, 8);
 920     }
 921 
 922     /**
 923      * Copy and byte swap 64 bit elements from off-heap memory to a heap array
 924      *
 925      * @param srcAddr
 926      *        source address
 927      * @param dst
 928      *        destination array, must be a 64-bit primitive array type
 929      * @param dstPos
 930      *        byte offset within the destination array of the first element to write
 931      * @param length
 932      *        number of bytes to copy
 933      */
 934     static void copyToLongArray(long srcAddr, Object dst, long dstPos, long length) {
 935         unsafe.copySwapMemory(null, srcAddr, dst, unsafe.arrayBaseOffset(dst.getClass()) + dstPos, length, 8);
 936     }
 937 }
   1 /*
   2  * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 791      *          offset of first element of storage in destination array
 792      * @param   dstPos
 793      *          offset within destination array of the first element to write
 794      * @param   length
 795      *          number of bytes to copy
 796      */
 797     static void copyToArray(long srcAddr, Object dst, long dstBaseOffset, long dstPos,
 798                             long length)
 799     {
 800         long offset = dstBaseOffset + dstPos;
 801         while (length > 0) {
 802             long size = (length > UNSAFE_COPY_THRESHOLD) ? UNSAFE_COPY_THRESHOLD : length;
 803             unsafe.copyMemory(null, srcAddr, dst, offset, size);
 804             length -= size;
 805             srcAddr += size;
 806             offset += size;
 807         }
 808     }
 809 
 810     /**
 811      * Copy and unconditionally byte swap 16 bit elements from a heap array to off-heap memory
 812      *
 813      * @param src
 814      *        the source array, must be a 16-bit primitive array type
 815      * @param srcPos
 816      *        byte offset within source array of the first element to read
 817      * @param dstAddr
 818      *        destination address
 819      * @param length
 820      *        number of bytes to copy
 821      */
 822     static void copyFromCharArray(Object src, long srcPos, long dstAddr, long length) {
 823         unsafe.copySwapMemory(src, unsafe.arrayBaseOffset(src.getClass()) + srcPos, null, dstAddr, length, 2);
 824     }
 825 
 826     /**
 827      * Copy and unconditionally byte swap 16 bit elements from off-heap memory to a heap array
 828      *
 829      * @param srcAddr
 830      *        source address
 831      * @param dst
 832      *        destination array, must be a 16-bit primitive array type
 833      * @param dstPos
 834      *        byte offset within the destination array of the first element to write
 835      * @param length
 836      *        number of bytes to copy
 837      */
 838     static void copyToCharArray(long srcAddr, Object dst, long dstPos, long length) {
 839         unsafe.copySwapMemory(null, srcAddr, dst, unsafe.arrayBaseOffset(dst.getClass()) + dstPos, length, 2);
 840     }
 841 
 842     /**
 843      * Copy and unconditionally byte swap 16 bit elements from a heap array to off-heap memory
 844      *
 845      * @param src
 846      *        the source array, must be a 16-bit primitive array type
 847      * @param srcPos
 848      *        byte offset within source array of the first element to read
 849      * @param dstAddr
 850      *        destination address
 851      * @param length
 852      *        number of bytes to copy
 853      */
 854     static void copyFromShortArray(Object src, long srcPos, long dstAddr, long length) {
 855         unsafe.copySwapMemory(src, unsafe.arrayBaseOffset(src.getClass()) + srcPos, null, dstAddr, length, 2);
 856     }
 857 
 858     /**
 859      * Copy and unconditionally byte swap 16 bit elements from off-heap memory to a heap array
 860      *
 861      * @param srcAddr
 862      *        source address
 863      * @param dst
 864      *        destination array, must be a 16-bit primitive array type
 865      * @param dstPos
 866      *        byte offset within the destination array of the first element to write
 867      * @param length
 868      *        number of bytes to copy
 869      */
 870     static void copyToShortArray(long srcAddr, Object dst, long dstPos, long length) {
 871         unsafe.copySwapMemory(null, srcAddr, dst, unsafe.arrayBaseOffset(dst.getClass()) + dstPos, length, 2);
 872     }
 873 
 874     /**
 875      * Copy and unconditionally byte swap 32 bit elements from a heap array to off-heap memory
 876      *
 877      * @param src
 878      *        the source array, must be a 32-bit primitive array type
 879      * @param srcPos
 880      *        byte offset within source array of the first element to read
 881      * @param dstAddr
 882      *        destination address
 883      * @param length
 884      *        number of bytes to copy
 885      */
 886     static void copyFromIntArray(Object src, long srcPos, long dstAddr, long length) {
 887         unsafe.copySwapMemory(src, unsafe.arrayBaseOffset(src.getClass()) + srcPos, null, dstAddr, length, 4);
 888     }
 889 
 890     /**
 891      * Copy and unconditionally byte swap 32 bit elements from off-heap memory to a heap array
 892      *
 893      * @param srcAddr
 894      *        source address
 895      * @param dst
 896      *        destination array, must be a 32-bit primitive array type
 897      * @param dstPos
 898      *        byte offset within the destination array of the first element to write
 899      * @param length
 900      *        number of bytes to copy
 901      */
 902     static void copyToIntArray(long srcAddr, Object dst, long dstPos, long length) {
 903         unsafe.copySwapMemory(null, srcAddr, dst, unsafe.arrayBaseOffset(dst.getClass()) + dstPos, length, 4);
 904     }
 905 
 906     /**
 907      * Copy and unconditionally byte swap 64 bit elements from a heap array to off-heap memory
 908      *
 909      * @param src
 910      *        the source array, must be a 64-bit primitive array type
 911      * @param srcPos
 912      *        byte offset within source array of the first element to read
 913      * @param dstAddr
 914      *        destination address
 915      * @param length
 916      *        number of bytes to copy
 917      */
 918     static void copyFromLongArray(Object src, long srcPos, long dstAddr, long length) {
 919         unsafe.copySwapMemory(src, unsafe.arrayBaseOffset(src.getClass()) + srcPos, null, dstAddr, length, 8);
 920     }
 921 
 922     /**
 923      * Copy and unconditionally byte swap 64 bit elements from off-heap memory to a heap array
 924      *
 925      * @param srcAddr
 926      *        source address
 927      * @param dst
 928      *        destination array, must be a 64-bit primitive array type
 929      * @param dstPos
 930      *        byte offset within the destination array of the first element to write
 931      * @param length
 932      *        number of bytes to copy
 933      */
 934     static void copyToLongArray(long srcAddr, Object dst, long dstPos, long length) {
 935         unsafe.copySwapMemory(null, srcAddr, dst, unsafe.arrayBaseOffset(dst.getClass()) + dstPos, length, 8);
 936     }
 937 }
src/java.base/share/classes/java/nio/Bits.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File