Search in sources :

Example 31 with VirtualObjectNode

use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.

the class VirtualFrameSetNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode tagAlias = tool.getAlias(frame.virtualFrameTagArray);
    ValueNode dataAlias = tool.getAlias(TruffleCompilerRuntime.getRuntime().getJavaKindForFrameSlotKind(accessTag) == JavaKind.Object ? frame.virtualFrameObjectArray : frame.virtualFramePrimitiveArray);
    if (tagAlias instanceof VirtualObjectNode && dataAlias instanceof VirtualObjectNode) {
        VirtualObjectNode tagVirtual = (VirtualObjectNode) tagAlias;
        VirtualObjectNode dataVirtual = (VirtualObjectNode) dataAlias;
        if (frameSlotIndex < tagVirtual.entryCount() && frameSlotIndex < dataVirtual.entryCount()) {
            tool.setVirtualEntry(tagVirtual, frameSlotIndex, getConstant(accessTag));
            ValueNode dataEntry = tool.getEntry(dataVirtual, frameSlotIndex);
            if (dataEntry.getStackKind() == value.getStackKind()) {
                if (tool.setVirtualEntry(dataVirtual, frameSlotIndex, value, value.getStackKind(), -1)) {
                    tool.delete();
                    return;
                }
            }
        }
    }
    /*
         * Deoptimization is our only option here. We cannot go back to a UnsafeStoreNode because we
         * do not have a FrameState to use for the memory store.
         */
    insertDeoptimization(tool);
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 32 with VirtualObjectNode

use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.

the class AssertTypeStateNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode alias = tool.getAlias(getInput());
    if (alias instanceof VirtualObjectNode) {
        Set<ResolvedJavaType> ourTypes = new HashSet<>();
        addAllTypes(ourTypes, typeState);
        if (!ourTypes.contains(StampTool.typeOrNull(alias))) {
            throw shouldNotReachHere("Virtual object not compatible with type state: " + this + " : " + getTypeState() + ", " + alias.stamp(NodeView.DEFAULT));
        }
        tool.replaceWith(alias);
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) HashSet(java.util.HashSet)

Example 33 with VirtualObjectNode

use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.

