On Tue, 21 Apr 2026 07:05:00 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).
>
> Damon Fenacci has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   JDK-8369166: join ifs

Looks good to me, thanks for making the fix

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

Marked as reviewed by qamai (Committer).

PR Review: 
https://git.openjdk.org/valhalla/pull/2336#pullrequestreview-4145770785

Reply via email to