Search in sources :

Example 16 with GraalError

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

the class CompileQueue method defaultParseFunction.

@SuppressWarnings("try")
private void defaultParseFunction(DebugContext debug, HostedMethod method, CompileReason reason, RuntimeConfiguration config) {
    if (method.getAnnotation(Fold.class) != null || method.getAnnotation(NodeIntrinsic.class) != null) {
        throw VMError.shouldNotReachHere("Parsing method annotated with @Fold or @NodeIntrinsic: " + method.format("%H.%n(%p)"));
    }
    HostedProviders providers = (HostedProviders) config.lookupBackend(method).getProviders();
    boolean needParsing = false;
    OptionValues options = HostedOptionValues.singleton();
    StructuredGraph graph = method.buildGraph(debug, method, providers, Purpose.AOT_COMPILATION);
    if (graph == null) {
        InvocationPlugin plugin = providers.getGraphBuilderPlugins().getInvocationPlugins().lookupInvocation(method);
        if (plugin != null && !plugin.inlineOnly()) {
            Bytecode code = new ResolvedJavaMethodBytecode(method);
            // DebugContext debug = new DebugContext(options, providers.getSnippetReflection());
            graph = new SubstrateIntrinsicGraphBuilder(debug.getOptions(), debug, providers.getMetaAccess(), providers.getConstantReflection(), providers.getConstantFieldProvider(), providers.getStampProvider(), code).buildGraph(plugin);
        }
    }
    if (graph == null && method.isNative() && NativeImageOptions.ReportUnsupportedElementsAtRuntime.getValue()) {
        graph = DeletedMethod.buildGraph(debug, method, providers, DeletedMethod.NATIVE_MESSAGE);
    }
    if (graph == null) {
        needParsing = true;
        if (!method.compilationInfo.isDeoptTarget()) {
            /*
                 * Disabling liveness analysis preserves the values of local variables beyond the
                 * bytecode-liveness. This greatly helps debugging. When local variable numbers are
                 * reused by javac, local variables can still get illegal values. Since we cannot
                 * "restore" such illegal values during deoptimization, we must do liveness analysis
                 * for deoptimization target methods.
                 */
            options = new OptionValues(options, GraalOptions.OptClearNonLiveLocals, false);
        }
        graph = new StructuredGraph.Builder(options, debug).method(method).build();
    }
    try (DebugContext.Scope s = debug.scope("Parsing", graph, method, this)) {
        try {
            if (needParsing) {
                GraphBuilderConfiguration gbConf = createHostedGraphBuilderConfiguration(providers, method);
                new HostedGraphBuilderPhase(providers.getMetaAccess(), providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), gbConf, optimisticOpts, null, providers.getWordTypes()).apply(graph);
            } else {
                graph.setGuardsStage(GuardsStage.FIXED_DEOPTS);
            }
            new DeadStoreRemovalPhase().apply(graph);
            new DevirtualizeCallsPhase().apply(graph);
            new CanonicalizerPhase().apply(graph, new PhaseContext(providers));
            /*
                 * The StrengthenStampsPhase may not insert type check nodes for specialized
                 * methods, because we would get type state mismatches regarding Const<Type> !=
                 * <Type>
                 */
            /*
                 * cwimmer: the old, commented out, condition always disabled checking of static
                 * analysis results. Therefore, the checks are broken right now.
                 */
            // new StrengthenStampsPhase(BootImageOptions.CheckStaticAnalysisResults.getValue()
            // && method.compilationInfo.deoptTarget != null &&
            // !method.compilationInfo.isDeoptTarget).apply(graph);
            new StrengthenStampsPhase(false).apply(graph);
            new CanonicalizerPhase().apply(graph, new PhaseContext(providers));
            /* Check that graph is in good shape after parsing. */
            assert GraphOrder.assertSchedulableGraph(graph);
            method.compilationInfo.graph = graph;
            for (Invoke invoke : graph.getInvokes()) {
                if (!canBeUsedForInlining(invoke)) {
                    invoke.setUseForInlining(false);
                }
                if (invoke.callTarget() instanceof MethodCallTargetNode) {
                    MethodCallTargetNode targetNode = (MethodCallTargetNode) invoke.callTarget();
                    HostedMethod invokeTarget = (HostedMethod) targetNode.targetMethod();
                    if (targetNode.invokeKind().isDirect()) {
                        if (invokeTarget.wrapped.isImplementationInvoked()) {
                            handleSpecialization(method, targetNode, invokeTarget, invokeTarget);
                            ensureParsed(invokeTarget, new DirectCallReason(method, reason));
                        }
                    } else {
                        for (HostedMethod invokeImplementation : invokeTarget.getImplementations()) {
                            handleSpecialization(method, targetNode, invokeTarget, invokeImplementation);
                            ensureParsed(invokeImplementation, new VirtualCallReason(method, invokeImplementation, reason));
                        }
                    }
                }
            }
        } catch (Throwable ex) {
            GraalError error = ex instanceof GraalError ? (GraalError) ex : new GraalError(ex);
            error.addContext("method: " + method.format("%r %H.%n(%p)"));
            throw error;
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) OptionValues(org.graalvm.compiler.options.OptionValues) SubstrateIntrinsicGraphBuilder(com.oracle.graal.pointsto.phases.SubstrateIntrinsicGraphBuilder) HostedGraphBuilderPhase(com.oracle.svm.hosted.phases.HostedGraphBuilderPhase) DeadStoreRemovalPhase(com.oracle.svm.core.graal.phases.DeadStoreRemovalPhase) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Invoke(org.graalvm.compiler.nodes.Invoke) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) Bytecode(org.graalvm.compiler.bytecode.Bytecode) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) DevirtualizeCallsPhase(com.oracle.svm.hosted.phases.DevirtualizeCallsPhase) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) StrengthenStampsPhase(com.oracle.svm.hosted.phases.StrengthenStampsPhase)

