use of net.bytebuddy.jar.asm.ClassVisitor in project reactor-core by reactor.
the class ReactorDebugAgent method instrument.
private static void instrument(Instrumentation instrumentation) {
ClassFileTransformer transformer = new ClassFileTransformer() {
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> clazz, ProtectionDomain protectionDomain, byte[] bytes) {
if (loader == null) {
return null;
}
if (className == null || className.startsWith("java/") || className.startsWith("jdk/") || className.startsWith("sun/") || className.startsWith("com/sun/") || className.startsWith("reactor/core/")) {
return null;
}
if (clazz != null && (clazz.isPrimitive() || clazz.isArray() || clazz.isAnnotation() || clazz.isSynthetic())) {
return null;
}
ClassReader cr = new ClassReader(bytes);
ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS);
AtomicBoolean changed = new AtomicBoolean();
ClassVisitor classVisitor = new ReactorDebugClassVisitor(cw, changed);
try {
cr.accept(classVisitor, 0);
} catch (Throwable e) {
e.printStackTrace();
throw e;
}
if (!changed.get()) {
return null;
}
return cw.toByteArray();
}
};
instrumentation.addTransformer(transformer, true);
}
Aggregations