RFR: 8311864: Add ArraysSupport.hashCode(int[] a, fromIndex, length, initialValue)
Claes Redestad
redestad at openjdk.org
Fri Jul 28 10:07:50 UTC 2023
On Tue, 11 Jul 2023 16:35:51 GMT, Pavel Rappo <prappo at openjdk.org> wrote:
> This PR adds an internal method to calculate hash code from the provided integer array, offset and length into that array, and the initial hash code value.
>
> Current options for calculating a hash code for int[] are inflexible. It's either ArraysSupport.vectorizedHashCode with an offset, length and initial value, or Arrays.hashCode with just an array.
>
> For an arbitrary int[], unconditional vectorization might be unwarranted or puzzling. Unfortunately, it's the only hash code method that operates on an array subrange or accepts the initial hash code value.
>
> A more convenient method could be added and then used, for example, here:
>
> * https://github.com/openjdk/jdk/blob/0ef03f122866f010ebf50683097e9b92e41cdaad/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java#L1076-L1083
>
> * https://github.com/openjdk/jdk/blob/0ef03f122866f010ebf50683097e9b92e41cdaad/src/java.base/share/classes/java/util/ArrayList.java#L669-L680
>
> * https://github.com/openjdk/jdk/blob/0ef03f122866f010ebf50683097e9b92e41cdaad/src/java.base/share/classes/sun/security/pkcs10/PKCS10.java#L356-L362
>
> This PR adds such a method and provides tests for it. Additionally, this PR adds tests for `null` passed to `java.util.Arrays.hashCode` overloads, behaviour which was specified but untested.
I think we could consider dropping `vectorized` from `vectorizedHashCode`: there's nothing in the library-side implementation for this that is explicitly setting up for vectorization of each case (unlike the `mismatch/vectorizedMismatch` pair). Handling of short arrays is dealt with in the intrinsic, and care was taken to make sure that the implementation is as fast or faster for small as well as large inputs.
It might make sense to move the tiny-input case switch to `ArraysSupport` though, and have it delegate to the IntrinsicCandidate method (the point of those is to avoid calling into the intrinsic routine for tiny inputs).
-------------
PR Comment: https://git.openjdk.org/jdk/pull/14831#issuecomment-1655426453
More information about the core-libs-dev
mailing list