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");
}
}
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]);
}
Aggregations