Skip to content

Commit 108a373

Browse files
committed
Enable metadata tracing with -H:Preserve=all
Also move other feature-enabling flags to be used only with -H:Preserve=all. The flags were blowing up image size overly much for simple -H:Preserve usage.
1 parent 4f61e16 commit 108a373

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ public void clearDynamicAccessSelectors() {
147147
}
148148

149149
public boolean isPreserveMode() {
150-
return !preserveSelectors.classpathEntries.isEmpty() || !preserveSelectors.moduleNames.isEmpty() || !preserveSelectors.packages.isEmpty() || preserveAll();
150+
return !preserveSelectors.classpathEntries.isEmpty() || !preserveSelectors.moduleNames.isEmpty() || !preserveSelectors.packages.isEmpty() || isPreserveAll();
151151
}
152152

153153
/**
154154
* @return true if {@link PreserveOptionsSupport#PRESERVE_ALL preserve all} is enabled.
155155
*/
156-
private boolean preserveAll() {
156+
public boolean isPreserveAll() {
157157
return preserveAllOrigin().isPresent();
158158
}
159159

@@ -312,7 +312,7 @@ private ModuleFinder getModulePathsFinder() {
312312
public void loadAllClasses(ForkJoinPool executor, ImageClassLoader imageClassLoader) {
313313
VMError.guarantee(!includeConfigSealed, "This method should be executed only once.");
314314

315-
if (preserveAll()) {
315+
if (isPreserveAll()) {
316316
String msg = """
317317
This image build includes all classes from the classpath and the JDK via the %s option. This will lead to noticeably bigger images and increased startup times.
318318
If you notice '--initialize-at-build-time' related errors during the build, this is because unanticipated types ended up in the image heap.\

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/PreserveOptionsSupport.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static com.oracle.svm.core.SubstrateOptions.EnableURLProtocols;
2929
import static com.oracle.svm.core.SubstrateOptions.Preserve;
3030
import static com.oracle.svm.core.jdk.JRTSupport.Options.AllowJRTFileSystem;
31+
import static com.oracle.svm.core.metadata.MetadataTracer.Options.MetadataTracingSupport;
3132
import static com.oracle.svm.hosted.SecurityServicesFeature.Options.AdditionalSecurityProviders;
3233
import static com.oracle.svm.hosted.jdk.localization.LocalizationFeature.Options.AddAllCharsets;
3334
import static com.oracle.svm.hosted.jdk.localization.LocalizationFeature.Options.IncludeAllLocales;
@@ -40,6 +41,7 @@
4041
import java.security.Security;
4142
import java.util.Arrays;
4243
import java.util.Comparator;
44+
import java.util.List;
4345
import java.util.Set;
4446
import java.util.StringJoiner;
4547
import java.util.stream.Stream;
@@ -140,19 +142,32 @@ public static void parsePreserveOption(EconomicMap<OptionKey<?>, Object> hostedV
140142
}
141143
});
142144
if (classLoaderSupport.isPreserveMode()) {
145+
/* Significantly speeds up analysis */
143146
if (UseConservativeUnsafeAccess.hasBeenSet(optionValues)) {
144147
UserError.guarantee(UseConservativeUnsafeAccess.getValue(optionValues), "%s can not be used together with %s. Please unset %s.",
145148
SubstrateOptionsParser.commandArgument(UseConservativeUnsafeAccess, "-"),
146149
SubstrateOptionsParser.commandArgument(Preserve, "<value>"),
147150
SubstrateOptionsParser.commandArgument(UseConservativeUnsafeAccess, "-"));
148151
}
149152
UseConservativeUnsafeAccess.update(hostedValues, true);
153+
}
150154

155+
if (classLoaderSupport.isPreserveAll()) {
156+
/* Include all parts of native image that are stripped */
151157
AddAllCharsets.update(hostedValues, true);
152158
IncludeAllLocales.update(hostedValues, true);
153159
AllowJRTFileSystem.update(hostedValues, true);
154-
EnableURLProtocols.update(hostedValues, "http,https,ftp,jar,file,mailto,jrt,jmod");
160+
161+
/* Should be removed with GR-61365 */
162+
var missingJDKProtocols = List.of("http", "https", "ftp", "jar", "mailto", "jrt", "jmod");
163+
for (String missingProtocol : missingJDKProtocols) {
164+
EnableURLProtocols.update(hostedValues, missingProtocol);
165+
}
166+
155167
AdditionalSecurityProviders.update(hostedValues, getSecurityProvidersCSV());
168+
169+
/* Allow metadata tracing in preserve all images */
170+
MetadataTracingSupport.update(hostedValues, true);
156171
}
157172
}
158173

0 commit comments

Comments
 (0)