< prev index next >

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

Print this page




  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("ppc64") || arch.equals("ppc64le");

  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("ppc64") || arch.equals("ppc64le")
  98             || arch.equals("aarch64");
  99     }
 100 
 101     /**
 102      * byte[] to int[] conversion, little endian byte order.
 103      */
 104     static void b2iLittle(byte[] in, int inOfs, int[] out, int outOfs, int len) {
 105         if ((inOfs < 0) || ((in.length - inOfs) < len) ||
 106             (outOfs < 0) || ((out.length - outOfs) < len/4)) {
 107             throw new ArrayIndexOutOfBoundsException();
 108         }
 109         if (littleEndianUnaligned) {
 110             inOfs += byteArrayOfs;
 111             len += inOfs;
 112             while (inOfs < len) {
 113                 out[outOfs++] = unsafe.getInt(in, (long)inOfs);
 114                 inOfs += 4;
 115             }
 116         } else if (bigEndian && ((inOfs & 3) == 0)) {
 117             inOfs += byteArrayOfs;
 118             len += inOfs;


< prev index next >