Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-47647] [GR-47928] [GR-47692] Fix and improve experimental option handling. #7222

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ def extra_image_build_argument(self, benchmark, args):
'--initialize-at-run-time=io.netty.internal.tcnative.SSL,io.netty.handler.codec.compression.ZstdOptions',
'-H:NativeLinkerOption=-no-pie',
'-H:+AddAllCharsets',
'-H:+ReportExceptionStackTraces',
] + mx_sdk_vm_impl.svm_experimental_options([
'-H:-ParseOnce',
'-H:+AllowFoldMethods',
'-H:+ReportExceptionStackTraces',
'-H:-UseServiceLoaderFeature',
'-H:+AllowDeprecatedBuilderClassesOnImageClasspath', # needs to be removed once GR-41746 is fixed
]) + super(BaseQuarkusBenchmarkSuite, self).extra_image_build_argument(benchmark, args)
Expand Down Expand Up @@ -540,9 +540,9 @@ def extra_image_build_argument(self, benchmark, args):
'io\.netty\.netty-handler',
'/META-INF/native-image/io\.netty/netty-handler/generated/handlers/reflect-config\.json',
'-H:-AddAllCharsets',
'-H:+ReportExceptionStackTraces',
] + mx_sdk_vm_impl.svm_experimental_options([
'-H:+AllowFoldMethods',
'-H:+ReportExceptionStackTraces',
'-H:-UseServiceLoaderFeature',
]) + super(BaseQuarkusBenchmarkSuite,self).extra_image_build_argument(benchmark, args)

Expand Down
1 change: 1 addition & 0 deletions substratevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This changelog summarizes major changes to GraalVM Native Image.
* (GR-46740) Add support for foreign downcalls (part of "Project Panama") on the AMD64 platform.
* (GR-27034) Add `-H:ImageBuildID` option to generate Image Build ID, which is a 128-bit UUID string generated randomly, once per bundle or digest of input args when bundles are not used.
* (GR-47647) Add `-H:±UnlockExperimentalVMOptions` for unlocking access to experimental options similar to HotSpot's `-XX:UnlockExperimentalVMOptions`. Explicit unlocking will be required in a future release, which can be tested with the env setting `NATIVE_IMAGE_EXPERIMENTAL_OPTIONS_ARE_FATAL=true`. For more details, see [issue #7105](https://github.com/oracle/graal/issues/7105).
* (GR-47647) Add `--color[=WHEN]` option to color the output WHEN ('always', 'never', or 'auto'). This API option supersedes the experimental option `-H:+BuildOutputColorful`.

