openj9 icon indicating copy to clipboard operation
openj9 copied to clipboard

State based hashcode for value types

Open hangshao0 opened this issue 2 years ago • 4 comments

The hash code of a value type should be based on its state rather than the identity (address). Currently OpenJ9 still calculates the hash code of value types using its address rather than its value.

hangshao0 avatar Jul 12 '22 20:07 hangshao0

This is related to https://github.com/eclipse-openj9/openj9/pull/15497.

JCL has a private helper in class PrimitiveObjectMethods that calculates the VT hash code: private static int primitiveObjectHashCode(Object o)

hangshao0 avatar Jul 12 '22 20:07 hangshao0

@ehrenjulzert will be look at this.

hangshao0 avatar Jul 14 '22 18:07 hangshao0

Doing call-in inside existing native method convertValueToHash() is not an option, see the discussions here: https://github.com/eclipse-openj9/openj9/pull/15741.

hangshao0 avatar Aug 22 '22 19:08 hangshao0

As we discussed in #15880, implementing hashcodes for value types natively will be difficult and require changes to the GC. It also may not be worth it to sink too too much time into the native implementation since the spec may change in the future to remove the need to hash value types at all. For this reason I've decided to instead make a temporary implementation purely in Java which just calls the primitiveObjectHashCode helper function.

ehrenjulzert avatar Sep 19 '22 20:09 ehrenjulzert