Skip to content

Commit b0d0619

Browse files
committed
move layered images options to their own file.
1 parent 82ae059 commit b0d0619

18 files changed

+188
-131
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import com.oracle.svm.core.option.APIOptionGroup;
6161
import com.oracle.svm.core.option.AccumulatingLocatableMultiOptionValue;
6262
import com.oracle.svm.core.option.BundleMember;
63-
import com.oracle.svm.core.option.BundleMember.Role;
6463
import com.oracle.svm.core.option.GCOptionValue;
6564
import com.oracle.svm.core.option.HostedOptionKey;
6665
import com.oracle.svm.core.option.HostedOptionValues;
@@ -129,30 +128,6 @@ public class SubstrateOptions {
129128
@Option(help = "Build shared library")//
130129
public static final HostedOptionKey<Boolean> SharedLibrary = new HostedOptionKey<>(false);
131130

132-
@Option(help = "Persist and reload all graphs across layers. If false, graphs defined in the base layer can be reparsed by the current layer and inlined before analysis, " +
133-
"but will not be inlined after analysis has completed via our other inlining infrastructure")//
134-
public static final HostedOptionKey<Boolean> UseSharedLayerGraphs = new HostedOptionKey<>(true) {
135-
@Override
136-
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean oldValue, Boolean newValue) {
137-
if (!newValue) {
138-
UseSharedLayerStrengthenedGraphs.update(values, false);
139-
}
140-
}
141-
};
142-
143-
@Option(help = "Persist and reload strengthened graphs across layers. If false, inlining after analysis will be disabled")//
144-
public static final HostedOptionKey<Boolean> UseSharedLayerStrengthenedGraphs = new HostedOptionKey<>(false) {
145-
@Override
146-
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean oldValue, Boolean newValue) {
147-
if (newValue) {
148-
UserError.guarantee(UseSharedLayerStrengthenedGraphs.getValueOrDefault(values),
149-
"UseSharedLayerStrengthenedGraph is a subset of UseSharedLayerGraphs, so the former cannot be enabled alone.");
150-
} else {
151-
NeverInline.update(values, "SubstrateStringConcatHelper.simpleConcat");
152-
}
153-
}
154-
};
155-
156131
@APIOption(name = "static")//
157132
@Option(help = "Build statically linked executable (requires static libc and zlib)")//
158133
public static final HostedOptionKey<Boolean> StaticExecutable = new HostedOptionKey<>(false, key -> {
@@ -170,31 +145,6 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean o
170145
}
171146
});
172147