the class ObjectEqualsNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode xAlias = tool.getAlias(getX());
    ValueNode yAlias = tool.getAlias(getY());
    VirtualObjectNode xVirtual = xAlias instanceof VirtualObjectNode ? (VirtualObjectNode) xAlias : null;
    VirtualObjectNode yVirtual = yAlias instanceof VirtualObjectNode ? (VirtualObjectNode) yAlias : null;
    if (xVirtual != null && yVirtual == null) {
        virtualizeNonVirtualComparison(xVirtual, yAlias, tool);
    } else if (xVirtual == null && yVirtual != null) {
        virtualizeNonVirtualComparison(yVirtual, xAlias, tool);
    } else if (xVirtual != null && yVirtual != null) {
        if (xVirtual.hasIdentity() ^ yVirtual.hasIdentity()) {
            /*
                 * One of the two objects has identity, the other doesn't. In code, this looks like
                 * "Integer.valueOf(a) == new Integer(b)", which is always false.
                 *
                 * In other words: an object created via valueOf can never be equal to one created
                 * by new in the same compilation unit.
                 */
            tool.replaceWithValue(LogicConstantNode.contradiction(graph()));
        } else if (!xVirtual.hasIdentity() && !yVirtual.hasIdentity()) {
            ResolvedJavaType type = xVirtual.type();
            if (type.equals(yVirtual.type())) {
                MetaAccessProvider metaAccess = tool.getMetaAccessProvider();
                if (type.equals(metaAccess.lookupJavaType(Integer.class)) || type.equals(metaAccess.lookupJavaType(Long.class))) {
                    // both are virtual without identity: check contents
                    assert xVirtual.entryCount() == 1 && yVirtual.entryCount() == 1;
                    assert xVirtual.entryKind(0).getStackKind() == JavaKind.Int || xVirtual.entryKind(0) == JavaKind.Long;
                    IntegerEqualsNode equals = new IntegerEqualsNode(tool.getEntry(xVirtual, 0), tool.getEntry(yVirtual, 0));
                    tool.addNode(equals);
                    tool.replaceWithValue(equals);
                }
            }
        } else {
            // both are virtual with identity: check if they refer to the same object
            tool.replaceWithValue(LogicConstantNode.forBoolean(xVirtual == yVirtual, graph()));
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Example 34 with VirtualObjectNode

use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.

the class UnboxNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode alias = tool.getAlias(getValue());
    if (alias instanceof VirtualObjectNode) {
        VirtualObjectNode virtual = (VirtualObjectNode) alias;
        ResolvedJavaType objectType = virtual.type();
        ResolvedJavaType expectedType = tool.getMetaAccessProvider().lookupJavaType(boxingKind.toBoxedJavaClass());
        if (objectType.equals(expectedType)) {
            tool.replaceWithValue(tool.getEntry(virtual, 0));
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 35 with VirtualObjectNode

use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.

the class GraphUtil method virtualizeArrayCopy.

/**
 * Virtualize an array copy.
 *
 * @param tool the virtualization tool
 * @param source the source array
 * @param sourceLength the length of the source array
 * @param newLength the length of the new array
 * @param from the start index in the source array
 * @param newComponentType the component type of the new array
 * @param elementKind the kind of the new array elements
 * @param graph the node graph
 * @param virtualArrayProvider a functional provider that returns a new virtual array given the
 *            component type and length
 */
public static void virtualizeArrayCopy(VirtualizerTool tool, ValueNode source, ValueNode sourceLength, ValueNode newLength, ValueNode from, ResolvedJavaType newComponentType, JavaKind elementKind, StructuredGraph graph, BiFunction<ResolvedJavaType, Integer, VirtualArrayNode> virtualArrayProvider) {
    ValueNode sourceAlias = tool.getAlias(source);
    ValueNode replacedSourceLength = tool.getAlias(sourceLength);
    ValueNode replacedNewLength = tool.getAlias(newLength);
    ValueNode replacedFrom = tool.getAlias(from);
    if (!replacedNewLength.isConstant() || !replacedFrom.isConstant() || !replacedSourceLength.isConstant()) {
        return;
    }
    assert newComponentType != null : "An array copy can be virtualized only if the real type of the resulting array is known statically.";
    int fromInt = replacedFrom.asJavaConstant().asInt();
    int newLengthInt = replacedNewLength.asJavaConstant().asInt();
    int sourceLengthInt = replacedSourceLength.asJavaConstant().asInt();
    if (sourceAlias instanceof VirtualObjectNode) {
        VirtualObjectNode sourceVirtual = (VirtualObjectNode) sourceAlias;
        assert sourceLengthInt == sourceVirtual.entryCount();
    }
    if (fromInt < 0 || newLengthInt < 0 || fromInt > sourceLengthInt) {
        /* Illegal values for either from index, the new length or the source length. */
        return;
    }
    if (newLengthInt >= tool.getMaximumEntryCount()) {
        /* The new array size is higher than maximum allowed size of virtualized objects. */
        return;
    }
    ValueNode[] newEntryState = new ValueNode[newLengthInt];
    int readLength = Math.min(newLengthInt, sourceLengthInt - fromInt);
    if (sourceAlias instanceof VirtualObjectNode) {
        /* The source array is virtualized, just copy over the values. */
        VirtualObjectNode sourceVirtual = (VirtualObjectNode) sourceAlias;
        for (int i = 0; i < readLength; i++) {
            newEntryState[i] = tool.getEntry(sourceVirtual, fromInt + i);
        }
    } else {
        /* The source array is not virtualized, emit index loads. */
        for (int i = 0; i < readLength; i++) {
            LoadIndexedNode load = new LoadIndexedNode(null, sourceAlias, ConstantNode.forInt(i + fromInt, graph), elementKind);
            tool.addNode(load);
            newEntryState[i] = load;
        }
    }
    if (readLength < newLengthInt) {
        /* Pad the copy with the default value of its elment kind. */
        ValueNode defaultValue = ConstantNode.defaultForKind(elementKind, graph);
        for (int i = readLength; i < newLengthInt; i++) {
            newEntryState[i] = defaultValue;
        }
    }
    /* Perform the replacement. */
    VirtualArrayNode newVirtualArray = virtualArrayProvider.apply(newComponentType, newLengthInt);
    tool.createVirtualObject(newVirtualArray, newEntryState, Collections.<MonitorIdNode>emptyList(), false);
    tool.replaceWithVirtual(newVirtualArray);
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) VirtualArrayNode(org.graalvm.compiler.nodes.virtual.VirtualArrayNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Aggregations

VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)42 ValueNode (org.graalvm.compiler.nodes.ValueNode)38 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)8 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)7 Node (org.graalvm.compiler.graph.Node)7 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)7 VirtualObjectState (org.graalvm.compiler.virtual.nodes.VirtualObjectState)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 PhiNode (org.graalvm.compiler.nodes.PhiNode)5 Block (org.graalvm.compiler.nodes.cfg.Block)5 ArrayList (java.util.ArrayList)4 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)4 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 ValueProxyNode (org.graalvm.compiler.nodes.ValueProxyNode)4 VirtualArrayNode (org.graalvm.compiler.nodes.virtual.VirtualArrayNode)4 VirtualInstanceNode (org.graalvm.compiler.nodes.virtual.VirtualInstanceNode)4 JavaKind (jdk.vm.ci.meta.JavaKind)3 FrameState (org.graalvm.compiler.nodes.FrameState)3 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)3 BitSet (java.util.BitSet)2