Search in sources :

Example 86 with ResolvedJavaType

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

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

the class PartialEvaluator method postPartialEvaluation.

private static void postPartialEvaluation(final StructuredGraph graph) {
    NeverPartOfCompilationNode.verifyNotFoundIn(graph);
    for (AllowMaterializeNode materializeNode : graph.getNodes(AllowMaterializeNode.TYPE).snapshot()) {
        materializeNode.replaceAtUsages(materializeNode.getFrame());
        graph.removeFixed(materializeNode);
    }
    TruffleCompilerRuntime rt = TruffleCompilerRuntime.getRuntime();
    for (VirtualObjectNode virtualObjectNode : graph.getNodes(VirtualObjectNode.TYPE)) {
        if (virtualObjectNode instanceof VirtualInstanceNode) {
            VirtualInstanceNode virtualInstanceNode = (VirtualInstanceNode) virtualObjectNode;
            ResolvedJavaType type = virtualInstanceNode.type();
            if (rt.isValueType(type)) {
                virtualInstanceNode.setIdentity(false);
            }
        }
    }
    if (!TruffleCompilerOptions.getValue(TruffleInlineAcrossTruffleBoundary)) {
        // Do not inline across Truffle boundaries.
        for (MethodCallTargetNode mct : graph.getNodes(MethodCallTargetNode.TYPE)) {
            InlineInfo inlineInfo = rt.getInlineInfo(mct.targetMethod(), false);
            if (!inlineInfo.allowsInlining()) {
                mct.invoke().setUseForInlining(false);
            }
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) TruffleCompilerRuntime(org.graalvm.compiler.truffle.common.TruffleCompilerRuntime) AllowMaterializeNode(org.graalvm.compiler.truffle.compiler.nodes.frame.AllowMaterializeNode) VirtualInstanceNode(org.graalvm.compiler.nodes.virtual.VirtualInstanceNode) InlineInfo.createStandardInlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo) InlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 88 with ResolvedJavaType

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

the class TruffleCompilerImpl method getSkippedExceptionTypes.

private ResolvedJavaType[] getSkippedExceptionTypes(TruffleCompilerRuntime runtime) {
    final MetaAccessProvider metaAccess = providers.getMetaAccess();
    ResolvedJavaType[] head = metaAccess.lookupJavaTypes(new Class<?>[] { ArithmeticException.class, IllegalArgumentException.class, VirtualMachineError.class, IndexOutOfBoundsException.class, ClassCastException.class, BufferUnderflowException.class, BufferOverflowException.class });
    ResolvedJavaType[] tail = { runtime.resolveType(metaAccess, "com.oracle.truffle.api.nodes.UnexpectedResultException"), runtime.resolveType(metaAccess, "com.oracle.truffle.api.nodes.SlowPathException") };
    ResolvedJavaType[] skippedExceptionTypes = new ResolvedJavaType[head.length + tail.length];
    System.arraycopy(head, 0, skippedExceptionTypes, 0, head.length);
    System.arraycopy(tail, 0, skippedExceptionTypes, head.length, tail.length);
    return skippedExceptionTypes;
}
Also used : MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 89 with ResolvedJavaType

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

the class TruffleGraphBuilderPlugins method registerOptimizedCallTargetPlugins.

public static void registerOptimizedCallTargetPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, boolean canDelayIntrinsification, KnownTruffleTypes types) {
    final ResolvedJavaType optimizedCallTargetType = getRuntime().resolveType(metaAccess, "org.graalvm.compiler.truffle.runtime.OptimizedCallTarget");
    Registration r = new Registration(plugins, new ResolvedJavaSymbol(optimizedCallTargetType));
    r.register2("createFrame", new ResolvedJavaSymbol(types.classFrameDescriptor), Object[].class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode descriptor, ValueNode args) {
            if (canDelayIntrinsification) {
                return false;
            }
            if (!descriptor.isJavaConstant()) {
                throw b.bailout("Parameter 'descriptor' is not a compile-time constant");
            }
            ValueNode nonNullArguments = b.add(PiNode.create(args, StampFactory.objectNonNull(StampTool.typeReferenceOrNull(args))));
            b.addPush(JavaKind.Object, new NewFrameNode(b, descriptor, nonNullArguments, types));
            return true;
        }
    });
    r.register2("castArrayFixedLength", Object[].class, int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode args, ValueNode length) {
            b.addPush(JavaKind.Object, new PiArrayNode(args, length, args.stamp(NodeView.DEFAULT)));
            return true;
        }
    });
    registerUnsafeCast(r, canDelayIntrinsification);
}
Also used : NewFrameNode(org.graalvm.compiler.truffle.compiler.nodes.frame.NewFrameNode) 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) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) PiArrayNode(org.graalvm.compiler.nodes.PiArrayNode) ResolvedJavaSymbol(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 90 with ResolvedJavaType

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

the class TruffleGraphBuilderPlugins method registerOptimizedAssumptionPlugins.

public static void registerOptimizedAssumptionPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, KnownTruffleTypes types) {
    ResolvedJavaType optimizedAssumptionType = getRuntime().resolveType(metaAccess, "org.graalvm.compiler.truffle.runtime.OptimizedAssumption");
    Registration r = new Registration(plugins, new ResolvedJavaSymbol(optimizedAssumptionType), null);
    InvocationPlugin plugin = new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (receiver.isConstant() && b.getAssumptions() != null) {
                JavaConstant assumption = (JavaConstant) receiver.get().asConstant();
                if (b.getConstantReflection().readFieldValue(types.fieldOptimizedAssumptionIsValid, assumption).asBoolean()) {
                    if (targetMethod.getName().equals("isValid")) {
                        b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
                    } else {
                        assert targetMethod.getName().equals("check") : targetMethod;
                    }
                    b.getAssumptions().record(new TruffleAssumption(assumption));
                } else {
                    if (targetMethod.getName().equals("isValid")) {
                        b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(false));
                    } else {
                        assert targetMethod.getName().equals("check") : targetMethod;
                        b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.None));
                    }
                }
                return true;
            } else {
                return false;
            }
        }
    };
    r.register1("isValid", Receiver.class, plugin);
    r.register1("check", Receiver.class, plugin);
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) TruffleAssumption(org.graalvm.compiler.truffle.compiler.nodes.TruffleAssumption) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) JavaConstant(jdk.vm.ci.meta.JavaConstant) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) ResolvedJavaSymbol(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol) 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