Search in sources :

Example 1 with HashMultiMap

use of soot.util.HashMultiMap in project soot by Sable.

the class TrapTransformer method getUnitsWithMonitor.

public Set<Unit> getUnitsWithMonitor(UnitGraph ug) {
    // Idea: Associate each unit with a set of monitors held at that
    // statement
    MultiMap<Unit, Value> unitMonitors = new HashMultiMap<>();
    // Start at the heads of the unit graph
    List<Unit> workList = new ArrayList<>();
    Set<Unit> doneSet = new HashSet<>();
    for (Unit head : ug.getHeads()) {
        workList.add(head);
    }
    while (!workList.isEmpty()) {
        Unit curUnit = workList.remove(0);
        boolean hasChanged = false;
        Value exitValue = null;
        if (curUnit instanceof EnterMonitorStmt) {
            // We enter a new monitor
            EnterMonitorStmt ems = (EnterMonitorStmt) curUnit;
            hasChanged = unitMonitors.put(curUnit, ems.getOp());
        } else if (curUnit instanceof ExitMonitorStmt) {
            // We leave a monitor
            ExitMonitorStmt ems = (ExitMonitorStmt) curUnit;
            exitValue = ems.getOp();
        }
        // Copy over the monitors from the predecessors
        for (Unit pred : ug.getPredsOf(curUnit)) for (Value v : unitMonitors.get(pred)) if (v != exitValue)
            if (unitMonitors.put(curUnit, v))
                hasChanged = true;
        // Work on the successors
        if (doneSet.add(curUnit) || hasChanged)
            workList.addAll(ug.getSuccsOf(curUnit));
    }
    return unitMonitors.keySet();
}
Also used : ExitMonitorStmt(soot.jimple.ExitMonitorStmt) Value(soot.Value) ArrayList(java.util.ArrayList) HashMultiMap(soot.util.HashMultiMap) Unit(soot.Unit) EnterMonitorStmt(soot.jimple.EnterMonitorStmt) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Unit (soot.Unit)1 Value (soot.Value)1 EnterMonitorStmt (soot.jimple.EnterMonitorStmt)1 ExitMonitorStmt (soot.jimple.ExitMonitorStmt)1 HashMultiMap (soot.util.HashMultiMap)1