Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Byte Buddy for Instrumentation by default #389

Merged
merged 3 commits into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-389.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: improvement
improvement:
carterkozak marked this conversation as resolved.
Show resolved Hide resolved
description: Use Byte Buddy for Instrumentation by default, reducing excess stack
frames from instrumentation.
links:
- https://github.com/palantir/tritium/pull/389
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -46,8 +47,22 @@ public static BooleanSupplier getSystemPropertySupplier(String name) {

@SuppressWarnings("WeakerAccess") // public API
public static boolean isSpecificEnabled(String name) {
String qualifiedValue = instrumentationProperties().get(INSTRUMENT_PREFIX + "." + name);
return "true".equalsIgnoreCase(qualifiedValue) || qualifiedValue == null;
return isSpecificEnabled(name, true);
}

@SuppressWarnings("WeakerAccess") // public API
public static boolean isSpecificEnabled(String name, boolean defaultValue) {
String qualifiedValue = getSpecific(name);
if (qualifiedValue == null) {
return defaultValue;
}
return "true".equalsIgnoreCase(qualifiedValue);
}

/** Applies the {@link #INSTRUMENT_PREFIX} and returns the current value. */
@Nullable
private static String getSpecific(String name) {
return instrumentationProperties().get(INSTRUMENT_PREFIX + "." + name);
}

@SuppressWarnings("WeakerAccess") // public API
Expand Down Expand Up @@ -100,5 +115,4 @@ private static Map<String, String> createInstrumentationSystemProperties() {
log.debug("Reloaded instrumentation properties {}", map);
return map;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,82 @@ public void onFailure(Throwable throwable) {
assertThat(barrier.getNumberWaiting()).isZero();
});
}

@Test
void testIsSpecificEnabled_notSet() {
assertThat(InstrumentationProperties.isSpecificEnabled("not_set")).isTrue();
}

@Test
void testIsSpecificEnabled_notSet_defaultTrue() {
assertThat(InstrumentationProperties.isSpecificEnabled("not_set", true)).isTrue();
}

@Test
void testIsSpecificEnabled_notSet_defaultFalse() {
assertThat(InstrumentationProperties.isSpecificEnabled("not_set", false)).isFalse();
}

@Test
void testIsSpecificEnabled_setGarbage() {
System.setProperty("instrument.garbage", "garbage");
InstrumentationProperties.reload();
assertThat(InstrumentationProperties.isSpecificEnabled("garbage")).isFalse();
}

@Test
void testIsSpecificEnabled_setGarbage_defaultTrue() {
System.setProperty("instrument.garbage", "garbage");
InstrumentationProperties.reload();
assertThat(InstrumentationProperties.isSpecificEnabled("garbage", true)).isFalse();
}

@Test
void testIsSpecificEnabled_setGarbage_defaultFalse() {
System.setProperty("instrument.garbage", "garbage");
InstrumentationProperties.reload();
assertThat(InstrumentationProperties.isSpecificEnabled("garbage", false)).isFalse();
}

@Test
void testIsSpecificEnabled_setTrue() {
System.setProperty("instrument.true", "true");
InstrumentationProperties.reload();
assertThat(InstrumentationProperties.isSpecificEnabled("true")).isTrue();
}

@Test
void testIsSpecificEnabled_setTrue_defaultTrue() {
System.setProperty("instrument.true", "true");
InstrumentationProperties.reload();
assertThat(InstrumentationProperties.isSpecificEnabled("true", true)).isTrue();
}

@Test
void testIsSpecificEnabled_setTrue_defaultFalse() {
System.setProperty("instrument.true", "true");
InstrumentationProperties.reload();
assertThat(InstrumentationProperties.isSpecificEnabled("true", false)).isTrue();
}

@Test
void testIsSpecificEnabled_setFalse() {
System.setProperty("instrument.false", "false");
InstrumentationProperties.reload();
assertThat(InstrumentationProperties.isSpecificEnabled("false")).isFalse();
}

@Test
void testIsSpecificEnabled_setFalse_defaultTrue() {
System.setProperty("instrument.false", "false");
InstrumentationProperties.reload();
assertThat(InstrumentationProperties.isSpecificEnabled("false", true)).isFalse();
}

@Test
void testIsSpecificEnabled_setFalse_defaultFalse() {
System.setProperty("instrument.false", "false");
InstrumentationProperties.reload();
assertThat(InstrumentationProperties.isSpecificEnabled("false", false)).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static <T, U extends T> T wrap(Class<T> interfaceClass,
return delegate;
}

if (InstrumentationProperties.isSpecificEnabled("dynamic-proxy")) {
if (InstrumentationProperties.isSpecificEnabled("dynamic-proxy", false)) {
return Proxies.newProxy(interfaceClass, delegate,
new InstrumentationProxy<>(instrumentationFilter, handlers, delegate));
} else {
Expand Down