Class AsmUtil
java.lang.Object
ru.progrm_jarvis.javacommons.bytecode.asm.AsmUtil
Utility for common ObjectWeb ASM tasks.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSignature ofboolean()methodstatic final StringSignature ofbyte()methodstatic final StringDescriptor ofCallSitestatic final StringInternal name ofCallSitestatic final org.objectweb.asm.TypeASM type ofCallSitestatic final StringSignature ofchar()methodstatic final StringName of constructor methodstatic final StringSignature ofdouble()methodstatic final StringName ofObject.equals(Object)methodstatic final StringSignature offloat()methodstatic final StringName ofObject.hashCode()methodstatic final StringSignature ofint()methodstatic final StringSignature oflong()methodstatic final StringDescriptor ofMethodHandles.Lookupstatic final StringName of inner lookup class.static final StringInternal name ofMethodHandles.Lookupstatic final org.objectweb.asm.TypeASM type ofMethodHandles.Lookupstatic final StringDescriptor ofMethodHandlesstatic final StringInternal name ofMethodHandlesstatic final org.objectweb.asm.TypeASM type ofMethodHandlesstatic final StringDescriptor ofMethodTypestatic final StringInternal name ofMethodTypestatic final org.objectweb.asm.TypeASM type ofMethodTypestatic final StringDescriptor ofObjectarraystatic final StringInternal name ofObjectarraystatic final org.objectweb.asm.TypeASM type ofObjectarraystatic final StringDescriptor ofObjectstatic final StringInternal name ofObjectstatic final StringSignature ofObject()methodstatic final org.objectweb.asm.TypeASM type ofObjectstatic final intResult ofOpcodes.ACC_PUBLICandOpcodes.ACC_FINALflags disjunctionstatic final intResult ofOpcodes.ACC_PUBLIC,Opcodes.ACC_FINALandOpcodes.ACC_SUPERflags disjunctionstatic final intResult ofOpcodes.ACC_PUBLIC,Opcodes.ACC_STATICandOpcodes.ACC_FINALflags disjunctionstatic final StringSignature ofshort()methodstatic final StringName of static initializer methodstatic final StringDescriptor ofStringstatic final StringInternal name ofStringstatic final StringSignature ofString()methodstatic final org.objectweb.asm.TypeASM type ofStringstatic final StringName ofObject.toString()methodstatic final StringSignature ofvoid(boolean)methodstatic final StringSignature ofvoid(byte)methodstatic final StringSignature ofvoid(char)methodstatic final StringSignature ofvoid(double)methodstatic final StringSignature ofvoid(float)methodstatic final StringSignature ofvoid(int)methodstatic final StringSignature ofvoid(long)methodstatic final StringSignature ofvoid()methodstatic final StringSignature ofvoid(short)methodstatic final StringSignature ofvoid(String)method -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddEmptyConstructor(@NonNull org.objectweb.asm.ClassVisitor classVisitor) Adds an empty constructor to the class via its visitor.static voidaddEmptyConstructor(@NonNull org.objectweb.asm.ClassVisitor classVisitor, @NonNull String superClassInternalName) Adds an empty constructor to the class via its visitor.static voidaddLookup(@NonNull org.objectweb.asm.ClassVisitor clazz) Addsthe inner lookup classto the class needed by the JVM via its visitor.static intarrayLoadOpcode(Class<?> loadedComponentType) Gets the array-load-opcodecorresponding to the array of given component type.static intarrayStoreOpcode(Class<?> storedComponentType) Gets the array-store-opcodecorresponding to the array of given component type.static @NotNull StringclassNameToInternalName(@NonNull String className) Gets the internal name (aka VM-name) for the givenClassLoader-unique name.static @NotNull StringinternalNameOf(@NonNull Class<?> type) Gets the internal name (aka VM-name) of the given class.static intloadOpcode(Class<?> loadedType) Gets the load-opcodecorresponding to the given type.static intnonVoidReturnOpcode(Class<?> returnType) Gets the return-opcodecorresponding to the given non-void type.static voidpushCharUnsafely(@NonNull org.objectweb.asm.MethodVisitor method, char value) Adds code to the method which unsafely pushes the givencharvalue onto the stack.static voidpushDouble(@NonNull org.objectweb.asm.MethodVisitor method, double value) Adds code to the method which pushes the givendoublevalue onto the stack.static voidpushFloat(@NonNull org.objectweb.asm.MethodVisitor method, float value) Adds code to the method which pushes the givenfloatvalue onto the stack.static voidpushInt(@NonNull org.objectweb.asm.MethodVisitor method, int value) Adds code to the method which pushes the givenintvalue onto the stack.static voidpushLong(@NonNull org.objectweb.asm.MethodVisitor method, long value) Adds code to the method which pushes the givenlongvalue onto the stack.static intreturnOpcode(Class<?> returnType) Gets the return-opcodecorresponding to the given type.static intstoreOpcode(Class<?> storedType) Gets the store-opcodecorresponding to the given typestatic org.objectweb.asm.MethodVisitorvisitStaticInitializer(@NonNull org.objectweb.asm.ClassVisitor clazz) Visits the class's static initializer method.
-
Field Details
-
OBJECT_TYPE
public static final org.objectweb.asm.Type OBJECT_TYPEASM type ofObject -
OBJECT_ARRAY_TYPE
public static final org.objectweb.asm.Type OBJECT_ARRAY_TYPEASM type ofObjectarray -
STRING_TYPE
public static final org.objectweb.asm.Type STRING_TYPEASM type ofString -
METHOD_HANDLES_TYPE
public static final org.objectweb.asm.Type METHOD_HANDLES_TYPEASM type ofMethodHandles -
LOOKUP_TYPE
public static final org.objectweb.asm.Type LOOKUP_TYPEASM type ofMethodHandles.Lookup -
CALL_SITE_TYPE
public static final org.objectweb.asm.Type CALL_SITE_TYPEASM type ofCallSite -
METHOD_TYPE_TYPE
public static final org.objectweb.asm.Type METHOD_TYPE_TYPEASM type ofMethodType -
STATIC_INITIALIZER_METHOD_NAME
Name of static initializer method- See Also:
-
CONSTRUCTOR_METHOD_NAME
Name of constructor method- See Also:
-
LOOKUP_INNER_CLASS_NAME
Name of inner lookup class.- See Also:
-
HASH_CODE_METHOD_NAME
Name ofObject.hashCode()method- See Also:
-
EQUALS_METHOD_NAME
Name ofObject.equals(Object)method- See Also:
-
TO_STRING_METHOD_NAME
Name ofObject.toString()method- See Also:
-
OBJECT_INTERNAL_NAME
Internal name ofObject -
OBJECT_ARRAY_INTERNAL_NAME
Internal name ofObjectarray -
STRING_INTERNAL_NAME
Internal name ofString -
METHOD_HANDLES_INTERNAL_NAME
Internal name ofMethodHandles -
LOOKUP_INTERNAL_NAME
Internal name ofMethodHandles.Lookup -
CALL_SITE_INTERNAL_NAME
Internal name ofCallSite -
METHOD_TYPE_INTERNAL_NAME
Internal name ofMethodType -
OBJECT_DESCRIPTOR
Descriptor ofObject -
OBJECT_ARRAY_DESCRIPTOR
Descriptor ofObjectarray -
STRING_DESCRIPTOR
Descriptor ofString -
METHOD_HANDLES_DESCRIPTOR
Descriptor ofMethodHandles -
LOOKUP_DESCRIPTOR
Descriptor ofMethodHandles.Lookup -
CALL_SITE_DESCRIPTOR
Descriptor ofCallSite -
METHOD_TYPE_DESCRIPTOR
Descriptor ofMethodType -
VOID_METHOD_DESCRIPTOR
Signature ofvoid()method -
BOOLEAN_METHOD_DESCRIPTOR
Signature ofboolean()method -
BYTE_METHOD_DESCRIPTOR
Signature ofbyte()method -
SHORT_METHOD_DESCRIPTOR
Signature ofshort()method -
INT_METHOD_DESCRIPTOR
Signature ofint()method -
LONG_METHOD_DESCRIPTOR
Signature oflong()method -
FLOAT_METHOD_DESCRIPTOR
Signature offloat()method -
DOUBLE_METHOD_DESCRIPTOR
Signature ofdouble()method -
CHAR_METHOD_DESCRIPTOR
Signature ofchar()method -
OBJECT_METHOD_DESCRIPTOR
Signature ofObject()method -
STRING_METHOD_DESCRIPTOR
Signature ofString()method -
VOID_BOOLEAN_METHOD_DESCRIPTOR
Signature ofvoid(boolean)method -
VOID_BYTE_METHOD_DESCRIPTOR
Signature ofvoid(byte)method -
VOID_SHORT_METHOD_DESCRIPTOR
Signature ofvoid(short)method -
VOID_INT_METHOD_DESCRIPTOR
Signature ofvoid(int)method -
VOID_LONG_METHOD_DESCRIPTOR
Signature ofvoid(long)method -
VOID_FLOAT_METHOD_DESCRIPTOR
Signature ofvoid(float)method -
VOID_DOUBLE_METHOD_DESCRIPTOR
Signature ofvoid(double)method -
VOID_CHAR_METHOD_DESCRIPTOR
Signature ofvoid(char)method -
VOID_STRING_METHOD_DESCRIPTOR
Signature ofvoid(String)method -
OPCODES_ACC_PUBLIC_FINAL
public static final int OPCODES_ACC_PUBLIC_FINALResult ofOpcodes.ACC_PUBLICandOpcodes.ACC_FINALflags disjunction- See Also:
-
OPCODES_ACC_PUBLIC_STATIC_FINAL
public static final int OPCODES_ACC_PUBLIC_STATIC_FINALResult ofOpcodes.ACC_PUBLIC,Opcodes.ACC_STATICandOpcodes.ACC_FINALflags disjunction- See Also:
-
OPCODES_ACC_PUBLIC_FINAL_SUPER
public static final int OPCODES_ACC_PUBLIC_FINAL_SUPERResult ofOpcodes.ACC_PUBLIC,Opcodes.ACC_FINALandOpcodes.ACC_SUPERflags disjunction- See Also:
-
-
Method Details
-
classNameToInternalName
Gets the internal name (aka VM-name) for the givenClassLoader-unique name.- Parameters:
className- name of the class- Returns:
- internal name corresponding to the given class name
- See Also:
-
internalNameOf
Gets the internal name (aka VM-name) of the given class.- Parameters:
type- class whose internal name should be resolved- Returns:
- internal name of the given class
-
visitStaticInitializer
public static org.objectweb.asm.MethodVisitor visitStaticInitializer(@NonNull @NonNull org.objectweb.asm.ClassVisitor clazz) Visits the class's static initializer method.- Parameters:
clazz- visitor of the class- Returns:
- static initializer block of the class
-
addLookup
public static void addLookup(@NonNull @NonNull org.objectweb.asm.ClassVisitor clazz) Addsthe inner lookup classto the class needed by the JVM via its visitor.- Parameters:
clazz- visitor of the class
-
addEmptyConstructor
public static void addEmptyConstructor(@NonNull @NonNull org.objectweb.asm.ClassVisitor classVisitor, @NonNull @NonNull String superClassInternalName) Adds an empty constructor to the class via its visitor.- Parameters:
classVisitor- visitor of the class modifiedsuperClassInternalName- internal name of the super-class whose constructor should be invoked
-
addEmptyConstructor
public static void addEmptyConstructor(@NonNull @NonNull org.objectweb.asm.ClassVisitor classVisitor) Adds an empty constructor to the class via its visitor.- Parameters:
classVisitor- visitor of the class modified- See Also:
-
returnOpcode
Gets the return-opcodecorresponding to the given type.- Parameters:
returnType- type of the value for which to get the return-opcode- Returns:
- return-opcode corresponding to the given type
-
nonVoidReturnOpcode
Gets the return-opcodecorresponding to the given non-void type.- Parameters:
returnType- type of the value for which to get the return-opcode- Returns:
- return-opcode corresponding to the given type
- Throws:
IllegalArgumentException- ifreturnTypeis ofvoidtype
-
loadOpcode
Gets the load-opcodecorresponding to the given type.- Parameters:
loadedType- type of the value for which to get the load-opcode- Returns:
- load-opcode corresponding to the given type
-
arrayLoadOpcode
Gets the array-load-opcodecorresponding to the array of given component type.- Parameters:
loadedComponentType- component type of the array for which to get the array-load-opcode- Returns:
- array-load-opcode corresponding to the given array component type
-
storeOpcode
Gets the store-opcodecorresponding to the given type- Parameters:
storedType- type of the value for which to get the store-opcode- Returns:
- store-opcode corresponding to the given type
-
arrayStoreOpcode
Gets the array-store-opcodecorresponding to the array of given component type.- Parameters:
storedComponentType- component type of the array for which to get the array-store-opcode- Returns:
- array-store-opcode corresponding to the given array component type
-
pushInt
public static void pushInt(@NonNull @NonNull org.objectweb.asm.MethodVisitor method, int value) Adds code to the method which pushes the givenintvalue onto the stack.- Parameters:
method- method visitor used for appending code to the methodvalue- value to get pushed onto the stack
-
pushLong
public static void pushLong(@NonNull @NonNull org.objectweb.asm.MethodVisitor method, long value) Adds code to the method which pushes the givenlongvalue onto the stack.- Parameters:
method- method visitor used for appending code to the methodvalue- value to get pushed onto the stack
-
pushFloat
public static void pushFloat(@NonNull @NonNull org.objectweb.asm.MethodVisitor method, float value) Adds code to the method which pushes the givenfloatvalue onto the stack.- Parameters:
method- method visitor used for appending code to the methodvalue- value to get pushed onto the stack
-
pushDouble
public static void pushDouble(@NonNull @NonNull org.objectweb.asm.MethodVisitor method, double value) Adds code to the method which pushes the givendoublevalue onto the stack.- Parameters:
method- method visitor used for appending code to the methodvalue- value to get pushed onto the stack
-
pushCharUnsafely
public static void pushCharUnsafely(@NonNull @NonNull org.objectweb.asm.MethodVisitor method, char value) Adds code to the method which unsafely pushes the givencharvalue onto the stack. The unsafety of this operation is in the fact that for some chars ([(char) 128; (char) 255] and [(char) 32768; (char) 65535) negativeints will be pushed onto the stack thus resulting incorrect values when casting those to signed numeric types. This yet might be a micro-optimization in some cases when there is a guarantee that the pushed value will only be treated aschar(such as passing it toStringBuilder.append(char).- Parameters:
method- method visitor used for appending code to the methodvalue- value to get pushed onto the stack- See Also:
-