Search in sources :

Example 21 with GraalError

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

the class GraphOrder method visitForward.

private static void visitForward(ArrayList<Node> nodes, NodeBitMap visited, Node node, boolean floatingOnly) {
    try {
        assert node == null || node.isAlive() : node + " not alive";
        if (node != null && !visited.isMarked(node)) {
            if (floatingOnly && node instanceof FixedNode) {
                throw new GraalError("unexpected reference to fixed node: %s (this indicates an unexpected cycle)", node);
            }
            visited.mark(node);
            FrameState stateAfter = null;
            if (node instanceof StateSplit) {
                stateAfter = ((StateSplit) node).stateAfter();
            }
            for (Node input : node.inputs()) {
                if (input != stateAfter) {
                    visitForward(nodes, visited, input, true);
                }
            }
            if (node instanceof EndNode) {
                EndNode end = (EndNode) node;
                for (PhiNode phi : end.merge().phis()) {
                    visitForward(nodes, visited, phi.valueAt(end), true);
                }
            }
            nodes.add(node);
            if (node instanceof AbstractMergeNode) {
                for (PhiNode phi : ((AbstractMergeNode) node).phis()) {
                    visited.mark(phi);
                    nodes.add(phi);
                }
            }
            if (stateAfter != null) {
                visitForward(nodes, visited, stateAfter, true);
            }
        }
    } catch (GraalError e) {
        throw GraalGraphError.transformAndAddContext(e, node);
    }
}
Also used : GraalError(org.graalvm.compiler.debug.GraalError) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) EndNode(org.graalvm.compiler.nodes.EndNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) FrameState(org.graalvm.compiler.nodes.FrameState) StateSplit(org.graalvm.compiler.nodes.StateSplit)

Example 22 with GraalError

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

the class InliningData method doInline.

