Search in sources :

Example 16 with TypeReference

use of org.graalvm.compiler.core.common.type.TypeReference in project graal by oracle.

the class BytecodeParser method createExceptionDispatch.

private void createExceptionDispatch(ExceptionDispatchBlock block) {
    lastInstr = finishInstruction(lastInstr, frameState);
    assert frameState.stackSize() == 1 : frameState;
    if (block.handler.isCatchAll()) {
        assert block.getSuccessorCount() == 1;
        appendGoto(block.getSuccessor(0));
        return;
    }
    JavaType catchType = block.handler.getCatchType();
    if (graphBuilderConfig.eagerResolving()) {
        catchType = lookupType(block.handler.catchTypeCPI(), INSTANCEOF);
    }
    if (catchType instanceof ResolvedJavaType) {
        TypeReference checkedCatchType = TypeReference.createTrusted(graph.getAssumptions(), (ResolvedJavaType) catchType);
        if (graphBuilderConfig.getSkippedExceptionTypes() != null) {
            for (ResolvedJavaType skippedType : graphBuilderConfig.getSkippedExceptionTypes()) {
                if (skippedType.isAssignableFrom(checkedCatchType.getType())) {
                    BciBlock nextBlock = block.getSuccessorCount() == 1 ? blockMap.getUnwindBlock() : block.getSuccessor(1);
                    ValueNode exception = frameState.stack[0];
                    FixedNode trueSuccessor = graph.add(new DeoptimizeNode(InvalidateReprofile, UnreachedCode));
                    FixedNode nextDispatch = createTarget(nextBlock, frameState);
                    append(new IfNode(graph.addOrUniqueWithInputs(createInstanceOf(checkedCatchType, exception)), trueSuccessor, nextDispatch, 0));
                    return;
                }
            }
        }
        BciBlock nextBlock = block.getSuccessorCount() == 1 ? blockMap.getUnwindBlock() : block.getSuccessor(1);
        ValueNode exception = frameState.stack[0];
        /* Anchor for the piNode, which must be before any LoopExit inserted by createTarget. */
        BeginNode piNodeAnchor = graph.add(new BeginNode());
        ObjectStamp checkedStamp = StampFactory.objectNonNull(checkedCatchType);
        PiNode piNode = graph.addWithoutUnique(new PiNode(exception, checkedStamp));
        frameState.pop(JavaKind.Object);
        frameState.push(JavaKind.Object, piNode);
        FixedNode catchSuccessor = createTarget(block.getSuccessor(0), frameState);
        frameState.pop(JavaKind.Object);
        frameState.push(JavaKind.Object, exception);
        FixedNode nextDispatch = createTarget(nextBlock, frameState);
        piNodeAnchor.setNext(catchSuccessor);
        IfNode ifNode = append(new IfNode(graph.unique(createInstanceOf(checkedCatchType, exception)), piNodeAnchor, nextDispatch, 0.5));
        assert ifNode.trueSuccessor() == piNodeAnchor;
        piNode.setGuard(ifNode.trueSuccessor());
    } else {
        handleUnresolvedExceptionType(catchType);
    }
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) BeginNode(org.graalvm.compiler.nodes.BeginNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) KillingBeginNode(org.graalvm.compiler.nodes.KillingBeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) PiNode(org.graalvm.compiler.nodes.PiNode) BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 17 with TypeReference

use of org.graalvm.compiler.core.common.type.TypeReference in project graal by oracle.

the class LoadHubNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    if (!GeneratePIC.getValue(tool.getOptions())) {
        ValueNode alias = tool.getAlias(getValue());
        TypeReference type = StampTool.typeReferenceOrNull(alias);
        if (type != null && type.isExact()) {
            tool.replaceWithValue(ConstantNode.forConstant(stamp(NodeView.DEFAULT), tool.getConstantReflectionProvider().asObjectHub(type.getType()), tool.getMetaAccessProvider(), graph()));
        }
    }
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference)

