Class Enhancer
Each enhancer has the same number of constructors as the class it enhances, but each constructor takes an additional handler array before the rest of the expected arguments.
Enhanced methods are overridden to call the handler with the same index as the method. The handler delegates to the interceptor stack. Once the last interceptor returns the handler will call back into the trampoline with the method index, which invokes the superclass method.
The trampoline also provides access to constructor invokers that take a context object (the handler array) with an argument array and invokes the appropriate enhanced constructor. These invokers are used in the proxy factory to create enhanced instances.
Enhanced classes have the following pseudo-Java structure:
public class HostClass$$EnhancerByGuice
extends HostClass
{
// InterceptorStackCallbacks, one per enhanced method
private final InvocationHandler[] GUICE$HANDLERS;
public HostClass$$EnhancerByGuice(InvocationHandler[] handlers, ...) {
// JVM lets us store this before calling the superclass constructor
GUICE$HANDLERS = handlers;
super(...);
}
public static Object GUICE$TRAMPOLINE(int index, Object context, Object[] args) {
switch (index) {
case 0: {
return new HostClass$$EnhancerByGuice((InvocationHandler[]) context, ...);
}
case 1: {
return context.super.instanceMethod(...); // call original unenhanced method
}
}
return null;
}
// enhanced method
public final Object instanceMethod(...) {
// pack arguments and trigger the associated InterceptorStackCallback
return GUICE$HANDLERS[0].invoke(this, null, args);
}
// ...
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final org.objectweb.asm.Typeprivate static final org.objectweb.asm.Typeprivate static final Stringprivate static final Stringprivate static final Stringprivate static final org.objectweb.asm.TypeFields inherited from class com.google.inject.internal.aop.AbstractGlueGenerator
GENERATED_SOURCE, hostClass, hostName, proxyName, TRAMPOLINE_DESCRIPTOR, TRAMPOLINE_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidenhanceConstructor(org.objectweb.asm.ClassWriter cw, Constructor<?> constructor) Generate enhanced constructor that takes a handler array along with the expected arguments.private voidenhanceMethod(org.objectweb.asm.ClassWriter cw, Method method, int methodIndex) Generate enhanced method that calls the handler with the same index.private static String[]exceptionNames(Executable member) Returns internal names of exceptions declared by the given constructor/method.protected voidgenerateConstructorInvoker(org.objectweb.asm.MethodVisitor mv, Constructor<?> constructor) Generate invoker that takes a context and an argument array and calls the constructor.protected byte[]generateGlue(Collection<Executable> members) Generates enhancer/fast-class bytecode for the given constructors/methods.protected voidgenerateMethodInvoker(org.objectweb.asm.MethodVisitor mv, Method method) Generate invoker that takes an instance and an argument array and calls the method.private voidgenerateVirtualBridge(org.objectweb.asm.ClassWriter cw, Method bridge, Method target) Override the original bridge method and replace it with virtual dispatch to the target.protected MethodHandlelookupInvokerTable(Class<?> glueClass) Lookup the invoker table; this may be represented by a function or a trampoline.private voidsetupInvokerTable(org.objectweb.asm.ClassWriter cw) Generate static initializer to setup invoker table based on the trampoline.Methods inherited from class com.google.inject.internal.aop.AbstractGlueGenerator
generateTrampoline, glue
-
Field Details
-
HANDLERS_NAME
- See Also:
-
HANDLERS_DESCRIPTOR
- See Also:
-
HANDLER_TYPE
-
HANDLER_ARRAY_TYPE
-
INVOKERS_NAME
- See Also:
-
INVOKERS_DESCRIPTOR
- See Also:
-
CALLBACK_DESCRIPTOR
- See Also:
-
METAFACTORY_DESCRIPTOR
- See Also:
-
INDEX_TO_INVOKER_METHOD_TYPE
private static final org.objectweb.asm.Type INDEX_TO_INVOKER_METHOD_TYPE -
RAW_INVOKER_METHOD_TYPE
private static final org.objectweb.asm.Type RAW_INVOKER_METHOD_TYPE -
INVOKER_METHOD_TYPE
private static final org.objectweb.asm.Type INVOKER_METHOD_TYPE -
bridgeDelegates
-
checkcastToProxy
-
-
Constructor Details
-
Enhancer
-
-
Method Details
-
generateGlue
Description copied from class:AbstractGlueGeneratorGenerates enhancer/fast-class bytecode for the given constructors/methods.- Specified by:
generateGluein classAbstractGlueGenerator
-
setupInvokerTable
private void setupInvokerTable(org.objectweb.asm.ClassWriter cw) Generate static initializer to setup invoker table based on the trampoline. -
enhanceConstructor
Generate enhanced constructor that takes a handler array along with the expected arguments. -
enhanceMethod
Generate enhanced method that calls the handler with the same index. -
generateConstructorInvoker
protected void generateConstructorInvoker(org.objectweb.asm.MethodVisitor mv, Constructor<?> constructor) Description copied from class:AbstractGlueGeneratorGenerate invoker that takes a context and an argument array and calls the constructor.- Specified by:
generateConstructorInvokerin classAbstractGlueGenerator
-
generateMethodInvoker
Description copied from class:AbstractGlueGeneratorGenerate invoker that takes an instance and an argument array and calls the method.- Specified by:
generateMethodInvokerin classAbstractGlueGenerator
-
generateVirtualBridge
Override the original bridge method and replace it with virtual dispatch to the target. -
lookupInvokerTable
Description copied from class:AbstractGlueGeneratorLookup the invoker table; this may be represented by a function or a trampoline.- Specified by:
lookupInvokerTablein classAbstractGlueGenerator- Throws:
Throwable
-
exceptionNames
Returns internal names of exceptions declared by the given constructor/method.
-