Search in sources :

Example 51 with ResolvedJavaType

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

the class VerifyUpdateUsages method verify.

@Override
protected boolean verify(StructuredGraph graph, PhaseContext context) {
    if (graph.method().isConstructor()) {
        return true;
    }
    /*
         * There are only two acceptable patterns for methods which update Node inputs, either a
         * single StoreField node and invoke of updateUsages or updateUsagesInterface, or 2
         * StoreFields that come from LoadFields on the same object. Other patterns can be added as
         * needed but it would be best to keep things simple so that verification can be simple.
         */
    List<StoreFieldNode> stores = graph.getNodes().filter(StoreFieldNode.class).snapshot();
    ResolvedJavaType declaringClass = graph.method().getDeclaringClass();
    ResolvedJavaType nodeInputList = context.getMetaAccess().lookupJavaType(NodeInputList.class);
    StoreFieldNode storeField1 = null;
    StoreFieldNode storeField2 = null;
    for (StoreFieldNode store : stores) {
        if (isNodeInput(store.field(), declaringClass, nodeInputList)) {
            if (storeField1 == null) {
                storeField1 = store;
            } else if (storeField2 == null) {
                storeField2 = store;
            } else {
                return false;
            }
        }
    }
    if (storeField1 == null) {
        return true;
    }
    if (storeField2 == null) {
        // Single input field update so just check for updateUsages or updateUsagesInterface
        // call
        ResolvedJavaType node = context.getMetaAccess().lookupJavaType(Node.class);
        for (MethodCallTargetNode call : graph.getNodes().filter(MethodCallTargetNode.class)) {
            ResolvedJavaMethod callee = call.targetMethod();
            if (callee.getDeclaringClass().equals(node) && (callee.getName().equals("updateUsages") || callee.getName().equals("updateUsagesInterface"))) {
                return true;
            }
        }
    } else {
        if (storeField1.value() instanceof LoadFieldNode && storeField2.value() instanceof LoadFieldNode) {
            LoadFieldNode load1 = (LoadFieldNode) storeField1.value();
            LoadFieldNode load2 = (LoadFieldNode) storeField2.value();
            // Check for swapping values within the same object
            if (load1.object() == storeField1.object() && load2.object() == storeField2.object() && storeField1.object() == storeField2.object() && load1.field().equals(storeField2.field()) && load2.field().equals(storeField1.field())) {
                return true;
            }
        }
    }
    return false;
}
Also used : StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 52 with ResolvedJavaType

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

the class VerifyVirtualizableUsage method verifyVirtualizableEffectArguments.

private static void verifyVirtualizableEffectArguments(ResolvedJavaType constantNodeType, ResolvedJavaMethod caller, ResolvedJavaMethod callee, int bciCaller, NodeInputList<? extends Node> arguments, int startIdx) {
    /*
         * Virtualizable.virtualize should never apply effects on the graph during the execution of
         * the call as the handling of loops during pea might be speculative and does not hold. We
         * should only allow nodes changing the graph that do no harm like constants.
         */
    int i = 0;
    for (Node arg : arguments) {
        if (i >= startIdx) {
            Stamp argStamp = ((ValueNode) arg).stamp(NodeView.DEFAULT);
            if (argStamp instanceof ObjectStamp) {
                ObjectStamp objectStamp = (ObjectStamp) argStamp;
                ResolvedJavaType argStampType = objectStamp.type();
                if (!(argStampType.equals(constantNodeType))) {
                    StackTraceElement e = caller.asStackTraceElement(bciCaller);
                    throw new VerificationError("%s:Parameter %d in call to %s (which has effects on the graph) is not a " + "constant and thus not safe to apply during speculative virtualization.", e, i, callee.format("%H.%n(%p)"));
                }
            }
        }
        i++;
    }
}
Also used : Stamp(org.graalvm.compiler.core.common.type.Stamp) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 53 with ResolvedJavaType

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

the class VerifyBailoutUsage method verify.

@Override
protected boolean verify(StructuredGraph graph, PhaseContext context) {
    final ResolvedJavaType bailoutType = context.getMetaAccess().lookupJavaType(BailoutException.class);
    ResolvedJavaMethod caller = graph.method();
    String holderQualified = caller.format("%H");
    String holderUnqualified = caller.format("%h");
    String packageName = holderQualified.substring(0, holderQualified.length() - holderUnqualified.length() - 1);
    if (!matchesPrefix(packageName)) {
        for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
            ResolvedJavaMethod callee = t.targetMethod();
            if (callee.getDeclaringClass().equals(bailoutType)) {
                // we only allow the getter
                if (!callee.getName().equals("isPermanent")) {
                    throw new VerificationError("Call to %s at callsite %s is prohibited. Consider using %s for permanent bailouts or %s for retryables.", callee.format("%H.%n(%p)"), caller.format("%H.%n(%p)"), PermanentBailoutException.class.getName(), RetryableBailoutException.class.getName());
                }
            }
        }
    }
    return true;
}
Also used : RetryableBailoutException(org.graalvm.compiler.core.common.RetryableBailoutException) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) PermanentBailoutException(org.graalvm.compiler.core.common.PermanentBailoutException)

Example 54 with ResolvedJavaType

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

the class VerifyGetOptionsUsage method verify.

@Override
protected boolean verify(StructuredGraph graph, PhaseContext context) {
    MetaAccessProvider metaAccess = context.getMetaAccess();
    ResolvedJavaType canonicalizerToolClass = metaAccess.lookupJavaType(CanonicalizerTool.class);
    boolean hasTool = false;
    try {
        for (ResolvedJavaMethod.Parameter parameter : graph.method().getParameters()) {
            if (parameter.getType().getName().equals(canonicalizerToolClass.getName())) {
                hasTool = true;
                break;
            }
        }
    } catch (MalformedParametersException e) {
    // Lambdas sometimes have malformed parameters so ignore this.
    }
    if (hasTool) {
        ResolvedJavaMethod getOptionsMethod = metaAccess.lookupJavaMethod(lookupMethod(Node.class, "getOptions"));
        for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
            ResolvedJavaMethod callee = t.targetMethod();
            if (callee.equals(getOptionsMethod)) {
                if (hasTool) {
                    throw new VerificationError("Must use CanonicalizerTool.getOptions() instead of Node.getOptions() in method '%s' of class '%s'.", graph.method().getName(), graph.method().getDeclaringClass().getName());
                }
            }
        }
    }
    return true;
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) Node(org.graalvm.compiler.graph.Node) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) MalformedParametersException(java.lang.reflect.MalformedParametersException) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 55 with ResolvedJavaType

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

the class VerifyGraphAddUsage method verify.

@Override
protected boolean verify(StructuredGraph graph, PhaseContext context) {
    boolean allowed = false;
    for (Class<?> cls : ALLOWED_CLASSES) {
        ResolvedJavaType declaringClass = graph.method().getDeclaringClass();
        if (context.getMetaAccess().lookupJavaType(cls).isAssignableFrom(declaringClass)) {
            allowed = true;
        }
    }
    if (!allowed) {
        ResolvedJavaMethod addOrUniqueMethod = context.getMetaAccess().lookupJavaMethod(ADD_OR_UNIQUE);
        for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
            ResolvedJavaMethod callee = t.targetMethod();
            if (callee.equals(addOrUniqueMethod)) {
                ValueNode nodeArgument = t.arguments().get(1);
                EconomicSet<Node> seen = EconomicSet.create();
                checkNonFactory(graph, seen, context, nodeArgument);
            }
        }
    }
    return true;
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) Node(org.graalvm.compiler.graph.Node) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

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