use of soot.toolkits.graph.HashMutableDirectedGraph in project soot by Sable.
the class DeadlockDetector method reorderLocksets.
public void reorderLocksets(Map<Value, Integer> lockToLockNum, MutableEdgeLabelledDirectedGraph<Integer, CriticalSection> lockOrder) {
for (CriticalSection tn : criticalSections) {
// Get the portion of the lock order that is visible to tn
HashMutableDirectedGraph<Integer> visibleOrder = new HashMutableDirectedGraph<Integer>();
if (tn.group != null) {
for (CriticalSection otherTn : criticalSections) {
// Check if otherTn and tn share a static lock
boolean tnsShareAStaticLock = false;
for (EquivalentValue tnLockEqVal : tn.lockset) {
Integer tnLockNum = lockToLockNum.get(tnLockEqVal.getValue());
if (tnLockNum < 0) {
// this is a static lock... see if some lock in labelTn has the same #
if (otherTn.group != null) {
for (EquivalentValue otherTnLockEqVal : otherTn.lockset) {
if (Objects.equals(lockToLockNum.get(otherTnLockEqVal.getValue()), tnLockNum)) {
tnsShareAStaticLock = true;
}
}
} else {
// not really... but we want to skip this one
tnsShareAStaticLock = true;
}
}
}
if (// if tns don't share any static lock, or if tns are the same one
!tnsShareAStaticLock || tn == otherTn) {
// add these orderings to tn's visible order
DirectedGraph<Integer> orderings = lockOrder.getEdgesForLabel(otherTn);
for (Integer node1 : orderings) {
if (!visibleOrder.containsNode(node1)) {
visibleOrder.addNode(node1);
}
for (Integer node2 : orderings.getSuccsOf(node1)) {
if (!visibleOrder.containsNode(node2)) {
visibleOrder.addNode(node2);
}
visibleOrder.addEdge(node1, node2);
}
}
}
}
logger.debug("VISIBLE ORDER FOR " + tn.name);
visibleOrder.printGraph();
// Order locks in tn's lockset according to the visible order (insertion sort)
List<EquivalentValue> newLockset = new ArrayList<EquivalentValue>();
for (EquivalentValue lockEqVal : tn.lockset) {
Value lockToInsert = lockEqVal.getValue();
Integer lockNumToInsert = lockToLockNum.get(lockToInsert);
int i = 0;
while (i < newLockset.size()) {
EquivalentValue existingLockEqVal = newLockset.get(i);
Value existingLock = existingLockEqVal.getValue();
Integer existingLockNum = lockToLockNum.get(existingLock);
if (visibleOrder.containsEdge(lockNumToInsert, existingLockNum) || // !visibleOrder.containsEdge(existingLockNum, lockNumToInsert) ) // if(! existing before toinsert )
lockNumToInsert < existingLockNum) {
break;
}
i++;
}
newLockset.add(i, lockEqVal);
}
logger.debug("reordered from " + LockAllocator.locksetToLockNumString(tn.lockset, lockToLockNum) + " to " + LockAllocator.locksetToLockNumString(newLockset, lockToLockNum));
tn.lockset = newLockset;
}
}
}
Aggregations