Example 17 with GraalError

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

the class DebugInfoBuilder method computeFrameForState.

protected BytecodeFrame computeFrameForState(FrameState state) {
    try {
        assert state.bci != BytecodeFrame.INVALID_FRAMESTATE_BCI;
        assert state.bci != BytecodeFrame.UNKNOWN_BCI;
        assert state.bci != BytecodeFrame.BEFORE_BCI || state.locksSize() == 0;
        assert state.bci != BytecodeFrame.AFTER_BCI || state.locksSize() == 0;
        assert state.bci != BytecodeFrame.AFTER_EXCEPTION_BCI || state.locksSize() == 0;
        assert !(state.getMethod().isSynchronized() && state.bci != BytecodeFrame.BEFORE_BCI && state.bci != BytecodeFrame.AFTER_BCI && state.bci != BytecodeFrame.AFTER_EXCEPTION_BCI) || state.locksSize() > 0;
        assert state.verify();
        int numLocals = state.localsSize();
        int numStack = state.stackSize();
        int numLocks = state.locksSize();
        int numValues = numLocals + numStack + numLocks;
        int numKinds = numLocals + numStack;
        JavaValue[] values = numValues == 0 ? NO_JAVA_VALUES : new JavaValue[numValues];
        JavaKind[] slotKinds = numKinds == 0 ? NO_JAVA_KINDS : new JavaKind[numKinds];
        computeLocals(state, numLocals, values, slotKinds);
        computeStack(state, numLocals, numStack, values, slotKinds);
        computeLocks(state, values);
        BytecodeFrame caller = null;
        if (state.outerFrameState() != null) {
            caller = computeFrameForState(state.outerFrameState());
        }
        if (!state.canProduceBytecodeFrame()) {
            // This typically means a snippet or intrinsic frame state made it to the backend
            StackTraceElement ste = state.getCode().asStackTraceElement(state.bci);
            throw new GraalError("Frame state for %s cannot be converted to a BytecodeFrame since the frame state's code is " + "not the same as the frame state method's code", ste);
        }
        return new BytecodeFrame(caller, state.getMethod(), state.bci, state.rethrowException(), state.duringCall(), values, slotKinds, numLocals, numStack, numLocks);
    } catch (GraalError e) {
        throw e.addContext("FrameState: ", state);
    }
}
Also used : BytecodeFrame(jdk.vm.ci.code.BytecodeFrame) GraalError(org.graalvm.compiler.debug.GraalError) JavaValue(jdk.vm.ci.meta.JavaValue) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 18 with GraalError

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

the class NodeLIRBuilder method doBlock.

