On Fri, 23 Jan 2026 10:20:37 GMT, Tobias Hartmann <[email protected]> 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 Thank you for doing this, and nice that we're not wasting the bits anymore :-). I have left some smaller nit-ish comments, one open question I have myself is whether it's safe to `set_mark` when running with a concurrent GC. If anyone has any insights, it'd be good to hear. src/hotspot/share/prims/jvm.cpp line 780: > 778: // Check if mark word contains hash code already > 779: intptr_t hash = obj->mark().hash(); > 780: if (hash != 0) { We have a `has_no_hash` which might be better instead. We actually use a constant no hash value in the markWord (albeit it is zero right now). src/hotspot/share/prims/jvm.cpp line 799: > 797: } > 798: } > 799: hash = result.get_jint() & markWord::hash_mask; I don't think it's a good idea to do mask ops outside of the markWord, because it gets difficult to find them and maintain them. Can we introduce a helper function inside the markWord to do this for us? ------------- PR Review: https://git.openjdk.org/valhalla/pull/1954#pullrequestreview-3698196680 PR Review Comment: https://git.openjdk.org/valhalla/pull/1954#discussion_r2721785985 PR Review Comment: https://git.openjdk.org/valhalla/pull/1954#discussion_r2721752945
