[lworld] RFR: 8376171: [lworld] Enable storing the hash code in the mark word of value objects [v3]

Stefan Karlsson stefank at openjdk.org
Tue Jan 27 10:25:26 UTC 2026


On Mon, 26 Jan 2026 15:43:08 GMT, Tobias Hartmann <thartmann at openjdk.org> wrote:

>> Since [JDK-8247299](https://bugs.openjdk.org/browse/JDK-8247299), value objects no longer use `markWord::always_locked_pattern` (see description of [JDK-8247298](https://bugs.openjdk.org/browse/JDK-8247298) for more details). Therefore, the limitations around storing the hash code in the mark word that are mentioned in [JDK-8244975](https://bugs.openjdk.org/browse/JDK-8244975) no longer exist. Let's enable this optimization.
>> 
>> Running `System.identityHashCode(obj)` in a loop and passing various primitive boxes leads to a **17-18x speedup** on my machine. I'm also seeing a **7% improvement** in the score of the SPECjvm2008 serial benchmark but we are still a bit behind baseline without `--enable-preview`. More improvements to come.
>> 
>> It's worth noting that value objects will lose their buffer object when stored in a flat container or sometimes when being scalarized ([JDK-8372268](https://bugs.openjdk.org/browse/JDK-8372268) will improve this). The hash then needs to be re-computed, which is expensive.
>> 
>> I'm working on ways to further improve this, see [JDK-8252185](https://bugs.openjdk.org/browse/JDK-8252185).
>> 
>> Thanks,
>> Tobias
>
> Tobias Hartmann has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Use CAS to set mark

src/hotspot/share/prims/jvm.cpp line 804:

> 802:     markWord old_mark, new_mark, test;
> 803:     do {
> 804:       old_mark = ho->mark_acquire();

Can this be just:

Suggestion:

      old_mark = ho->mark();

I don't see why this would require an "acquire".

src/hotspot/share/prims/jvm.cpp line 809:

> 807:     } while (test != old_mark);
> 808: 
> 809:     return checked_cast<jint>(new_mark.hash());

Can this be:
Suggestion:

    return checked_cast<jint>(hash);

I want to make sure that I'm not missing some subtle detail here.

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

PR Review Comment: https://git.openjdk.org/valhalla/pull/1954#discussion_r2731269365
PR Review Comment: https://git.openjdk.org/valhalla/pull/1954#discussion_r2731262778


More information about the valhalla-dev mailing list