Search in sources :

Example 1 with SubstrateNarrowOopStamp

use of com.oracle.svm.core.graal.nodes.SubstrateNarrowOopStamp in project graal by oracle.

the class CompileQueue method replaceAnalysisObjects.

public static Object replaceAnalysisObjects(Object obj, Node node, IdentityHashMap<Object, Object> replacements, HostedUniverse hUniverse) {
    if (obj == null) {
        return obj;
    }
    Object existingReplacement = replacements.get(obj);
    if (existingReplacement != null) {
        return existingReplacement;
    }
    Object newReplacement;
    if (obj instanceof Node) {
        throw VMError.shouldNotReachHere("Must not replace a Graal graph nodes, only data objects referenced from a node");
    } else if (obj instanceof AnalysisType) {
        newReplacement = hUniverse.lookup((AnalysisType) obj);
    } else if (obj instanceof AnalysisMethod) {
        newReplacement = hUniverse.lookup((AnalysisMethod) obj);
    } else if (obj instanceof AnalysisField) {
        newReplacement = hUniverse.lookup((AnalysisField) obj);
    } else if (obj.getClass() == ObjectStamp.class) {
        ObjectStamp stamp = (ObjectStamp) obj;
        if (stamp.type() == null) {
            /* No actual type referenced, so we can keep the original object. */
            newReplacement = obj;
        } else {
            /*
                 * ObjectStamp references a type indirectly, so we need to provide a new stamp with
                 * a modified type.
                 */
            newReplacement = new ObjectStamp((ResolvedJavaType) replaceAnalysisObjects(stamp.type(), node, replacements, hUniverse), stamp.isExactType(), stamp.nonNull(), stamp.alwaysNull(), stamp.isAlwaysArray());
        }
    } else if (obj.getClass() == SubstrateNarrowOopStamp.class) {
        SubstrateNarrowOopStamp stamp = (SubstrateNarrowOopStamp) obj;
        if (stamp.type() == null) {
            newReplacement = obj;
        } else {
            newReplacement = new SubstrateNarrowOopStamp((ResolvedJavaType) replaceAnalysisObjects(stamp.type(), node, replacements, hUniverse), stamp.isExactType(), stamp.nonNull(), stamp.alwaysNull(), stamp.isAlwaysArray(), stamp.getEncoding());
        }
    } else if (obj.getClass() == PiNode.PlaceholderStamp.class) {
        assert ((PiNode.PlaceholderStamp) obj).type() == null : "PlaceholderStamp never references a type";
        newReplacement = obj;
    } else if (obj instanceof AbstractObjectStamp) {
        throw VMError.shouldNotReachHere("missing replacement of a subclass of AbstractObjectStamp: " + obj.getClass().getTypeName());
    } else if (obj.getClass() == StampPair.class) {
        StampPair pair = (StampPair) obj;
        Stamp trustedStamp = (Stamp) replaceAnalysisObjects(pair.getTrustedStamp(), node, replacements, hUniverse);
        Stamp uncheckedStamp = (Stamp) replaceAnalysisObjects(pair.getUncheckedStamp(), node, replacements, hUniverse);
        if (trustedStamp != pair.getTrustedStamp() || uncheckedStamp != pair.getUncheckedStamp()) {
            newReplacement = StampPair.create(trustedStamp, uncheckedStamp);
        } else {
            newReplacement = pair;
        }
    } else if (obj.getClass() == ResolvedJavaMethodBytecode.class) {
        ResolvedJavaMethodBytecode bc = (ResolvedJavaMethodBytecode) obj;
        newReplacement = new ResolvedJavaMethodBytecode(hUniverse.lookup(bc.getMethod()), bc.getOrigin());
    } else if (obj instanceof Object[]) {
        Object[] originalArray = (Object[]) obj;
        Object[] copyArray = null;
        for (int i = 0; i < originalArray.length; i++) {
            Object original = originalArray[i];
            Object replaced = replaceAnalysisObjects(original, node, replacements, hUniverse);
            if (replaced != original) {
                if (copyArray == null) {
                    copyArray = Arrays.copyOf(originalArray, originalArray.length);
                }
                copyArray[i] = replaced;
            }
        }
        newReplacement = copyArray != null ? copyArray : originalArray;
    } else if (obj.getClass() == NodeSourcePosition.class) {
        NodeSourcePosition nsp = (NodeSourcePosition) obj;
        NodeSourcePosition replacedCaller = (NodeSourcePosition) replaceAnalysisObjects(nsp.getCaller(), node, replacements, hUniverse);
        ResolvedJavaMethod replacedMethod = (ResolvedJavaMethod) replaceAnalysisObjects(nsp.getMethod(), node, replacements, hUniverse);
        newReplacement = new NodeSourcePosition(nsp.getSourceLanguage(), replacedCaller, replacedMethod, nsp.getBCI(), nsp.getMarker());
    } else if (obj.getClass() == BytecodePosition.class) {
        BytecodePosition nsp = (BytecodePosition) obj;
        BytecodePosition replacedCaller = (BytecodePosition) replaceAnalysisObjects(nsp.getCaller(), node, replacements, hUniverse);
        ResolvedJavaMethod replacedMethod = (ResolvedJavaMethod) replaceAnalysisObjects(nsp.getMethod(), node, replacements, hUniverse);
        newReplacement = new BytecodePosition(replacedCaller, replacedMethod, nsp.getBCI());
    } else if (obj.getClass() == SubstrateMethodPointerConstant.class) {
        SubstrateMethodPointerConstant methodPointerConstant = (SubstrateMethodPointerConstant) obj;
        MethodPointer methodPointer = methodPointerConstant.pointer();
        ResolvedJavaMethod method = methodPointer.getMethod();
        ResolvedJavaMethod replacedMethod = (ResolvedJavaMethod) replaceAnalysisObjects(method, node, replacements, hUniverse);
        newReplacement = new SubstrateMethodPointerConstant(new MethodPointer(replacedMethod));
    } else {
        /* Check that we do not have a class or package name that relates to the analysis. */
        assert !obj.getClass().getName().toLowerCase().contains("analysis") : "Object " + obj + " of " + obj.getClass() + " in node " + node;
        assert !obj.getClass().getName().toLowerCase().contains("pointsto") : "Object " + obj + " of " + obj.getClass() + " in node " + node;
        newReplacement = obj;
    }
    replacements.put(obj, newReplacement);
    return newReplacement;
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) SubstrateNarrowOopStamp(com.oracle.svm.core.graal.nodes.SubstrateNarrowOopStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) BytecodePosition(jdk.vm.ci.code.BytecodePosition) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) DeoptTestNode(com.oracle.svm.core.graal.nodes.DeoptTestNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) VirtualInstanceNode(org.graalvm.compiler.nodes.virtual.VirtualInstanceNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) DeoptEntryNode(com.oracle.svm.core.graal.nodes.DeoptEntryNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) StartNode(org.graalvm.compiler.nodes.StartNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) SubstrateMethodPointerConstant(com.oracle.svm.core.meta.SubstrateMethodPointerConstant) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) PiNode(org.graalvm.compiler.nodes.PiNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) Infopoint(jdk.vm.ci.code.site.Infopoint) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) MethodPointer(com.oracle.svm.core.meta.MethodPointer) StampPair(org.graalvm.compiler.core.common.type.StampPair) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) SubstrateNarrowOopStamp(com.oracle.svm.core.graal.nodes.SubstrateNarrowOopStamp) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition)

Aggregations

AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)1 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)1 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)1 DeoptEntryInfopoint (com.oracle.svm.core.deopt.DeoptEntryInfopoint)1 DeoptEntryNode (com.oracle.svm.core.graal.nodes.DeoptEntryNode)1 DeoptTestNode (com.oracle.svm.core.graal.nodes.DeoptTestNode)1 SubstrateNarrowOopStamp (com.oracle.svm.core.graal.nodes.SubstrateNarrowOopStamp)1 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)1 MethodPointer (com.oracle.svm.core.meta.MethodPointer)1 SubstrateMethodPointerConstant (com.oracle.svm.core.meta.SubstrateMethodPointerConstant)1 BytecodePosition (jdk.vm.ci.code.BytecodePosition)1 Infopoint (jdk.vm.ci.code.site.Infopoint)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 ResolvedJavaMethodBytecode (org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode)1 AbstractObjectStamp (org.graalvm.compiler.core.common.type.AbstractObjectStamp)1 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)1 Stamp (org.graalvm.compiler.core.common.type.Stamp)1 StampPair (org.graalvm.compiler.core.common.type.StampPair)1 Node (org.graalvm.compiler.graph.Node)1