diff --git a/substratevm/CHANGELOG.md b/substratevm/CHANGELOG.md index c582d59de57a..a925c670defb 100644 --- a/substratevm/CHANGELOG.md +++ b/substratevm/CHANGELOG.md @@ -5,6 +5,7 @@ This changelog summarizes major changes to GraalVM Native Image. ## GraalVM for JDK 22 (Internal Version 24.0.0) * (GR-48304) Red Hat added support for the JFR event ThreadAllocationStatistics. * (GR-48343) Red Hat added support for the JFR events AllocationRequiringGC and SystemGC. +* (GR-48612) Enable `--strict-image-heap` by default. The option is now deprecated and can be removed from your argument list. A blog post with more information will follow shortly. ## GraalVM for JDK 21 (Internal Version 23.1.0) * (GR-35746) Lower the default aligned chunk size from 1 MB to 512 KB for the serial and epsilon GCs, reducing memory usage and image size in many cases. diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index 89f5d7cec1c1..9d118dd13a28 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -1520,9 +1520,9 @@ def build_and_test_clinittest_image(native_image, args, new_class_init_policy): mx.ensure_dir_exists(build_dir) if new_class_init_policy: - policy_args = svm_experimental_options(['-H:+StrictImageHeap', '-H:+SimulateClassInitializer']) + ['--features=com.oracle.svm.test.clinit.TestClassInitializationFeatureNewPolicyFeature'] + policy_args = svm_experimental_options(['-H:+SimulateClassInitializer']) + ['--features=com.oracle.svm.test.clinit.TestClassInitializationFeatureNewPolicyFeature'] else: - policy_args = svm_experimental_options(['-H:-SimulateClassInitializer']) + ['--features=com.oracle.svm.test.clinit.TestClassInitializationFeatureOldPolicyFeature'] + policy_args = svm_experimental_options(['-H:-StrictImageHeap', '-H:-SimulateClassInitializer']) + ['--features=com.oracle.svm.test.clinit.TestClassInitializationFeatureOldPolicyFeature'] # Build and run the example binary_path = join(build_dir, 'clinittest') diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporterFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporterFeature.java index 0cdd7e80d321..56bcd223ace1 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporterFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporterFeature.java @@ -37,11 +37,9 @@ import com.oracle.svm.core.feature.InternalFeature; import com.oracle.svm.core.jni.access.JNIAccessibleClass; import com.oracle.svm.core.jni.access.JNIReflectionDictionary; -import com.oracle.svm.core.option.SubstrateOptionsParser; import com.oracle.svm.hosted.FeatureImpl.AfterCompilationAccessImpl; import com.oracle.svm.hosted.FeatureImpl.BeforeImageWriteAccessImpl; import com.oracle.svm.hosted.ProgressReporter.DirectPrinter; -import com.oracle.svm.hosted.classinitialization.ClassInitializationOptions; import com.oracle.svm.hosted.jdk.JNIRegistrationSupport; import com.oracle.svm.hosted.util.CPUTypeAArch64; import com.oracle.svm.hosted.util.CPUTypeAMD64; @@ -92,10 +90,6 @@ public void createAdditionalArtifacts(@SuppressWarnings("unused") BuildArtifacts protected List getRecommendations() { return List.of(// in order of appearance: - new UserRecommendation("INIT", - "Adopt " + SubstrateOptionsParser.commandArgument(ClassInitializationOptions.StrictImageHeap, "+", "strict-image-heap", true, false) + - " to prepare for the next GraalVM release.", - () -> !ClassInitializationOptions.StrictImageHeap.getValue()), new UserRecommendation("AWT", "Use the tracing agent to collect metadata for AWT.", ProgressReporterFeature::recommendTraceAgentForAWT), new UserRecommendation("HEAP", "Set max heap for improved and more predictable memory usage.", () -> SubstrateGCOptions.MaxHeapSize.getValue() == 0), new UserRecommendation("CPU", "Enable more CPU features with '-march=native' for improved performance.", ProgressReporterFeature::recommendMArchNative)); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationFeature.java index 193aa810400e..e1d88d3869d4 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationFeature.java @@ -171,13 +171,12 @@ private Object checkImageHeapInstance(Object obj) { if (ClassInitializationOptions.StrictImageHeap.getValue()) { msg += System.lineSeparator(); msg += """ - If you are seeing this message after enabling %s, this means that some objects ended up in the image heap without their type being marked with --initialize-at-build-time. + If you are seeing this message after upgrading to a new GraalVM release, this means that some objects ended up in the image heap without their type being marked with --initialize-at-build-time. To fix this, include %s in your configuration. If the classes do not originate from your code, it is advised to update all library or framework dependencies to the latest version before addressing this error. - Please address this problem to be prepared for future releases of GraalVM. """ .replaceAll("\n", System.lineSeparator()) .formatted( - SubstrateOptionsParser.commandArgument(ClassInitializationOptions.StrictImageHeap, "+", "strict-image-heap", true, false), + SubstrateOptionsParser.commandArgument(ClassInitializationOptions.StrictImageHeap, "+", true, false), SubstrateOptionsParser.commandArgument(ClassInitializationOptions.ClassInitialization, proxyOrLambda ? proxyLambdaInterfaceCSV : typeName, "initialize-at-build-time", true, false)); } 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 4b2b30c2823c..9636161cb637 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 @@ -37,7 +37,7 @@ import com.oracle.svm.core.option.APIOption; import com.oracle.svm.core.option.HostedOptionKey; import com.oracle.svm.core.option.LocatableMultiOptionValue; -import com.oracle.svm.core.util.UserError; +import com.oracle.svm.util.LogUtils; public final class ClassInitializationOptions { @@ -101,11 +101,12 @@ private static class InitializationValueEager extends InitializationValueTransfo @Option(help = "Assert class initialization is specified for all classes.", type = OptionType.Debug)// public static final HostedOptionKey AssertInitializationSpecifiedForAllClasses = new HostedOptionKey<>(false); - @APIOption(name = "strict-image-heap")// - @Option(help = "Enable the strict image heap mode that allows all classes to be used at build-time but also requires types of all objects in the heap to be explicitly marked for build-time initialization.", type = OptionType.User) // - public static final HostedOptionKey StrictImageHeap = new HostedOptionKey<>(false, k -> { + @APIOption(name = "strict-image-heap", deprecated = "'--strict-image-heap' is now the default. You can remove the option.") // + @Option(help = "Enable the strict image heap mode that allows all classes to be used at build-time but also requires types of all objects in the heap to be explicitly marked for build-time initialization.", // + type = OptionType.User, deprecated = true, deprecationMessage = "The strict image heap mode is now the default. You can remove the option.") // + public static final HostedOptionKey StrictImageHeap = new HostedOptionKey<>(true, k -> { if (k.hasBeenSet() && Boolean.FALSE.equals(k.getValue())) { - throw UserError.abort("Strict image heap mode cannot be explicitly disabled."); + LogUtils.warning("The non-strict image heap mode should be avoided as it is deprecated and marked for removal."); } });