173-
public static final String LAYER_OPTION_PREFIX = "-H:Layer"; // "--layer"
174-
public static final String LAYER_CREATE_OPTION = LAYER_OPTION_PREFIX + "Create"; // "-create"
175-
// @APIOption(name = LAYER_CREATE_OPTION) // use when non-experimental
176-
@Option(help = "Experimental: Build a Native Image layer. See NativeImageLayers.md for more info.")//
177-
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> LayerCreate = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());
178-
179-
// public static final String LAYER_USE_OPTION = LAYER_OPTION_PREFIX + "-use";
180-
// @APIOption(name = LAYER_USE_OPTION) // use when non-experimental
181-
@Option(help = "Experimental: Build an image based on a Native Image layer.")//
182-
@BundleMember(role = Role.Input) //
183-
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Paths> LayerUse = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Paths.build());
184-
185-
@Option(help = "Experimental: Perform strict checking of options used for layered image build.")//
186-
public static final HostedOptionKey<Boolean> LayerOptionVerification = new HostedOptionKey<>(true);
187-
188-
@Option(help = "Experimental: Provide verbose output of difference in builder options between layers.")//
189-
public static final HostedOptionKey<Boolean> LayerOptionVerificationVerbose = new HostedOptionKey<>(false);
190-
191-
@Option(help = "Mark singleton as application layer only")//
192-
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> ApplicationLayerOnlySingletons = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());
193-
194-
@Option(help = "Register class as being initialized in the app layer.")//
195-
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> ApplicationLayerInitializedClasses = new HostedOptionKey<>(
196-
AccumulatingLocatableMultiOptionValue.Strings.build());
197-
198148
@APIOption(name = "libc")//
199149
@Option(help = "Selects the libc implementation to use. Available implementations: glibc, musl, bionic")//
200150
public static final HostedOptionKey<String> UseLibC = new HostedOptionKey<>(null) {
@@ -1611,12 +1561,6 @@ public static int interfaceHashingMaxId() {
16111561
return InterfaceHashingMaxId.getValue();
16121562
}
16131563

1614-
@Option(help = "Throws an exception on potential type conflict during heap persisting if enabled", type = OptionType.Debug) //
1615-
public static final HostedOptionKey<Boolean> AbortOnNameConflict = new HostedOptionKey<>(false);
1616-
1617-
@Option(help = "Enables logging of failed hash code injection", type = OptionType.Debug) //
1618-
public static final HostedOptionKey<Boolean> LoggingHashCodeInjection = new HostedOptionKey<>(false);
1619-
16201564
public static class TruffleStableOptions {
16211565

16221566
@Option(help = "Automatically copy the necessary language resources to the resources directory next to the produced image.", type = User, stability = OptionStability.STABLE)//
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) 2025, 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+
package com.oracle.svm.core.imagelayer;
26+
27+
import org.graalvm.collections.EconomicMap;
28+
29+
import com.oracle.svm.core.SubstrateOptions;
30+
import com.oracle.svm.core.option.AccumulatingLocatableMultiOptionValue;
31+
import com.oracle.svm.core.option.BundleMember;
32+
import com.oracle.svm.core.option.HostedOptionKey;
33+
import com.oracle.svm.core.util.UserError;
34+
35+
import jdk.graal.compiler.options.Option;
36+
import jdk.graal.compiler.options.OptionKey;
37+
import jdk.graal.compiler.options.OptionType;
38+
39+
public class LayeredImageOptions {
40+
public static final String LAYER_OPTION_PREFIX = "-H:Layer"; // "--layer"
41+
public static final String LAYER_CREATE_OPTION = LAYER_OPTION_PREFIX + "Create"; // "-create"
42+
43+
// @APIOption(name = LAYER_CREATE_OPTION) // use when non-experimental
44+
@Option(help = "Build a Native Image layer. See NativeImageLayers.md for more info.")//
45+
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> LayerCreate = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());
46+
47+
// public static final String LAYER_USE_OPTION = LAYER_OPTION_PREFIX + "-use";
48+
// @APIOption(name = LAYER_USE_OPTION) // use when non-experimental
49+
@Option(help = "Build an image based on a Native Image layer.")//
50+
@BundleMember(role = BundleMember.Role.Input) //
51+
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Paths> LayerUse = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Paths.build());
52+
53+
@Option(help = "Mark singleton as application layer only")//
54+
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> ApplicationLayerOnlySingletons = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());
55+
56+
@Option(help = "Register class as being initialized in the app layer.")//
57+
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> ApplicationLayerInitializedClasses = new HostedOptionKey<>(
58+
AccumulatingLocatableMultiOptionValue.Strings.build());
59+
@Option(help = "Persist and reload all graphs across layers. If false, graphs defined in the base layer can be reparsed by the current layer and inlined before analysis, " +
60+
"but will not be inlined after analysis has completed via our other inlining infrastructure")//
61+
public static final HostedOptionKey<Boolean> UseSharedLayerGraphs = new HostedOptionKey<>(true) {
62+
@Override
63+
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean oldValue, Boolean newValue) {
64+
if (!newValue) {
65+
UseSharedLayerStrengthenedGraphs.update(values, false);
66+
}
67+
}
68+
};
69+
70+
@Option(help = "Persist and reload strengthened graphs across layers. If false, inlining after analysis will be disabled")//
71+
public static final HostedOptionKey<Boolean> UseSharedLayerStrengthenedGraphs = new HostedOptionKey<>(false) {
72+
@Override
73+
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean oldValue, Boolean newValue) {
74+
if (newValue) {
75+
UserError.guarantee(UseSharedLayerStrengthenedGraphs.getValueOrDefault(values),
76+
"UseSharedLayerStrengthenedGraph is a subset of UseSharedLayerGraphs, so the former cannot be enabled alone.");
77+
} else {
78+
SubstrateOptions.NeverInline.update(values, "SubstrateStringConcatHelper.simpleConcat");
79+
}
80+
}
81+
};
82+
83+
public static class LayeredImageDiagnosticOptions {
84+
@Option(help = "Log discrepancies between layered open world type information. This is an experimental option which will be removed.")//
85+
public static final HostedOptionKey<Boolean> LogLayeredDispatchTableDiscrepancies = new HostedOptionKey<>(false);
86+
87+
@Option(help = "Throw an error when there are discrepancies between layered open world type information. This is an experimental option which will be removed.")//
88+
public static final HostedOptionKey<Boolean> AbortOnLayeredDispatchTableDiscrepancies = new HostedOptionKey<>(false);
89+
90+
@Option(help = "Log unique names which do not match across layers. This is an experimental option which will be removed.") //
91+
public static final HostedOptionKey<Boolean> LogUniqueNameInconsistencies = new HostedOptionKey<>(false);
92+
93+
@Option(help = "Enables logging of failed hash code injection", type = OptionType.Debug) //
94+
public static final HostedOptionKey<Boolean> LogHashCodeInjectionFailure = new HostedOptionKey<>(false);
95+
96+
@Option(help = "Enables logging on various loading failures", type = OptionType.Debug) //
97+
public static final HostedOptionKey<Boolean> LogLoadingFailures = new HostedOptionKey<>(false);
98+
99+
@Option(help = "Throws an exception on potential type conflict during heap persisting if enabled", type = OptionType.Debug) //
100+
public static final HostedOptionKey<Boolean> AbortOnNameConflict = new HostedOptionKey<>(false);
101+
102+
@Option(help = "Logs potential type conflict during heap persisting if enabled", type = OptionType.Debug) //
103+
public static final HostedOptionKey<Boolean> LogOnNameConflict = new HostedOptionKey<>(false);
104+
105+
@Option(help = "Enables logging of layered archiving")//
106+
public static final HostedOptionKey<Boolean> LogLayeredArchiving = new HostedOptionKey<>(false);
107+
108+
@Option(help = "Perform strict checking of options used for layered image build.")//
109+
public static final HostedOptionKey<Boolean> LayerOptionVerification = new HostedOptionKey<>(true);
110+
111+
@Option(help = "Provide verbose output of difference in builder options between layers.")//
112+
public static final HostedOptionKey<Boolean> LayerOptionVerificationVerbose = new HostedOptionKey<>(false);
113+
}
114+
}

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.nio.file.Paths;
3131
import java.util.List;
3232

