Search in sources :

Example 1 with ArrayLengthNode

use of org.graalvm.compiler.nodes.java.ArrayLengthNode 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 2 with ArrayLengthNode

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

the class SubstrateGraphBuilderPlugins method registerKnownIntrinsicsPlugins.

private static void registerKnownIntrinsicsPlugins(InvocationPlugins plugins, boolean analysis) {
    Registration r = new Registration(plugins, KnownIntrinsics.class);
    r.register0("heapBase", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, ReadRegisterFixedNode.forHeapBase());
            return true;
        }
    });
    r.register1("readArrayLength", Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode array) {
            b.addPush(JavaKind.Int, new ArrayLengthNode(array));
            return true;
        }
    });
    r.register1("readHub", Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            ValueNode nonNullObject = b.nullCheckedValue(object);
            b.addPush(JavaKind.Object, new LoadHubNode(b.getStampProvider(), nonNullObject));
            return true;
        }
    });
    r.register3("formatObject", Pointer.class, Class.class, boolean.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode memory, ValueNode hub, ValueNode rememberedSet) {
            b.addPush(JavaKind.Object, new FormatObjectNode(memory, hub, rememberedSet));
            return true;
        }
    });
    r.register5("formatArray", Pointer.class, Class.class, int.class, boolean.class, boolean.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode memory, ValueNode hub, ValueNode length, ValueNode rememberedSet, ValueNode unaligned) {
            b.addPush(JavaKind.Object, new FormatArrayNode(memory, hub, length, rememberedSet, unaligned));
            return true;
        }
    });
    r.register2("unsafeCast", Object.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object, ValueNode toTypeNode) {
            /*
                 * We need to make sure that the updated type information does not flow up, because
                 * it can depend on any condition before (and we do not know which condition, so we
                 * cannot anchor at a particular block).
                 */
            ResolvedJavaType toType = typeValue(b.getConstantReflection(), b, targetMethod, toTypeNode, "toType");
            TypeReference toTypeRef = TypeReference.createTrustedWithoutAssumptions(toType);
            b.addPush(JavaKind.Object, new FixedValueAnchorNode(object, StampFactory.object(toTypeRef)));
            return true;
        }
    });
    r.register1("nonNullPointer", Pointer.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            b.addPush(JavaKind.Object, new PiNode(object, nonZeroWord()));
            return true;
        }
    });
    r.register0("readStackPointer", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, new ReadStackPointerNode());
            return true;
        }
    });
    r.register1("writeStackPointer", Pointer.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.add(new WriteStackPointerNode(value));
            return true;
        }
    });
    r.register0("readInstructionPointer", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, new ReadInstructionPointerNode());
            return true;
        }
    });
    r.register0("readCallerStackPointer", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, new ReadCallerStackPointerNode());
            return true;
        }
    });
    r.register0("readReturnAddress", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, new ReadReturnAddressNode());
            return true;
        }
    });
    r.register3("farReturn", Object.class, Pointer.class, CodePointer.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode result, ValueNode sp, ValueNode ip) {
            b.add(new FarReturnNode(result, sp, ip));
            return true;
        }
    });
    r.register0("testDeoptimize", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new TestDeoptimizeNode());
            return true;
        }
    });
    r.register0("isDeoptimizationTarget", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (b.getGraph().method() instanceof SharedMethod) {
                SharedMethod method = (SharedMethod) b.getGraph().method();
                if (method.isDeoptTarget()) {
                    b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
                } else {
                    b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(false));
                }
            } else {
                // In analysis the value is always true.
                b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
            }
            return true;
        }
    });
    r.register2("convertUnknownValue", Object.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object, ValueNode typeNode) {
            ResolvedJavaType type = typeValue(b.getConstantReflection(), b, targetMethod, typeNode, "type");
            TypeReference typeRef = TypeReference.createTrustedWithoutAssumptions(type);
            Stamp stamp = StampFactory.object(typeRef);
            if (analysis) {
                b.addPush(JavaKind.Object, new ConvertUnknownValueNode(object, stamp));
            } else {
                b.addPush(JavaKind.Object, PiNode.create(object, stamp));
            }
            return true;
        }
    });
}
Also used : FixedValueAnchorNode(org.graalvm.compiler.nodes.extended.FixedValueAnchorNode) TestDeoptimizeNode(com.oracle.svm.core.graal.nodes.TestDeoptimizeNode) DynamicPiNode(org.graalvm.compiler.nodes.DynamicPiNode) PiNode(org.graalvm.compiler.nodes.PiNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) FarReturnNode(com.oracle.svm.core.graal.nodes.FarReturnNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ReadStackPointerNode(com.oracle.svm.core.graal.nodes.ReadStackPointerNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) ArrayLengthNode(org.graalvm.compiler.nodes.java.ArrayLengthNode) ReadCallerStackPointerNode(com.oracle.svm.core.graal.nodes.ReadCallerStackPointerNode) WriteStackPointerNode(com.oracle.svm.core.graal.nodes.WriteStackPointerNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ReadInstructionPointerNode(com.oracle.svm.core.graal.nodes.ReadInstructionPointerNode) ReadReturnAddressNode(com.oracle.svm.core.graal.nodes.ReadReturnAddressNode) FormatObjectNode(com.oracle.svm.core.graal.nodes.FormatObjectNode) FormatArrayNode(com.oracle.svm.core.graal.nodes.FormatArrayNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) SharedMethod(com.oracle.svm.core.meta.SharedMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 3 with ArrayLengthNode

use of org.graalvm.compiler.nodes.java.ArrayLengthNode 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)

Aggregations

ArrayLengthNode (org.graalvm.compiler.nodes.java.ArrayLengthNode)3 LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)2 LoadIndexedNode (org.graalvm.compiler.nodes.java.LoadIndexedNode)2 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)1 FarReturnNode (com.oracle.svm.core.graal.nodes.FarReturnNode)1 FormatArrayNode (com.oracle.svm.core.graal.nodes.FormatArrayNode)1 FormatObjectNode (com.oracle.svm.core.graal.nodes.FormatObjectNode)1 ReadCallerStackPointerNode (com.oracle.svm.core.graal.nodes.ReadCallerStackPointerNode)1 ReadInstructionPointerNode (com.oracle.svm.core.graal.nodes.ReadInstructionPointerNode)1 ReadReturnAddressNode (com.oracle.svm.core.graal.nodes.ReadReturnAddressNode)1 ReadStackPointerNode (com.oracle.svm.core.graal.nodes.ReadStackPointerNode)1 TestDeoptimizeNode (com.oracle.svm.core.graal.nodes.TestDeoptimizeNode)1 WriteStackPointerNode (com.oracle.svm.core.graal.nodes.WriteStackPointerNode)1 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)1 SharedMethod (com.oracle.svm.core.meta.SharedMethod)1 List (java.util.List)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)1 Stamp (org.graalvm.compiler.core.common.type.Stamp)1