Search in sources :

Example 6 with Providers

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;
}
Also used : LowTierContext(org.graalvm.compiler.phases.tiers.LowTierContext) HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) RuntimeOptionValues(com.oracle.svm.core.option.RuntimeOptionValues) OptionValues(org.graalvm.compiler.options.OptionValues) StackValuePhase(com.oracle.svm.core.graal.stackvalue.StackValuePhase) CompressEncoding(org.graalvm.compiler.core.common.CompressEncoding) SubstrateAMD64RegisterConfig(com.oracle.svm.core.graal.code.amd64.SubstrateAMD64RegisterConfig) DeadStoreRemovalPhase(com.oracle.svm.core.graal.phases.DeadStoreRemovalPhase) Providers(org.graalvm.compiler.phases.util.Providers) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) RemoveUnwindPhase(com.oracle.svm.core.graal.phases.RemoveUnwindPhase) SubstrateAMD64AddressLowering(com.oracle.svm.core.graal.code.amd64.SubstrateAMD64AddressLowering) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) OptimizeExceptionCallsPhase(com.oracle.svm.core.graal.phases.OptimizeExceptionCallsPhase) BasePhase(org.graalvm.compiler.phases.BasePhase) AddressLoweringPhase(org.graalvm.compiler.phases.common.AddressLoweringPhase) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites) LoopSafepointInsertionPhase(org.graalvm.compiler.phases.common.LoopSafepointInsertionPhase) ConvertDeoptimizeToGuardPhase(org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase) FixReadsPhase(org.graalvm.compiler.phases.common.FixReadsPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) MethodSafepointInsertionPhase(com.oracle.svm.core.graal.phases.MethodSafepointInsertionPhase) DeoptimizationGroupingPhase(org.graalvm.compiler.phases.common.DeoptimizationGroupingPhase) CollectDeoptimizationSourcePositionsPhase(com.oracle.svm.core.graal.phases.CollectDeoptimizationSourcePositionsPhase) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) VerifyNoGuardsPhase(com.oracle.svm.hosted.phases.VerifyNoGuardsPhase)

Example 7 with Providers

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();
}
Also used : SubstrateForeignCallDescriptor(com.oracle.svm.core.snippets.SnippetRuntime.SubstrateForeignCallDescriptor) HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) RuntimeOptionValues(com.oracle.svm.core.option.RuntimeOptionValues) OptionValues(org.graalvm.compiler.options.OptionValues) SubstrateLoweringProvider(com.oracle.svm.core.graal.meta.SubstrateLoweringProvider) DebugHandlersFactory(org.graalvm.compiler.debug.DebugHandlersFactory) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) Node(org.graalvm.compiler.graph.Node) SubstrateForeignCallsProvider(com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider) SubstrateForeignCallLinkage(com.oracle.svm.core.graal.meta.SubstrateForeignCallLinkage) DebugContext(org.graalvm.compiler.debug.DebugContext) Providers(org.graalvm.compiler.phases.util.Providers) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory) SubstrateReplacements(com.oracle.svm.core.graal.meta.SubstrateReplacements) NodeLoweringProvider(com.oracle.svm.core.graal.snippets.NodeLoweringProvider)

Example 8 with Providers

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());
            }
        }
    }
}
Also used : VerifyPhase(org.graalvm.compiler.phases.VerifyPhase) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) RuntimeProvider(org.graalvm.compiler.runtime.RuntimeProvider) IOException(java.io.IOException) Providers(org.graalvm.compiler.phases.util.Providers) ZipFile(java.util.zip.ZipFile) File(java.io.File) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) Test(org.junit.Test)

Example 9 with Providers

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);
    }
}
Also used : AllocatedObjectNode(org.graalvm.compiler.nodes.virtual.AllocatedObjectNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) AbstractNewObjectNode(org.graalvm.compiler.nodes.java.AbstractNewObjectNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) TypeGuardInlineInfo(org.graalvm.compiler.phases.common.inlining.info.TypeGuardInlineInfo) AssumptionInlineInfo(org.graalvm.compiler.phases.common.inlining.info.AssumptionInlineInfo) InlineInfo(org.graalvm.compiler.phases.common.inlining.info.InlineInfo) ExactInlineInfo(org.graalvm.compiler.phases.common.inlining.info.ExactInlineInfo) MultiTypeGuardInlineInfo(org.graalvm.compiler.phases.common.inlining.info.MultiTypeGuardInlineInfo) DebugContext(org.graalvm.compiler.debug.DebugContext) Providers(org.graalvm.compiler.phases.util.Providers) Invoke(org.graalvm.compiler.nodes.Invoke) BailoutException(jdk.vm.ci.code.BailoutException) InlineableGraph(org.graalvm.compiler.phases.common.inlining.info.elem.InlineableGraph) Graph(org.graalvm.compiler.graph.Graph) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError)

Example 10 with Providers

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;
}
Also used : TypeGuardInlineInfo(org.graalvm.compiler.phases.common.inlining.info.TypeGuardInlineInfo) AssumptionInlineInfo(org.graalvm.compiler.phases.common.inlining.info.AssumptionInlineInfo) InlineInfo(org.graalvm.compiler.phases.common.inlining.info.InlineInfo) ExactInlineInfo(org.graalvm.compiler.phases.common.inlining.info.ExactInlineInfo) MultiTypeGuardInlineInfo(org.graalvm.compiler.phases.common.inlining.info.MultiTypeGuardInlineInfo) Providers(org.graalvm.compiler.phases.util.Providers)

Aggregations

Providers (org.graalvm.compiler.phases.util.Providers)18 DebugContext (org.graalvm.compiler.debug.DebugContext)10 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)9 OptionValues (org.graalvm.compiler.options.OptionValues)9 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)8 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)7 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)6 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)6 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)6 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)6 RuntimeProvider (org.graalvm.compiler.runtime.RuntimeProvider)6 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)5 Method (java.lang.reflect.Method)5 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)5 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)5 PhaseSuite (org.graalvm.compiler.phases.PhaseSuite)5 TargetDescription (jdk.vm.ci.code.TargetDescription)4 BytecodeProvider (org.graalvm.compiler.bytecode.BytecodeProvider)4 LoweringProvider (org.graalvm.compiler.nodes.spi.LoweringProvider)3 WordTypes (org.graalvm.compiler.word.WordTypes)3