Search in sources :

Example 16 with DebugContext

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

the class TruffleCompilerImpl method doCompile.

@Override
@SuppressWarnings("try")
public void doCompile(DebugContext inDebug, CompilationIdentifier inCompilationId, OptionValues options, CompilableTruffleAST compilable, TruffleInliningPlan inliningPlan, Cancellable cancellable, TruffleCompilerListener listener) {
    CompilationIdentifier compilationId = inCompilationId == null ? getCompilationIdentifier(compilable) : inCompilationId;
    DebugContext debug = inDebug == null ? openDebugContext(options, compilationId, compilable) : inDebug;
    try (DebugContext debugToClose = debug == inDebug ? null : debug;
        DebugContext.Scope s = maybeOpenTruffleScope(compilable, debug)) {
        new TruffleCompilationWrapper(getDebugOutputDirectory(), getCompilationProblemsPerAction(), compilable, cancellable, inliningPlan, compilationId, listener).run(debug);
    } catch (Throwable e) {
        notifyCompilableOfFailure(compilable, e);
    }
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) Scope(org.graalvm.compiler.debug.DebugContext.Scope) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 17 with DebugContext

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

the class BasicArrayCopyNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode sourcePosition = tool.getAlias(getSourcePosition());
    ValueNode destinationPosition = tool.getAlias(getDestinationPosition());
    ValueNode replacedLength = tool.getAlias(getLength());
    if (sourcePosition.isConstant() && destinationPosition.isConstant() && replacedLength.isConstant()) {
        int srcPosInt = sourcePosition.asJavaConstant().asInt();
        int destPosInt = destinationPosition.asJavaConstant().asInt();
        int len = replacedLength.asJavaConstant().asInt();
        ValueNode destAlias = tool.getAlias(getDestination());
        if (destAlias instanceof VirtualArrayNode) {
            VirtualArrayNode destVirtual = (VirtualArrayNode) destAlias;
            if (len < 0 || !checkBounds(destPosInt, len, destVirtual)) {
                return;
            }
            ValueNode srcAlias = tool.getAlias(getSource());
            if (srcAlias instanceof VirtualObjectNode) {
                if (!(srcAlias instanceof VirtualArrayNode)) {
                    return;
                }
                VirtualArrayNode srcVirtual = (VirtualArrayNode) srcAlias;
                if (destVirtual.componentType().getJavaKind() != srcVirtual.componentType().getJavaKind()) {
                    return;
                }
                if (!checkBounds(srcPosInt, len, srcVirtual)) {
                    return;
                }
                if (!checkEntryTypes(srcPosInt, len, srcVirtual, destVirtual.type().getComponentType(), tool)) {
                    return;
                }
                for (int i = 0; i < len; i++) {
                    tool.setVirtualEntry(destVirtual, destPosInt + i, tool.getEntry(srcVirtual, srcPosInt + i));
                }
                tool.delete();
                DebugContext debug = getDebug();
                if (debug.isLogEnabled()) {
                    debug.log("virtualized arraycopy(%s, %d, %s, %d, %d)", getSource(), srcPosInt, getDestination(), destPosInt, len);
                }
            } else {
                ResolvedJavaType sourceType = StampTool.typeOrNull(srcAlias);
                if (sourceType == null || !sourceType.isArray()) {
                    return;
                }
                ResolvedJavaType sourceComponentType = sourceType.getComponentType();
                ResolvedJavaType destComponentType = destVirtual.type().getComponentType();
                if (!sourceComponentType.equals(destComponentType)) {
                    return;
                }
                for (int i = 0; i < len; i++) {
                    LoadIndexedNode load = new LoadIndexedNode(graph().getAssumptions(), srcAlias, ConstantNode.forInt(i + srcPosInt, graph()), destComponentType.getJavaKind());
                    tool.addNode(load);
                    tool.setVirtualEntry(destVirtual, destPosInt + i, load);
                }
                tool.delete();
            }
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) VirtualArrayNode(org.graalvm.compiler.nodes.virtual.VirtualArrayNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DebugContext(org.graalvm.compiler.debug.DebugContext) AbstractMemoryCheckpoint(org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 18 with DebugContext

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

the class GraalTest method afterTest.

@After
public void afterTest() {
    List<DebugContext> cached = cachedDebugs.get();
    if (cached != null) {
        for (DebugContext debug : cached) {
            debug.close();
            debug.closeDumpHandlers(true);
        }
    }
}
Also used : DebugContext(org.graalvm.compiler.debug.DebugContext) After(org.junit.After)

Example 19 with DebugContext

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

the class GraalTest method getDebugContext.

/**
 * Gets a {@link DebugContext} object corresponding to {@code options}, creating a new one if
 * none currently exists. Debug contexts created by this method will have their
 * {@link DebugDumpHandler}s closed in {@link #afterTest()}.
 *
 * @param options currently active options
 * @param id identification of the compilation or {@code null}
 * @param method method to use for a proper description of the context or {@code null}
 * @return configured context for compilation
 */
protected DebugContext getDebugContext(OptionValues options, String id, ResolvedJavaMethod method) {
    List<DebugContext> cached = cachedDebugs.get();
    if (cached == null) {
        cached = new ArrayList<>();
        cachedDebugs.set(cached);
    }
    for (DebugContext debug : cached) {
        if (debug.getOptions() == options) {
            return debug;
        }
    }
    final DebugContext.Description descr;
    if (method == null) {
        descr = NO_DESCRIPTION;
    } else {
        descr = new DebugContext.Description(method, id == null ? method.getName() : id);
    }
    DebugContext debug = DebugContext.create(options, descr, globalMetrics, DEFAULT_LOG_STREAM, getDebugHandlersFactories());
    cached.add(debug);
    return debug;
}
Also used : DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 20 with DebugContext

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

the class SubstrateGraalUtils method compileGraph.

@SuppressWarnings("try")
public static CompilationResult compileGraph(RuntimeConfiguration runtimeConfig, Suites suites, LIRSuites lirSuites, final SharedMethod method, final StructuredGraph graph) {
    assert runtimeConfig != null : "no runtime";
    if (Options.ForceDumpGraphsBeforeCompilation.getValue()) {
        /*
             * forceDump is often used during debugging, and we want to make sure that it keeps
             * working, i.e., does not lead to image generation problems when adding a call to it.
             * This code ensures that forceDump is seen as reachable for all images that include
             * Graal, because it is conditional on a runtime option.
             */
        graph.getDebug().forceDump(graph, "Force dump before compilation");
    }
    String methodName = method.format("%h.%n");
    try (DebugContext debug = graph.getDebug();
        Indent indent = debug.logAndIndent("compile graph %s for method %s", graph, methodName)) {
        OptimisticOptimizations optimisticOpts = OptimisticOptimizations.ALL.remove(OptimisticOptimizations.Optimization.UseLoopLimitChecks);
        final Backend backend = runtimeConfig.lookupBackend(method);
        try (Indent indent2 = debug.logAndIndent("do compilation")) {
            SubstrateCompilationResult result = new SubstrateCompilationResult(graph.compilationId(), method.format("%H.%n(%p)"));
            GraalCompiler.compileGraph(graph, method, backend.getProviders(), backend, null, optimisticOpts, null, suites, lirSuites, result, CompilationResultBuilderFactory.Default);
            return result;
        }
    }
}
Also used : SubstrateCompilationResult(com.oracle.svm.core.graal.code.SubstrateCompilationResult) Indent(org.graalvm.compiler.debug.Indent) Backend(org.graalvm.compiler.core.target.Backend) DebugContext(org.graalvm.compiler.debug.DebugContext) OptimisticOptimizations(org.graalvm.compiler.phases.OptimisticOptimizations)

Aggregations

DebugContext (org.graalvm.compiler.debug.DebugContext)234 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)87 OptionValues (org.graalvm.compiler.options.OptionValues)50 Indent (org.graalvm.compiler.debug.Indent)37 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)31 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)29 Test (org.junit.Test)27 Node (org.graalvm.compiler.graph.Node)24 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)24 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)22 LIRInstruction (org.graalvm.compiler.lir.LIRInstruction)20 Scope (org.graalvm.compiler.debug.DebugContext.Scope)18 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)18 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)17 ValueNode (org.graalvm.compiler.nodes.ValueNode)16 FixedNode (org.graalvm.compiler.nodes.FixedNode)14 CompilationResult (org.graalvm.compiler.code.CompilationResult)13 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)13 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)12 LIR (org.graalvm.compiler.lir.LIR)11