Example 18 with TypeReference

use of org.graalvm.compiler.core.common.type.TypeReference 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 19 with TypeReference

use of org.graalvm.compiler.core.common.type.TypeReference in project graal by oracle.

the class SubstrateObjectCloneNode method genLoadFieldNode.

@Override
protected LoadFieldNode genLoadFieldNode(Assumptions assumptions, ValueNode originalAlias, ResolvedJavaField field) {
    if (field.getJavaKind() == JavaKind.Object && field.getType() instanceof SharedType) {
        /*
             * We have the static analysis to check interface types, e.g.., if a parameter of field
             * has a declared interface type and is assigned something that does not implement the
             * interface, the static analysis reports an error.
             */
        TypeReference trusted = TypeReference.createTrustedWithoutAssumptions((SharedType) field.getType());
        StampPair pair = StampPair.createSingle(StampFactory.object(trusted, false));
        return LoadFieldNode.createOverrideStamp(pair, originalAlias, field);
    } else {
        return super.genLoadFieldNode(assumptions, originalAlias, field);
    }
}
Also used : SharedType(com.oracle.svm.core.meta.SharedType) StampPair(org.graalvm.compiler.core.common.type.StampPair) TypeReference(org.graalvm.compiler.core.common.type.TypeReference)

Example 20 with TypeReference

use of org.graalvm.compiler.core.common.type.TypeReference in project graal by oracle.

the class MethodCallTargetNode method devirtualizeCall.

public static ResolvedJavaMethod devirtualizeCall(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, ResolvedJavaType contextType, Assumptions assumptions, Stamp receiverStamp) {
    TypeReference type = StampTool.typeReferenceOrNull(receiverStamp);
    if (type == null && invokeKind == InvokeKind.Virtual) {
        // For virtual calls, we are guaranteed to receive a correct receiver type.
        type = TypeReference.createTrusted(assumptions, targetMethod.getDeclaringClass());
    }
    if (type != null) {
        /*
             * either the holder class is exact, or the receiver object has an exact type, or it's
             * an array type
             */
        ResolvedJavaMethod resolvedMethod = type.getType().resolveConcreteMethod(targetMethod, contextType);
        if (resolvedMethod != null && (resolvedMethod.canBeStaticallyBound() || type.isExact() || type.getType().isArray())) {
            return resolvedMethod;
        }
        AssumptionResult<ResolvedJavaMethod> uniqueConcreteMethod = type.getType().findUniqueConcreteMethod(targetMethod);
        if (uniqueConcreteMethod != null && uniqueConcreteMethod.canRecordTo(assumptions)) {
            uniqueConcreteMethod.recordTo(assumptions);
            return uniqueConcreteMethod.getResult();
        }
    }
    return null;
}
Also used : TypeReference(org.graalvm.compiler.core.common.type.TypeReference) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

TypeReference (org.graalvm.compiler.core.common.type.TypeReference)21 ValueNode (org.graalvm.compiler.nodes.ValueNode)15 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)13 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)8 LogicNode (org.graalvm.compiler.nodes.LogicNode)8 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)6 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)6 Assumptions (jdk.vm.ci.meta.Assumptions)4 JavaType (jdk.vm.ci.meta.JavaType)4 Stamp (org.graalvm.compiler.core.common.type.Stamp)4 PiNode (org.graalvm.compiler.nodes.PiNode)4 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 HostedType (com.oracle.svm.hosted.meta.HostedType)2 RuntimeConstraint (jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint)2 JavaConstant (jdk.vm.ci.meta.JavaConstant)2 JavaKind (jdk.vm.ci.meta.JavaKind)2 JavaTypeProfile (jdk.vm.ci.meta.JavaTypeProfile)2 Signature (jdk.vm.ci.meta.Signature)2 AbstractObjectStamp (org.graalvm.compiler.core.common.type.AbstractObjectStamp)2