[Soot-list] suboptimal type assignment?

Oege de Moor Oege.de.Moor at comlab.ox.ac.uk
Tue Feb 12 10:55:46 EST 2008


Hi sooters,

Ben Bellamy, an undergrad at Oxford, is doing a project
on type inference. In his experiments, he's come across
some cases where it appears that the Jimple type assigner
is assigning greater types than strictly necessary.

An example is attached to this message.

abc.weaving.residues.IfResidue.codeGen()

assigns type soot.Value to local 'r39'. However, 'r39'
is only assigned twice, giving types soot.jimpleEqExpr
and soot.jimple.NeExpr. It would appear, therefore, that
type soot.jimple.ConditionExpr is a better choice than
soot.Value.

Are we overlooking something? Is there a reason for
making a seemingly suboptimal choice?

Also, any challenge benchmarks for a fast type assigner
would be very welcome. We've tried abc already :-), but
we could do with some weird non-javac sources of bytecode,
and applications (typically generated methods) where the
current type assigner is slow.

Thanks,

-Oege

(also on behalf of Ben and Pavel)
-------------- next part --------------
public class abc.weaving.residues.IfResidue extends abc.weaving.residues.Residue
{
    private soot.SootMethod impl;
    private java.util.List args;

    public abc.weaving.residues.Residue optimize()
    {
        abc.weaving.residues.IfResidue r0;

        r0 := @this: abc.weaving.residues.IfResidue;
        return r0;
    }

    public abc.weaving.residues.Residue inline(abc.weaving.weaver.ConstructorInliningMap)
    {
        abc.weaving.residues.IfResidue r0, $r5;
        abc.weaving.weaver.ConstructorInliningMap r1;
        soot.SootMethod $r2;
        java.util.List $r3, $r4;

        r0 := @this: abc.weaving.residues.IfResidue;
        r1 := @parameter0: abc.weaving.weaver.ConstructorInliningMap;
        $r2 = r0.<abc.weaving.residues.IfResidue: soot.SootMethod impl>;
        $r3 = r0.<abc.weaving.residues.IfResidue: java.util.List args>;
        $r4 = staticinvoke <abc.weaving.residues.WeavingVar: java.util.List inline(java.util.List,abc.weaving.weaver.ConstructorInliningMap)>($r3, r1);
        $r5 = staticinvoke <abc.weaving.residues.IfResidue: abc.weaving.residues.IfResidue construct(soot.SootMethod,java.util.List)>($r2, $r4);
        return $r5;
    }

    private void <init>(soot.SootMethod, java.util.List)
    {
        abc.weaving.residues.IfResidue r0;
        soot.SootMethod r1;
        java.util.List r2;

        r0 := @this: abc.weaving.residues.IfResidue;
        r1 := @parameter0: soot.SootMethod;
        r2 := @parameter1: java.util.List;
        specialinvoke r0.<abc.weaving.residues.Residue: void <init>()>();
        r0.<abc.weaving.residues.IfResidue: soot.SootMethod impl> = r1;
        r0.<abc.weaving.residues.IfResidue: java.util.List args> = r2;
        return;
    }

    public abc.weaving.residues.Residue resetForReweaving()
    {
        abc.weaving.residues.IfResidue r0;
        java.util.Iterator r1;
        abc.weaving.residues.WeavingVar r2;
        java.util.List $r3;
        boolean $z0;
        java.lang.Object $r4;

        r0 := @this: abc.weaving.residues.IfResidue;
        $r3 = r0.<abc.weaving.residues.IfResidue: java.util.List args>;
        r1 = interfaceinvoke $r3.<java.util.List: java.util.Iterator iterator()>();

     label0:
        $z0 = interfaceinvoke r1.<java.util.Iterator: boolean hasNext()>();
        if $z0 == 0 goto label1;

        $r4 = interfaceinvoke r1.<java.util.Iterator: java.lang.Object next()>();
        r2 = (abc.weaving.residues.WeavingVar) $r4;
        virtualinvoke r2.<abc.weaving.residues.WeavingVar: void resetForReweaving()>();
        goto label0;

     label1:
        return r0;
    }

    public static abc.weaving.residues.IfResidue construct(soot.SootMethod, java.util.List)
    {
        soot.SootMethod r0;
        java.util.List r1;
        abc.weaving.residues.IfResidue $r2;

        r0 := @parameter0: soot.SootMethod;
        r1 := @parameter1: java.util.List;
        $r2 = new abc.weaving.residues.IfResidue;
        specialinvoke $r2.<abc.weaving.residues.IfResidue: void <init>(soot.SootMethod,java.util.List)>(r0, r1);
        return $r2;
    }

