Search in sources :

Example 26 with Unit

use of soot.Unit in project soot by Sable.

the class TypeResolverBV method check_constraints.

private void check_constraints() throws TypeException {
    ConstraintCheckerBV checker = new ConstraintCheckerBV(this, false);
    StringBuffer s = null;
    if (DEBUG) {
        s = new StringBuffer("Checking:\n");
    }
    for (Iterator<Unit> stmtIt = stmtBody.getUnits().iterator(); stmtIt.hasNext(); ) {
        final Stmt stmt = (Stmt) stmtIt.next();
        if (DEBUG) {
            s.append(" " + stmt + "\n");
        }
        try {
            checker.check(stmt, stmtBody);
        } catch (TypeException e) {
            if (DEBUG) {
                logger.debug("" + s);
            }
            throw e;
        }
    }
}
Also used : Unit(soot.Unit) InvokeStmt(soot.jimple.InvokeStmt) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt)

Example 27 with Unit

use of soot.Unit in project soot by Sable.

the class TypeResolverBV method collect_constraints_3.

private void collect_constraints_3() {
    ConstraintCollectorBV collector = new ConstraintCollectorBV(this, false);
    for (Iterator<Unit> stmtIt = stmtBody.getUnits().iterator(); stmtIt.hasNext(); ) {
        final Stmt stmt = (Stmt) stmtIt.next();
        if (DEBUG) {
            logger.debug("stmt: ");
        }
        collector.collect(stmt, stmtBody);
        if (DEBUG) {
            logger.debug("" + stmt);
        }
    }
}
Also used : Unit(soot.Unit) InvokeStmt(soot.jimple.InvokeStmt) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt)

Example 28 with Unit

use of soot.Unit in project soot by Sable.

the class LockAllocationBodyTransformer method getLockFor.

public static Value getLockFor(EquivalentValue lockEqVal) {
    Value lock = lockEqVal.getValue();
    if (lock instanceof InstanceFieldRef)
        return lock;
    if (// it would be better to lock the array
    lock instanceof ArrayRef)
        // ref for each value of the index!
        return ((ArrayRef) lock).getBase();
    if (lock instanceof Local)
        return lock;
    if (lock instanceof StaticFieldRef || lock instanceof NewStaticLock) {
        if (lockEqValToLock.containsKey(lockEqVal))
            return lockEqValToLock.get(lockEqVal);
        SootClass lockClass = null;
        if (lock instanceof StaticFieldRef) {
            StaticFieldRef sfrLock = (StaticFieldRef) lock;
            lockClass = sfrLock.getField().getDeclaringClass();
        } else if (lock instanceof NewStaticLock) {
            DeadlockAvoidanceEdge dae = (DeadlockAvoidanceEdge) lock;
            lockClass = dae.getLockClass();
        }
        SootMethod clinitMethod = null;
        JimpleBody clinitBody = null;
        Stmt firstStmt = null;
        boolean addingNewClinit = !lockClass.declaresMethod("void <clinit>()");
        if (addingNewClinit) {
            clinitMethod = Scene.v().makeSootMethod("<clinit>", new ArrayList(), VoidType.v(), Modifier.PUBLIC | Modifier.STATIC);
            clinitBody = Jimple.v().newBody(clinitMethod);
            clinitMethod.setActiveBody(clinitBody);
            lockClass.addMethod(clinitMethod);
        } else {
            clinitMethod = lockClass.getMethod("void <clinit>()");
            clinitBody = (JimpleBody) clinitMethod.getActiveBody();
            firstStmt = clinitBody.getFirstNonIdentityStmt();
        }
        PatchingChain<Unit> clinitUnits = clinitBody.getUnits();
        Local lockLocal = Jimple.v().newLocal("objectLockLocal" + lockNumber, RefType.v("java.lang.Object"));
        // lockNumber is increased below
        // TODO: add name conflict
        clinitBody.getLocals().add(lockLocal);
        // avoidance code
        // assign new object to lock obj
        Stmt newStmt = Jimple.v().newAssignStmt(lockLocal, Jimple.v().newNewExpr(RefType.v("java.lang.Object")));
        if (addingNewClinit)
            clinitUnits.add(newStmt);
        else
            clinitUnits.insertBeforeNoRedirect(newStmt, firstStmt);
        // initialize new object
        SootClass objectClass = Scene.v().loadClassAndSupport("java.lang.Object");
        RefType type = RefType.v(objectClass);
        SootMethod initMethod = objectClass.getMethod("void <init>()");
        Stmt initStmt = Jimple.v().newInvokeStmt(Jimple.v().newSpecialInvokeExpr(lockLocal, initMethod.makeRef(), Collections.EMPTY_LIST));
        if (addingNewClinit)
            clinitUnits.add(initStmt);
        else
            clinitUnits.insertBeforeNoRedirect(initStmt, firstStmt);
        // copy new object to global static lock object (for use by other
        // fns)
        SootField actualLockObject = Scene.v().makeSootField("objectLockGlobal" + lockNumber, RefType.v("java.lang.Object"), Modifier.STATIC | Modifier.PUBLIC);
        lockNumber++;
        lockClass.addField(actualLockObject);
        StaticFieldRef actualLockSfr = Jimple.v().newStaticFieldRef(actualLockObject.makeRef());
        Stmt assignStmt = Jimple.v().newAssignStmt(actualLockSfr, lockLocal);
        if (addingNewClinit)
            clinitUnits.add(assignStmt);
        else
            clinitUnits.insertBeforeNoRedirect(assignStmt, firstStmt);
        if (addingNewClinit)
            clinitUnits.add(Jimple.v().newReturnVoidStmt());
        lockEqValToLock.put(lockEqVal, actualLockSfr);
        return actualLockSfr;
    }
    throw new RuntimeException("Unknown type of lock (" + lock + "): expected FieldRef, ArrayRef, or Local");
}
Also used : ArrayList(java.util.ArrayList) FakeJimpleLocal(soot.jimple.toolkits.infoflow.FakeJimpleLocal) Local(soot.Local) SootClass(soot.SootClass) Unit(soot.Unit) StaticFieldRef(soot.jimple.StaticFieldRef) Stmt(soot.jimple.Stmt) ArrayRef(soot.jimple.ArrayRef) RefType(soot.RefType) EquivalentValue(soot.EquivalentValue) Value(soot.Value) InstanceFieldRef(soot.jimple.InstanceFieldRef) SootMethod(soot.SootMethod) SootField(soot.SootField) JimpleBody(soot.jimple.JimpleBody)