33-
import com.oracle.svm.core.SubstrateOptions;
33+
import com.oracle.svm.core.imagelayer.LayeredImageOptions;
3434
import com.oracle.svm.core.option.OptionOrigin;
3535
import com.oracle.svm.core.option.OptionUtils;
3636
import com.oracle.svm.driver.NativeImage.ArgumentQueue;
@@ -148,7 +148,7 @@ public boolean consume(ArgumentQueue args) {
148148
if (headArg.startsWith(nativeImage.oHLayerCreate)) {
149149
String rawLayerCreateValue = headArg.substring(nativeImage.oHLayerCreate.length());
150150
if (!rawLayerCreateValue.isEmpty()) {
151-
List<String> layerCreateValue = OptionUtils.resolveOptionValuesRedirection(SubstrateOptions.LayerCreate, rawLayerCreateValue, OptionOrigin.from(args.argumentOrigin));
151+
List<String> layerCreateValue = OptionUtils.resolveOptionValuesRedirection(LayeredImageOptions.LayerCreate, rawLayerCreateValue, OptionOrigin.from(args.argumentOrigin));
152152
LayerOption layerOption = LayerOption.parse(layerCreateValue);
153153
for (ExtendedOption option : layerOption.extendedOptions()) {
154154
var packageOptionValue = IncludeOptionsSupport.PackageOptionValue.from(option);

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
import com.oracle.svm.core.SubstrateOptions;
9191
import com.oracle.svm.core.SubstrateUtil;
9292
import com.oracle.svm.core.VM;
93+
import com.oracle.svm.core.imagelayer.LayeredImageOptions;
9394
import com.oracle.svm.core.option.BundleMember;
9495
import com.oracle.svm.core.option.OptionOrigin;
9596
import com.oracle.svm.core.option.OptionUtils;
@@ -283,7 +284,7 @@ private static <T> String oR(OptionKey<T> option) {
283284
final String oHUseLibC = oH(SubstrateOptions.UseLibC);
284285
final String oHEnableStaticExecutable = oHEnabled(SubstrateOptions.StaticExecutable);
285286
final String oHEnableSharedLibraryFlagPrefix = oHEnabled + SubstrateOptions.SharedLibrary.getName();
286-
final String oHEnableImageLayerFlagPrefix = oH + SubstrateOptions.LayerCreate.getName();
287+
final String oHEnableImageLayerFlagPrefix = oH + LayeredImageOptions.LayerCreate.getName();
287288
final String oHColor = oH(SubstrateOptions.Color);
288289
final String oHEnableBuildOutputProgress = oHEnabledByDriver(SubstrateOptions.BuildOutputProgress);
289290
final String oHEnableBuildOutputLinks = oHEnabledByDriver(SubstrateOptions.BuildOutputLinks);
@@ -297,7 +298,7 @@ private static <T> String oR(OptionKey<T> option) {
297298

298299
final String oHInspectServerContentPath = oH(PointstoOptions.InspectServerContentPath);
299300
final String oHDeadlockWatchdogInterval = oH(SubstrateOptions.DeadlockWatchdogInterval);
300-
final String oHLayerCreate = oH(SubstrateOptions.LayerCreate);
301+
final String oHLayerCreate = oH(LayeredImageOptions.LayerCreate);
301302

302303
final Map<String, String> imageBuilderEnvironment = new HashMap<>();
303304
private final ArrayList<String> imageBuilderArgs = new ArrayList<>();

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ImageSingletonsSupportImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
import org.graalvm.nativeimage.impl.AnnotationExtractor;
4545
import org.graalvm.nativeimage.impl.ImageSingletonsSupport;
4646

47-
import com.oracle.svm.core.SubstrateOptions;
4847
import com.oracle.svm.core.SubstrateUtil;
4948
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
49+
import com.oracle.svm.core.imagelayer.LayeredImageOptions;
5050
import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonSupport;
5151
import com.oracle.svm.core.layeredimagesingleton.LayeredPersistFlags;
5252
import com.oracle.svm.core.layeredimagesingleton.LoadedLayeredImageSingletonInfo;
@@ -435,7 +435,7 @@ private void addSingleton(Class<?> key, Object value) {
435435
traitMap.getTrait(SingletonTraitKind.LAYERED_INSTALLATION_KIND).ifPresent(trait -> {
436436
var kind = SingletonLayeredInstallationKind.getInstallationKind(trait);
437437
if (forbiddenInstallationKinds.contains(kind)) {
438-
if (SubstrateOptions.LayerOptionVerification.getValue()) {
438+
if (LayeredImageOptions.LayeredImageDiagnosticOptions.LayerOptionVerification.getValue()) {
439439
throw VMError.shouldNotReachHere("Singleton with installation kind %s can no longer be added: %s", kind, value);
440440
}
441441
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
import com.oracle.svm.core.SharedConstants;
9292
import com.oracle.svm.core.SubstrateOptions;
9393
import com.oracle.svm.core.SubstrateUtil;
94+
import com.oracle.svm.core.imagelayer.LayeredImageOptions;
9495
import com.oracle.svm.core.option.AccumulatingLocatableMultiOptionValue;
9596
import com.oracle.svm.core.option.HostedOptionKey;
9697
import com.oracle.svm.core.option.LocatableMultiOptionValue.ValueWithOrigin;
@@ -148,7 +149,7 @@ public final class NativeImageClassLoaderSupport {
148149

149150
private Path layerFile;
150151

151-
private final IncludeSelectors layerSelectors = new IncludeSelectors(SubstrateOptions.LayerCreate);
152+
private final IncludeSelectors layerSelectors = new IncludeSelectors(LayeredImageOptions.LayerCreate);
152153
private final IncludeSelectors preserveSelectors = new IncludeSelectors(SubstrateOptions.Preserve);
153154
private final IncludeSelectors dynamicAccessSelectors = new IncludeSelectors(SubstrateOptions.TrackDynamicAccess);
154155
private boolean includeConfigSealed;
@@ -728,7 +729,7 @@ public void setupLibGraalClassLoader() {
728729

729730
public void allClassesLoaded() {
730731
if (loadClassHandler != null) {
731-
loadClassHandler.validatePackageInclusionRequests(loadClassHandler.includePackages, SubstrateOptions.LayerCreate);
732+
loadClassHandler.validatePackageInclusionRequests(loadClassHandler.includePackages, LayeredImageOptions.LayerCreate);
732733
loadClassHandler.validatePackageInclusionRequests(loadClassHandler.preservePackages, SubstrateOptions.Preserve);
733734
loadClassHandler = null;
734735
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
package com.oracle.svm.hosted;
2626

2727
import static com.oracle.graal.pointsto.api.PointstoOptions.UseExperimentalReachabilityAnalysis;
28-
import static com.oracle.svm.core.SubstrateOptions.LayerCreate;
28+
import static com.oracle.svm.core.imagelayer.LayeredImageOptions.LayerCreate;
2929
import static com.oracle.svm.hosted.NativeImageOptions.DiagnosticsDir;
3030
import static com.oracle.svm.hosted.NativeImageOptions.DiagnosticsMode;
3131
import static jdk.graal.compiler.hotspot.JVMCIVersionCheck.OPEN_LABSJDK_RELEASE_URL_PATTERN;
@@ -53,6 +53,7 @@
5353
import java.util.function.BooleanSupplier;
5454
import java.util.function.Function;
5555

56+
import com.oracle.svm.core.imagelayer.LayeredImageOptions;
5657
import com.oracle.svm.hosted.reflect.ReflectionFeature;
5758
import org.graalvm.collections.EconomicSet;
5859
import org.graalvm.collections.Pair;
@@ -999,8 +1000,8 @@ protected void setupNativeImage(OptionValues options, Map<Method, CEntryPointDat
9991000
imageLayerSnapshotUtil = HostedConfiguration.instance().createSVMImageLayerSnapshotUtil(loader);
10001001
}
10011002

1002-
Boolean useSharedLayerGraphs = SubstrateOptions.UseSharedLayerGraphs.getValue();
1003-
Boolean useSharedLayerStrengthenedGraphs = SubstrateOptions.UseSharedLayerStrengthenedGraphs.getValue();
1003+
Boolean useSharedLayerGraphs = LayeredImageOptions.UseSharedLayerGraphs.getValue();
1004+
Boolean useSharedLayerStrengthenedGraphs = LayeredImageOptions.UseSharedLayerStrengthenedGraphs.getValue();
10041005
if (ImageLayerBuildingSupport.buildingSharedLayer()) {
10051006
SVMImageLayerWriter imageLayerWriter = HostedConfiguration.instance().createSVMImageLayerWriter(imageLayerSnapshotUtil, useSharedLayerGraphs, useSharedLayerStrengthenedGraphs);
10061007
HostedImageLayerBuildingSupport.singleton().setWriter(imageLayerWriter);

0 commit comments

Comments
 (0)