RFR: 8032218: Emit single post-constructor barrier for chain of superclass constructors

Joshua Cao duke at openjdk.org
Fri Apr 19 22:35:31 UTC 2024


Opening this PR on top of https://github.com/openjdk/jdk/pull/18505. This PR is only valid if we agree it is sufficient to use `StoreStore` barriers at the end of constructors instead of `Release` barriers.

Currently on master, [C2 emits a Release barrier for each constructor call](https://github.com/openjdk/jdk/blob/32946e1882e9b22c983cbba3c6bda3cc7295946a/src/hotspot/share/opto/parse1.cpp#L1019) in a chain of superclass constructor calls. After https://github.com/openjdk/jdk/pull/18505 is merged, it is the same except that the barrier is a `StoreStore`. It is unnecessary. We only need to emit a single barrier for each object allocation / each pair of `Allocation/InitializeNode`. 

[Macro expansion emits a trailing StoreStore after an InitializeNode](https://github.com/openjdk/jdk/blob/32946e1882e9b22c983cbba3c6bda3cc7295946a/src/hotspot/share/opto/macro.cpp#L1610-L1628). This `StoreStore` is sufficient as the post-constructor barrier. From the [InitializeNode definition](https://github.com/openjdk/jdk/blob/32946e1882e9b22c983cbba3c6bda3cc7295946a/src/hotspot/share/opto/memnode.cpp#L3639-L3642):

> // An InitializeNode collects and isolates object initialization after
// an AllocateNode and before the next possible safepoint.  As a
// memory barrier (MemBarNode), it keeps critical stores from drifting
// down past any safepoint or any publication of the allocation.

All the writes that occur in the constructor will come before the `InitializeNode/StoreStore`. This PR subsumes https://github.com/openjdk/jdk/pull/18505.

Passes hotspot tier1 locally on x86 linux machine. New tests make sure that there is a single `StoreStore` for chained constructors.

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

Depends on: https://git.openjdk.org/jdk/pull/18505

Commit messages:
 - 8032218: Emit single post-constructor barrier for chain of superclass constructors

Changes: https://git.openjdk.org/jdk/pull/18870/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18870&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8032218
  Stats: 360 lines in 7 files changed: 240 ins; 117 del; 3 mod
  Patch: https://git.openjdk.org/jdk/pull/18870.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18870/head:pull/18870

PR: https://git.openjdk.org/jdk/pull/18870


More information about the hotspot-compiler-dev mailing list