[lworld] RFR: 8377101: [lworld] Automatically generate value class sources based on source annotations [v4]

Chen Liang liach at openjdk.org
Fri Feb 27 18:58:50 UTC 2026


On Fri, 27 Feb 2026 18:45:27 GMT, David Beaumont <duke at openjdk.org> wrote:

>> Adds a new AnnotationProcessor to read the @MigratedValueClass on prospective value classes and generate the equivalent source file with the 'value' keyword at each annotated class declaration.
>> 
>> This adds new PROCESSOR_PATH variable to the compilation macro and use it for annotation processing.
>> This also requires moving the plugin discovery path to the new variable (was in classpath before) because the addition of a '--processor-path' flag disables using the classpath for plugin discovery.
>> 
>> For now this is all limited to `java.base` but that's expandable later easily. There was an issue just enabling it for all modules however (esp. `jdk.incubator` which might be special).
>> 
>> While there is currently no specific unit test for this code, if it were to fail to generate the correct value classes, a lot of other downstream tests would fail.
>
> David Beaumont has updated the pull request incrementally with one additional commit since the last revision:
> 
>   More tests and tidying

Impressive work! For the injection logic, what if we have something like:

@MigratedValueClass
record Test() {}

where would value be injected?

make/jdk/src/classes/build/tools/valhalla/valuetypes/GenValueClasses.java line 81:

> 79:  * </ul>
> 80:  */
> 81: @SupportedAnnotationTypes({"jdk.internal.MigratedValueClass"})

The literal FQCN of MigratedValueClass appears twice, we might declare a constant field for it too.

make/jdk/src/classes/build/tools/valhalla/valuetypes/GenValueClasses.java line 85:

> 83: public final class GenValueClasses extends AbstractProcessor {
> 84:     // Matches preprocessor option flag in CompileJavaModules.gmk.
> 85:     private static final String OUTDIR_OPTION_KEY = "valueclasses.outdir";

Let's make this package-private so we can use it in the annotation above.

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

Marked as reviewed by liach (Committer).

PR Review: https://git.openjdk.org/valhalla/pull/2180#pullrequestreview-3868512763
PR Review Comment: https://git.openjdk.org/valhalla/pull/2180#discussion_r2865725541
PR Review Comment: https://git.openjdk.org/valhalla/pull/2180#discussion_r2865723192


More information about the valhalla-dev mailing list