On Wed, 22 Apr 2026 12:04:02 GMT, David Beaumont <[email protected]> wrote:
>> Implementation of preview-mode support for jimage modules file, migrated >> from Valhalla related work (see JDK-8352750). >> >> This PR (the first of several) migrates work from Valhalla (lworld) to the >> JDK mainline repository in relation to "preview mode" support. It affects >> the creation and reading of the jimage file, both in Java >> (BasicImageReader/ImageReader) and C++ (imageFile.xpp/jimage.xpp). >> >> Preview mode is a mechanism by which alternate version of JDK class files >> and resources can be made available for class loading and reflection when >> the '--enable-preview' flag is passed to the runtime. >> >> Alternate classes/resource appear in each module under the: >> >> /<module>/META-INF/preview/<path-to>/<resource-or-class> >> >> and replace the original: >> >> /<module>/<path-to>/<resource-or-class> >> >> files when preview mode is enabled. >> >> While initially useful for Valhalla work, this mechanism will be used for >> other cases where preview features (in the JEP 12 sense) require alternate >> classes/resources to be provided. None of the changes in this (or the >> follow-up PRs) are Valhalla specific. >> >> In this PR: >> * the writing of jimage files is modified to recognize and handle preview >> mode paths >> * flags in the jimage file are added or modified to support preview mode >> efficiently >> * (C++) the class loader is modified to permit reading preview versions of >> classes >> * (Java) the image reader and associated JRT file-system classes are >> modified to permit reading preview files >> * unit tests are added to ensure preview mode works as expected when enabled >> * (temporary) any code calling into the affected API (other than tests) >> specifies that preview mode is disabled >> >> Future PRs will add the plumbing to enable preview mode correctly, but with >> the PR there should be no observable change in behaviour (especially since >> no preview classes or resources are being supplied at this point). >> >> --------- >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > David Beaumont has updated the pull request incrementally with one additional > commit since the last revision: > > Fix issue with resource lookup in ImageReader test/jdk/tools/jlink/JLinkPreviewTest.java line 60: > 58: * @run junit/othervm JLinkPreviewTest > 59: */ > 60: public class JLinkPreviewTest { I needed this additional hunk for the test to work on linkable runtimes: diff --git a/test/jdk/tools/jlink/JLinkPreviewTest.java b/test/jdk/tools/jlink/JLinkPreviewTest.java index fcaa7493f07..d263c1ad972 100644 --- a/test/jdk/tools/jlink/JLinkPreviewTest.java +++ b/test/jdk/tools/jlink/JLinkPreviewTest.java @@ -55,6 +55,7 @@ * tests.* * @modules jdk.jlink/jdk.tools.jimage * jdk.jlink/jdk.tools.jlink.internal + * java.base/jdk.internal.jimage * @run junit/othervm JLinkPreviewTest */ public class JLinkPreviewTest { Compilation of the test fails otherwise with: /disk/openjdk/upstream-sources/git/jdk-jdk/test/jdk/tools/lib/tests/JImageValidator.java:37: error: package jdk.internal.jimage is not visible import jdk.internal.jimage.BasicImageReader; ^ (package jdk.internal.jimage is declared in module java.base, which does not export it to the unnamed module) /disk/openjdk/upstream-sources/git/jdk-jdk/test/jdk/tools/lib/tests/JImageValidator.java:38: error: package jdk.internal.jimage is not visible import jdk.internal.jimage.ImageLocation; ^ (package jdk.internal.jimage is declared in module java.base, which does not export it to the unnamed module) 2 errors TEST RESULT: Failed. Compilation failed: Compilation failed -------------------------------------------------- ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/29414#discussion_r3136533277
