8380084: [lworld] Implement value classes in test code using annotation#2253
8380084: [lworld] Implement value classes in test code using annotation#2253bwhuang-us wants to merge 6 commits intoopenjdk:lworldfrom
Conversation
|
👋 Welcome back bhuang! A progress list of the required criteria for merging this PR into |
|
@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: 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
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 |
|
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 |
|
@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. |
|
Does 'make test TEST=java/util/Collections/AddAll.java' run the value class patched version of the test? |
|
@liach |
|
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. |
…ng explicit VALUE_CLASS_PLUGIN flag
|
@liach Please review the latest commit, which removes the VALUE_CLASS_PLUGIN flag and adds a test instance with ValueClassPlugin and preview features enabled. |
liach
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
Webrevs
|
… @enablePreview tag.
liach
left a comment
There was a problem hiding this comment.
Looks good to me. I think at least @RogerRiggs would like to take a look too.
make/RunTests.gmk
Outdated
| )) | ||
| endif | ||
|
|
||
| ifneq ($$(wildcard $$(JTREG_VALUE_CLASS_ANNOTATION_JAR)), ) |
There was a problem hiding this comment.
Do we need to add this jar into cpa?
The tests should add '/test/lib' library and should compile this annotationati anyway?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:...
test/jtreg_value_class_plugin/plugin/jdk/test/valueclass/ValueClassPlugin.java
Show resolved
Hide resolved
| * @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 |
There was a problem hiding this comment.
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 {} |
There was a problem hiding this comment.
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 ...
There was a problem hiding this comment.
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.
lmesnik
left a comment
There was a problem hiding this comment.
see my inline comments about test dependency on plugin in the line
@compile -XDaccessInternalAPI -Xplugin:ValueClassPlugin AddAll.java
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:
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/valhalla.git pull/2253/head:pull/2253$ git checkout pull/2253Update a local copy of the PR:
$ git checkout pull/2253$ git pull https://git.openjdk.org/valhalla.git pull/2253/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 2253View PR using the GUI difftool:
$ git pr show -t 2253Using diff file
Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/2253.diff
Using Webrev
Link to Webrev Comment