Skip to content

8380084: [lworld] Implement value classes in test code using annotation#2253

Open
bwhuang-us wants to merge 6 commits intoopenjdk:lworldfrom
bwhuang-us:annotation2
Open

8380084: [lworld] Implement value classes in test code using annotation#2253
bwhuang-us wants to merge 6 commits intoopenjdk:lworldfrom
bwhuang-us:annotation2

Conversation

@bwhuang-us
Copy link
Copy Markdown
Contributor

@bwhuang-us bwhuang-us commented Mar 24, 2026

The idea is to implement the ValueClass annotation that can be used in test code to allow to run the same tests with and without --enable-preview.

This annotation should be used to mark value classes.

The new jtreg test compilation and execution mode that uses javac plugin to process classes during compilation. This plugin change classes with ValueClass annotation to value classes.
By default, the annotation doesn't have any impact on the tests.

Here are the work items:

  1. Create ValueClass annotation.
  2. Create a javac plugin, ValueClassPlugin, that implements a TaskListener to mark a class as a value class during the PARSE phase.
  3. Build the ValueClass plugin.
  4. Pass a new plugin option, -Xplugin:ValueClassPlugin, to enable the plugin and enable preview.

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (1 review required, with at least 1 Committer)

Issue

  • JDK-8380084: [lworld] Implement value classes in test code using annotation (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/valhalla.git pull/2253/head:pull/2253
$ git checkout pull/2253

Update a local copy of the PR:
$ git checkout pull/2253
$ git pull https://git.openjdk.org/valhalla.git pull/2253/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 2253

View PR using the GUI difftool:
$ git pr show -t 2253

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/2253.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Mar 24, 2026

👋 Welcome back bhuang! A progress list of the required criteria for merging this PR into lworld will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link
Copy Markdown

openjdk bot commented Mar 24, 2026

@bwhuang-us This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8380084: [lworld] Implement value classes in test code using annotation

Reviewed-by: liach

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 222 new commits pushed to the lworld branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@liach, @lmesnik, @RogerRiggs) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@liach
Copy link
Copy Markdown
Member

liach commented Mar 24, 2026

Looks good in principle but this means we need extra JTREG flags and need to update CI configuration; wonder if we can just update our @build or @run directives instead.

@bwhuang-us
Copy link
Copy Markdown
Contributor Author

@liach Could you please elaborate your suggestions? The goal of this task is to run tests with and without enable-preview. The annotation is the indirection that lets the same source file be valid Java in both modes. Without it (or something equivalent), there's no way to write a single source file that compiles cleanly on a normal build and becomes a value class when compiled with the plugin under preview.

@liach
Copy link
Copy Markdown
Member

liach commented Mar 25, 2026

Does 'make test TEST=java/util/Collections/AddAll.java' run the value class patched version of the test?

@bwhuang-us
Copy link
Copy Markdown
Contributor Author

@liach make test TEST=jdk/java/util/Collections/AddAll.java runs in normal mode. It needs the VALUE_CLASS_PLUGIN option to enable ValueClassPlugin and preview feature: make test TEST=jdk/java/util/Collections/AddAll.java JTREG=VALUE_CLASS_PLUGIN=true

@liach
Copy link
Copy Markdown
Member

liach commented Mar 25, 2026

Yep, so my concern is this requires special command line, which means CI tweaks elsewhere... If Oracle picks it up, github actions or other test runners may not be aware of this still.

@bwhuang-us
Copy link
Copy Markdown
Contributor Author

@liach Please review the latest commit, which removes the VALUE_CLASS_PLUGIN flag and adds a test instance with ValueClassPlugin and preview features enabled.

Copy link
Copy Markdown
Member

@liach liach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better now! Thanks for this update.

* @compile AddAll.java
* @run main AddAll
*
* @compile -XDaccessInternalAPI --enable-preview --source ${java.specification.version} -Xplugin:ValueClassPlugin AddAll.java
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might create a separate test scenario like this:

You can use another set of directives.

Alternatively I think you can do a @enablePreview after the old @run to make the subsequent run preview-enabled. But having two tests make the result looks slightly cleaner that you know it's the preview case that fails just in case.

@openjdk openjdk bot changed the title JDK-8380084 [lworld] Implement value classes in test code using annotation 8380084: [lworld] Implement value classes in test code using annotation Mar 26, 2026
@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 26, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge bot commented Mar 26, 2026

