ExitCode (CompileContext context, ModuleChunk chunk, InstrumentationClassFinder finder, OutputConsumer outputConsumer) { ExitCode exitCode = ExitCode.NOTHING_DONE; for (CompiledClass compiledClass : outputConsumer.getCompiledClasses().values()) { if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) { LOG.debug("checking " + compiledClass + " by " + getClass()); } final BinaryContent originalContent = compiledClass.getContent(); final ClassReader reader = new FailSafeClassReader(originalContent.getBuffer(), originalContent.getOffset(), originalContent.getLength()); final int version = InstrumenterClassWriter.getClassFileVersion(reader); if (IS_INSTRUMENTED_KEY.get(compiledClass, Boolean.FALSE) || !canInstrument(compiledClass, version)) { // do not instrument the same content twice continue; } final ClassWriter writer = new InstrumenterClassWriter(reader, InstrumenterClassWriter.getAsmClassWriterFlags(version), finder); try { if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) { LOG.debug("instrumenting " + compiledClass + " by " + getClass()); } final BinaryContent instrumented = instrument(context, compiledClass, reader, writer, finder); if (instrumented != null) { compiledClass.setContent(instrumented); String className = compiledClass.getClassName(); assert className != null : compiledClass; finder.cleanCachedData(className); IS_INSTRUMENTED_KEY.set(compiledClass, Boolean.TRUE); exitCode = ExitCode.OK; } } catch (Throwable e) { LOG.info(e); final String message = e.getMessage(); if (message != null) { String sourcePath = ContainerUtil.getFirstItem(compiledClass.getSourceFilesPaths()); context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, message, sourcePath)); } else { context.processMessage(CompilerMessage.createInternalCompilationError(getPresentableName(), e)); } } } return exitCode; }