RFR: 8372845: C2: Fold identity hash code if object is constant [v4]
Quan Anh Mai
qamai at openjdk.org
Tue Jan 13 03:31:36 UTC 2026
On Mon, 15 Dec 2025 19:49:52 GMT, Chen Liang <liach at openjdk.org> wrote:
>> Folding identity hash as constant if the incoming argument is constant would be useful for quick map lookups, such as for the [Classifier proposal](https://openjdk.org/jeps/8357674). Currently, identity hash is not constant because it loads the object header/mark word. We can add an explicit bypass to load an existing hash eagerly instead.
>
> Chen Liang has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 12 additional commits since the last revision:
>
> - Move test, fix merge garbage
> - Merge branch 'master' of https://github.com/openjdk/jdk into fix/identity-hash-const
> - Merge branch 'master' of https://github.com/openjdk/jdk into fix/identity-hash-const
> - Typo
> - assert
> - refactorings
> - Typo
> - Merge branch 'master' of https://github.com/openjdk/jdk into fix/identity-hash-const
> - Cleanup
> - identity hash support in C2
> - ... and 2 more: https://git.openjdk.org/jdk/compare/91227712...67a3954f
src/hotspot/share/ci/ciArray.cpp line 93:
> 91: // Returns T_ILLEGAL if there is no element at the given index.
> 92: ciConstant ciArray::element_value(int index) {
> 93: assert(index >= 0, "out-of-bounds index: %d", index);
IIUC, this is because you use `-1` as the offset for hashcode, so you need to make sure we are accessing a real element here, or the cache access will return something dubious. I think it is then more uniform to save the value at the cache using the offset instead of the element index.
src/hotspot/share/ci/ciObject.cpp line 233:
> 231: // Observed value is cached, so it doesn't change during compilation.
> 232: ciConstant ciObject::identity_hash() {
> 233: if (!is_null_object()) {
Just a very small nitpick: Usually it is recommended to do an early return pattern instead.
src/hotspot/share/ci/ciObject.hpp line 76:
> 74: };
> 75:
> 76: const int IDENTITY_HASH_OFFSET = -1;
`const` is fine, but `constexpr` is often preferred. Also, is `static` needed here? Another nitpick is that constants are usually not in uppercase in C++, as macros are often in uppercase.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28589#discussion_r2684670938
PR Review Comment: https://git.openjdk.org/jdk/pull/28589#discussion_r2684645067
PR Review Comment: https://git.openjdk.org/jdk/pull/28589#discussion_r2684655292
More information about the hotspot-runtime-dev
mailing list