public static final String INTERLOC = "INTERLOC";
- public static final String PCLOC = "PCLOC";
+ public static final String PCLOC = "_PCLOC_";
- public static final String RLOC = "RLOC";
+ public static final String RLOC = "_RLOC_";
public static final Descriptor GLOBALDESC = new NameDescriptor(GLOBALLOC);
public static final Descriptor RETURNLOC = new NameDescriptor(RLOC);
+ public static final Descriptor LITERALDESC = new NameDescriptor("LITERAL");
+
public static String newline = System.getProperty("line.separator");
LocationInfo curMethodInfo;
public void inference() {
+ ssjava.init();
+
// construct value flow graph
constructFlowGraph();
assignCompositeLocation();
+ // calculate RETURNLOC,PCLOC
+ calculateExtraLocations();
+
+ _debug_writeFlowGraph();
+
// System.exit(0);
constructHierarchyGraph();
debug_writeHierarchyDotFiles();
- // calculate RETURNLOC,PCLOC
- calculateExtraLocations();
-
simplifyHierarchyGraph();
debug_writeSimpleHierarchyDotFiles();
System.out.println("\nSSJAVA: Translate composite location assignments to flow graphs:");
MethodDescriptor methodEventLoopDesc = ssjava.getMethodContainingSSJavaLoop();
translateCompositeLocationAssignmentToFlowGraph(methodEventLoopDesc);
- _debug_printGraph();
}
private void updateCompositeLocationAssignments() {
System.out.println("---updatedCompLoc1=" + updatedCompLoc);
} else {
NTuple<Descriptor> descTuple = node.getDescTuple();
+ System.out.println("update desc=" + descTuple);
CompositeLocation compLoc = convertToCompositeLocation(md, descTuple);
compLoc = updateCompositeLocation(compLoc);
node.setCompositeLocation(compLoc);
Set<FlowNode> nodeSet = flowGraph.getNodeSet();
for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
FlowNode node = (FlowNode) iterator.next();
- if (node.getDescTuple().startsWith(localDesc)) {
+ if (node.getDescTuple().startsWith(localDesc)
+ && !node.getDescTuple().get(0).equals(LITERALDESC)) {
// need to assign the inferred composite location to this node
CompositeLocation newCompLoc = generateCompositeLocation(node.getDescTuple(), inferCompLoc);
node.setCompositeLocation(newCompLoc);
// do fixed-point analysis
- ssjava.init();
LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
// Collections.sort(descriptorListToAnalyze, new
}
methodGraph.getHNode(GLOBALDESC).setSkeleton(true);
+ if (ssjava.getMethodContainingSSJavaLoop().equals(md)) {
+ // if the current method contains the event loop
+ // we need to set all nodes of the hierarchy graph as a skeleton node
+ Set<HNode> hnodeSet = methodGraph.getNodeSet();
+ for (Iterator iterator = hnodeSet.iterator(); iterator.hasNext();) {
+ HNode hnode = (HNode) iterator.next();
+ hnode.setSkeleton(true);
+ }
+ }
+
}
private MethodSummary getMethodSummary(MethodDescriptor md) {
int idx =
getParamLocation(methodDefStr,
generateVarDeclaration((VarDescriptor) localVarDesc));
-
+ System.out.println("methodDefStr=" + methodDefStr + " localVarDesc=" + localVarDesc
+ + " idx=" + idx);
assert (idx != -1);
String annoatedStr =
}
- private void inferLattices() {
- }
-
private void calculateExtraLocations() {
- LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
- for (Iterator iterator = descriptorListToAnalyze.iterator(); iterator.hasNext();) {
+
+ LinkedList<MethodDescriptor> methodDescList = ssjava.getSortedDescriptors();
+ for (Iterator iterator = methodDescList.iterator(); iterator.hasNext();) {
MethodDescriptor md = (MethodDescriptor) iterator.next();
if (!ssjava.getMethodContainingSSJavaLoop().equals(md)) {
calculateExtraLocations(md);
}
}
+
}
private void checkLatticesOfVirtualMethods(MethodDescriptor md) {
// PC location is higher than location types of parameters which has incoming flows.
Set<NTuple<Location>> paramLocTupleHavingInFlowSet = new HashSet<NTuple<Location>>();
- Set<NTuple<Location>> paramLocTupleNOTHavingInFlowSet = new HashSet<NTuple<Location>>();
+ Set<Descriptor> paramDescNOTHavingInFlowSet = new HashSet<Descriptor>();
+ // Set<FlowNode> paramNodeNOThavingInFlowSet = new HashSet<FlowNode>();
int numParams = fg.getNumParameters();
for (int i = 0; i < numParams; i++) {
// parameter has in-value flows
paramLocTupleHavingInFlowSet.add(paramLocTuple);
} else {
- paramLocTupleNOTHavingInFlowSet.add(paramLocTuple);
+ // paramNodeNOThavingInFlowSet.add(fg.getFlowNode(paramDescTuple));
+ paramDescNOTHavingInFlowSet.add(prefix);
}
}
+ System.out.println("paramNodeNOThavingInFlowSet=" + paramDescNOTHavingInFlowSet);
if (paramLocTupleHavingInFlowSet.size() > 0
&& !coversAllParamters(md, fg, paramLocTupleHavingInFlowSet)) {
NTuple<Location> pcLocTuple =
generateLocTupleRelativeTo(md, paramLocTupleHavingInFlowSet, PCLOC);
- int pcLocTupleIdx = pcLocTuple.size() - 1;
- Location pcLoc = pcLocTuple.get(pcLocTupleIdx);
- Descriptor pcDesc = pcLoc.getLocDescriptor();
- Descriptor enclosingDesc = pcLocTuple.get(pcLocTupleIdx).getDescriptor();
-
- HierarchyGraph hierarchyGraph = getHierarchyGraph(enclosingDesc);
- HNode pcNode = hierarchyGraph.getHNode(pcDesc);
- pcNode.setSkeleton(true);
-
- // add ordering relations s.t. PCLOC is higher than all of parameters with incoming flows
- // and lower than paramters which do not have any incoming flows
- for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
- NTuple<Location> paramLocTuple = (NTuple<Location>) iterator.next();
- if (paramLocTuple.size() > pcLocTupleIdx) {
- Descriptor lowerDesc = paramLocTuple.get(pcLocTupleIdx).getLocDescriptor();
- hierarchyGraph.addEdge(pcDesc, lowerDesc);
- }
- }
+ NTuple<Descriptor> pcDescTuple = translateToDescTuple(pcLocTuple);
+
+ // add ordering relations s.t. PCLOC is higher than all flow nodes except the set of
+ // parameters that do not have incoming flows
- for (Iterator iterator = paramLocTupleNOTHavingInFlowSet.iterator(); iterator.hasNext();) {
- NTuple<Location> paramLocTuple = (NTuple<Location>) iterator.next();
- if (paramLocTuple.size() > pcLocTupleIdx) {
- Descriptor higherDesc = paramLocTuple.get(pcLocTupleIdx).getLocDescriptor();
- hierarchyGraph.addEdge(higherDesc, pcDesc);
+ for (Iterator iterator = fg.getNodeSet().iterator(); iterator.hasNext();) {
+ FlowNode node = (FlowNode) iterator.next();
+
+ if (!paramDescNOTHavingInFlowSet.contains(node.getCurrentDescTuple().get(0))) {
+ fg.addValueFlowEdge(pcDescTuple, node.getDescTuple());
}
}
- System.out.println("pcLoc=" + pcLoc);
+ System.out.println("pcLoc=" + pcLocTuple);
methodSummary.setPCLoc(new CompositeLocation(pcLocTuple));
}
System.out.println("#calculateRETURNLOC= " + md);
// calculate a return location:
// the return location type is lower than all parameters and the location of return values
-
MethodSummary methodSummary = getMethodSummary(md);
-
FlowGraph fg = getFlowGraph(md);
-
Map<Integer, CompositeLocation> mapParamToLoc = methodSummary.getMapParamIdxToInferLoc();
Set<Integer> paramIdxSet = mapParamToLoc.keySet();
// first, generate the set of return value location types that starts
// with 'this' reference
- Set<NTuple<Location>> inferFieldReturnLocSet = new HashSet<NTuple<Location>>();
-
Set<FlowNode> paramFlowNodeFlowingToReturnValueSet = getParamNodeFlowingToReturnValue(md);
System.out.println("paramFlowNodeFlowingToReturnValueSet="
+ paramFlowNodeFlowingToReturnValueSet);
- Set<NTuple<Location>> locFlowingToReturnValueSet = new HashSet<NTuple<Location>>();
+ Set<NTuple<Location>> tupleToBeHigherThanReturnLocSet = new HashSet<NTuple<Location>>();
for (Iterator iterator = paramFlowNodeFlowingToReturnValueSet.iterator(); iterator.hasNext();) {
FlowNode fn = (FlowNode) iterator.next();
-
NTuple<Descriptor> paramDescTuple = fn.getCurrentDescTuple();
- NTuple<Location> paramLocTuple = translateToLocTuple(md, paramDescTuple);
-
- locFlowingToReturnValueSet.add(paramLocTuple);
+ tupleToBeHigherThanReturnLocSet.add(translateToLocTuple(md, paramDescTuple));
}
Set<FlowNode> returnNodeSet = fg.getReturnNodeSet();
for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
FlowNode returnNode = (FlowNode) iterator.next();
NTuple<Descriptor> returnDescTuple = returnNode.getCurrentDescTuple();
- NTuple<Location> returnLocTuple = translateToLocTuple(md, returnDescTuple);
- locFlowingToReturnValueSet.add(returnLocTuple);
+ tupleToBeHigherThanReturnLocSet.add(translateToLocTuple(md, returnDescTuple));
}
- System.out.println("locFlowingToReturnValueSet=" + locFlowingToReturnValueSet);
+ System.out.println("-flow graph's returnNodeSet=" + returnNodeSet);
+ System.out.println("tupleSetToBeHigherThanReturnLoc=" + tupleToBeHigherThanReturnLocSet);
// Here, generates a return location in the method lattice that is lower than the
// locFlowingToReturnValueSet
NTuple<Location> returnLocTuple =
- generateLocTupleRelativeTo(md, locFlowingToReturnValueSet, RLOC);
+ generateLocTupleRelativeTo(md, tupleToBeHigherThanReturnLocSet, RLOC);
System.out.println("returnLocTuple=" + returnLocTuple);
- int returnLocTupleIdx = returnLocTuple.size() - 1;
- Location returnLoc = returnLocTuple.get(returnLocTupleIdx);
- Descriptor returnDesc = returnLoc.getLocDescriptor();
- Descriptor enclosingDesc = returnLocTuple.get(returnLocTupleIdx).getDescriptor();
-
- HierarchyGraph hierarchyGraph = getHierarchyGraph(enclosingDesc);
- HNode returnNode = hierarchyGraph.getHNode(returnDesc);
- returnNode.setSkeleton(true);
-
- for (Iterator iterator = locFlowingToReturnValueSet.iterator(); iterator.hasNext();) {
- NTuple<Location> locTuple = (NTuple<Location>) iterator.next();
- Descriptor higherDesc = locTuple.get(returnLocTupleIdx).getLocDescriptor();
- hierarchyGraph.addEdge(higherDesc, returnDesc);
+ NTuple<Descriptor> returnDescTuple = translateToDescTuple(returnLocTuple);
+ for (Iterator iterator = tupleToBeHigherThanReturnLocSet.iterator(); iterator.hasNext();) {
+ NTuple<Location> higherTuple = (NTuple<Location>) iterator.next();
+ fg.addValueFlowEdge(translateToDescTuple(higherTuple), returnDescTuple);
}
+ fg.getFlowNode(returnDescTuple).setSkeleton(true);
+ System.out.println("fg node set=" + fg.getNodeSet());
+
methodSummary.setRETURNLoc(new CompositeLocation(returnLocTuple));
// skip: for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
if (curDescriptor instanceof VarDescriptor) {
enclosingDescriptor = md.getClassDesc();
+ } else if (curDescriptor instanceof FieldDescriptor) {
+ enclosingDescriptor = ((FieldDescriptor) curDescriptor).getClassDescriptor();
} else if (curDescriptor instanceof NameDescriptor) {
// it is "GLOBAL LOC" case!
enclosingDescriptor = GLOBALDESC;
- } else if (curDescriptor instanceof InterDescriptor) {
- enclosingDescriptor = null;
} else {
- enclosingDescriptor = ((FieldDescriptor) curDescriptor).getClassDescriptor();
+ enclosingDescriptor = null;
}
}
newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
newImplicitTupleSet.addTupleSet(condTupleNode);
- if (newImplicitTupleSet.size() > 1) {
+ if (needToGenerateInterLoc(newImplicitTupleSet)) {
// need to create an intermediate node for the GLB of conditional
// locations & implicit flows
NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
private void analyzeFlowReturnNode(MethodDescriptor md, SymbolTable nametable, ReturnNode rn,
NodeTupleSet implicitFlowTupleSet) {
+ System.out.println("-analyzeFlowReturnNode=" + rn.printNode(0));
ExpressionNode returnExp = rn.getReturnExpression();
if (returnExp != null) {
// add tuples corresponding to the current implicit flows
currentFlowTupleSet.addTupleSet(implicitFlowTupleSet);
- if (currentFlowTupleSet.size() > 1) {
+ System.out.println("---currentFlowTupleSet=" + currentFlowTupleSet);
+
+ if (needToGenerateInterLoc(currentFlowTupleSet)) {
+ System.out.println("---needToGenerateInterLoc");
FlowNode meetNode = fg.createIntermediateNode();
for (Iterator iterator = currentFlowTupleSet.iterator(); iterator.hasNext();) {
NTuple<Descriptor> currentFlowTuple = (NTuple<Descriptor>) iterator.next();
fg.addValueFlowEdge(currentFlowTuple, meetNode.getDescTuple());
}
fg.addReturnFlowNode(meetNode.getDescTuple());
- } else if (currentFlowTupleSet.size() == 1) {
- NTuple<Descriptor> tuple = currentFlowTupleSet.iterator().next();
- fg.addReturnFlowNode(tuple);
+ } else {
+ // currentFlowTupleSet = removeLiteralTuple(currentFlowTupleSet);
+ for (Iterator iterator = currentFlowTupleSet.iterator(); iterator.hasNext();) {
+ NTuple<Descriptor> currentFlowTuple = (NTuple<Descriptor>) iterator.next();
+ fg.addReturnFlowNode(currentFlowTuple);
+ }
}
}
}
+ private NodeTupleSet removeLiteralTuple(NodeTupleSet inSet) {
+ NodeTupleSet tupleSet = new NodeTupleSet();
+ for (Iterator<NTuple<Descriptor>> iter = inSet.iterator(); iter.hasNext();) {
+ NTuple<Descriptor> tuple = iter.next();
+ if (!tuple.get(0).equals(LITERALDESC)) {
+ tupleSet.addTuple(tuple);
+ }
+ }
+ return tupleSet;
+ }
+
+ private boolean needToGenerateInterLoc(NodeTupleSet tupleSet) {
+ int size = 0;
+ for (Iterator<NTuple<Descriptor>> iter = tupleSet.iterator(); iter.hasNext();) {
+ NTuple<Descriptor> descTuple = iter.next();
+ if (!descTuple.get(0).equals(LITERALDESC)) {
+ size++;
+ }
+ }
+ if (size > 1) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
private void analyzeFlowLoopNode(MethodDescriptor md, SymbolTable nametable, LoopNode ln,
NodeTupleSet implicitFlowTupleSet) {
newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
newImplicitTupleSet.addTupleSet(condTupleNode);
- if (newImplicitTupleSet.size() > 1) {
+ if (needToGenerateInterLoc(newImplicitTupleSet)) {
// need to create an intermediate node for the GLB of conditional
// locations & implicit flows
NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
analyzeFlowExpressionNode(md, bn.getVarTable(), ln.getCondition(), condTupleNode, null,
implicitFlowTupleSet, false);
- // ///////////
- NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
+ NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
+ newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
+ newImplicitTupleSet.addTupleSet(condTupleNode);
- for (Iterator<NTuple<Descriptor>> idxIter = condTupleNode.iterator(); idxIter.hasNext();) {
- NTuple<Descriptor> tuple = idxIter.next();
- addFlowGraphEdge(md, tuple, interTuple);
- }
+ if (needToGenerateInterLoc(newImplicitTupleSet)) {
+ // need to create an intermediate node for the GLB of conditional
+ // locations & implicit flows
+ NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
+ for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter
+ .hasNext();) {
+ NTuple<Descriptor> tuple = idxIter.next();
+ addFlowGraphEdge(md, tuple, interTuple);
+ }
+ newImplicitTupleSet.clear();
+ newImplicitTupleSet.addTuple(interTuple);
- for (Iterator<NTuple<Descriptor>> idxIter = implicitFlowTupleSet.iterator(); idxIter
- .hasNext();) {
- NTuple<Descriptor> tuple = idxIter.next();
- addFlowGraphEdge(md, tuple, interTuple);
}
- NodeTupleSet newImplicitSet = new NodeTupleSet();
- newImplicitSet.addTuple(interTuple);
- analyzeFlowBlockNode(md, bn.getVarTable(), ln.getUpdate(), newImplicitSet);
- analyzeFlowBlockNode(md, bn.getVarTable(), ln.getBody(), newImplicitSet);
+ // ///////////
+ // NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
+ //
+ // for (Iterator<NTuple<Descriptor>> idxIter = condTupleNode.iterator(); idxIter.hasNext();) {
+ // NTuple<Descriptor> tuple = idxIter.next();
+ // addFlowGraphEdge(md, tuple, interTuple);
+ // }
+ //
+ // for (Iterator<NTuple<Descriptor>> idxIter = implicitFlowTupleSet.iterator(); idxIter
+ // .hasNext();) {
+ // NTuple<Descriptor> tuple = idxIter.next();
+ // addFlowGraphEdge(md, tuple, interTuple);
+ // }
+ //
+ // NodeTupleSet newImplicitSet = new NodeTupleSet();
+ // newImplicitSet.addTuple(interTuple);
+ analyzeFlowBlockNode(md, bn.getVarTable(), ln.getUpdate(), newImplicitTupleSet);
+ analyzeFlowBlockNode(md, bn.getVarTable(), ln.getBody(), newImplicitTupleSet);
// ///////////
// condTupleNode.addTupleSet(implicitFlowTupleSet);
// System.out.println("implicitFlowTupleSet=" + implicitFlowTupleSet);
// System.out.println("newImplicitTupleSet=" + newImplicitTupleSet);
- if (newImplicitTupleSet.size() > 1) {
+ if (needToGenerateInterLoc(newImplicitTupleSet)) {
// need to create an intermediate node for the GLB of conditional locations & implicit flows
NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
// creates edges from RHS to LHS
NTuple<Descriptor> interTuple = null;
- if (nodeSetRHS.size() > 1) {
+ if (needToGenerateInterLoc(nodeSetRHS)) {
interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
}
break;
case Kind.LiteralNode:
- analyzeLiteralNode(md, nametable, (LiteralNode) en);
+ analyzeFlowLiteralNode(md, nametable, (LiteralNode) en, nodeSet);
break;
case Kind.MethodInvokeNode:
// if argument is liternal node, argTuple is set to NULL
NTuple<Descriptor> argTuple = new NTuple<Descriptor>();
- if (argTupleSet.size() > 1) {
+ if (needToGenerateInterLoc(argTupleSet)) {
NTuple<Descriptor> interTuple =
getFlowGraph(md).createIntermediateNode().getDescTuple();
for (Iterator<NTuple<Descriptor>> idxIter = argTupleSet.iterator(); idxIter.hasNext();) {
mapIdxToTuple.put(new Integer(idx), argTuple);
}
- private void analyzeLiteralNode(MethodDescriptor md, SymbolTable nametable, LiteralNode en) {
-
+ private void analyzeFlowLiteralNode(MethodDescriptor md, SymbolTable nametable, LiteralNode en,
+ NodeTupleSet nodeSet) {
+ NTuple<Descriptor> tuple = new NTuple<Descriptor>();
+ tuple.add(LITERALDESC);
+ nodeSet.addTuple(tuple);
}
private void analyzeFlowArrayAccessNode(MethodDescriptor md, SymbolTable nametable,
private NTuple<Descriptor> analyzeFlowNameNode(MethodDescriptor md, SymbolTable nametable,
NameNode nn, NodeTupleSet nodeSet, NTuple<Descriptor> base, NodeTupleSet implicitFlowTupleSet) {
- // System.out.println("analyzeFlowNameNode=" + nn.printNode(0));
+ System.out.println("analyzeFlowNameNode=" + nn.printNode(0));
if (base == null) {
base = new NTuple<Descriptor>();
if (fd.isFinal()) {
// if it is 'static final', no need to have flow node for the TOP
// location
+ System.out.println("STATIC FINAL");
return null;
} else {
// if 'static', assign the default GLOBAL LOCATION to the first
// creates edges from RHS to LHS
NTuple<Descriptor> interTuple = null;
- if (nodeSetRHS.size() > 1) {
+ if (needToGenerateInterLoc(nodeSetRHS)) {
interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
}
String fileName = "lattice_";
if (md != null) {
fileName +=
- cd.getSymbol().replaceAll("[\\W_]", "") + "_" + md.toString().replaceAll("[\\W_]", "");
+ /* cd.getSymbol().replaceAll("[\\W_]", "") + "_" + */md.toString().replaceAll("[\\W_]", "");
} else {
fileName += cd.getSymbol().replaceAll("[\\W_]", "");
}
bw.write(locName + " [label=\"" + prettyStr + "\"]" + ";\n");
}
- public void _debug_printGraph() {
+ public void _debug_writeFlowGraph() {
Set<MethodDescriptor> keySet = mapMethodDescriptorToFlowGraph.keySet();
for (Iterator<MethodDescriptor> iterator = keySet.iterator(); iterator.hasNext();) {