From 07812b873e1b0761afb6954651811d9d572eb86f Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 4 Jun 2025 16:02:03 +0200 Subject: [PATCH 1/6] svm: move FileSystemProviderSupport to buildtimeinit --- .../com/oracle/svm/core/jdk/JRTSupport.java | 2 +- ...leSystemProviderBuildTimeInitSupport.java} | 36 +++++++++++++------ .../core/jdk/buildtimeinit/package-info.java | 34 ++++++++++++++++++ .../FileSystemProviderRuntimeInitSupport.java | 9 ++--- .../svm/hosted/webimage/WebImageFeature.java | 4 +-- 5 files changed, 67 insertions(+), 18 deletions(-) rename substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/{FileSystemProviderSupport.java => buildtimeinit/FileSystemProviderBuildTimeInitSupport.java} (92%) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/package-info.java diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JRTSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JRTSupport.java index 55f9ce289a4d..712eff9d3cf9 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JRTSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JRTSupport.java @@ -62,7 +62,7 @@ */ public final class JRTSupport { - static class Options { + public static class Options { @Option(help = "Enable support for reading Java modules (jimage format) and the jrt:// file system. Requires java.home to be set at runtime.", type = OptionType.Expert) // public static final HostedOptionKey AllowJRTFileSystem = new HostedOptionKey<>(false); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/FileSystemProviderSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java similarity index 92% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/FileSystemProviderSupport.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java index a1ffb6f9d56e..867e05ebac66 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/FileSystemProviderSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java @@ -23,7 +23,7 @@ * questions. */ -package com.oracle.svm.core.jdk; +package com.oracle.svm.core.jdk.buildtimeinit; import java.nio.file.spi.FileSystemProvider; import java.util.ArrayList; @@ -45,6 +45,10 @@ import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.core.feature.InternalFeature; +import com.oracle.svm.core.jdk.JDKInitializedAtBuildTime; +import com.oracle.svm.core.jdk.JRTSupport; +import com.oracle.svm.core.jdk.SystemPropertiesSupport; +import com.oracle.svm.core.jdk.UserSystemProperty; import com.oracle.svm.core.option.HostedOptionKey; import com.oracle.svm.core.util.BasedOnJDKFile; import com.oracle.svm.core.util.VMError; @@ -52,7 +56,16 @@ import jdk.graal.compiler.options.Option; import jdk.internal.util.StaticProperty; -public final class FileSystemProviderSupport { +/** + * This file contains substitutions that are required for initializing {@link FileSystemProvider} at + * image {@linkplain JDKInitializedAtBuildTime build time}. Other related functionality (general and + * run-time initialization) can be found in + * {@link com.oracle.svm.core.jdk.runtimeinit.FileSystemProviderRuntimeInitSupport}. + * + * @see JDKInitializedAtBuildTime + * @see com.oracle.svm.core.jdk.runtimeinit.FileSystemProviderRuntimeInitSupport + */ +public final class FileSystemProviderBuildTimeInitSupport { public static class Options { @Option(help = "Make all supported providers returned by FileSystemProvider.installedProviders() available at run time.")// @@ -63,7 +76,7 @@ public static class Options { final List installedProvidersImmutable; @Platforms(Platform.HOSTED_ONLY.class) - FileSystemProviderSupport(List installedProviders) { + FileSystemProviderBuildTimeInitSupport(List installedProviders) { this.installedProvidersMutable = installedProviders; this.installedProvidersImmutable = Collections.unmodifiableList(installedProviders); } @@ -75,7 +88,7 @@ public static class Options { */ @Platforms(Platform.HOSTED_ONLY.class) public static void register(FileSystemProvider provider) { - List installedProviders = ImageSingletons.lookup(FileSystemProviderSupport.class).installedProvidersMutable; + List installedProviders = ImageSingletons.lookup(FileSystemProviderBuildTimeInitSupport.class).installedProvidersMutable; String scheme = provider.getScheme(); for (int i = 0; i < installedProviders.size(); i++) { @@ -98,7 +111,7 @@ public static void register(FileSystemProvider provider) { */ @Platforms(Platform.HOSTED_ONLY.class) public static void remove(String scheme) { - List installedProviders = ImageSingletons.lookup(FileSystemProviderSupport.class).installedProvidersMutable; + List installedProviders = ImageSingletons.lookup(FileSystemProviderBuildTimeInitSupport.class).installedProvidersMutable; for (int i = 0; i < installedProviders.size(); i++) { /* @@ -115,12 +128,12 @@ public static void remove(String scheme) { } @AutomaticallyRegisteredFeature -final class FileSystemProviderFeature implements InternalFeature { +final class FileSystemProviderBuildTimeInitFeature implements InternalFeature { @Override public void afterRegistration(AfterRegistrationAccess access) { List installedProviders = new ArrayList<>(); - if (FileSystemProviderSupport.Options.AddAllFileSystemProviders.getValue()) { + if (FileSystemProviderBuildTimeInitSupport.Options.AddAllFileSystemProviders.getValue()) { /* * The first invocation of FileSystemProvider.installedProviders() causes the default * provider to be initialized (if not already initialized) and loads any other installed @@ -133,11 +146,11 @@ public void afterRegistration(AfterRegistrationAccess access) { */ installedProviders.addAll(FileSystemProvider.installedProviders()); } - ImageSingletons.add(FileSystemProviderSupport.class, new FileSystemProviderSupport(installedProviders)); + ImageSingletons.add(FileSystemProviderBuildTimeInitSupport.class, new FileSystemProviderBuildTimeInitSupport(installedProviders)); /* Access to Java modules (jimage/jrtfs access) in images is experimental. */ if (!JRTSupport.Options.AllowJRTFileSystem.getValue()) { - FileSystemProviderSupport.remove("jrt"); + FileSystemProviderBuildTimeInitSupport.remove("jrt"); } } } @@ -146,7 +159,7 @@ public void afterRegistration(AfterRegistrationAccess access) { final class Target_java_nio_file_spi_FileSystemProvider { @Substitute public static List installedProviders() { - return ImageSingletons.lookup(FileSystemProviderSupport.class).installedProvidersImmutable; + return ImageSingletons.lookup(FileSystemProviderBuildTimeInitSupport.class).installedProvidersImmutable; } } @@ -160,7 +173,8 @@ public static List installedProviders() { * * a) Disallow UnixFileSystem and UnixFileSystemProvider in the image heap, i.e., create all * instances at run time. This is undesirable because then all file system providers need to be - * loaded at run time, i.e., the caching in {@link FileSystemProviderSupport} would no longer work. + * loaded at run time, i.e., the caching in {@link FileSystemProviderBuildTimeInitSupport} would no + * longer work. * * b) Disallow UnixFileSystem in the image heap, but have the UnixFileSystemProvider instance in the * image heap. This requires a recomputation of the field UnixFileSystemProvider.theFileSystem at diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/package-info.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/package-info.java new file mode 100644 index 000000000000..ad39a4773e8d --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/package-info.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * This package contains "legacy" substitutions and features that are required to support + * initializing certain parts of the JDK at image + * {@linkplain com.oracle.svm.core.jdk.JDKInitializedAtBuildTime build time}. Those parts of the JDK + * are planned to be initialized at {@linkplain com.oracle.svm.core.jdk.JDKInitializedAtRunTime run + * time} in the {@linkplain com.oracle.svm.core.FutureDefaultsOptions future}. Once run time + * initialization is the default, this package will be removed. + */ +package com.oracle.svm.core.jdk.buildtimeinit; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/runtimeinit/FileSystemProviderRuntimeInitSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/runtimeinit/FileSystemProviderRuntimeInitSupport.java index a1190a1c48ea..8bf659d2bddf 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/runtimeinit/FileSystemProviderRuntimeInitSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/runtimeinit/FileSystemProviderRuntimeInitSupport.java @@ -40,6 +40,7 @@ import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.core.feature.InternalFeature; import com.oracle.svm.core.jdk.JDKInitializedAtRunTime; +import com.oracle.svm.core.jdk.buildtimeinit.FileSystemProviderBuildTimeInitSupport; import com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystemProvider; import com.oracle.svm.core.util.BasedOnJDKFile; import com.oracle.svm.core.util.VMError; @@ -47,13 +48,13 @@ /** * This file contains substitutions that are required for initializing {@link FileSystemProvider} at - * image run time. Other related functionality (general and build time initialization) can be found - * in {@link com.oracle.svm.core.jdk.FileSystemProviderSupport}. + * image {@linkplain JDKInitializedAtRunTime run time}. Other related functionality (general and + * build time initialization) can be found in {@link FileSystemProviderBuildTimeInitSupport}. * * @see JDKInitializedAtRunTime - * @see com.oracle.svm.core.jdk.FileSystemProviderSupport + * @see FileSystemProviderBuildTimeInitSupport */ -final class FileSystemProviderRuntimeInitSupport { +public final class FileSystemProviderRuntimeInitSupport { } @AutomaticallyRegisteredFeature diff --git a/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/WebImageFeature.java b/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/WebImageFeature.java index b13b31659381..f0a18cb6d1ee 100644 --- a/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/WebImageFeature.java +++ b/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/WebImageFeature.java @@ -70,10 +70,10 @@ import com.oracle.svm.core.heap.RestrictHeapAccessCallees; import com.oracle.svm.core.hub.DynamicHub; import com.oracle.svm.core.hub.DynamicHubCompanion; -import com.oracle.svm.core.jdk.FileSystemProviderSupport; import com.oracle.svm.core.jdk.PlatformNativeLibrarySupport; import com.oracle.svm.core.jdk.SystemInOutErrSupport; import com.oracle.svm.core.jdk.SystemPropertiesSupport; +import com.oracle.svm.core.jdk.buildtimeinit.FileSystemProviderBuildTimeInitSupport; import com.oracle.svm.core.log.Log; import com.oracle.svm.core.option.HostedOptionValues; import com.oracle.svm.core.util.VMError; @@ -323,7 +323,7 @@ public void afterRegistration(AfterRegistrationAccess access) { * Registers our own file system provider, which replaces the default provider for the * 'file' scheme. */ - FileSystemProviderSupport.register(WebImageNIOFileSystemProvider.INSTANCE); + FileSystemProviderBuildTimeInitSupport.register(WebImageNIOFileSystemProvider.INSTANCE); } @Override From 9776a2e59680798aa7863beab3392e8d044dd1e4 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 4 Jun 2025 16:22:33 +0200 Subject: [PATCH 2/6] svm: FileSystemProviderBuildTimeInitSupport add _BuildTime suffix to substitutions --- ...ileSystemProviderBuildTimeInitSupport.java | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java index 867e05ebac66..d35090c0e371 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java @@ -156,7 +156,7 @@ public void afterRegistration(AfterRegistrationAccess access) { } @TargetClass(value = java.nio.file.spi.FileSystemProvider.class, onlyWith = JDKInitializedAtBuildTime.class) -final class Target_java_nio_file_spi_FileSystemProvider { +final class Target_java_nio_file_spi_FileSystemProvider_BuildTime { @Substitute public static List installedProviders() { return ImageSingletons.lookup(FileSystemProviderBuildTimeInitSupport.class).installedProvidersImmutable; @@ -187,10 +187,10 @@ public static List installedProviders() { */ @TargetClass(className = "sun.nio.fs.UnixFileSystem", onlyWith = JDKInitializedAtBuildTime.class) @Platforms({Platform.LINUX.class, Platform.DARWIN.class}) -final class Target_sun_nio_fs_UnixFileSystem { +final class Target_sun_nio_fs_UnixFileSystem_BuildTime { @Alias // - Target_sun_nio_fs_UnixFileSystemProvider provider; + Target_sun_nio_fs_UnixFileSystemProvider_BuildTime provider; /* * All fields of UnixFileSystem that contain state. At this point, the subclasses @@ -207,7 +207,7 @@ final class Target_sun_nio_fs_UnixFileSystem { private boolean needToResolveAgainstDefaultDirectory; @Alias // @InjectAccessors(UnixFileSystemAccessors.class) // - private Target_sun_nio_fs_UnixPath rootDirectory; + private Target_sun_nio_fs_UnixPath_BuildTime rootDirectory; /** * Flag to check if reinitialization at run time is needed. For objects in the image heap, this @@ -231,21 +231,21 @@ final class Target_sun_nio_fs_UnixFileSystem { boolean injectedNeedToResolveAgainstDefaultDirectory; @Inject // @RecomputeFieldValue(kind = Kind.Reset)// - Target_sun_nio_fs_UnixPath injectedRootDirectory; + Target_sun_nio_fs_UnixPath_BuildTime injectedRootDirectory; @Alias @TargetElement(name = TargetElement.CONSTRUCTOR_NAME) - native void originalConstructor(Target_sun_nio_fs_UnixFileSystemProvider p, String dir); + native void originalConstructor(Target_sun_nio_fs_UnixFileSystemProvider_BuildTime p, String dir); } @TargetClass(className = "sun.nio.fs.UnixFileSystemProvider", onlyWith = JDKInitializedAtBuildTime.class) @Platforms({Platform.LINUX.class, Platform.DARWIN.class}) -final class Target_sun_nio_fs_UnixFileSystemProvider { +final class Target_sun_nio_fs_UnixFileSystemProvider_BuildTime { } @TargetClass(className = "sun.nio.fs.UnixPath", onlyWith = JDKInitializedAtBuildTime.class) @Platforms({Platform.LINUX.class, Platform.DARWIN.class}) -final class Target_sun_nio_fs_UnixPath { +final class Target_sun_nio_fs_UnixPath_BuildTime { } class NeedsReinitializationProvider implements FieldValueTransformer { @@ -271,21 +271,21 @@ class UnixFileSystemAccessors { * first access of any of the fields. */ - static byte[] getDefaultDirectory(Target_sun_nio_fs_UnixFileSystem that) { + static byte[] getDefaultDirectory(Target_sun_nio_fs_UnixFileSystem_BuildTime that) { if (that.needsReinitialization != NeedsReinitializationProvider.STATUS_REINITIALIZED) { reinitialize(that); } return that.injectedDefaultDirectory; } - static boolean getNeedToResolveAgainstDefaultDirectory(Target_sun_nio_fs_UnixFileSystem that) { + static boolean getNeedToResolveAgainstDefaultDirectory(Target_sun_nio_fs_UnixFileSystem_BuildTime that) { if (that.needsReinitialization != NeedsReinitializationProvider.STATUS_REINITIALIZED) { reinitialize(that); } return that.injectedNeedToResolveAgainstDefaultDirectory; } - static Target_sun_nio_fs_UnixPath getRootDirectory(Target_sun_nio_fs_UnixFileSystem that) { + static Target_sun_nio_fs_UnixPath_BuildTime getRootDirectory(Target_sun_nio_fs_UnixFileSystem_BuildTime that) { if (that.needsReinitialization != NeedsReinitializationProvider.STATUS_REINITIALIZED) { reinitialize(that); } @@ -298,15 +298,15 @@ static Target_sun_nio_fs_UnixPath getRootDirectory(Target_sun_nio_fs_UnixFileSys * of the constructor to write to the injected fields directly. */ - static void setDefaultDirectory(Target_sun_nio_fs_UnixFileSystem that, byte[] value) { + static void setDefaultDirectory(Target_sun_nio_fs_UnixFileSystem_BuildTime that, byte[] value) { that.injectedDefaultDirectory = value; } - static void setNeedToResolveAgainstDefaultDirectory(Target_sun_nio_fs_UnixFileSystem that, boolean value) { + static void setNeedToResolveAgainstDefaultDirectory(Target_sun_nio_fs_UnixFileSystem_BuildTime that, boolean value) { that.injectedNeedToResolveAgainstDefaultDirectory = value; } - static void setRootDirectory(Target_sun_nio_fs_UnixFileSystem that, Target_sun_nio_fs_UnixPath value) { + static void setRootDirectory(Target_sun_nio_fs_UnixFileSystem_BuildTime that, Target_sun_nio_fs_UnixPath_BuildTime value) { that.injectedRootDirectory = value; } @@ -314,7 +314,7 @@ static void setRootDirectory(Target_sun_nio_fs_UnixFileSystem that, Target_sun_n @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+20/src/java.base/linux/classes/sun/nio/fs/LinuxFileSystemProvider.java#L45-L47") @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+20/src/java.base/unix/classes/sun/nio/fs/UnixFileSystemProvider.java#L75-L77") @BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+20/src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java#L78-L108") - private static synchronized void reinitialize(Target_sun_nio_fs_UnixFileSystem that) { + private static synchronized void reinitialize(Target_sun_nio_fs_UnixFileSystem_BuildTime that) { if (that.needsReinitialization != NeedsReinitializationProvider.STATUS_NEEDS_REINITIALIZATION) { /* Field initialized is volatile, so double-checked locking is OK. */ return; @@ -350,10 +350,10 @@ private static synchronized void reinitialize(Target_sun_nio_fs_UnixFileSystem t @TargetClass(className = "sun.nio.fs.WindowsFileSystem") @Platforms({Platform.WINDOWS.class}) -final class Target_sun_nio_fs_WindowsFileSystem { +final class Target_sun_nio_fs_WindowsFileSystem_BuildTime { @Alias // - Target_sun_nio_fs_WindowsFileSystemProvider provider; + Target_sun_nio_fs_WindowsFileSystemProvider_BuildTime provider; @Alias // @InjectAccessors(WindowsFileSystemAccessors.class) // @@ -375,39 +375,39 @@ final class Target_sun_nio_fs_WindowsFileSystem { @Alias @TargetElement(name = TargetElement.CONSTRUCTOR_NAME) - native void originalConstructor(Target_sun_nio_fs_WindowsFileSystemProvider p, String dir); + native void originalConstructor(Target_sun_nio_fs_WindowsFileSystemProvider_BuildTime p, String dir); } @TargetClass(className = "sun.nio.fs.WindowsFileSystemProvider") @Platforms({Platform.WINDOWS.class}) -final class Target_sun_nio_fs_WindowsFileSystemProvider { +final class Target_sun_nio_fs_WindowsFileSystemProvider_BuildTime { } @Platforms({Platform.WINDOWS.class}) class WindowsFileSystemAccessors { - static String getDefaultDirectory(Target_sun_nio_fs_WindowsFileSystem that) { + static String getDefaultDirectory(Target_sun_nio_fs_WindowsFileSystem_BuildTime that) { if (that.needsReinitialization != NeedsReinitializationProvider.STATUS_REINITIALIZED) { reinitialize(that); } return that.injectedDefaultDirectory; } - static String getDefaultRoot(Target_sun_nio_fs_WindowsFileSystem that) { + static String getDefaultRoot(Target_sun_nio_fs_WindowsFileSystem_BuildTime that) { if (that.needsReinitialization != NeedsReinitializationProvider.STATUS_REINITIALIZED) { reinitialize(that); } return that.injectedDefaultRoot; } - static void setDefaultDirectory(Target_sun_nio_fs_WindowsFileSystem that, String value) { + static void setDefaultDirectory(Target_sun_nio_fs_WindowsFileSystem_BuildTime that, String value) { that.injectedDefaultDirectory = value; } - static void setDefaultRoot(Target_sun_nio_fs_WindowsFileSystem that, String value) { + static void setDefaultRoot(Target_sun_nio_fs_WindowsFileSystem_BuildTime that, String value) { that.injectedDefaultRoot = value; } - private static synchronized void reinitialize(Target_sun_nio_fs_WindowsFileSystem that) { + private static synchronized void reinitialize(Target_sun_nio_fs_WindowsFileSystem_BuildTime that) { if (that.needsReinitialization != NeedsReinitializationProvider.STATUS_NEEDS_REINITIALIZATION) { return; } @@ -419,7 +419,7 @@ private static synchronized void reinitialize(Target_sun_nio_fs_WindowsFileSyste @TargetClass(className = "java.io.UnixFileSystem", onlyWith = JDKInitializedAtBuildTime.class) @Platforms({Platform.LINUX.class, Platform.DARWIN.class}) -final class Target_java_io_UnixFileSystem { +final class Target_java_io_UnixFileSystem_BuildTime { @Alias // @InjectAccessors(UserDirAccessors.class) // @@ -427,7 +427,7 @@ final class Target_java_io_UnixFileSystem { } @TargetClass(className = "java.io.FileSystem", onlyWith = JDKInitializedAtBuildTime.class) -final class Target_java_io_FileSystem { +final class Target_java_io_FileSystem_BuildTime { @Alias native String normalize(String path); @@ -435,7 +435,7 @@ final class Target_java_io_FileSystem { class UserDirAccessors { @SuppressWarnings("unused") - static String getUserDir(Target_java_io_FileSystem that) { + static String getUserDir(Target_java_io_FileSystem_BuildTime that) { if (Platform.includedIn(Platform.WINDOWS.class)) { /* * Note that on Windows, we normalize the property value (JDK-8198997) and do not use @@ -447,14 +447,14 @@ static String getUserDir(Target_java_io_FileSystem that) { } @SuppressWarnings("unused") - static void setUserDir(Target_java_io_FileSystem that, String value) { + static void setUserDir(Target_java_io_FileSystem_BuildTime that, String value) { throw VMError.shouldNotReachHere("Field userDir is initialized at build time"); } } @TargetClass(className = "java.io.WinNTFileSystem") @Platforms(Platform.WINDOWS.class) -final class Target_java_io_WinNTFileSystem { +final class Target_java_io_WinNTFileSystem_BuildTime { @Alias // @InjectAccessors(UserDirAccessors.class) // From 19f828df171c300accb722619c22d434c01a7f75 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 4 Jun 2025 16:17:21 +0200 Subject: [PATCH 3/6] svm: only use FileSystemProviderBuildTimeInitFeature if not isJDKInitializedAtRunTime --- .../FileSystemProviderBuildTimeInitSupport.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java index d35090c0e371..849bbe098b75 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java @@ -35,6 +35,7 @@ import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.FieldValueTransformer; +import com.oracle.svm.core.FutureDefaultsOptions; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.Inject; import com.oracle.svm.core.annotate.InjectAccessors; @@ -130,6 +131,11 @@ public static void remove(String scheme) { @AutomaticallyRegisteredFeature final class FileSystemProviderBuildTimeInitFeature implements InternalFeature { + @Override + public boolean isInConfiguration(IsInConfigurationAccess access) { + return !FutureDefaultsOptions.isJDKInitializedAtRunTime(); + } + @Override public void afterRegistration(AfterRegistrationAccess access) { List installedProviders = new ArrayList<>(); From 7a35c8214705d71e5e6cb60a9dea4ea66b1a43b2 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 4 Jun 2025 16:31:17 +0200 Subject: [PATCH 4/6] svm: rename FileSystemProviderRuntimeInitSupport to FileSystemProviderRunTimeInitSupport --- .../FileSystemProviderBuildTimeInitSupport.java | 9 +++------ ...rt.java => FileSystemProviderRunTimeInitSupport.java} | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) rename substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/runtimeinit/{FileSystemProviderRuntimeInitSupport.java => FileSystemProviderRunTimeInitSupport.java} (96%) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java index 849bbe098b75..adbbc23aa082 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java @@ -50,6 +50,7 @@ import com.oracle.svm.core.jdk.JRTSupport; import com.oracle.svm.core.jdk.SystemPropertiesSupport; import com.oracle.svm.core.jdk.UserSystemProperty; +import com.oracle.svm.core.jdk.runtimeinit.FileSystemProviderRunTimeInitSupport; import com.oracle.svm.core.option.HostedOptionKey; import com.oracle.svm.core.util.BasedOnJDKFile; import com.oracle.svm.core.util.VMError; @@ -59,12 +60,8 @@ /** * This file contains substitutions that are required for initializing {@link FileSystemProvider} at - * image {@linkplain JDKInitializedAtBuildTime build time}. Other related functionality (general and - * run-time initialization) can be found in - * {@link com.oracle.svm.core.jdk.runtimeinit.FileSystemProviderRuntimeInitSupport}. - * - * @see JDKInitializedAtBuildTime - * @see com.oracle.svm.core.jdk.runtimeinit.FileSystemProviderRuntimeInitSupport + * image {@linkplain JDKInitializedAtBuildTime build time}. Run-time initialization related + * functionality can be found in {@link FileSystemProviderRunTimeInitSupport}. */ public final class FileSystemProviderBuildTimeInitSupport { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/runtimeinit/FileSystemProviderRuntimeInitSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/runtimeinit/FileSystemProviderRunTimeInitSupport.java similarity index 96% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/runtimeinit/FileSystemProviderRuntimeInitSupport.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/runtimeinit/FileSystemProviderRunTimeInitSupport.java index 8bf659d2bddf..8d93b4814792 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/runtimeinit/FileSystemProviderRuntimeInitSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/runtimeinit/FileSystemProviderRunTimeInitSupport.java @@ -48,13 +48,10 @@ /** * This file contains substitutions that are required for initializing {@link FileSystemProvider} at - * image {@linkplain JDKInitializedAtRunTime run time}. Other related functionality (general and - * build time initialization) can be found in {@link FileSystemProviderBuildTimeInitSupport}. - * - * @see JDKInitializedAtRunTime - * @see FileSystemProviderBuildTimeInitSupport + * image {@linkplain JDKInitializedAtRunTime run time}. Build-time initialization related + * functionality can be found in {@link FileSystemProviderBuildTimeInitSupport}. */ -public final class FileSystemProviderRuntimeInitSupport { +public final class FileSystemProviderRunTimeInitSupport { } @AutomaticallyRegisteredFeature From 2070206ae9c672769a35ebfe470e5ca43fdf26ac Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 11 Jun 2025 11:54:11 +0200 Subject: [PATCH 5/6] svm: keep a legacy FileSystemProviderSupport class for backwards compatibility [GR-65809] --- .../core/jdk/FileSystemProviderSupport.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/FileSystemProviderSupport.java diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/FileSystemProviderSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/FileSystemProviderSupport.java new file mode 100644 index 000000000000..4ea1343186fb --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/FileSystemProviderSupport.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.svm.core.jdk; + +import java.nio.file.spi.FileSystemProvider; + +import org.graalvm.nativeimage.Platform; +import org.graalvm.nativeimage.Platforms; + +import com.oracle.svm.core.FutureDefaultsOptions; +import com.oracle.svm.core.jdk.buildtimeinit.FileSystemProviderBuildTimeInitSupport; +import com.oracle.svm.core.util.VMError; + +/** + * Legacy delegate for backwards compatibility. It should go away eventually (GR-65809). + * + * @see com.oracle.svm.core.jdk.buildtimeinit.FileSystemProviderBuildTimeInitSupport + */ +@SuppressWarnings("unused") +public final class FileSystemProviderSupport { + + @Platforms(Platform.HOSTED_ONLY.class) + public static void register(FileSystemProvider provider) { + VMError.guarantee(!FutureDefaultsOptions.isJDKInitializedAtRunTime(), "No need to register FileSystemProvider if the JDK is initialized at run time."); + FileSystemProviderBuildTimeInitSupport.register(provider); + } + +} From cc6b282e3607bcac9c12e7c87fd4c00170ca82a7 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 12 Jun 2025 10:16:46 +0200 Subject: [PATCH 6/6] svm: fix Windows file system providers for future defaults [GR-65860] --- .../FileSystemProviderBuildTimeInitSupport.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java index adbbc23aa082..18944d5d41bd 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java @@ -351,7 +351,7 @@ private static synchronized void reinitialize(Target_sun_nio_fs_UnixFileSystem_B * fields so we cannot re-use the substitutions. */ -@TargetClass(className = "sun.nio.fs.WindowsFileSystem") +@TargetClass(className = "sun.nio.fs.WindowsFileSystem", onlyWith = JDKInitializedAtBuildTime.class) @Platforms({Platform.WINDOWS.class}) final class Target_sun_nio_fs_WindowsFileSystem_BuildTime { @@ -381,7 +381,7 @@ final class Target_sun_nio_fs_WindowsFileSystem_BuildTime { native void originalConstructor(Target_sun_nio_fs_WindowsFileSystemProvider_BuildTime p, String dir); } -@TargetClass(className = "sun.nio.fs.WindowsFileSystemProvider") +@TargetClass(className = "sun.nio.fs.WindowsFileSystemProvider", onlyWith = JDKInitializedAtBuildTime.class) @Platforms({Platform.WINDOWS.class}) final class Target_sun_nio_fs_WindowsFileSystemProvider_BuildTime { } @@ -455,7 +455,7 @@ static void setUserDir(Target_java_io_FileSystem_BuildTime that, String value) { } } -@TargetClass(className = "java.io.WinNTFileSystem") +@TargetClass(className = "java.io.WinNTFileSystem", onlyWith = JDKInitializedAtBuildTime.class) @Platforms(Platform.WINDOWS.class) final class Target_java_io_WinNTFileSystem_BuildTime {