Search in sources :

Example 6 with Assumptions

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

the class PEGraphDecoder method doInline.

protected LoopScope doInline(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, InlineInfo inlineInfo, ValueNode[] arguments) {
    ResolvedJavaMethod inlineMethod = inlineInfo.getMethodToInline();
    EncodedGraph graphToInline = lookupEncodedGraph(inlineMethod, inlineInfo.getOriginalMethod(), inlineInfo.getIntrinsicBytecodeProvider(), graph.trackNodeSourcePosition());
    if (graphToInline == null) {
        return null;
    }
    assert !graph.trackNodeSourcePosition() || graphToInline.trackNodeSourcePosition() : graph + " " + graphToInline;
    if (methodScope.inliningDepth > Options.InliningDepthError.getValue(options)) {
        throw tooDeepInlining(methodScope);
    }
    for (InlineInvokePlugin plugin : inlineInvokePlugins) {
        plugin.notifyBeforeInline(inlineMethod);
    }
    Invoke invoke = invokeData.invoke;
    FixedNode invokeNode = invoke.asNode();
    FixedWithNextNode predecessor = (FixedWithNextNode) invokeNode.predecessor();
    invokeNode.replaceAtPredecessor(null);
    PEMethodScope inlineScope = new PEMethodScope(graph, methodScope, loopScope, graphToInline, inlineMethod, invokeData, methodScope.inliningDepth + 1, loopExplosionPlugin, arguments);
    if (!inlineMethod.isStatic()) {
        if (StampTool.isPointerAlwaysNull(arguments[0])) {
            /*
                 * The receiver is null, so we can unconditionally throw a NullPointerException
                 * instead of performing any inlining.
                 */
            DeoptimizeNode deoptimizeNode = graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.NullCheckException));
            predecessor.setNext(deoptimizeNode);
            finishInlining(inlineScope);
            /* Continue decoding in the caller. */
            return loopScope;
        } else if (!StampTool.isPointerNonNull(arguments[0])) {
            /* The receiver might be null, so we need to insert a null check. */
            PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(inlineScope, predecessor);
            arguments[0] = graphBuilderContext.nullCheckedValue(arguments[0]);
            predecessor = graphBuilderContext.lastInstr;
        }
    }
    LoopScope inlineLoopScope = createInitialLoopScope(inlineScope, predecessor);
    /*
         * The GraphEncoder assigns parameters a nodeId immediately after the fixed nodes.
         * Initializing createdNodes here avoid decoding and immediately replacing the
         * ParameterNodes.
         */
    int firstArgumentNodeId = inlineScope.maxFixedNodeOrderId + 1;
    for (int i = 0; i < arguments.length; i++) {
        inlineLoopScope.createdNodes[firstArgumentNodeId + i] = arguments[i];
    }
    // Copy assumptions from inlinee to caller
    Assumptions assumptions = graph.getAssumptions();
    Assumptions inlinedAssumptions = graphToInline.getAssumptions();
    if (assumptions != null) {
        if (inlinedAssumptions != null) {
            assumptions.record(inlinedAssumptions);
        }
    } else {
        assert inlinedAssumptions == null : String.format("cannot inline graph (%s) which makes assumptions into a graph (%s) that doesn't", inlineMethod, graph);
    }
    // Copy inlined methods from inlinee to caller
    List<ResolvedJavaMethod> inlinedMethods = graphToInline.getInlinedMethods();
    if (inlinedMethods != null) {
        graph.getMethods().addAll(inlinedMethods);
    }
    if (graphToInline.getFields() != null) {
        for (ResolvedJavaField field : graphToInline.getFields()) {
            graph.recordField(field);
        }
    }
    if (graphToInline.hasUnsafeAccess()) {
        graph.markUnsafeAccess();
    }
    /*
         * Do the actual inlining by returning the initial loop scope for the inlined method scope.
         */
    return inlineLoopScope;
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) EncodedGraph(org.graalvm.compiler.nodes.EncodedGraph) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) FixedNode(org.graalvm.compiler.nodes.FixedNode) Invoke(org.graalvm.compiler.nodes.Invoke) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) Assumptions(jdk.vm.ci.meta.Assumptions) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 7 with Assumptions

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

the class MethodHandleNode method getTargetInvokeNode.

/**
 * Helper function to get the {@link InvokeNode} for the targetMethod of a
 * java.lang.invoke.MemberName.
 *
 * @param adder
 * @param target the target, already loaded from the member name node
 *
 * @return invoke node for the member name target
 */
