Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8291989

Specialize java.util.Objects.hash(Object... values) for single argument.

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • generic
    • generic

      ```
          public static int hash(Object... values) {
              return Arrays.hashCode(values);
          }
      ```
      From Object... values to Object a[], java has to allocate an array for them.

      if user calls Objects.hash() with one argument, we don't need an array for "values".

      C2 doesn't suffer from this issue because c2 has escape analysis. The supporting array is certainly non-escaped and can be scalar replaced. only c1 and interpreter see the useless allocation.


      Inside of jdk, I only found a few hits.

      ```
      src/java.base/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java:259: Objects.hash(getAnnotatedOwnerType());
      src/java.base/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java:490: Objects.hash((Object[])getAnnotatedActualTypeArguments());
      src/java.base/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java:608: Objects.hash((Object[])getAnnotatedUpperBounds());
      src/java.base/share/classes/jdk/internal/foreign/abi/Binding.java:394: return Objects.hash(tag);
      src/java.management/share/classes/javax/management/MBeanConstructorInfo.java:207: return Objects.hash(getName()) ^ Arrays.hashCode(fastGetSignature());
      src/java.security.jgss/share/classes/sun/security/krb5/internal/rcache/AuthTimeWithHash.java:97: return Objects.hash(hash);
      ```

      on github, I found 212 cases.
      https://grep.app/search?q=Objects%5C.hash%5C%28%5B%5E%2C%5D%2A%5C%29%3B&regexp=true&filter[lang][0]=Java


            Unassigned Unassigned
            xliu Xin Liu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: