Skip to content

Commit 07812b8

Browse files
committed
svm: move FileSystemProviderSupport to buildtimeinit
1 parent dd565a3 commit 07812b8

File tree

5 files changed

+67
-18
lines changed

5 files changed

+67
-18
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JRTSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
*/
6363
public final class JRTSupport {
6464

65-
static class Options {
65+
public static class Options {
6666
@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) //
6767
public static final HostedOptionKey<Boolean> AllowJRTFileSystem = new HostedOptionKey<>(false);
6868
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/FileSystemProviderSupport.java renamed to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/buildtimeinit/FileSystemProviderBuildTimeInitSupport.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* questions.
2424
*/
2525

26-
package com.oracle.svm.core.jdk;
26+
package com.oracle.svm.core.jdk.buildtimeinit;
2727

2828
import java.nio.file.spi.FileSystemProvider;
2929
import java.util.ArrayList;
@@ -45,14 +45,27 @@
4545
import com.oracle.svm.core.annotate.TargetElement;
4646
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
4747
import com.oracle.svm.core.feature.InternalFeature;
48+
import com.oracle.svm.core.jdk.JDKInitializedAtBuildTime;
49+
import com.oracle.svm.core.jdk.JRTSupport;
50+
import com.oracle.svm.core.jdk.SystemPropertiesSupport;
51+
import com.oracle.svm.core.jdk.UserSystemProperty;
4852
import com.oracle.svm.core.option.HostedOptionKey;
4953
import com.oracle.svm.core.util.BasedOnJDKFile;
5054
import com.oracle.svm.core.util.VMError;
5155

5256
import jdk.graal.compiler.options.Option;
5357
import jdk.internal.util.StaticProperty;
5458

55-
public final class FileSystemProviderSupport {
59+
/**
60+
* This file contains substitutions that are required for initializing {@link FileSystemProvider} at
61+
* image {@linkplain JDKInitializedAtBuildTime build time}. Other related functionality (general and
62+
* run-time initialization) can be found in
63+
* {@link com.oracle.svm.core.jdk.runtimeinit.FileSystemProviderRuntimeInitSupport}.
64+
*
65+
* @see JDKInitializedAtBuildTime
66+
* @see com.oracle.svm.core.jdk.runtimeinit.FileSystemProviderRuntimeInitSupport
67+
*/
68+
public final class FileSystemProviderBuildTimeInitSupport {
5669

5770
public static class Options {
5871
@Option(help = "Make all supported providers returned by FileSystemProvider.installedProviders() available at run time.")//
@@ -63,7 +76,7 @@ public static class Options {
6376
final List<FileSystemProvider> installedProvidersImmutable;
6477

6578
@Platforms(Platform.HOSTED_ONLY.class)
66-
FileSystemProviderSupport(List<FileSystemProvider> installedProviders) {
79+
FileSystemProviderBuildTimeInitSupport(List<FileSystemProvider> installedProviders) {
6780
this.installedProvidersMutable = installedProviders;
6881
this.installedProvidersImmutable = Collections.unmodifiableList(installedProviders);
6982
}
@@ -75,7 +88,7 @@ public static class Options {
7588
*/
7689
@Platforms(Platform.HOSTED_ONLY.class)
7790
public static void register(FileSystemProvider provider) {
78-
List<FileSystemProvider> installedProviders = ImageSingletons.lookup(FileSystemProviderSupport.class).installedProvidersMutable;
91+
List<FileSystemProvider> installedProviders = ImageSingletons.lookup(FileSystemProviderBuildTimeInitSupport.class).installedProvidersMutable;
7992

8093
String scheme = provider.getScheme();
8194
for (int i = 0; i < installedProviders.size(); i++) {
@@ -98,7 +111,7 @@ public static void register(FileSystemProvider provider) {
98111
*/
99112
@Platforms(Platform.HOSTED_ONLY.class)
100113
public static void remove(String scheme) {
101-
List<FileSystemProvider> installedProviders = ImageSingletons.lookup(FileSystemProviderSupport.class).installedProvidersMutable;
114+
List<FileSystemProvider> installedProviders = ImageSingletons.lookup(FileSystemProviderBuildTimeInitSupport.class).installedProvidersMutable;
102115

103116
for (int i = 0; i < installedProviders.size(); i++) {
104117
/*
@@ -115,12 +128,12 @@ public static void remove(String scheme) {
115128
}
116129

117130
@AutomaticallyRegisteredFeature
118-
final class FileSystemProviderFeature implements InternalFeature {
131+
final class FileSystemProviderBuildTimeInitFeature implements InternalFeature {
119132

120133
@Override
121134
public void afterRegistration(AfterRegistrationAccess access) {
122135
List<FileSystemProvider> installedProviders = new ArrayList<>();
123-
if (FileSystemProviderSupport.Options.AddAllFileSystemProviders.getValue()) {
136+
if (FileSystemProviderBuildTimeInitSupport.Options.AddAllFileSystemProviders.getValue()) {
124137
/*
125138
* The first invocation of FileSystemProvider.installedProviders() causes the default
126139
* provider to be initialized (if not already initialized) and loads any other installed
@@ -133,11 +146,11 @@ public void afterRegistration(AfterRegistrationAccess access) {
133146
*/
134147
installedProviders.addAll(FileSystemProvider.installedProviders());
135148
}
136-
ImageSingletons.add(FileSystemProviderSupport.class, new FileSystemProviderSupport(installedProviders));
149+
ImageSingletons.add(FileSystemProviderBuildTimeInitSupport.class, new FileSystemProviderBuildTimeInitSupport(installedProviders));
137150

138151
/* Access to Java modules (jimage/jrtfs access) in images is experimental. */
139152
if (!JRTSupport.Options.AllowJRTFileSystem.getValue()) {
140-
FileSystemProviderSupport.remove("jrt");
153+
FileSystemProviderBuildTimeInitSupport.remove("jrt");
141154
}
142155
}
143156
}
@@ -146,7 +159,7 @@ public void afterRegistration(AfterRegistrationAccess access) {
146159
final class Target_java_nio_file_spi_FileSystemProvider {
147160
@Substitute
148161
public static List<FileSystemProvider> installedProviders() {
149-
return ImageSingletons.lookup(FileSystemProviderSupport.class).installedProvidersImmutable;
162+
return ImageSingletons.lookup(FileSystemProviderBuildTimeInitSupport.class).installedProvidersImmutable;
150163
}
151164
}
152165

@@ -160,7 +173,8 @@ public static List<FileSystemProvider> installedProviders() {
160173
*
161174
* a) Disallow UnixFileSystem and UnixFileSystemProvider in the image heap, i.e., create all
162175
* instances at run time. This is undesirable because then all file system providers need to be
163-
* loaded at run time, i.e., the caching in {@link FileSystemProviderSupport} would no longer work.
176+
* loaded at run time, i.e., the caching in {@link FileSystemProviderBuildTimeInitSupport} would no
177+
* longer work.
164178
*
165179
* b) Disallow UnixFileSystem in the image heap, but have the UnixFileSystemProvider instance in the
166180
* image heap. This requires a recomputation of the field UnixFileSystemProvider.theFileSystem at
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
/**
27+
* This package contains "legacy" substitutions and features that are required to support
28+
* initializing certain parts of the JDK at image
29+
* {@linkplain com.oracle.svm.core.jdk.JDKInitializedAtBuildTime build time}. Those parts of the JDK
30+
* are planned to be initialized at {@linkplain com.oracle.svm.core.jdk.JDKInitializedAtRunTime run
31+
* time} in the {@linkplain com.oracle.svm.core.FutureDefaultsOptions future}. Once run time
32+
* initialization is the default, this package will be removed.
33+
*/
34+
package com.oracle.svm.core.jdk.buildtimeinit;

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/runtimeinit/FileSystemProviderRuntimeInitSupport.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,21 @@
4040
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
4141
import com.oracle.svm.core.feature.InternalFeature;
4242
import com.oracle.svm.core.jdk.JDKInitializedAtRunTime;
43+
import com.oracle.svm.core.jdk.buildtimeinit.FileSystemProviderBuildTimeInitSupport;
4344
import com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystemProvider;
4445
import com.oracle.svm.core.util.BasedOnJDKFile;
4546
import com.oracle.svm.core.util.VMError;
4647
import com.oracle.svm.util.ReflectionUtil;
4748

4849
/**
4950
* This file contains substitutions that are required for initializing {@link FileSystemProvider} at
50-
* image run time. Other related functionality (general and build time initialization) can be found
51-
* in {@link com.oracle.svm.core.jdk.FileSystemProviderSupport}.
51+
* image {@linkplain JDKInitializedAtRunTime run time}. Other related functionality (general and
52+
* build time initialization) can be found in {@link FileSystemProviderBuildTimeInitSupport}.
5253
*
5354
* @see JDKInitializedAtRunTime
54-
* @see com.oracle.svm.core.jdk.FileSystemProviderSupport
55+
* @see FileSystemProviderBuildTimeInitSupport
5556
*/
56-
final class FileSystemProviderRuntimeInitSupport {
57+
public final class FileSystemProviderRuntimeInitSupport {
5758
}
5859

5960
@AutomaticallyRegisteredFeature

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/WebImageFeature.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@
7070
import com.oracle.svm.core.heap.RestrictHeapAccessCallees;
7171
import com.oracle.svm.core.hub.DynamicHub;
7272
import com.oracle.svm.core.hub.DynamicHubCompanion;
73-
import com.oracle.svm.core.jdk.FileSystemProviderSupport;
7473
import com.oracle.svm.core.jdk.PlatformNativeLibrarySupport;
7574
import com.oracle.svm.core.jdk.SystemInOutErrSupport;
7675
import com.oracle.svm.core.jdk.SystemPropertiesSupport;
76+
import com.oracle.svm.core.jdk.buildtimeinit.FileSystemProviderBuildTimeInitSupport;
7777
import com.oracle.svm.core.log.Log;
7878
import com.oracle.svm.core.option.HostedOptionValues;
7979
import com.oracle.svm.core.util.VMError;
@@ -323,7 +323,7 @@ public void afterRegistration(AfterRegistrationAccess access) {
323323
* Registers our own file system provider, which replaces the default provider for the
324324
* 'file' scheme.
325325
*/
326-
FileSystemProviderSupport.register(WebImageNIOFileSystemProvider.INSTANCE);
326+
FileSystemProviderBuildTimeInitSupport.register(WebImageNIOFileSystemProvider.INSTANCE);
327327
}
328328

329329
@Override

0 commit comments

Comments
 (0)