Search in sources :

Example 1 with SubstrateMethodCallTargetNode

use of com.oracle.svm.core.nodes.SubstrateMethodCallTargetNode in project graal by oracle.

the class ExceptionSynthesizer method throwException.

public static void throwException(GraphBuilderContext b, Method throwExceptionMethod, String message) {
    ValueNode messageNode = ConstantNode.forConstant(b.getConstantReflection().forString(message), b.getMetaAccess(), b.getGraph());
    ResolvedJavaMethod exceptionMethod = b.getMetaAccess().lookupJavaMethod(throwExceptionMethod);
    assert exceptionMethod.isStatic();
    StampPair returnStamp = StampFactory.forDeclaredType(b.getGraph().getAssumptions(), exceptionMethod.getSignature().getReturnType(null), false);
    MethodCallTargetNode callTarget = b.add(new SubstrateMethodCallTargetNode(InvokeKind.Static, exceptionMethod, new ValueNode[] { messageNode }, returnStamp, null, null));
    b.add(new InvokeWithExceptionNode(callTarget, null, b.bci()));
    /* The invoked method always throws an exception, i.e., never returns. */
    b.add(new LoweredDeadEndNode());
}
Also used : SubstrateMethodCallTargetNode(com.oracle.svm.core.nodes.SubstrateMethodCallTargetNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) StampPair(org.graalvm.compiler.core.common.type.StampPair) SubstrateMethodCallTargetNode(com.oracle.svm.core.nodes.SubstrateMethodCallTargetNode) LoweredDeadEndNode(com.oracle.svm.core.graal.nodes.LoweredDeadEndNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with SubstrateMethodCallTargetNode

use of com.oracle.svm.core.nodes.SubstrateMethodCallTargetNode in project graal by oracle.

the class DevirtualizeCallsPhase method run.

@Override
protected void run(StructuredGraph graph) {
    for (Invoke invoke : graph.getInvokes()) {
        if (invoke.callTarget() instanceof SubstrateMethodCallTargetNode) {
            SubstrateMethodCallTargetNode callTarget = (SubstrateMethodCallTargetNode) invoke.callTarget();
            if (callTarget.invokeKind().isDirect() && !((HostedMethod) callTarget.targetMethod()).getWrapped().isSimplyImplementationInvoked()) {
                /*
                     * This is a direct call to a method that the static analysis did not see as
                     * invoked. This can happen when the receiver is always null. In most cases, the
                     * method profile also has a length of 0 and the below code to kill the invoke
                     * would trigger. But not all methods have profiles, for example methods with
                     * manually constructed graphs.
                     */
                unreachableInvoke(graph, invoke, callTarget);
                continue;
            }
            JavaMethodProfile methodProfile = callTarget.getMethodProfile();
            if (methodProfile != null) {
                if (methodProfile.getMethods().length == 0) {
                    unreachableInvoke(graph, invoke, callTarget);
                } else if (methodProfile.getMethods().length == 1) {
                    if (callTarget.invokeKind().isIndirect()) {
                        singleCallee((HostedMethod) methodProfile.getMethods()[0].getMethod(), graph, invoke, callTarget);
                    }
                }
            }
        }
    }
}
Also used : HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) SubstrateMethodCallTargetNode(com.oracle.svm.core.nodes.SubstrateMethodCallTargetNode) JavaMethodProfile(jdk.vm.ci.meta.JavaMethodProfile) Invoke(org.graalvm.compiler.nodes.Invoke)

Aggregations

SubstrateMethodCallTargetNode (com.oracle.svm.core.nodes.SubstrateMethodCallTargetNode)2 LoweredDeadEndNode (com.oracle.svm.core.graal.nodes.LoweredDeadEndNode)1 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)1 JavaMethodProfile (jdk.vm.ci.meta.JavaMethodProfile)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 StampPair (org.graalvm.compiler.core.common.type.StampPair)1 Invoke (org.graalvm.compiler.nodes.Invoke)1 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)1