Search in sources :

Example 1 with CounterKey

use of org.graalvm.compiler.debug.CounterKey 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 2 with CounterKey

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

the class DebugContextTest method testInvariantChecking.

/**
 * Tests that using a {@link DebugContext} on a thread other than the one on which it was
 * created causes an assertion failure.
 */
@Test
public void testInvariantChecking() throws InterruptedException {
    Assume.assumeTrue(Assertions.assertionsEnabled());
    EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
    // Configure with an option that enables counters
    map.put(DebugOptions.Counters, "");
    OptionValues options = new OptionValues(map);
    DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
    CounterKey counter = DebugContext.counter("DebugContextTestCounter");
    AssertionError[] result = { null };
    Thread thread = new Thread() {

        @Override
        public void run() {
            try {
                counter.add(debug, 1);
            } catch (AssertionError e) {
                result[0] = e;
            }
        }
    };
    thread.start();
    thread.join();
    Assert.assertNotNull("Expected thread to throw AssertionError", result[0]);
}
Also used : CounterKey(org.graalvm.compiler.debug.CounterKey) OptionValues(org.graalvm.compiler.options.OptionValues) OptionKey(org.graalvm.compiler.options.OptionKey) DebugContext(org.graalvm.compiler.debug.DebugContext) Test(org.junit.Test)

Aggregations

CounterKey (org.graalvm.compiler.debug.CounterKey)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 ConstantReference (jdk.vm.ci.code.site.ConstantReference)1 DataPatch (jdk.vm.ci.code.site.DataPatch)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 VMConstant (jdk.vm.ci.meta.VMConstant)1 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)1 CompilationResultBuilder (org.graalvm.compiler.lir.asm.CompilationResultBuilder)1 FrameMap (org.graalvm.compiler.lir.framemap.FrameMap)1 OptionKey (org.graalvm.compiler.options.OptionKey)1 OptionValues (org.graalvm.compiler.options.OptionValues)1 Test (org.junit.Test)1