}
private byte[] instrumentClass(String className, ClassReader r) {
log(LogLevel.INFO, "TRANSFORM: %s %s", className, (db.getClassEntry(className) != null && db.getClassEntry(className).requiresInstrumentation()) ? "request" : "");
final ClassWriter cw = new DBClassWriter(db, r);
ClassVisitor cv = (check && EXAMINED_CLASS == null) ? new CheckClassAdapter(cw) : cw;
if (EXAMINED_CLASS != null && className.startsWith(EXAMINED_CLASS))
cv = new TraceClassVisitor(cv, new PrintWriter(System.out));
final InstrumentClass ic = new InstrumentClass(cv, db, false);
byte[] transformed = null;
try {
r.accept(ic, ClassReader.SKIP_FRAMES);
transformed = cw.toByteArray();
} catch (Exception e) {
if (ic.hasSuspendableMethods()) {
error("Unable to instrument class " + className, e);
throw e;
} else {
if (!MethodDatabase.isProblematicClass(className))
log(LogLevel.DEBUG, "Unable to instrument class " + className);
return null;
}
}
if (EXAMINED_CLASS != null) {
if (className.startsWith(EXAMINED_CLASS)) {
try (OutputStream os = new FileOutputStream(className.replace('/', '.') + ".class")) {
os.write(transformed);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (check) {
ClassReader r2 = new ClassReader(transformed);
ClassVisitor cv2 = new CheckClassAdapter(new TraceClassVisitor(null), true);
r2.accept(cv2, 0);
}
}
return transformed;