[lworld] RFR: 8372515: [lworld] Plumb in javac flags for compiling with preview mode [v2]
Roger Riggs
rriggs at openjdk.org
Wed Nov 26 21:29:29 UTC 2025
On Tue, 25 Nov 2025 15:57:56 GMT, David Beaumont <duke at openjdk.org> wrote:
>> Plumbing for javac flags, mostly inspired by/copied from test commits made by @lahodaj .
>>
>> There are several things here, mostly entangled, so it's a bit tricky to try splitting this out, but it would be possible if people wanted.
>>
>> The biggest "refactoing" part of this PR is "src/jdk.compiler/share/classes/com/sun/tools/javac/file/JRTIndex.java" which now has a properly controlled lifecycle and disposed its resources correctly. Prior to this, the class used a non-closeable JRT file-system reference, which leads to "persistent open file" issues such as JDK-8357249.
>>
>> This *does* mean that if compilation and the runtime have the same preview mode, then a 2nd JRT file system to the same jimage file is "opened", *but* the file system itself is lightweight, non-caching and both of them will use the underlying SharedImageReader (which is where nodes are cached etc.) so it really shouldn't be an issue (I will make sure javac benchmarks are checked however).
>>
>> The benefit of this is that now, the shared index (which does do some caching) is correctly tracked across all users, and will be closed when the last user closes the lightweight wrapper instance.
>>
>> A lot of the smaller "spot fix" changes in this PR were just copied by me, or at least inspired directly by Jan's work, so I may have missed some semantic subtlety in the code I'm not familiar with. Please evaluate that carefully.
>
> David Beaumont has updated the pull request incrementally with one additional commit since the last revision:
>
> Remove note about StableValue (not possible)
src/jdk.compiler/share/classes/com/sun/tools/javac/file/JRTIndex.java line 59:
> 57: */
> 58: public class JRTIndex implements Closeable {
> 59: public static JRTIndex getInstance(boolean previewMode) {
Generally, we (core-libs) have been dropping the "get" prefix on accessors; so there's no need to change the name of the method back to an older pattern.
src/jdk.compiler/share/classes/com/sun/tools/javac/file/JRTIndex.java line 305:
> 303: }
> 304:
> 305: private final FileSystemResources sharedResources;
The fields of JRTIndex should be at the top of the class.
Fields, constructors, static methods, the rest.
There's some debate about where nested classes go (I say at the end).
test/langtools/tools/javac/preview/PreviewJRTImage.java line 85:
> 83: for (String option : new String[]{"--source", "--release"}) {
> 84: for (Mode mode : new Mode[]{Mode.API, Mode.CMDLINE}) {
> 85: //without preview:
Space after //; here and below
-------------
PR Review Comment: https://git.openjdk.org/valhalla/pull/1761#discussion_r2566317316
PR Review Comment: https://git.openjdk.org/valhalla/pull/1761#discussion_r2566328294
PR Review Comment: https://git.openjdk.org/valhalla/pull/1761#discussion_r2566531466
More information about the valhalla-dev
mailing list