Search in sources :

Example 1 with LoadIndexedNode

use of org.graalvm.compiler.nodes.java.LoadIndexedNode in project graal by oracle.

the class BasicArrayCopyNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode sourcePosition = tool.getAlias(getSourcePosition());
    ValueNode destinationPosition = tool.getAlias(getDestinationPosition());
    ValueNode replacedLength = tool.getAlias(getLength());
    if (sourcePosition.isConstant() && destinationPosition.isConstant() && replacedLength.isConstant()) {
        int srcPosInt = sourcePosition.asJavaConstant().asInt();
        int destPosInt = destinationPosition.asJavaConstant().asInt();
        int len = replacedLength.asJavaConstant().asInt();
        ValueNode destAlias = tool.getAlias(getDestination());
        if (destAlias instanceof VirtualArrayNode) {
            VirtualArrayNode destVirtual = (VirtualArrayNode) destAlias;
            if (len < 0 || !checkBounds(destPosInt, len, destVirtual)) {
                return;
            }
            ValueNode srcAlias = tool.getAlias(getSource());
            if (srcAlias instanceof VirtualObjectNode) {
                if (!(srcAlias instanceof VirtualArrayNode)) {
                    return;
                }
                VirtualArrayNode srcVirtual = (VirtualArrayNode) srcAlias;
                if (destVirtual.componentType().getJavaKind() != srcVirtual.componentType().getJavaKind()) {
                    return;
                }
                if (!checkBounds(srcPosInt, len, srcVirtual)) {
                    return;
                }
                if (!checkEntryTypes(srcPosInt, len, srcVirtual, destVirtual.type().getComponentType(), tool)) {
                    return;
                }
                for (int i = 0; i < len; i++) {
                    tool.setVirtualEntry(destVirtual, destPosInt + i, tool.getEntry(srcVirtual, srcPosInt + i));
                }
                tool.delete();
                DebugContext debug = getDebug();
                if (debug.isLogEnabled()) {
                    debug.log("virtualized arraycopy(%s, %d, %s, %d, %d)", getSource(), srcPosInt, getDestination(), destPosInt, len);
                }
            } else {
                ResolvedJavaType sourceType = StampTool.typeOrNull(srcAlias);
                if (sourceType == null || !sourceType.isArray()) {
                    return;
                }
                ResolvedJavaType sourceComponentType = sourceType.getComponentType();
                ResolvedJavaType destComponentType = destVirtual.type().getComponentType();
                if (!sourceComponentType.equals(destComponentType)) {
                    return;
                }
                for (int i = 0; i < len; i++) {
                    LoadIndexedNode load = new LoadIndexedNode(graph().getAssumptions(), srcAlias, ConstantNode.forInt(i + srcPosInt, graph()), destComponentType.getJavaKind());
                    tool.addNode(load);
                    tool.setVirtualEntry(destVirtual, destPosInt + i, load);
                }
                tool.delete();
            }
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) VirtualArrayNode(org.graalvm.compiler.nodes.virtual.VirtualArrayNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DebugContext(org.graalvm.compiler.debug.DebugContext) AbstractMemoryCheckpoint(org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 2 with LoadIndexedNode

use of org.graalvm.compiler.nodes.java.LoadIndexedNode in project graal by oracle.

the class SimplifyingGraphDecoder method canonicalizeFixedNode.

/**
 * Canonicalizes the provided node, which was originally a {@link FixedNode} but can already be
 * canonicalized (and therefore be a non-fixed node).
 *
 * @param methodScope The current method.
 * @param node The node to be canonicalized.
 */
protected Node canonicalizeFixedNode(MethodScope methodScope, Node node) {
    if (node instanceof LoadFieldNode) {
        LoadFieldNode loadFieldNode = (LoadFieldNode) node;
        return loadFieldNode.canonical(canonicalizerTool);
    } else if (node instanceof FixedGuardNode) {
        FixedGuardNode guard = (FixedGuardNode) node;
        if (guard.getCondition() instanceof LogicConstantNode) {
            LogicConstantNode condition = (LogicConstantNode) guard.getCondition();
            if (condition.getValue() == guard.isNegated()) {
                DeoptimizeNode deopt = new DeoptimizeNode(guard.getAction(), guard.getReason(), guard.getSpeculation());
                if (guard.stateBefore() != null) {
                    deopt.setStateBefore(guard.stateBefore());
                }
                return deopt;
            } else {
                return null;
            }
        }
        return node;
    } else if (node instanceof IfNode) {
        IfNode ifNode = (IfNode) node;
        if (ifNode.condition() instanceof LogicNegationNode) {
            ifNode.eliminateNegation();
        }
        if (ifNode.condition() instanceof LogicConstantNode) {
            boolean condition = ((LogicConstantNode) ifNode.condition()).getValue();
            AbstractBeginNode survivingSuccessor = ifNode.getSuccessor(condition);
            AbstractBeginNode deadSuccessor = ifNode.getSuccessor(!condition);
            graph.removeSplit(ifNode, survivingSuccessor);
            assert deadSuccessor.next() == null : "must not be parsed yet";
            deadSuccessor.safeDelete();
        }
        return node;
    } else if (node instanceof LoadIndexedNode) {
        LoadIndexedNode loadIndexedNode = (LoadIndexedNode) node;
        return loadIndexedNode.canonical(canonicalizerTool);
    } else if (node instanceof ArrayLengthNode) {
        ArrayLengthNode arrayLengthNode = (ArrayLengthNode) node;
        return arrayLengthNode.canonical(canonicalizerTool);
    } else if (node instanceof IntegerSwitchNode && ((IntegerSwitchNode) node).value().isConstant()) {
        IntegerSwitchNode switchNode = (IntegerSwitchNode) node;
        int value = switchNode.value().asJavaConstant().asInt();
        AbstractBeginNode survivingSuccessor = switchNode.successorAtKey(value);
        List<Node> allSuccessors = switchNode.successors().snapshot();
        graph.removeSplit(switchNode, survivingSuccessor);
        for (Node successor : allSuccessors) {
            if (successor != survivingSuccessor) {
                assert ((AbstractBeginNode) successor).next() == null : "must not be parsed yet";
                successor.safeDelete();
            }
        }
        return node;
    } else if (node instanceof Canonicalizable) {
        return ((Canonicalizable) node).canonical(canonicalizerTool);
    } else {
        return node;
    }
}
Also used : IntegerSwitchNode(org.graalvm.compiler.nodes.extended.IntegerSwitchNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ArrayLengthNode(org.graalvm.compiler.nodes.java.ArrayLengthNode) Node(org.graalvm.compiler.graph.Node) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) Canonicalizable(org.graalvm.compiler.graph.spi.Canonicalizable) List(java.util.List) ArrayLengthNode(org.graalvm.compiler.nodes.java.ArrayLengthNode) IntegerSwitchNode(org.graalvm.compiler.nodes.extended.IntegerSwitchNode)

Example 3 with LoadIndexedNode

use of org.graalvm.compiler.nodes.java.LoadIndexedNode in project graal by oracle.

the class PEGraphDecoder method canonicalizeFixedNode.

@SuppressWarnings("try")
@Override
protected Node canonicalizeFixedNode(MethodScope s, Node node) {
    PEMethodScope methodScope = (PEMethodScope) s;
    Node replacedNode = node;
    if (nodePlugins != null && nodePlugins.length > 0) {
        if (node instanceof LoadFieldNode) {
            LoadFieldNode loadFieldNode = (LoadFieldNode) node;
            PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, loadFieldNode);
            ResolvedJavaField field = loadFieldNode.field();
            if (loadFieldNode.isStatic()) {
                for (NodePlugin nodePlugin : nodePlugins) {
                    if (nodePlugin.handleLoadStaticField(graphBuilderContext, field)) {
                        replacedNode = graphBuilderContext.pushedNode;
                        break;
                    }
                }
            } else {
                ValueNode object = loadFieldNode.object();
                for (NodePlugin nodePlugin : nodePlugins) {
                    if (nodePlugin.handleLoadField(graphBuilderContext, object, field)) {
                        replacedNode = graphBuilderContext.pushedNode;
                        break;
                    }
                }
            }
        } else if (node instanceof StoreFieldNode) {
            StoreFieldNode storeFieldNode = (StoreFieldNode) node;
            PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, storeFieldNode);
            ResolvedJavaField field = storeFieldNode.field();
            if (storeFieldNode.isStatic()) {
                ValueNode value = storeFieldNode.value();
                for (NodePlugin nodePlugin : nodePlugins) {
                    if (nodePlugin.handleStoreStaticField(graphBuilderContext, field, value)) {
                        replacedNode = graphBuilderContext.pushedNode;
                        break;
                    }
                }
            } else {
                ValueNode object = storeFieldNode.object();
                ValueNode value = storeFieldNode.value();
                for (NodePlugin nodePlugin : nodePlugins) {
                    if (nodePlugin.handleStoreField(graphBuilderContext, object, field, value)) {
                        replacedNode = graphBuilderContext.pushedNode;
                        break;
                    }
                }
            }
        } else if (node instanceof LoadIndexedNode) {
            LoadIndexedNode loadIndexedNode = (LoadIndexedNode) node;
            PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, loadIndexedNode);
            ValueNode array = loadIndexedNode.array();
            ValueNode index = loadIndexedNode.index();
            for (NodePlugin nodePlugin : nodePlugins) {
                if (nodePlugin.handleLoadIndexed(graphBuilderContext, array, index, loadIndexedNode.elementKind())) {
                    replacedNode = graphBuilderContext.pushedNode;
                    break;
                }
            }
        } else if (node instanceof StoreIndexedNode) {
            StoreIndexedNode storeIndexedNode = (StoreIndexedNode) node;
            PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, storeIndexedNode);
            ValueNode array = storeIndexedNode.array();
            ValueNode index = storeIndexedNode.index();
            ValueNode value = storeIndexedNode.value();
            for (NodePlugin nodePlugin : nodePlugins) {
                if (nodePlugin.handleStoreIndexed(graphBuilderContext, array, index, storeIndexedNode.elementKind(), value)) {
                    replacedNode = graphBuilderContext.pushedNode;
                    break;
                }
            }
        } else if (node instanceof NewInstanceNode) {
            NewInstanceNode newInstanceNode = (NewInstanceNode) node;
            PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, newInstanceNode);
            ResolvedJavaType type = newInstanceNode.instanceClass();
            for (NodePlugin nodePlugin : nodePlugins) {
                if (nodePlugin.handleNewInstance(graphBuilderContext, type)) {
                    replacedNode = graphBuilderContext.pushedNode;
                    break;
                }
            }
        } else if (node instanceof NewArrayNode) {
            NewArrayNode newArrayNode = (NewArrayNode) node;
            PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, newArrayNode);
            ResolvedJavaType elementType = newArrayNode.elementType();
            ValueNode length = newArrayNode.length();
            for (NodePlugin nodePlugin : nodePlugins) {
                if (nodePlugin.handleNewArray(graphBuilderContext, elementType, length)) {
                    replacedNode = graphBuilderContext.pushedNode;
                    break;
                }
            }
        } else if (node instanceof NewMultiArrayNode) {
            NewMultiArrayNode newArrayNode = (NewMultiArrayNode) node;
            PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, newArrayNode);
            ResolvedJavaType elementType = newArrayNode.type();
            ValueNode[] dimensions = newArrayNode.dimensions().toArray(new ValueNode[0]);
            for (NodePlugin nodePlugin : nodePlugins) {
                if (nodePlugin.handleNewMultiArray(graphBuilderContext, elementType, dimensions)) {
                    replacedNode = graphBuilderContext.pushedNode;
                    break;
                }
            }
        }
    }
    return super.canonicalizeFixedNode(methodScope, replacedNode);
}
Also used : StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) NewMultiArrayNode(org.graalvm.compiler.nodes.java.NewMultiArrayNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) IntegerSwitchNode(org.graalvm.compiler.nodes.extended.IntegerSwitchNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) Node(org.graalvm.compiler.graph.Node) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) NewMultiArrayNode(org.graalvm.compiler.nodes.java.NewMultiArrayNode) NodePlugin(org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 4 with LoadIndexedNode

use of org.graalvm.compiler.nodes.java.LoadIndexedNode in project graal by oracle.

the class PEReadEliminationClosure method processNode.

@Override
protected boolean processNode(Node node, PEReadEliminationBlockState state, GraphEffectList effects, FixedWithNextNode lastFixedNode) {
    if (super.processNode(node, state, effects, lastFixedNode)) {
        return true;
    }
    if (node instanceof LoadFieldNode) {
        return processLoadField((LoadFieldNode) node, state, effects);
    } else if (node instanceof StoreFieldNode) {
        return processStoreField((StoreFieldNode) node, state, effects);
    } else if (node instanceof LoadIndexedNode) {
        return processLoadIndexed((LoadIndexedNode) node, state, effects);
    } else if (node instanceof StoreIndexedNode) {
        return processStoreIndexed((StoreIndexedNode) node, state, effects);
    } else if (node instanceof ArrayLengthNode) {
        return processArrayLength((ArrayLengthNode) node, state, effects);
    } else if (node instanceof UnboxNode) {
        return processUnbox((UnboxNode) node, state, effects);
    } else if (node instanceof RawLoadNode) {
        return processUnsafeLoad((RawLoadNode) node, state, effects);
    } else if (node instanceof RawStoreNode) {
        return processUnsafeStore((RawStoreNode) node, state, effects);
    } else if (node instanceof MemoryCheckpoint.Single) {
        COUNTER_MEMORYCHECKPOINT.increment(node.getDebug());
        LocationIdentity identity = ((MemoryCheckpoint.Single) node).getLocationIdentity();
        processIdentity(state, identity);
    } else if (node instanceof MemoryCheckpoint.Multi) {
        COUNTER_MEMORYCHECKPOINT.increment(node.getDebug());
        for (LocationIdentity identity : ((MemoryCheckpoint.Multi) node).getLocationIdentities()) {
            processIdentity(state, identity);
        }
    }
    return false;
}
Also used : RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) UnboxNode(org.graalvm.compiler.nodes.extended.UnboxNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) LocationIdentity(org.graalvm.word.LocationIdentity) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) NamedLocationIdentity(org.graalvm.compiler.nodes.NamedLocationIdentity) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ArrayLengthNode(org.graalvm.compiler.nodes.java.ArrayLengthNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode)

