Search in sources :

Example 26 with DebugCloseable

use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.

the class AbstractFixedGuardNode method lowerToIf.

@SuppressWarnings("try")
public DeoptimizeNode lowerToIf() {
    try (DebugCloseable position = this.withNodeSourcePosition()) {
        FixedNode currentNext = next();
        setNext(null);
        DeoptimizeNode deopt = graph().add(new DeoptimizeNode(action, reason, speculation));
        deopt.setStateBefore(stateBefore());
        IfNode ifNode;
        AbstractBeginNode noDeoptSuccessor;
        if (negated) {
            ifNode = graph().add(new IfNode(condition, deopt, currentNext, 0));
            noDeoptSuccessor = ifNode.falseSuccessor();
        } else {
            ifNode = graph().add(new IfNode(condition, currentNext, deopt, 1));
            noDeoptSuccessor = ifNode.trueSuccessor();
        }
        ((FixedWithNextNode) predecessor()).setNext(ifNode);
        this.replaceAtUsages(noDeoptSuccessor);
        GraphUtil.killWithUnusedFloatingInputs(this);
        return deopt;
    }
}
Also used : DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 27 with DebugCloseable

use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.

the class BeginNode method begin.

@SuppressWarnings("try")
public static AbstractBeginNode begin(FixedNode with) {
    try (DebugCloseable position = with.withNodeSourcePosition()) {
        if (with instanceof AbstractBeginNode) {
            return (AbstractBeginNode) with;
        }
        BeginNode begin = with.graph().add(new BeginNode());
        begin.setNext(with);
        return begin;
    }
}
Also used : DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 28 with DebugCloseable

use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.

the class SnippetTemplate method instantiate.

/**
 * Replaces a given floating node with this specialized snippet.
 *
 * @param metaAccess
 * @param replacee the node that will be replaced
 * @param replacer object that replaces the usages of {@code replacee}
 * @param tool lowering tool used to insert the snippet into the control-flow
 * @param args the arguments to be bound to the flattened positional parameters of the snippet
 */
