[lworld] RFR: 8368467: [lworld] Add new flag generation for jimage to support preview mode
David Beaumont
duke at openjdk.org
Tue Nov 4 17:21:17 UTC 2025
On Tue, 4 Nov 2025 17:08:45 GMT, David Beaumont <duke at openjdk.org> wrote:
> Adds support for writing preview related flags into jimage files.
>
> Preview mode is complex. It's not nearly as simple as "does something in /modules/xxx/... have an entry in /modules/xxx/META-INF/preview/...".
>
> Specific issues include:
>
> Supporting preview-only resources without forcing a double lookup on everything.
> Changing the set of entries in /packages/xxx directories to account for preview only packages in some modules.
> Minimising the work done during image reader initialization to only need to process the small number of preview resources (rather than scanning the whole file to look for them).
> The new flags added by this code address these issues, but calculating them correctly with only minor adjustments to the existing code was not feasible, it just became a lot larger and very complex.
>
> To address this, a new type (ModuleReference) is introduced to track and then merge information about packages seen in each module. This allows a much simpler inner loop for processing resource paths when building the node tree, combined with a subsequent merging stage to produce the final package information for each module.
>
> Not that since ModuleReference is needed during jimage reading, that class is already present in the previous PR on which this is based, but it starts to be used to calculate the module flags in this PR.
>
> This PR can also adds the ImageReader unit tests for preview mode, which rely on being able to generate jimage files with preview mode flags in.
src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageResourcesTree.java line 393:
> 391: ByteBuffer byteBuffer = ByteBuffer.allocate(8 * refs.size());
> 392: byteBuffer.order(writer.getByteOrder());
> 393: ModuleReference.write(refs, byteBuffer.asIntBuffer(), writer::addString);
By letting the ModuleReference helper do the writing, the calculation of package entry flags is completely hidden so nothing can be confused with image location flags.
test/jdk/jdk/internal/jimage/ImageLocationTest.java line 1:
> 1: /*
Probably more ImageLocation tests could be written for existing functionality, but that something someone could add later. At least the preview flag stuff is tested now.
test/jdk/jdk/internal/jimage/ImageReaderTest.java line 1:
> 1: /*
Now we've got the code to do the jimage writing, we can add tests for the preview flags.
-------------
PR Review Comment: https://git.openjdk.org/valhalla/pull/1718#discussion_r2491391198
PR Review Comment: https://git.openjdk.org/valhalla/pull/1718#discussion_r2491405512
PR Review Comment: https://git.openjdk.org/valhalla/pull/1718#discussion_r2491397325
More information about the valhalla-dev
mailing list