RFR: 8306075: Micro-optimize Enum.hashCode [v4]

Aleksey Shipilev shade at openjdk.org
Mon Apr 17 16:28:35 UTC 2023


On Mon, 17 Apr 2023 15:41:34 GMT, olivergillespie <duke at openjdk.org> wrote:

>> Yes, it is a bit strange to see @implNote here as this is a private field that isn't going to show up in the javadoc. The javadoc for non-transient fields in Serializable classes does show up in the Serialized Form page but this Enum which is special.
>
> Thanks, so I'll switch to a `/*` comment with no markup?

No. Existing `private` fields, `name` and `ordinal` use Javadoc-style `/**` comment. New field should use `/**` to match the style. The only thing that we might want is to move implementation discussion into the method body, like this:


    /**
     * The hash code of this enumeration constant.
     */
    @Stable
    private int hash;

    /**
     * Returns a hash code for this enum constant.
     *
     * @return a hash code for this enum constant.
     */
    public final int hashCode() {
        // Once initialized, the hash field value does not change.
        // HotSpot's identity hash code generation also never returns zero
        // as the identity hash code. This makes zero a convenient marker
        // for the un-initialized value for both @Stable and the lazy
        // initialization code below.

        int hc = hash;
        if (hc == 0) {
            hc = hash = System.identityHashCode(this);
        }
        return hc;
    }

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

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


More information about the core-libs-dev mailing list