Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
}
1 change: 0 additions & 1 deletion dd-java-agent/benchmark/out/jmh/resources/dd-trace.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion dd-java-agent/dd-java-agent.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "com.github.johnrengelman.shadow" version "2.0.3"
id "com.github.johnrengelman.shadow" version "2.0.4"
}

description = 'dd-java-agent'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "com.github.johnrengelman.shadow" version "2.0.3"
id "com.github.johnrengelman.shadow" version "2.0.4"
}

apply plugin: 'application'
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip

This file was deleted.

Binary file modified examples/rest-spark/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip

This file was deleted.

2 changes: 1 addition & 1 deletion examples/rest-spark/rest-spark.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "com.github.johnrengelman.shadow" version "2.0.3"
id "com.github.johnrengelman.shadow" version "2.0.4"
}

apply plugin: 'application'
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ext {
groovy : groovyVer,
junit : "4.12",
logback : "1.2.3",
bytebuddy : "1.8.1",
bytebuddy : "1.8.8",
]

deps = [
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip