Re: RFR: 8306075: Micro-optimize Enum.hashCode [v3]

2023-04-17 Thread olivergillespie
> Improve the speed of Enum.hashCode by caching the identity hashcode on first > use. I've seen an application where Enum.hashCode is a hot path, and this is > fairly simple speedup. The memory overhead is low; in enums with no extra > fields there is already a 4-byte space due to alignment so t

Re: RFR: 8306075: Micro-optimize Enum.hashCode [v3]

2023-04-17 Thread olivergillespie
On Mon, 17 Apr 2023 13:27:43 GMT, olivergillespie wrote: >> Improve the speed of Enum.hashCode by caching the identity hashcode on first >> use. I've seen an application where Enum.hashCode is a hot path, and this is >> fairly simple speedup. The memory overhead is low; in enums with no extra

Re: RFR: 8306075: Micro-optimize Enum.hashCode [v3]

2023-04-17 Thread Claes Redestad
On Mon, 17 Apr 2023 13:27:43 GMT, olivergillespie wrote: >> Improve the speed of Enum.hashCode by caching the identity hashcode on first >> use. I've seen an application where Enum.hashCode is a hot path, and this is >> fairly simple speedup. The memory overhead is low; in enums with no extra

Re: RFR: 8306075: Micro-optimize Enum.hashCode [v3]

2023-04-17 Thread Pavel Rappo
On Mon, 17 Apr 2023 13:08:41 GMT, Aleksey Shipilev wrote: >> 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.hp

Re: RFR: 8306075: Micro-optimize Enum.hashCode [v3]

2023-04-17 Thread Andrei Pangin
On Mon, 17 Apr 2023 13:27:43 GMT, olivergillespie wrote: >> Improve the speed of Enum.hashCode by caching the identity hashcode on first >> use. I've seen an application where Enum.hashCode is a hot path, and this is >> fairly simple speedup. The memory overhead is low; in enums with no extra

Re: RFR: 8306075: Micro-optimize Enum.hashCode [v3]

2023-04-17 Thread Aleksey Shipilev
On Mon, 17 Apr 2023 13:45:16 GMT, Pavel Rappo wrote: >> 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. > > From t

Re: RFR: 8306075: Micro-optimize Enum.hashCode [v3]

2023-04-17 Thread Pavel Rappo
On Mon, 17 Apr 2023 13:27:43 GMT, olivergillespie wrote: >> Improve the speed of Enum.hashCode by caching the identity hashcode on first >> use. I've seen an application where Enum.hashCode is a hot path, and this is >> fairly simple speedup. The memory overhead is low; in enums with no extra

Re: RFR: 8306075: Micro-optimize Enum.hashCode [v3]

2023-04-17 Thread Chen Liang
On Mon, 17 Apr 2023 13:45:05 GMT, Andrei Pangin wrote: >> olivergillespie has refreshed the contents of this pull request, and >> previous commits have been removed. Incremental views are not available. The >> pull request now contains one commit: >> >> 8306075: Micro-optimize Enum.hashCode

Re: RFR: 8306075: Micro-optimize Enum.hashCode [v3]

2023-04-17 Thread Pavel Rappo
On Mon, 17 Apr 2023 13:49:11 GMT, Aleksey Shipilev wrote: >> From that impl note it seemed like it was a big deal for hash code to never >> return 0 for an object. Could you maybe de-emphasize the importance of that >> HotSpot behavior in the note? > > All right, we can change "This allows to t

Re: RFR: 8306075: Micro-optimize Enum.hashCode [v3]

2023-04-17 Thread ExE Boss
On Mon, 17 Apr 2023 13:00:36 GMT, Aleksey Shipilev 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()`?

Re: RFR: 8306075: Micro-optimize Enum.hashCode [v3]

2023-04-18 Thread Aleksey Shipilev
On Tue, 18 Apr 2023 04:49:46 GMT, ExE Boss wrote: >> 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 `invokespecia

Re: RFR: 8306075: Micro-optimize Enum.hashCode [v3]

2023-04-18 Thread ExE Boss
On Tue, 18 Apr 2023 08:34:41 GMT, Aleksey Shipilev wrote: >> Shouldn’t `invokespecial` produce a non‑virtual call as well? >> >> And `this`/`super` can never be `null`. > > `super.hashCode()` is a virtual call. `System.identityHashCode` is the static > call. I don't understand where `invokespec

Re: RFR: 8306075: Micro-optimize Enum.hashCode [v3]

2023-04-18 Thread Aleksey Shipilev
On Tue, 18 Apr 2023 17:23:54 GMT, ExE Boss wrote: >> `super.hashCode()` is a virtual call. `System.identityHashCode` is the >> static call. I don't understand where `invokespecial` enters the picture >> here. > > `invokespecial` is used to call instance methods in a non‑virtual manner. > > ---

Re: RFR: 8306075: Micro-optimize Enum.hashCode [v3]

2023-04-18 Thread Chen Liang
On Tue, 18 Apr 2023 19:32:42 GMT, Aleksey Shipilev wrote: >> `invokespecial` is used to call instance methods in a non‑virtual manner. >> >> >> >> Using `super.hashCode()` in `java.lang.Enum` produces the bytecode: