Search in sources :

Example 11 with CoreProviders

use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.

the class UnsafeVirtualizationTest method testPartialEscapeReadElimination.

public void testPartialEscapeReadElimination(String snippet, boolean canonicalizeBefore, boolean shouldEscapeRead, boolean shouldEscapeWrite, Object... args) {
    assert TestClassInt.fieldOffset1 % 8 == 0 : "First of the two int-fields must be 8-byte aligned";
    ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
    OptionValues options = graph.getOptions();
    CoreProviders context = getDefaultHighTierContext();
    CanonicalizerPhase canonicalizer = createCanonicalizerPhase();
    if (canonicalizeBefore) {
        canonicalizer.apply(graph, context);
    }
    Result r = executeExpected(method, null, args);
    int readCount = graph.getNodes().filter(RawLoadNode.class).count();
    int writeCount = graph.getNodes().filter(RawStoreNode.class).count();
    new PartialEscapePhase(true, true, canonicalizer, null, options).apply(graph, context);
    boolean canVirtualize = true;
    assert graph.getNodes().filter(VirtualObjectNode.class).count() == 1;
    VirtualObjectNode virtual = graph.getNodes().filter(VirtualObjectNode.class).first();
    if (virtual instanceof VirtualArrayNode) {
        VirtualArrayNode array = (VirtualArrayNode) virtual;
        if (array.isVirtualByteArray(context.getMetaAccessExtensionProvider())) {
            canVirtualize = context.getPlatformConfigurationProvider().canVirtualizeLargeByteArrayAccess();
        }
    }
    boolean escapeReads = shouldEscapeRead && canVirtualize;
    boolean escapeWrites = shouldEscapeWrite && canVirtualize;
    if (escapeReads) {
        int newCount = graph.getNodes().filter(RawLoadNode.class).count();
        assertTrue(readCount > newCount, "PEA did not escape reads. before: " + readCount + ", after " + newCount);
    }
    if (escapeWrites) {
        int newCount = graph.getNodes().filter(RawStoreNode.class).count();
        assertTrue(writeCount > newCount, "PEA did not escape writes, before: " + writeCount + ", after: " + newCount);
    }
    try {
        InstalledCode code = getCode(method, graph);
        Object result = code.executeVarargs(args);
        assertEquals(r, new Result(result, null));
    } catch (Throwable e) {
        assertFalse(true, e.toString());
    }
}
Also used : RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) PartialEscapePhase(org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase) OptionValues(org.graalvm.compiler.options.OptionValues) VirtualArrayNode(org.graalvm.compiler.nodes.virtual.VirtualArrayNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InstalledCode(jdk.vm.ci.code.InstalledCode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 12 with CoreProviders

use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.

the class UnsafeReadEliminationTest method testPartialEscapeReadElimination.

public void testPartialEscapeReadElimination(StructuredGraph graph, int reads, int writes) {
    OptionValues options = graph.getOptions();
    CoreProviders context = getDefaultHighTierContext();
    CanonicalizerPhase canonicalizer = createCanonicalizerPhase();
    canonicalizer.apply(graph, context);
    new PartialEscapePhase(true, true, canonicalizer, null, options).apply(graph, context);
    Assert.assertEquals(3, graph.getNodes().filter(UnsafeAccessNode.class).count());
    // after lowering the same applies for reads and writes
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    canonicalizer.apply(graph, context);
    new PartialEscapePhase(true, true, canonicalizer, null, options).apply(graph, context);
    Assert.assertEquals(reads, graph.getNodes().filter(ReadNode.class).count());
    Assert.assertEquals(writes, graph.getNodes().filter(WriteNode.class).count());
}
Also used : CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) PartialEscapePhase(org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase) OptionValues(org.graalvm.compiler.options.OptionValues) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 13 with CoreProviders

use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.

the class IfNodeCanonicalizationTest method test.

public void test(String name, Class<? extends Node> expectedClass, int expectedCount) {
    StructuredGraph graph = parseEager(name, AllowAssumptions.YES);
    CoreProviders context = getProviders();
    CanonicalizerPhase canonicalizer = createCanonicalizerPhase();
    new ConvertDeoptimizeToGuardPhase().apply(graph, context);
    graph.clearAllStateAfterForTestingOnly();
    graph.setGuardsStage(StructuredGraph.GuardsStage.AFTER_FSA);
    canonicalizer.apply(graph, context);
    new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
    canonicalizer.apply(graph, context);
    canonicalizer.apply(graph, context);
    Assert.assertEquals(expectedCount, graph.getNodes().filter(expectedClass).count());
}
Also used : IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) ConvertDeoptimizeToGuardPhase(org.graalvm.compiler.loop.phases.ConvertDeoptimizeToGuardPhase)

