Skip to content

Commit f04a11d

Browse files
author
Michael Haas
committed
Add AOT fallback compilation.
1 parent 831b011 commit f04a11d

File tree

19 files changed

+242
-47
lines changed

19 files changed

+242
-47
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/util/ParallelExecutionException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class ParallelExecutionException extends RuntimeException {
3838
private final List<Throwable> exceptions;
3939

4040
ParallelExecutionException(List<Throwable> exceptions) {
41+
super(exceptions.getFirst().getMessage());
4142
this.exceptions = exceptions;
4243
}
4344

substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/SubstrateAArch64SuitesCreatorProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
public class SubstrateAArch64SuitesCreatorProvider extends SubstrateSuitesCreatorProvider {
3333
public SubstrateAArch64SuitesCreatorProvider() {
3434
super(new AArch64SubstrateSuitesCreator(getHostedCompilerConfiguration()),
35-
new AArch64SubstrateSuitesCreator(new EconomyCompilerConfiguration()));
35+
new AArch64SubstrateSuitesCreator(new EconomyCompilerConfiguration()), new AArch64SubstrateSuitesCreator(getFallbackCompilerConfiguration()));
3636
}
3737
}

substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64SuitesCreatorProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
public class SubstrateAMD64SuitesCreatorProvider extends SubstrateSuitesCreatorProvider {
3232
public SubstrateAMD64SuitesCreatorProvider() {
3333
super(new AMD64SubstrateSuitesCreator(getHostedCompilerConfiguration()),
34-
new AMD64SubstrateSuitesCreator(new EconomyCompilerConfiguration()));
34+
new AMD64SubstrateSuitesCreator(new EconomyCompilerConfiguration()), new AMD64SubstrateSuitesCreator(getFallbackCompilerConfiguration()));
3535
}
3636
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,4 +1697,19 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean o
16971697
}
16981698
}
16991699
};
1700+
1701+
@Option(help = "Fallback to economy mode in case a compilation during native image generation fails.")//
1702+
public static final HostedOptionKey<Boolean> EnableFallbackCompilation = new HostedOptionKey<>(false, SubstrateOptions::validateEnableFallbackCompilation);
1703+
1704+
private static void validateEnableFallbackCompilation(HostedOptionKey<Boolean> optionKey) {
1705+
if (optionKey.getValue() && SubstrateOptions.useEconomyCompilerConfig()) {
1706+
throw UserError.invalidOptionValue(optionKey, true,
1707+
String.format("Combining the option %s with %s is not supported", SubstrateOptionsParser.commandArgument(SubstrateOptions.EnableFallbackCompilation, "+"),
1708+
SubstrateOptionsParser.commandArgument(SubstrateOptions.Optimize, "b")));
1709+
}
1710+
}
1711+
1712+
public static boolean canEnableFallbackCompilation() {
1713+
return !EnableFallbackCompilation.getValue() && !useEconomyCompilerConfig();
1714+
}
17001715
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/feature/InternalFeature.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ default void registerLowerings(RuntimeConfiguration runtimeConfig, OptionValues
9595
* @param suites The Graal compilation suites to add to.
9696
* @param hosted True if registering for ahead-of-time compilation, false if registering for
9797
* runtime compilation.
98+
* @param fallback True if registering for fallback compilation, false otherwise.
9899
*/
99-
default void registerGraalPhases(Providers providers, Suites suites, boolean hosted) {
100+
default void registerGraalPhases(Providers providers, Suites suites, boolean hosted, boolean fallback) {
100101
}
101102

102103
/**

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/GraalConfiguration.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ public Suites createFirstTierSuites(OptionValues options, @SuppressWarnings("unu
124124
return ImageSingletons.lookup(SubstrateSuitesCreatorProvider.class).getFirstTierSuitesCreator().createSuites(options, arch);
125125
}
126126

127+
public Suites createFallbackSuites(OptionValues options, @SuppressWarnings("unused") boolean hosted, Architecture arch) {
128+
return ImageSingletons.lookup(SubstrateSuitesCreatorProvider.class).getFallbackSuitesCreator().createSuites(options, arch);
129+
}
130+
127131
public LIRSuites createLIRSuites(OptionValues options) {
128132
return ImageSingletons.lookup(SubstrateSuitesCreatorProvider.class).getSuitesCreator().createLIRSuites(options);
129133
}
@@ -132,6 +136,10 @@ public LIRSuites createFirstTierLIRSuites(OptionValues options) {
132136
return ImageSingletons.lookup(SubstrateSuitesCreatorProvider.class).getFirstTierSuitesCreator().createLIRSuites(options);
133137
}
134138

139+
public LIRSuites createFallbackLIRSuites(OptionValues options) {
140+
return ImageSingletons.lookup(SubstrateSuitesCreatorProvider.class).getFallbackSuitesCreator().createLIRSuites(options);
141+
}
142+
135143
public String getCompilerConfigurationName() {
136144
return COMPILER_CONFIGURATION_NAME;
137145
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/SubstrateSuitesCreatorProvider.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@
2525
*/
2626
package com.oracle.svm.core.graal.code;
2727

28+
import com.oracle.svm.core.SubstrateOptions;
29+
2830
import jdk.graal.compiler.core.phases.CommunityCompilerConfiguration;
2931
import jdk.graal.compiler.core.phases.EconomyCompilerConfiguration;
3032
import jdk.graal.compiler.phases.tiers.CompilerConfiguration;
3133
import jdk.graal.compiler.phases.tiers.SuitesCreator;
3234

33-
import com.oracle.svm.core.SubstrateOptions;
34-
3535
public class SubstrateSuitesCreatorProvider {
3636
private final SuitesCreator suitesCreator;
3737

3838
private final SuitesCreator firstTierSuitesCreator;
3939

40+
private final SuitesCreator fallbackSuitesCreator;
41+
4042
protected static CompilerConfiguration getHostedCompilerConfiguration() {
4143
if (SubstrateOptions.useEconomyCompilerConfig()) {
4244
return new EconomyCompilerConfiguration();
@@ -45,13 +47,23 @@ protected static CompilerConfiguration getHostedCompilerConfiguration() {
4547
}
4648
}
4749

48-
protected SubstrateSuitesCreatorProvider(SuitesCreator suitesCreator, SuitesCreator firstTierSuitesCreator) {
50+
protected static CompilerConfiguration getFallbackCompilerConfiguration() {
51+
return new EconomyCompilerConfiguration();
52+
}
53+
54+
protected SubstrateSuitesCreatorProvider(SuitesCreator suitesCreator, SuitesCreator firstTierSuitesCreator, SuitesCreator fallbackSuitesCreator) {
4955
this.suitesCreator = suitesCreator;
5056
this.firstTierSuitesCreator = firstTierSuitesCreator;
57+
this.fallbackSuitesCreator = fallbackSuitesCreator;
58+
}
59+
60+
protected SubstrateSuitesCreatorProvider(SuitesCreator suitesCreator, SuitesCreator firstTierSuitesCreator) {
61+
this(suitesCreator, firstTierSuitesCreator, new SubstrateSuitesCreator(getFallbackCompilerConfiguration()));
5162
}
5263

5364
public SubstrateSuitesCreatorProvider() {
54-
this(new SubstrateSuitesCreator(getHostedCompilerConfiguration()), new SubstrateSuitesCreator(new EconomyCompilerConfiguration()));
65+
this(new SubstrateSuitesCreator(getHostedCompilerConfiguration()), new SubstrateSuitesCreator(new EconomyCompilerConfiguration()),
66+
new SubstrateSuitesCreator(getFallbackCompilerConfiguration()));
5567
}
5668

5769
public final SuitesCreator getSuitesCreator() {
@@ -61,4 +73,8 @@ public final SuitesCreator getSuitesCreator() {
6173
public final SuitesCreator getFirstTierSuitesCreator() {
6274
return firstTierSuitesCreator;
6375
}
76+
77+
public final SuitesCreator getFallbackSuitesCreator() {
78+
return fallbackSuitesCreator;
79+
}
6480
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/StackOverflowCheckFeature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void afterRegistration(AfterRegistrationAccess access) {
6666
}
6767

6868
@Override
69-
public void registerGraalPhases(Providers providers, Suites suites, boolean hosted) {
69+
public void registerGraalPhases(Providers providers, Suites suites, boolean hosted, boolean fallback) {
7070
/*
7171
* There is no need to have the stack overflow check in the graph throughout most of the
7272
* compilation pipeline. Inserting it before the mid-tier lowering is done for pragmatic

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/stackvalue/StackValueFeature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
@AutomaticallyRegisteredFeature
5050
public class StackValueFeature implements InternalFeature {
5151
@Override
52-
public void registerGraalPhases(Providers providers, Suites suites, boolean hosted) {
52+
public void registerGraalPhases(Providers providers, Suites suites, boolean hosted, boolean fallback) {
5353
ListIterator<BasePhase<? super MidTierContext>> midTierPos = suites.getMidTier().findPhase(FrameStateAssignmentPhase.class);
5454
midTierPos.previous();
5555
midTierPos.add(new StackValueRecursionDepthPhase());

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

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ public static Suites createSuites(FeatureHandler featureHandler, RuntimeConfigur
15781578
} else {
15791579
suites = GraalConfiguration.runtimeInstance().createSuites(optionsToUse == null ? RuntimeOptionValues.singleton() : optionsToUse, hosted, ConfigurationValues.getTarget().arch);
15801580
}
1581-
return modifySuites(backend, suites, featureHandler, hosted, false);
1581+
return modifySuites(backend, suites, featureHandler, hosted, false, false);
15821582
}
15831583

15841584
public static Suites createSuites(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, boolean hosted) {
@@ -1593,18 +1593,34 @@ public static Suites createFirstTierSuites(FeatureHandler featureHandler, Runtim
15931593
} else {
15941594
suites = GraalConfiguration.runtimeInstance().createFirstTierSuites(RuntimeOptionValues.singleton(), hosted, ConfigurationValues.getTarget().arch);
15951595
}
1596-
return modifySuites(backend, suites, featureHandler, hosted, true);
1596+
return modifySuites(backend, suites, featureHandler, hosted, true, false);
1597+
}
1598+
1599+
/**
1600+
* Creates a fallback set of {@link Suites} for the given environment and configuration. These
1601+
* suites contain fewer optimizations and can be used as a fallback for problematic
1602+
* compilations.
1603+
*/
1604+
public static Suites createFallbackSuites(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, boolean hosted) {
1605+
SubstrateBackend backend = runtimeConfig.getBackendForNormalMethod();
1606+
Suites suites;
1607+
if (hosted) {
1608+
suites = GraalConfiguration.hostedInstance().createFallbackSuites(HostedOptionValues.singleton(), hosted, ConfigurationValues.getTarget().arch);
1609+
} else {
1610+
suites = GraalConfiguration.runtimeInstance().createFallbackSuites(RuntimeOptionValues.singleton(), hosted, ConfigurationValues.getTarget().arch);
1611+
}
1612+
return modifySuites(backend, suites, featureHandler, hosted, false, true);
15971613
}
15981614

15991615
private static Suites modifySuites(SubstrateBackend backend, Suites suites, FeatureHandler featureHandler,
1600-
boolean hosted, boolean firstTier) {
1616+
boolean hosted, boolean firstTier, boolean fallback) {
16011617
Providers runtimeCallProviders = backend.getProviders();
16021618

16031619
PhaseSuite<HighTierContext> highTier = suites.getHighTier();
16041620
PhaseSuite<MidTierContext> midTier = suites.getMidTier();
16051621
PhaseSuite<LowTierContext> lowTier = suites.getLowTier();
16061622

1607-
final boolean economy = firstTier || SubstrateOptions.useEconomyCompilerConfig();
1623+
final boolean economy = firstTier || fallback || SubstrateOptions.useEconomyCompilerConfig();
16081624

16091625
ListIterator<BasePhase<? super HighTierContext>> position;
16101626
if (hosted) {
@@ -1665,7 +1681,7 @@ private static Suites modifySuites(SubstrateBackend backend, Suites suites, Feat
16651681
}
16661682
}
16671683

1668-
featureHandler.forEachGraalFeature(feature -> feature.registerGraalPhases(runtimeCallProviders, suites, hosted));
1684+
featureHandler.forEachGraalFeature(feature -> feature.registerGraalPhases(runtimeCallProviders, suites, hosted, fallback));
16691685

16701686
if (hosted && ImageBuildStatistics.Options.CollectImageBuildStatistics.getValue(HostedOptionValues.singleton())) {
16711687
highTier.prependPhase(new ImageBuildStatisticsCounterPhase(ImageBuildStatistics.CheckCountLocation.BEFORE_HIGH_TIER));
@@ -1735,6 +1751,21 @@ public static LIRSuites createFirstTierLIRSuites(FeatureHandler featureHandler,
17351751
return lirSuites;
17361752
}
17371753

1754+
@SuppressWarnings("unused")
1755+
public static LIRSuites createFallbackLIRSuites(FeatureHandler featureHandler, Providers providers, boolean hosted) {
1756+
LIRSuites lirSuites;
1757+
if (hosted) {
1758+
lirSuites = GraalConfiguration.hostedInstance().createFallbackLIRSuites(HostedOptionValues.singleton());
1759+
lirSuites.getFinalCodeAnalysisStage().appendPhase(new VerifyCFunctionReferenceMapsLIRPhase());
1760+
} else {
1761+
lirSuites = GraalConfiguration.runtimeInstance().createFallbackLIRSuites(RuntimeOptionValues.singleton());
1762+
}
1763+
1764+
/* Add phases that just perform assertion checking. */
1765+
assert addAssertionLIRPhases(lirSuites, hosted);
1766+
return lirSuites;
1767+
}
1768+
17381769
private static boolean addAssertionLIRPhases(LIRSuites lirSuites, boolean hosted) {
17391770
if (hosted) {
17401771
lirSuites.getFinalCodeAnalysisStage().appendPhase(new VerifyDeoptLIRFrameStatesPhase());

0 commit comments

Comments
 (0)