RFR: 8306075: Micro-optimize Enum.hashCode [v3]
ExE Boss
duke at openjdk.org
Tue Apr 18 04:52:45 UTC 2023
On Mon, 17 Apr 2023 13:00:36 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/Enum.java line 191:
>>
>>> 189: int hc = hash;
>>> 190: if (hc == 0) {
>>> 191: hc = hash = System.identityHashCode(this);
>>
>> Why not `hc = hash = super.hashCode()`?
>
> Saves the virtual call, makes for a simpler intrinsic path (no need to handle NPE and fold away, for example), since we know the super-class is already `java.lang.Object`. Unless I miss something else here...
Shouldn’t `invokespecial` produce a non‑virtual call as well?
And `this`/`super` can never be `null`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13491#discussion_r1169484780
More information about the core-libs-dev
mailing list