Search in sources :

Example 11 with ResolvedJavaType

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

the class LoadJavaMirrorWithKlassPhase method getClassConstantReplacement.

private ValueNode getClassConstantReplacement(StructuredGraph graph, PhaseContext context, JavaConstant constant) {
    if (constant instanceof HotSpotObjectConstant) {
        ConstantReflectionProvider constantReflection = context.getConstantReflection();
        ResolvedJavaType type = constantReflection.asJavaType(constant);
        if (type != null) {
            MetaAccessProvider metaAccess = context.getMetaAccess();
            Stamp stamp = StampFactory.objectNonNull(TypeReference.createExactTrusted(metaAccess.lookupJavaType(Class.class)));
            if (type instanceof HotSpotResolvedObjectType) {
                ConstantNode klass = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), ((HotSpotResolvedObjectType) type).klass(), metaAccess, graph);
                ValueNode getClass = graph.unique(new HubGetClassNode(metaAccess, klass));
                if (((HotSpotObjectConstant) constant).isCompressed()) {
                    return HotSpotCompressionNode.compress(getClass, oopEncoding);
                } else {
                    return getClass;
                }
            } else {
                /*
                     * Primitive classes are more difficult since they don't have a corresponding
                     * Klass* so get them from Class.TYPE for the java box type.
                     */
                HotSpotResolvedPrimitiveType primitive = (HotSpotResolvedPrimitiveType) type;
                ResolvedJavaType boxingClass = metaAccess.lookupJavaType(primitive.getJavaKind().toBoxedJavaClass());
                ConstantNode clazz = ConstantNode.forConstant(context.getConstantReflection().asJavaClass(boxingClass), metaAccess, graph);
                HotSpotResolvedJavaField[] a = (HotSpotResolvedJavaField[]) boxingClass.getStaticFields();
                HotSpotResolvedJavaField typeField = null;
                for (HotSpotResolvedJavaField f : a) {
                    if (f.getName().equals("TYPE")) {
                        typeField = f;
                        break;
                    }
                }
                if (typeField == null) {
                    throw new GraalError("Can't find TYPE field in class");
                }
                if (oopEncoding != null) {
                    stamp = HotSpotNarrowOopStamp.compressed((AbstractObjectStamp) stamp, oopEncoding);
                }
                AddressNode address = graph.unique(new OffsetAddressNode(clazz, ConstantNode.forLong(typeField.offset(), graph)));
                ValueNode read = graph.unique(new FloatingReadNode(address, FINAL_LOCATION, null, stamp));
                if (oopEncoding == null || ((HotSpotObjectConstant) constant).isCompressed()) {
                    return read;
                } else {
                    return HotSpotCompressionNode.uncompress(read, oopEncoding);
                }
            }
        }
    }
    return null;
}
Also used : KlassPointerStamp(org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) HotSpotNarrowOopStamp(org.graalvm.compiler.hotspot.nodes.type.HotSpotNarrowOopStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) HubGetClassNode(org.graalvm.compiler.hotspot.replacements.HubGetClassNode) HotSpotResolvedPrimitiveType(jdk.vm.ci.hotspot.HotSpotResolvedPrimitiveType) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) GraalError(org.graalvm.compiler.debug.GraalError) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Example 12 with ResolvedJavaType

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

the class ForeignCallStub method createParameters.

private ParameterNode[] createParameters(GraphKit kit, Class<?>[] args) {
    ParameterNode[] params = new ParameterNode[args.length];
    ResolvedJavaType accessingClass = providers.getMetaAccess().lookupJavaType(getClass());
    for (int i = 0; i < args.length; i++) {
        ResolvedJavaType type = providers.getMetaAccess().lookupJavaType(args[i]).resolve(accessingClass);
        StampPair stamp = StampFactory.forDeclaredType(kit.getGraph().getAssumptions(), type, false);
        ParameterNode param = kit.unique(new ParameterNode(i, stamp));
        params[i] = param;
    }
    return params;
}
Also used : ParameterNode(org.graalvm.compiler.nodes.ParameterNode) StampPair(org.graalvm.compiler.core.common.type.StampPair) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 13 with ResolvedJavaType

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

