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

Joshua Cao duke at openjdk.org
Sun Aug 18 07:35:41 UTC 2024


> [C2 emits a StoreStore barrier for each constructor call](https://github.com/openjdk/jdk/blob/72ca7bafcd49a98c1fe09da72e4e47683f052e9d/src/hotspot/share/opto/parse1.cpp#L1016) in a chain of superclass constructor calls. 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.
> 
> This PR modifies `Parse::do_exits()` such that it only emits a barrier for a constructor if we find that the constructed object does not have an `InitializeNode`. It is possible that we cannot find an `InitializeNode` i.e. if the outermost method of the compilation unit is the constructor. We still need to emit a barrier in these cases.
> 
> Passes hotspot tier1 locally on x86 linux machine. New tests make sure that there is a single `StoreStore` for chained constructors.

Joshua Cao has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 27 commits:

 - Add tests for Stable fields
 - Fix typo in comment block
 - Merge branch 'master' into chainstorestore
 - Attempt2: Only emit StoreStore in do_exits when there is no parent
   caller
 - Merge branch 'master' of https://git.openjdk.org/jdk into chainstorestore
 - 8032218: Emit single post-constructor barrier for chain of superclass constructors
 - Add riscv64 to test
 - Merge branch 'master' into storestore
 - Merge branch 'master' into storestore
 - Apply suggestions from code review
   
   some formatting suggestions from @shipilev
   
   Co-authored-by: Aleksey Shipilëv <shipilev at amazon.de>
 - ... and 17 more: https://git.openjdk.org/jdk/compare/8635642d...acca7a26

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

Changes: https://git.openjdk.org/jdk/pull/18870/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18870&range=03
  Stats: 449 lines in 2 files changed: 445 ins; 1 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