Search in sources :

Example 1 with UncheckedInterfaceProvider

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

the class MethodCallTargetNode method simplify.

@Override
public void simplify(SimplifierTool tool) {
    // attempt to devirtualize the call
    if (invoke().getContextMethod() == null) {
        // avoid invokes that have placeholder bcis: they do not have a valid contextType
        assert (invoke().stateAfter() != null && BytecodeFrame.isPlaceholderBci(invoke().stateAfter().bci)) || BytecodeFrame.isPlaceholderBci(invoke().stateDuring().bci);
        return;
    }
    ResolvedJavaType contextType = (invoke().stateAfter() == null && invoke().stateDuring() == null) ? null : invoke().getContextType();
    ResolvedJavaMethod specialCallTarget = findSpecialCallTarget(invokeKind, receiver(), targetMethod, contextType);
    if (specialCallTarget != null) {
        this.setTargetMethod(specialCallTarget);
        setInvokeKind(InvokeKind.Special);
        return;
    }
    Assumptions assumptions = graph().getAssumptions();
    /*
         * Even though we are not registering an assumption (see comment below), the optimization is
         * only valid when speculative optimizations are enabled.
         */
    if (invokeKind().isIndirect() && invokeKind().isInterface() && assumptions != null) {
        // check if the type of the receiver can narrow the result
        ValueNode receiver = receiver();
        // try to turn a interface call into a virtual call
        ResolvedJavaType declaredReceiverType = targetMethod().getDeclaringClass();
        /*
             * We need to check the invoke kind to avoid recursive simplification for virtual
             * interface methods calls.
             */
        if (declaredReceiverType.isInterface()) {
            ResolvedJavaType singleImplementor = declaredReceiverType.getSingleImplementor();
            if (singleImplementor != null && !singleImplementor.equals(declaredReceiverType)) {
                TypeReference speculatedType = TypeReference.createTrusted(assumptions, singleImplementor);
                if (tryCheckCastSingleImplementor(receiver, speculatedType)) {
                    return;
                }
            }
        }
        if (receiver instanceof UncheckedInterfaceProvider) {
            UncheckedInterfaceProvider uncheckedInterfaceProvider = (UncheckedInterfaceProvider) receiver;
            Stamp uncheckedStamp = uncheckedInterfaceProvider.uncheckedStamp();
            if (uncheckedStamp != null) {
                TypeReference speculatedType = StampTool.typeReferenceOrNull(uncheckedStamp);
                if (speculatedType != null) {
                    tryCheckCastSingleImplementor(receiver, speculatedType);
                }
            }
        }
    }
}
Also used : Stamp(org.graalvm.compiler.core.common.type.Stamp) Assumptions(jdk.vm.ci.meta.Assumptions) ValueNode(org.graalvm.compiler.nodes.ValueNode) UncheckedInterfaceProvider(org.graalvm.compiler.nodes.spi.UncheckedInterfaceProvider) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with UncheckedInterfaceProvider

use of org.graalvm.compiler.nodes.spi.UncheckedInterfaceProvider 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 3 with UncheckedInterfaceProvider

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

the class VerifyUsageWithEquals method isAssignableToRestrictedType.

/**
 * Determines whether the type of {@code node} is assignable to the {@link #restrictedClass}.
 */
private boolean isAssignableToRestrictedType(ValueNode node, MetaAccessProvider metaAccess) {
    if (node.stamp(NodeView.DEFAULT) instanceof ObjectStamp) {
        ResolvedJavaType restrictedType = metaAccess.lookupJavaType(restrictedClass);
        ResolvedJavaType nodeType = StampTool.typeOrNull(node);
        if (nodeType == null && node instanceof LoadFieldNode) {
            nodeType = (ResolvedJavaType) ((LoadFieldNode) node).field().getType();
        }
        if (nodeType == null && node instanceof Invoke) {
            ResolvedJavaMethod target = ((Invoke) node).callTarget().targetMethod();
            nodeType = (ResolvedJavaType) target.getSignature().getReturnType(target.getDeclaringClass());
        }
        if (nodeType == null && node instanceof UncheckedInterfaceProvider) {
            nodeType = StampTool.typeOrNull(((UncheckedInterfaceProvider) node).uncheckedStamp());
        }
        if (nodeType != null && restrictedType.isAssignableFrom(nodeType)) {
            return true;
        }
    }
    return false;
}
Also used : ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) UncheckedInterfaceProvider(org.graalvm.compiler.nodes.spi.UncheckedInterfaceProvider) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Invoke(org.graalvm.compiler.nodes.Invoke)

Aggregations

ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)3 UncheckedInterfaceProvider (org.graalvm.compiler.nodes.spi.UncheckedInterfaceProvider)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 Stamp (org.graalvm.compiler.core.common.type.Stamp)2 Assumptions (jdk.vm.ci.meta.Assumptions)1 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)1 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)1 Invoke (org.graalvm.compiler.nodes.Invoke)1 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 BlackholeNode (org.graalvm.compiler.nodes.debug.BlackholeNode)1 LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)1 Test (org.junit.Test)1