import java.util.Stack; //导入方法依赖的package包/类
public void addCycle(Stack stack, SootMethod sm) {
// check that there is a cycle with m
if (stack.search(sm) == -1)
throw new RuntimeException("error: method not in stack. No cycle!"+ printMethodAndStack(sm, stack));
// check that there are not more than one
if (stack.lastIndexOf(sm) != stack.indexOf(sm))
throw new RuntimeException("error: a method cannot be more than twice in the stack! "+ printMethodAndStack(sm, stack));
// two cycles with the same method is not possible since we memorize already computed methods
//if (cycle2Methods.containsKey(sm))
// throw new RuntimeException("error: there already exist a cycle with the same method! "+ printMethodAndStack(sm, stack));
// At this point the stack looks like this:
// 0 1 2 n-1
// M1|M2|M3|.....|Mn
// sm = M3
// sm is at depth n in the stack, but is not in the stack.
// Methods M3, M4, ... Mn have to be saved to be later
// updated with the correct permission set of M3.
Set methods = new HashSet();
int startIndex = stack.indexOf(sm);
for (int i=startIndex+1; i
methods.add(stack.elementAt(i));
CycleKey ck = new CycleKey(sm, stack.size()+1); // +1 since sm is not in the stack
if (cycle2Methods.keySet().contains(ck)){
cycle2Methods.get(ck).addAll(methods);
}
else{
cycle2Methods.put(ck, methods);
}
cache.addAll(methods);
System.out.println("[cycle] add at depth '"+ stack.size() +"' for method '"+ sm +"'");
}