private static InvokeNode getTargetInvokeNode(GraphAdder adder, IntrinsicMethod intrinsicMethod, int bci, StampPair returnStamp, ValueNode[] originalArguments, ResolvedJavaMethod target, ResolvedJavaMethod original) {
    if (target == null) {
        return null;
    }
    // In lambda forms we erase signature types to avoid resolving issues
    // involving class loaders. When we optimize a method handle invoke
    // to a direct call we must cast the receiver and arguments to its
    // actual types.
    Signature signature = target.getSignature();
    final boolean isStatic = target.isStatic();
    final int receiverSkip = isStatic ? 0 : 1;
    Assumptions assumptions = adder.getAssumptions();
    ResolvedJavaMethod realTarget = null;
    if (target.canBeStaticallyBound()) {
        realTarget = target;
    } else {
        ResolvedJavaType targetType = target.getDeclaringClass();
        // Try to bind based on the declaredType
        AssumptionResult<ResolvedJavaMethod> concreteMethod = targetType.findUniqueConcreteMethod(target);
        if (concreteMethod == null) {
            // Try to get the most accurate receiver type
            if (intrinsicMethod == IntrinsicMethod.LINK_TO_VIRTUAL || intrinsicMethod == IntrinsicMethod.LINK_TO_INTERFACE) {
                ValueNode receiver = getReceiver(originalArguments);
                TypeReference receiverType = StampTool.typeReferenceOrNull(receiver.stamp(NodeView.DEFAULT));
                if (receiverType != null) {
                    concreteMethod = receiverType.getType().findUniqueConcreteMethod(target);
                }
            }
        }
        if (concreteMethod != null && concreteMethod.canRecordTo(assumptions)) {
            concreteMethod.recordTo(assumptions);
            realTarget = concreteMethod.getResult();
        }
    }
    if (realTarget != null) {
        // Don't mutate the passed in arguments
        ValueNode[] arguments = originalArguments.clone();
        // Cast receiver to its type.
        if (!isStatic) {
            JavaType receiverType = target.getDeclaringClass();
            maybeCastArgument(adder, arguments, 0, receiverType);
        }
        // Cast reference arguments to its type.
        for (int index = 0; index < signature.getParameterCount(false); index++) {
            JavaType parameterType = signature.getParameterType(index, target.getDeclaringClass());
            maybeCastArgument(adder, arguments, receiverSkip + index, parameterType);
        }
        InvokeNode invoke = createTargetInvokeNode(assumptions, intrinsicMethod, realTarget, original, bci, returnStamp, arguments);
        assert invoke != null : "graph has been modified so this must result an invoke";
        return invoke;
    }
    return null;
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) Signature(jdk.vm.ci.meta.Signature) Assumptions(jdk.vm.ci.meta.Assumptions) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 8 with Assumptions

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

the class LoadMethodNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool) {
    if (hub instanceof LoadHubNode) {
        ValueNode object = ((LoadHubNode) hub).getValue();
        TypeReference type = StampTool.typeReferenceOrNull(object);
        if (type != null) {
            if (type.isExact()) {
                return resolveExactMethod(tool, type.getType());
            }
            Assumptions assumptions = graph().getAssumptions();
            AssumptionResult<ResolvedJavaMethod> resolvedMethod = type.getType().findUniqueConcreteMethod(method);
            if (resolvedMethod != null && resolvedMethod.canRecordTo(assumptions) && !type.getType().isInterface() && method.getDeclaringClass().isAssignableFrom(type.getType())) {
                NodeView view = NodeView.from(tool);
                resolvedMethod.recordTo(assumptions);
                return ConstantNode.forConstant(stamp(view), resolvedMethod.getResult().getEncoding(), tool.getMetaAccess());
            }
        }
    }
    if (hub.isConstant()) {
        return resolveExactMethod(tool, tool.getConstantReflection().asJavaType(hub.asConstant()));
    }
    return this;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) Assumptions(jdk.vm.ci.meta.Assumptions) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) NodeView(org.graalvm.compiler.nodes.NodeView) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 9 with Assumptions

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

the class TypeReference method createTrusted.

/**
 * Create a type reference using the given type with assumptions and trusting interface types.
 */
public static TypeReference createTrusted(Assumptions assumptions, ResolvedJavaType type) {
    if (type == null) {
        return null;
    }
    ResolvedJavaType exactType = type.isLeaf() ? type : null;
    if (exactType == null) {
        Assumptions.AssumptionResult<ResolvedJavaType> leafConcreteSubtype = type.findLeafConcreteSubtype();
        if (leafConcreteSubtype != null && leafConcreteSubtype.canRecordTo(assumptions)) {
            leafConcreteSubtype.recordTo(assumptions);
            exactType = leafConcreteSubtype.getResult();
        }
    }
    if (exactType == null) {
        return new TypeReference(type, false);
    }
    return new TypeReference(exactType, true);
}
Also used : Assumptions(jdk.vm.ci.meta.Assumptions) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Aggregations

Assumptions (jdk.vm.ci.meta.Assumptions)9 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)5 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)5 ValueNode (org.graalvm.compiler.nodes.ValueNode)5 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)4 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)2 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)2 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)2 FixedNode (org.graalvm.compiler.nodes.FixedNode)2 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)2 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)2 LogicNode (org.graalvm.compiler.nodes.LogicNode)2 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)2 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 AllowAssumptions (org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions)2 GuardingNode (org.graalvm.compiler.nodes.extended.GuardingNode)2 Method (java.lang.reflect.Method)1 Assumption (jdk.vm.ci.meta.Assumptions.Assumption)1 LeafType (jdk.vm.ci.meta.Assumptions.LeafType)1