Search in sources :

Example 6 with LoadHubNode

use of org.graalvm.compiler.nodes.extended.LoadHubNode in project graal by oracle.

the class DefaultHotSpotLoweringProvider method lowerGetClassNode.

private static void lowerGetClassNode(GetClassNode getClass, LoweringTool tool, StructuredGraph graph) {
    StampProvider stampProvider = tool.getStampProvider();
    LoadHubNode hub = graph.unique(new LoadHubNode(stampProvider, getClass.getObject()));
    HubGetClassNode hubGetClass = graph.unique(new HubGetClassNode(tool.getMetaAccess(), hub));
    getClass.replaceAtUsagesAndDelete(hubGetClass);
    hub.lower(tool);
    hubGetClass.lower(tool);
}
Also used : StampProvider(org.graalvm.compiler.nodes.spi.StampProvider) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) HubGetClassNode(org.graalvm.compiler.hotspot.replacements.HubGetClassNode)

Example 7 with LoadHubNode

use of org.graalvm.compiler.nodes.extended.LoadHubNode in project graal by oracle.

the class KlassLayoutHelperNode method inferStamp.

@Override
public boolean inferStamp() {
    if (klass instanceof LoadHubNode) {
        LoadHubNode hub = (LoadHubNode) klass;
        Stamp hubStamp = hub.getValue().stamp(NodeView.DEFAULT);
        if (hubStamp instanceof ObjectStamp) {
            ObjectStamp objectStamp = (ObjectStamp) hubStamp;
            ResolvedJavaType type = objectStamp.type();
            if (type != null && !type.isJavaLangObject()) {
                if (!type.isArray() && !type.isInterface()) {
                    /*
                         * Definitely some form of instance type.
                         */
                    return updateStamp(StampFactory.forInteger(JavaKind.Int, config.klassLayoutHelperNeutralValue, Integer.MAX_VALUE));
                }
                if (type.isArray()) {
                    return updateStamp(StampFactory.forInteger(JavaKind.Int, Integer.MIN_VALUE, config.klassLayoutHelperNeutralValue - 1));
                }
            }
        }
    }
    return false;
}
Also used : LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 8 with LoadHubNode

use of org.graalvm.compiler.nodes.extended.LoadHubNode in project graal by oracle.

the class KlassLayoutHelperNode method canonical.

private static ValueNode canonical(KlassLayoutHelperNode klassLayoutHelperNode, GraalHotSpotVMConfig config, ValueNode klass, Stamp stamp, ConstantReflectionProvider constantReflection, MetaAccessProvider metaAccess) {
    KlassLayoutHelperNode self = klassLayoutHelperNode;
    if (klass.isConstant()) {
        if (!klass.asConstant().isDefaultForKind()) {
            Constant constant = stamp.readConstant(constantReflection.getMemoryAccessProvider(), klass.asConstant(), config.klassLayoutHelperOffset);
            return ConstantNode.forConstant(stamp, constant, metaAccess);
        }
    }
    if (klass instanceof LoadHubNode) {
        LoadHubNode hub = (LoadHubNode) klass;
        Stamp hubStamp = hub.getValue().stamp(NodeView.DEFAULT);
        if (hubStamp instanceof ObjectStamp) {
            ObjectStamp ostamp = (ObjectStamp) hubStamp;
            HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) ostamp.type();
            if (type != null && type.isArray() && !type.getComponentType().isPrimitive()) {
                // The layout for all object arrays is the same.
                Constant constant = stamp.readConstant(constantReflection.getMemoryAccessProvider(), type.klass(), config.klassLayoutHelperOffset);
                return ConstantNode.forConstant(stamp, constant, metaAccess);
            }
        }
    }
    if (self == null) {
        self = new KlassLayoutHelperNode(config, klass);
    }
    return self;
}
Also used : LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Constant(jdk.vm.ci.meta.Constant) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType)

Example 9 with LoadHubNode

use of org.graalvm.compiler.nodes.extended.LoadHubNode in project graal by oracle.

the class TypeSwitchNode method simplify.

