Search in sources :

Example 1 with InlineEverythingPolicy

use of org.graalvm.compiler.phases.common.inlining.policy.InlineEverythingPolicy in project graal by oracle.

the class MarkUnsafeAccessTest method testCompiled.

@Test
public void testCompiled() throws IOException {
    ResolvedJavaMethod getMethod = asResolvedJavaMethod(getMethod(ByteBuffer.class, "get", new Class<?>[] {}));
    ResolvedJavaType mbbClass = getMetaAccess().lookupJavaType(MappedByteBuffer.class);
    ResolvedJavaMethod getMethodImpl = mbbClass.findUniqueConcreteMethod(getMethod).getResult();
    Assert.assertNotNull(getMethodImpl);
    StructuredGraph graph = parseForCompile(getMethodImpl);
    HighTierContext highContext = getDefaultHighTierContext();
    new CanonicalizerPhase().apply(graph, highContext);
    new InliningPhase(new InlineEverythingPolicy(), new CanonicalizerPhase()).apply(graph, highContext);
    InstalledCode compiledCode = getCode(getMethodImpl, graph);
    testMappedByteBuffer(mbb -> {
        try {
            return (byte) compiledCode.executeVarargs(mbb);
        } catch (InvalidInstalledCodeException e) {
            Assert.fail();
            return 0;
        }
    });
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InlineEverythingPolicy(org.graalvm.compiler.phases.common.inlining.policy.InlineEverythingPolicy) InvalidInstalledCodeException(jdk.vm.ci.code.InvalidInstalledCodeException) InstalledCode(jdk.vm.ci.code.InstalledCode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) ByteBuffer(java.nio.ByteBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) Test(org.junit.Test)

Example 2 with InlineEverythingPolicy

use of org.graalvm.compiler.phases.common.inlining.policy.InlineEverythingPolicy in project graal by oracle.

the class WriteBarrierAdditionTest method testHelper.

@SuppressWarnings("try")
private void testHelper(final String snippetName, final int expectedBarriers) throws Exception, SecurityException {
    ResolvedJavaMethod snippet = getResolvedJavaMethod(snippetName);
    DebugContext debug = getDebugContext();
    try (DebugContext.Scope s = debug.scope("WriteBarrierAdditionTest", snippet)) {
        StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO, debug);
        HighTierContext highContext = getDefaultHighTierContext();
        MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
        new InliningPhase(new InlineEverythingPolicy(), new CanonicalizerPhase()).apply(graph, highContext);
        new CanonicalizerPhase().apply(graph, highContext);
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, highContext);
        new GuardLoweringPhase().apply(graph, midContext);
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, midContext);
        new WriteBarrierAdditionPhase(config).apply(graph);
        debug.dump(DebugContext.BASIC_LEVEL, graph, "After Write Barrier Addition");
        int barriers = 0;
        if (config.useG1GC) {
            barriers = graph.getNodes().filter(G1ReferentFieldReadBarrier.class).count() + graph.getNodes().filter(G1PreWriteBarrier.class).count() + graph.getNodes().filter(G1PostWriteBarrier.class).count();
        } else {
            barriers = graph.getNodes().filter(SerialWriteBarrier.class).count();
        }
        if (expectedBarriers != barriers) {
            Assert.assertEquals(getScheduledGraphString(graph), expectedBarriers, barriers);
        }
        for (WriteNode write : graph.getNodes().filter(WriteNode.class)) {
            if (config.useG1GC) {
                if (write.getBarrierType() != BarrierType.NONE) {
                    Assert.assertEquals(1, write.successors().count());
                    Assert.assertTrue(write.next() instanceof G1PostWriteBarrier);
                    Assert.assertTrue(write.predecessor() instanceof G1PreWriteBarrier);
                }
            } else {
                if (write.getBarrierType() != BarrierType.NONE) {
                    Assert.assertEquals(1, write.successors().count());
                    Assert.assertTrue(write.next() instanceof SerialWriteBarrier);
                }
            }
        }
        for (ReadNode read : graph.getNodes().filter(ReadNode.class)) {
            if (read.getBarrierType() != BarrierType.NONE) {
                Assert.assertTrue(read.getAddress() instanceof OffsetAddressNode);
                JavaConstant constDisp = ((OffsetAddressNode) read.getAddress()).getOffset().asJavaConstant();
                Assert.assertNotNull(constDisp);
                Assert.assertEquals(referentOffset, constDisp.asLong());
                Assert.assertTrue(config.useG1GC);
                Assert.assertEquals(BarrierType.PRECISE, read.getBarrierType());
                Assert.assertTrue(read.next() instanceof G1ReferentFieldReadBarrier);
            }
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : InlineEverythingPolicy(org.graalvm.compiler.phases.common.inlining.policy.InlineEverythingPolicy) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) WriteBarrierAdditionPhase(org.graalvm.compiler.hotspot.phases.WriteBarrierAdditionPhase) G1PreWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier) JavaConstant(jdk.vm.ci.meta.JavaConstant) DebugContext(org.graalvm.compiler.debug.DebugContext) SerialWriteBarrier(org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier) G1ReferentFieldReadBarrier(org.graalvm.compiler.hotspot.nodes.G1ReferentFieldReadBarrier) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) G1PostWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)2 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)2 InlineEverythingPolicy (org.graalvm.compiler.phases.common.inlining.policy.InlineEverythingPolicy)2 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)2 ByteBuffer (java.nio.ByteBuffer)1 MappedByteBuffer (java.nio.MappedByteBuffer)1 InstalledCode (jdk.vm.ci.code.InstalledCode)1 InvalidInstalledCodeException (jdk.vm.ci.code.InvalidInstalledCodeException)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 G1PostWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier)1 G1PreWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier)1 G1ReferentFieldReadBarrier (org.graalvm.compiler.hotspot.nodes.G1ReferentFieldReadBarrier)1 SerialWriteBarrier (org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier)1 WriteBarrierAdditionPhase (org.graalvm.compiler.hotspot.phases.WriteBarrierAdditionPhase)1 ReadNode (org.graalvm.compiler.nodes.memory.ReadNode)1 WriteNode (org.graalvm.compiler.nodes.memory.WriteNode)1