src/java.base/share/classes/sun/security/provider/ByteArrayAccess.java

Print this page
rev 11278 : 8073093: AARCH64: C2 generates poor code for ByteBuffer accesses
Reviewed-by: kvn


  77         boolean scaleOK = ((unsafe.arrayIndexScale(byte[].class) == 1)
  78             && (unsafe.arrayIndexScale(int[].class) == 4)
  79             && (unsafe.arrayIndexScale(long[].class) == 8)
  80             && ((byteArrayOfs & 3) == 0));
  81 
  82         ByteOrder byteOrder = ByteOrder.nativeOrder();
  83         littleEndianUnaligned =
  84             scaleOK && unaligned() && (byteOrder == ByteOrder.LITTLE_ENDIAN);
  85         bigEndian =
  86             scaleOK && (byteOrder == ByteOrder.BIG_ENDIAN);
  87     }
  88 
  89     // Return whether this platform supports full speed int/long memory access
  90     // at unaligned addresses.
  91     // This code was copied from java.nio.Bits because there is no equivalent
  92     // public API.
  93     private static boolean unaligned() {
  94         String arch = java.security.AccessController.doPrivileged
  95             (new sun.security.action.GetPropertyAction("os.arch", ""));
  96         return arch.equals("i386") || arch.equals("x86") || arch.equals("amd64")
  97             || arch.equals("x86_64");
  98     }
  99 
 100     /**
 101      * byte[] to int[] conversion, little endian byte order.
 102      */
 103     static void b2iLittle(byte[] in, int inOfs, int[] out, int outOfs, int len) {
 104         if ((inOfs < 0) || ((in.length - inOfs) < len) ||
 105             (outOfs < 0) || ((out.length - outOfs) < len/4)) {
 106             throw new ArrayIndexOutOfBoundsException();
 107         }
 108         if (littleEndianUnaligned) {
 109             inOfs += byteArrayOfs;
 110             len += inOfs;
 111             while (inOfs < len) {
 112                 out[outOfs++] = unsafe.getInt(in, (long)inOfs);
 113                 inOfs += 4;
 114             }
 115         } else if (bigEndian && ((inOfs & 3) == 0)) {
 116             inOfs += byteArrayOfs;
 117             len += inOfs;




  77         boolean scaleOK = ((unsafe.arrayIndexScale(byte[].class) == 1)
  78             && (unsafe.arrayIndexScale(int[].class) == 4)
  79             && (unsafe.arrayIndexScale(long[].class) == 8)
  80             && ((byteArrayOfs & 3) == 0));
  81 
  82         ByteOrder byteOrder = ByteOrder.nativeOrder();
  83         littleEndianUnaligned =
  84             scaleOK && unaligned() && (byteOrder == ByteOrder.LITTLE_ENDIAN);
  85         bigEndian =
  86             scaleOK && (byteOrder == ByteOrder.BIG_ENDIAN);
  87     }
  88 
  89     // Return whether this platform supports full speed int/long memory access
  90     // at unaligned addresses.
  91     // This code was copied from java.nio.Bits because there is no equivalent
  92     // public API.
  93     private static boolean unaligned() {
  94         String arch = java.security.AccessController.doPrivileged
  95             (new sun.security.action.GetPropertyAction("os.arch", ""));
  96         return arch.equals("i386") || arch.equals("x86") || arch.equals("amd64")
  97             || arch.equals("x86_64") || arch.equals("aarch64");
  98     }
  99 
 100     /**
 101      * byte[] to int[] conversion, little endian byte order.
 102      */
 103     static void b2iLittle(byte[] in, int inOfs, int[] out, int outOfs, int len) {
 104         if ((inOfs < 0) || ((in.length - inOfs) < len) ||
 105             (outOfs < 0) || ((out.length - outOfs) < len/4)) {
 106             throw new ArrayIndexOutOfBoundsException();
 107         }
 108         if (littleEndianUnaligned) {
 109             inOfs += byteArrayOfs;
 110             len += inOfs;
 111             while (inOfs < len) {
 112                 out[outOfs++] = unsafe.getInt(in, (long)inOfs);
 113                 inOfs += 4;
 114             }
 115         } else if (bigEndian && ((inOfs & 3) == 0)) {
 116             inOfs += byteArrayOfs;
 117             len += inOfs;