Package com.ibm.wala.shrike.shrikeBT
Class Util
- java.lang.Object
-
- com.ibm.wala.shrike.shrikeBT.Util
-
public final class Util extends java.lang.ObjectThis class contains miscellaneous useful functions.In the documentation below, we refer to a 'Java class name'. These are formatted according to the rules for Class.forName() and Class.getName(). A Java class name must use '$' to separate inner class names from their containing class. There is no way to for Shrike to disambiguate 'A.B' otherwise.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.ibm.wala.util.collections.Pair<boolean[],boolean[]>computeBasicBlocks(IInstruction[] instructions, ExceptionHandler[][] handlers)static java.lang.StringcomputeSignature(java.lang.Class<?>[] params, java.lang.Class<?> result)Given a Java Method, compute the VM-style type signature.static voiderror(java.lang.String s)General "print an error" routine.static java.lang.reflect.MethodfindMethod(java.lang.Class<?> c, java.lang.String name)static java.lang.reflect.MethodfindMethod(java.lang.Class<?> c, java.lang.String name, java.lang.Class<?>[] paramTypes)static intgetParamsCount(java.lang.String type)Compute the number of parameters given by method signature "type".static java.lang.String[]getParamsTypes(java.lang.String thisClassType, java.lang.String type)Extract the types of the parameters given by method signature "type".static java.lang.String[]getParamsTypesInLocals(java.lang.String thisClassType, java.lang.String type)Compute the types of the local variables on entry to a method.static intgetParamsWordSize(java.lang.String type)Compute the total number of JVM "stack words" occupied by the method parameters for method signature "type".static java.lang.StringgetReturnType(java.lang.String s)Get the return type from a method signature.static java.lang.StringgetStackType(java.lang.String t)Compute the promoted type that the JVM uses to manipulate values of type "t" on its working stack.static bytegetWordSize(java.lang.String s)static booleanisArrayType(java.lang.String t)static booleanisPrimitiveType(java.lang.String t)static java.lang.StringmakeArray(java.lang.String t)Compute the type "array of t".static java.lang.StringmakeClass(java.lang.String t)Convert a JVM type name back into a Java class name.static GetInstructionmakeGet(java.lang.Class<?> c, java.lang.String name)Make an Instruction which loads the value of a field, given its name and Java Class.static InvokeInstructionmakeInvoke(java.lang.Class<?> c, java.lang.String name)Make an Instruction which calls a method, given its name and Java Class.static InvokeInstructionmakeInvoke(java.lang.Class<?> c, java.lang.String name, java.lang.Class<?>[] paramTypes)Make an Instruction which calls a method, given its name, Java Class, and a list of parameter classes to use for overload resolution.static PutInstructionmakePut(java.lang.Class<?> c, java.lang.String name)Make an Instruction which stores the value of a field, given its name and Java Class.static java.lang.StringmakeType(java.lang.Class<?> c)Compute the JVM type name for an actual Java class.static java.lang.StringmakeType(java.lang.String c)Convert a fully-qualified Java class name ('.' separated) into an internal JVM type name ('/' separated, starting with 'L' and ending with ';').static java.lang.StringmakeTypeAll(java.lang.String c)Convert a fully-qualified Java type name (either primitive or class name, '.' separated) into an internal JVM type name (one letter for primitive and '/' separated, starting with 'L' and ending with ';' for class name).static byte[]readFully(java.io.InputStream s)static voidreadFully(java.io.InputStream s, byte[] bytes)
-
-
-
Method Detail
-
getWordSize
public static byte getWordSize(java.lang.String s)
- Returns:
- the JVM "stack word size" for the given JVM type
- Throws:
java.lang.IllegalArgumentException- if s is null
-
getParamsWordSize
public static int getParamsWordSize(java.lang.String type) throws java.lang.IllegalArgumentExceptionCompute the total number of JVM "stack words" occupied by the method parameters for method signature "type". Any "this" parameter is not included.- Throws:
java.lang.IllegalArgumentException- if type is null
-
makeType
public static java.lang.String makeType(java.lang.String c)
Convert a fully-qualified Java class name ('.' separated) into an internal JVM type name ('/' separated, starting with 'L' and ending with ';').- Throws:
java.lang.IllegalArgumentException- if c is null
-
makeTypeAll
public static java.lang.String makeTypeAll(java.lang.String c)
Convert a fully-qualified Java type name (either primitive or class name, '.' separated) into an internal JVM type name (one letter for primitive and '/' separated, starting with 'L' and ending with ';' for class name).
-
makeClass
public static java.lang.String makeClass(java.lang.String t) throws java.lang.IllegalArgumentExceptionConvert a JVM type name back into a Java class name.- Throws:
java.lang.IllegalArgumentException- if t is null
-
makeType
public static java.lang.String makeType(java.lang.Class<?> c)
Compute the JVM type name for an actual Java class. Names such as "int", "void", etc are also converted to their JVM type names.- Throws:
java.lang.IllegalArgumentException- if c is null
-
getParamsCount
public static int getParamsCount(java.lang.String type) throws java.lang.IllegalArgumentExceptionCompute the number of parameters given by method signature "type". Any "this" parameter is not included.- Throws:
java.lang.IllegalArgumentException- if type == null
-
getParamsTypes
public static java.lang.String[] getParamsTypes(java.lang.String thisClassType, java.lang.String type) throws java.lang.IllegalArgumentExceptionExtract the types of the parameters given by method signature "type".- Parameters:
thisClassType- null if the method is static, otherwise the type of "this"- Returns:
- an array of the parameter types in order, including "this" as the first parameter if thisClassType was non-null
- Throws:
java.lang.IllegalArgumentException- if type == null
-
getParamsTypesInLocals
public static java.lang.String[] getParamsTypesInLocals(java.lang.String thisClassType, java.lang.String type) throws java.lang.IllegalArgumentExceptionCompute the types of the local variables on entry to a method. Similar to "getParamsTypes" except null array entries are inserted to account for unused local variables because of 2-word parameter values.- Throws:
java.lang.IllegalArgumentException- if type == null
-
getStackType
public static java.lang.String getStackType(java.lang.String t)
Compute the promoted type that the JVM uses to manipulate values of type "t" on its working stack.- Throws:
java.lang.IllegalArgumentException- if t is null
-
makeArray
public static java.lang.String makeArray(java.lang.String t)
Compute the type "array of t".
-
isArrayType
public static boolean isArrayType(java.lang.String t)
- Returns:
- true iff t is an array type
-
isPrimitiveType
public static boolean isPrimitiveType(java.lang.String t)
- Returns:
- true iff t is a primitive type
-
getReturnType
public static java.lang.String getReturnType(java.lang.String s)
Get the return type from a method signature.- Throws:
java.lang.IllegalArgumentException- if s is null
-
error
public static void error(java.lang.String s)
General "print an error" routine.
-
computeSignature
public static java.lang.String computeSignature(java.lang.Class<?>[] params, java.lang.Class<?> result) throws java.lang.IllegalArgumentExceptionGiven a Java Method, compute the VM-style type signature.- Throws:
java.lang.IllegalArgumentException- if params == null
-
makeGet
public static GetInstruction makeGet(java.lang.Class<?> c, java.lang.String name)
Make an Instruction which loads the value of a field, given its name and Java Class. The field type is obtained using reflection.- Throws:
java.lang.IllegalArgumentException- if c is null
-
makePut
public static PutInstruction makePut(java.lang.Class<?> c, java.lang.String name)
Make an Instruction which stores the value of a field, given its name and Java Class. The field type is obtained using reflection.- Throws:
java.lang.IllegalArgumentException- if c is null
-
findMethod
public static java.lang.reflect.Method findMethod(java.lang.Class<?> c, java.lang.String name)
-
findMethod
public static java.lang.reflect.Method findMethod(java.lang.Class<?> c, java.lang.String name, java.lang.Class<?>[] paramTypes)
-
makeInvoke
public static InvokeInstruction makeInvoke(java.lang.Class<?> c, java.lang.String name, java.lang.Class<?>[] paramTypes)
Make an Instruction which calls a method, given its name, Java Class, and a list of parameter classes to use for overload resolution. Method information is obtained using reflection.- Throws:
java.lang.IllegalArgumentException- if name is null
-
makeInvoke
public static InvokeInstruction makeInvoke(java.lang.Class<?> c, java.lang.String name)
Make an Instruction which calls a method, given its name and Java Class. Method information is obtained using reflection. If there is more than one method with the given name, an error will be thrown.- Throws:
java.lang.IllegalArgumentException- if name is null
-
readFully
public static void readFully(java.io.InputStream s, byte[] bytes) throws java.lang.IllegalArgumentException, java.lang.IllegalArgumentException, java.io.IOException- Throws:
java.lang.IllegalArgumentExceptionjava.io.IOException
-
readFully
public static byte[] readFully(java.io.InputStream s) throws java.io.IOException- Throws:
java.io.IOException
-
computeBasicBlocks
public static com.ibm.wala.util.collections.Pair<boolean[],boolean[]> computeBasicBlocks(IInstruction[] instructions, ExceptionHandler[][] handlers)
-
-