-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8365467: Issues with jrtfs implementation for exploded run-time images #26757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8365467: Issues with jrtfs implementation for exploded run-time images #26757
Conversation
* tweaking tests for readability * Address issues and add unit tests
|
👋 Welcome back david-beaumont! A progress list of the required criteria for merging this PR into |
|
@david-beaumont 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 259 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 (@RogerRiggs, @sundararajana, @liach) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
|
@david-beaumont The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
david-beaumont
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding explanatory notes for the non-test changes/fixes.
| private static final int PACKAGES_LEN = PACKAGES.length(); | ||
|
|
||
| private final FileSystem defaultFS; | ||
| private final Path modulesDir; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to make this class actually testable and avoid just using the static field from SystemImage.
| ExplodedImage(Path modulesDir) throws IOException { | ||
| defaultFS = FileSystems.getDefault(); | ||
| String str = defaultFS.getSeparator(); | ||
| this.modulesDir = modulesDir; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid unnecessary assumptions about file systems.
| this.children = children; | ||
| } | ||
|
|
||
| @Override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discovered this method was missing during testing. I think this logic is what's needed here, but I would like someone to just double check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that thumbs up and confirmation that you've checked it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@david-beaumont I think you need to override getLocation if you override isResource so image reader can actually fetch the data - unfortunately this is not clearly documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooooh. That's interesting.
So before, these nodes were none of the types resource, directory or link.
And obviously that was working to an extent.
And you're right that "isResource()" should imply "getResource()" works, but if that's the case, how can a JRT file system be built on top of this at all?
I need to investigate more...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no, there is not, and never was a "getResource()" method on the node class. Nodes are not inner classes and do not have access to the image.
The getResource() method exists (both now and before my changes) on the ExplocedImage class.
So I think what I've done here is correct, and no other changes are necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was the method I saw:
| ImageLocation getLocation() { |
It is package private so we cannot override it here. What is it for at all then...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for getting the location from a Resource node inside the getResource(Node) method.
ExplodedImage nodes just don't use ImageLocation at all, so cannot need it.
getResource(Node) is overloaded on ExplodedImage and the parent method never called.
| try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { | ||
| for (Path p : stream) { | ||
| p = explodedModulesDir.relativize(p); | ||
| p = modulesDir.relativize(p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using static field.
|
|
||
| @Override | ||
| public void close() throws IOException { | ||
| public synchronized void close() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nodes map is always accessed synchronised except here, so by synchronizing this we can stop using ConcurrentHashMap.
| // "nodes" map contains only /modules/<foo> nodes only so far and so add all as children of /modules | ||
| PathNode modulesDir = new PathNode("/modules", new ArrayList<>(nodes.values())); | ||
| nodes.put(modulesDir.getName(), modulesDir); | ||
| PathNode modulesRootNode = new PathNode("/modules", new ArrayList<>(nodes.values())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed because there's already "modulesDir" elsewhere.
| } | ||
|
|
||
| static final String RUNTIME_HOME; | ||
| private static final String RUNTIME_HOME; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hiding these prevents unwanted use by other classes (which would make them effectively untestable).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can still use Method handles and @modules java.base/jdk.internal.jrtfs:+open in JTReg to test these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but anyone who accesses these via method handles deserves all they get (imo).
If these do need to be tested, they can be opened up again. Making them private is taking the temptation to just use them casually away from whoever edits these files next.
| * @modules java.base/jdk.internal.jrtfs java.base/jdk.internal.jimage | ||
| * @run junit/othervm java.base/jdk.internal.jrtfs.ExplodedImageTest | ||
| */ | ||
| public class ExplodedImageTestDriver {} No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not 100% sure if a class declaration is needed here. It seems to work fine, but I've seen a case where there wasn't one (but that felt odd). Happy to remove if not wanted.
| @@ -0,0 +1,4 @@ | |||
| modules = \ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cargo-culted without a true understand of what's going on. This seems to be what's needed for module access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://openjdk.org/jtreg/tag-spec.html#:~:text=@modules%20%5B/,when%20the%20test%20is%20run
modules <module[/package[:flag]]>+
Express a default dependence, for tests in this directory and its subdirectories, on modules in the system being tested, and optionally, on selected internal packages in some or all of those modules.
| * path does not reference a file. | ||
| */ | ||
| Path underlyingModulesPath(String name) { | ||
| if (name.startsWith(MODULES) && name.length() > MODULES.length()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extra length test avoids issues when "/modules/" is given, since that should be invalid but otherwise gets turned into a path to the parent dir.
RogerRiggs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good.
| * @return the newly created and cached node, or {@code null} if the given | ||
| * path references a file which must be hidden in the node hierarchy. | ||
| */ | ||
| Node createModulesNode(String name, Path path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and other methods could be private if not used outside the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There's little consistency in a lot of the access modifiers in the code around here, so I'm defaulting to "don't touch" since I don't know what is, or is not the accepted style. There are lots of other methods here which could/should be private, and it's probably better to raise a PR to go over the entire package and do a sweep for consistency rather than picking these off one-at-a-time.
| */ | ||
| Node createModulesNode(String name, Path path) { | ||
| assert !nodes.containsKey(name) : "Node must not already exist: " + name; | ||
| assert name.startsWith(MODULES) && name.length() > MODULES.length() : "Invalid modules name: " + name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
startsWith(MODUELES) && name.length(...) might be worth a utility method.
Only 2 uses though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
Just some context here. jrtfs has support for exploded images so that it can be used (by javac) in the JDK build. This code is not used once the JDK images are built. It's very likely that some of this code is never executed as javac only uses a subset of the file system API. So good to have tests for this as it would other be untested/unused and bugs will hide until the day that javac expands its usage and hits them. |
sundararajana
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| @@ -0,0 +1,4 @@ | |||
| modules = \ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://openjdk.org/jtreg/tag-spec.html#:~:text=@modules%20%5B/,when%20the%20test%20is%20run
modules <module[/package[:flag]]>+
Express a default dependence, for tests in this directory and its subdirectories, on modules in the system being tested, and optionally, on selected internal packages in some or all of those modules.
|
/integrate |
|
@david-beaumont |
liach
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting changes for the isResource update.
| this.children = children; | ||
| } | ||
|
|
||
| @Override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@david-beaumont I think you need to override getLocation if you override isResource so image reader can actually fetch the data - unfortunately this is not clearly documented.
| } | ||
|
|
||
| static final String RUNTIME_HOME; | ||
| private static final String RUNTIME_HOME; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can still use Method handles and @modules java.base/jdk.internal.jrtfs:+open in JTReg to test these.
RogerRiggs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
|
/integrate |
|
@david-beaumont |
|
/sponsor |
|
Going to push as commit e190355.
Your commit was automatically rebased without conflicts. |
|
@RogerRiggs @david-beaumont Pushed as commit e190355. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This PR addresses several issues found while adding unit tests for ExplodedImage.
I have added review comments for changes (some of which are a little preferential, but bring the code into line with things like ImageReader in terms of the name choices for variables).
Later it is likely that this code will be adapted for the up-coming preview mode support in Valhalla, so having it unit-testable is important.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26757/head:pull/26757$ git checkout pull/26757Update a local copy of the PR:
$ git checkout pull/26757$ git pull https://git.openjdk.org/jdk.git pull/26757/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26757View PR using the GUI difftool:
$ git pr show -t 26757Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26757.diff
Using Webrev
Link to Webrev Comment