Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ParallelExecutionException extends RuntimeException {
private final List<Throwable> exceptions;

ParallelExecutionException(List<Throwable> exceptions) {
super(exceptions.getFirst().getMessage());
this.exceptions = exceptions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
public class SubstrateAArch64SuitesCreatorProvider extends SubstrateSuitesCreatorProvider {
public SubstrateAArch64SuitesCreatorProvider() {
super(new AArch64SubstrateSuitesCreator(getHostedCompilerConfiguration()),
new AArch64SubstrateSuitesCreator(new EconomyCompilerConfiguration()));
new AArch64SubstrateSuitesCreator(new EconomyCompilerConfiguration()), new AArch64SubstrateSuitesCreator(getFallbackCompilerConfiguration()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
public class SubstrateAMD64SuitesCreatorProvider extends SubstrateSuitesCreatorProvider {
public SubstrateAMD64SuitesCreatorProvider() {
super(new AMD64SubstrateSuitesCreator(getHostedCompilerConfiguration()),
new AMD64SubstrateSuitesCreator(new EconomyCompilerConfiguration()));
new AMD64SubstrateSuitesCreator(new EconomyCompilerConfiguration()), new AMD64SubstrateSuitesCreator(getFallbackCompilerConfiguration()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1697,4 +1697,19 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean o
}
}
};

@Option(help = "Fallback to economy mode in case a compilation during native image generation fails.")//
public static final HostedOptionKey<Boolean> EnableFallbackCompilation = new HostedOptionKey<>(false, SubstrateOptions::validateEnableFallbackCompilation);

private static void validateEnableFallbackCompilation(HostedOptionKey<Boolean> optionKey) {
if (optionKey.getValue() && SubstrateOptions.useEconomyCompilerConfig()) {
throw UserError.invalidOptionValue(optionKey, true,
String.format("Combining the option %s with %s is not supported", SubstrateOptionsParser.commandArgument(SubstrateOptions.EnableFallbackCompilation, "+"),
SubstrateOptionsParser.commandArgument(SubstrateOptions.Optimize, "b")));
}
}

public static boolean canEnableFallbackCompilation() {
return !EnableFallbackCompilation.getValue() && !useEconomyCompilerConfig();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ default void registerLowerings(RuntimeConfiguration runtimeConfig, OptionValues
* @param suites The Graal compilation suites to add to.
* @param hosted True if registering for ahead-of-time compilation, false if registering for
* runtime compilation.
* @param fallback True if registering for fallback compilation, false otherwise.
*/
default void registerGraalPhases(Providers providers, Suites suites, boolean hosted) {
default void registerGraalPhases(Providers providers, Suites suites, boolean hosted, boolean fallback) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public Suites createFirstTierSuites(OptionValues options, @SuppressWarnings("unu
return ImageSingletons.lookup(SubstrateSuitesCreatorProvider.class).getFirstTierSuitesCreator().createSuites(options, arch);
}

public Suites createFallbackSuites(OptionValues options, @SuppressWarnings("unused") boolean hosted, Architecture arch) {
return ImageSingletons.lookup(SubstrateSuitesCreatorProvider.class).getFallbackSuitesCreator().createSuites(options, arch);
}

public LIRSuites createLIRSuites(OptionValues options) {
return ImageSingletons.lookup(SubstrateSuitesCreatorProvider.class).getSuitesCreator().createLIRSuites(options);
}
Expand All @@ -132,6 +136,10 @@ public LIRSuites createFirstTierLIRSuites(OptionValues options) {
return ImageSingletons.lookup(SubstrateSuitesCreatorProvider.class).getFirstTierSuitesCreator().createLIRSuites(options);
}

public LIRSuites createFallbackLIRSuites(OptionValues options) {
return ImageSingletons.lookup(SubstrateSuitesCreatorProvider.class).getFallbackSuitesCreator().createLIRSuites(options);
}

public String getCompilerConfigurationName() {
return COMPILER_CONFIGURATION_NAME;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@
*/
package com.oracle.svm.core.graal.code;

import com.oracle.svm.core.SubstrateOptions;

import jdk.graal.compiler.core.phases.CommunityCompilerConfiguration;
import jdk.graal.compiler.core.phases.EconomyCompilerConfiguration;
import jdk.graal.compiler.phases.tiers.CompilerConfiguration;
import jdk.graal.compiler.phases.tiers.SuitesCreator;

import com.oracle.svm.core.SubstrateOptions;

public class SubstrateSuitesCreatorProvider {
private final SuitesCreator suitesCreator;

private final SuitesCreator firstTierSuitesCreator;

private final SuitesCreator fallbackSuitesCreator;

protected static CompilerConfiguration getHostedCompilerConfiguration() {
if (SubstrateOptions.useEconomyCompilerConfig()) {
return new EconomyCompilerConfiguration();
Expand All @@ -45,13 +47,23 @@ protected static CompilerConfiguration getHostedCompilerConfiguration() {
}
}

protected SubstrateSuitesCreatorProvider(SuitesCreator suitesCreator, SuitesCreator firstTierSuitesCreator) {
protected static CompilerConfiguration getFallbackCompilerConfiguration() {
return new EconomyCompilerConfiguration();
}

protected SubstrateSuitesCreatorProvider(SuitesCreator suitesCreator, SuitesCreator firstTierSuitesCreator, SuitesCreator fallbackSuitesCreator) {
this.suitesCreator = suitesCreator;
this.firstTierSuitesCreator = firstTierSuitesCreator;
this.fallbackSuitesCreator = fallbackSuitesCreator;
}

protected SubstrateSuitesCreatorProvider(SuitesCreator suitesCreator, SuitesCreator firstTierSuitesCreator) {
this(suitesCreator, firstTierSuitesCreator, new SubstrateSuitesCreator(getFallbackCompilerConfiguration()));
}

public SubstrateSuitesCreatorProvider() {
this(new SubstrateSuitesCreator(getHostedCompilerConfiguration()), new SubstrateSuitesCreator(new EconomyCompilerConfiguration()));
this(new SubstrateSuitesCreator(getHostedCompilerConfiguration()), new SubstrateSuitesCreator(new EconomyCompilerConfiguration()),
new SubstrateSuitesCreator(getFallbackCompilerConfiguration()));
}

public final SuitesCreator getSuitesCreator() {
Expand All @@ -61,4 +73,8 @@ public final SuitesCreator getSuitesCreator() {
public final SuitesCreator getFirstTierSuitesCreator() {
return firstTierSuitesCreator;
}

public final SuitesCreator getFallbackSuitesCreator() {
return fallbackSuitesCreator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void afterRegistration(AfterRegistrationAccess access) {
}

@Override
public void registerGraalPhases(Providers providers, Suites suites, boolean hosted) {
public void registerGraalPhases(Providers providers, Suites suites, boolean hosted, boolean fallback) {
/*
* There is no need to have the stack overflow check in the graph throughout most of the
* compilation pipeline. Inserting it before the mid-tier lowering is done for pragmatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
@AutomaticallyRegisteredFeature
public class StackValueFeature implements InternalFeature {
@Override
public void registerGraalPhases(Providers providers, Suites suites, boolean hosted) {
public void registerGraalPhases(Providers providers, Suites suites, boolean hosted, boolean fallback) {
ListIterator<BasePhase<? super MidTierContext>> midTierPos = suites.getMidTier().findPhase(FrameStateAssignmentPhase.class);
midTierPos.previous();
midTierPos.add(new StackValueRecursionDepthPhase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ public static Suites createSuites(FeatureHandler featureHandler, RuntimeConfigur
} else {
suites = GraalConfiguration.runtimeInstance().createSuites(optionsToUse == null ? RuntimeOptionValues.singleton() : optionsToUse, hosted, ConfigurationValues.getTarget().arch);
}
return modifySuites(backend, suites, featureHandler, hosted, false);
return modifySuites(backend, suites, featureHandler, hosted, false, false);
}

public static Suites createSuites(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, boolean hosted) {
Expand All @@ -1593,18 +1593,34 @@ public static Suites createFirstTierSuites(FeatureHandler featureHandler, Runtim
} else {
suites = GraalConfiguration.runtimeInstance().createFirstTierSuites(RuntimeOptionValues.singleton(), hosted, ConfigurationValues.getTarget().arch);
}
return modifySuites(backend, suites, featureHandler, hosted, true);
return modifySuites(backend, suites, featureHandler, hosted, true, false);
}

/**
* Creates a fallback set of {@link Suites} for the given environment and configuration. These
* suites contain fewer optimizations and can be used as a fallback for problematic
* compilations.
*/
public static Suites createFallbackSuites(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, boolean hosted) {
SubstrateBackend backend = runtimeConfig.getBackendForNormalMethod();
Suites suites;
if (hosted) {
suites = GraalConfiguration.hostedInstance().createFallbackSuites(HostedOptionValues.singleton(), hosted, ConfigurationValues.getTarget().arch);
} else {
suites = GraalConfiguration.runtimeInstance().createFallbackSuites(RuntimeOptionValues.singleton(), hosted, ConfigurationValues.getTarget().arch);
}
return modifySuites(backend, suites, featureHandler, hosted, false, true);
}

private static Suites modifySuites(SubstrateBackend backend, Suites suites, FeatureHandler featureHandler,
boolean hosted, boolean firstTier) {
boolean hosted, boolean firstTier, boolean fallback) {
Providers runtimeCallProviders = backend.getProviders();

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

final boolean economy = firstTier || SubstrateOptions.useEconomyCompilerConfig();
final boolean economy = firstTier || fallback || SubstrateOptions.useEconomyCompilerConfig();

ListIterator<BasePhase<? super HighTierContext>> position;
if (hosted) {
Expand Down Expand Up @@ -1665,7 +1681,7 @@ private static Suites modifySuites(SubstrateBackend backend, Suites suites, Feat
}
}

featureHandler.forEachGraalFeature(feature -> feature.registerGraalPhases(runtimeCallProviders, suites, hosted));
featureHandler.forEachGraalFeature(feature -> feature.registerGraalPhases(runtimeCallProviders, suites, hosted, fallback));

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

@SuppressWarnings("unused")
public static LIRSuites createFallbackLIRSuites(FeatureHandler featureHandler, Providers providers, boolean hosted) {
LIRSuites lirSuites;
if (hosted) {
lirSuites = GraalConfiguration.hostedInstance().createFallbackLIRSuites(HostedOptionValues.singleton());
lirSuites.getFinalCodeAnalysisStage().appendPhase(new VerifyCFunctionReferenceMapsLIRPhase());
} else {
lirSuites = GraalConfiguration.runtimeInstance().createFallbackLIRSuites(RuntimeOptionValues.singleton());
}

/* Add phases that just perform assertion checking. */
assert addAssertionLIRPhases(lirSuites, hosted);
return lirSuites;
}

private static boolean addAssertionLIRPhases(LIRSuites lirSuites, boolean hosted) {
if (hosted) {
lirSuites.getFinalCodeAnalysisStage().appendPhase(new VerifyDeoptLIRFrameStatesPhase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import com.oracle.svm.core.FallbackExecutor;
import com.oracle.svm.core.JavaMainWrapper;
import com.oracle.svm.core.JavaMainWrapper.JavaMainSupport;
import com.oracle.svm.core.JavaVersionUtil;
import com.oracle.svm.core.OS;
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.option.HostedOptionKey;
Expand All @@ -81,7 +82,6 @@
import com.oracle.svm.util.ReflectionUtil.ReflectionUtilError;

import jdk.graal.compiler.options.OptionValues;
import com.oracle.svm.core.JavaVersionUtil;
import jdk.vm.ci.aarch64.AArch64;
import jdk.vm.ci.amd64.AMD64;
import jdk.vm.ci.code.Architecture;
Expand Down Expand Up @@ -587,15 +587,9 @@ private int buildImage(ImageClassLoader classLoader) {
hasUserError = true;
}
}
if (hasUserError) {
return ExitStatus.BUILDER_ERROR.getValue();
}

if (pee.getExceptions().size() > 1) {
System.out.println(pee.getExceptions().size() + " fatal errors detected:");
}
for (Throwable exception : pee.getExceptions()) {
NativeImageGeneratorRunner.reportFatalError(exception);
if (!hasUserError) {
unhandledThrowable = pee;
}
return ExitStatus.BUILDER_ERROR.getValue();
} catch (Throwable e) {
Expand Down
Loading