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

pack-priv abstract Class AbstractGlueGenerator

extends Object
Class Inheritance
Known Direct Subclasses
com.google.inject.internal.aop.Enhancer, com.google.inject.internal.aop.FastClass
Static Imports
java.lang.reflect.Modifier.PUBLIC, .Modifier.STATIC, org.objectweb.asm.Opcodes.ACONST_NULL, .Opcodes.ARETURN, .Opcodes.F_SAME, .Opcodes.ILOAD

Support code for generating enhancer/fast-class glue.

Each glue class has a trampoline that accepts an index, context object, and argument array:

public static Object GUICE$TRAMPOLINE(int index, Object context, Object[] args) {
  switch (index) {
    case 0: {
      return ...;
    }
    case 1: {
      return ...;
    }
  }
  return null;
}
Each indexed statement in the trampoline invokes a constructor or method, returning the result. The expected context object depends on the statement; it could be the invocation target, some additional constructor context, or it may be unused. Arguments are unpacked from the array onto the call stack, unboxing or casting them as necessary. Primitive results are autoboxed before being returned.

Where possible the trampoline is converted into a lookup Function mapping an integer to an invoker function, each invoker represented as a BiFunction that accepts a context object plus argument array and returns the result. These functional interfaces are used to avoid introducing a dependency from the glue class to Guice specific types. This means the glue class can be loaded anywhere that can see the host class, it doesn't need access to Guice's own ClassLoader. (In other words it removes any need for bridge ClassLoaders.)

Author
[email protected] (Stuart McCulloch)

Field Summary

Modifier and TypeField and Description
private static final AtomicInteger
protected static final String
protected final Class<?>
protected final String
protected final String
protected static final String
TRAMPOLINE_DESCRIPTOR

The trampoline method takes an index, along with a context object and an array of argument objects, and invokes the appropriate constructor/method returning the result as an object.

protected static final String

Constructor Summary

AccessConstructor and Description
protected
AbstractGlueGenerator(Class<?> hostClass, String marker)

Method Summary

Modifier and TypeMethod and Description
private static <E extends Throwable> RuntimeException
asIfUnchecked(Throwable e)

Generics trick to get compiler to treat given exception as if unchecked (as JVM does).

private static Function<String, BiFunction<Object, Object[], Object>>
bindSignaturesToInvokers(ToIntFunction<String> signatureTable, MethodHandle invokerTable)

Combines the signature and invoker tables into a mapping from signature to invoker.

protected abstract void
generateConstructorInvoker(MethodVisitor mv, Constructor<?> constructor)

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

protected abstract byte[]
generateGlue(Collection<Executable> members)

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

protected abstract void
generateMethodInvoker(MethodVisitor mv, Method method)

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

protected final void
generateTrampoline(ClassWriter cw, Collection<Executable> members)

Generate trampoline that takes an index, along with a context object and array of argument objects, and invokes the appropriate constructor/method returning the result as an object.

public final Function<String, BiFunction<Object, Object[], Object>>
glue(NavigableMap<String, Executable> glueMap)

Generates the enhancer/fast-class and returns a mapping from signature to invoker.

protected abstract MethodHandle
lookupInvokerTable(Class<?> glueClass)

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

private static String
proxyName(String hostName, String marker, int hash)

Generates a unique name based on the original class name and marker.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

COUNTERback to summary
private static final AtomicInteger COUNTER
GENERATED_SOURCEback to summary
protected static final String GENERATED_SOURCE
hostClassback to summary
protected final Class<?> hostClass
hostNameback to summary
protected final String hostName
proxyNameback to summary
protected final String proxyName
TRAMPOLINE_DESCRIPTORback to summary
protected static final String TRAMPOLINE_DESCRIPTOR

The trampoline method takes an index, along with a context object and an array of argument objects, and invokes the appropriate constructor/method returning the result as an object.

TRAMPOLINE_NAMEback to summary
protected static final String TRAMPOLINE_NAME

Constructor Detail

AbstractGlueGeneratorback to summary
protected AbstractGlueGenerator(Class<?> hostClass, String marker)

Method Detail

asIfUncheckedback to summary
private static <E extends Throwable> RuntimeException asIfUnchecked(Throwable e) throws Throwable-:E

Generics trick to get compiler to treat given exception as if unchecked (as JVM does).

Annotations
@SuppressWarnings:unchecked
bindSignaturesToInvokersback to summary
private static Function<String, BiFunction<Object, Object[], Object>> bindSignaturesToInvokers(ToIntFunction<String> signatureTable, MethodHandle invokerTable)

Combines the signature and invoker tables into a mapping from signature to invoker.

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

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

generateGlueback to summary
protected abstract byte[] generateGlue(Collection<Executable> members)

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

generateMethodInvokerback to summary
protected abstract void generateMethodInvoker(MethodVisitor mv, Method method)

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

generateTrampolineback to summary
protected final void generateTrampoline(ClassWriter cw, Collection<Executable> members)

Generate trampoline that takes an index, along with a context object and array of argument objects, and invokes the appropriate constructor/method returning the result as an object.

glueback to summary
public final Function<String, BiFunction<Object, Object[], Object>> glue(NavigableMap<String, Executable> glueMap)

Generates the enhancer/fast-class and returns a mapping from signature to invoker.

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

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

proxyNameback to summary
private static String proxyName(String hostName, String marker, int hash)

Generates a unique name based on the original class name and marker.