From 43c74c3b1018f8c05bfbbfc615246df9fa9ff047 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Fri, 21 Oct 2022 13:43:12 -0700 Subject: [PATCH 1/2] Rename TolerateBuilderClassesOnImageClasspath to AllowDreprecatedBuilderClassesOnImageClasspath --- java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py | 2 +- substratevm/CHANGELOG.md | 2 +- .../src/com/oracle/svm/core/SubstrateOptions.java | 2 +- .../oracle/svm/hosted/NativeImageClassLoaderSupport.java | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py b/java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py index e06144b61a0c..f4877b043825 100644 --- a/java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py +++ b/java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py @@ -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', diff --git a/substratevm/CHANGELOG.md b/substratevm/CHANGELOG.md index fb21c4e9fcd9..a49aef6695f3 100644 --- a/substratevm/CHANGELOG.md +++ b/substratevm/CHANGELOG.md @@ -3,7 +3,7 @@ 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. ## Version 22.3.0 diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java index e5a15741de31..32ce9b17e6ba 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java @@ -858,6 +858,6 @@ public Boolean getValueOrDefault(UnmodifiableEconomicMap, 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 TolerateBuilderClassesOnImageClasspath = new HostedOptionKey<>(false); + public static final HostedOptionKey AllowDeprecatedBuilderClassesOnImageClasspath = new HostedOptionKey<>(false); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java index fd29913a61bb..acee7873699e 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java @@ -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> applicationClassesEntries = applicationClasses.getEntries(); while (applicationClassesEntries.advance()) { var applicationClassContainer = applicationClassesEntries.getKey(); @@ -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); } From 8ad5d4e8c1aad1d3508722f12b7ca78a7ccd39d1 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Wed, 26 Oct 2022 09:55:36 -0700 Subject: [PATCH 2/2] Disallow --initialize-at-build-time without arguments --- substratevm/CHANGELOG.md | 1 + .../ClassInitializationOptions.java | 3 +++ .../hosted/classinitialization/InitKind.java | 21 ++++++++++++------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/substratevm/CHANGELOG.md b/substratevm/CHANGELOG.md index a49aef6695f3..29d2c50545a7 100644 --- a/substratevm/CHANGELOG.md +++ b/substratevm/CHANGELOG.md @@ -5,6 +5,7 @@ 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:+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. diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationOptions.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationOptions.java index 277cb730b59f..496e30429b3c 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationOptions.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationOptions.java @@ -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 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 AllowDeprecatedInitializeAllClassesAtBuildTime = new HostedOptionKey<>(false); + @Option(help = "Prints class initialization info for all classes detected by analysis.", type = OptionType.Debug)// public static final HostedOptionKey PrintClassInitialization = new HostedOptionKey<>(false); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/InitKind.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/InitKind.java index 8a4941675c4e..74453743a39c 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/InitKind.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/InitKind.java @@ -24,8 +24,6 @@ */ 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; @@ -33,6 +31,8 @@ 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 @@ -71,12 +71,17 @@ Consumer 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)); };