-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace CGLIB with custom code to generate "enhancers" and "fast-classes". Some user visible changes from using cglib: - intercepted method that has a return type of int but returns null from the interceptor will no longer be automatically converted to 0, instead a NullPointerException will be thrown. - Scope implementation can no longer check for circular proxy instance using CircularDependencyProxy marker class, instead should use Scopes.isCircularProxy - Depending on which custom class loading option is used, Guice enhanced class may no longer be mockable/spyable - Generated class name is slightly longer. Closes #1298 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=320433559
- Loading branch information
Showing
175 changed files
with
1,903 additions
and
460 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...google/inject/internal/BytecodeGen#[T]_newCircularProxy(Class[T],InvocationHandler).mjava
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** Creates a new circular proxy for the given type. */ | ||
static <T> T newCircularProxy(Class<T> type, InvocationHandler handler) { | ||
Object proxy = Proxy.newProxyInstance(type.getClassLoader(), new Class<?>[] {type}, handler); | ||
circularProxyTypeCache.put(proxy.getClass(), Boolean.TRUE); | ||
return type.cast(proxy); | ||
} | ||
|
8 changes: 0 additions & 8 deletions
8
core/src/com/google/inject/internal/BytecodeGen#canonicalize(ClassLoader).mjava
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
...ncedConstructor(Function[String,BiFunction[Object,Object[],Object]],Constructor[#]).mjava
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Returns an invoker that constructs an enhanced instance. The invoker function accepts an array | ||
* of invocation handlers plus an array of arguments for the original constructor. | ||
*/ | ||
static BiFunction<Object, Object[], Object> enhancedConstructor( | ||
Function<String, BiFunction<Object, Object[], Object>> enhancer, Constructor<?> constructor) { | ||
checkArgument(canEnhance(constructor), "Constructor is not visible"); | ||
return enhancer.apply(signature(constructor)); | ||
} | ||
|
5 changes: 5 additions & 0 deletions
5
core/src/com/google/inject/internal/BytecodeGen#enhancerBuilder(Class[#]).mjava
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** Create a builder of enhancers for the given class. */ | ||
static EnhancerBuilder enhancerBuilder(Class<?> hostClass) { | ||
return ENHANCER_BUILDERS.getUnchecked(hostClass); | ||
} | ||
|
7 changes: 7 additions & 0 deletions
7
core/src/com/google/inject/internal/BytecodeGen#fastClass(Executable).mjava
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Prepares the class declaring the given member for fast invocation using bytecode generation. | ||
*/ | ||
private static Function<String, BiFunction<Object, Object[], Object>> fastClass(Executable member) { | ||
return FAST_CLASSES.get(member.getDeclaringClass()); | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
core/src/com/google/inject/internal/BytecodeGen#fastConstructor(Constructor[#]).mjava
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Returns a fast invoker for the given constructor. The invoker function ignores the first | ||
* parameter and accepts an array of arguments for the constructor in the second parameter. | ||
* | ||
* <p>Returns {@code null} if the constructor cannot be "fast-invoked" due to visibility issues. | ||
*/ | ||
static BiFunction<Object, Object[], Object> fastConstructor(Constructor<?> constructor) { | ||
if (canFastInvoke(constructor)) { | ||
return fastClass(constructor).apply(signature(constructor)); | ||
} | ||
return null; | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
core/src/com/google/inject/internal/BytecodeGen#fastMethod(Method).mjava
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Returns a fast invoker for the given method. The invoker function accepts an instance, which | ||
* will be {@code null} for static methods, and an array of arguments for the method. | ||
* | ||
* <p>Returns {@code null} if the method cannot be "fast-invoked" due to visibility issues. | ||
*/ | ||
static BiFunction<Object, Object[], Object> fastMethod(Method method) { | ||
if (canFastInvoke(method)) { | ||
return fastClass(method).apply(signature(method)); | ||
} | ||
return null; | ||
} | ||
|
5 changes: 0 additions & 5 deletions
5
core/src/com/google/inject/internal/BytecodeGen#getClassLoader(Class[#]).mjava
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
core/src/com/google/inject/internal/BytecodeGen#getClassLoader(Class[#],ClassLoader).mjava
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
core/src/com/google/inject/internal/BytecodeGen#hasSameVersionOfCglib(ClassLoader).mjava
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
core/src/com/google/inject/internal/BytecodeGen#isCircularProxy(Object).mjava
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** Returns true if the given object is a circular proxy. */ | ||
public static boolean isCircularProxy(Object object) { | ||
return object != null && circularProxyTypeCache.containsKey(object.getClass()); | ||
} | ||
|
26 changes: 0 additions & 26 deletions
26
core/src/com/google/inject/internal/BytecodeGen#isPubliclyCallable(Member).mjava
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
core/src/com/google/inject/internal/BytecodeGen#newEnhancer(Class[#],Visibility).mjava
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
core/src/com/google/inject/internal/BytecodeGen#newFastClassForMember(Class[#],Member).mjava
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
core/src/com/google/inject/internal/BytecodeGen#newFastClassForMember(Member).mjava
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
...BytecodeGen#superMethod(Function[String,BiFunction[Object,Object[],Object]],Method).mjava
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Returns an invoker that calls the original unenhanced method. The invoker function accepts an | ||
* enhanced instance plus an array of arguments for the original method. | ||
*/ | ||
static BiFunction<Object, Object[], Object> superMethod( | ||
Function<String, BiFunction<Object, Object[], Object>> enhancer, Method method) { | ||
// no need to check 'canEnhance', ProxyFactory will only pick methods from enhanceable list | ||
return enhancer.apply(signature(method)); | ||
} | ||
|
4 changes: 0 additions & 4 deletions
4
core/src/com/google/inject/internal/BytecodeGen.BridgeClassLoader#BridgeClassLoader().mjava
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
...google/inject/internal/BytecodeGen.BridgeClassLoader#BridgeClassLoader(ClassLoader).mjava
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...ogle/inject/internal/BytecodeGen.BridgeClassLoader#classicLoadClass(String,boolean).mjava
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
.../com/google/inject/internal/BytecodeGen.BridgeClassLoader#loadClass(String,boolean).mjava
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
core/src/com/google/inject/internal/BytecodeGen.EnhancerBuilder#buildEnhancer(BitSet).mjava
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Generates an enhancer for the selected subset of methods. | ||
* | ||
* <p>The enhancer maps constructor and method signatures to invokers, where each invoker is | ||
* represented as a {@link BiFunction} that accepts a context object and an argument array. | ||
* | ||
* <p>Constructor invokers take an array of {@link InvocationHandler}s as their context object. | ||
* This is stored in the enhanced class before the original host class constructor is called, | ||
* with arguments unpacked from the argument array. The enhanced instance is then returned. | ||
* | ||
* <p>Method invokers take an enhanced instance as their context object and call the original | ||
* super-method with arguments unpacked from the argument array, ie. provides super-invocation. | ||
*/ | ||
Function<String, BiFunction<Object, Object[], Object>> buildEnhancer(BitSet methodIndices); | ||
|
11 changes: 11 additions & 0 deletions
11
.../src/com/google/inject/internal/BytecodeGen.EnhancerBuilder#getEnhanceableMethods().mjava
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Lists the methods in the host class that can be enhanced. | ||
* | ||
* <p>This always includes public and protected methods that are neither static nor final. | ||
* | ||
* <p>Package-private methods can only be enhanced if they're in the same package as the host | ||
* and we can define types in the same class loader with Unsafe. The {@link #finalize} method | ||
* can never be enhanced. | ||
*/ | ||
Method[] getEnhanceableMethods(); | ||
|
2 changes: 0 additions & 2 deletions
2
core/src/com/google/inject/internal/BytecodeGen.Visibility#and(Visibility).mjava
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
core/src/com/google/inject/internal/BytecodeGen.Visibility#forMember(Member).mjava
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
core/src/com/google/inject/internal/BytecodeGen.Visibility#forType(Class[#]).mjava
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.