## GraalVM for JDK 17 and GraalVM for JDK 20 (Internal 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.
Expand Down
7 changes: 4 additions & 3 deletions substratevm/mx.substratevm/mx_substratevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ def native_image_context(common_args=None, hosted_assertions=True, native_image_
common_args = [] if common_args is None else common_args
base_args = [
'--no-fallback',
'-H:+ReportExceptionStackTraces',
] + svm_experimental_options([
'-H:+EnforceMaxRuntimeCompileMethods',
'-H:+ReportExceptionStackTraces',
'-H:Path=' + svmbuild_dir(),
])
if mx.get_opts().verbose:
Expand Down Expand Up @@ -1280,10 +1280,11 @@ def _native_image_launcher_extra_jvm_args():
'--add-exports=jdk.internal.vm.ci/jdk.vm.ci.services=ALL-UNNAMED',

'--initialize-at-build-time=org.graalvm.compiler,org.graalvm.libgraal,com.oracle.truffle',

'-H:+ReportExceptionStackTraces',
] + svm_experimental_options([
'-H:-UseServiceLoaderFeature',
'-H:+AllowFoldMethods',
'-H:+ReportExceptionStackTraces',
'-Djdk.vm.ci.services.aot=true',
'-Dtruffle.TruffleRuntime=',
'-H:InitialCollectionPolicy=LibGraal',
Expand Down Expand Up @@ -1517,10 +1518,10 @@ def build_and_test_clinittest_image(native_image, args, new_class_init_policy):
'-J--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED',
'-J-ea', '-J-esa',
'-o', binary_path,
'-H:+ReportExceptionStackTraces',
] + svm_experimental_options([
'-H:Class=com.oracle.svm.test.clinit.TestClassInitialization',
'-H:+PrintClassInitialization',
'-H:+ReportExceptionStackTraces',
]) + policy_args + args)
mx.run([binary_path])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,36 @@ public static void updateMaxJavaStackTraceDepth(EconomicMap<OptionKey<?>, Object
/*
* Build output options.
*/

@APIOption(name = "color")//
@Option(help = "Color build output ('always', 'never', or 'auto')", type = OptionType.User)//
public static final HostedOptionKey<String> Color = new HostedOptionKey<>("auto");

public static final boolean hasColorsEnabled(OptionValues values) {
if (Color.hasBeenSet(values)) {
String value = Color.getValue(values);
return switch (value) {
case "always" -> true;
case "auto" -> {
/* Fail only when assertions are enabled. */
assert false : "'auto' value should have been resolved in the driver";
yield false;
}
case "never" -> false;
default -> throw UserError.abort("Unsupported value '%s' for '--color' option. Only 'always', 'never', and 'auto' are accepted.", value);
};
}
return false;
}

@APIOption(name = "silent")//
@Option(help = "Silence build output", type = OptionType.User)//
public static final HostedOptionKey<Boolean> BuildOutputSilent = new HostedOptionKey<>(false);

@Option(help = "Prefix build output with '<pid>:<image name>'", type = OptionType.User)//
public static final HostedOptionKey<Boolean> BuildOutputPrefix = new HostedOptionKey<>(false);

@Option(help = "Colorize build output (enabled by default if colors are supported by terminal)", type = OptionType.User)//
@Option(help = "Color build output (enabled by default if colors are supported by terminal)", type = OptionType.User, deprecated = true, deprecationMessage = "Please use the '--color' option.")//
public static final HostedOptionKey<Boolean> BuildOutputColorful = new HostedOptionKey<>(false);

@Option(help = "Show links in build output (defaults to the value of BuildOutputColorful)", type = OptionType.User)//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public void validateExperimentalOptions() {
}

