Search in sources :

Example 81 with DebugContext

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

the class GraalCompiler method emitCode.

@SuppressWarnings("try")
public static void emitCode(Backend backend, Assumptions assumptions, ResolvedJavaMethod rootMethod, Collection<ResolvedJavaMethod> inlinedMethods, EconomicSet<ResolvedJavaField> accessedFields, int bytecodeSize, LIRGenerationResult lirGenRes, CompilationResult compilationResult, ResolvedJavaMethod installedCodeOwner, CompilationResultBuilderFactory factory) {
    DebugContext debug = lirGenRes.getLIR().getDebug();
    try (DebugCloseable a = EmitCode.start(debug)) {
        FrameMap frameMap = lirGenRes.getFrameMap();
        CompilationResultBuilder crb = backend.newCompilationResultBuilder(lirGenRes, frameMap, compilationResult, factory);
        backend.emitCode(crb, lirGenRes.getLIR(), installedCodeOwner);
        if (assumptions != null && !assumptions.isEmpty()) {
            compilationResult.setAssumptions(assumptions.toArray());
        }
        if (rootMethod != null) {
            compilationResult.setMethods(rootMethod, inlinedMethods);
            compilationResult.setFields(accessedFields);
            compilationResult.setBytecodeSize(bytecodeSize);
        }
        crb.finish();
        if (debug.isCountEnabled()) {
            List<DataPatch> ldp = compilationResult.getDataPatches();
            JavaKind[] kindValues = JavaKind.values();
            CounterKey[] dms = new CounterKey[kindValues.length];
            for (int i = 0; i < dms.length; i++) {
                dms[i] = DebugContext.counter("DataPatches-%s", kindValues[i]);
            }
            for (DataPatch dp : ldp) {
                JavaKind kind = JavaKind.Illegal;
                if (dp.reference instanceof ConstantReference) {
                    VMConstant constant = ((ConstantReference) dp.reference).getConstant();
                    if (constant instanceof JavaConstant) {
                        kind = ((JavaConstant) constant).getJavaKind();
                    }
                }
                dms[kind.ordinal()].add(debug, 1);
            }
            DebugContext.counter("CompilationResults").increment(debug);
            DebugContext.counter("CodeBytesEmitted").add(debug, compilationResult.getTargetCodeSize());
            DebugContext.counter("InfopointsEmitted").add(debug, compilationResult.getInfopoints().size());
            DebugContext.counter("DataPatches").add(debug, ldp.size());
            DebugContext.counter("ExceptionHandlersEmitted").add(debug, compilationResult.getExceptionHandlers().size());
        }
        debug.dump(DebugContext.BASIC_LEVEL, compilationResult, "After code generation");
    }
}
Also used : FrameMap(org.graalvm.compiler.lir.framemap.FrameMap) ConstantReference(jdk.vm.ci.code.site.ConstantReference) JavaConstant(jdk.vm.ci.meta.JavaConstant) DebugContext(org.graalvm.compiler.debug.DebugContext) CounterKey(org.graalvm.compiler.debug.CounterKey) CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) DataPatch(jdk.vm.ci.code.site.DataPatch) VMConstant(jdk.vm.ci.meta.VMConstant) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 82 with DebugContext

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

the class GraalCompiler method emitLIR0.

