Modifier and Type | Class and Description |
---|---|
static class |
Utils.ReturnType |
Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
NO_STRINGS |
ACC_PRIVATE_PROTECTED, ACC_PRIVATE_STATIC, ACC_PRIVATE_STATIC_FINAL, ACC_PRIVATE_STATIC_SYNTHETIC, ACC_PUBLIC_ABSTRACT, ACC_PUBLIC_INTERFACE, ACC_PUBLIC_PRIVATE_PROTECTED, ACC_PUBLIC_PROTECTED, ACC_PUBLIC_STATIC, ACC_PUBLIC_STATIC_FINAL, ACC_PUBLIC_STATIC_SYNTHETIC, ACC_PUBLIC_SYNTHETIC, DEFAULT_BOOLEAN, DEFAULT_BYTE, DEFAULT_CHAR, DEFAULT_DOUBLE, DEFAULT_FLOAT, DEFAULT_INT, DEFAULT_LONG, DEFAULT_SHORT, descriptorChangedForInvokeSpecialName, executorClassNamePattern, fInstanceFieldsName, fReloadableTypeFieldName, fStaticFieldsName, JLC_GETCONSTRUCTOR, JLC_GETDECLAREDCONSTRUCTOR, JLC_GETDECLAREDCONSTRUCTORS, JLC_GETDECLAREDFIELD, JLC_GETDECLAREDFIELDS, JLC_GETDECLAREDMETHOD, JLC_GETDECLAREDMETHODS, JLC_GETFIELD, JLC_GETMETHOD, JLC_GETMETHODS, JLC_GETMODIFIERS, jlcgc, jlcgcDescriptor, jlcgdc, jlcgdcDescriptor, jlcgdf, jlcgdfDescriptor, jlcgdfs, jlcgdfsDescriptor, jlcgdm, jlcgdmDescriptor, jlcgdms, jlcgdmsDescriptor, jlcGetDeclaredConstructorsDescriptor, jlcGetDeclaredConstructorsMember, jlcgf, jlcgfDescriptor, jlcgm, jlcgmDescriptor, jlcgmods, jlcgmodsDescriptor, jlcgms, jlcgmsDescriptor, jlObject, jloObjectStream_hasInitializerMethod, JLOS_HASSTATICINITIALIZER, JLRF_GET, JLRF_GETLONG, jlrfGetDescriptor, jlrfGetLongDescriptor, jlrfGetLongMember, jlrfGetMember, JLRM_INVOKE, jlrmInvokeDescriptor, jlrmInvokeMember, lDynamicallyDispatchable, lInstanceStateManager, lRegistryType, lReloadableType, lStaticStateManager, magicDescriptorForGeneratedCtors, mChangedForConstructorName, mChangedForInvocationName, mChangedForInvokeDynamicName, mChangedForInvokeInterfaceName, mChangedForInvokeSpecialName, mChangedForInvokeStaticName, mChangedForInvokeVirtualName, mDynamicDispatchDescriptor, mDynamicDispatchName, methodSuffixSuperDispatcher, mInitializerName, mInstanceFieldGetterDescriptor, mInstanceFieldGetterName, mInstanceFieldInterceptionRequired, mInstanceFieldSetterDescriptor, mInstanceFieldSetterName, mPerformInvokeDynamicName, mStaticFieldGetterName, mStaticFieldInterceptionRequired, mStaticFieldSetterDescriptor, mStaticFieldSetterName, mStaticInitializerName, NO_FIELDS, NO_METHODS, PREFIX, tDynamicallyDispatchable, tInstanceStateManager, tRegistryType, tReloadableType, tStaticStateManager, WAS_INVOKESTATIC, WAS_INVOKEVIRTUAL
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_MANDATED, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASM4, ASM5, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, H_GETFIELD, H_GETSTATIC, H_INVOKEINTERFACE, H_INVOKESPECIAL, H_INVOKESTATIC, H_INVOKEVIRTUAL, H_NEWINVOKESPECIAL, H_PUTFIELD, H_PUTSTATIC, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INTEGER, INVOKEDYNAMIC, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, TOP, UNINITIALIZED_THIS, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6, V1_7, V1_8
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static void |
addCorrectReturnInstruction(org.objectweb.asm.MethodVisitor mv,
Utils.ReturnType returnType,
boolean createCast)
Depending on the signature of the return type, add the appropriate instructions to the method visitor.
|
static java.lang.String |
annotationNodeFormat(org.objectweb.asm.tree.AnnotationNode o) |
static void |
appendDescriptor(java.lang.Class<?> p,
java.lang.StringBuilder s) |
static <T> T[] |
arrayCopyOf(T[] array,
int newSize)
Utility method similar to Java 1.6 Arrays.copyOf, used instead of that method to stick to Java 1.5 only API.
|
static void |
assertDotted(java.lang.String name) |
static void |
assertSlashed(java.lang.String name) |
static void |
assertTrue(boolean condition,
java.lang.String detail) |
static java.lang.Object |
checkCompatibility(TypeRegistry registry,
java.lang.Object result,
java.lang.String expectedTypeDescriptor)
Check that the value we have discovered is of the right type.
|
static int |
collapseStackToArray(org.objectweb.asm.MethodVisitor mv,
java.lang.String desc) |
static void |
createLoadsBasedOnDescriptor(org.objectweb.asm.MethodVisitor mv,
java.lang.String descriptor,
int startindex)
Create the set of LOAD instructions to load the method parameters.
|
static long |
decode(java.lang.String s)
Decode a base62 encoded string into a number (base10).
|
static java.lang.String[] |
discoverInterfaces(byte[] classbytes)
Determine the interfaces implemented by a given class (supplied as bytes)
|
static java.lang.String |
dump(java.lang.String slashname,
byte[] bytes)
Dump the specified bytes under the specified name in the filesystem.
|
static void |
dumpClass(java.lang.String file,
byte[] bytes)
Dump some bytes into the specified file.
|
static java.lang.String |
encode(long number)
Convert a number (base10) to base62 encoded string
|
static java.lang.String |
fieldNodeFormat(java.util.Collection<org.objectweb.asm.tree.FieldNode> fieldNodes) |
static java.lang.String |
fieldNodeFormat(org.objectweb.asm.tree.FieldNode fieldNode) |
static void |
formatAnnotationNodeNameValuePairValue(java.lang.Object value,
java.lang.StringBuilder s) |
static void |
generateInstructionsToUnpackArrayAccordingToDescriptor(org.objectweb.asm.MethodVisitor mv,
java.lang.String toCallDescriptor,
int arrayVariableIndex)
Generate the instructions in the specified method visitor to unpack an assumed array (on top of the stack) according to the
specified descriptor.
|
static java.lang.String |
getDispatcherName(java.lang.String name,
java.lang.String versionstamp) |
static java.lang.String |
getExecutorName(java.lang.String name,
java.lang.String versionstamp)
Generate the name for the executor class.
|
static java.lang.String |
getInterfaceName(java.lang.String owner) |
static int |
getParameterCount(java.lang.String methodDescriptor)
Return the number of parameters in the descriptor.
|
static java.lang.String |
getParamSequence(java.lang.String descriptor)
Return a simple sequence for the descriptor where type references are collapsed to 'O', so (IILjava/lang/String;Z) will
return IIOZ.
|
static java.lang.String |
getProtectedFieldGetterName(java.lang.String fieldname) |
static java.lang.String |
getProtectedFieldSetterName(java.lang.String fieldname) |
static Utils.ReturnType |
getReturnTypeDescriptor(java.lang.String methodDescriptor)
Discover the descriptor for the return type.
|
static int |
getSize(java.lang.String descriptor)
Compute the size required for a specific method descriptor.
|
static void |
insertBoxInsns(org.objectweb.asm.MethodVisitor mv,
char ch) |
static void |
insertBoxInsns(org.objectweb.asm.MethodVisitor mv,
java.lang.String type) |
static java.lang.String |
insertExtraParameter(java.lang.String classname,
java.lang.String descriptor) |
static int |
insertPopsForAllParameters(org.objectweb.asm.MethodVisitor mv,
java.lang.String desc)
Looks at the supplied descriptor and inserts enough pops to remove all parameters.
|
static void |
insertUnboxInsns(org.objectweb.asm.MethodVisitor mv,
char ch,
boolean isObject) |
static void |
insertUnboxInsnsIfNecessary(org.objectweb.asm.MethodVisitor mv,
java.lang.String type,
boolean isObject) |
static boolean |
isAssignableFrom(java.lang.String lookingFor,
TypeDescriptor candidate) |
static boolean |
isAssignableFrom(TypeRegistry reg,
java.lang.Class<?> clazz,
java.lang.String lookingFor) |
static boolean |
isConvertableFrom(java.lang.Class<?> targetType,
java.lang.Class<?> sourceType) |
static boolean |
isInitializer(java.lang.String membername) |
static boolean |
isObjectIsUnboxableTo(java.lang.Class<?> possiblyBoxedType,
char primitive) |
static byte[] |
load(java.io.File file) |
static byte[] |
loadBytesFromStream(java.io.InputStream stream)
Load all the byte data from an input stream.
|
static byte[] |
loadDottedClassAsBytes(java.lang.ClassLoader loader,
java.lang.String dottedclassname)
Access the specified class as a resource accessible through the specified loader and return the bytes.
|
static byte[] |
loadFromStream(java.io.InputStream stream)
Load the contents of an input stream.
|
static byte[] |
loadSlashedClassAsBytes(java.lang.ClassLoader loader,
java.lang.String slashedclassname)
Access the specified class as a resource accessible through the specified loader and return the bytes.
|
static void |
logAndThrow(java.util.logging.Logger log,
java.lang.String message) |
static int |
makePublicNonFinal(int access)
Modify visibility to be public.
|
static int |
promoteDefaultOrPrivateOrProtectedToPublic(int access) |
static int |
promoteDefaultOrProtectedToPublic(int access)
If the flags indicate it is not public, private or protected, then it is default and make it public.
|
static int |
promoteDefaultOrProtectedToPublic(int access,
boolean isEnum,
java.lang.String name) |
static int |
sizeOf(java.lang.String typeDescriptor)
Return the size of a type.
|
static java.lang.Class<?>[] |
slashedNamesToClasses(java.lang.String[] slashedNames,
java.lang.ClassLoader classLoader) |
static java.lang.Class<?> |
slashedNameToClass(java.lang.String slashedName,
java.lang.ClassLoader classLoader) |
static java.lang.String |
stripFirstParameter(java.lang.String descriptor)
Strip the first parameter out of a method descriptor and return the shortened method descriptor.
|
static java.lang.Class<?> |
toClass(ReloadableType rtype) |
static java.lang.Class<?> |
toClass(org.objectweb.asm.Type type,
java.lang.ClassLoader classLoader)
Convert an asm Type into a corresponding Class object, requires a reference to a ClassLoader to be able to convert classnames
to class objects.
|
static int |
toCombined(int typeRegistryId,
int classId) |
static java.lang.String |
toConstructorDescriptor(java.lang.Class<?>... params) |
static java.lang.String |
toMethodDescriptor(java.lang.reflect.Method m) |
static java.lang.String |
toMethodDescriptor(java.lang.reflect.Method method,
boolean ignoreFirstParameter)
Construct the method descriptor for a method.
|
static java.lang.String |
toOpcodeString(int opcode) |
static java.lang.String |
toPaddedNumber(int value,
int width)
Create the string representation of an integer and pad it to a particular width using leading zeroes.
|
static java.lang.Class<?>[] |
toParamClasses(java.lang.String methodDescriptor,
java.lang.ClassLoader classLoader)
Given a method descriptor, extract the parameter descriptor and convert into corresponding Class objects.
|
static java.lang.String |
toParamDescriptor(java.lang.Class<?>... params)
Create a descriptor for some set of parameter types.
|
static java.lang.Object |
toResultCheckIfNull(java.lang.Object value,
java.lang.String desc)
Convert a value to the requested descriptor.
|
static java.lang.String |
toSuperAccessor(java.lang.String typename,
java.lang.String name) |
static void |
write(java.io.File file,
byte[] data) |
public static java.lang.String encode(long number)
number
- the number to convertpublic static long decode(java.lang.String s)
s
- the string to decodepublic static void addCorrectReturnInstruction(org.objectweb.asm.MethodVisitor mv, Utils.ReturnType returnType, boolean createCast)
mv
- where to visit to append the instructionsreturnType
- return type descriptorcreateCast
- whether to include CHECKCAST instructions for return type valuespublic static int getParameterCount(java.lang.String methodDescriptor)
methodDescriptor
- a method descriptor of the form (Ljava/lang/String;I[[Z)Ipublic static void createLoadsBasedOnDescriptor(org.objectweb.asm.MethodVisitor mv, java.lang.String descriptor, int startindex)
mv
- the method visitor to recieve the load instructionsdescriptor
- the complete method descriptor (eg. "(ILjava/lang/String;)V") - params and return type are skippedstartindex
- the initial index in which to assume the first parameter is storedpublic static void insertUnboxInsnsIfNecessary(org.objectweb.asm.MethodVisitor mv, java.lang.String type, boolean isObject)
public static void insertUnboxInsns(org.objectweb.asm.MethodVisitor mv, char ch, boolean isObject)
public static java.lang.String getParamSequence(java.lang.String descriptor)
descriptor
- method descriptor, for example (IILjava/lang/String;Z)Vpublic static void insertBoxInsns(org.objectweb.asm.MethodVisitor mv, java.lang.String type)
public static void insertBoxInsns(org.objectweb.asm.MethodVisitor mv, char ch)
public static java.lang.String getInterfaceName(java.lang.String owner)
public static void assertSlashed(java.lang.String name)
public static void assertDotted(java.lang.String name)
public static java.lang.String toOpcodeString(int opcode)
public static java.lang.String toParamDescriptor(java.lang.Class<?>... params)
params
- the (possibly null) list of parameters for which to create the descriptorpublic static java.lang.Class<?>[] toParamClasses(java.lang.String methodDescriptor, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException
methodDescriptor
- a method descriptor (e.g (Ljava/lang/String;)I)classLoader
- a class loader that can be used to lookup typesjava.lang.ClassNotFoundException
- if there is a problem finding the Class for a particular name in the descriptorpublic static java.lang.Class<?> toClass(org.objectweb.asm.Type type, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException
type
- the asm TypeclassLoader
- a class loader that can be used to find typesjava.lang.ClassNotFoundException
- if there is a problem finding the Class for the typepublic static java.lang.String toMethodDescriptor(java.lang.reflect.Method method, boolean ignoreFirstParameter)
method
- method for which the descriptor should be createdignoreFirstParameter
- whether to include the first parameter in the output descriptorpublic static void appendDescriptor(java.lang.Class<?> p, java.lang.StringBuilder s)
public static java.lang.String toPaddedNumber(int value, int width)
value
- the value to convert to a stringwidth
- the width (in chars) that the resultant string should bepublic static java.lang.String toMethodDescriptor(java.lang.reflect.Method m)
public static byte[] loadDottedClassAsBytes(java.lang.ClassLoader loader, java.lang.String dottedclassname)
loader
- the classloader against which getResourceAsStream() will be invokeddottedclassname
- the dot separated classname without .class suffixpublic static byte[] loadSlashedClassAsBytes(java.lang.ClassLoader loader, java.lang.String slashedclassname)
loader
- the classloader against which getResourceAsStream() will be invokedslashedclassname
- the dot separated classname without .class suffixpublic static byte[] load(java.io.File file)
public static void write(java.io.File file, byte[] data)
public static byte[] loadBytesFromStream(java.io.InputStream stream)
stream
- thr input stream from which to readpublic static void assertTrue(boolean condition, java.lang.String detail)
public static java.lang.String getDispatcherName(java.lang.String name, java.lang.String versionstamp)
public static java.lang.String getExecutorName(java.lang.String name, java.lang.String versionstamp)
name
- the name prefix for the executor classversionstamp
- the suffix string for the executor class namepublic static java.lang.String stripFirstParameter(java.lang.String descriptor)
descriptor
- method descriptor to be shortenedpublic static Utils.ReturnType getReturnTypeDescriptor(java.lang.String methodDescriptor)
methodDescriptor
- method descriptorpublic static java.lang.String insertExtraParameter(java.lang.String classname, java.lang.String descriptor)
public static void generateInstructionsToUnpackArrayAccordingToDescriptor(org.objectweb.asm.MethodVisitor mv, java.lang.String toCallDescriptor, int arrayVariableIndex)
mv
- the method visitor to receive the unpack instructionstoCallDescriptor
- the descriptor for the method whose parameters describe the array contentsarrayVariableIndex
- index of the array variablepublic static boolean isInitializer(java.lang.String membername)
public static int toCombined(int typeRegistryId, int classId)
public static void logAndThrow(java.util.logging.Logger log, java.lang.String message)
public static java.lang.String dump(java.lang.String slashname, byte[] bytes)
slashname
- the slashed class name (e.g. java/lang/String)bytes
- the bytes to dumppublic static int sizeOf(java.lang.String typeDescriptor)
typeDescriptor
- the descriptor for a single type, may be primitive. For example: I, J, Z, Ljava/lang/String;public static void dumpClass(java.lang.String file, byte[] bytes)
file
- full filename for where to dump the stuff (e.g. c:/temp/Foo.class)bytes
- the bytes to write to the filepublic static java.lang.String toSuperAccessor(java.lang.String typename, java.lang.String name)
public static int getSize(java.lang.String descriptor)
descriptor
- a method descriptor, for example (Ljava/lang/String;ZZ)Vpublic static java.lang.Class<?>[] slashedNamesToClasses(java.lang.String[] slashedNames, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public static java.lang.Class<?> slashedNameToClass(java.lang.String slashedName, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public static java.lang.String fieldNodeFormat(org.objectweb.asm.tree.FieldNode fieldNode)
public static java.lang.String annotationNodeFormat(org.objectweb.asm.tree.AnnotationNode o)
public static void formatAnnotationNodeNameValuePairValue(java.lang.Object value, java.lang.StringBuilder s)
public static java.lang.String fieldNodeFormat(java.util.Collection<org.objectweb.asm.tree.FieldNode> fieldNodes)
public static byte[] loadFromStream(java.io.InputStream stream)
stream
- input stream that contains the bytes to loadpublic static int promoteDefaultOrProtectedToPublic(int access)
access
- incoming access modifierspublic static int promoteDefaultOrProtectedToPublic(int access, boolean isEnum, java.lang.String name)
public static int promoteDefaultOrPrivateOrProtectedToPublic(int access)
public static <T> T[] arrayCopyOf(T[] array, int newSize)
T
- the type of the array entriesarray
- the array to copynewSize
- the size of the new arraypublic static int makePublicNonFinal(int access)
access
- existing accesspublic static java.lang.Class<?> toClass(ReloadableType rtype)
public static boolean isObjectIsUnboxableTo(java.lang.Class<?> possiblyBoxedType, char primitive)
possiblyBoxedType
- a reference type that may be the boxed form of a primitiveprimitive
- the primitive we are looking forpublic static java.lang.Object toResultCheckIfNull(java.lang.Object value, java.lang.String desc)
value
- the valuedesc
- the type the caller would like it to bepublic static java.lang.Object checkCompatibility(TypeRegistry registry, java.lang.Object result, java.lang.String expectedTypeDescriptor)
registry
- the type registry that can be quizzed for type informationresult
- the result we have discovered and are about to return - this is never nullexpectedTypeDescriptor
- the type we are looking for (will be primitive or Ljava/lang/String style)public static boolean isAssignableFrom(TypeRegistry reg, java.lang.Class<?> clazz, java.lang.String lookingFor)
public static boolean isAssignableFrom(java.lang.String lookingFor, TypeDescriptor candidate)
public static int collapseStackToArray(org.objectweb.asm.MethodVisitor mv, java.lang.String desc)
public static int insertPopsForAllParameters(org.objectweb.asm.MethodVisitor mv, java.lang.String desc)
mv
- the method visitor to append instructions todesc
- the method descriptor for the parameter sequence (e.g. (Ljava/lang/String;IZZ)V)public static java.lang.String toConstructorDescriptor(java.lang.Class<?>... params)
public static boolean isConvertableFrom(java.lang.Class<?> targetType, java.lang.Class<?> sourceType)
public static java.lang.String[] discoverInterfaces(byte[] classbytes)
classbytes
- the classfile bytespublic static java.lang.String getProtectedFieldGetterName(java.lang.String fieldname)
public static java.lang.String getProtectedFieldSetterName(java.lang.String fieldname)