RFR: 8306075: Micro-optimize Enum.hashCode

Aleksey Shipilev shade at openjdk.org
Mon Apr 17 13:11:34 UTC 2023


On Mon, 17 Apr 2023 12:58:57 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/Enum.java line 175:
>> 
>>> 173:      *
>>> 174:      * @implNote Once initialized, the field value does not change.
>>> 175:      * Hotspot's identity hash code generation also never returns zero
>> 
>>> Hotspot's identity hash code generation also never returns zero
>> 
>> Isn't that behavior VM-specific? Also, where is it documented?
>
> Yes, it is implementation-specific, that is why it says "Hotspot's identity hash code". The relevant code blocks are https://github.com/openjdk/jdk/blob/cc60f2ff3f16bdb04917e09cb87f09bd544f1f8b/src/hotspot/share/oops/markWord.hpp#L231-L233 (property) and https://github.com/openjdk/jdk/blob/cc60f2ff3f16bdb04917e09cb87f09bd544f1f8b/src/hotspot/share/runtime/synchronizer.cpp#L826-L827 (invariant).

It would not break the code functionally if that invariant ever breaks: we would "just" call the (intrinsic) method on zero hash code. That `implNote` only shows that it would not happen with current implementation at all.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13491#discussion_r1168667338


More information about the core-libs-dev mailing list