Skip to content

Alt preview mode#30718

Draft
david-beaumont wants to merge 16 commits intoopenjdk:masterfrom
david-beaumont:alt_preview_mode
Draft

Alt preview mode#30718
david-beaumont wants to merge 16 commits intoopenjdk:masterfrom
david-beaumont:alt_preview_mode

Conversation

@david-beaumont
Copy link
Copy Markdown
Contributor

@david-beaumont david-beaumont commented Apr 14, 2026

Alternate preview flags prototype.



Progress

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

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30718

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30718.diff

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Apr 14, 2026

👋 Welcome back dbeaumont! A progress list of the required criteria for merging this PR into master 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 Apr 14, 2026

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added hotspot-runtime hotspot-runtime-dev@openjdk.org core-libs core-libs-dev@openjdk.org net net-dev@openjdk.org labels Apr 14, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 14, 2026

@david-beaumont The following labels will be automatically applied to this pull request:

  • core-libs
  • hotspot-runtime
  • net

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

if (name.startsWith(PACKAGES_PREFIX + "/")) {
throw new IllegalArgumentException(
"Package sub-directory flags handled separately: " + name);
// '/packages/xxx' entries have flags, but not calculated here.
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.

Not an error now, return zero to leave packages flags alone though.

return attributes;
}

public static byte[] compress(long[] attributes) {
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.

Moved from parent class (it's only used here).

}
// Jimage cannot encode resources where the module name is "modules" or "packages".
// Module names should only come from Module instances or other trusted sources.
#ifdef ASSERT
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.

Frustrating need for ifdef to avoid compilation failure due to unused consts.

}

public void addLocation(
public ImageLocationWriter addLocation(
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.

Returned so we can add the package flags early (special case).

}
}

private void generateLocationFlags() {
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.

This replaces the 2 calls (I can also tidy the API to pass the keySet instead of a predicate if desired).

res.path(), p -> resultResources.findEntry(p).isPresent());
duplicates.add(path);
writer.addLocation(path, offset[0], compressedSize, uncompressedSize, locFlags);
writer.addLocation(path, offset[0], compressedSize, uncompressedSize);
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.

This gets slightly simpler in this version.

.addAttribute(ATTRIBUTE_OFFSET, contentOffset)
.addAttribute(ATTRIBUTE_COMPRESSED, compressedSize)
.addAttribute(ATTRIBUTE_UNCOMPRESSED, uncompressedSize)
.addAttribute(ATTRIBUTE_PREVIEW_FLAGS, previewFlags);
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.

No longer set flags during init. I think this is a weakness of the change because there's no longer a forcing function and now code code accidentally fail to set values. This is, however, quite well tested.

static final class Tree {
private static final String PREVIEW_PREFIX = "META-INF/preview/";

private final Map<String, Node> directAccess = new HashMap<>();
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.

This name has always been confusing, I finally realized that "direct" means "directory", not "direct".

// Flags are more complex to calculate than other cases, so do them
// early (the other flags are calculated in the writer itself).
ImageLocationWriter location = writer.addLocation(current.getPath(), offset, 0, size);
location.addAttribute(ATTRIBUTE_PREVIEW_FLAGS, ImageLocation.getPackageFlags(links));
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.

This is the "sore thumb" of this change. We need to return the writer from addLocation() so we can poke the package flags in here, because it's hard to generate them after this point.

// Normal directory entries have 4-byte entries (offset only).
int size = ret.length * 4;
writer.addLocation(current.getPath(), offset, 0, size, locFlags);
writer.addLocation(current.getPath(), offset, 0, size);
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.

Slightly simpler in this change.

}

private ImageLocationWriter addAttribute(int kind, long value) {
private static byte[] compress(long[] attributes) {
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.

The moved method from the parent class (which never needs it).

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

Labels

core-libs core-libs-dev@openjdk.org hotspot-runtime hotspot-runtime-dev@openjdk.org net net-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

1 participant