abstract class AbstractGlueGenerator
extends java.lang.Object
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.)
Modifier and Type | Field and Description |
---|---|
private static java.util.concurrent.atomic.AtomicInteger |
COUNTER |
protected static java.lang.String |
GENERATED_SOURCE |
protected java.lang.Class<?> |
hostClass |
protected java.lang.String |
hostName |
protected java.lang.String |
proxyName |
protected static java.lang.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 java.lang.String |
TRAMPOLINE_NAME |
Modifier | Constructor and Description |
---|---|
protected |
AbstractGlueGenerator(java.lang.Class<?> hostClass,
java.lang.String marker) |
Modifier and Type | Method and Description |
---|---|
private static <E extends java.lang.Throwable> |
asIfUnchecked(java.lang.Throwable e)
Generics trick to get compiler to treat given exception as if unchecked (as JVM does).
|
private static java.util.function.Function<java.lang.String,java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>> |
bindSignaturesToInvokers(java.util.function.ToIntFunction<java.lang.String> signatureTable,
java.lang.invoke.MethodHandle invokerTable)
Combines the signature and invoker tables into a mapping from signature to invoker.
|
protected abstract void |
generateConstructorInvoker(org.objectweb.asm.MethodVisitor mv,
java.lang.reflect.Constructor<?> constructor)
Generate invoker that takes a context and an argument array and calls the constructor.
|
protected abstract byte[] |
generateGlue(java.util.Collection<java.lang.reflect.Executable> members)
Generates enhancer/fast-class bytecode for the given constructors/methods.
|
protected abstract void |
generateMethodInvoker(org.objectweb.asm.MethodVisitor mv,
java.lang.reflect.Method method)
Generate invoker that takes an instance and an argument array and calls the method.
|
protected void |
generateTrampoline(org.objectweb.asm.ClassWriter cw,
java.util.Collection<java.lang.reflect.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.
|
java.util.function.Function<java.lang.String,java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>> |
glue(java.util.NavigableMap<java.lang.String,java.lang.reflect.Executable> glueMap)
Generates the enhancer/fast-class and returns a mapping from signature to invoker.
|
protected abstract java.lang.invoke.MethodHandle |
lookupInvokerTable(java.lang.Class<?> glueClass)
Lookup the invoker table; this may be represented by a function or a trampoline.
|
private static java.lang.String |
proxyName(java.lang.String hostName,
java.lang.String marker,
int hash)
Generates a unique name based on the original class name and marker.
|
protected static final java.lang.String GENERATED_SOURCE
protected static final java.lang.String TRAMPOLINE_NAME
protected static final java.lang.String TRAMPOLINE_DESCRIPTOR
protected final java.lang.Class<?> hostClass
protected final java.lang.String hostName
protected final java.lang.String proxyName
private static final java.util.concurrent.atomic.AtomicInteger COUNTER
protected AbstractGlueGenerator(java.lang.Class<?> hostClass, java.lang.String marker)
private static java.lang.String proxyName(java.lang.String hostName, java.lang.String marker, int hash)
public final java.util.function.Function<java.lang.String,java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>> glue(java.util.NavigableMap<java.lang.String,java.lang.reflect.Executable> glueMap)
protected abstract byte[] generateGlue(java.util.Collection<java.lang.reflect.Executable> members)
protected abstract java.lang.invoke.MethodHandle lookupInvokerTable(java.lang.Class<?> glueClass) throws java.lang.Throwable
java.lang.Throwable
private static java.util.function.Function<java.lang.String,java.util.function.BiFunction<java.lang.Object,java.lang.Object[],java.lang.Object>> bindSignaturesToInvokers(java.util.function.ToIntFunction<java.lang.String> signatureTable, java.lang.invoke.MethodHandle invokerTable)
private static <E extends java.lang.Throwable> java.lang.RuntimeException asIfUnchecked(java.lang.Throwable e) throws E extends java.lang.Throwable
E extends java.lang.Throwable
protected final void generateTrampoline(org.objectweb.asm.ClassWriter cw, java.util.Collection<java.lang.reflect.Executable> members)
protected abstract void generateConstructorInvoker(org.objectweb.asm.MethodVisitor mv, java.lang.reflect.Constructor<?> constructor)
protected abstract void generateMethodInvoker(org.objectweb.asm.MethodVisitor mv, java.lang.reflect.Method method)