Skip to content

Commit 0f76434

Browse files
author
Christian Wimmer
committed
[GR-41978] Disallow --initialize-at-build-time without arguments.
PullRequest: graal/12987
2 parents 75cc35c + 8ad5d4e commit 0f76434

File tree

6 files changed

+23
-14
lines changed

6 files changed

+23
-14
lines changed

java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def extra_image_build_argument(self, benchmark, args):
371371
'-H:EnableURLProtocols=http',
372372
'-H:NativeLinkerOption=-no-pie',
373373
'-H:-UseServiceLoaderFeature',
374-
'-H:+TolerateBuilderClassesOnImageClasspath', # needs to be removed once GR-41746 is fixed
374+
'-H:+AllowDeprecatedBuilderClassesOnImageClasspath', # needs to be removed once GR-41746 is fixed
375375
'--add-exports=org.graalvm.sdk/org.graalvm.nativeimage.impl=ALL-UNNAMED',
376376
'--add-exports=org.graalvm.nativeimage.base/com.oracle.svm.util=ALL-UNNAMED',
377377
'--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.configure=ALL-UNNAMED',

substratevm/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
This changelog summarizes major changes to GraalVM Native Image.
44

55
## Version 23.0.0
6-
* (GR-40187) Report invalid use of SVM specific classes on image class- or module-path as error. As a temporary workaround, -H:+TolerateBuilderClassesOnImageClasspath allows turning the error into a warning.
6+
* (GR-40187) Report invalid use of SVM specific classes on image class- or module-path as error. As a temporary workaround, `-H:+AllowDeprecatedBuilderClassesOnImageClasspath` allows turning the error into a warning.
77
* (GR-41196) Provide `.debug.svm.imagebuild.*` sections that contain build options and properties used in the build of the image.
8+
* (GR-41978) Disallow `--initialize-at-build-time` without arguments. As a temporary workaround, `-H:+AllowDeprecatedInitializeAllClassesAtBuildTime` allows turning this error into a warning.
89

910
## Version 22.3.0
1011
* (GR-35721) Remove old build output style and the `-H:±BuildOutputUseNewStyle` option.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,6 @@ public Boolean getValueOrDefault(UnmodifiableEconomicMap<OptionKey<?>, Object> v
858858
};
859859

860860
@Option(help = "Instead of abort, only warn if image builder classes are found on the image class-path.", type = Debug)//
861-
public static final HostedOptionKey<Boolean> TolerateBuilderClassesOnImageClasspath = new HostedOptionKey<>(false);
861+
public static final HostedOptionKey<Boolean> AllowDeprecatedBuilderClassesOnImageClasspath = new HostedOptionKey<>(false);
862862

