Search in sources :

Example 41 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant 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)

Example 42 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class AheadOfTimeCompilationTest method testPrimitiveClassObject.

@Test
public void testPrimitiveClassObject() {
    StructuredGraph result = compile("getPrimitiveClassObject", false);
    NodeIterable<ConstantNode> filter = getConstantNodes(result);
    assertDeepEquals(1, filter.count());
    JavaConstant c = filter.first().asJavaConstant();
    Assert.assertEquals(getSnippetReflection().asObject(Class.class, c), Integer.TYPE);
    assertDeepEquals(0, result.getNodes().filter(ReadNode.class).count());
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Example 43 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class AheadOfTimeCompilationTest method testBoxedBooleanAOT.

@Test
public void testBoxedBooleanAOT() {
    StructuredGraph result = compile("getBoxedBoolean", true);
    assertDeepEquals(0, result.getNodes().filter(FloatingReadNode.class).count());
    assertDeepEquals(0, result.getNodes(PiNode.TYPE).count());
    assertDeepEquals(1, getConstantNodes(result).count());
    ConstantNode constant = getConstantNodes(result).first();
    assertDeepEquals(JavaKind.Object, constant.getStackKind());
    JavaConstant c = constant.asJavaConstant();
    Assert.assertEquals(getSnippetReflection().asObject(Boolean.class, c), Boolean.TRUE);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Example 44 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class AheadOfTimeCompilationTest method testClassObject.

@Test
public void testClassObject() {
    StructuredGraph result = compile("getClassObject", false);
    NodeIterable<ConstantNode> filter = getConstantNodes(result);
    assertDeepEquals(1, filter.count());
    JavaConstant c = filter.first().asJavaConstant();
    Assert.assertEquals(getSnippetReflection().asObject(Class.class, c), AheadOfTimeCompilationTest.class);
    assertDeepEquals(0, result.getNodes().filter(ReadNode.class).count());
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Example 45 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class InstalledCodeExecuteHelperTest method parse.

@Override
protected StructuredGraph parse(Builder builder, PhaseSuite<HighTierContext> graphBuilderSuite) {
    StructuredGraph graph = super.parse(builder, graphBuilderSuite);
    if (argsToBind != null) {
        ResolvedJavaMethod m = graph.method();
        Object receiver = isStatic(m.getModifiers()) ? null : this;
        Object[] args = argsWithReceiver(receiver, argsToBind);
        JavaType[] parameterTypes = m.toParameterTypes();
        assert parameterTypes.length == args.length;
        for (int i = 0; i < argsToBind.length; i++) {
            ParameterNode param = graph.getParameter(i);
            JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[i].getJavaKind(), argsToBind[i]);
            ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
            param.replaceAtUsages(replacement);
        }
    }
    return graph;
}
Also used : JavaType(jdk.vm.ci.meta.JavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

JavaConstant (jdk.vm.ci.meta.JavaConstant)122 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)33 ValueNode (org.graalvm.compiler.nodes.ValueNode)24 Test (org.junit.Test)19 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)17 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)15 Stamp (org.graalvm.compiler.core.common.type.Stamp)11 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)11 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)11 JavaKind (jdk.vm.ci.meta.JavaKind)10 Constant (jdk.vm.ci.meta.Constant)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)7 Condition (org.graalvm.compiler.core.common.calc.Condition)7 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)6 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)6 LogicNode (org.graalvm.compiler.nodes.LogicNode)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)5 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)5