-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
None
-
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®exp=true&filter[lang][0]=Java
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®exp=true&filter[lang][0]=Java