abc.soot.util
Class Restructure

java.lang.Object
  extended by abc.soot.util.Restructure

public class Restructure
extends java.lang.Object

This class contains a variety of helper methods to restructure Soot method Bodies.

Author:
Laurie Hendren, Ondrej Lhotak, Jennifer Lhotak, Sascha Kuzins, Ganesh Sittampalam

Nested Class Summary
static class Restructure.JavaTypeInfo
          This class helps implement boxing.
 
Constructor Summary
Restructure()
           
 
Method Summary
static Local addParameterToMethod(SootMethod method, Type type, java.lang.String suggestedName)
          Adds a new parameter to a method and creates the matching identity statement.
static Stmt findFirstRealStmt(SootMethod m, Chain units)
          Given a Chain for the body of a method, find the first "real" stmt (i.e. not an identity stmt or the copy of "this" we often make) and return a reference to it.
static Stmt findFirstRealStmtOrNop(SootMethod m, Chain units)
           
static InvokeStmt findInitStmt(Chain units)
          Given a Chain for a body of an method, find the call to the corresponding to either a this() or super() call.
static AssignStmt getEquivAssignStmt(SootMethod m, InvokeStmt stmt)
           
static IdentityStmt getParameterIdentityStatement(SootMethod method, int arg)
          Retrieves the identity statement of the argument at position arg
static Local getThisLocal(SootMethod m)
          Restructure the method to place a copy of 'this' in a new local variable.
static ConstructorInliningMap inlineThisCall(SootMethod method)
          inline a call to this() if one exists, return a ConstructorInliningMap if an inlining was done, null otherwise (no this() to inline).
static void insertBoxingCast(Body body, AssignStmt stmt, boolean allowBoxing)
          Converts the assignment statement into a sequence of statements performing a typecast.
static boolean isBaseClass(SootClass baseClass, SootClass subClass)
           
static void reset()
           
static void resetTrapsEnd(Body b, Stmt oldend, Stmt newend)
          update all traps that used to end at oldend to now end at newend
static void resetTrapsStart(Body b, Stmt oldstart, Stmt newstart)
          update all traps that used to start at oldstart to now start at newstart
static Stmt restructureReturn(SootMethod method)
          Given a SootMethod, restructure its body so that the body ends with L1:nop; return; or L1:nop; return();.
static void validateMethod(SootMethod method)
          Sanity check for methods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Restructure

public Restructure()
Method Detail

reset

public static void reset()

findInitStmt

public static InvokeStmt findInitStmt(Chain units)
Given a Chain for a body of an method, find the call to the corresponding to either a this() or super() call. Check that there is exactly one such , otherwise throw a InternalCompilerError. Return the Stmt.


findFirstRealStmt

public static Stmt findFirstRealStmt(SootMethod m,
                                     Chain units)
Given a Chain for the body of a method, find the first "real" stmt (i.e. not an identity stmt or the copy of "this" we often make) and return a reference to it.


findFirstRealStmtOrNop

public static Stmt findFirstRealStmtOrNop(SootMethod m,
                                          Chain units)

resetTrapsEnd

public static void resetTrapsEnd(Body b,
                                 Stmt oldend,
                                 Stmt newend)
update all traps that used to end at oldend to now end at newend


resetTrapsStart

public static void resetTrapsStart(Body b,
                                   Stmt oldstart,
                                   Stmt newstart)
update all traps that used to start at oldstart to now start at newstart


restructureReturn

public static Stmt restructureReturn(SootMethod method)
Given a SootMethod, restructure its body so that the body ends with L1:nop; return; or L1:nop; return();. Rewire all other returns in the body to assign to and goto L1. Return a reference to the nop at L1.


inlineThisCall

public static ConstructorInliningMap inlineThisCall(SootMethod method)
inline a call to this() if one exists, return a ConstructorInliningMap if an inlining was done, null otherwise (no this() to inline).


getThisLocal

public static Local getThisLocal(SootMethod m)
Restructure the method to place a copy of 'this' in a new local variable. Why is this useful? The local bound by the relevant identity statement will always point to local variable slot 0 (ignoring ITD stuff), which will always be 'this' at method entry However, optimised bytecode might reuse slot 0 at a later point, and we want to be sure we really have a handle on the value of 'this', not whatever it gets reused for later (which might even be the wrong type). UPDATE: Experiments show that the this-local never changes throughout the method, even if the byte-code assigns to slot 0. In this case, Jimple creates a new local to assign to.


getEquivAssignStmt

public static AssignStmt getEquivAssignStmt(SootMethod m,
                                            InvokeStmt stmt)

validateMethod

public static void validateMethod(SootMethod method)
Sanity check for methods. Checks for: - @this identity statement as the first statement - parameter identity statements in the right order for all parameters

Parameters:
method -

insertBoxingCast

public static void insertBoxingCast(Body body,
                                    AssignStmt stmt,
                                    boolean allowBoxing)
Converts the assignment statement into a sequence of statements performing a typecast. Boxes/unboxes if the assignment is from/to an Object to/from a simple type.

Parameters:
body -
stmt -

getParameterIdentityStatement

public static IdentityStmt getParameterIdentityStatement(SootMethod method,
                                                         int arg)
Retrieves the identity statement of the argument at position arg

Parameters:
method -
arg -
Returns:

addParameterToMethod

public static Local addParameterToMethod(SootMethod method,
                                         Type type,
                                         java.lang.String suggestedName)
Adds a new parameter to a method and creates the matching identity statement. Returns the local of the newly created parameter.

Parameters:
method -
type -
suggestedName -
Returns:

isBaseClass

public static boolean isBaseClass(SootClass baseClass,
                                  SootClass subClass)