Skip to content

Commit df7bfc1

Browse files
committed
[GR-48612] Enable --strict-image-heap by default.
PullRequest: graal/15624
2 parents a03d99f + a049aab commit df7bfc1

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

substratevm/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This changelog summarizes major changes to GraalVM Native Image.
55
## GraalVM for JDK 22 (Internal Version 24.0.0)
66
* (GR-48304) Red Hat added support for the JFR event ThreadAllocationStatistics.
77
* (GR-48343) Red Hat added support for the JFR events AllocationRequiringGC and SystemGC.
8+
* (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.
89

910
## GraalVM for JDK 21 (Internal Version 23.1.0)
1011
* (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.

substratevm/mx.substratevm/mx_substratevm.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1520,9 +1520,9 @@ def build_and_test_clinittest_image(native_image, args, new_class_init_policy):
15201520
mx.ensure_dir_exists(build_dir)
15211521

15221522
if new_class_init_policy:
1523-
policy_args = svm_experimental_options(['-H:+StrictImageHeap', '-H:+SimulateClassInitializer']) + ['--features=com.oracle.svm.test.clinit.TestClassInitializationFeatureNewPolicyFeature']
1523+
policy_args = svm_experimental_options(['-H:+SimulateClassInitializer']) + ['--features=com.oracle.svm.test.clinit.TestClassInitializationFeatureNewPolicyFeature']
15241524
else:
1525-
policy_args = svm_experimental_options(['-H:-SimulateClassInitializer']) + ['--features=com.oracle.svm.test.clinit.TestClassInitializationFeatureOldPolicyFeature']
1525+
policy_args = svm_experimental_options(['-H:-StrictImageHeap', '-H:-SimulateClassInitializer']) + ['--features=com.oracle.svm.test.clinit.TestClassInitializationFeatureOldPolicyFeature']
15261526

15271527
# Build and run the example
15281528
binary_path = join(build_dir, 'clinittest')

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporterFeature.java

-6
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@
3737
import com.oracle.svm.core.feature.InternalFeature;
3838
import com.oracle.svm.core.jni.access.JNIAccessibleClass;
3939
import com.oracle.svm.core.jni.access.JNIReflectionDictionary;
40-
import com.oracle.svm.core.option.SubstrateOptionsParser;
4140
import com.oracle.svm.hosted.FeatureImpl.AfterCompilationAccessImpl;
4241
import com.oracle.svm.hosted.FeatureImpl.BeforeImageWriteAccessImpl;
4342
import com.oracle.svm.hosted.ProgressReporter.DirectPrinter;
44-
import com.oracle.svm.hosted.classinitialization.ClassInitializationOptions;
4543
import com.oracle.svm.hosted.jdk.JNIRegistrationSupport;
4644
import com.oracle.svm.hosted.util.CPUTypeAArch64;
4745
import com.oracle.svm.hosted.util.CPUTypeAMD64;
@@ -92,10 +90,6 @@ public void createAdditionalArtifacts(@SuppressWarnings("unused") BuildArtifacts
9290

9391
protected List<UserRecommendation> getRecommendations() {
9492
return List.of(// in order of appearance:
95-
new UserRecommendation("INIT",
96-
"Adopt " + SubstrateOptionsParser.commandArgument(ClassInitializationOptions.StrictImageHeap, "+", "strict-image-heap", true, false) +
97-
" to prepare for the next GraalVM release.",
98-
() -> !ClassInitializationOptions.StrictImageHeap.getValue()),
9993
new UserRecommendation("AWT", "Use the tracing agent to collect metadata for AWT.", ProgressReporterFeature::recommendTraceAgentForAWT),
10094
new UserRecommendation("HEAP", "Set max heap for improved and more predictable memory usage.", () -> SubstrateGCOptions.MaxHeapSize.getValue() == 0),
10195
new UserRecommendation("CPU", "Enable more CPU features with '-march=native' for improved performance.", ProgressReporterFeature::recommendMArchNative));

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,12 @@ private Object checkImageHeapInstance(Object obj) {
171171
if (ClassInitializationOptions.StrictImageHeap.getValue()) {
172172
msg += System.lineSeparator();
173173
msg += """
174-
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.
174+
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.
175175
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.
176-
Please address this problem to be prepared for future releases of GraalVM.
177176
"""
178177
.replaceAll("\n", System.lineSeparator())
179178
.formatted(
180-
SubstrateOptionsParser.commandArgument(ClassInitializationOptions.StrictImageHeap, "+", "strict-image-heap", true, false),
179+
SubstrateOptionsParser.commandArgument(ClassInitializationOptions.StrictImageHeap, "+", true, false),
181180
SubstrateOptionsParser.commandArgument(ClassInitializationOptions.ClassInitialization, proxyOrLambda ? proxyLambdaInterfaceCSV : typeName,
182181
"initialize-at-build-time", true, false));
183182
}

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import com.oracle.svm.core.option.APIOption;
3838
import com.oracle.svm.core.option.HostedOptionKey;
3939
import com.oracle.svm.core.option.LocatableMultiOptionValue;
40-
import com.oracle.svm.core.util.UserError;
40+
import com.oracle.svm.util.LogUtils;
4141

4242
public final class ClassInitializationOptions {
4343

@@ -101,11 +101,12 @@ private static class InitializationValueEager extends InitializationValueTransfo
101101
@Option(help = "Assert class initialization is specified for all classes.", type = OptionType.Debug)//
102102
public static final HostedOptionKey<Boolean> AssertInitializationSpecifiedForAllClasses = new HostedOptionKey<>(false);
103103

104-
@APIOption(name = "strict-image-heap")//
105-
@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) //
106-
public static final HostedOptionKey<Boolean> StrictImageHeap = new HostedOptionKey<>(false, k -> {
104+
@APIOption(name = "strict-image-heap", deprecated = "'--strict-image-heap' is now the default. You can remove the option.") //
105+
@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.", //
106+
type = OptionType.User, deprecated = true, deprecationMessage = "The strict image heap mode is now the default. You can remove the option.") //
107+
public static final HostedOptionKey<Boolean> StrictImageHeap = new HostedOptionKey<>(true, k -> {
107108
if (k.hasBeenSet() && Boolean.FALSE.equals(k.getValue())) {
108-
throw UserError.abort("Strict image heap mode cannot be explicitly disabled.");
109+
LogUtils.warning("The non-strict image heap mode should be avoided as it is deprecated and marked for removal.");
109110
}
110111
});
111112

0 commit comments

Comments
 (0)