@SuppressWarnings("try")
private static LIRGenerationResult emitLIR0(Backend backend, StructuredGraph graph, Object stub, RegisterConfig registerConfig, LIRSuites lirSuites, String[] allocationRestrictedTo) {
    DebugContext debug = graph.getDebug();
    try (DebugContext.Scope ds = debug.scope("EmitLIR");
        DebugCloseable a = EmitLIR.start(debug)) {
        assert !graph.hasValueProxies();
        ScheduleResult schedule = graph.getLastSchedule();
        Block[] blocks = schedule.getCFG().getBlocks();
        Block startBlock = schedule.getCFG().getStartBlock();
        assert startBlock != null;
        assert startBlock.getPredecessorCount() == 0;
        AbstractBlockBase<?>[] codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, startBlock);
        AbstractBlockBase<?>[] linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, startBlock);
        LIR lir = new LIR(schedule.getCFG(), linearScanOrder, codeEmittingOrder, graph.getOptions(), graph.getDebug());
        FrameMapBuilder frameMapBuilder = backend.newFrameMapBuilder(registerConfig);
        LIRGenerationResult lirGenRes = backend.newLIRGenerationResult(graph.compilationId(), lir, frameMapBuilder, graph, stub);
        LIRGeneratorTool lirGen = backend.newLIRGenerator(lirGenRes);
        NodeLIRBuilderTool nodeLirGen = backend.newNodeLIRBuilder(graph, lirGen);
        // LIR generation
        LIRGenerationContext context = new LIRGenerationContext(lirGen, nodeLirGen, graph, schedule);
        new LIRGenerationPhase().apply(backend.getTarget(), lirGenRes, context);
        try (DebugContext.Scope s = debug.scope("LIRStages", nodeLirGen, lirGenRes, lir)) {
            // Dump LIR along with HIR (the LIR is looked up from context)
            debug.dump(DebugContext.BASIC_LEVEL, graph.getLastSchedule(), "After LIR generation");
            LIRGenerationResult result = emitLowLevel(backend.getTarget(), lirGenRes, lirGen, lirSuites, backend.newRegisterAllocationConfig(registerConfig, allocationRestrictedTo));
            return result;
        } catch (Throwable e) {
            throw debug.handle(e);
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    } finally {
        graph.checkCancellation();
    }
}
Also used : ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) FrameMapBuilder(org.graalvm.compiler.lir.framemap.FrameMapBuilder) DebugContext(org.graalvm.compiler.debug.DebugContext) AbstractBlockBase(org.graalvm.compiler.core.common.cfg.AbstractBlockBase) NodeLIRBuilderTool(org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool) LIRGenerationResult(org.graalvm.compiler.lir.gen.LIRGenerationResult) LIRGenerationContext(org.graalvm.compiler.core.LIRGenerationPhase.LIRGenerationContext) LIR(org.graalvm.compiler.lir.LIR) Block(org.graalvm.compiler.nodes.cfg.Block) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) LIRGeneratorTool(org.graalvm.compiler.lir.gen.LIRGeneratorTool)

Example 83 with DebugContext

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

the class GraalCompiler method emitLowLevel.

public static LIRGenerationResult emitLowLevel(TargetDescription target, LIRGenerationResult lirGenRes, LIRGeneratorTool lirGen, LIRSuites lirSuites, RegisterAllocationConfig registerAllocationConfig) {
    DebugContext debug = lirGenRes.getLIR().getDebug();
    PreAllocationOptimizationContext preAllocOptContext = new PreAllocationOptimizationContext(lirGen);
    lirSuites.getPreAllocationOptimizationStage().apply(target, lirGenRes, preAllocOptContext);
    debug.dump(DebugContext.BASIC_LEVEL, lirGenRes.getLIR(), "After PreAllocationOptimizationStage");
    AllocationContext allocContext = new AllocationContext(lirGen.getSpillMoveFactory(), registerAllocationConfig);
    lirSuites.getAllocationStage().apply(target, lirGenRes, allocContext);
    debug.dump(DebugContext.BASIC_LEVEL, lirGenRes.getLIR(), "After AllocationStage");
    PostAllocationOptimizationContext postAllocOptContext = new PostAllocationOptimizationContext(lirGen);
    lirSuites.getPostAllocationOptimizationStage().apply(target, lirGenRes, postAllocOptContext);
    debug.dump(DebugContext.BASIC_LEVEL, lirGenRes.getLIR(), "After PostAllocationOptimizationStage");
    return lirGenRes;
}
Also used : AllocationContext(org.graalvm.compiler.lir.phases.AllocationPhase.AllocationContext) PreAllocationOptimizationContext(org.graalvm.compiler.lir.phases.PreAllocationOptimizationPhase.PreAllocationOptimizationContext) PostAllocationOptimizationContext(org.graalvm.compiler.lir.phases.PostAllocationOptimizationPhase.PostAllocationOptimizationContext) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 84 with DebugContext

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

