From 57eade612f90201ffda0c50064c5113e8323bb64 Mon Sep 17 00:00:00 2001 From: Tyler Benson Date: Thu, 26 Apr 2018 16:19:48 +1000 Subject: [PATCH] Upgrade Byte-buddy to 1.8.8 Also remove some erronously checked in files. --- .../agent/tooling/ExceptionHandlers.java | 104 +++++++++--------- .../benchmark/out/jmh/resources/dd-trace.yaml | 1 - .../production/resources/configuration.yaml | 5 - .../production/resources/configuration.yaml | 5 - gradle/dependencies.gradle | 2 +- 5 files changed, 54 insertions(+), 63 deletions(-) delete mode 100644 dd-java-agent/benchmark/out/jmh/resources/dd-trace.yaml delete mode 100644 examples/dropwizard-mongo-client/out/production/resources/configuration.yaml delete mode 100644 examples/rest-spark/out/production/resources/configuration.yaml diff --git a/dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/ExceptionHandlers.java b/dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/ExceptionHandlers.java index 422f430e24..c898ce9a58 100644 --- a/dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/ExceptionHandlers.java +++ b/dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/ExceptionHandlers.java @@ -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; } } diff --git a/dd-java-agent/benchmark/out/jmh/resources/dd-trace.yaml b/dd-java-agent/benchmark/out/jmh/resources/dd-trace.yaml deleted file mode 100644 index 22d9698b6f..0000000000 --- a/dd-java-agent/benchmark/out/jmh/resources/dd-trace.yaml +++ /dev/null @@ -1 +0,0 @@ -enableCustomAnnotationTracingOver: ["datadog.benchmark"] diff --git a/examples/dropwizard-mongo-client/out/production/resources/configuration.yaml b/examples/dropwizard-mongo-client/out/production/resources/configuration.yaml deleted file mode 100644 index 295673f037..0000000000 --- a/examples/dropwizard-mongo-client/out/production/resources/configuration.yaml +++ /dev/null @@ -1,5 +0,0 @@ -logging: - level: INFO - loggers: - "datadog.trace": DEBUG - "io.opentracing": DEBUG diff --git a/examples/rest-spark/out/production/resources/configuration.yaml b/examples/rest-spark/out/production/resources/configuration.yaml deleted file mode 100644 index 295673f037..0000000000 --- a/examples/rest-spark/out/production/resources/configuration.yaml +++ /dev/null @@ -1,5 +0,0 @@ -logging: - level: INFO - loggers: - "datadog.trace": DEBUG - "io.opentracing": DEBUG diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index a9b75a467d..120dec2ce1 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -14,7 +14,7 @@ ext { groovy : groovyVer, junit : "4.12", logback : "1.2.3", - bytebuddy : "1.8.1", + bytebuddy : "1.8.8", ] deps = [