Top Description Fields Constructors Methods
com.google.inject.internal.aop

pack-priv final Class Enhancer

extends AbstractGlueGenerator
Class Inheritance
Static Imports
com.google.inject.internal.BytecodeGen.ENHANCER_BY_GUICE_MARKER, com.google.inject.internal.aop.BytecodeTasks.box, .BytecodeTasks.loadArgument, .BytecodeTasks.packArguments, .BytecodeTasks.pushInteger, .BytecodeTasks.unbox, .BytecodeTasks.unpackArguments, java.lang.reflect.Modifier.ABSTRACT, .Modifier.FINAL, .Modifier.NATIVE, .Modifier.PRIVATE, .Modifier.PUBLIC, .Modifier.STATIC, .Modifier.SYNCHRONIZED, org.objectweb.asm.ClassWriter.COMPUTE_MAXS, .Opcodes.AALOAD, .Opcodes.ACC_SUPER, .Opcodes.ACONST_NULL, .Opcodes.ALOAD, .Opcodes.ARETURN, .Opcodes.CHECKCAST, .Opcodes.DUP, .Opcodes.GETFIELD, .Opcodes.H_INVOKESTATIC, .Opcodes.INVOKEINTERFACE, .Opcodes.INVOKESPECIAL, .Opcodes.INVOKESTATIC, .Opcodes.INVOKEVIRTUAL, .Opcodes.IRETURN, .Opcodes.NEW, .Opcodes.PUTFIELD, .Opcodes.PUTSTATIC, .Opcodes.RETURN, .Opcodes.SWAP, .Opcodes.V1_8

Generates enhanced classes.

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);
  }

  // ...
}
Author
[email protected] (Stuart McCulloch)

Field Summary

Modifier and TypeField and Description
private final Map<Method, Method>
private static final String
private final String
private static final String
private static final String
private static final String
private static final String
private static final Type
private static final Type
private static final String
private static final String
private static final String
private static final Type
Inherited from com.google.inject.internal.aop.AbstractGlueGenerator:
GENERATED_SOURCEhostClasshostNameproxyNameTRAMPOLINE_DESCRIPTORTRAMPOLINE_NAME

Constructor Summary

AccessConstructor and Description
pack-priv
Enhancer(Class<?> hostClass, Map<Method, Method> bridgeDelegates)

Method Summary

Modifier and TypeMethod and Description
private void
enhanceConstructor(ClassWriter cw, Constructor<?> constructor)

Generate enhanced constructor that takes a handler array along with the expected arguments.

private void
enhanceMethod(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 void
generateConstructorInvoker(MethodVisitor mv, Constructor<?> constructor)

Implements abstract com.google.inject.internal.aop.AbstractGlueGenerator.generateConstructorInvoker.

Generate invoker that takes a context and an argument array and calls the constructor.
protected byte[]
generateGlue(Collection<Executable> members)

Implements abstract com.google.inject.internal.aop.AbstractGlueGenerator.generateGlue.

Generates enhancer/fast-class bytecode for the given constructors/methods.
protected void
generateMethodInvoker(MethodVisitor mv, Method method)

Implements abstract com.google.inject.internal.aop.AbstractGlueGenerator.generateMethodInvoker.

Generate invoker that takes an instance and an argument array and calls the method.
private void
generateVirtualBridge(ClassWriter cw, Method bridge, Method target)

Override the original bridge method and replace it with virtual dispatch to the target.

protected MethodHandle
lookupInvokerTable(Class<?> glueClass)

Implements abstract com.google.inject.internal.aop.AbstractGlueGenerator.lookupInvokerTable.

Lookup the invoker table; this may be represented by a function or a trampoline.
private void
setupInvokerTable(ClassWriter cw)

Generate static initializer to setup invoker table based on the trampoline.

Inherited from com.google.inject.internal.aop.AbstractGlueGenerator:
generateTrampolineglue

Field Detail

bridgeDelegatesback to summary
private final Map<Method, Method> bridgeDelegates
CALLBACK_DESCRIPTORback to summary
private static final String CALLBACK_DESCRIPTOR
checkcastToProxyback to summary
private final String checkcastToProxy
HANDLER_ARRAY_TYPEback to summary
private static final String HANDLER_ARRAY_TYPE
HANDLER_TYPEback to summary
private static final String HANDLER_TYPE
HANDLERS_DESCRIPTORback to summary
private static final String HANDLERS_DESCRIPTOR
HANDLERS_NAMEback to summary
private static final String HANDLERS_NAME
INDEX_TO_INVOKER_METHOD_TYPEback to summary
private static final Type INDEX_TO_INVOKER_METHOD_TYPE
INVOKER_METHOD_TYPEback to summary
private static final Type INVOKER_METHOD_TYPE
INVOKERS_DESCRIPTORback to summary
private static final String INVOKERS_DESCRIPTOR
INVOKERS_NAMEback to summary
private static final String INVOKERS_NAME
METAFACTORY_DESCRIPTORback to summary
private static final String METAFACTORY_DESCRIPTOR
RAW_INVOKER_METHOD_TYPEback to summary
private static final Type RAW_INVOKER_METHOD_TYPE

Constructor Detail

Enhancerback to summary
pack-priv Enhancer(Class<?> hostClass, Map<Method, Method> bridgeDelegates)

Method Detail

enhanceConstructorback to summary
private void enhanceConstructor(ClassWriter cw, Constructor<?> constructor)

Generate enhanced constructor that takes a handler array along with the expected arguments.

enhanceMethodback to summary
private void enhanceMethod(ClassWriter cw, Method method, int methodIndex)

Generate enhanced method that calls the handler with the same index.

exceptionNamesback to summary
private static String[] exceptionNames(Executable member)

Returns internal names of exceptions declared by the given constructor/method.

generateConstructorInvokerback to summary
protected void generateConstructorInvoker(MethodVisitor mv, Constructor<?> constructor)

Implements abstract com.google.inject.internal.aop.AbstractGlueGenerator.generateConstructorInvoker.

Doc from com.google.inject.internal.aop.AbstractGlueGenerator.generateConstructorInvoker.

Generate invoker that takes a context and an argument array and calls the constructor.

Annotations
@Override
generateGlueback to summary
protected byte[] generateGlue(Collection<Executable> members)

Implements abstract com.google.inject.internal.aop.AbstractGlueGenerator.generateGlue.

Doc from com.google.inject.internal.aop.AbstractGlueGenerator.generateGlue.

Generates enhancer/fast-class bytecode for the given constructors/methods.

Annotations
@Override
generateMethodInvokerback to summary
protected void generateMethodInvoker(MethodVisitor mv, Method method)

Implements abstract com.google.inject.internal.aop.AbstractGlueGenerator.generateMethodInvoker.

Doc from com.google.inject.internal.aop.AbstractGlueGenerator.generateMethodInvoker.

Generate invoker that takes an instance and an argument array and calls the method.

Annotations
@Override
generateVirtualBridgeback to summary
private void generateVirtualBridge(ClassWriter cw, Method bridge, Method target)

Override the original bridge method and replace it with virtual dispatch to the target.

lookupInvokerTableback to summary
protected MethodHandle lookupInvokerTable(Class<?> glueClass) throws Throwable

Implements abstract com.google.inject.internal.aop.AbstractGlueGenerator.lookupInvokerTable.

Doc from com.google.inject.internal.aop.AbstractGlueGenerator.lookupInvokerTable.

Lookup the invoker table; this may be represented by a function or a trampoline.

Annotations
@Override
setupInvokerTableback to summary
private void setupInvokerTable(ClassWriter cw)

Generate static initializer to setup invoker table based on the trampoline.