Skip to content

Commit

Permalink
Reintroduce binary compatible method for method graph compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Sep 22, 2021
1 parent a0c48f6 commit 8b80bf1
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 71 deletions.
1 change: 1 addition & 0 deletions byte-buddy-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>**/module-info.class</exclude>
<exclude>**/NOTICE</exclude>
</excludes>
</filter>
</filters>
Expand Down
2 changes: 1 addition & 1 deletion byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java
Original file line number Diff line number Diff line change
Expand Up @@ -11756,7 +11756,7 @@ public <T extends Annotation> WithCustomMapping bindLambda(Class<T> type,
if (!functionalInterface.isInterface()) {
throw new IllegalArgumentException(functionalInterface + " is not an interface type");
}
MethodList<?> methods = methodGraphCompiler.compile(functionalInterface)
MethodList<?> methods = methodGraphCompiler.compile((TypeDefinition) functionalInterface)
.listNodes()
.asMethodList()
.filter(isAbstract());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2352,12 +2352,12 @@ public void visitMethodInsn(int opcode, String owner, String internalName, Strin
? ElementMatchers.<MethodDescription>isPrivate().and(not(isStatic())).and(named(internalName).and(hasDescriptor(descriptor)))
: ElementMatchers.<MethodDescription>failSafe(isPrivate().<MethodDescription>and(not(isStatic())).and(named(internalName).and(hasDescriptor(descriptor)))));
if (candidates.isEmpty()) {
candidates = methodGraphCompiler.compile(resolution.resolve(), instrumentedType).listNodes().asMethodList().filter(strict
candidates = methodGraphCompiler.compile((TypeDefinition) resolution.resolve(), instrumentedType).listNodes().asMethodList().filter(strict
? ElementMatchers.<MethodDescription>named(internalName).and(hasDescriptor(descriptor))
: ElementMatchers.<MethodDescription>failSafe(named(internalName).and(hasDescriptor(descriptor))));
}
} else {
candidates = methodGraphCompiler.compile(resolution.resolve(), instrumentedType).listNodes().asMethodList().filter(strict
candidates = methodGraphCompiler.compile((TypeDefinition) resolution.resolve(), instrumentedType).listNodes().asMethodList().filter(strict
? ElementMatchers.<MethodDescription>named(internalName).and(hasDescriptor(descriptor))
: ElementMatchers.<MethodDescription>failSafe(named(internalName).and(hasDescriptor(descriptor))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,28 @@ public Linked compile(TypeDefinition typeDefinition) {
return this;
}

/**
* {@inheritDoc}
*/
@Deprecated
public Linked compile(TypeDescription typeDescription) {
return this;
}

/**
* {@inheritDoc}
*/
public Linked compile(TypeDefinition typeDefinition, TypeDescription viewPoint) {
return this;
}

/**
* {@inheritDoc}
*/
@Deprecated
public Linked compile(TypeDescription typeDefinition, TypeDescription viewPoint) {
return this;
}
}

/**
Expand Down Expand Up @@ -415,6 +431,16 @@ interface Compiler {
*/
MethodGraph.Linked compile(TypeDefinition typeDefinition);

/**
* Compiles the given type into a method graph considering the type to be the viewpoint.
*
* @param typeDescription The type to be compiled.
* @return A linked method graph representing the given type.
* @deprecated Use {@link MethodGraph.Compiler#compile(TypeDefinition)}.
*/
@Deprecated
MethodGraph.Linked compile(TypeDescription typeDescription);

/**
* Compiles the given type into a method graph.
*
Expand All @@ -424,6 +450,17 @@ interface Compiler {
*/
MethodGraph.Linked compile(TypeDefinition typeDefinition, TypeDescription viewPoint);

/**
* Compiles the given type into a method graph.
*
* @param typeDefinition The type to be compiled.
* @param viewPoint The view point that determines the method's visibility.
* @return A linked method graph representing the given type.
* @deprecated Use {@link MethodGraph.Compiler#compile(TypeDefinition, TypeDescription)}.
*/
@Deprecated
MethodGraph.Linked compile(TypeDescription typeDefinition, TypeDescription viewPoint);

/**
* A flat compiler that simply returns the methods that are declared by the instrumented type.
*/
Expand All @@ -441,6 +478,14 @@ public Linked compile(TypeDefinition typeDefinition) {
return compile(typeDefinition, typeDefinition.asErasure());
}

/**
* {@inheritDoc}
*/
@Deprecated
public Linked compile(TypeDescription typeDescription) {
return compile((TypeDefinition) typeDescription, typeDescription);
}

/**
* {@inheritDoc}
*/
Expand All @@ -451,6 +496,14 @@ public Linked compile(TypeDefinition typeDefinition, TypeDescription viewPoint)
}
return new Linked.Delegation(new MethodGraph.Simple(nodes), Empty.INSTANCE, Collections.<TypeDescription, MethodGraph>emptyMap());
}

/**
* {@inheritDoc}
*/
@Deprecated
public Linked compile(TypeDescription typeDefinition, TypeDescription viewPoint) {
return compile((TypeDefinition) typeDefinition, viewPoint);
}
}

/**
Expand All @@ -464,6 +517,22 @@ abstract class AbstractBase implements Compiler {
public Linked compile(TypeDefinition typeDefinition) {
return compile(typeDefinition, typeDefinition.asErasure());
}

/**
* {@inheritDoc}
*/
@Deprecated
public Linked compile(TypeDescription typeDescription) {
return compile((TypeDefinition) typeDescription, typeDescription);
}

/**
* {@inheritDoc}
*/
@Deprecated
public Linked compile(TypeDescription typeDefinition, TypeDescription viewPoint) {
return compile((TypeDefinition) typeDefinition, viewPoint);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.method.MethodList;
import net.bytebuddy.description.modifier.Visibility;
import net.bytebuddy.description.type.TypeDefinition;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.Transformer;
import net.bytebuddy.dynamic.VisibilityBridgeStrategy;
Expand Down Expand Up @@ -468,7 +469,7 @@ public MethodRegistry.Prepared prepare(InstrumentedType instrumentedType,
}
}
}
MethodGraph.Linked methodGraph = methodGraphCompiler.compile(instrumentedType);
MethodGraph.Linked methodGraph = methodGraphCompiler.compile((TypeDefinition) instrumentedType);
// Casting required for Java 6 compiler.
ElementMatcher<? super MethodDescription> relevanceMatcher = (ElementMatcher<? super MethodDescription>) not(anyOf(implementations.keySet()))
.and(returns(isVisibleTo(instrumentedType)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public DynamicType.Unloaded<T> make(TypeResolutionStrategy typeResolutionStrateg
return TypeWriter.Default.<T>forDecoration(instrumentedType,
classFileVersion,
auxiliaryTypes,
CompoundList.of(methodGraphCompiler.compile(instrumentedType)
CompoundList.of(methodGraphCompiler.compile((TypeDefinition) instrumentedType)
.listNodes()
.asMethodList()
.filter(not(ignoredMethods.resolve(instrumentedType))), instrumentedType.getDeclaredMethods().filter(not(isVirtual()))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ public MethodDescription resolve(TypeDescription targetType, MethodDescription i
List<MethodDescription> candidates = CompoundList.<MethodDescription>of(
instrumentedType.getSuperClass().getDeclaredMethods().filter(isConstructor().and(matcher)),
instrumentedType.getDeclaredMethods().filter(not(ElementMatchers.isVirtual()).and(matcher)),
methodGraphCompiler.compile(targetType, instrumentedType).listNodes().asMethodList().filter(matcher));
methodGraphCompiler.compile((TypeDefinition) targetType, instrumentedType).listNodes().asMethodList().filter(matcher));
if (candidates.size() == 1) {
return candidates.get(0);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ protected ForMethodReturn(String name,
public Compiled compile(TypeDescription instrumentedType) {
MethodList<?> targets = new MethodList.Explicit<MethodDescription>(CompoundList.<MethodDescription>of(
instrumentedType.getDeclaredMethods().filter(isStatic().or(isPrivate())),
methodGraphCompiler.compile(instrumentedType).listNodes().asMethodList())
methodGraphCompiler.compile((TypeDefinition) instrumentedType).listNodes().asMethodList())
).filter(named(name).and(takesArguments(0)).and(not(returns(isPrimitive().or(isArray())))));
if (targets.size() != 1) {
throw new IllegalStateException(instrumentedType + " does not define method without arguments with name " + name + ": " + targets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,15 @@ protected enum PrecomputedMethodGraph implements MethodGraph.Compiler {
* {@inheritDoc}
*/
public MethodGraph.Linked compile(TypeDefinition typeDefinition) {
return compile(typeDefinition, typeDefinition.asErasure());
return methodGraph;
}

/**
* {@inheritDoc}
*/
@Deprecated
public MethodGraph.Linked compile(TypeDescription typeDescription) {
return methodGraph;
}

/**
Expand All @@ -229,6 +237,14 @@ public MethodGraph.Linked compile(TypeDefinition typeDefinition) {
public MethodGraph.Linked compile(TypeDefinition typeDefinition, TypeDescription viewPoint) {
return methodGraph;
}

/**
* {@inheritDoc}
*/
@Deprecated
public MethodGraph.Linked compile(TypeDescription typeDefinition, TypeDescription viewPoint) {
return methodGraph;
}
}

/**
Expand Down
Loading

0 comments on commit 8b80bf1

Please sign in to comment.