On Mon, 20 Apr 2026 06:49:26 GMT, Damon Fenacci <[email protected]> wrote:
> [JDK-8367785](https://bugs.openjdk.org/browse/JDK-8367785) added a barrier to > the beginning of `java.lang.Object::<init>` for _strict_ fields. > > If the field is _strict_ **and** _final_, we will also add barriers to the > end of the constructors. > C1: > https://github.com/openjdk/valhalla/blob/274d56076260a490ed52df29373216617ddf73ef/src/hotspot/share/c1/c1_GraphBuilder.cpp#L1645-L1652 > C2: > https://github.com/openjdk/valhalla/blob/274d56076260a490ed52df29373216617ddf73ef/src/hotspot/share/opto/parse1.cpp#L1092-L1099 > > In that specific case the _final_ barrier can be omitted because the object > can only escape after `java.lang.Object::<init>` for strict fields. > > So, this change narrows the constructor exit barrier condition to non-strict > instance final writes only. In C2, the `do_exits()` decision now uses > `wrote_non_strict_final`, and that flag is set only for final stores where > `!field->is_strict()`. The same condition is mirrored in C1 by tracking > `wrote_non_strict_final` in IRScope and using it in > `GraphBuilder::method_return`. > > ## Testing > * added C2 IR test that checks that strict-final constructors do not get a > constructor exit barrier, while non-strict final constructors still do > * added C1 test run (to `TestStrictFinalBarriers.java`) to exercise > constructor strict-field barrier behaviour > * Tier 1-3+ > > --------- > - [x] I confirm that I make this contribution in accordance with the [OpenJDK > Interim AI Policy](https://openjdk.org/legal/ai). This pull request has now been integrated. Changeset: d841d4a6 Author: Damon Fenacci <[email protected]> URL: https://git.openjdk.org/valhalla/commit/d841d4a69885c8d8670aa7b995466a60088bd28a Stats: 167 lines in 8 files changed: 152 ins; 0 del; 15 mod 8369166: [lworld] Avoid final field barriers at the end of constructors for strict fields Reviewed-by: liach, qamai, thartmann ------------- PR: https://git.openjdk.org/valhalla/pull/2336
