Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,7 @@ public LocationType getType() {
case ImageStrings.EMPTY_STRING_OFFSET:
// Only 2 choices, either the "/modules" or "/packages" root.
assert isRootDir() : "Invalid root directory: " + getFullName();

// Temporary logic to handle package root classification until new
// image reader code is committed which sets FLAGS_IS_PACKAGE_ROOT.
// Base name is "/packages" or "/modules" (NOT "packages" and "modules").
// TODO: Uncomment the FLAGS_IS_PACKAGE_ROOT test below.
// return (getFlags() & FLAGS_IS_PACKAGE_ROOT) != 0
return getBase().charAt(1) == 'p'
return (getFlags() & FLAGS_IS_PACKAGE_ROOT) != 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Introducing a flag bit that is carried around in lots of entries but applies to only one is overkill.
The simple test above for the first letter is cleaner and very localized.

? LocationType.PACKAGES_ROOT
: LocationType.MODULES_ROOT;
default:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@
* to the jimage file provided by the shipped JDK by tools running on JDK 8.
*/
public final class ModuleReference implements Comparable<ModuleReference> {
// The following flags are designed to be additive (hence "has-resources"
// rather than "is-empty", even though "isEmpty()" is whats in the API).
// API methods like "isEmpty()" and "hasPreviewVersion()" are designed to
// match the semantics of ImageLocation flags to avoid having business
// logic need to reason about two different flag regimes.
// The following flags are designed to be additive.

/** If set, the associated module has resources (in normal or preview mode). */
private static final int FLAGS_HAS_CONTENT = 0x1;
Expand Down Expand Up @@ -192,14 +188,7 @@ public static Iterator<Integer> readNameOffsets(
int nextIdx(int idx) {
for (; idx < bufferSize; idx += 2) {
// If any of the test flags are set, include this entry.

// Temporarily allow for *neither* flag to be set. This is what would
// be written by a 1.0 version of the jimage flag, and indicates a
// normal resource without a preview version.
// TODO: Remove the zero-check below once image writer code is updated.
int previewFlags =
buffer.get(idx) & (FLAGS_HAS_NORMAL_VERSION | FLAGS_HAS_PREVIEW_VERSION);
if (previewFlags == 0 || (previewFlags & testFlags) != 0) {
if ((buffer.get(idx) & testFlags) != 0) {
return idx;
} else if (!includeNormal) {
// Preview entries are first in the offset buffer, so we
Expand Down
14 changes: 13 additions & 1 deletion src/java.base/share/classes/jdk/internal/jimage/PreviewMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ boolean resolve() {
ENABLED() {
@Override
boolean resolve() {
return true;
return ENABLE_PREVIEW_MODE;
}
},
/**
Expand All @@ -63,6 +63,9 @@ boolean resolve() {
FOR_RUNTIME() {
@Override
boolean resolve() {
if (!ENABLE_PREVIEW_MODE) {
return false;
}
Comment on lines +66 to +68
Copy link
Collaborator

Choose a reason for hiding this comment

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

As commented in the 1618 PR, the extra subclasses caused by the overrides can be replaced by the resolve method switching on ordinal().

// We want to call jdk.internal.misc.PreviewFeatures.isEnabled(), but
// is not available in older JREs, so we must look to it reflectively.
Class<?> clazz;
Expand All @@ -81,6 +84,15 @@ boolean resolve() {
}
};

// Temporary system property to disable preview patching and enable the new preview mode
// feature for testing/development. Once the preview mode feature is finished, the value
// will be always 'true' and this code, and all related dead-code can be removed.
private static final boolean DISABLE_PREVIEW_PATCHING_DEFAULT = false;
private static final boolean ENABLE_PREVIEW_MODE = Boolean.parseBoolean(
System.getProperty(
"DISABLE_PREVIEW_PATCHING",
Boolean.toString(DISABLE_PREVIEW_PATCHING_DEFAULT)));

/**
* Resolves whether preview mode should be enabled for an {@link ImageReader}.
*/
Expand Down
7 changes: 1 addition & 6 deletions src/java.base/share/native/libjimage/imageFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,7 @@ bool ImageFileReader::open() {
!read_at((u1*)&_header, header_size, 0) ||
_header.magic(_endian) != IMAGE_MAGIC ||
_header.major_version(_endian) != MAJOR_VERSION ||
// Temporarily, we allow either version (1.1 or 1.0) of the file to
// be read so this code can be committed before image writing changes
// for preview mode. Preview mode changes do not modify any structure,
// so a 1.0 file will look like a jimage without any preview resources.
// TODO: Restore equality check for MINOR_VERSION.
_header.minor_version(_endian) > MINOR_VERSION) {
_header.minor_version(_endian) != MINOR_VERSION) {
close();
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -76,10 +76,10 @@ public String getString(int offset) {
}

public void addLocation(String fullname, long contentOffset,
long compressedSize, long uncompressedSize) {
long compressedSize, long uncompressedSize, int previewFlags) {
ImageLocationWriter location =
ImageLocationWriter.newLocation(fullname, strings,
contentOffset, compressedSize, uncompressedSize);
contentOffset, compressedSize, uncompressedSize, previewFlags);
input.add(location);
length++;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -49,6 +49,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import jdk.internal.jimage.ImageLocation;
import jdk.tools.jlink.internal.Archive.Entry;
import jdk.tools.jlink.internal.Archive.Entry.EntryType;
import jdk.tools.jlink.internal.JRTArchive.ResourceFileEntry;
Expand Down Expand Up @@ -227,31 +228,8 @@ private static ResourcePool generateJImage(ResourcePoolManager allContent,
DataOutputStream out,
boolean generateRuntimeImage
) throws IOException {
ResourcePool resultResources;
try {
resultResources = pluginSupport.visitResources(allContent);
if (generateRuntimeImage) {
// Keep track of non-modules resources for linking from a run-time image
resultResources = addNonClassResourcesTrackFiles(resultResources,
writer);
// Generate the diff between the input resources from packaged
// modules in 'allContent' to the plugin- or otherwise
// generated-content in 'resultResources'
resultResources = addResourceDiffFiles(allContent.resourcePool(),
resultResources,
writer);
}
} catch (PluginException pe) {
if (JlinkTask.DEBUG) {
pe.printStackTrace();
}
throw pe;
} catch (Exception ex) {
if (JlinkTask.DEBUG) {
ex.printStackTrace();
}
throw new IOException(ex);
}
ResourcePool resultResources =
getResourcePool(allContent, writer, pluginSupport, generateRuntimeImage);
Set<String> duplicates = new HashSet<>();
long[] offset = new long[1];

Expand Down Expand Up @@ -282,8 +260,10 @@ private static ResourcePool generateJImage(ResourcePoolManager allContent,
offset[0] += onFileSize;
return;
}
int locFlags = ImageLocation.getFlags(
res.path(), p -> resultResources.findEntry(p).isPresent());
duplicates.add(path);
writer.addLocation(path, offset[0], compressedSize, uncompressedSize);
writer.addLocation(path, offset[0], compressedSize, uncompressedSize, locFlags);
paths.add(path);
offset[0] += onFileSize;
}
Expand All @@ -307,6 +287,40 @@ private static ResourcePool generateJImage(ResourcePoolManager allContent,
return resultResources;
}

private static ResourcePool getResourcePool(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pulled out so the variable holding it is effectively final and can be used in a lambda expression.

ResourcePoolManager allContent,
BasicImageWriter writer,
ImagePluginStack pluginSupport,
boolean generateRuntimeImage)
throws IOException {
ResourcePool resultResources;
try {
resultResources = pluginSupport.visitResources(allContent);
if (generateRuntimeImage) {
// Keep track of non-modules resources for linking from a run-time image
resultResources = addNonClassResourcesTrackFiles(resultResources,
writer);
// Generate the diff between the input resources from packaged
// modules in 'allContent' to the plugin- or otherwise
// generated-content in 'resultResources'
resultResources = addResourceDiffFiles(allContent.resourcePool(),
resultResources,
writer);
}
} catch (PluginException pe) {
if (JlinkTask.DEBUG) {
pe.printStackTrace();
}
throw pe;
} catch (Exception ex) {
if (JlinkTask.DEBUG) {
ex.printStackTrace();
}
throw new IOException(ex);
}
return resultResources;
}

/**
* Support for creating a runtime suitable for linking from the run-time
* image.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -54,8 +54,8 @@ private ImageLocationWriter addAttribute(int kind, String value) {
}

static ImageLocationWriter newLocation(String fullName,
ImageStringsWriter strings,
long contentOffset, long compressedSize, long uncompressedSize) {
ImageStringsWriter strings,
long contentOffset, long compressedSize, long uncompressedSize, int previewFlags) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wrap or untab to avoid long lines.

String moduleName = "";
String parentName = "";
String baseName;
Expand Down Expand Up @@ -90,13 +90,14 @@ static ImageLocationWriter newLocation(String fullName,
}

return new ImageLocationWriter(strings)
.addAttribute(ATTRIBUTE_MODULE, moduleName)
.addAttribute(ATTRIBUTE_PARENT, parentName)
.addAttribute(ATTRIBUTE_BASE, baseName)
.addAttribute(ATTRIBUTE_EXTENSION, extensionName)
.addAttribute(ATTRIBUTE_OFFSET, contentOffset)
.addAttribute(ATTRIBUTE_COMPRESSED, compressedSize)
.addAttribute(ATTRIBUTE_UNCOMPRESSED, uncompressedSize);
.addAttribute(ATTRIBUTE_MODULE, moduleName)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This got reformatted correctly to 8 indent because of the new entry.

.addAttribute(ATTRIBUTE_PARENT, parentName)
.addAttribute(ATTRIBUTE_BASE, baseName)
.addAttribute(ATTRIBUTE_EXTENSION, extensionName)
.addAttribute(ATTRIBUTE_OFFSET, contentOffset)
.addAttribute(ATTRIBUTE_COMPRESSED, compressedSize)
.addAttribute(ATTRIBUTE_UNCOMPRESSED, uncompressedSize)
.addAttribute(ATTRIBUTE_PREVIEW_FLAGS, previewFlags);
}

@Override
Expand Down
Loading