On Fri, 18 Sep 2026 12:49:59 GMT, Chen Liang <[email protected]> wrote:

>> The identity hash code of value objects currently can produce 0. A zero 
>> value is usually not anticipated for System.identityHashCode calls unless 
>> the argument is null; the 0 hash also cannot be cached. Thus, we should move 
>> away from the 0 hash.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Chen Liang has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Don't overmask

src/java.base/share/classes/java/lang/runtime/ValueObjectMethods.java line 176:

> 174:         // to enable caching. The identity hash of the value class 
> distinguishes
> 175:         // different value classes and is easy for the compiler to fetch.
> 176:         return (result & U.hashCodeMask()) == 0 ? typeHash : result;

Should this comment be updated:
> Use an alternative non-zero value when the computed hash is zero,

It contradicts the check, since we aren't comparing the computed hash code 
`result` with `0`:

> (result & U.hashCodeMask()) == 0

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/32660#discussion_r4060052222

Reply via email to