@SuppressWarnings("try")
public void instantiate(MetaAccessProvider metaAccess, FloatingNode replacee, UsageReplacer replacer, LoweringTool tool, Arguments args) {
    DebugContext debug = replacee.getDebug();
    assert assertSnippetKills(replacee);
    try (DebugCloseable a = args.info.instantiationTimer.start(debug)) {
        args.info.instantiationCounter.increment(debug);
        // Inline the snippet nodes, replacing parameters with the given args in the process
        StartNode entryPointNode = snippet.start();
        FixedNode firstCFGNode = entryPointNode.next();
        StructuredGraph replaceeGraph = replacee.graph();
        EconomicMap<Node, Node> replacements = bind(replaceeGraph, metaAccess, args);
        replacements.put(entryPointNode, tool.getCurrentGuardAnchor().asNode());
        UnmodifiableEconomicMap<Node, Node> duplicates = inlineSnippet(replacee, debug, replaceeGraph, replacements);
        FixedWithNextNode lastFixedNode = tool.lastFixedNode();
        assert lastFixedNode != null && lastFixedNode.isAlive() : replaceeGraph + " lastFixed=" + lastFixedNode;
        FixedNode next = lastFixedNode.next();
        lastFixedNode.setNext(null);
        FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode);
        replaceeGraph.addAfterFixed(lastFixedNode, firstCFGNodeDuplicate);
        rewireFrameStates(replacee, duplicates);
        updateStamps(replacee, duplicates);
        rewireMemoryGraph(replacee, duplicates);
        // Replace all usages of the replacee with the value returned by the snippet
        ReturnNode returnDuplicate = (ReturnNode) duplicates.get(returnNode);
        ValueNode returnValue = returnDuplicate.result();
        assert returnValue != null || replacee.hasNoUsages();
        replacer.replace(replacee, returnValue);
        if (returnDuplicate.isAlive()) {
            returnDuplicate.replaceAndDelete(next);
        }
        debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After lowering %s with %s", replacee, this);
    }
}
Also used : StartNode(org.graalvm.compiler.nodes.StartNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) MemoryNode(org.graalvm.compiler.nodes.memory.MemoryNode) MemoryAnchorNode(org.graalvm.compiler.nodes.memory.MemoryAnchorNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) ExplodeLoopNode(org.graalvm.compiler.replacements.nodes.ExplodeLoopNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) LoadSnippetVarargParameterNode(org.graalvm.compiler.replacements.nodes.LoadSnippetVarargParameterNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) StartNode(org.graalvm.compiler.nodes.StartNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) MemoryMapNode(org.graalvm.compiler.nodes.memory.MemoryMapNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DebugContext(org.graalvm.compiler.debug.DebugContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) FixedNode(org.graalvm.compiler.nodes.FixedNode)

Example 29 with DebugCloseable

use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.

the class DefaultJavaLoweringProvider method lowerCommitAllocationNode.

@SuppressWarnings("try")
protected void lowerCommitAllocationNode(CommitAllocationNode commit, LoweringTool tool) {
    StructuredGraph graph = commit.graph();
    if (graph.getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS) {
        List<AbstractNewObjectNode> recursiveLowerings = new ArrayList<>();
        ValueNode[] allocations = new ValueNode[commit.getVirtualObjects().size()];
        BitSet omittedValues = new BitSet();
        int valuePos = 0;
        for (int objIndex = 0; objIndex < commit.getVirtualObjects().size(); objIndex++) {
            VirtualObjectNode virtual = commit.getVirtualObjects().get(objIndex);
            int entryCount = virtual.entryCount();
            AbstractNewObjectNode newObject;
            try (DebugCloseable nsp = virtual.withNodeSourcePosition()) {
                if (virtual instanceof VirtualInstanceNode) {
                    newObject = graph.add(createNewInstanceFromVirtual(virtual));
                } else {
                    newObject = graph.add(createNewArrayFromVirtual(virtual, ConstantNode.forInt(entryCount, graph)));
                }
            }
            recursiveLowerings.add(newObject);
            graph.addBeforeFixed(commit, newObject);
            allocations[objIndex] = newObject;
            for (int i = 0; i < entryCount; i++) {
                ValueNode value = commit.getValues().get(valuePos);
                if (value instanceof VirtualObjectNode) {
                    value = allocations[commit.getVirtualObjects().indexOf(value)];
                }
                if (value == null) {
                    omittedValues.set(valuePos);
                } else if (!(value.isConstant() && value.asConstant().isDefaultForKind())) {
                    // Constant.illegal is always the defaultForKind, so it is skipped
                    JavaKind valueKind = value.getStackKind();
                    JavaKind entryKind = virtual.entryKind(i);
                    // Truffle requires some leniency in terms of what can be put where:
                    assert valueKind.getStackKind() == entryKind.getStackKind() || (valueKind == JavaKind.Long || valueKind == JavaKind.Double || (valueKind == JavaKind.Int && virtual instanceof VirtualArrayNode));
                    AddressNode address = null;
                    BarrierType barrierType = null;
                    if (virtual instanceof VirtualInstanceNode) {
                        ResolvedJavaField field = ((VirtualInstanceNode) virtual).field(i);
                        long offset = fieldOffset(field);
                        if (offset >= 0) {
                            address = createOffsetAddress(graph, newObject, offset);
                            barrierType = fieldInitializationBarrier(entryKind);
                        }
                    } else {
                        address = createOffsetAddress(graph, newObject, arrayBaseOffset(entryKind) + i * arrayScalingFactor(entryKind));
                        barrierType = arrayInitializationBarrier(entryKind);
                    }
                    if (address != null) {
                        WriteNode write = new WriteNode(address, LocationIdentity.init(), implicitStoreConvert(graph, entryKind, value), barrierType);
                        graph.addAfterFixed(newObject, graph.add(write));
                    }
                }
                valuePos++;
            }
        }
        valuePos = 0;
        for (int objIndex = 0; objIndex < commit.getVirtualObjects().size(); objIndex++) {
            VirtualObjectNode virtual = commit.getVirtualObjects().get(objIndex);
            int entryCount = virtual.entryCount();
            ValueNode newObject = allocations[objIndex];
            for (int i = 0; i < entryCount; i++) {
                if (omittedValues.get(valuePos)) {
                    ValueNode value = commit.getValues().get(valuePos);
                    assert value instanceof VirtualObjectNode;
                    ValueNode allocValue = allocations[commit.getVirtualObjects().indexOf(value)];
                    if (!(allocValue.isConstant() && allocValue.asConstant().isDefaultForKind())) {
                        assert virtual.entryKind(i) == JavaKind.Object && allocValue.getStackKind() == JavaKind.Object;
                        AddressNode address;
                        BarrierType barrierType;
                        if (virtual instanceof VirtualInstanceNode) {
                            VirtualInstanceNode virtualInstance = (VirtualInstanceNode) virtual;
                            address = createFieldAddress(graph, newObject, virtualInstance.field(i));
                            barrierType = BarrierType.IMPRECISE;
                        } else {
                            address = createArrayAddress(graph, newObject, virtual.entryKind(i), ConstantNode.forInt(i, graph));
                            barrierType = BarrierType.PRECISE;
                        }
                        if (address != null) {
                            WriteNode write = new WriteNode(address, LocationIdentity.init(), implicitStoreConvert(graph, JavaKind.Object, allocValue), barrierType);
                            graph.addBeforeFixed(commit, graph.add(write));
                        }
                    }
                }
                valuePos++;
            }
        }
        finishAllocatedObjects(tool, commit, allocations);
        graph.removeFixed(commit);
        for (AbstractNewObjectNode recursiveLowering : recursiveLowerings) {
            recursiveLowering.lower(tool);
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) VirtualArrayNode(org.graalvm.compiler.nodes.virtual.VirtualArrayNode) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) BarrierType(org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) AbstractNewObjectNode(org.graalvm.compiler.nodes.java.AbstractNewObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) VirtualInstanceNode(org.graalvm.compiler.nodes.virtual.VirtualInstanceNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) AtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode) JavaWriteNode(org.graalvm.compiler.nodes.extended.JavaWriteNode) LoweredAtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 30 with DebugCloseable

use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.

the class GraphKit method createInvoke.

/**
 * Creates and appends an {@link InvokeNode} for a call to a given method with a given set of
 * arguments.
 */
@SuppressWarnings("try")
public InvokeNode createInvoke(ResolvedJavaMethod method, InvokeKind invokeKind, FrameStateBuilder frameStateBuilder, int bci, ValueNode... args) {
    try (DebugCloseable context = graph.withNodeSourcePosition(NodeSourcePosition.substitution(graph.currentNodeSourcePosition(), method))) {
        assert method.isStatic() == (invokeKind == InvokeKind.Static);
        Signature signature = method.getSignature();
        JavaType returnType = signature.getReturnType(null);
        assert checkArgs(method, args);
        StampPair returnStamp = graphBuilderPlugins.getOverridingStamp(this, returnType, false);
        if (returnStamp == null) {
            returnStamp = StampFactory.forDeclaredType(graph.getAssumptions(), returnType, false);
        }
        MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, method, args, returnStamp, bci));
        InvokeNode invoke = append(new InvokeNode(callTarget, bci));
        if (frameStateBuilder != null) {
            if (invoke.getStackKind() != JavaKind.Void) {
                frameStateBuilder.push(invoke.getStackKind(), invoke);
            }
            invoke.setStateAfter(frameStateBuilder.create(bci, invoke));
            if (invoke.getStackKind() != JavaKind.Void) {
                frameStateBuilder.pop(invoke.getStackKind());
            }
        }
        return invoke;
    }
}
Also used : JavaType(jdk.vm.ci.meta.JavaType) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) Signature(jdk.vm.ci.meta.Signature) StampPair(org.graalvm.compiler.core.common.type.StampPair) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Aggregations

DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)48 DebugContext (org.graalvm.compiler.debug.DebugContext)23 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)18 ValueNode (org.graalvm.compiler.nodes.ValueNode)14 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)9 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)9 OptionValues (org.graalvm.compiler.options.OptionValues)9 FixedNode (org.graalvm.compiler.nodes.FixedNode)8 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)8 Node (org.graalvm.compiler.graph.Node)7 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 MergeNode (org.graalvm.compiler.nodes.MergeNode)7 EndNode (org.graalvm.compiler.nodes.EndNode)6 StartNode (org.graalvm.compiler.nodes.StartNode)6 Method (java.lang.reflect.Method)5 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)5 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)5 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)5 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)5