the class MultiTypeGuardInlineInfo method inlineMultipleMethods.

private EconomicSet<Node> inlineMultipleMethods(StructuredGraph graph, Providers providers) {
    int numberOfMethods = concretes.size();
    FixedNode continuation = invoke.next();
    // setup merge and phi nodes for results and exceptions
    AbstractMergeNode returnMerge = graph.add(new MergeNode());
    returnMerge.setStateAfter(invoke.stateAfter());
    PhiNode returnValuePhi = null;
    if (invoke.asNode().getStackKind() != JavaKind.Void) {
        returnValuePhi = graph.addWithoutUnique(new ValuePhiNode(invoke.asNode().stamp(NodeView.DEFAULT).unrestricted(), returnMerge));
    }
    AbstractMergeNode exceptionMerge = null;
    PhiNode exceptionObjectPhi = null;
    if (invoke instanceof InvokeWithExceptionNode) {
        InvokeWithExceptionNode invokeWithException = (InvokeWithExceptionNode) invoke;
        ExceptionObjectNode exceptionEdge = (ExceptionObjectNode) invokeWithException.exceptionEdge();
        exceptionMerge = graph.add(new MergeNode());
        FixedNode exceptionSux = exceptionEdge.next();
        graph.addBeforeFixed(exceptionSux, exceptionMerge);
        exceptionObjectPhi = graph.addWithoutUnique(new ValuePhiNode(StampFactory.forKind(JavaKind.Object), exceptionMerge));
        exceptionMerge.setStateAfter(exceptionEdge.stateAfter().duplicateModified(invoke.stateAfter().bci, true, JavaKind.Object, new JavaKind[] { JavaKind.Object }, new ValueNode[] { exceptionObjectPhi }));
    }
    // create one separate block for each invoked method
    AbstractBeginNode[] successors = new AbstractBeginNode[numberOfMethods + 1];
    for (int i = 0; i < numberOfMethods; i++) {
        successors[i] = createInvocationBlock(graph, invoke, returnMerge, returnValuePhi, exceptionMerge, exceptionObjectPhi, true);
    }
    // create the successor for an unknown type
    FixedNode unknownTypeSux;
    if (shouldFallbackToInvoke()) {
        unknownTypeSux = createInvocationBlock(graph, invoke, returnMerge, returnValuePhi, exceptionMerge, exceptionObjectPhi, false);
    } else {
        unknownTypeSux = graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TypeCheckedInliningViolated));
    }
    successors[successors.length - 1] = BeginNode.begin(unknownTypeSux);
    // replace the invoke exception edge
    if (invoke instanceof InvokeWithExceptionNode) {
        InvokeWithExceptionNode invokeWithExceptionNode = (InvokeWithExceptionNode) invoke;
        ExceptionObjectNode exceptionEdge = (ExceptionObjectNode) invokeWithExceptionNode.exceptionEdge();
        exceptionEdge.replaceAtUsages(exceptionObjectPhi);
        exceptionEdge.setNext(null);
        GraphUtil.killCFG(invokeWithExceptionNode.exceptionEdge());
    }
    assert invoke.asNode().isAlive();
    // replace the invoke with a switch on the type of the actual receiver
    boolean methodDispatch = createDispatchOnTypeBeforeInvoke(graph, successors, false, providers.getStampProvider(), providers.getConstantReflection());
    assert invoke.next() == continuation;
    invoke.setNext(null);
    returnMerge.setNext(continuation);
    if (returnValuePhi != null) {
        invoke.asNode().replaceAtUsages(returnValuePhi);
    }
    invoke.asNode().safeDelete();
    ArrayList<PiNode> replacementNodes = new ArrayList<>();
    // prepare the anchors for the invokes
    for (int i = 0; i < numberOfMethods; i++) {
        AbstractBeginNode node = successors[i];
        Invoke invokeForInlining = (Invoke) node.next();
        ResolvedJavaType commonType;
        if (methodDispatch) {
            commonType = concretes.get(i).getDeclaringClass();
        } else {
            commonType = getLeastCommonType(i);
        }
        ValueNode receiver = ((MethodCallTargetNode) invokeForInlining.callTarget()).receiver();
        boolean exact = (getTypeCount(i) == 1 && !methodDispatch);
        PiNode anchoredReceiver = InliningUtil.createAnchoredReceiver(graph, node, commonType, receiver, exact);
        invokeForInlining.callTarget().replaceFirstInput(receiver, anchoredReceiver);
        assert !anchoredReceiver.isDeleted() : anchoredReceiver;
        replacementNodes.add(anchoredReceiver);
    }
    if (shouldFallbackToInvoke()) {
        replacementNodes.add(null);
    }
    EconomicSet<Node> canonicalizeNodes = EconomicSet.create(Equivalence.DEFAULT);
    // do the actual inlining for every invoke
    for (int i = 0; i < numberOfMethods; i++) {
        Invoke invokeForInlining = (Invoke) successors[i].next();
        canonicalizeNodes.addAll(doInline(i, invokeForInlining));
    }
    if (returnValuePhi != null) {
        canonicalizeNodes.add(returnValuePhi);
    }
    return canonicalizeNodes;
}
Also used : ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) TypeSwitchNode(org.graalvm.compiler.nodes.java.TypeSwitchNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) ArrayList(java.util.ArrayList) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) PiNode(org.graalvm.compiler.nodes.PiNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) Invoke(org.graalvm.compiler.nodes.Invoke) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 14 with ResolvedJavaType

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