Example 5 with LoadIndexedNode

use of org.graalvm.compiler.nodes.java.LoadIndexedNode in project graal by oracle.

the class InstrumentPhase method insertCounter.

protected static void insertCounter(StructuredGraph graph, PhaseContext context, JavaConstant tableConstant, FixedWithNextNode targetNode, int slotIndex) {
    assert (tableConstant != null);
    TypeReference typeRef = TypeReference.createExactTrusted(context.getMetaAccess().lookupJavaType(tableConstant));
    ConstantNode table = graph.unique(new ConstantNode(tableConstant, StampFactory.object(typeRef, true)));
    ConstantNode rawIndex = graph.unique(ConstantNode.forInt(slotIndex));
    LoadIndexedNode load = graph.add(new LoadIndexedNode(null, table, rawIndex, JavaKind.Long));
    ConstantNode one = graph.unique(ConstantNode.forLong(1L));
    ValueNode add = graph.unique(new AddNode(load, one));
    StoreIndexedNode store = graph.add(new StoreIndexedNode(table, rawIndex, JavaKind.Long, add));
    graph.addAfterFixed(targetNode, load);
    graph.addAfterFixed(load, store);
}
Also used : StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Aggregations

LoadIndexedNode (org.graalvm.compiler.nodes.java.LoadIndexedNode)7 ValueNode (org.graalvm.compiler.nodes.ValueNode)5 LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)3 StoreIndexedNode (org.graalvm.compiler.nodes.java.StoreIndexedNode)3 List (java.util.List)2 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 Node (org.graalvm.compiler.graph.Node)2 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)2 IntegerSwitchNode (org.graalvm.compiler.nodes.extended.IntegerSwitchNode)2 ArrayLengthNode (org.graalvm.compiler.nodes.java.ArrayLengthNode)2 StoreFieldNode (org.graalvm.compiler.nodes.java.StoreFieldNode)2 MemoryCheckpoint (org.graalvm.compiler.nodes.memory.MemoryCheckpoint)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DeoptimizationAction (jdk.vm.ci.meta.DeoptimizationAction)1