Upgrade Byte-buddy to 1.8.8

Also remove some erronously checked in files.
This commit is contained in:
Tyler Benson 2018-04-26 16:19:48 +10:00
parent f295b73d4b
commit 57eade612f
5 changed files with 54 additions and 63 deletions

View File

@ -1,6 +1,7 @@
package datadog.trace.agent.tooling;
import datadog.trace.bootstrap.ExceptionLogger;
import net.bytebuddy.asm.Advice.ExceptionHandler;
import net.bytebuddy.implementation.Implementation;
import net.bytebuddy.implementation.bytecode.StackManipulation;
import net.bytebuddy.jar.asm.Label;
@ -16,65 +17,66 @@ public class ExceptionHandlers {
// Bootstrap ExceptionHandler.class will always be resolvable, so we'll use it in the log name
private static final String HANDLER_NAME = ExceptionLogger.class.getName().replace('.', '/');
private static final StackManipulation EXCEPTION_STACK_HANDLER =
new StackManipulation() {
// Pops one Throwable off the stack. Maxes the stack to at least 3.
private final Size size = new StackManipulation.Size(-1, 3);
private static final ExceptionHandler EXCEPTION_STACK_HANDLER =
new ExceptionHandler.Simple(
new StackManipulation() {
// Pops one Throwable off the stack. Maxes the stack to at least 3.
private final Size size = new StackManipulation.Size(-1, 3);
@Override
public boolean isValid() {
return true;
}
@Override
public boolean isValid() {
return true;
}
@Override
public Size apply(MethodVisitor mv, Implementation.Context context) {
// writes the following bytecode:
// try {
// org.slf4j.LoggerFactory.getLogger((Class)ExceptionLogger.class).debug("exception in instrumentation", t);
// } catch (Throwable t2) {
// }
Label logStart = new Label();
Label logEnd = new Label();
Label eatException = new Label();
Label handlerExit = new Label();
@Override
public Size apply(final MethodVisitor mv, final Implementation.Context context) {
// writes the following bytecode:
// try {
// org.slf4j.LoggerFactory.getLogger((Class)ExceptionLogger.class).debug("exception in instrumentation", t);
// } catch (Throwable t2) {
// }
final Label logStart = new Label();
final Label logEnd = new Label();
final Label eatException = new Label();
final Label handlerExit = new Label();
mv.visitTryCatchBlock(logStart, logEnd, eatException, "java/lang/Throwable");
mv.visitTryCatchBlock(logStart, logEnd, eatException, "java/lang/Throwable");
// stack: (top) throwable
mv.visitLabel(logStart);
mv.visitLdcInsn(Type.getType("L" + HANDLER_NAME + ";"));
mv.visitMethodInsn(
Opcodes.INVOKESTATIC,
LOG_FACTORY_NAME,
"getLogger",
"(Ljava/lang/Class;)L" + LOGGER_NAME + ";",
false);
mv.visitInsn(Opcodes.SWAP); // stack: (top) throwable,logger
mv.visitLdcInsn("Failed to handle exception in instrumentation");
mv.visitInsn(Opcodes.SWAP); // stack: (top) throwable,string,logger
mv.visitMethodInsn(
Opcodes.INVOKEINTERFACE,
LOGGER_NAME,
"debug",
"(Ljava/lang/String;Ljava/lang/Throwable;)V",
true);
mv.visitLabel(logEnd);
mv.visitJumpInsn(Opcodes.GOTO, handlerExit);
// stack: (top) throwable
mv.visitLabel(logStart);
mv.visitLdcInsn(Type.getType("L" + HANDLER_NAME + ";"));
mv.visitMethodInsn(
Opcodes.INVOKESTATIC,
LOG_FACTORY_NAME,
"getLogger",
"(Ljava/lang/Class;)L" + LOGGER_NAME + ";",
false);
mv.visitInsn(Opcodes.SWAP); // stack: (top) throwable,logger
mv.visitLdcInsn("Failed to handle exception in instrumentation");
mv.visitInsn(Opcodes.SWAP); // stack: (top) throwable,string,logger
mv.visitMethodInsn(
Opcodes.INVOKEINTERFACE,
LOGGER_NAME,
"debug",
"(Ljava/lang/String;Ljava/lang/Throwable;)V",
true);
mv.visitLabel(logEnd);
mv.visitJumpInsn(Opcodes.GOTO, handlerExit);
// if the runtime can't reach our ExceptionHandler or logger, silently eat the exception
mv.visitLabel(eatException);
mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"java/lang/Throwable"});
mv.visitInsn(Opcodes.POP);
// mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "printStackTrace", "()V", false);
// if the runtime can't reach our ExceptionHandler or logger, silently eat the exception
mv.visitLabel(eatException);
mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"java/lang/Throwable"});
mv.visitInsn(Opcodes.POP);
// mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "printStackTrace", "()V", false);
mv.visitLabel(handlerExit);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
mv.visitLabel(handlerExit);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
return size;
}
};
return size;
}
});
public static StackManipulation defaultExceptionHandler() {
public static ExceptionHandler defaultExceptionHandler() {
return EXCEPTION_STACK_HANDLER;
}
}

View File

@ -1 +0,0 @@
enableCustomAnnotationTracingOver: ["datadog.benchmark"]

View File

@ -1,5 +0,0 @@
logging:
level: INFO
loggers:
"datadog.trace": DEBUG
"io.opentracing": DEBUG

View File

@ -1,5 +0,0 @@
logging:
level: INFO
loggers:
"datadog.trace": DEBUG
"io.opentracing": DEBUG

View File

@ -14,7 +14,7 @@ ext {
groovy : groovyVer,
junit : "4.12",
logback : "1.2.3",
bytebuddy : "1.8.1",
bytebuddy : "1.8.8",
]
deps = [