RFR: 8372845: C2: Fold identity hash code if object is constant [v6]
Dean Long
dlong at openjdk.org
Thu Jan 29 06:50:32 UTC 2026
On Wed, 28 Jan 2026 03:43:15 GMT, Chen Liang <liach at openjdk.org> wrote:
>> src/hotspot/share/opto/library_call.cpp line 4791:
>>
>>> 4789: const TypeInstPtr* t = _gvn.type(obj)->isa_instptr();
>>> 4790: if (t != nullptr && t->const_oop() != nullptr) {
>>> 4791: assert(!is_virtual, "no devirtualization for constant receiver?");
>>
>> Don't we also need to check for `is_static`, to distinguish between `Object.hashCode` and `System.identityHashCode`?
>
> I think once we are not virtual, the native Object::hashCode behaves like System::identityHashCode. The only difference is null check, but I think there's a null check in the beginning so we should be safe.
OK so if we get here we are guaranteed to be calling Object::hashCode and not a devirtualized MySubClass::hashCode? I guess the intrinsic lookup would fail if the callee was a subclass.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28589#discussion_r2740204610
More information about the hotspot-dev
mailing list