Skip to content

Commit

Permalink
[GR-41978] Disallow --initialize-at-build-time without arguments.
Browse files Browse the repository at this point in the history
PullRequest: graal/12987
  • Loading branch information
Christian Wimmer committed Oct 26, 2022
2 parents 75cc35c + 8ad5d4e commit 0f76434
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def extra_image_build_argument(self, benchmark, args):
'-H:EnableURLProtocols=http',
'-H:NativeLinkerOption=-no-pie',
'-H:-UseServiceLoaderFeature',
'-H:+TolerateBuilderClassesOnImageClasspath', # needs to be removed once GR-41746 is fixed
'-H:+AllowDeprecatedBuilderClassesOnImageClasspath', # needs to be removed once GR-41746 is fixed
'--add-exports=org.graalvm.sdk/org.graalvm.nativeimage.impl=ALL-UNNAMED',
'--add-exports=org.graalvm.nativeimage.base/com.oracle.svm.util=ALL-UNNAMED',
'--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.configure=ALL-UNNAMED',
Expand Down
3 changes: 2 additions & 1 deletion substratevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
This changelog summarizes major changes to GraalVM Native Image.

## Version 23.0.0
* (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.
* (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.
* (GR-41196) Provide `.debug.svm.imagebuild.*` sections that contain build options and properties used in the build of the image.
* (GR-41978) Disallow `--initialize-at-build-time` without arguments. As a temporary workaround, `-H:+AllowDeprecatedInitializeAllClassesAtBuildTime` allows turning this error into a warning.

## Version 22.3.0
* (GR-35721) Remove old build output style and the `-H:±BuildOutputUseNewStyle` option.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,6 @@ public Boolean getValueOrDefault(UnmodifiableEconomicMap<OptionKey<?>, Object> v
};

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ public void reportBuilderClassesInApplication() {
var destinationMap = builderURILocations.contains(classesEntries.getKey()) ? builderClasses : applicationClasses;
destinationMap.put(classesEntries.getKey(), classesEntries.getValue());
}
boolean tolerateViolations = SubstrateOptions.TolerateBuilderClassesOnImageClasspath.getValue(parsedHostedOptions);
boolean tolerateViolations = SubstrateOptions.AllowDeprecatedBuilderClassesOnImageClasspath.getValue(parsedHostedOptions);
MapCursor<URI, EconomicSet<String>> applicationClassesEntries = applicationClasses.getEntries();
while (applicationClassesEntries.advance()) {
var applicationClassContainer = applicationClassesEntries.getKey();
Expand All @@ -833,8 +833,8 @@ public void reportBuilderClassesInApplication() {
if (!tolerateViolations) {
String errorMessage = String.join(" ", message,
"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.",
"As a temporary workaround, %s allows turning this error into a warning.");
throw UserError.abort(errorMessage, SubstrateOptionsParser.commandArgument(SubstrateOptions.TolerateBuilderClassesOnImageClasspath, "+"));
"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.");
throw UserError.abort(errorMessage, SubstrateOptionsParser.commandArgument(SubstrateOptions.AllowDeprecatedBuilderClassesOnImageClasspath, "+"));
} else {
System.out.println("Warning: " + message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ private static class InitializationValueEager extends InitializationValueTransfo
@Option(help = "A comma-separated list of classes appended with their initialization strategy (':build_time', ':rerun', or ':run_time')", type = OptionType.User)//
public static final HostedOptionKey<LocatableMultiOptionValue.Strings> ClassInitialization = new HostedOptionKey<>(new LocatableMultiOptionValue.Strings());

@Option(help = "Instead of abort, only warn if --initialize-at-build-time= is used.", type = OptionType.Debug)//
public static final HostedOptionKey<Boolean> AllowDeprecatedInitializeAllClassesAtBuildTime = new HostedOptionKey<>(false);

@Option(help = "Prints class initialization info for all classes detected by analysis.", type = OptionType.Debug)//
public static final HostedOptionKey<Boolean> PrintClassInitialization = new HostedOptionKey<>(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
*/
package com.oracle.svm.hosted.classinitialization;

import static com.oracle.svm.hosted.NativeImageOptions.DiagnosticsMode;

import java.util.Arrays;
import java.util.Optional;
import java.util.function.Consumer;

import org.graalvm.collections.Pair;

import com.oracle.svm.core.option.OptionOrigin;
import com.oracle.svm.core.option.SubstrateOptionsParser;
import com.oracle.svm.core.util.UserError;

/**
* The initialization kind for a class. The order of the enum values matters, {@link #max} depends
Expand Down Expand Up @@ -71,12 +71,17 @@ Consumer<String> stringConsumer(ClassInitializationSupport support, OptionOrigin
return name -> support.rerunInitialization(name, reason(origin, name));
} else {
return name -> {
if (name.equals("") && !DiagnosticsMode.getValue()) {
System.err.println(
"--initialize-at-build-time without arguments has been deprecated when not using --diagnostics-mode. With GraalVM 22.0.0" +
" --initialize-at-build-time will only work with --diagnostics-mode for debugging purposes.\n" +
"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;" +
" that assumption is often incorrect.");
if (name.equals("") && !origin.commandLineLike()) {
String msg = "--initialize-at-build-time without arguments is not allowed." + System.lineSeparator() +
"Origin of the option: " + origin + System.lineSeparator() +
"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;" +
" that assumption is often incorrect.";
if (ClassInitializationOptions.AllowDeprecatedInitializeAllClassesAtBuildTime.getValue()) {
System.out.println("Warning: " + msg);
} else {
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,
SubstrateOptionsParser.commandArgument(ClassInitializationOptions.AllowDeprecatedInitializeAllClassesAtBuildTime, "+"));
}
}
support.initializeAtBuildTime(name, reason(origin, name));
};
Expand Down

0 comments on commit 0f76434

Please sign in to comment.