Search in sources :

Example 26 with VirtualObjectNode

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

the class ArrayEqualsNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode alias1 = tool.getAlias(array1);
    ValueNode alias2 = tool.getAlias(array2);
    if (alias1 == alias2) {
        // the same virtual objects will always have the same contents
        tool.replaceWithValue(ConstantNode.forBoolean(true, graph()));
    } else if (alias1 instanceof VirtualObjectNode && alias2 instanceof VirtualObjectNode) {
        VirtualObjectNode virtual1 = (VirtualObjectNode) alias1;
        VirtualObjectNode virtual2 = (VirtualObjectNode) alias2;
        if (virtual1.entryCount() == virtual2.entryCount()) {
            int entryCount = virtual1.entryCount();
            boolean allEqual = true;
            for (int i = 0; i < entryCount; i++) {
                ValueNode entry1 = tool.getEntry(virtual1, i);
                ValueNode entry2 = tool.getEntry(virtual2, i);
                if (entry1 != entry2) {
                    if (entry1 instanceof ConstantNode && entry2 instanceof ConstantNode) {
                        // equal in Arrays.equals([F[F) or Arrays.equals([D[D).
                        if (entry1.getStackKind() == JavaKind.Float && entry2.getStackKind() == JavaKind.Float) {
                            float value1 = ((JavaConstant) ((ConstantNode) entry1).asConstant()).asFloat();
                            float value2 = ((JavaConstant) ((ConstantNode) entry2).asConstant()).asFloat();
                            if (Float.floatToIntBits(value1) != Float.floatToIntBits(value2)) {
                                allEqual = false;
                            }
                        } else if (entry1.getStackKind() == JavaKind.Double && entry2.getStackKind() == JavaKind.Double) {
                            double value1 = ((JavaConstant) ((ConstantNode) entry1).asConstant()).asDouble();
                            double value2 = ((JavaConstant) ((ConstantNode) entry2).asConstant()).asDouble();
                            if (Double.doubleToLongBits(value1) != Double.doubleToLongBits(value2)) {
                                allEqual = false;
                            }
                        } else {
                            allEqual = false;
                        }
                    } else {
                        // the contents might be different
                        allEqual = false;
                    }
                }
                if (entry1.stamp(NodeView.DEFAULT).alwaysDistinct(entry2.stamp(NodeView.DEFAULT))) {
                    // the contents are different
                    tool.replaceWithValue(ConstantNode.forBoolean(false, graph()));
                    return;
                }
            }
            if (allEqual) {
                tool.replaceWithValue(ConstantNode.forBoolean(true, graph()));
            }
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 27 with VirtualObjectNode

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

the class PartialEvaluator method postPartialEvaluation.

private static void postPartialEvaluation(final StructuredGraph graph) {
    NeverPartOfCompilationNode.verifyNotFoundIn(graph);
    for (AllowMaterializeNode materializeNode : graph.getNodes(AllowMaterializeNode.TYPE).snapshot()) {
        materializeNode.replaceAtUsages(materializeNode.getFrame());
        graph.removeFixed(materializeNode);
    }
    TruffleCompilerRuntime rt = TruffleCompilerRuntime.getRuntime();
    for (VirtualObjectNode virtualObjectNode : graph.getNodes(VirtualObjectNode.TYPE)) {
        if (virtualObjectNode instanceof VirtualInstanceNode) {
            VirtualInstanceNode virtualInstanceNode = (VirtualInstanceNode) virtualObjectNode;
            ResolvedJavaType type = virtualInstanceNode.type();
            if (rt.isValueType(type)) {
                virtualInstanceNode.setIdentity(false);
            }
        }
    }
    if (!TruffleCompilerOptions.getValue(TruffleInlineAcrossTruffleBoundary)) {
        // Do not inline across Truffle boundaries.
        for (MethodCallTargetNode mct : graph.getNodes(MethodCallTargetNode.TYPE)) {
            InlineInfo inlineInfo = rt.getInlineInfo(mct.targetMethod(), false);
            if (!inlineInfo.allowsInlining()) {
                mct.invoke().setUseForInlining(false);
            }
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) TruffleCompilerRuntime(org.graalvm.compiler.truffle.common.TruffleCompilerRuntime) AllowMaterializeNode(org.graalvm.compiler.truffle.compiler.nodes.frame.AllowMaterializeNode) VirtualInstanceNode(org.graalvm.compiler.nodes.virtual.VirtualInstanceNode) InlineInfo.createStandardInlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo) InlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 28 with VirtualObjectNode

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

the class AllowMaterializeNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode alias = tool.getAlias(frame);
    if (alias instanceof VirtualObjectNode) {
        VirtualObjectNode virtual = (VirtualObjectNode) alias;
        tool.setEnsureVirtualized(virtual, false);
        tool.replaceWithVirtual(virtual);
    } else {
        tool.replaceWithValue(alias);
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 29 with VirtualObjectNode

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

the class VirtualFrameGetNode 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()) {
            ValueNode actualTag = tool.getEntry(tagVirtual, frameSlotIndex);
            if (!actualTag.isConstant() || actualTag.asJavaConstant().asInt() != accessTag) {
                /*
                     * We cannot constant fold the tag-check immediately, so we need to create a
                     * guard comparing the actualTag with the accessTag.
                     */
                LogicNode comparison = new IntegerEqualsNode(actualTag, getConstant(accessTag));
                tool.addNode(comparison);
                tool.addNode(new FixedGuardNode(comparison, DeoptimizationReason.RuntimeConstraint, DeoptimizationAction.InvalidateRecompile));
            }
            ValueNode dataEntry = tool.getEntry(dataVirtual, frameSlotIndex);
            if (dataEntry.getStackKind() == getStackKind()) {
                tool.replaceWith(dataEntry);
                return;
            }
        }
    }
    /*
         * We could "virtualize" to a UnsafeLoadNode here that remains a memory access. However,
         * that could prevent further escape analysis for parts of the method that actually matter.
         * So we just deoptimize.
         */
    insertDeoptimization(tool);
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode)

Example 30 with VirtualObjectNode

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

the class VirtualFrameIsNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode tagAlias = tool.getAlias(frame.virtualFrameTagArray);
    if (tagAlias instanceof VirtualObjectNode) {
        VirtualObjectNode tagVirtual = (VirtualObjectNode) tagAlias;
        if (frameSlotIndex < tagVirtual.entryCount()) {
            ValueNode actualTag = tool.getEntry(tagVirtual, frameSlotIndex);
            if (actualTag.isConstant()) {
                tool.replaceWith(getConstant(actualTag.asJavaConstant().asInt() == accessTag ? 1 : 0));
            } else {
                LogicNode comparison = new IntegerEqualsNode(actualTag, getConstant(accessTag));
                tool.addNode(comparison);
                ConditionalNode result = new ConditionalNode(comparison, getConstant(1), getConstant(0));
                tool.addNode(result);
                tool.replaceWith(result);
            }
            return;
        }
    }
    /*
         * We could "virtualize" to a UnsafeLoadNode here that remains a memory access. But it is
         * simpler, and consistent with the get and set intrinsification, to deoptimize.
         */
    insertDeoptimization(tool);
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode)

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