use of soot.Unit in project soot by Sable.
the class GroupIntPair method calculateStackHeight.
private void calculateStackHeight(Block aBlock) {
int blockHeight = blockToStackHeight.get(aBlock).intValue();
if (blockHeight > maxStackHeight) {
maxStackHeight = blockHeight;
}
for (Unit u : aBlock) {
Inst nInst = (Inst) u;
blockHeight -= nInst.getInMachineCount();
if (blockHeight < 0) {
throw new RuntimeException("Negative Stack height has been attained in :" + aBlock.getBody().getMethod().getSignature() + " \n" + "StackHeight: " + blockHeight + "\n" + "At instruction:" + nInst + "\n" + "Block:\n" + aBlock + "\n\nMethod: " + aBlock.getBody().getMethod().getName() + "\n" + aBlock.getBody().getMethod());
}
blockHeight += nInst.getOutMachineCount();
if (blockHeight > maxStackHeight) {
maxStackHeight = blockHeight;
}
// logger.debug(">>> " + nInst + " " + blockHeight);
}
for (Block b : aBlock.getSuccs()) {
Integer i = blockToStackHeight.get(b);
if (i != null) {
if (i.intValue() != blockHeight) {
throw new RuntimeException(aBlock.getBody().getMethod().getSignature() + ": incoherent stack height at block merge point " + b + aBlock + "\ncomputed blockHeight == " + blockHeight + " recorded blockHeight = " + i.intValue());
}
} else {
blockToStackHeight.put(b, new Integer(blockHeight));
calculateStackHeight(b);
}
}
}
use of soot.Unit in project soot by Sable.
the class AugmentedStmtGraph method mirror_PredsSuccs.
private void mirror_PredsSuccs(AugmentedStmt as, UnitGraph ug) {
Stmt s = as.get_Stmt();
LinkedList<AugmentedStmt> preds = new LinkedList<AugmentedStmt>(), succs = new LinkedList<AugmentedStmt>();
// mirror the predecessors
for (Unit u : ug.getPredsOf(s)) {
AugmentedStmt po = get_AugStmt((Stmt) u);
if (preds.contains(po) == false)
preds.add(po);
}
// mirror the successors
for (Unit u : ug.getSuccsOf(s)) {
AugmentedStmt so = get_AugStmt((Stmt) u);
if (succs.contains(so) == false)
succs.add(so);
}
// attach the mirrors properly to the AugmentedStmt
if (ug instanceof BriefUnitGraph) {
as.bpreds = preds;
as.bsuccs = succs;
if (preds.size() == 0)
bheads.add(as);
if (succs.size() == 0)
btails.add(as);
} else if (ug instanceof TrapUnitGraph) {
as.cpreds = preds;
as.csuccs = succs;
if (preds.size() == 0)
cheads.add(as);
if (succs.size() == 0)
ctails.add(as);
} else
throw new RuntimeException("Unknown UnitGraph type: " + ug.getClass());
}
use of soot.Unit in project soot by Sable.
the class DeadlockDetector method detectComponentBasedDeadlock.
public MutableDirectedGraph<CriticalSectionGroup> detectComponentBasedDeadlock() {
MutableDirectedGraph<CriticalSectionGroup> lockOrder;
boolean foundDeadlock;
int iteration = 0;
do {
iteration++;
logger.debug("[DeadlockDetector] Deadlock Iteration #" + iteration);
foundDeadlock = false;
// start each iteration with a fresh graph
lockOrder = new HashMutableDirectedGraph<CriticalSectionGroup>();
// Assemble the partial ordering of locks
Iterator<CriticalSection> deadlockIt1 = criticalSections.iterator();
while (deadlockIt1.hasNext() && !foundDeadlock) {
CriticalSection tn1 = deadlockIt1.next();
// skip if unlocked
if (tn1.setNumber <= 0) {
continue;
}
// add a node for this set
if (!lockOrder.containsNode(tn1.group)) {
lockOrder.addNode(tn1.group);
}
// Get list of tn1's target methods
if (tn1.transitiveTargets == null) {
tn1.transitiveTargets = new HashSet<MethodOrMethodContext>();
for (Unit tn1Invoke : tn1.invokes) {
Iterator<MethodOrMethodContext> targetIt = tt.iterator(tn1Invoke);
while (targetIt.hasNext()) {
tn1.transitiveTargets.add(targetIt.next());
}
}
}
// compare to each other tn
Iterator<CriticalSection> deadlockIt2 = criticalSections.iterator();
while (deadlockIt2.hasNext() && (!optionRepairDeadlock || !foundDeadlock)) {
CriticalSection tn2 = deadlockIt2.next();
// skip if unlocked or in same set as tn1
if (// this is wrong... dynamic locks in same group can be diff locks
tn2.setNumber <= 0 || (tn2.setNumber == tn1.setNumber && !optionAllowSelfEdges)) {
continue;
}
// add a node for this set
if (!lockOrder.containsNode(tn2.group)) {
lockOrder.addNode(tn2.group);
}
if (tn1.transitiveTargets.contains(tn2.method)) {
// This implies the partial ordering tn1lock before tn2lock
if (optionPrintDebug) {
logger.debug("group" + (tn1.setNumber) + " before group" + (tn2.setNumber) + ": " + "outer: " + tn1.name + " inner: " + tn2.name);
}
// Check if tn2lock before tn1lock is in our lock order
List<CriticalSectionGroup> afterTn2 = new ArrayList<CriticalSectionGroup>();
afterTn2.addAll(lockOrder.getSuccsOf(tn2.group));
for (int i = 0; i < afterTn2.size(); i++) {
for (CriticalSectionGroup o : lockOrder.getSuccsOf(afterTn2.get(i))) {
if (!afterTn2.contains(o)) {
afterTn2.add(o);
}
}
}
if (afterTn2.contains(tn1.group)) {
if (!optionRepairDeadlock) {
logger.debug("[DeadlockDetector] DEADLOCK HAS BEEN DETECTED: not correcting");
foundDeadlock = true;
} else {
logger.debug("[DeadlockDetector] DEADLOCK HAS BEEN DETECTED: merging group" + (tn1.setNumber) + " and group" + (tn2.setNumber) + " and restarting deadlock detection");
if (optionPrintDebug) {
logger.debug("tn1.setNumber was " + tn1.setNumber + " and tn2.setNumber was " + tn2.setNumber);
logger.debug("tn1.group.size was " + tn1.group.criticalSections.size() + " and tn2.group.size was " + tn2.group.criticalSections.size());
logger.debug("tn1.group.num was " + tn1.group.num() + " and tn2.group.num was " + tn2.group.num());
}
tn1.group.mergeGroups(tn2.group);
if (optionPrintDebug) {
logger.debug("tn1.setNumber is " + tn1.setNumber + " and tn2.setNumber is " + tn2.setNumber);
logger.debug("tn1.group.size is " + tn1.group.criticalSections.size() + " and tn2.group.size is " + tn2.group.criticalSections.size());
}
foundDeadlock = true;
}
}
lockOrder.addEdge(tn1.group, tn2.group);
}
}
}
} while (foundDeadlock && optionRepairDeadlock);
return lockOrder;
}
use of soot.Unit in project soot by Sable.
the class TypeAssigner method replaceNullType.
/**
* Replace statements using locals with null_type type and that would
* throw a NullPointerException at runtime by a set of instructions
* throwing a NullPointerException.
*
* This is done to remove locals with null_type type.
*
* @param b
*/
private void replaceNullType(Body b) {
List<Local> localsToRemove = new ArrayList<Local>();
boolean hasNullType = false;
// check if any local has null_type
for (Local l : b.getLocals()) {
if (l.getType() instanceof NullType) {
localsToRemove.add(l);
hasNullType = true;
}
}
// No local with null_type
if (!hasNullType)
return;
// force to propagate null constants
Map<String, String> opts = PhaseOptions.v().getPhaseOptions("jop.cpf");
if (!opts.containsKey("enabled") || !opts.get("enabled").equals("true")) {
logger.warn("Cannot run TypeAssigner.replaceNullType(Body). Try to enable jop.cfg.");
return;
}
ConstantPropagatorAndFolder.v().transform(b);
List<Unit> unitToReplaceByException = new ArrayList<Unit>();
for (Unit u : b.getUnits()) {
for (ValueBox vb : u.getUseBoxes()) {
if (vb.getValue() instanceof Local && ((Local) vb.getValue()).getType() instanceof NullType) {
Local l = (Local) vb.getValue();
Stmt s = (Stmt) u;
boolean replace = false;
if (s.containsArrayRef()) {
ArrayRef r = s.getArrayRef();
if (r.getBase() == l) {
replace = true;
}
} else if (s.containsFieldRef()) {
FieldRef r = s.getFieldRef();
if (r instanceof InstanceFieldRef) {
InstanceFieldRef ir = (InstanceFieldRef) r;
if (ir.getBase() == l) {
replace = true;
}
}
} else if (s.containsInvokeExpr()) {
InvokeExpr ie = s.getInvokeExpr();
if (ie instanceof InstanceInvokeExpr) {
InstanceInvokeExpr iie = (InstanceInvokeExpr) ie;
if (iie.getBase() == l) {
replace = true;
}
}
}
if (replace) {
unitToReplaceByException.add(u);
}
}
}
}
for (Unit u : unitToReplaceByException) {
soot.dexpler.Util.addExceptionAfterUnit(b, "java.lang.NullPointerException", u, "This statement would have triggered an Exception: " + u);
b.getUnits().remove(u);
}
// should be done on a separate phase
DeadAssignmentEliminator.v().transform(b);
UnusedLocalEliminator.v().transform(b);
}
use of soot.Unit in project soot by Sable.
the class TypeResolverBV method check_and_fix_constraints.
private void check_and_fix_constraints() throws TypeException {
ConstraintCheckerBV checker = new ConstraintCheckerBV(this, true);
StringBuffer s = null;
PatchingChain<Unit> units = stmtBody.getUnits();
Stmt[] stmts = new Stmt[units.size()];
units.toArray(stmts);
if (DEBUG) {
s = new StringBuffer("Checking:\n");
}
for (Stmt stmt : stmts) {
if (DEBUG) {
s.append(" " + stmt + "\n");
}
try {
checker.check(stmt, stmtBody);
} catch (TypeException e) {
if (DEBUG) {
logger.debug("" + s);
}
throw e;
}
}
}
Aggregations