the class Backend method createInstalledCode.

/**
 * Installs code based on a given compilation result.
 *
 * @param method the method compiled to produce {@code compiledCode} or {@code null} if the
 *            input to {@code compResult} was not a {@link ResolvedJavaMethod}
 * @param compilationRequest the compilation request or {@code null}
 * @param compilationResult the code to be installed
 * @param predefinedInstalledCode a pre-allocated {@link InstalledCode} object to use as a
 *            reference to the installed code. If {@code null}, a new {@link InstalledCode}
 *            object will be created.
 * @param speculationLog the speculation log to be used
 * @param isDefault specifies if the installed code should be made the default implementation of
 *            {@code compRequest.getMethod()}. The default implementation for a method is the
 *            code executed for standard calls to the method. This argument is ignored if
 *            {@code compRequest == null}.
 * @param context a custom debug context to use for the code installation
 * @return a reference to the compiled and ready-to-run installed code
 * @throws BailoutException if the code installation failed
 */
@SuppressWarnings("try")
public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult, SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault, Object[] context) {
    Object[] debugContext = context != null ? context : new Object[] { getProviders().getCodeCache(), method, compilationResult };
    CodeInstallationTask[] tasks;
    synchronized (this) {
        tasks = new CodeInstallationTask[codeInstallationTaskFactories.size()];
        for (int i = 0; i < codeInstallationTaskFactories.size(); i++) {
            tasks[i] = codeInstallationTaskFactories.get(i).create();
        }
    }
    try (DebugContext.Scope s2 = debug.scope("CodeInstall", debugContext);
        DebugContext.Activation a = debug.activate()) {
        InstalledCode installedCode;
        try {
            preCodeInstallationTasks(tasks, compilationResult, predefinedInstalledCode);
            CompiledCode compiledCode = createCompiledCode(method, compilationRequest, compilationResult);
            installedCode = getProviders().getCodeCache().installCode(method, compiledCode, predefinedInstalledCode, speculationLog, isDefault);
            assert predefinedInstalledCode == null || installedCode == predefinedInstalledCode;
        } catch (Throwable t) {
            failCodeInstallationTasks(tasks, t);
            throw t;
        }
        postCodeInstallationTasks(tasks, installedCode);
        return installedCode;
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : InstalledCode(jdk.vm.ci.code.InstalledCode) CompiledCode(jdk.vm.ci.code.CompiledCode) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 85 with DebugContext

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

the class DebugContextTest method testDisableIntercept.

@Test
public void testDisableIntercept() {
    EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
    // Configure with an option that enables scopes
    map.put(DebugOptions.DumpOnError, true);
    OptionValues options = new OptionValues(map);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(baos), DebugHandlersFactory.LOADER);
    Exception e = new Exception();
    try {
        try (DebugCloseable disabled = debug.disableIntercept();
            Scope s1 = debug.scope("ScopeWithDisabledIntercept")) {
            try (Scope s2 = debug.scope("InnerScopeInheritsDisabledIntercept")) {
                throw e;
            }
        } catch (Throwable t) {
            assert e == t;
            debug.handle(t);
        }
    } catch (Throwable t) {
        // The exception object should propagate all the way out through
        // an intercept disabled scope
        Assert.assertEquals(e, t);
    }
    String logged = baos.toString();
    Assert.assertEquals("Exception should not have been intercepted", "", logged);
}
Also used : PrintStream(java.io.PrintStream) OptionValues(org.graalvm.compiler.options.OptionValues) Scope(org.graalvm.compiler.debug.DebugContext.Scope) OptionKey(org.graalvm.compiler.options.OptionKey) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DebugContext(org.graalvm.compiler.debug.DebugContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) IOException(java.io.IOException) Test(org.junit.Test)

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