@Override
@SuppressWarnings("try")
public void doBlock(Block block, StructuredGraph graph, BlockMap<List<Node>> blockMap) {
    OptionValues options = graph.getOptions();
    try (BlockScope blockScope = gen.getBlockScope(block)) {
        setSourcePosition(null);
        if (block == gen.getResult().getLIR().getControlFlowGraph().getStartBlock()) {
            assert block.getPredecessorCount() == 0;
            emitPrologue(graph);
        } else {
            assert block.getPredecessorCount() > 0;
            // create phi-in value array
            AbstractBeginNode begin = block.getBeginNode();
            if (begin instanceof AbstractMergeNode) {
                AbstractMergeNode merge = (AbstractMergeNode) begin;
                LabelOp label = (LabelOp) gen.getResult().getLIR().getLIRforBlock(block).get(0);
                label.setPhiValues(createPhiIn(merge));
                if (Options.PrintIRWithLIR.getValue(options) && !TTY.isSuppressed()) {
                    TTY.println("Created PhiIn: " + label);
                }
            }
        }
        doBlockPrologue(block, options);
        List<Node> nodes = blockMap.get(block);
        // Allow NodeLIRBuilder subclass to specialize code generation of any interesting groups
        // of instructions
        matchComplexExpressions(nodes);
        boolean trace = traceLIRGeneratorLevel >= 3;
        for (int i = 0; i < nodes.size(); i++) {
            Node node = nodes.get(i);
            if (node instanceof ValueNode) {
                DebugContext debug = node.getDebug();
                ValueNode valueNode = (ValueNode) node;
                if (trace) {
                    TTY.println("LIRGen for " + valueNode);
                }
                Value operand = getOperand(valueNode);
                if (operand == null) {
                    if (!peephole(valueNode)) {
                        try {
                            doRoot(valueNode);
                        } catch (GraalError e) {
                            throw GraalGraphError.transformAndAddContext(e, valueNode);
                        } catch (Throwable e) {
                            throw new GraalGraphError(e).addContext(valueNode);
                        }
                    }
                } else if (ComplexMatchValue.INTERIOR_MATCH.equals(operand)) {
                    // Doesn't need to be evaluated
                    debug.log("interior match for %s", valueNode);
                } else if (operand instanceof ComplexMatchValue) {
                    debug.log("complex match for %s", valueNode);
                    ComplexMatchValue match = (ComplexMatchValue) operand;
                    operand = match.evaluate(this);
                    if (operand != null) {
                        setResult(valueNode, operand);
                    }
                } else {
                // There can be cases in which the result of an instruction is already set
                // before by other instructions.
                }
            }
        }
        if (!gen.hasBlockEnd(block)) {
            NodeIterable<Node> successors = block.getEndNode().successors();
            assert successors.count() == block.getSuccessorCount();
            if (block.getSuccessorCount() != 1) {
                /*
                     * If we have more than one successor, we cannot just use the first one. Since
                     * successors are unordered, this would be a random choice.
                     */
                throw new GraalError("Block without BlockEndOp: " + block.getEndNode());
            }
            gen.emitJump(getLIRBlock((FixedNode) successors.first()));
        }
        assert verifyBlock(gen.getResult().getLIR(), block);
    }
}
Also used : LabelOp(org.graalvm.compiler.lir.StandardOp.LabelOp) OptionValues(org.graalvm.compiler.options.OptionValues) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) IfNode(org.graalvm.compiler.nodes.IfNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DirectCallTargetNode(org.graalvm.compiler.nodes.DirectCallTargetNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) IntegerTestNode(org.graalvm.compiler.nodes.calc.IntegerTestNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) IntegerSwitchNode(org.graalvm.compiler.nodes.extended.IntegerSwitchNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) SwitchNode(org.graalvm.compiler.nodes.extended.SwitchNode) LoweredCallTargetNode(org.graalvm.compiler.nodes.LoweredCallTargetNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) Node(org.graalvm.compiler.graph.Node) PhiNode(org.graalvm.compiler.nodes.PhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LIRGenerationDebugContext(org.graalvm.compiler.lir.debug.LIRGenerationDebugContext) DebugContext(org.graalvm.compiler.debug.DebugContext) FixedNode(org.graalvm.compiler.nodes.FixedNode) ComplexMatchValue(org.graalvm.compiler.core.match.ComplexMatchValue) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) GraalError(org.graalvm.compiler.debug.GraalError) BlockScope(org.graalvm.compiler.lir.gen.LIRGeneratorTool.BlockScope) GraalGraphError(org.graalvm.compiler.graph.GraalGraphError) ValueNode(org.graalvm.compiler.nodes.ValueNode) ComplexMatchValue(org.graalvm.compiler.core.match.ComplexMatchValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue)

Example 19 with GraalError

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

the class GraalCompiler method emitLIR.

@SuppressWarnings("try")
public static LIRGenerationResult emitLIR(Backend backend, StructuredGraph graph, Object stub, RegisterConfig registerConfig, LIRSuites lirSuites) {
    String registerPressure = GraalOptions.RegisterPressure.getValue(graph.getOptions());
    String[] allocationRestrictedTo = registerPressure == null ? null : registerPressure.split(",");
    try {
        return emitLIR0(backend, graph, stub, registerConfig, lirSuites, allocationRestrictedTo);
    } catch (OutOfRegistersException e) {
        if (allocationRestrictedTo != null) {
            allocationRestrictedTo = null;
            return emitLIR0(backend, graph, stub, registerConfig, lirSuites, allocationRestrictedTo);
        }
        /* If the re-execution fails we convert the exception into a "hard" failure */
        throw new GraalError(e);
    } finally {
        graph.checkCancellation();
    }
}
Also used : GraalError(org.graalvm.compiler.debug.GraalError) OutOfRegistersException(org.graalvm.compiler.lir.alloc.OutOfRegistersException)

Example 20 with GraalError

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

the class GraalOSRLockTest method run.

protected static void run(Runnable r) {
    if (TestInSeparateThread) {
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                beforeOSRLockTest();
                r.run();
                afterOSRLockTest();
            }
        });
        t.start();
        try {
            t.join();
        } catch (Throwable t1) {
            throw new GraalError(t1);
        }
    } else {
        beforeOSRLockTest();
        r.run();
        afterOSRLockTest();
    }
}
Also used : GraalError(org.graalvm.compiler.debug.GraalError)

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