Webrevs

Copy link
Copy Markdown
Member

@liach liach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I think at least @RogerRiggs would like to take a look too.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Mar 26, 2026
))
endif

ifneq ($$(wildcard $$(JTREG_VALUE_CLASS_ANNOTATION_JAR)), )
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add this jar into cpa?

The tests should add '/test/lib' library and should compile this annotationati anyway?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right. This code is redundant after the restructuring. We don't need to add the ValueClass annotation to the cpa.

*/

/*
* @test id=Preview
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is going to fail if test is executed with
jtreg -jdk: -test ....

I think that is better to support
make JTREG_VALUE_CLASS=true run-test TEST=test/jdk/java/util/Collections/AddAll.java
and in this mode test is compiled with this plugin.

So we are not executing the preview mode by default, but can run all our test compiling and executing with --enable-preview. So all JDK build in value classes and these ValueClass marked classes are value classes.

Copy link
Copy Markdown
Contributor Author

@bwhuang-us bwhuang-us Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that plain jtreg without cpa will fail with "plugin not found". But this is temporary solution that goes away when value classes graduate from preview - so the failure being loud and obvious is a feature, not a bug. Anyone running these tests without the plugin jar is misconfigured rather than silently getting results that don't test value class behavior.

On the other hand, make test already handles it properly - the plugin jar is built as part of the test image and cpa is added automatically.

Copy link
Copy Markdown
Member

@lmesnik lmesnik Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your intentions, but not sure it is achievable.
We can't break plain jtreg execution for testing preview features. We should be able to run the default test without any additional requirements. The change of default behavior requires much wider discussion and documentation changes that doesn't worth for temporary solution.

It still think that it should be controlled in the make files. Like adding (the actual options might be updated)


+  ifneq ($$(JTREG_ENABLE_VALUE_CLASS), )
+    $1_JTREG_BASIC_OPTIONS += \
+        -vmoption:'-Djtreg.value.class=true' \
+        -vmoption:'--enable-preview' \
+        -javacoption:'-XDaccessInternalAPI' \
+        -javacoption:'--source' \
+        -javacoption:'27' \
+        -javacoption:'--enable-preview' \
+        -javacoption:'-cp' \
+        -javacoption:'...../public-plugin.jar' \
+        -javacoption:'-Xplugin:VallhallaPlugin'
+
+    $1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$(wildcard \
+        $$(addprefix $$($1_TEST_ROOT)/, ProblemList-enable-preview.txt) \
+    ))
+  endif

So we have this mode JTREG_ENABLE_VALUE_CLASS and use it instead of '--enable-preview' to test value classes. Instead of just running test with value classes enabled, we compile and use test classes as value classes here.

And test should just pass when executed with jtreg -test:...

Comment on lines +25 to +45
* @test id=NoPreview
* @bug 4822887
* @summary Basic test for Collections.addAll
* @author Josh Bloch
* @key randomness
* @library /test/lib
* @build jdk.test.lib.valueclass.ValueClass
* @run main AddAll
*/

/*
* @test id=Preview
* @bug 4822887
* @summary Basic test for Collections.addAll - Preview
* @author Josh Bloch
* @key randomness
* @library /test/lib
* @build jdk.test.lib.valueclass.ValueClass
* @enablePreview
* @compile -XDaccessInternalAPI -Xplugin:ValueClassPlugin AddAll.java
* @run main AddAll
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't scale well, the mods have to be made to each test.
Separate test blocks are fine but are only 1 use case.

There are entire test runs in which enable-preview is passed in view a test argument and all test are run with/without enable preview based on the flags.

Since the plugin is inactive unless --enable-preview is present, using the second @test block but without @enablePreview would allow the tests to be run either way with enable-preview controlled from outside the test.

*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface ValueClass {}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name ValueClass does not reflect the conditional or test context use of the annotation.
It should be named to convey that it is a parameter to the test or condition.

Maybe "TestableAsValueClass", or ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to name it AsValueClass?

… drop redundant annotation jar from jtreg -cpa, and collapse AddAll test to a single block with externally-controlled preview.
Copy link
Copy Markdown
Member

@lmesnik lmesnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my inline comments about test dependency on plugin in the line
@compile -XDaccessInternalAPI -Xplugin:ValueClassPlugin AddAll.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready Pull request is ready to be integrated rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

4 participants