[Soot-list] A BUG about JimpleConstructorFolder and Line number or any options I did not turn on?

Eric Bodden eric.bodden at mail.mcgill.ca
Mon Apr 9 20:36:31 EDT 2007


Thanks Peng.

I will incorporate parts of the patch tomorrow. Keeping track of hash
codes makes little sense in a general setting. So this is something
you will still have to keep modified in your version. Or,
alternatively, try to look out for another solution. None of the
statements and expressions implement hashCode() and they shouldn't
because equality on statements and expressions makes most often no
sense. So internally in Soot we usually keep maps between expressions
or statements whenever we need to track them.

Eric

On 09/04/07, Peng Li <lipeng360 at gmail.com> wrote:
> HI Chris,
> This is the diff result,
>
> Cheers
> Peng
>
> ------------------
> $ diff -u JimpleConstructorFolder.java  ModifiedJimpleConstructorFolder.java
> --- JimpleConstructorFolder.java        Mon Apr  9 17:28:49 2007
> +++ ModifiedJimpleConstructorFolder.java        Mon Apr  9 17:28:40 2007
> @@ -1,16 +1,17 @@
> -package soot.jimple.toolkits.base;
>  import soot.options.*;
>
>  import soot.*;
>  import soot.toolkits.scalar.*;
>  import soot.jimple.*;
> +import soot.jimple.internal.JNewExpr;
>  import soot.toolkits.graph.*;
>  import soot.grimp.*;
>  import soot.util.*;
>  import java.util.*;
> +
>  import soot.tagkit.*;
>
> -public class JimpleConstructorFolder extends BodyTransformer
> +public class ModifiedJimpleConstructorFolder extends BodyTransformer
>  {
>      //public JimpleConstructorFolder( Singletons.Global g ) {}
>      //public static JimpleConstructorFolder v() { return
> G.v().JimpleConstructorFolder(); }
> @@ -17,13 +18,15 @@
>
>      /** This method pushes all newExpr down to be the stmt directly
> before every
>       * invoke of the init */
> +       static Vector NewOldHashCode = new Vector();
> +
>      public void internalTransform(Body b, String phaseName, Map options)
>      {
>          JimpleBody body = (JimpleBody)b;
> -
> -        if(Options.v().verbose())
> +        ClassMember cm = body.getMethod();
> +        /*if(Options.v().verbose())
>              G.v().out.println("[" + body.getMethod().getName() +
> -                "] Folding Jimple constructors...");
> +                "] Folding Jimple constructors...");*/
>
>          Chain units = body.getUnits();
>          List stmtList = new ArrayList();
> @@ -61,15 +64,25 @@
>              //check if very next statement is invoke -->
>              //this indicates there is no control flow between
>              //new and invoke and should do nothing
> +
>              if (nextStmtIt.hasNext()){
>                  Stmt next = (Stmt)nextStmtIt.next();
> -                if (next instanceof InvokeStmt){
> +                if (next instanceof InvokeStmt)
> +                {
>                      InvokeStmt invoke = (InvokeStmt)next;
>
>                      if (invoke.getInvokeExpr() instanceof SpecialInvokeExpr &&
> -
> invoke.getInvokeExpr().getMethodRef().name().equals(SootMethod.constructorName))
> {
> +
> invoke.getInvokeExpr().getMethodRef().name().equals(SootMethod.constructorName))
> +                    {
>                          SpecialInvokeExpr invokeExpr =
> (SpecialInvokeExpr)invoke.getInvokeExpr();
> -                        if (invokeExpr.getBase() == lhs){
> +                        if (invokeExpr.getBase() == lhs)
> +                        {
> +                            NewExprWithHashCode exprcode = new
> NewExprWithHashCode();
> +                            JNewExpr newexpr=(JNewExpr)
> ((AssignStmt)s).getRightOp();
> +
> exprcode.SetNewExprWithHashCode((AssignStmt)s, newexpr.hashCode(),
> newexpr.hashCode(), invoke, cm.getDeclaringClass().toString(),
> body.getMethod(), getLineNumber(s));
> +
> +                            // System.out.println
> ("******"+newexpr.hashCode()+"  "+newexpr +"*****"+s.hashCode()+"
> "+s);
> +                            NewOldHashCode.add(exprcode);
>                              continue;
>                          }
>                      }
> @@ -91,18 +104,29 @@
>                    lhs != ((SpecialInvokeExpr)is.getInvokeExpr()).getBase())
>                      continue;
>
> -             //make a new one here
> -              AssignStmt constructStmt = Jimple.v().newAssignStmt
> -                (((DefinitionStmt)s).getLeftOp(),
> ((DefinitionStmt)s).getRightOp());
> -              constructStmt.setRightOp
> -                (Jimple.v().newNewExpr
> -                 (((NewExpr)rhs).getBaseType()));
> +             //make a new stmt here
> +              AssignStmt constructStmt =
> Jimple.v().newAssignStmt(((DefinitionStmt)s).getLeftOp(),
> ((DefinitionStmt)s).getRightOp());
> +              LineNumberTag tag =
> (LineNumberTag)s.getTag("LineNumberTag");  // add
> +              constructStmt.addTag(tag);
> +              constructStmt.setRightOp(Jimple.v().newNewExpr(((NewExpr)rhs).getBaseType()));
>                MadeNewInvokeExpr = true;
>
> +
>                // redirect jumps
>                use.redirectJumpsToThisTo(constructStmt);
>                // insert new one here
>                units.insertBefore(constructStmt, use);
> +
> +              NewExprWithHashCode exprcode1 = new NewExprWithHashCode();
> +              JNewExpr newexpr1 = (JNewExpr) constructStmt.getRightOp();
> +
> +              JNewExpr newexpr2=(JNewExpr) ((AssignStmt)s).getRightOp();
> +              exprcode1.SetNewExprWithHashCode(constructStmt,
> newexpr2.hashCode(), newexpr1.hashCode(), is,
> cm.getDeclaringClass().toString(), body.getMethod(),
> getLineNumber(constructStmt));
> +              System.out.println(getLineNumber(constructStmt));
> +              //System.out.println ("******"+jjj.hashCode()+"  "+jjj
> +"*****"+constructStmt.hashCode()+"  "+constructStmt);
> +              NewOldHashCode.add(exprcode1);
> +
> +
>                if (s.hasTag("SourceLnPosTag")){
>
> constructStmt.addTag((SourceLnPosTag)s.getTag("SourceLnPosTag"));
>                }
> @@ -113,4 +137,17 @@
>              }
>          }
>      }
> +
> +       private static int getLineNumber(Stmt s) {
> +               Iterator ti = s.getTags().iterator();
> +               while (ti.hasNext()) {
> +                       Object o = ti.next();
> +                       if (o instanceof LineNumberTag)
> +                       {
> +                               LineNumberTag linetag = (LineNumberTag) o;
> +                               return linetag.getLineNumber();
> +                       }
> +               }
> +               return -1;
> +       }
>  }
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>


-- 
Eric Bodden
Sable Research Group
McGill University, Montréal, Canada


More information about the Soot-list mailing list