Example 14 with CoreProviders

use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.

the class ConditionAnchoringTest method test.

public void test(String name, int ids) {
    StructuredGraph graph = parseEager(name, AllowAssumptions.YES);
    NodeIterable<RawLoadNode> unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
    assertThat(unsafeNodes, hasCount(1));
    // lower unsafe load
    CoreProviders context = getProviders();
    LoweringPhase lowering = new LoweringPhase(createCanonicalizerPhase(), StandardLoweringStage.HIGH_TIER);
    lowering.apply(graph, context);
    unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
    NodeIterable<ConditionAnchorNode> conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
    NodeIterable<ReadNode> reads = graph.getNodes().filter(ReadNode.class);
    assertThat(unsafeNodes, isEmpty());
    assertThat(conditionAnchors, hasCount(1));
    // 2 * ids id reads, 1 'field' access
    assertThat(reads, hasCount(2 * ids + 1));
    // float reads and canonicalize to give a chance to conditions to GVN
    FloatingReadPhase floatingReadPhase = new FloatingReadPhase();
    floatingReadPhase.apply(graph);
    CanonicalizerPhase canonicalizerPhase = createCanonicalizerPhase();
    canonicalizerPhase.apply(graph, context);
    NodeIterable<FloatingReadNode> floatingReads = graph.getNodes().filter(FloatingReadNode.class);
    // 1 id read, 1 'field' access
    assertThat(floatingReads, hasCount(ids + 1));
    new ConditionalEliminationPhase(false).apply(graph, context);
    floatingReads = graph.getNodes().filter(FloatingReadNode.class).filter(n -> ((FloatingReadNode) n).getLocationIdentity() instanceof ObjectLocationIdentity);
    conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
    assertThat(floatingReads, hasCount(1));
    assertThat(conditionAnchors, isEmpty());
    FloatingReadNode readNode = floatingReads.first();
    assertThat(readNode.getGuard(), instanceOf(BeginNode.class));
    assertThat(readNode.getGuard().asNode().predecessor(), instanceOf(IfNode.class));
}
Also used : RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) Unsafe(sun.misc.Unsafe) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) TruffleGraphBuilderPlugins(org.graalvm.compiler.truffle.compiler.substitutions.TruffleGraphBuilderPlugins) ConditionAnchorNode(org.graalvm.compiler.nodes.ConditionAnchorNode) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) NodeIterableIsEmpty.isEmpty(org.graalvm.compiler.graph.test.matchers.NodeIterableIsEmpty.isEmpty) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) Assert.assertThat(org.junit.Assert.assertThat) InlineInfo.createStandardInlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo) JavaKind(jdk.vm.ci.meta.JavaKind) ObjectLocationIdentity(org.graalvm.compiler.truffle.compiler.nodes.ObjectLocationIdentity) BeginNode(org.graalvm.compiler.nodes.BeginNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) IfNode(org.graalvm.compiler.nodes.IfNode) Test(org.junit.Test) CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) NodeIterable(org.graalvm.compiler.graph.iterators.NodeIterable) NodeIterableCount.hasCount(org.graalvm.compiler.graph.test.matchers.NodeIterableCount.hasCount) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) StandardLoweringStage(org.graalvm.compiler.nodes.spi.LoweringTool.StandardLoweringStage) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ConditionAnchorNode(org.graalvm.compiler.nodes.ConditionAnchorNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ObjectLocationIdentity(org.graalvm.compiler.truffle.compiler.nodes.ObjectLocationIdentity) IfNode(org.graalvm.compiler.nodes.IfNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) BeginNode(org.graalvm.compiler.nodes.BeginNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 15 with CoreProviders

use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.

the class NativeImageGenerator method modifySuites.

@SuppressWarnings("unused")
private static Suites modifySuites(SubstrateBackend backend, Suites suites, FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, SnippetReflectionProvider snippetReflection, boolean hosted, boolean firstTier) {
    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();
    ListIterator<BasePhase<? super HighTierContext>> position;
    if (hosted) {
        position = GraalConfiguration.hostedInstance().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());
    }
    lowTier.addBeforeLast(new OptimizeExceptionPathsPhase());
    BasePhase<CoreProviders> addressLoweringPhase = backend.newAddressLoweringPhase(runtimeCallProviders.getCodeCache());
    if (economy) {
        lowTier.findPhase(ExpandLogicPhase.class, true).add(addressLoweringPhase);
    } else {
        lowTier.findPhase(UseTrappingNullChecksPhase.class).add(addressLoweringPhase);
    }
    if (SubstrateOptions.MultiThreaded.getValue()) {
        /*
             * Graal inserts only loop safepoints. We want a SafepointNode also before every return.
             * Our safepoint insertion phase inserts both kinds of safepoints.
             */
        midTier.findPhase(LoopSafepointInsertionPhase.class).set(new SubstrateSafepointInsertionPhase());
    } 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.removePhase(ConvertDeoptimizeToGuardPhase.class);
        midTier.removePhase(DeoptimizationGroupingPhase.class);
    } else {
        if (economy) {
            ListIterator<BasePhase<? super MidTierContext>> it = midTier.findPhase(FrameStateAssignmentPhase.class);
            it.add(new CollectDeoptimizationSourcePositionsPhase());
            // On SVM, the economy configuration requires a canonicalization run at the end of
            // mid tier.
            it = midTier.findLastPhase();
            it.add(CanonicalizerPhase.create());
        } 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));
    if (hosted && ImageBuildStatistics.Options.CollectImageBuildStatistics.getValue(HostedOptionValues.singleton())) {
        highTier.prependPhase(new ImageBuildStatisticsCounterPhase(ImageBuildStatistics.CheckCountLocation.BEFORE_HIGH_TIER));
        highTier.prependPhase(CanonicalizerPhase.create());
        highTier.findLastPhase().add(CanonicalizerPhase.create());
        highTier.findLastPhase().add(new ImageBuildStatisticsCounterPhase(ImageBuildStatistics.CheckCountLocation.AFTER_HIGH_TIER));
    }
    return suites;
}
Also used : UseTrappingNullChecksPhase(org.graalvm.compiler.phases.common.UseTrappingNullChecksPhase) LowTierContext(org.graalvm.compiler.phases.tiers.LowTierContext) LoopSafepointInsertionPhase(org.graalvm.compiler.phases.common.LoopSafepointInsertionPhase) DeadStoreRemovalPhase(com.oracle.svm.core.graal.phases.DeadStoreRemovalPhase) Providers(org.graalvm.compiler.phases.util.Providers) CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) RemoveUnwindPhase(com.oracle.svm.core.graal.phases.RemoveUnwindPhase) OptimizeExceptionPathsPhase(com.oracle.svm.core.graal.phases.OptimizeExceptionPathsPhase) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) ImageBuildStatisticsCounterPhase(com.oracle.svm.hosted.phases.ImageBuildStatisticsCounterPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) ExpandLogicPhase(org.graalvm.compiler.phases.common.ExpandLogicPhase) SubstrateSafepointInsertionPhase(com.oracle.svm.core.graal.phases.SubstrateSafepointInsertionPhase) CollectDeoptimizationSourcePositionsPhase(com.oracle.svm.core.graal.phases.CollectDeoptimizationSourcePositionsPhase) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) VerifyNoGuardsPhase(com.oracle.svm.hosted.phases.VerifyNoGuardsPhase) BasePhase(org.graalvm.compiler.phases.BasePhase)

Aggregations

CoreProviders (org.graalvm.compiler.nodes.spi.CoreProviders)30 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)25 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)16 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)15 DebugContext (org.graalvm.compiler.debug.DebugContext)9 ConditionalEliminationPhase (org.graalvm.compiler.phases.common.ConditionalEliminationPhase)7 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)7 Test (org.junit.Test)6 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)5 IterativeConditionalEliminationPhase (org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase)5 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)4 MidTierContext (org.graalvm.compiler.phases.tiers.MidTierContext)4 Node (org.graalvm.compiler.graph.Node)3 FloatingReadNode (org.graalvm.compiler.nodes.memory.FloatingReadNode)3 GuardLoweringPhase (org.graalvm.compiler.phases.common.GuardLoweringPhase)3 SchedulePhase (org.graalvm.compiler.phases.schedule.SchedulePhase)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)2 FrameState (org.graalvm.compiler.nodes.FrameState)2