    public java.lang.String toString()
    {
        abc.weaving.residues.IfResidue r0;

        r0 := @this: abc.weaving.residues.IfResidue;
        return "if(...)";
    }

    public soot.jimple.Stmt codeGen(soot.SootMethod, abc.soot.util.LocalGeneratorEx, soot.util.Chain, soot.jimple.Stmt, soot.jimple.Stmt, boolean, abc.weaving.weaver.WeavingContext)
    {
        abc.weaving.residues.IfResidue r0;
        soot.SootMethod r1, $r32;
        abc.soot.util.LocalGeneratorEx r2;
        soot.util.Chain r3;
        soot.jimple.Stmt r4, r5, r10;
        boolean z0, $z1, $z2;
        abc.weaving.weaver.WeavingContext r6;
        java.util.Vector $r7, r8;
        java.util.Iterator r9;
        abc.weaving.residues.WeavingVar r11;
        soot.Local r12, r18, r30;
        soot.RefType r13;
        soot.SootClass r14;
        soot.Type r15, $r24;
        java.util.ArrayList $r16;
        soot.SootMethodRef r17, $r33;
        soot.jimple.VirtualInvokeExpr r19;
        soot.jimple.AssignStmt r20, r36;
        java.util.List $r21, $r22;
        int $i0;
        java.lang.Object $r23;
        soot.Scene $r25;
        java.lang.String $r26;
        soot.jimple.Jimple $r27, $r28, $r31, $r35, $r37, $r40, $r42;
        soot.BooleanType $r29;
        soot.jimple.StaticInvokeExpr r34;
        soot.jimple.IntConstant $r38, $r41;
        soot.Value r39;
        soot.jimple.IfStmt r43;

        r0 := @this: abc.weaving.residues.IfResidue;
        r1 := @parameter0: soot.SootMethod;
        r2 := @parameter1: abc.soot.util.LocalGeneratorEx;
        r3 := @parameter2: soot.util.Chain;
        r4 := @parameter3: soot.jimple.Stmt;
        r5 := @parameter4: soot.jimple.Stmt;
        z0 := @parameter5: boolean;
        r6 := @parameter6: abc.weaving.weaver.WeavingContext;
        $r7 = new java.util.Vector;
        $r21 = r0.<abc.weaving.residues.IfResidue: java.util.List args>;
        $i0 = interfaceinvoke $r21.<java.util.List: int size()>();
        specialinvoke $r7.<java.util.Vector: void <init>(int)>($i0);
        r8 = $r7;
        $r22 = r0.<abc.weaving.residues.IfResidue: java.util.List args>;
        r9 = interfaceinvoke $r22.<java.util.List: java.util.Iterator iterator()>();
        r10 = r4;

     label0:
        $z1 = interfaceinvoke r9.<java.util.Iterator: boolean hasNext()>();
        if $z1 == 0 goto label3;

        $r23 = interfaceinvoke r9.<java.util.Iterator: java.lang.Object next()>();
        r11 = (abc.weaving.residues.WeavingVar) $r23;
        r12 = virtualinvoke r11.<abc.weaving.residues.WeavingVar: soot.Local get()>();
        $z2 = virtualinvoke r11.<abc.weaving.residues.WeavingVar: boolean mustBox()>();
        if $z2 == 0 goto label1;

        $r24 = virtualinvoke r11.<abc.weaving.residues.WeavingVar: soot.Type getType()>();
        r13 = (soot.RefType) $r24;
        r14 = virtualinvoke r13.<soot.RefType: soot.SootClass getSootClass()>();
        r15 = staticinvoke <abc.soot.util.Restructure$JavaTypeInfo: soot.Type getBoxingClassPrimType(soot.SootClass)>(r14);
        $r25 = staticinvoke <soot.Scene: soot.Scene v()>();
        $r26 = staticinvoke <abc.soot.util.Restructure$JavaTypeInfo: java.lang.String getSimpleTypeBoxingClassMethodName(soot.Type)>(r15);
        $r16 = new java.util.ArrayList;
        specialinvoke $r16.<java.util.ArrayList: void <init>()>();
        r17 = virtualinvoke $r25.<soot.Scene: soot.SootMethodRef makeMethodRef(soot.SootClass,java.lang.String,java.util.List,soot.Type,boolean)>(r14, $r26, $r16, r15, 0);
        r18 = virtualinvoke r2.<abc.soot.util.LocalGeneratorEx: soot.Local generateLocal(soot.Type,java.lang.String)>(r13, "ifparam");
        $r27 = staticinvoke <soot.jimple.Jimple: soot.jimple.Jimple v()>();
        r19 = virtualinvoke $r27.<soot.jimple.Jimple: soot.jimple.VirtualInvokeExpr newVirtualInvokeExpr(soot.Local,soot.SootMethodRef)>(r12, r17);
        $r28 = staticinvoke <soot.jimple.Jimple: soot.jimple.Jimple v()>();
        r20 = virtualinvoke $r28.<soot.jimple.Jimple: soot.jimple.AssignStmt newAssignStmt(soot.Value,soot.Value)>(r18, r19);
        staticinvoke <abc.weaving.tagkit.Tagger: void tagStmt(soot.jimple.Stmt,abc.weaving.tagkit.TagContainer)>(r20, r6);
        interfaceinvoke r3.<soot.util.Chain: void insertAfter(java.lang.Object,java.lang.Object)>(r20, r10);
        r10 = r20;
        interfaceinvoke r8.<java.util.List: boolean add(java.lang.Object)>(r18);
        goto label2;

     label1:
        interfaceinvoke r8.<java.util.List: boolean add(java.lang.Object)>(r12);

     label2:
        goto label0;

     label3:
        $r29 = staticinvoke <soot.BooleanType: soot.BooleanType v()>();
        r30 = virtualinvoke r2.<abc.soot.util.LocalGeneratorEx: soot.Local generateLocal(soot.Type,java.lang.String)>($r29, "ifresult");
        $r31 = staticinvoke <soot.jimple.Jimple: soot.jimple.Jimple v()>();
        $r32 = r0.<abc.weaving.residues.IfResidue: soot.SootMethod impl>;
        $r33 = virtualinvoke $r32.<soot.SootMethod: soot.SootMethodRef makeRef()>();
        r34 = virtualinvoke $r31.<soot.jimple.Jimple: soot.jimple.StaticInvokeExpr newStaticInvokeExpr(soot.SootMethodRef,java.util.List)>($r33, r8);
        $r35 = staticinvoke <soot.jimple.Jimple: soot.jimple.Jimple v()>();
        r36 = virtualinvoke $r35.<soot.jimple.Jimple: soot.jimple.AssignStmt newAssignStmt(soot.Value,soot.Value)>(r30, r34);
        if z0 == 0 goto label4;

        $r37 = staticinvoke <soot.jimple.Jimple: soot.jimple.Jimple v()>();
        $r38 = staticinvoke <soot.jimple.IntConstant: soot.jimple.IntConstant v(int)>(0);
        r39 = virtualinvoke $r37.<soot.jimple.Jimple: soot.jimple.EqExpr newEqExpr(soot.Value,soot.Value)>(r30, $r38);
        goto label5;

     label4:
        $r40 = staticinvoke <soot.jimple.Jimple: soot.jimple.Jimple v()>();
        $r41 = staticinvoke <soot.jimple.IntConstant: soot.jimple.IntConstant v(int)>(0);
        r39 = virtualinvoke $r40.<soot.jimple.Jimple: soot.jimple.NeExpr newNeExpr(soot.Value,soot.Value)>(r30, $r41);

     label5:
        $r42 = staticinvoke <soot.jimple.Jimple: soot.jimple.Jimple v()>();
        r43 = virtualinvoke $r42.<soot.jimple.Jimple: soot.jimple.IfStmt newIfStmt(soot.Value,soot.Unit)>(r39, r5);
        staticinvoke <abc.weaving.tagkit.Tagger: void tagStmt(soot.jimple.Stmt,abc.weaving.tagkit.TagContainer)>(r36, r6);
        staticinvoke <abc.weaving.tagkit.Tagger: void tagStmt(soot.jimple.Stmt,abc.weaving.tagkit.TagContainer)>(r43, r6);
        interfaceinvoke r3.<soot.util.Chain: void insertAfter(java.lang.Object,java.lang.Object)>(r36, r10);
        interfaceinvoke r3.<soot.util.Chain: void insertAfter(java.lang.Object,java.lang.Object)>(r43, r36);
        return r43;
    }
}


More information about the Soot-list mailing list