Example 29 with Unit

use of soot.Unit in project soot by Sable.

the class TypeResolver method collect_constraints_3.

private void collect_constraints_3() {
    ConstraintCollector collector = new ConstraintCollector(this, false);
    for (Iterator<Unit> stmtIt = stmtBody.getUnits().iterator(); stmtIt.hasNext(); ) {
        final Stmt stmt = (Stmt) stmtIt.next();
        if (DEBUG) {
            logger.debug("stmt: ");
        }
        collector.collect(stmt, stmtBody);
        if (DEBUG) {
            logger.debug("" + stmt);
        }
    }
}
Also used : Unit(soot.Unit) InvokeStmt(soot.jimple.InvokeStmt) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt)

Example 30 with Unit

use of soot.Unit in project soot by Sable.

the class TypeResolver method collect_constraints_1_2.

private void collect_constraints_1_2() {
    ConstraintCollector collector = new ConstraintCollector(this, true);
    for (Iterator<Unit> stmtIt = stmtBody.getUnits().iterator(); stmtIt.hasNext(); ) {
        final Stmt stmt = (Stmt) stmtIt.next();
        if (DEBUG) {
            logger.debug("stmt: ");
        }
        collector.collect(stmt, stmtBody);
        if (DEBUG) {
            logger.debug("" + stmt);
        }
    }
}
Also used : Unit(soot.Unit) InvokeStmt(soot.jimple.InvokeStmt) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt)

Aggregations

Unit (soot.Unit)240 Local (soot.Local)77 Stmt (soot.jimple.Stmt)77 Value (soot.Value)74 ArrayList (java.util.ArrayList)65 AssignStmt (soot.jimple.AssignStmt)58 SootMethod (soot.SootMethod)47 Body (soot.Body)37 InvokeStmt (soot.jimple.InvokeStmt)35 Type (soot.Type)34 HashSet (java.util.HashSet)33 ValueBox (soot.ValueBox)33 InvokeExpr (soot.jimple.InvokeExpr)33 Trap (soot.Trap)32 RefType (soot.RefType)30 IdentityStmt (soot.jimple.IdentityStmt)28 HashMap (java.util.HashMap)27 IfStmt (soot.jimple.IfStmt)27 DefinitionStmt (soot.jimple.DefinitionStmt)25 List (java.util.List)23