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).

src/hotspot/share/opto/parse3.cpp line 332:

> 330:     if (field->is_final() || field->is_stable()) {
> 331:       if (field->is_final()) {
> 332:         if (!field->is_strict()) {

Please combine this with the previous `if`.

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

PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2336#discussion_r3112696592

Reply via email to