@Override
public void simplify(SimplifierTool tool) {
    NodeView view = NodeView.from(tool);
    if (value() instanceof ConstantNode) {
        Constant constant = value().asConstant();
        int survivingEdge = keySuccessorIndex(keyCount());
        for (int i = 0; i < keyCount(); i++) {
            Constant typeHub = keyAt(i);
            Boolean equal = tool.getConstantReflection().constantEquals(constant, typeHub);
            if (equal == null) {
                /* We don't know if this key is a match or not, so we cannot simplify. */
                return;
            } else if (equal.booleanValue()) {
                survivingEdge = keySuccessorIndex(i);
            }
        }
        killOtherSuccessors(tool, survivingEdge);
    }
    if (value() instanceof LoadHubNode && ((LoadHubNode) value()).getValue().stamp(view) instanceof ObjectStamp) {
        ObjectStamp objectStamp = (ObjectStamp) ((LoadHubNode) value()).getValue().stamp(view);
        if (objectStamp.type() != null) {
            int validKeys = 0;
            for (int i = 0; i < keyCount(); i++) {
                if (objectStamp.type().isAssignableFrom(keys[i])) {
                    validKeys++;
                }
            }
            if (validKeys == 0) {
                tool.addToWorkList(defaultSuccessor());
                graph().removeSplitPropagate(this, defaultSuccessor());
            } else if (validKeys != keys.length) {
                ArrayList<AbstractBeginNode> newSuccessors = new ArrayList<>(blockSuccessorCount());
                ResolvedJavaType[] newKeys = new ResolvedJavaType[validKeys];
                int[] newKeySuccessors = new int[validKeys + 1];
                double[] newKeyProbabilities = new double[validKeys + 1];
                double totalProbability = 0;
                int current = 0;
                for (int i = 0; i < keyCount() + 1; i++) {
                    if (i == keyCount() || objectStamp.type().isAssignableFrom(keys[i])) {
                        int index = newSuccessors.indexOf(keySuccessor(i));
                        if (index == -1) {
                            index = newSuccessors.size();
                            newSuccessors.add(keySuccessor(i));
                        }
                        newKeySuccessors[current] = index;
                        if (i < keyCount()) {
                            newKeys[current] = keys[i];
                        }
                        newKeyProbabilities[current] = keyProbability(i);
                        totalProbability += keyProbability(i);
                        current++;
                    }
                }
                if (totalProbability > 0) {
                    for (int i = 0; i < current; i++) {
                        newKeyProbabilities[i] /= totalProbability;
                    }
                } else {
                    for (int i = 0; i < current; i++) {
                        newKeyProbabilities[i] = 1.0 / current;
                    }
                }
                for (int i = 0; i < blockSuccessorCount(); i++) {
                    AbstractBeginNode successor = blockSuccessor(i);
                    if (!newSuccessors.contains(successor)) {
                        tool.deleteBranch(successor);
                    }
                    setBlockSuccessor(i, null);
                }
                AbstractBeginNode[] successorsArray = newSuccessors.toArray(new AbstractBeginNode[newSuccessors.size()]);
                TypeSwitchNode newSwitch = graph().add(new TypeSwitchNode(value(), successorsArray, newKeys, newKeyProbabilities, newKeySuccessors, tool.getConstantReflection()));
                ((FixedWithNextNode) predecessor()).setNext(newSwitch);
                GraphUtil.killWithUnusedFloatingInputs(this);
            }
        }
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Constant(jdk.vm.ci.meta.Constant) ArrayList(java.util.ArrayList) NodeView(org.graalvm.compiler.nodes.NodeView) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 10 with LoadHubNode

use of org.graalvm.compiler.nodes.extended.LoadHubNode in project graal by oracle.

the class TypeGuardInlineInfo method createGuard.

@SuppressWarnings("try")
private void createGuard(StructuredGraph graph, Providers providers) {
    try (DebugCloseable context = invoke.asNode().withNodeSourcePosition()) {
        ValueNode nonNullReceiver = InliningUtil.nonNullReceiver(invoke);
        LoadHubNode receiverHub = graph.unique(new LoadHubNode(providers.getStampProvider(), nonNullReceiver));
        ConstantNode typeHub = ConstantNode.forConstant(receiverHub.stamp(NodeView.DEFAULT), providers.getConstantReflection().asObjectHub(type), providers.getMetaAccess(), graph);
        LogicNode typeCheck = CompareNode.createCompareNode(graph, CanonicalCondition.EQ, receiverHub, typeHub, providers.getConstantReflection(), NodeView.DEFAULT);
        FixedGuardNode guard = graph.add(new FixedGuardNode(typeCheck, DeoptimizationReason.TypeCheckedInliningViolated, DeoptimizationAction.InvalidateReprofile));
        assert invoke.predecessor() != null;
        ValueNode anchoredReceiver = InliningUtil.createAnchoredReceiver(graph, guard, type, nonNullReceiver, true);
        invoke.callTarget().replaceFirstInput(nonNullReceiver, anchoredReceiver);
        graph.addBeforeFixed(invoke.asNode(), guard);
    }
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Aggregations

LoadHubNode (org.graalvm.compiler.nodes.extended.LoadHubNode)10 ValueNode (org.graalvm.compiler.nodes.ValueNode)5 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)4 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)4 Stamp (org.graalvm.compiler.core.common.type.Stamp)4 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 Constant (jdk.vm.ci.meta.Constant)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)2 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)2 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)2 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)2 LogicNode (org.graalvm.compiler.nodes.LogicNode)2 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)1 FarReturnNode (com.oracle.svm.core.graal.nodes.FarReturnNode)1 FloatingWordCastNode (com.oracle.svm.core.graal.nodes.FloatingWordCastNode)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