Package com.google.inject.internal.aop
Class AbstractGlueGenerator
java.lang.Object
com.google.inject.internal.aop.AbstractGlueGenerator
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 ClassLoader
s.)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final AtomicInteger
protected static final String
protected final Class<?>
protected final String
protected final String
protected static final String
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static <E extends Throwable>
RuntimeExceptionGenerics trick to get compiler to treat given exception as if unchecked (as JVM does).bindSignaturesToInvokers
(ToIntFunction<String> signatureTable, MethodHandle invokerTable) Combines the signature and invoker tables into a mapping from signature to invoker.protected abstract void
generateConstructorInvoker
(org.objectweb.asm.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
(org.objectweb.asm.MethodVisitor mv, Method method) Generate invoker that takes an instance and an argument array and calls the method.protected final void
generateTrampoline
(org.objectweb.asm.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.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
Generates a unique name based on the original class name and marker.
-
Field Details
-
GENERATED_SOURCE
- See Also:
-
TRAMPOLINE_NAME
- See Also:
-
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.- See Also:
-
hostClass
-
hostName
-
proxyName
-
COUNTER
-
-
Constructor Details
-
AbstractGlueGenerator
-
-
Method Details
-
proxyName
Generates a unique name based on the original class name and marker. -
generateGlue
Generates enhancer/fast-class bytecode for the given constructors/methods. -
lookupInvokerTable
Lookup the invoker table; this may be represented by a function or a trampoline.- Throws:
Throwable
-
bindSignaturesToInvokers
private static Function<String,BiFunction<Object, bindSignaturesToInvokersObject[], Object>> (ToIntFunction<String> signatureTable, MethodHandle invokerTable) Combines the signature and invoker tables into a mapping from signature to invoker. -
asIfUnchecked
Generics trick to get compiler to treat given exception as if unchecked (as JVM does).- Throws:
E extends Throwable
-
generateTrampoline
protected final void generateTrampoline(org.objectweb.asm.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. -
generateConstructorInvoker
protected abstract void generateConstructorInvoker(org.objectweb.asm.MethodVisitor mv, Constructor<?> constructor) Generate invoker that takes a context and an argument array and calls the constructor. -
generateMethodInvoker
Generate invoker that takes an instance and an argument array and calls the method.
-