8379355: [lworld] Improve test coverage of fields layouts and substitutability test with randomly generated classes#2202
8379355: [lworld] Improve test coverage of fields layouts and substitutability test with randomly generated classes#2202fparain wants to merge 14 commits intoopenjdk:lworldfrom
Conversation
|
👋 Welcome back fparain! A progress list of the required criteria for merging this PR into |
|
@fparain 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 2 new commits pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
Arraying
left a comment
There was a problem hiding this comment.
Nice test, thanks for the work. I've done a first pass of feedback mostly on the jtreg side of things to ensure that everything goes smoothly.
| shortVals[2] = "(short)1"; | ||
| shortVals[3] = "Short.MAX_VALUE"; | ||
| shortVals[4] = "Short.MIN_VALUE"; | ||
| for (int i = 5; i < NUM_PREDEFINED_VALUES; i++) { |
There was a problem hiding this comment.
Same comment for short and int as for char. Would be nice to also factor out the generation into its own method. For example:
void generateUniqueRandom(int low, int high, Function<Integer, Object> mapper, Object[] destination) and then call it e.g. generateUniqueRandom(shortMin, shortMax, i -> (short) i, shortVals.
| static ProcessBuilder exec(boolean useAtomicFlat, boolean useNullableAtomicFlat, | ||
| boolean useNullableNonAtomicFlat, String... args) throws Exception { | ||
| List<String> argsList = new ArrayList<>(); | ||
| Collections.addAll(argsList, "--enable-preview"); |
There was a problem hiding this comment.
Not necessary, ProcessTools will add it.
There was a problem hiding this comment.
I've tried to remove it, but then the test fails because of an unsupported class file version.
There was a problem hiding this comment.
That really shouldn't happen... we investigate once it's integrated.
|
Thank you @Arraying for the review. |
Arraying
left a comment
There was a problem hiding this comment.
Nice work, this is already much easier to read! I've left some follow-up comments for improving readability even further. None of them are super strictly necessary, but I feel like it may be useful for me to write down some painpoints I had in understanding.
The file handling is much better. I think it should still be made consistent with the convention of the other tests that we have that create temp files (i.e., use our own util for it rather than Java's). If you disagree, let me know, but then I'd want to take an extra closer look to ensure we don't leave any stale files anywhere.
| do { | ||
| c = (char)random.nextInt(Character.MAX_VALUE+1); | ||
|
|
||
| } while (c == Character.MAX_VALUE || c == Character.MIN_VALUE); |
There was a problem hiding this comment.
The existence loop is really confusing to me. Can we not constrain the nextInt to be within 0 to (MAX-MIN) and then offset it by MIN? (Or adjust the bounds by -1, +1, etc., but the point is then we'd always get the correct number.)
There was a problem hiding this comment.
I prefer to follow the same pattern for each primitive type.
| }, | ||
| false, new String[] {"(char)1", "Character.MAX_VALUE", "Character.MIN_VALUE"}); | ||
| primitiveTypes.add(new PrimitiveDesc("char", false, charVals)); | ||
| String[] shortVals = getPregeneratedValues(() -> { |
There was a problem hiding this comment.
Thinking about it, we could get less complexity if we converted Supplier<String> to a Function<Set, String>whereby theSet` represents all of the already computed values. So then our lambda becomes something like:
String v = null;
do {
v = "(short)" + (random.nextInt(0, (shortMax - shortMin)) + shortMin);
} while (existing.contains(v))Using a Set would also simplify getPregeneratedValues greatly. We won't need to do the duplicate checking etc. ourselves. I would suggest a TreeSet for backing so we are deterministic. We can really easily turn the Set into a String[] at the end before we return.
There was a problem hiding this comment.
I want to preserve the hard coded values with their original writing ('MAX_VALUE' and others) when generating the source file of the test classes. Still doable with the approach you propose, but then each value would have to be stored in both String and numerical format. I don't think this complexity is justified for such a minor piece of code.
| return (int)Math.ceil(Math.exp(random.nextInt(16)/7.0)); | ||
| } | ||
|
|
||
| void printStatistics(ArrayList<? extends ValueClassDesc> list) { |
There was a problem hiding this comment.
This whole method could probably be simplified with a mapreduce-style stream/collect but it will get the job done.
There was a problem hiding this comment.
Initially, it was a debug code that I kept because it can give a quick insight if the distributions used to generate the classes behave as expected or not. Again, not a critical part of the code.
| Path currentDir = Paths.get("").toAbsolutePath(); | ||
| Path tempWorkDir; | ||
| try { | ||
| tempWorkDir = Files.createTempDirectory(currentDir, "generatedClasses_" + seed); |
There was a problem hiding this comment.
Sorry, I gave you the wrong name in the earlier comment. I meant Utils not Path.
Use this instead:
valhalla/test/lib/jdk/test/lib/Utils.java
Line 808 in 432870d
There was a problem hiding this comment.
This code and the one in Utils.java are equivalent. The tests have been updated to use jdk/lib/Utils code for the sake of integration with JTREG. FYI, most tests in the runtime directory still use Files.createTemp[Directory|File] instead of the jdk/lib/Utils version.
There was a problem hiding this comment.
We should migrate to Utils, I believe there is an effort in mainline for this. Thanks for changing!
|
Thanks @Arraying for the reviews and the suggestions. |
|
Going to push as commit 56caf4a.
Your commit was automatically rebased without conflicts. |
This patch adds new tests of fields layouts and the substitutability method using randomly generated methods.
In its current form, the value class generator is limited to the JEP 401 model, meaning it doesn't support null-restricted fields nor non-atomic values.
The value class generator (ValueClassGenerator.java) is used by ValueRandomLayoutTest.java which runs the FieldLayoutAnalyzer on all generated classes to verify invariants of layouts.
The value class generator is also used by ValueComparisonTest.java which tests the substitutability method. The generated value classes have a set of pre-computed values than can be used for instance initializations and value comparisons.
Testing in progress tier1-4
Fred
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/valhalla.git pull/2202/head:pull/2202$ git checkout pull/2202Update a local copy of the PR:
$ git checkout pull/2202$ git pull https://git.openjdk.org/valhalla.git pull/2202/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 2202View PR using the GUI difftool:
$ git pr show -t 2202Using diff file
Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/2202.diff
Using Webrev
Link to Webrev Comment