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.)
| Modifier and Type | Field 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 |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method 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 | 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 | 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 |
| COUNTER | back to summary |
|---|---|
| private static final AtomicInteger COUNTER | |
| GENERATED_SOURCE | back to summary |
|---|---|
| protected static final String GENERATED_SOURCE | |
| hostClass | back to summary |
|---|---|
| protected final Class<?> hostClass | |
| hostName | back to summary |
|---|---|
| protected final String hostName | |
| proxyName | back to summary |
|---|---|
| protected final String proxyName | |
| TRAMPOLINE_DESCRIPTOR | back 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_NAME | back to summary |
|---|---|
| protected static final String TRAMPOLINE_NAME | |
| AbstractGlueGenerator | back to summary |
|---|---|
| protected AbstractGlueGenerator(Class<?> hostClass, String marker) | |
| asIfUnchecked | back 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).
| |
| bindSignaturesToInvokers | back to summary |
|---|---|
| private static Function Combines the signature and invoker tables into a mapping from signature to invoker. | |
| generateConstructorInvoker | back to summary |
|---|---|
| protected abstract void generateConstructorInvoker(MethodVisitor mv, Constructor<?> constructor) Generate invoker that takes a context and an argument array and calls the constructor. | |
| generateGlue | back to summary |
|---|---|
| protected abstract byte[] generateGlue(Collection<Executable> members) Generates enhancer/fast-class bytecode for the given constructors/methods. | |
| generateMethodInvoker | back to summary |
|---|---|
| protected abstract void generateMethodInvoker(MethodVisitor mv, Method method) Generate invoker that takes an instance and an argument array and calls the method. | |
| generateTrampoline | back 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. | |
| glue | back to summary |
|---|---|
| public final Function Generates the enhancer/fast-class and returns a mapping from signature to invoker. | |
| lookupInvokerTable | back to summary |
|---|---|
| protected abstract MethodHandle lookupInvokerTable(Class<?> glueClass) throws Throwable Lookup the invoker table; this may be represented by a function or a trampoline. | |
| proxyName | back to summary |
|---|---|
| private static String proxyName(String hostName, String marker, int hash) Generates a unique name based on the original class name and marker. | |