Package com.google.inject.internal
Class BytecodeGen
- java.lang.Object
-
- com.google.inject.internal.BytecodeGen
-
public final class BytecodeGen extends java.lang.ObjectUtility methods for circular proxies, faster reflection, and method interception.This class makes heavy use of
FunctionandBiFunctiontypes 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 sameClassLoaderas their host class without needing access to Guice's ownClassLoader. (In other words it removes any need for bridgeClassLoaders.)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceBytecodeGen.EnhancerBuilderBuilder of enhanced classes.
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.Class<?>,java.lang.Boolean>circularProxyTypeCacheprivate static com.google.common.cache.LoadingCache<java.lang.Class<?>,BytecodeGen.EnhancerBuilder>ENHANCER_BUILDERSCache of recentBytecodeGen.EnhancerBuilders.static java.lang.StringENHANCER_BY_GUICE_MARKERprivate static java.lang.ClassValue<java.util.function.Function<java.lang.String,java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>>>FAST_CLASSESLazy association between classes and their generated fast-classes.static java.lang.StringFASTCLASS_BY_GUICE_MARKER
-
Constructor Summary
Constructors Constructor Description BytecodeGen()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>enhancedConstructor(java.util.function.Function<java.lang.String,java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>> enhancer, java.lang.reflect.Constructor<?> constructor)Returns an invoker that constructs an enhanced instance.(package private) static BytecodeGen.EnhancerBuilderenhancerBuilder(java.lang.Class<?> hostClass)Create a builder of enhancers for the given class.private static java.util.function.Function<java.lang.String,java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>>fastClass(java.lang.reflect.Executable member)Prepares the class declaring the given member for fast invocation using bytecode generation.(package private) static java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>fastConstructor(java.lang.reflect.Constructor<?> constructor)Returns a fast invoker for the given constructor.(package private) static java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>fastMethod(java.lang.reflect.Method method)Returns a fast invoker for the given method.static booleanisCircularProxy(java.lang.Object object)Returns true if the given object is a circular proxy.(package private) static <T> TnewCircularProxy(java.lang.Class<T> type, java.lang.reflect.InvocationHandler handler)Creates a new circular proxy for the given type.(package private) static java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>superMethod(java.util.function.Function<java.lang.String,java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>> enhancer, java.lang.reflect.Method method)Returns an invoker that calls the original unenhanced method.
-
-
-
Field Detail
-
circularProxyTypeCache
private static final java.util.Map<java.lang.Class<?>,java.lang.Boolean> circularProxyTypeCache
-
ENHANCER_BY_GUICE_MARKER
public static final java.lang.String ENHANCER_BY_GUICE_MARKER
- See Also:
- Constant Field Values
-
FASTCLASS_BY_GUICE_MARKER
public static final java.lang.String FASTCLASS_BY_GUICE_MARKER
- See Also:
- Constant Field Values
-
ENHANCER_BUILDERS
private static final com.google.common.cache.LoadingCache<java.lang.Class<?>,BytecodeGen.EnhancerBuilder> ENHANCER_BUILDERS
Cache of recentBytecodeGen.EnhancerBuilders.Uses weak values so builders can be collected after they're done enhancing.
-
FAST_CLASSES
private static final java.lang.ClassValue<java.util.function.Function<java.lang.String,java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>>> FAST_CLASSES
Lazy association between classes and their generated fast-classes.
-
-
Method Detail
-
isCircularProxy
public static boolean isCircularProxy(java.lang.Object object)
Returns true if the given object is a circular proxy.
-
newCircularProxy
static <T> T newCircularProxy(java.lang.Class<T> type, java.lang.reflect.InvocationHandler handler)Creates a new circular proxy for the given type.
-
enhancerBuilder
static BytecodeGen.EnhancerBuilder enhancerBuilder(java.lang.Class<?> hostClass)
Create a builder of enhancers for the given class.
-
enhancedConstructor
static java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object> enhancedConstructor(java.util.function.Function<java.lang.String,java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>> enhancer, java.lang.reflect.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 java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object> superMethod(java.util.function.Function<java.lang.String,java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>> enhancer, java.lang.reflect.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
static java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object> fastConstructor(java.lang.reflect.Constructor<?> constructor)
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
nullif the constructor cannot be "fast-invoked" due to visibility issues.
-
fastMethod
static java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object> fastMethod(java.lang.reflect.Method method)
Returns a fast invoker for the given method. The invoker function accepts an instance, which will benullfor static methods, and an array of arguments for the method.Returns
nullif the method cannot be "fast-invoked" due to visibility issues.
-
fastClass
private static java.util.function.Function<java.lang.String,java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>> fastClass(java.lang.reflect.Executable member)
Prepares the class declaring the given member for fast invocation using bytecode generation.
-
-