use of org.graalvm.compiler.phases.util.Providers in project graal by oracle.
the class NativeImageGenerator method createSuites.
public static Suites createSuites(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, SnippetReflectionProvider snippetReflection, boolean hosted) {
Providers runtimeCallProviders = runtimeConfig.getBackendForNormalMethod().getProviders();
OptionValues options = hosted ? HostedOptionValues.singleton() : RuntimeOptionValues.singleton();
Suites suites = GraalConfiguration.instance().createSuites(options, hosted);
PhaseSuite<HighTierContext> highTier = suites.getHighTier();
PhaseSuite<MidTierContext> midTier = suites.getMidTier();
PhaseSuite<LowTierContext> lowTier = suites.getLowTier();
ListIterator<BasePhase<? super HighTierContext>> position;
if (hosted) {
position = GraalConfiguration.instance().createHostedInliners(highTier);
} else {
/* Find the runtime inliner. */
position = highTier.findPhase(InliningPhase.class);
}
if (position != null) {
/* These two phases must be after all method inlining. */
position.add(new DeadStoreRemovalPhase());
position.add(new RemoveUnwindPhase());
} else {
/* There is no inlining, so prepend them in reverse order. */
highTier.prependPhase(new RemoveUnwindPhase());
highTier.prependPhase(new DeadStoreRemovalPhase());
}
highTier.appendPhase(new StackValuePhase());
lowTier.addBeforeLast(new OptimizeExceptionCallsPhase());
CompressEncoding compressEncoding = ImageSingletons.lookup(CompressEncoding.class);
SubstrateAMD64RegisterConfig registerConfig = (SubstrateAMD64RegisterConfig) runtimeCallProviders.getCodeCache().getRegisterConfig();
SubstrateAMD64AddressLowering addressLowering = new SubstrateAMD64AddressLowering(compressEncoding, registerConfig);
lowTier.findPhase(FixReadsPhase.class).add(new AddressLoweringPhase(addressLowering));
if (SubstrateOptions.MultiThreaded.getValue()) {
/*
* Graal inserts only loop safepoints. We want a SafepointNode also before every return.
*/
midTier.findPhase(LoopSafepointInsertionPhase.class).add(new MethodSafepointInsertionPhase());
} else {
/* No need for safepoints when we have only one thread. */
VMError.guarantee(midTier.removePhase(LoopSafepointInsertionPhase.class));
}
if (hosted) {
lowTier.appendPhase(new VerifyNoGuardsPhase());
/* Disable the Graal method inlining, since we have our own inlining system. */
highTier.removePhase(InliningPhase.class);
/* Remove phases that are not suitable for AOT compilation. */
highTier.findPhase(ConvertDeoptimizeToGuardPhase.class, true).remove();
midTier.findPhase(DeoptimizationGroupingPhase.class).remove();
} else {
ListIterator<BasePhase<? super MidTierContext>> it = midTier.findPhase(DeoptimizationGroupingPhase.class);
it.previous();
it.add(new CollectDeoptimizationSourcePositionsPhase());
}
featureHandler.forEachGraalFeature(feature -> feature.registerGraalPhases(runtimeCallProviders, snippetReflection, suites, hosted));
return suites;
}
use of org.graalvm.compiler.phases.util.Providers in project graal by oracle.
the class NativeImageGenerator method registerReplacements.
@SuppressWarnings("try")
public static void registerReplacements(DebugContext debug, FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, Providers providers, SnippetReflectionProvider snippetReflection, boolean hosted) {
OptionValues options = hosted ? HostedOptionValues.singleton() : RuntimeOptionValues.singleton();
Providers runtimeCallProviders = runtimeConfig != null ? runtimeConfig.getBackendForNormalMethod().getProviders() : providers;
SubstrateForeignCallsProvider foreignCallsProvider = (SubstrateForeignCallsProvider) providers.getForeignCalls();
for (SubstrateForeignCallDescriptor descriptor : SnippetRuntime.getRuntimeCalls()) {
foreignCallsProvider.getForeignCalls().put(descriptor, new SubstrateForeignCallLinkage(runtimeCallProviders, descriptor));
}
featureHandler.forEachGraalFeature(feature -> feature.registerForeignCalls(runtimeConfig, runtimeCallProviders, snippetReflection, foreignCallsProvider.getForeignCalls(), hosted));
try (DebugContext.Scope s = debug.scope("RegisterLowerings", new DebugDumpScope("RegisterLowerings"))) {
SubstrateLoweringProvider lowerer = (SubstrateLoweringProvider) providers.getLowerer();
Map<Class<? extends Node>, NodeLoweringProvider<?>> lowerings = lowerer.getLowerings();
Iterable<DebugHandlersFactory> factories = runtimeConfig != null ? runtimeConfig.getDebugHandlersFactories() : Collections.singletonList(new GraalDebugHandlersFactory(snippetReflection));
lowerer.setConfiguration(runtimeConfig, options, factories, providers, snippetReflection);
NonSnippetLowerings.registerLowerings(runtimeConfig, options, factories, providers, snippetReflection, lowerings);
ArithmeticSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
MonitorSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
TypeSnippets.registerLowerings(runtimeConfig, options, factories, providers, snippetReflection, lowerings);
ExceptionSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
if (hosted) {
AssertSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
DeoptHostedSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
} else {
DeoptRuntimeSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
}
if (NativeImageOptions.DeoptimizeAll.getValue()) {
DeoptTestSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
}
featureHandler.forEachGraalFeature(feature -> feature.registerLowerings(runtimeConfig, options, factories, providers, snippetReflection, lowerings, hosted));
} catch (Throwable e) {
throw debug.handle(e);
}
SubstrateReplacements replacements = (SubstrateReplacements) providers.getReplacements();
assert checkInvocationPluginMethods(replacements);
replacements.encodeSnippets();
}
use of org.graalvm.compiler.phases.util.Providers in project graal by oracle.
the class ClassfileBytecodeProviderTest method test.
@Test
public void test() {
RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
Providers providers = rt.getHostBackend().getProviders();
MetaAccessProvider metaAccess = providers.getMetaAccess();
Assume.assumeTrue(VerifyPhase.class.desiredAssertionStatus());
String propertyName = Java8OrEarlier ? "sun.boot.class.path" : "jdk.module.path";
String bootclasspath = System.getProperty(propertyName);
Assert.assertNotNull("Cannot find value of " + propertyName, bootclasspath);
for (String path : bootclasspath.split(File.pathSeparator)) {
if (shouldProcess(path)) {
try {
final ZipFile zipFile = new ZipFile(new File(path));
for (final Enumeration<? extends ZipEntry> entry = zipFile.entries(); entry.hasMoreElements(); ) {
final ZipEntry zipEntry = entry.nextElement();
String name = zipEntry.getName();
if (name.endsWith(".class") && !name.equals("module-info.class") && !name.startsWith("META-INF/versions/")) {
String className = name.substring(0, name.length() - ".class".length()).replace('/', '.');
if (isInNativeImage(className)) {
/*
* Native image requires non-graalsdk classes to be present in the
* classpath.
*/
continue;
}
try {
checkClass(metaAccess, getSnippetReflection(), className);
} catch (ClassNotFoundException e) {
throw new AssertionError(e);
}
}
}
} catch (IOException ex) {
Assert.fail(ex.toString());
}
}
}
}
use of org.graalvm.compiler.phases.util.Providers in project graal by oracle.
the class InliningData method doInline.
@SuppressWarnings("try")
private void doInline(CallsiteHolderExplorable callerCallsiteHolder, MethodInvocation calleeInvocation) {
StructuredGraph callerGraph = callerCallsiteHolder.graph();
InlineInfo calleeInfo = calleeInvocation.callee();
try {
try (DebugContext.Scope scope = debug.scope("doInline", callerGraph)) {
EconomicSet<Node> canonicalizedNodes = EconomicSet.create(Equivalence.IDENTITY);
canonicalizedNodes.addAll(calleeInfo.invoke().asNode().usages());
EconomicSet<Node> parameterUsages = calleeInfo.inline(new Providers(context));
canonicalizedNodes.addAll(parameterUsages);
counterInliningRuns.increment(debug);
debug.dump(DebugContext.DETAILED_LEVEL, callerGraph, "after %s", calleeInfo);
Graph.Mark markBeforeCanonicalization = callerGraph.getMark();
canonicalizer.applyIncremental(callerGraph, context, canonicalizedNodes);
// process invokes that are possibly created during canonicalization
for (Node newNode : callerGraph.getNewNodes(markBeforeCanonicalization)) {
if (newNode instanceof Invoke) {
callerCallsiteHolder.pushInvoke((Invoke) newNode);
}
}
callerCallsiteHolder.computeProbabilities();
counterInliningPerformed.increment(debug);
}
} catch (BailoutException bailout) {
throw bailout;
} catch (AssertionError | RuntimeException e) {
throw new GraalError(e).addContext(calleeInfo.toString());
} catch (GraalError e) {
throw e.addContext(calleeInfo.toString());
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.phases.util.Providers in project graal by oracle.
the class InliningData method tryToInline.
/**
* This method attempts:
* <ol>
* <li>to inline at the callsite given by <code>calleeInvocation</code>, where that callsite
* belongs to the {@link CallsiteHolderExplorable} at the top of the {@link #graphQueue}
* maintained in this class.</li>
* <li>otherwise, to devirtualize the callsite in question.</li>
* </ol>
*
* @return true iff inlining was actually performed
*/
private boolean tryToInline(MethodInvocation calleeInvocation, int inliningDepth) {
CallsiteHolderExplorable callerCallsiteHolder = (CallsiteHolderExplorable) currentGraph();
InlineInfo calleeInfo = calleeInvocation.callee();
assert callerCallsiteHolder.containsInvoke(calleeInfo.invoke());
counterInliningConsidered.increment(debug);
if (inliningPolicy.isWorthInlining(context.getReplacements(), calleeInvocation, inliningDepth, true)) {
doInline(callerCallsiteHolder, calleeInvocation);
return true;
}
if (context.getOptimisticOptimizations().devirtualizeInvokes(calleeInfo.graph().getOptions())) {
calleeInfo.tryToDevirtualizeInvoke(new Providers(context));
}
return false;
}
Aggregations