the class MultiTypeGuardInlineInfo method createDispatchOnTypeBeforeInvoke.

private boolean createDispatchOnTypeBeforeInvoke(StructuredGraph graph, AbstractBeginNode[] successors, boolean invokeIsOnlySuccessor, StampProvider stampProvider, ConstantReflectionProvider constantReflection) {
    assert ptypes.size() >= 1;
    ValueNode nonNullReceiver = InliningUtil.nonNullReceiver(invoke);
    LoadHubNode hub = graph.unique(new LoadHubNode(stampProvider, nonNullReceiver));
    graph.getDebug().log("Type switch with %d types", concretes.size());
    ResolvedJavaType[] keys = new ResolvedJavaType[ptypes.size()];
    double[] keyProbabilities = new double[ptypes.size() + 1];
    int[] keySuccessors = new int[ptypes.size() + 1];
    double totalProbability = notRecordedTypeProbability;
    for (int i = 0; i < ptypes.size(); i++) {
        keys[i] = ptypes.get(i).getType();
        keyProbabilities[i] = ptypes.get(i).getProbability();
        totalProbability += keyProbabilities[i];
        keySuccessors[i] = invokeIsOnlySuccessor ? 0 : typesToConcretes.get(i);
        assert keySuccessors[i] < successors.length - 1 : "last successor is the unknownTypeSux";
    }
    keyProbabilities[keyProbabilities.length - 1] = notRecordedTypeProbability;
    keySuccessors[keySuccessors.length - 1] = successors.length - 1;
    // Normalize the probabilities.
    for (int i = 0; i < keyProbabilities.length; i++) {
        keyProbabilities[i] /= totalProbability;
    }
    TypeSwitchNode typeSwitch = graph.add(new TypeSwitchNode(hub, successors, keys, keyProbabilities, keySuccessors, constantReflection));
    FixedWithNextNode pred = (FixedWithNextNode) invoke.asNode().predecessor();
    pred.setNext(typeSwitch);
    return false;
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) TypeSwitchNode(org.graalvm.compiler.nodes.java.TypeSwitchNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 15 with ResolvedJavaType

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

the class StampTool method typeOrNull.

public static ResolvedJavaType typeOrNull(Stamp stamp, MetaAccessProvider metaAccess) {
    if (stamp instanceof AbstractObjectStamp && stamp.hasValues()) {
        AbstractObjectStamp abstractObjectStamp = (AbstractObjectStamp) stamp;
        ResolvedJavaType type = abstractObjectStamp.type();
        if (type == null) {
            return metaAccess.lookupJavaType(Object.class);
        } else {
            return type;
        }
    }
    return null;
}
Also used : AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

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