The external interface to ProxyGenerator is the static "generateProxyClass" method.
| Modifier and Type | Class and Description |
|---|---|
| private static enum | ProxyGenerator.
A PrimitiveTypeInfo object contains bytecode-related information about a primitive type in its instance fields. |
| private class | ProxyGenerator.
A ProxyMethod object represents a proxy method in the proxy class being generated: a method whose implementation will encode and dispatch invocations to the proxy instance's invocation handler. |
| Modifier and Type | Field and Description |
|---|---|
| private final int | accessFlags
Proxy class access flags |
| private static final ClassDesc | |
| private static final ClassDesc | |
| private static final ClassDesc | |
| private static final ClassDesc | |
| private static final ClassDesc | |
| private static final ClassDesc | |
| private static final ClassDesc | |
| private static final ClassDesc | |
| private static final ClassDesc | |
| private static final ClassDesc | |
| private static final ClassDesc | |
| private static final ClassDesc | |
| private static final ClassFile | |
| private final ClassEntry | |
| private final MethodRefEntry | |
| private final MethodRefEntry | |
| private final List | |
| private final ConstantPoolBuilder | |
| private static final Class | |
| private final NameAndTypeEntry | |
| private final FieldRefEntry | |
| private final List | interfaces
Proxy interfaces |
| private final InterfaceMethodRefEntry | |
| private static final MethodTypeDesc | |
| private static final MethodTypeDesc | |
| private static final MethodTypeDesc | |
| private static final MethodTypeDesc | |
| private static final MethodTypeDesc | |
| private static final MethodTypeDesc | |
| private static final MethodTypeDesc | |
| private static final MethodTypeDesc | |
| private static final MethodTypeDesc | |
| private static final MethodTypeDesc | |
| private static final MethodTypeDesc | |
| private static final MethodTypeDesc | |
| private static final String | NAME_HANDLER_FIELD
name of field for storing a proxy instance's invocation handler |
| private static final String | |
| private static final Method | |
| private static final String | |
| private static final Method | |
| private static final String | |
| private static final Method | |
| private static final String | |
| private final ClassEntry | |
| private final ClassEntry | |
| private int | proxyMethodCount
Ordinal of next ProxyMethod object added to proxyMethods. |
| private final Map | proxyMethods
Maps method signature string to list of ProxyMethod objects for proxy methods with that signature. |
| private static final boolean | SAVE_GENERATED_FILES
debugging flag for saving generated class files |
| private final ClassEntry | thisClassCE
ClassEntry for this proxy class |
| private final MethodRefEntry | |
| private final List | |
| private final ClassEntry | |
| private final MethodRefEntry |
| Access | Constructor and Description |
|---|---|
| private | ProxyGenerator(String className, List<Class<?>> interfaces, int accessFlags)
Construct a ProxyGenerator to generate a proxy class with the specified name and for the given interfaces. |
| Modifier and Type | Method and Description |
|---|---|
| private void | addProxyMethod(Method m, Class<?> fromClass)
Add another method to be proxied, either by creating a new ProxyMethod object or augmenting an old one for a duplicate method. |
| private void | addProxyMethod(ProxyGenerator.
an existing ProxyMethod pmAdd an existing ProxyMethod (hashcode, equals, toString). |
| private static void | checkReturnTypes(List<ProxyGenerator.
For a given set of proxy methods with the same signature, check that their return types are compatible according to the Proxy specification. |
| private static void | collectCompatibleTypes(Class<?>[] from, Class<?>[] with, List<Class<?>> list)
Add to the given list all of the types in the "from" array that are not already contained in the list and are assignable to at least one of the types in the "with" array. |
| private static List | computeUniqueCatchList(Class<?>[] exceptions)
Given the exceptions declared in the throws clause of a proxy method, compute the exceptions that need to be caught from the invocation handler's invoke method and rethrown intact in the method's implementation before catching other Throwables and wrapping them in UndeclaredThrowableExceptions. |
| private byte[] | |
| private void | |
| private void | generateLookupAccessor(ClassBuilder clb)
Generate the static lookup accessor method that returns the Lookup on this proxy class if the caller's lookup class is java.lang.reflect.Proxy; otherwise, IllegalAccessException is thrown |
| pack-priv static byte[] | generateProxyClass(ClassLoader loader, final String
the class name of the proxy class name, List<Class<?>> proxy interfaces interfaces, int access flags of the proxy class accessFlags)Generate a proxy class given a name and a list of proxy interfaces. |
| private void | |
| private List | |
| private static List | Returns: the entries of the given typethe types)Class objects, not primitive types nor array typesReturns the entries of the given type. |
| accessFlags | back to summary |
|---|---|
| private final int accessFlags Proxy class access flags | |
| CD_Class_array | back to summary |
|---|---|
| private static final ClassDesc CD_Class_array | |
| CD_ClassLoader | back to summary |
|---|---|
| private static final ClassDesc CD_ClassLoader | |
| CD_ClassNotFoundException | back to summary |
|---|---|
| private static final ClassDesc CD_ClassNotFoundException | |
| CD_IllegalAccessException | back to summary |
|---|---|
| private static final ClassDesc CD_IllegalAccessException | |
| CD_InvocationHandler | back to summary |
|---|---|
| private static final ClassDesc CD_InvocationHandler | |
| CD_Method | back to summary |
|---|---|
| private static final ClassDesc CD_Method | |
| CD_NoClassDefFoundError | back to summary |
|---|---|
| private static final ClassDesc CD_NoClassDefFoundError | |
| CD_NoSuchMethodError | back to summary |
|---|---|
| private static final ClassDesc CD_NoSuchMethodError | |
| CD_NoSuchMethodException | back to summary |
|---|---|
| private static final ClassDesc CD_NoSuchMethodException | |
| CD_Object_array | back to summary |
|---|---|
| private static final ClassDesc CD_Object_array | |
| CD_Proxy | back to summary |
|---|---|
| private static final ClassDesc CD_Proxy | |
| CD_UndeclaredThrowableException | back to summary |
|---|---|
| private static final ClassDesc CD_UndeclaredThrowableException | |
| CF_CONTEXT | back to summary |
|---|---|
| private static final ClassFile CF_CONTEXT | |
| classCE | back to summary |
|---|---|
| private final ClassEntry classCE | |
| classForName | back to summary |
|---|---|
| private final MethodRefEntry classForName | |
| classGetMethod | back to summary |
|---|---|
| private final MethodRefEntry classGetMethod | |
| classLoaderLocal | back to summary |
|---|---|
| private final List<StackMapFrameInfo. | |
| cp | back to summary |
|---|---|
| private final ConstantPoolBuilder cp | |
| EMPTY_CLASS_ARRAY | back to summary |
|---|---|
| private static final Class<?>[] EMPTY_CLASS_ARRAY | |
| exInit | back to summary |
|---|---|
| private final NameAndTypeEntry exInit | |
| handlerField | back to summary |
|---|---|
| private final FieldRefEntry handlerField | |
| interfaces | back to summary |
|---|---|
| private final List<Class<?>> interfaces Proxy interfaces | |
| invocationHandlerInvoke | back to summary |
|---|---|
| private final InterfaceMethodRefEntry invocationHandlerInvoke | |
| MTD_boolean | back to summary |
|---|---|
| private static final MethodTypeDesc MTD_boolean | |
| MTD_Class | back to summary |
|---|---|
| private static final MethodTypeDesc MTD_Class | |
| MTD_Class_String_boolean_ClassLoader | back to summary |
|---|---|
| private static final MethodTypeDesc MTD_Class_String_boolean_ClassLoader | |
| MTD_ClassLoader | back to summary |
|---|---|
| private static final MethodTypeDesc MTD_ClassLoader | |
| MTD_Method_String_Class_array | back to summary |
|---|---|
| private static final MethodTypeDesc MTD_Method_String_Class_array | |
| MTD_MethodHandles$Lookup | back to summary |
|---|---|
| private static final MethodTypeDesc MTD_MethodHandles$Lookup | |
| MTD_MethodHandles$Lookup_MethodHandles$Lookup | back to summary |
|---|---|
| private static final MethodTypeDesc MTD_MethodHandles$Lookup_MethodHandles$Lookup | |
| MTD_Object_Object_Method_ObjectArray | back to summary |
|---|---|
| private static final MethodTypeDesc MTD_Object_Object_Method_ObjectArray | |
| MTD_String | back to summary |
|---|---|
| private static final MethodTypeDesc MTD_String | |
| MTD_void_InvocationHandler | back to summary |
|---|---|
| private static final MethodTypeDesc MTD_void_InvocationHandler | |
| MTD_void_String | back to summary |
|---|---|
| private static final MethodTypeDesc MTD_void_String | |
| MTD_void_Throwable | back to summary |
|---|---|
| private static final MethodTypeDesc MTD_void_Throwable | |
| NAME_HANDLER_FIELD | back to summary |
|---|---|
| private static final String NAME_HANDLER_FIELD name of field for storing a proxy instance's invocation handler | |
| NAME_LOOKUP_ACCESSOR | back to summary |
|---|---|
| private static final String NAME_LOOKUP_ACCESSOR | |
| OBJECT_EQUALS_METHOD | back to summary |
|---|---|
| private static final Method OBJECT_EQUALS_METHOD | |
| OBJECT_EQUALS_SIG | back to summary |
|---|---|
| private static final String OBJECT_EQUALS_SIG | |
| OBJECT_HASH_CODE_METHOD | back to summary |
|---|---|
| private static final Method OBJECT_HASH_CODE_METHOD | |
| OBJECT_HASH_CODE_SIG | back to summary |
|---|---|
| private static final String OBJECT_HASH_CODE_SIG | |
| OBJECT_TO_STRING_METHOD | back to summary |
|---|---|
| private static final Method OBJECT_TO_STRING_METHOD | |
| OBJECT_TO_STRING_SIG | back to summary |
|---|---|
| private static final String OBJECT_TO_STRING_SIG | |
| objectCE | back to summary |
|---|---|
| private final ClassEntry objectCE | |
| proxyCE | back to summary |
|---|---|
| private final ClassEntry proxyCE | |
| proxyMethodCount | back to summary |
|---|---|
| private int proxyMethodCount Ordinal of next ProxyMethod object added to proxyMethods. Indexes are reserved for hashcode(0), equals(1), toString(2). | |
| proxyMethods | back to summary |
|---|---|
| private final Map<String, List<ProxyGenerator. Maps method signature string to list of ProxyMethod objects for proxy methods with that signature. Kept in insertion order to make it easier to compare old and new. | |
| SAVE_GENERATED_FILES | back to summary |
|---|---|
| private static final boolean SAVE_GENERATED_FILES debugging flag for saving generated class files | |
| thisClassCE | back to summary |
|---|---|
| private final ClassEntry thisClassCE ClassEntry for this proxy class | |
| throwableGetMessage | back to summary |
|---|---|
| private final MethodRefEntry throwableGetMessage | |
| throwableStack | back to summary |
|---|---|
| private final List<StackMapFrameInfo. | |
| uteCE | back to summary |
|---|---|
| private final ClassEntry uteCE | |
| uteInit | back to summary |
|---|---|
| private final MethodRefEntry uteInit | |
| ProxyGenerator | back to summary |
|---|---|
| private ProxyGenerator(String className, List<Class<?>> interfaces, int accessFlags) Construct a ProxyGenerator to generate a proxy class with the specified name and for the given interfaces. A ProxyGenerator object contains the state for the ongoing generation of a particular proxy class. | |
| addProxyMethod | back to summary |
|---|---|
| private void addProxyMethod(Method m, Class<?> fromClass) Add another method to be proxied, either by creating a new ProxyMethod object or augmenting an old one for a duplicate method. "fromClass" indicates the proxy interface that the method was found through, which may be different from (a subinterface of) the method's "declaring class". Note that the first Method object passed for a given name and descriptor identifies the Method object (and thus the declaring class) that will be passed to the invocation handler's "invoke" method for a given set of duplicate methods. | |
| addProxyMethod | back to summary |
|---|---|
| private void addProxyMethod(ProxyGenerator. Add an existing ProxyMethod (hashcode, equals, toString).
| |
| checkReturnTypes | back to summary |
|---|---|
| private static void checkReturnTypes(List<ProxyGenerator. For a given set of proxy methods with the same signature, check that their return types are compatible according to the Proxy specification. Specifically, if there is more than one such method, then all of the return types must be reference types, and there must be one return type that is assignable to each of the rest of them. | |
| collectCompatibleTypes | back to summary |
|---|---|
| private static void collectCompatibleTypes(Class<?>[] from, Class<?>[] with, List<Class<?>> list) Add to the given list all of the types in the "from" array that are not already contained in the list and are assignable to at least one of the types in the "with" array. This method is useful for computing the greatest common set of declared exceptions from duplicate methods inherited from different interfaces. | |
| computeUniqueCatchList | back to summary |
|---|---|
| private static List Given the exceptions declared in the throws clause of a proxy method, compute the exceptions that need to be caught from the invocation handler's invoke method and rethrown intact in the method's implementation before catching other Throwables and wrapping them in UndeclaredThrowableExceptions. The exceptions to be caught are returned in a List object. Each exception in the returned list is guaranteed to not be a subclass of any of the other exceptions in the list, so the catch blocks for these exceptions may be generated in any order relative to each other. Error and RuntimeException are each always contained by the returned list (if none of their superclasses are contained), since those unchecked exceptions should always be rethrown intact, and thus their subclasses will never appear in the returned list. The returned List will be empty if java.lang.Throwable is in the given list of declared exceptions, indicating that no exceptions need to be caught. | |
| generateClassFile | back to summary |
|---|---|
| private byte[] generateClassFile() Generate a class file for the proxy class. This method drives the class file generation process. | |
| generateConstructor | back to summary |
|---|---|
| private void generateConstructor(ClassBuilder clb) Generate the constructor method for the proxy class. | |
| generateLookupAccessor | back to summary |
|---|---|
| private void generateLookupAccessor(ClassBuilder clb) Generate the static lookup accessor method that returns the Lookup on this proxy class if the caller's lookup class is java.lang.reflect.Proxy; otherwise, IllegalAccessException is thrown | |
| generateProxyClass | back to summary |
|---|---|
| pack-priv static byte[] generateProxyClass(ClassLoader loader, final String name, List<Class<?>> interfaces, int accessFlags) Generate a proxy class given a name and a list of proxy interfaces. | |
| generateStaticInitializer | back to summary |
|---|---|
| private void generateStaticInitializer(ClassBuilder clb) Generate the class initializer. | |
| proxyMethodsFor | back to summary |
|---|---|
| private List | |
| toClassEntries | back to summary |
|---|---|
| private static List Returns the entries of the given type.
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final ProxyGenerator. | |
| public static final ProxyGenerator. | |
| public static final ProxyGenerator. | |
| public static final ProxyGenerator. | |
| public static final ProxyGenerator. | |
| public static final ProxyGenerator. | |
| public static final ProxyGenerator. | |
| public static final ProxyGenerator. | |
| private final String | unwrapMethodName
wrapper class method name for retrieving primitive value |
| private final MethodTypeDesc | unwrapMethodType
wrapper class method type for retrieving primitive value |
| private final ClassDesc | wrapperClass
wrapper class |
| private final MethodTypeDesc | wrapperMethodType
wrapper factory method type |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static ProxyGenerator. | |
| public FieldRefEntry | |
| public MethodRefEntry | |
| public static ProxyGenerator. | |
| public static ProxyGenerator. | |
| public MethodRefEntry |
| BOOLEAN | back to summary |
|---|---|
| public static final ProxyGenerator. | |
| BYTE | back to summary |
|---|---|
| public static final ProxyGenerator. | |
| CHAR | back to summary |
|---|---|
| public static final ProxyGenerator. | |
| DOUBLE | back to summary |
|---|---|
| public static final ProxyGenerator. | |
| FLOAT | back to summary |
|---|---|
| public static final ProxyGenerator. | |
| INT | back to summary |
|---|---|
| public static final ProxyGenerator. | |
| LONG | back to summary |
|---|---|
| public static final ProxyGenerator. | |
| SHORT | back to summary |
|---|---|
| public static final ProxyGenerator. | |
| unwrapMethodName | back to summary |
|---|---|
| private final String unwrapMethodName wrapper class method name for retrieving primitive value | |
| unwrapMethodType | back to summary |
|---|---|
| private final MethodTypeDesc unwrapMethodType wrapper class method type for retrieving primitive value | |
| wrapperClass | back to summary |
|---|---|
| private final ClassDesc wrapperClass wrapper class | |
| wrapperMethodType | back to summary |
|---|---|
| private final MethodTypeDesc wrapperMethodType wrapper factory method type | |
| PrimitiveTypeInfo | back to summary |
|---|---|
| private PrimitiveTypeInfo(Class<?> primitiveClass, ClassDesc baseType, ClassDesc wrapperClass) | |
| get | back to summary |
|---|---|
| public static ProxyGenerator. | |
| typeFieldRef | back to summary |
|---|---|
| public FieldRefEntry typeFieldRef(ConstantPoolBuilder cp) | |
| unwrapMethodRef | back to summary |
|---|---|
| public MethodRefEntry unwrapMethodRef(ConstantPoolBuilder cp) | |
| valueOf | back to summary |
|---|---|
| public static ProxyGenerator. | |
| values | back to summary |
|---|---|
| public static ProxyGenerator. | |
| wrapperMethodRef | back to summary |
|---|---|
| public MethodRefEntry wrapperMethodRef(ConstantPoolBuilder cp) | |
| Modifier and Type | Field and Description |
|---|---|
| private Class | |
| private final Class | |
| private final Method | |
| private final FieldRefEntry | |
| private final String | |
| private final Class | |
| private final String |
| Access | Constructor and Description |
|---|---|
| private | |
| private | ProxyMethod(Method
The method for which to create a proxy method, String sig, String methodFieldName)Create a new specific ProxyMethod with a specific field name |
| Modifier and Type | Method and Description |
|---|---|
| private void | codeClassForName(CodeBuilder cob, Class<?> cl)
Generate code to invoke the Class.forName with the name of the given class to get its Class object at runtime. |
| private void | codeFieldInitialization(CodeBuilder cob)
Generate code for initializing the static field that stores the Method object for this proxy method. |
| private void | codeUnwrapReturnValue(CodeBuilder cob, Class<?> type)
Generate code for unwrapping a return value of the given type from the invocation handler's "invoke" method (as type Object) to its correct type. |
| private void | codeWrapArgument(CodeBuilder cob, Class<?> type, int slot)
Generate code for wrapping an argument of the given type whose value can be found at the specified local variable index, in order for it to be passed (as an Object) to the invocation handler's "invoke" method. |
| private void | |
| private Class | |
| public String |
| exceptionTypes | back to summary |
|---|---|
| private Class<?>[] exceptionTypes | |
| fromClass | back to summary |
|---|---|
| private final Class<?> fromClass | |
| method | back to summary |
|---|---|
| private final Method method | |
| methodField | back to summary |
|---|---|
| private final FieldRefEntry methodField | |
| methodFieldName | back to summary |
|---|---|
| private final String methodFieldName | |
| returnType | back to summary |
|---|---|
| private final Class<?> returnType | |
| shortSignature | back to summary |
|---|---|
| private final String shortSignature | |
| ProxyMethod | back to summary |
|---|---|
| private ProxyMethod(Method method, String sig, Class<?> returnType, Class<?>[] exceptionTypes, Class<?> fromClass, String methodFieldName) | |
| ProxyMethod | back to summary |
|---|---|
| private ProxyMethod(Method method, String sig, String methodFieldName) Create a new specific ProxyMethod with a specific field name
| |
| codeClassForName | back to summary |
|---|---|
| private void codeClassForName(CodeBuilder cob, Class<?> cl) Generate code to invoke the Class.forName with the name of the given class to get its Class object at runtime. The code is written to the supplied stream. Note that the code generated by this method may cause the checked ClassNotFoundException to be thrown. A class loader is anticipated at local variable index 0. | |
| codeFieldInitialization | back to summary |
|---|---|
| private void codeFieldInitialization(CodeBuilder cob) Generate code for initializing the static field that stores the Method object for this proxy method. A class loader is anticipated at local variable index 0. | |
| codeUnwrapReturnValue | back to summary |
|---|---|
| private void codeUnwrapReturnValue(CodeBuilder cob, Class<?> type) Generate code for unwrapping a return value of the given type from the invocation handler's "invoke" method (as type Object) to its correct type. | |
| codeWrapArgument | back to summary |
|---|---|
| private void codeWrapArgument(CodeBuilder cob, Class<?> type, int slot) Generate code for wrapping an argument of the given type whose value can be found at the specified local variable index, in order for it to be passed (as an Object) to the invocation handler's "invoke" method. | |
| generateMethod | back to summary |
|---|---|
| private void generateMethod(ClassBuilder clb) Generate this method, including the code and exception table entry. | |
| parameterTypes | back to summary |
|---|---|
| private Class | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |