Class Util

java.lang.Object
com.ibm.wala.shrike.shrikeBT.Util

public final class Util extends Object
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 Details

    • getWordSize

      public static byte getWordSize(String s)
      Returns:
      the JVM "stack word size" for the given JVM type
      Throws:
      IllegalArgumentException - if s is null
    • getParamsWordSize

      public static int getParamsWordSize(String type) throws IllegalArgumentException
      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

      public static String makeType(String c)
      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

      public static String makeTypeAll(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 String makeClass(String t) throws IllegalArgumentException
      Convert a JVM type name back into a Java class name.
      Throws:
      IllegalArgumentException - if t is null
    • makeType

      public static String makeType(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:
      IllegalArgumentException - if c is null
    • getParamsCount

      public static int getParamsCount(String type) throws IllegalArgumentException
      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

      public static String getStackType(String t)
      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

      public static String makeArray(String t)
      Compute the type "array of t".
    • isArrayType

      public static boolean isArrayType(String t)
      Returns:
      true iff t is an array type
    • isPrimitiveType

      public static boolean isPrimitiveType(String t)
      Returns:
      true iff t is a primitive type
    • getReturnType

      public static String getReturnType(String s)
      Get the return type from a method signature.
      Throws:
      IllegalArgumentException - if s is null
    • error

      public static void error(String s)
      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

      public static GetInstruction makeGet(Class<?> c, 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:
      IllegalArgumentException - if c is null
    • makePut

      public static PutInstruction makePut(Class<?> c, 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:
      IllegalArgumentException - if c is null
    • findMethod

      public static Method findMethod(Class<?> c, String name)
    • findMethod

      public static Method findMethod(Class<?> c, String name, Class<?>[] paramTypes)
    • makeInvoke

      public static InvokeInstruction makeInvoke(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. Method information is obtained using reflection.
      Throws:
      IllegalArgumentException - if name is null
    • makeInvoke

      public static InvokeInstruction makeInvoke(Class<?> c, 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:
      IllegalArgumentException - if name is null
    • readFully

      public static void readFully(InputStream s, byte[] bytes) throws IllegalArgumentException, IllegalArgumentException, IOException
      Throws:
      IllegalArgumentException
      IOException
    • readFully

      public static byte[] readFully(InputStream s) throws IOException
      Throws:
      IOException
    • computeBasicBlocks

      public static Pair<boolean[],boolean[]> computeBasicBlocks(IInstruction[] instructions, ExceptionHandler[][] handlers)