On Mon, 8 Dec 2025 21:14:24 GMT, Chen Liang <[email protected]> wrote:

>> Currently, the hotspot compiler (as in ciField) trusts final fields in 
>> hidden classes, record classes, and selected jdk packages. Some classes in 
>> the JDK wish to be trusted, but they cannot apply package-wide opt-in due to 
>> other legacy classes in the package, such as java.util.
>> 
>> They currently can use `@Stable` as a workaround, but this is fragile 
>> because a stable final field may hold a trusted null, zero, or false value, 
>> which is currently treated as non-constant by ciField.
>> 
>> We should add an annotation to opt-in for a whole class, mainly for legacy 
>> packages. This would benefit greatly some of our classes already using a lot 
>> of Stable, such as java.util.Optional, whose empty instance is now 
>> constant-foldable, as demonstrated in a new IR test.
>> 
>> Paging @minborg who requested Optional folding for review.
>> 
>> I think we can remove redundant Stable in a few other java.util classes 
>> after this patch is integrated. I plan to do that in subsequent patches.
>
> Chen Liang has updated the pull request with a new target base due to a merge 
> or a rebase. The incremental webrev excludes the unrelated changes brought in 
> by the merge/rebase. The pull request contains 11 additional commits since 
> the last revision:
> 
>  - Jorn review
>  - Merge branch 'master' of https://github.com/openjdk/jdk into 
> feature/class-final-trusting
>  - bracket styles
>  - Doc tweaks
>  - Essay
>  - Spurious change
>  - Merge branch 'master' of https://github.com/openjdk/jdk into 
> feature/class-final-trusting
>  - Issue number and test update
>  - Fixed optional and unit test
>  - Merge branch 'master' of https://github.com/openjdk/jdk into 
> feature/class-final-trusting
>  - ... and 1 more: https://git.openjdk.org/jdk/compare/f4fe3397...b20b7f5b

Drive-by comments about IR test only ;)

test/hotspot/jtreg/compiler/c2/irTests/constantFold/TestOptional.java line 2:

> 1: /*
> 2:  * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.

We would like to move all tests away from `irTests`. It would be better to sort 
tests by topic, rather than by the method we test them.

test/hotspot/jtreg/compiler/c2/irTests/constantFold/TestOptional.java line 39:

> 37:  * @summary Verify constant folding for Optional
> 38:  * @library /test/lib /
> 39:  * @requires vm.compiler2.enabled

I doubt you actually need the C2 restriction here. IR tests could still run 
verification for results without C2. IR rules only run if C2 is available, 
otherwise the test can still pass, just no IR rules are run.

test/hotspot/jtreg/compiler/c2/irTests/constantFold/TestOptional.java line 40:

> 38:  * @library /test/lib /
> 39:  * @requires vm.compiler2.enabled
> 40:  * @run driver compiler.c2.irTests.constantFold.TestOptional

Suggestion:

 * @run driver ${test.main.class}

Since this is now possible, we should use this templated approach now, to avoid 
invoking the wrong test classes by accident.

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

Changes requested by epeter (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/28540#pullrequestreview-3561154527
PR Review Comment: https://git.openjdk.org/jdk/pull/28540#discussion_r2605537189
PR Review Comment: https://git.openjdk.org/jdk/pull/28540#discussion_r2605543019
PR Review Comment: https://git.openjdk.org/jdk/pull/28540#discussion_r2605539633

Reply via email to