Search in sources :

Example 1 with ResolvedJavaType

use of jdk.vm.ci.meta.ResolvedJavaType 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 ResolvedJavaType

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

the class ClassIsAssignableFromNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
    if (forX.isConstant() && forY.isConstant()) {
        ConstantReflectionProvider constantReflection = tool.getConstantReflection();
        ResolvedJavaType thisType = constantReflection.asJavaType(forX.asJavaConstant());
        ResolvedJavaType otherType = constantReflection.asJavaType(forY.asJavaConstant());
        if (thisType != null && otherType != null) {
            return LogicConstantNode.forBoolean(thisType.isAssignableFrom(otherType));
        }
    }
    return this;
}
Also used : ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 3 with ResolvedJavaType

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

the class RawLoadNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool) {
    if (!isAnyLocationForced() && getLocationIdentity().isAny()) {
        ValueNode targetObject = object();
        if (offset().isConstant() && targetObject.isConstant() && !targetObject.isNullConstant()) {
            ConstantNode objectConstant = (ConstantNode) targetObject;
            ResolvedJavaType type = StampTool.typeOrNull(objectConstant);
            if (type != null && type.isArray()) {
                JavaConstant arrayConstant = objectConstant.asJavaConstant();
                if (arrayConstant != null) {
                    int stableDimension = objectConstant.getStableDimension();
                    if (stableDimension > 0) {
                        NodeView view = NodeView.from(tool);
                        long constantOffset = offset().asJavaConstant().asLong();
                        Constant constant = stamp(view).readConstant(tool.getConstantReflection().getMemoryAccessProvider(), arrayConstant, constantOffset);
                        boolean isDefaultStable = objectConstant.isDefaultStable();
                        if (constant != null && (isDefaultStable || !constant.isDefaultForKind())) {
                            return ConstantNode.forConstant(stamp(view), constant, stableDimension - 1, isDefaultStable, tool.getMetaAccess());
                        }
                    }
                }
            }
        }
    }
    return super.canonical(tool);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Constant(jdk.vm.ci.meta.Constant) JavaConstant(jdk.vm.ci.meta.JavaConstant) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) NodeView(org.graalvm.compiler.nodes.NodeView) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 4 with ResolvedJavaType

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

the class UnsafeAccessNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool) {
    if (!isAnyLocationForced() && getLocationIdentity().isAny()) {
        if (offset().isConstant()) {
            long constantOffset = offset().asJavaConstant().asLong();
            // Try to canonicalize to a field access.
            ResolvedJavaType receiverType = StampTool.typeOrNull(object());
            if (receiverType != null) {
                ResolvedJavaField field = receiverType.findInstanceFieldWithOffset(constantOffset, accessKind());
                // never a valid access of an arbitrary address.
                if (field != null && field.getJavaKind() == this.accessKind()) {
                    assert !graph().isAfterFloatingReadPhase() : "cannot add more precise memory location after floating read phase";
                    return cloneAsFieldAccess(graph().getAssumptions(), field);
                }
            }
        }
        ResolvedJavaType receiverType = StampTool.typeOrNull(object());
        // Try to build a better location identity.
        if (receiverType != null && receiverType.isArray()) {
            LocationIdentity identity = NamedLocationIdentity.getArrayLocation(receiverType.getComponentType().getJavaKind());
            assert !graph().isAfterFloatingReadPhase() : "cannot add more precise memory location after floating read phase";
            return cloneAsArrayAccess(offset(), identity);
        }
    }
    return this;
}
Also used : LocationIdentity(org.graalvm.word.LocationIdentity) NamedLocationIdentity(org.graalvm.compiler.nodes.NamedLocationIdentity) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 5 with ResolvedJavaType

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

the class TruffleGraphBuilderPlugins method registerExactMathPlugins.

public static void registerExactMathPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess) {
    final ResolvedJavaType exactMathType = getRuntime().resolveType(metaAccess, "com.oracle.truffle.api.ExactMath");
    Registration r = new Registration(plugins, new ResolvedJavaSymbol(exactMathType));
    for (JavaKind kind : new JavaKind[] { JavaKind.Int, JavaKind.Long }) {
        Class<?> type = kind.toJavaClass();
        r.register2("multiplyHigh", type, type, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
                b.addPush(kind, new IntegerMulHighNode(x, y));
                return true;
            }
        });
        r.register2("multiplyHighUnsigned", type, type, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
                b.addPush(kind, new UnsignedMulHighNode(x, y));
                return true;
            }
        });
    }
}
Also used : Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ResolvedJavaSymbol(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol) IntegerMulHighNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerMulHighNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind) UnsignedMulHighNode(org.graalvm.compiler.replacements.nodes.arithmetic.UnsignedMulHighNode)

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