Update ByteBuddy to 1.10.20.
Reuse ElementMatcher for isDefaultConstructor(), lowering
the amount of garbage we potentially generate. While we are at it
make sure our intra-package use patters are more consistent.
Change-Id: I5cc297129c4b04eade4d1a8a9dfb96cd8504554e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
<!-- We are going to shade this -->
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<!-- We are going to shade this -->
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
- <version>1.10.17</version>
+ <version>1.10.20</version>
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
import net.bytebuddy.pool.TypePool;
final class ByteBuddyUtils {
import net.bytebuddy.pool.TypePool;
final class ByteBuddyUtils {
- static final StackManipulation THIS = MethodVariableAccess.loadThis();
+ private static final StackManipulation LOAD_THIS = MethodVariableAccess.loadThis();
private ByteBuddyUtils() {
}
private ByteBuddyUtils() {
}
+ // TODO: eliminate this method once MethodVariableAccess.loadThis() returns a singleton
+ static StackManipulation loadThis() {
+ return LOAD_THIS;
+ }
+
static StackManipulation invokeMethod(final Method method) {
return MethodInvocation.invoke(describe(method));
}
static StackManipulation invokeMethod(final Method method) {
return MethodInvocation.invoke(describe(method));
}
return new Mark(label);
}
return new Mark(label);
}
- static StackManipulation loadThis() {
- return THIS;
- }
-
static StackManipulation getField(final Field field) {
return FieldAccess.forField(new ForLoadedField(field).asDefined()).read();
}
static StackManipulation getField(final Field field) {
return FieldAccess.forField(new ForLoadedField(field).asDefined()).read();
}
import static com.google.common.base.Verify.verify;
import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
import static com.google.common.base.Verify.verify;
import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
-import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.THIS;
+import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.computeFrames;
import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.getField;
import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.invokeMethod;
import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.getField;
import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.invokeMethod;
+import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.loadThis;
import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.putField;
import com.google.common.collect.ImmutableMap;
import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.putField;
import com.google.common.collect.ImmutableMap;
final Generic bindingDef = TypeDefinition.Sort.describe(bindingInterface);
@SuppressWarnings("unchecked")
Builder<T> builder = (Builder<T>) BB.subclass(Generic.Builder.parameterizedType(superClass, bindingDef).build())
final Generic bindingDef = TypeDefinition.Sort.describe(bindingInterface);
@SuppressWarnings("unchecked")
Builder<T> builder = (Builder<T>) BB.subclass(Generic.Builder.parameterizedType(superClass, bindingDef).build())
- .visit(ByteBuddyUtils.computeFrames()).name(fqcn).implement(bindingDef);
+ .visit(computeFrames()).name(fqcn).implement(bindingDef);
builder = generateGetters(builder);
builder = generateGetters(builder);
private static Implementation codecHashCode(final Class<?> bindingInterface) {
return new Implementation.Simple(
// return Foo.bindingHashCode(this);
private static Implementation codecHashCode(final Class<?> bindingInterface) {
return new Implementation.Simple(
// return Foo.bindingHashCode(this);
invokeMethod(bindingInterface, BindingMapping.BINDING_HASHCODE_NAME, bindingInterface),
MethodReturn.INTEGER);
}
invokeMethod(bindingInterface, BindingMapping.BINDING_HASHCODE_NAME, bindingInterface),
MethodReturn.INTEGER);
}
private static Implementation codecEquals(final Class<?> bindingInterface) {
return new Implementation.Simple(
// return Foo.bindingEquals(this, obj);
private static Implementation codecEquals(final Class<?> bindingInterface) {
return new Implementation.Simple(
// return Foo.bindingEquals(this, obj);
FIRST_ARG_REF,
invokeMethod(bindingInterface, BindingMapping.BINDING_EQUALS_NAME, bindingInterface, Object.class),
MethodReturn.INTEGER);
FIRST_ARG_REF,
invokeMethod(bindingInterface, BindingMapping.BINDING_EQUALS_NAME, bindingInterface, Object.class),
MethodReturn.INTEGER);
private static Implementation toString(final Class<?> bindingInterface) {
return new Implementation.Simple(
// return Foo.bindingToString(this);
private static Implementation toString(final Class<?> bindingInterface) {
return new Implementation.Simple(
// return Foo.bindingToString(this);
invokeMethod(bindingInterface, BindingMapping.BINDING_TO_STRING_NAME, bindingInterface),
MethodReturn.REFERENCE);
}
invokeMethod(bindingInterface, BindingMapping.BINDING_TO_STRING_NAME, bindingInterface),
MethodReturn.REFERENCE);
}
public ByteCodeAppender appender(final Target implementationTarget) {
return new ByteCodeAppender.Simple(
// return (FooType) codecKey(getFoo$$$V);
public ByteCodeAppender appender(final Target implementationTarget) {
return new ByteCodeAppender.Simple(
// return (FooType) codecKey(getFoo$$$V);
getField(implementationTarget.getInstrumentedType(), handleName),
CODEC_KEY,
TypeCasting.to(retType),
getField(implementationTarget.getInstrumentedType(), handleName),
CODEC_KEY,
TypeCasting.to(retType),
final TypeDescription instrumentedType = implementationTarget.getInstrumentedType();
return new ByteCodeAppender.Simple(
// return (FooType) codecMember(getFoo$$$V, getFoo$$$S);
final TypeDescription instrumentedType = implementationTarget.getInstrumentedType();
return new ByteCodeAppender.Simple(
// return (FooType) codecMember(getFoo$$$V, getFoo$$$S);
getField(instrumentedType, handleName),
getField(instrumentedType, stringName),
CODEC_MEMBER,
getField(instrumentedType, handleName),
getField(instrumentedType, stringName),
CODEC_MEMBER,
public ByteCodeAppender appender(final Target implementationTarget) {
return new ByteCodeAppender.Simple(
// return (FooType) codecMember(getFoo$$$V, FooType.class);
public ByteCodeAppender appender(final Target implementationTarget) {
return new ByteCodeAppender.Simple(
// return (FooType) codecMember(getFoo$$$V, FooType.class);
getField(implementationTarget.getInstrumentedType(), handleName),
ClassConstant.of(TypeDefinition.Sort.describe(bindingClass).asErasure()),
CODEC_MEMBER,
getField(implementationTarget.getInstrumentedType(), handleName),
ClassConstant.of(TypeDefinition.Sort.describe(bindingClass).asErasure()),
CODEC_MEMBER,
final TypeDescription instrumentedType = implementationTarget.getInstrumentedType();
return new ByteCodeAppender.Simple(
// return (FooType) codecMember(getFoo$$$V, getFoo$$$C);
final TypeDescription instrumentedType = implementationTarget.getInstrumentedType();
return new ByteCodeAppender.Simple(
// return (FooType) codecMember(getFoo$$$V, getFoo$$$C);
getField(instrumentedType, handleName),
getField(instrumentedType, contextName),
CODEC_MEMBER,
getField(instrumentedType, handleName),
getField(instrumentedType, contextName),
CODEC_MEMBER,
import net.bytebuddy.implementation.bytecode.member.MethodVariableAccess;
import net.bytebuddy.jar.asm.MethodVisitor;
import net.bytebuddy.jar.asm.Opcodes;
import net.bytebuddy.implementation.bytecode.member.MethodVariableAccess;
import net.bytebuddy.jar.asm.MethodVisitor;
import net.bytebuddy.jar.asm.Opcodes;
+import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingStreamEventWriter;
import net.bytebuddy.matcher.ElementMatchers;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingStreamEventWriter;
private enum InitializeInstanceField implements ByteCodeAppender {
INSTANCE;
private enum InitializeInstanceField implements ByteCodeAppender {
INSTANCE;
+ // TODO: eliminate this constant when ElementMatchers.isDefaultConstructor() returns a singleton
+ private static final ElementMatcher<MethodDescription> IS_DEFAULT_CONSTRUCTOR =
+ ElementMatchers.isDefaultConstructor();
+
@Override
public Size apply(final MethodVisitor methodVisitor, final Context implementationContext,
final MethodDescription instrumentedMethod) {
@Override
public Size apply(final MethodVisitor methodVisitor, final Context implementationContext,
final MethodDescription instrumentedMethod) {
TypeCreation.of(instrumentedType),
Duplication.SINGLE,
MethodInvocation.invoke(instrumentedType.getDeclaredMethods()
TypeCreation.of(instrumentedType),
Duplication.SINGLE,
MethodInvocation.invoke(instrumentedType.getDeclaredMethods()
- .filter(ElementMatchers.isDefaultConstructor()).getOnly().asDefined()),
+ .filter(IS_DEFAULT_CONSTRUCTOR).getOnly().asDefined()),
putField(instrumentedType, INSTANCE_FIELD))
.apply(methodVisitor, implementationContext);
return new Size(operandStackSize.getMaximalSize(), instrumentedMethod.getStackSize());
putField(instrumentedType, INSTANCE_FIELD))
.apply(methodVisitor, implementationContext);
return new Size(operandStackSize.getMaximalSize(), instrumentedMethod.getStackSize());
package org.opendaylight.mdsal.binding.dom.codec.impl;
import static com.google.common.base.Preconditions.checkState;
package org.opendaylight.mdsal.binding.dom.codec.impl;
import static com.google.common.base.Preconditions.checkState;
+import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.getField;
+import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.loadThis;
+import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.putField;
import com.google.common.base.Throwables;
import java.lang.invoke.MethodHandle;
import com.google.common.base.Throwables;
import java.lang.invoke.MethodHandle;
private enum ConstructorImplementation implements Implementation {
INSTANCE;
private enum ConstructorImplementation implements Implementation {
INSTANCE;
- private static final StackManipulation INSTANT_ARG = MethodVariableAccess.REFERENCE.loadFrom(3);
+ private static final StackManipulation LOAD_INSTANT_ARG = MethodVariableAccess.REFERENCE.loadFrom(3);
private static final StackManipulation LOAD_CTOR_ARGS;
static {
private static final StackManipulation LOAD_CTOR_ARGS;
static {
.filter(ElementMatchers.isConstructor()).getOnly();
return new ByteCodeAppender.Simple(
.filter(ElementMatchers.isConstructor()).getOnly();
return new ByteCodeAppender.Simple(
LOAD_CTOR_ARGS,
MethodInvocation.invoke(superCtor),
LOAD_CTOR_ARGS,
MethodInvocation.invoke(superCtor),
- ByteBuddyUtils.THIS,
- INSTANT_ARG,
- ByteBuddyUtils.putField(instrumentedType, INSTANT_FIELD),
+ loadThis(),
+ LOAD_INSTANT_ARG,
+ putField(instrumentedType, INSTANT_FIELD),
@Override
public ByteCodeAppender appender(final Target implementationTarget) {
return new ByteCodeAppender.Simple(
@Override
public ByteCodeAppender appender(final Target implementationTarget) {
return new ByteCodeAppender.Simple(
- ByteBuddyUtils.THIS,
- ByteBuddyUtils.getField(implementationTarget.getInstrumentedType(), INSTANT_FIELD),
+ loadThis(),
+ getField(implementationTarget.getInstrumentedType(), INSTANT_FIELD),
MethodReturn.REFERENCE);
}
}
MethodReturn.REFERENCE);
}
}