RFR: 8372845: C2: Fold identity hash code if object is constant [v3]

Emanuel Peter epeter at openjdk.org
Wed Dec 10 17:21:05 UTC 2025


On Wed, 10 Dec 2025 15:36:36 GMT, Chen Liang <liach at openjdk.org> wrote:

>> test/hotspot/jtreg/compiler/c2/irTests/constantFold/IdentityHashCodeFold.java line 37:
>> 
>>> 35:  * @library /test/lib /
>>> 36:  * @requires vm.compiler2.enabled
>>> 37:  * @run driver compiler.c2.irTests.constantFold.IdentityHashCodeFold
>> 
>> Suggestion:
>> 
>>  * @run driver ${test.main.class}
>> 
>> Is the C2 requirement really necessary?
>
> The C2 requirement is effective if a build configuration disables the compiler2 feature. I don't know if we run tests in such a build. I copied this from `compiler/c2/irTests/TestEnumFinalFold.java` in particular.

You can for example run it with C1 or Xint only. That would disable the test. Or someone runs it with Graal.
I would generally remove `@requires` from any test we can, to get more coverage.

>> test/hotspot/jtreg/compiler/c2/irTests/constantFold/IdentityHashCodeFold.java line 51:
>> 
>>> 49:     public int testSum() {
>>> 50:         return a.hashCode() + System.identityHashCode(b);
>>> 51:     }
>> 
>> This does not test correctness of the result. How confident are we that this patch is sufficiently tested?
>> How can we test that the compiled and interpreter hashcode are equivalent?
>
> I can't find a way to access the identity hash code without compilation. Would something like a method that calls System.identityHashCode but is not inlied work?

You could compute the result in the static initializer, it should therefore be computed in the interpreter. And then add a `@Check` method to compare the `testSum` value from the compiler.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28589#discussion_r2607542060
PR Review Comment: https://git.openjdk.org/jdk/pull/28589#discussion_r2607538782


More information about the hotspot-dev mailing list