Package com.google.inject.internal
Class BytecodeGen
java.lang.Object
com.google.inject.internal.BytecodeGen
Utility methods for circular proxies, faster reflection, and method interception.
This class makes heavy use of Function
and BiFunction
types when interacting
with generated fast-classes and enhanced proxies. This is a deliberate design decision to avoid
using Guice-specific types in the generated classes. This means generated classes can be defined
in the same ClassLoader
as their host class without needing access to Guice's own ClassLoader
. (In other words it removes any need for bridge ClassLoader
s.)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Builder of enhanced classes. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final com.google.common.cache.LoadingCache
<Class<?>, BytecodeGen.EnhancerBuilder> Cache of recentBytecodeGen.EnhancerBuilder
s.static final String
private static final ClassValue
<Function<String, BiFunction<Object, Object[], Object>>> Lazy association between classes and their generated fast-classes.static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static BiFunction
<Object, Object[], Object> enhancedConstructor
(Function<String, BiFunction<Object, Object[], Object>> enhancer, Constructor<?> constructor) Returns an invoker that constructs an enhanced instance.(package private) static BytecodeGen.EnhancerBuilder
enhancerBuilder
(Class<?> hostClass) Create a builder of enhancers for the given class.fastClass
(Executable member) Prepares the class declaring the given member for fast invocation using bytecode generation.(package private) static BiFunction
<Object, Object[], Object> fastConstructor
(Constructor<?> constructor) Returns a fast invoker for the given constructor.(package private) static BiFunction
<Object, Object[], Object> fastMethod
(Method method) Returns a fast invoker for the given method.static boolean
isCircularProxy
(Object object) Returns true if the given object is a circular proxy.(package private) static <T> T
newCircularProxy
(Class<T> type, InvocationHandler handler) Creates a new circular proxy for the given type.(package private) static BiFunction
<Object, Object[], Object> superMethod
(Function<String, BiFunction<Object, Object[], Object>> enhancer, Method method) Returns an invoker that calls the original unenhanced method.
-
Field Details
-
circularProxyTypeCache
-
ENHANCER_BY_GUICE_MARKER
- See Also:
-
FASTCLASS_BY_GUICE_MARKER
- See Also:
-
ENHANCER_BUILDERS
private static final com.google.common.cache.LoadingCache<Class<?>,BytecodeGen.EnhancerBuilder> ENHANCER_BUILDERSCache of recentBytecodeGen.EnhancerBuilder
s.Uses weak values so builders can be collected after they're done enhancing.
-
FAST_CLASSES
Lazy association between classes and their generated fast-classes.
-
-
Constructor Details
-
BytecodeGen
public BytecodeGen()
-
-
Method Details
-
isCircularProxy
Returns true if the given object is a circular proxy. -
newCircularProxy
Creates a new circular proxy for the given type. -
enhancerBuilder
Create a builder of enhancers for the given class. -
enhancedConstructor
static BiFunction<Object,Object[], enhancedConstructorObject> (Function<String, BiFunction<Object, Object[], Object>> enhancer, Constructor<?> constructor) 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. -
superMethod
static BiFunction<Object,Object[], superMethodObject> (Function<String, BiFunction<Object, Object[], Object>> enhancer, Method method) 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. -
fastConstructor
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.Returns
null
if the constructor cannot be "fast-invoked" due to visibility issues. -
fastMethod
Returns a fast invoker for the given method. The invoker function accepts an instance, which will benull
for static methods, and an array of arguments for the method.Returns
null
if the method cannot be "fast-invoked" due to visibility issues. -
fastClass
Prepares the class declaring the given member for fast invocation using bytecode generation.
-