Skip to content

Conversation

david-beaumont
Copy link
Contributor

@david-beaumont david-beaumont commented Sep 23, 2025

Java changes for supporting preview mode when preview mode resources (with new location flags) are available.

At the moment, this code will operate on non-preview jimage files (1.0) and act as if no preview resources are available by virtue of the default value for missing attributes and package flags being zero (which matches jimage 1.0).

This should be reviewed on top of #1618


Progress

  • Change must not contain extraneous whitespace

Integration blocker

 ⚠️ Dependency #1618 must be integrated first

Issue

  • JDK-8368333: [lworld] Add preview mode to ImageReader and JRT file-system (Sub-task - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1619

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@david-beaumont
Copy link
Contributor Author

This is a new version of #1613, re-created so there's now a pr/xxx branch for use by dependent PRs.

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 23, 2025

👋 Welcome back david-beaumont! 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

openjdk bot commented Sep 23, 2025

@david-beaumont This change is no longer ready for integration - check the PR body for details.

@openjdk openjdk bot added ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 23, 2025
@david-beaumont david-beaumont changed the base branch from lworld to pr/1618 September 23, 2025 19:22
@mlbridge
Copy link

mlbridge bot commented Sep 23, 2025

Webrevs

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Sep 23, 2025
Comment on lines +39 to +42
* <p>Known jimage file code which needs updating on version change:
* <ul>
* <li>src/java.base/share/native/libjimage/imageFile.hpp
* </ul>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are there any java source files that have to be updated on a version change?

Comment on lines +66 to +72
/**
* Set on all locations in the {@code /modules/xxx/META-INF/preview/...}
* namespace.
*
* <p>This flag is mutually exclusive with {@link #FLAGS_HAS_PREVIEW_VERSION}.
*/
public static final int FLAGS_IS_PREVIEW_VERSION = 0x2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems to be redundant with HAS_PREVIEW_VERSION when seen in a preview location.

Comment on lines +73 to +87
/**
* Indicates that a location only exists due to preview resources.
*
* <p>This can apply to both resources and directories in the
* {@code /modules/xxx/...} namespace, as well as {@code /packages/xxx}
* directories.
*
* <p>For {@code /packages/xxx} directories it indicates that, for every
* module in which the package exists, it is preview only.
*
* <p>This flag is mutually exclusive with {@link #FLAGS_HAS_PREVIEW_VERSION}
* and need not imply that {@link #FLAGS_IS_PREVIEW_VERSION} is set (i.e.
* for {@code /packages/xxx} directories).
*/
public static final int FLAGS_IS_PREVIEW_ONLY = 0x4;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The preview-only case is expected to be the empty set. There seems to be a lot of code dedicated to it.

Comment on lines +103 to +104
* Helper function to calculate preview flags (ATTRIBUTE_PREVIEW_FLAGS).
*
Copy link
Collaborator

Choose a reason for hiding this comment

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

A summary of what gets what flags might be easier to read than the code.
Or list the flags and refer to their descriptions (that would describe the paths where the flags would be found)

Comment on lines +55 to +56
* Indicates that a non-preview location is associated with preview
* resources.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment would read better saying that preview resources exist related to this location.
More like FLAGS_HAS_PREVIEW_VERSION.

Comment on lines +51 to +52
import static jdk.internal.jimage.ImageLocation.FLAGS_HAS_PREVIEW_VERSION;
import static jdk.internal.jimage.ImageLocation.FLAGS_IS_PREVIEW_ONLY;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Import utility methods not flags.

Comment on lines +558 to +559
return ensureCachedIfNonNull(
loc != null && loc.getType() == RESOURCE ? newResource(name, loc) : null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems odd to test loc and type to produce a null and them pass it to a method that will do nothing.
The non-productive test can be done and return immediately.

Comment on lines +121 to 125
if (envValue instanceof Boolean && (Boolean) envValue) {
return PreviewMode.ENABLED;
} else if (envValue instanceof String && Boolean.parseBoolean((String) envValue)) {
return PreviewMode.ENABLED;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This kind of ambiguous type for the environment variable should not be supported.
Pick a type and stick to it.
Whereever the jrt: file system is specified will need a description for enablePreview to be added to the spec.

Comment on lines +78 to +79
// TODO: Maybe throw if enablePreview attempted for exploded image?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Exploded image is useful for debugging, it could support preview mode using the same META-INF directory structure.

}

// Encodes strings sequentially starting from index 100.
private static Function<String, Integer> testEncoder() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The method name testEncoder gives the impression of being a test, but it is just a utility function used by a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

2 participants