Search in sources :

Example 21 with ResolvedJavaType

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

the class BasicArrayCopyNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode sourcePosition = tool.getAlias(getSourcePosition());
    ValueNode destinationPosition = tool.getAlias(getDestinationPosition());
    ValueNode replacedLength = tool.getAlias(getLength());
    if (sourcePosition.isConstant() && destinationPosition.isConstant() && replacedLength.isConstant()) {
        int srcPosInt = sourcePosition.asJavaConstant().asInt();
        int destPosInt = destinationPosition.asJavaConstant().asInt();
        int len = replacedLength.asJavaConstant().asInt();
        ValueNode destAlias = tool.getAlias(getDestination());
        if (destAlias instanceof VirtualArrayNode) {
            VirtualArrayNode destVirtual = (VirtualArrayNode) destAlias;
            if (len < 0 || !checkBounds(destPosInt, len, destVirtual)) {
                return;
            }
            ValueNode srcAlias = tool.getAlias(getSource());
            if (srcAlias instanceof VirtualObjectNode) {
                if (!(srcAlias instanceof VirtualArrayNode)) {
                    return;
                }
                VirtualArrayNode srcVirtual = (VirtualArrayNode) srcAlias;
                if (destVirtual.componentType().getJavaKind() != srcVirtual.componentType().getJavaKind()) {
                    return;
                }
                if (!checkBounds(srcPosInt, len, srcVirtual)) {
                    return;
                }
                if (!checkEntryTypes(srcPosInt, len, srcVirtual, destVirtual.type().getComponentType(), tool)) {
                    return;
                }
                for (int i = 0; i < len; i++) {
                    tool.setVirtualEntry(destVirtual, destPosInt + i, tool.getEntry(srcVirtual, srcPosInt + i));
                }
                tool.delete();
                DebugContext debug = getDebug();
                if (debug.isLogEnabled()) {
                    debug.log("virtualized arraycopy(%s, %d, %s, %d, %d)", getSource(), srcPosInt, getDestination(), destPosInt, len);
                }
            } else {
                ResolvedJavaType sourceType = StampTool.typeOrNull(srcAlias);
                if (sourceType == null || !sourceType.isArray()) {
                    return;
                }
                ResolvedJavaType sourceComponentType = sourceType.getComponentType();
                ResolvedJavaType destComponentType = destVirtual.type().getComponentType();
                if (!sourceComponentType.equals(destComponentType)) {
                    return;
                }
                for (int i = 0; i < len; i++) {
                    LoadIndexedNode load = new LoadIndexedNode(graph().getAssumptions(), srcAlias, ConstantNode.forInt(i + srcPosInt, graph()), destComponentType.getJavaKind());
                    tool.addNode(load);
                    tool.setVirtualEntry(destVirtual, destPosInt + i, load);
                }
                tool.delete();
            }
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) VirtualArrayNode(org.graalvm.compiler.nodes.virtual.VirtualArrayNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DebugContext(org.graalvm.compiler.debug.DebugContext) AbstractMemoryCheckpoint(org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 22 with ResolvedJavaType

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

the class BasicObjectCloneNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode originalAlias = tool.getAlias(getObject());
    if (originalAlias instanceof VirtualObjectNode) {
        VirtualObjectNode originalVirtual = (VirtualObjectNode) originalAlias;
        if (originalVirtual.type().isCloneableWithAllocation()) {
            ValueNode[] newEntryState = new ValueNode[originalVirtual.entryCount()];
            for (int i = 0; i < newEntryState.length; i++) {
                newEntryState[i] = tool.getEntry(originalVirtual, i);
            }
            VirtualObjectNode newVirtual = originalVirtual.duplicate();
            tool.createVirtualObject(newVirtual, newEntryState, Collections.<MonitorIdNode>emptyList(), false);
            tool.replaceWithVirtual(newVirtual);
        }
    } else {
        ResolvedJavaType type = getConcreteType(originalAlias.stamp(NodeView.DEFAULT));
        if (type != null && !type.isArray()) {
            VirtualInstanceNode newVirtual = createVirtualInstanceNode(type, true);
            ResolvedJavaField[] fields = newVirtual.getFields();
            ValueNode[] state = new ValueNode[fields.length];
            final LoadFieldNode[] loads = new LoadFieldNode[fields.length];
            for (int i = 0; i < fields.length; i++) {
                state[i] = loads[i] = genLoadFieldNode(graph().getAssumptions(), originalAlias, fields[i]);
                tool.addNode(loads[i]);
            }
            tool.createVirtualObject(newVirtual, state, Collections.<MonitorIdNode>emptyList(), false);
            tool.replaceWithVirtual(newVirtual);
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) VirtualInstanceNode(org.graalvm.compiler.nodes.virtual.VirtualInstanceNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 23 with ResolvedJavaType

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

the class UncheckedInterfaceProviderTest method test.

@Test
public void test() {
    StructuredGraph graph = parseEager("snippet", StructuredGraph.AllowAssumptions.YES);
    for (BlackholeNode b : graph.getNodes().filter(BlackholeNode.class)) {
        Assert.assertThat(b.getValue(), is(instanceOf(UncheckedInterfaceProvider.class)));
        Stamp uncheckedStamp = ((UncheckedInterfaceProvider) b.getValue()).uncheckedStamp();
        String context = b.getValue().toString(Verbosity.Debugger);
        Assert.assertNotNull(context, uncheckedStamp);
        ResolvedJavaType uncheckedType = StampTool.typeOrNull(uncheckedStamp);
        ResolvedJavaType type = StampTool.typeOrNull(b.getValue());
        Assert.assertEquals(context, arrayDepth(type), arrayDepth(uncheckedType));
        Assert.assertTrue(context + ": " + type, type == null || type.getElementalType().isJavaLangObject());
        Assert.assertNotNull(context, uncheckedType);
        Assert.assertTrue(context, uncheckedType.getElementalType().isInterface());
    }
}
Also used : BlackholeNode(org.graalvm.compiler.nodes.debug.BlackholeNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Stamp(org.graalvm.compiler.core.common.type.Stamp) UncheckedInterfaceProvider(org.graalvm.compiler.nodes.spi.UncheckedInterfaceProvider) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) Test(org.junit.Test)

Example 24 with ResolvedJavaType

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

the class UncheckedInterfaceProviderTest method arrayDepth.

private static int arrayDepth(ResolvedJavaType type) {
    int depth = 0;
    ResolvedJavaType t = type;
    while (t != null && t.isArray()) {
        depth += 1;
        t = t.getComponentType();
    }
    return depth;
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 25 with ResolvedJavaType

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

Aggregations

ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)161 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)63 ValueNode (org.graalvm.compiler.nodes.ValueNode)60 JavaKind (jdk.vm.ci.meta.JavaKind)25 JavaType (jdk.vm.ci.meta.JavaType)25 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)19 Stamp (org.graalvm.compiler.core.common.type.Stamp)17 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)17 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)16 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)13 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)13 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)13 Signature (jdk.vm.ci.meta.Signature)11 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)11 LogicNode (org.graalvm.compiler.nodes.LogicNode)11 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)11 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)11 ArrayList (java.util.ArrayList)10 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)10 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)9