863863
}

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
@@ -819,7 +819,7 @@ public void reportBuilderClassesInApplication() {
819819
var destinationMap = builderURILocations.contains(classesEntries.getKey()) ? builderClasses : applicationClasses;
820820
destinationMap.put(classesEntries.getKey(), classesEntries.getValue());
821821
}
822-
boolean tolerateViolations = SubstrateOptions.TolerateBuilderClassesOnImageClasspath.getValue(parsedHostedOptions);
822+
boolean tolerateViolations = SubstrateOptions.AllowDeprecatedBuilderClassesOnImageClasspath.getValue(parsedHostedOptions);
823823
MapCursor<URI, EconomicSet<String>> applicationClassesEntries = applicationClasses.getEntries();
824824
while (applicationClassesEntries.advance()) {
825825
var applicationClassContainer = applicationClassesEntries.getKey();
@@ -833,8 +833,8 @@ public void reportBuilderClassesInApplication() {
833833
if (!tolerateViolations) {
834834
String errorMessage = String.join(" ", message,
835835
"This can be caused by a fat-jar that illegally includes svm.jar (or graal-sdk.jar) due to its build-time dependency on it.",
836-
"As a temporary workaround, %s allows turning this error into a warning.");
837-
throw UserError.abort(errorMessage, SubstrateOptionsParser.commandArgument(SubstrateOptions.TolerateBuilderClassesOnImageClasspath, "+"));
836+
"As a workaround, %s allows turning this error into a warning. Note that this option is deprecated and will be removed in a future version.");
837+
throw UserError.abort(errorMessage, SubstrateOptionsParser.commandArgument(SubstrateOptions.AllowDeprecatedBuilderClassesOnImageClasspath, "+"));
838838
} else {
839839
System.out.println("Warning: " + message);
840840
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationOptions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ private static class InitializationValueEager extends InitializationValueTransfo
9191
@Option(help = "A comma-separated list of classes appended with their initialization strategy (':build_time', ':rerun', or ':run_time')", type = OptionType.User)//
9292
public static final HostedOptionKey<LocatableMultiOptionValue.Strings> ClassInitialization = new HostedOptionKey<>(new LocatableMultiOptionValue.Strings());
9393

94+
@Option(help = "Instead of abort, only warn if --initialize-at-build-time= is used.", type = OptionType.Debug)//
95+
public static final HostedOptionKey<Boolean> AllowDeprecatedInitializeAllClassesAtBuildTime = new HostedOptionKey<>(false);
96+
9497
@Option(help = "Prints class initialization info for all classes detected by analysis.", type = OptionType.Debug)//
9598
public static final HostedOptionKey<Boolean> PrintClassInitialization = new HostedOptionKey<>(false);
9699

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/InitKind.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
*/
2525
package com.oracle.svm.hosted.classinitialization;
2626

27-
import static com.oracle.svm.hosted.NativeImageOptions.DiagnosticsMode;
28-
2927
import java.util.Arrays;
3028
import java.util.Optional;
3129
import java.util.function.Consumer;
3230

3331
import org.graalvm.collections.Pair;
3432

3533
import com.oracle.svm.core.option.OptionOrigin;
34+
import com.oracle.svm.core.option.SubstrateOptionsParser;
35+
import com.oracle.svm.core.util.UserError;
3636

3737
/**
3838
* The initialization kind for a class. The order of the enum values matters, {@link #max} depends
@@ -71,12 +71,17 @@ Consumer<String> stringConsumer(ClassInitializationSupport support, OptionOrigin
7171
return name -> support.rerunInitialization(name, reason(origin, name));
7272
} else {
7373
return name -> {
74-
if (name.equals("") && !DiagnosticsMode.getValue()) {
75-
System.err.println(
76-
"--initialize-at-build-time without arguments has been deprecated when not using --diagnostics-mode. With GraalVM 22.0.0" +
77-
" --initialize-at-build-time will only work with --diagnostics-mode for debugging purposes.\n" +
78-
"The reason for deprecation is that --initalize-at-build-time does not compose, i.e., a single library can make assumptions that the whole classpath can be safely initialized at build time;" +
79-
" that assumption is often incorrect.");
74+
if (name.equals("") && !origin.commandLineLike()) {
75+
String msg = "--initialize-at-build-time without arguments is not allowed." + System.lineSeparator() +
76+
"Origin of the option: " + origin + System.lineSeparator() +
77+
"The reason for deprecation is that --initalize-at-build-time does not compose, i.e., a single library can make assumptions that the whole classpath can be safely initialized at build time;" +
78+
" that assumption is often incorrect.";
79+
if (ClassInitializationOptions.AllowDeprecatedInitializeAllClassesAtBuildTime.getValue()) {
80+
System.out.println("Warning: " + msg);
81+
} else {
82+
throw UserError.abort("%s%nAs a workaround, %s allows turning this error into a warning. Note that this option is deprecated and will be removed in a future version.", msg,
83+
SubstrateOptionsParser.commandArgument(ClassInitializationOptions.AllowDeprecatedInitializeAllClassesAtBuildTime, "+"));
84+
}
8085
}
8186
support.initializeAtBuildTime(name, reason(origin, name));
8287
};

0 commit comments

Comments
 (0)