Class Util
java.lang.Object
com.ibm.wala.shrike.shrikeBT.Util
This 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
Modifier and TypeMethodDescriptionstatic Pair<boolean[], boolean[]> computeBasicBlocks(IInstruction[] instructions, ExceptionHandler[][] handlers) static StringcomputeSignature(Class<?>[] params, Class<?> result) Given a Java Method, compute the VM-style type signature.static voidGeneral "print an error" routine.static MethodfindMethod(Class<?> c, String name) static MethodfindMethod(Class<?> c, String name, Class<?>[] paramTypes) static intgetParamsCount(String type) Compute the number of parameters given by method signature "type".static String[]getParamsTypes(String thisClassType, String type) Extract the types of the parameters given by method signature "type".static String[]getParamsTypesInLocals(String thisClassType, String type) Compute the types of the local variables on entry to a method.static intgetParamsWordSize(String type) Compute the total number of JVM "stack words" occupied by the method parameters for method signature "type".static StringGet the return type from a method signature.static StringCompute the promoted type that the JVM uses to manipulate values of type "t" on its working stack.static bytestatic booleanstatic booleanstatic StringCompute the type "array of t".static StringConvert a JVM type name back into a Java class name.static GetInstructionMake an Instruction which loads the value of a field, given its name and Java Class.static InvokeInstructionmakeInvoke(Class<?> c, String name) Make an Instruction which calls a method, given its name and Java Class.static InvokeInstructionmakeInvoke(Class<?> c, String name, 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 PutInstructionMake an Instruction which stores the value of a field, given its name and Java Class.static StringCompute the JVM type name for an actual Java class.static StringConvert a fully-qualified Java class name ('.' separated) into an internal JVM type name ('/' separated, starting with 'L' and ending with ';').static StringConvert 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[]static voidreadFully(InputStream s, byte[] bytes)
-
Method Details
-
getWordSize
- Returns:
- the JVM "stack word size" for the given JVM type
- Throws:
IllegalArgumentException- if s is null
-
getParamsWordSize
Compute the total number of JVM "stack words" occupied by the method parameters for method signature "type". Any "this" parameter is not included.- Throws:
IllegalArgumentException- if type is null
-
makeType
Convert a fully-qualified Java class name ('.' separated) into an internal JVM type name ('/' separated, starting with 'L' and ending with ';').- Throws:
IllegalArgumentException- if c is null
-
makeTypeAll
-
makeClass
Convert a JVM type name back into a Java class name.- Throws:
IllegalArgumentException- if t is null
-
makeType
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:
IllegalArgumentException- if c is null
-
getParamsCount
Compute the number of parameters given by method signature "type". Any "this" parameter is not included.- Throws:
IllegalArgumentException- if type == null
-
getParamsTypes
public static String[] getParamsTypes(String thisClassType, String type) throws IllegalArgumentException Extract 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:
IllegalArgumentException- if type == null
-
getParamsTypesInLocals
public static String[] getParamsTypesInLocals(String thisClassType, String type) throws IllegalArgumentException Compute 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:
IllegalArgumentException- if type == null
-
getStackType
Compute the promoted type that the JVM uses to manipulate values of type "t" on its working stack.- Throws:
IllegalArgumentException- if t is null
-
makeArray
-
isArrayType
- Returns:
- true iff t is an array type
-
isPrimitiveType
- Returns:
- true iff t is a primitive type
-
getReturnType
Get the return type from a method signature.- Throws:
IllegalArgumentException- if s is null
-
error
General "print an error" routine. -
computeSignature
public static String computeSignature(Class<?>[] params, Class<?> result) throws IllegalArgumentException Given a Java Method, compute the VM-style type signature.- Throws:
IllegalArgumentException- if params == null
-
makeGet
Make an Instruction which loads the value of a field, given its name and Java Class. The field type is obtained using reflection.- Throws:
IllegalArgumentException- if c is null
-
makePut
Make an Instruction which stores the value of a field, given its name and Java Class. The field type is obtained using reflection.- Throws:
IllegalArgumentException- if c is null
-
findMethod
-
findMethod
-
makeInvoke
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:
IllegalArgumentException- if name is null
-
makeInvoke
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:
IllegalArgumentException- if name is null
-
readFully
public static void readFully(InputStream s, byte[] bytes) throws IllegalArgumentException, IllegalArgumentException, IOException - Throws:
IllegalArgumentExceptionIOException
-
readFully
- Throws:
IOException
-
computeBasicBlocks
public static Pair<boolean[], boolean[]> computeBasicBlocks(IInstruction[] instructions, ExceptionHandler[][] handlers)
-