This commit is contained in:
Shautvast 2024-07-03 14:12:07 +02:00
parent a73acb9ddb
commit 600589edc3

View file

@ -22,12 +22,12 @@ public class Agent {
instrumentation.addTransformer(new ClassFileTransformer() { instrumentation.addTransformer(new ClassFileTransformer() {
@Override @Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) { public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
return instrumentExceptionLoggerAtThrow(className, classfileBuffer); return injectExceptionLoggerBeforeThrow(className, classfileBuffer);
} }
@Override @Override
public byte[] transform(Module module, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) { public byte[] transform(Module module, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
return instrumentExceptionLoggerAtThrow(className, classfileBuffer); return injectExceptionLoggerBeforeThrow(className, classfileBuffer);
} }
}, true); }, true);
} }
@ -35,7 +35,7 @@ public class Agent {
/* /*
* Every throw opcode will be preceded by a call to our ExceptionLogger * Every throw opcode will be preceded by a call to our ExceptionLogger
*/ */
private static byte[] instrumentExceptionLoggerAtThrow(String className, byte[] classfileBuffer) { private static byte[] injectExceptionLoggerBeforeThrow(String className, byte[] classfileBuffer) {
var classFile = ClassFile.of(); var classFile = ClassFile.of();
var classModel = classFile.parse(classfileBuffer); var classModel = classFile.parse(classfileBuffer);
return classFile.build(classModel.thisClass().asSymbol(), classBuilder -> { return classFile.build(classModel.thisClass().asSymbol(), classBuilder -> {