@SuppressWarnings("try")
private void doInline(CallsiteHolderExplorable callerCallsiteHolder, MethodInvocation calleeInvocation) {
    StructuredGraph callerGraph = callerCallsiteHolder.graph();
    InlineInfo calleeInfo = calleeInvocation.callee();
    try {
        try (DebugContext.Scope scope = debug.scope("doInline", callerGraph)) {
            EconomicSet<Node> canonicalizedNodes = EconomicSet.create(Equivalence.IDENTITY);
            canonicalizedNodes.addAll(calleeInfo.invoke().asNode().usages());
            EconomicSet<Node> parameterUsages = calleeInfo.inline(new Providers(context));
            canonicalizedNodes.addAll(parameterUsages);
            counterInliningRuns.increment(debug);
            debug.dump(DebugContext.DETAILED_LEVEL, callerGraph, "after %s", calleeInfo);
            Graph.Mark markBeforeCanonicalization = callerGraph.getMark();
            canonicalizer.applyIncremental(callerGraph, context, canonicalizedNodes);
            // process invokes that are possibly created during canonicalization
            for (Node newNode : callerGraph.getNewNodes(markBeforeCanonicalization)) {
                if (newNode instanceof Invoke) {
                    callerCallsiteHolder.pushInvoke((Invoke) newNode);
                }
            }
            callerCallsiteHolder.computeProbabilities();
            counterInliningPerformed.increment(debug);
        }
    } catch (BailoutException bailout) {
        throw bailout;
    } catch (AssertionError | RuntimeException e) {
        throw new GraalError(e).addContext(calleeInfo.toString());
    } catch (GraalError e) {
        throw e.addContext(calleeInfo.toString());
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : AllocatedObjectNode(org.graalvm.compiler.nodes.virtual.AllocatedObjectNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) AbstractNewObjectNode(org.graalvm.compiler.nodes.java.AbstractNewObjectNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) TypeGuardInlineInfo(org.graalvm.compiler.phases.common.inlining.info.TypeGuardInlineInfo) AssumptionInlineInfo(org.graalvm.compiler.phases.common.inlining.info.AssumptionInlineInfo) InlineInfo(org.graalvm.compiler.phases.common.inlining.info.InlineInfo) ExactInlineInfo(org.graalvm.compiler.phases.common.inlining.info.ExactInlineInfo) MultiTypeGuardInlineInfo(org.graalvm.compiler.phases.common.inlining.info.MultiTypeGuardInlineInfo) DebugContext(org.graalvm.compiler.debug.DebugContext) Providers(org.graalvm.compiler.phases.util.Providers) Invoke(org.graalvm.compiler.nodes.Invoke) BailoutException(jdk.vm.ci.code.BailoutException) InlineableGraph(org.graalvm.compiler.phases.common.inlining.info.elem.InlineableGraph) Graph(org.graalvm.compiler.graph.Graph) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError)

Example 23 with GraalError

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

the class NoDeadCodeVerifyHandler method verify.

@Override
public void verify(DebugContext debug, Object object, String format, Object... args) {
    OptionValues options = debug.getOptions();
    if (Options.NDCV.getValue(options) != OFF && object instanceof StructuredGraph) {
        StructuredGraph graph = (StructuredGraph) object;
        List<Node> before = graph.getNodes().snapshot();
        new DeadCodeEliminationPhase().run(graph);
        List<Node> after = graph.getNodes().snapshot();
        assert after.size() <= before.size();
        if (before.size() != after.size()) {
            if (discovered.put(format, Boolean.TRUE) == null) {
                before.removeAll(after);
                String prefix = format == null ? "" : format + ": ";
                GraalError error = new GraalError("%sfound dead nodes in %s: %s", prefix, graph, before);
                if (Options.NDCV.getValue(options) == INFO) {
                    System.out.println(error.getMessage());
                } else if (Options.NDCV.getValue(options) == VERBOSE) {
                    error.printStackTrace(System.out);
                } else {
                    assert Options.NDCV.getValue(options) == FATAL;
                    throw error;
                }
            }
        }
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) Node(org.graalvm.compiler.graph.Node) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)

Example 24 with GraalError

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

the class EffectsClosure method processLoop.

@Override
@SuppressWarnings("try")
protected final List<BlockT> processLoop(Loop<Block> loop, BlockT initialState) {
    if (initialState.isDead()) {
        ArrayList<BlockT> states = new ArrayList<>();
        for (int i = 0; i < loop.getExits().size(); i++) {
            states.add(initialState);
        }
        return states;
    }
    /*
         * Special case nested loops: To avoid an exponential runtime for nested loops we try to
         * only process them as little times as possible.
         *
         * In the first iteration of an outer most loop we go into the inner most loop(s). We run
         * the first iteration of the inner most loop and then, if necessary, a second iteration.
         *
         * We return from the recursion and finish the first iteration of the outermost loop. If we
         * have to do a second iteration in the outer most loop we go again into the inner most
         * loop(s) but this time we already know all states that are killed by the loop so inside
         * the loop we will only have those changes that propagate from the first iteration of the
         * outer most loop into the current loop. We strip the initial loop state for the inner most
         * loops and do the first iteration with the (possible) changes from outer loops. If there
         * are no changes we only have to do 1 iteration and are done.
         *
         */
    BlockT initialStateRemovedKilledLocations = stripKilledLoopLocations(loop, cloneState(initialState));
    BlockT loopEntryState = initialStateRemovedKilledLocations;
    BlockT lastMergedState = cloneState(initialStateRemovedKilledLocations);
    processInitialLoopState(loop, lastMergedState);
    MergeProcessor mergeProcessor = createMergeProcessor(loop.getHeader());
    /*
         * Iterative loop processing: we take the predecessor state as the loop's starting state,
         * processing the loop contents, merge the states of all loop ends, and check whether the
         * resulting state is equal to the starting state. If it is, the loop processing has
         * finished, if not, another iteration is needed.
         *
         * This processing converges because the merge processing always makes the starting state
         * more generic, e.g., adding phis instead of non-phi values.
         */
    for (int iteration = 0; iteration < 10; iteration++) {
        try (Indent i = debug.logAndIndent("================== Process Loop Effects Closure: block:%s begin node:%s", loop.getHeader(), loop.getHeader().getBeginNode())) {
            LoopInfo<BlockT> info = ReentrantBlockIterator.processLoop(this, loop, cloneState(lastMergedState));
            List<BlockT> states = new ArrayList<>();
            states.add(initialStateRemovedKilledLocations);
            states.addAll(info.endStates);
            doMergeWithoutDead(mergeProcessor, states);
            debug.log("MergeProcessor New State: %s", mergeProcessor.newState);
            debug.log("===== vs.");
            debug.log("Last Merged State: %s", lastMergedState);
            if (mergeProcessor.newState.equivalentTo(lastMergedState)) {
                blockEffects.get(loop.getHeader()).insertAll(mergeProcessor.mergeEffects, 0);
                loopMergeEffects.put(loop, mergeProcessor.afterMergeEffects);
                assert info.exitStates.size() == loop.getExits().size();
                loopEntryStates.put((LoopBeginNode) loop.getHeader().getBeginNode(), loopEntryState);
                assert assertExitStatesNonEmpty(loop, info);
                processKilledLoopLocations(loop, initialStateRemovedKilledLocations, mergeProcessor.newState);
                return info.exitStates;
            } else {
                lastMergedState = mergeProcessor.newState;
                for (Block block : loop.getBlocks()) {
                    blockEffects.get(block).clear();
                }
            }
        }
    }
    throw new GraalError("too many iterations at %s", loop);
}
Also used : Indent(org.graalvm.compiler.debug.Indent) GraalError(org.graalvm.compiler.debug.GraalError) ArrayList(java.util.ArrayList) Block(org.graalvm.compiler.nodes.cfg.Block)

Example 25 with GraalError

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

the class CompileTheWorld method compile.

/**
 * Compiles all methods in all classes in {@link #inputClassPath}. If {@link #inputClassPath}
 * equals {@link #SUN_BOOT_CLASS_PATH} the boot classes are used.
 */
public void compile() throws Throwable {
    if (SUN_BOOT_CLASS_PATH.equals(inputClassPath)) {
        String bcpEntry = null;
        if (Java8OrEarlier) {
            final String[] entries = System.getProperty(SUN_BOOT_CLASS_PATH).split(File.pathSeparator);
            for (int i = 0; i < entries.length && bcpEntry == null; i++) {
                String entry = entries[i];
                File entryFile = new File(entry);
                if (entryFile.getName().endsWith("rt.jar") && entryFile.isFile()) {
                    bcpEntry = entry;
                }
            }
            if (bcpEntry == null) {
                throw new GraalError("Could not find rt.jar on boot class path %s", System.getProperty(SUN_BOOT_CLASS_PATH));
            }
        } else {
            bcpEntry = JRT_CLASS_PATH_ENTRY;
        }
        compile(bcpEntry);
    } else {
        compile(inputClassPath);
    }
}
Also used : GraalError(org.graalvm.compiler.debug.GraalError) JarFile(java.util.jar.JarFile) File(java.io.File) Print(org.graalvm.compiler.core.CompilationWrapper.ExceptionAction.Print)

Aggregations

GraalError (org.graalvm.compiler.debug.GraalError)42 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)9 ValueNode (org.graalvm.compiler.nodes.ValueNode)8 DebugContext (org.graalvm.compiler.debug.DebugContext)7 Indent (org.graalvm.compiler.debug.Indent)5 IOException (java.io.IOException)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 Node (org.graalvm.compiler.graph.Node)4 OptionValues (org.graalvm.compiler.options.OptionValues)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 ArrayList (java.util.ArrayList)3 CompilationResult (org.graalvm.compiler.code.CompilationResult)3 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 Invoke (org.graalvm.compiler.nodes.Invoke)3 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)3 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)3 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)2 InstalledCode (jdk.vm.ci.code.InstalledCode)2