> 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
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
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
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
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
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
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
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
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
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()`?
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
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
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.
>
> ---
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:
14 matches
Mail list logo