for (var illegalOption : illegalExperimentalOptions) {
LogUtils.warning("The option '" + illegalOption + "' is experimental and must be enabled via " + ENTER_UNLOCK_SCOPE + " in the future.");
LogUtils.warning("The option '" + illegalOption + "' is experimental and must be enabled via '" + ENTER_UNLOCK_SCOPE + "' in the future.");
}
LogUtils.warning("Please re-evaluate whether any experimental option is required, and either remove or unlock it. " +
"The build output lists all active experimental options, including where they come from and possible alternatives. " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.oracle.svm.core.option.OptionOrigin;
import org.graalvm.compiler.options.OptionKey;
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
import org.graalvm.nativeimage.Platform;
Expand All @@ -85,6 +84,7 @@
import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.VM;
import com.oracle.svm.core.option.BundleMember;
import com.oracle.svm.core.option.OptionOrigin;
import com.oracle.svm.core.option.OptionUtils;
import com.oracle.svm.core.util.ClasspathUtils;
import com.oracle.svm.core.util.ExitStatus;
Expand Down Expand Up @@ -249,7 +249,7 @@ private static <T> String oR(OptionKey<T> option) {
final String oHName = oH(SubstrateOptions.Name);
final String oHPath = oH(SubstrateOptions.Path);
final String oHEnableSharedLibraryFlagPrefix = oHEnabled + SubstrateOptions.SharedLibrary.getName();
final String oHEnableBuildOutputColorful = oHEnabledByDriver(SubstrateOptions.BuildOutputColorful);
final String oHColor = oH(SubstrateOptions.Color);
final String oHEnableBuildOutputProgress = oHEnabledByDriver(SubstrateOptions.BuildOutputProgress);
final String oHEnableBuildOutputLinks = oHEnabledByDriver(SubstrateOptions.BuildOutputLinks);
final String oHCLibraryPath = oH(SubstrateOptions.CLibraryPath);
Expand Down Expand Up @@ -2310,17 +2310,27 @@ private static boolean logRedirectedToFile() {

private boolean configureBuildOutput() {
boolean useColorfulOutput = false;
Boolean buildOutputColorfulValue = getHostedOptionFinalBooleanArgumentValue(imageBuilderArgs, SubstrateOptions.BuildOutputColorful);
if (buildOutputColorfulValue != null) {
useColorfulOutput = buildOutputColorfulValue; // use value set by user
} else if (hasColorSupport()) {
useColorfulOutput = true;
addPlainImageBuilderArg(oHEnableBuildOutputColorful);
String colorValue = getHostedOptionFinalArgumentValue(imageBuilderArgs, oHColor);
if (colorValue != null) { // use value set by user
if ("always".equals(colorValue)) {
useColorfulOutput = true;
} else if ("auto".equals(colorValue)) {
useColorfulOutput = hasColorSupport();
addPlainImageBuilderArg(injectHostedOptionOrigin(oHColor + (useColorfulOutput ? "always" : "never"), OptionOrigin.originDriver));
}
} else {
Boolean buildOutputColorfulValue = getHostedOptionFinalBooleanArgumentValue(imageBuilderArgs, SubstrateOptions.BuildOutputColorful);
if (buildOutputColorfulValue != null) {
useColorfulOutput = buildOutputColorfulValue; // use value set by user
} else if (hasColorSupport()) {
useColorfulOutput = true;
addPlainImageBuilderArg(injectHostedOptionOrigin(oHColor + "always", OptionOrigin.originDriver));
}
}
if (getHostedOptionFinalBooleanArgumentValue(imageBuilderArgs, SubstrateOptions.BuildOutputProgress) == null && hasProgressSupport(imageBuilderArgs)) {
addPlainImageBuilderArg(oHEnableBuildOutputProgress);
}
if (getHostedOptionFinalBooleanArgumentValue(imageBuilderArgs, SubstrateOptions.BuildOutputLinks) == null && buildOutputColorfulValue == null && useColorfulOutput) {
if (getHostedOptionFinalBooleanArgumentValue(imageBuilderArgs, SubstrateOptions.BuildOutputLinks) == null && (colorValue == null || "auto".equals(colorValue)) && useColorfulOutput) {
addPlainImageBuilderArg(oHEnableBuildOutputLinks);
}
return useColorfulOutput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ protected void setupNativeImage(OptionValues options, Map<Method, CEntryPointDat
registerEntryPointStubs(entryPoints);
}

ProgressReporter.singleton().printInitializeEnd(featureHandler.getUserSpecificFeatures());
ProgressReporter.singleton().printInitializeEnd(featureHandler.getUserSpecificFeatures(), loader);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,12 @@ private int buildImage(ImageClassLoader classLoader) {
throw UserError.abort(classLoader.getMainClassNotFoundErrorMessage(className));
} catch (UnsupportedClassVersionError ex) {
if (ex.getMessage().contains("compiled by a more recent version of the Java Runtime")) {
throw UserError.abort(ex, "Unable to load '%s' due to a Java version mismatch.%n" +
throw UserError.abort("Unable to load '%s' due to a Java version mismatch.%n" +
"Please take one of the following actions:%n" +
" 1) Recompile the source files for your application using Java %s, then try running native-image again%n" +
" 2) Use a version of native-image corresponding to the version of Java with which you compiled the source files for your application%n",
className, Runtime.version().feature());
" 2) Use a version of native-image corresponding to the version of Java with which you compiled the source files for your application%n%n" +
"Root cause: %s",
className, Runtime.version().feature(), ex);
} else {
throw UserError.abort(ex.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private static Path expandErrorFile(String errorFile) {
@Option(help = "If an error occurs, save a build error report to this file [default: " + DEFAULT_ERROR_FILE_NAME + "] (%p replaced with pid, %t with timestamp).)")//
public static final HostedOptionKey<String> ErrorFile = new HostedOptionKey<>(DEFAULT_ERROR_FILE_NAME);

@Option(help = "Show exception stack traces for exceptions during image building.)")//
@Option(help = "Show exception stack traces for exceptions during image building.)", stability = OptionStability.STABLE)//
public static final HostedOptionKey<Boolean> ReportExceptionStackTraces = new HostedOptionKey<>(areAssertionsEnabled());

@Option(help = "Maximum number of types allowed in the image. Used for tests where small number of types is necessary.", type = Debug)//
Expand Down
Loading