RFR 8136924 Vectorized support for array equals/compare/mismatch using Unsafe

Vladimir Kozlov vladimir.kozlov at oracle.com
Wed Dec 2 16:02:14 UTC 2015


Thank you, Paul. This looks good.

Vladimir

On 12/2/15 1:10 AM, Paul Sandoz wrote:
>
>> On 2 Dec 2015, at 02:55, Vladimir Kozlov <vladimir.kozlov at oracle.com> wrote:
>>
>> I reviewed 8143355 today and my main question is where are range checks?
>>
>
> In this case the range checks are performed by the methods in Arrays, which call non-checking type-specific methods in ArraysSupport that in turn call vectorizedMismatch e.g:
>
> http://cr.openjdk.java.net/~psandoz/jdk9/JDK-8136924-arrays-mismatch-vectorized-unsafe/webrev/src/java.base/share/classes/java/util/Arrays.java.sdiff.html
>
> 2861     @HotSpotIntrinsicCandidate
> 2862     public static boolean equals(byte[] a, byte[] a2) {
> 2863         if (a==a2)
> 2864             return true;
> 2865         if (a==null || a2==null)
> 2866             return false;
> 2867
> 2868         int length = a.length;
> 2869         if (a2.length != length)
> 2870             return false;
> 2871
> 2872         return ArraysSupport.mismatch(a, a2, length) < 0;
> 2873     }
>
>
> 2907     public static boolean equals(byte[] a, int aFromIndex, int aToIndex,
> 2908                                  byte[] b, int bFromIndex, int bToIndex) {
> 2909         rangeCheck(a.length, aFromIndex, aToIndex);
> 2910         rangeCheck(b.length, bFromIndex, bToIndex);
> 2911
> 2912         int aLength = aToIndex - aFromIndex;
> 2913         int bLength = bToIndex - bFromIndex;
> 2914         if (aLength != bLength)
> 2915             return false;
> 2916
> 2917         return ArraysSupport.mismatch(a, aFromIndex,
> 2918                                       b, bFromIndex,
> 2919                                       aLength) < 0;
> 2920     }
>
>
> 5875     public static int compare(byte[] a, byte[] b) {
> 5876         if (a == b)
> 5877             return 0;
> 5878         if (a == null || b == null)
> 5879             return a == null ? -1 : 1;
> 5880
> 5881         int i = ArraysSupport.mismatch(a, b,
> 5882                                        Math.min(a.length, b.length));
> 5883         if (i >= 0) {
> 5884             return Byte.compare(a[i], b[i]);
> 5885         }
> 5886
> 5887         return a.length - b.length;
> 5888     }
>
>
> 5950     public static int compare(byte[] a, int aFromIndex, int aToIndex,
> 5951                               byte[] b, int bFromIndex, int bToIndex) {
> 5952         rangeCheck(a.length, aFromIndex, aToIndex);
> 5953         rangeCheck(b.length, bFromIndex, bToIndex);
> 5954
> 5955         int aLength = aToIndex - aFromIndex;
> 5956         int bLength = bToIndex - bFromIndex;
> 5957         int i = ArraysSupport.mismatch(a, aFromIndex,
> 5958                                        b, bFromIndex,
> 5959                                        Math.min(aLength, bLength));
> 5960         if (i >= 0) {
> 5961             return Byte.compare(a[aFromIndex + i], b[bFromIndex + i]);
> 5962         }
> 5963
> 5964         return aLength - bLength;
> 5965     }
>
>
> There are existing tests in place verifying that exceptions are thrown for out of bounds conditions.
>
> Paul.
>



More information about the core-libs-dev mailing list