X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FSSJava%2FSSJavaAnalysis.java;h=61a90d09f568181f3f316473aee9077a10a74120;hp=fb9d4d5c3e54729424f8dd9903d55dc8812d427e;hb=47cc527f574f19b71e92fceac668fb8c0655b13b;hpb=fd76ab25bef61df70e1571a91b3709fab4a4cf18 diff --git a/Robust/src/Analysis/SSJava/SSJavaAnalysis.java b/Robust/src/Analysis/SSJava/SSJavaAnalysis.java index fb9d4d5c..61a90d09 100644 --- a/Robust/src/Analysis/SSJava/SSJavaAnalysis.java +++ b/Robust/src/Analysis/SSJava/SSJavaAnalysis.java @@ -26,6 +26,7 @@ import IR.ClassDescriptor; import IR.Descriptor; import IR.FieldDescriptor; import IR.MethodDescriptor; +import IR.NameDescriptor; import IR.State; import IR.SymbolTable; import IR.TypeUtil; @@ -112,6 +113,10 @@ public class SSJavaAnalysis { private Map> mapSharedLocToDescSet; + private Map> mapDescToCompleteLattice; + public Map mapNumLocsMapManual; + public Map mapNumPathsMapManual; + public SSJavaAnalysis(State state, TypeUtil tu, BuildFlat bf, CallGraph callgraph) { this.state = state; this.tu = tu; @@ -132,6 +137,9 @@ public class SSJavaAnalysis { this.sortedDescriptors = new LinkedList(); this.md2pcLoc = new HashMap(); this.mapSharedLocToDescSet = new HashMap>(); + this.mapDescToCompleteLattice = new HashMap>(); + this.mapNumLocsMapManual = new HashMap(); + this.mapNumPathsMapManual = new HashMap(); } public void doCheck() { @@ -151,6 +159,8 @@ public class SSJavaAnalysis { System.exit(0); } else { parseLocationAnnotation(); + debug_countNumLocations(); + // System.exit(0); doFlowDownCheck(); doDefinitelyWrittenCheck(); doLoopCheck(); @@ -160,9 +170,113 @@ public class SSJavaAnalysis { MethodDescriptor md = (MethodDescriptor) iterator.next(); MethodLattice locOrder = getMethodLattice(md); writeLatticeDotFile(md.getClassDesc(), md, getMethodLattice(md)); - // System.out.println("~~~\t" + md.getClassDesc() + "_" + md + "\t" - // + locOrder.getKeySet().size()); + System.out.println("~~~\t" + md.getClassDesc() + "_" + md + "\t" + + locOrder.getKeySet().size()); + } + + } + + private void debug_countNumLocations() { + + BuildLattice buildLattice = new BuildLattice(); + + for (Iterator iterator = cd2lattice.keySet().iterator(); iterator.hasNext();) { + ClassDescriptor cd = (ClassDescriptor) iterator.next(); + SSJavaLattice lattice = cd2lattice.get(cd).clone(); + SSJavaLattice completeLattice = debug_buildCompleteLattice(buildLattice, cd, lattice); + mapDescToCompleteLattice.put(cd, completeLattice); + writeLatticeDotFile(cd, null, completeLattice); + } + + for (Iterator iterator = md2lattice.keySet().iterator(); iterator.hasNext();) { + MethodDescriptor md = (MethodDescriptor) iterator.next(); + SSJavaLattice lattice = md2lattice.get(md).clone(); + SSJavaLattice completeLattice = debug_buildCompleteLattice(buildLattice, md, lattice); + mapDescToCompleteLattice.put(md, completeLattice); + writeLatticeDotFile(md.getClassDesc(), md, completeLattice); + } + + for (Iterator iterator = annotationRequireSet.iterator(); iterator.hasNext();) { + MethodDescriptor md = (MethodDescriptor) iterator.next(); + SSJavaLattice lattice = getMethodLattice(md).clone(); + if (!mapDescToCompleteLattice.containsKey(md)) { + System.out.println("@NOT FOUND!"); + SSJavaLattice completeLattice = + debug_buildCompleteLattice(buildLattice, md, lattice); + mapDescToCompleteLattice.put(md, completeLattice); + writeLatticeDotFile(md.getClassDesc(), md, completeLattice); + } + } + + writeNumLocsPathsCSVFile(); + + } + + public SSJavaLattice debug_buildCompleteLattice(BuildLattice buildLattice, + Descriptor desc, SSJavaLattice lattice) { + + // First, create a hierarchy graph + HierarchyGraph hierarchyGraph = new HierarchyGraph(); + Set keySet = lattice.getKeySet(); + + Map mapLocNameToDesc = new HashMap(); + + for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) { + String higher = (String) iterator2.next(); + Set lowerSet = lattice.get(higher); + if (!mapLocNameToDesc.containsKey(higher)) { + mapLocNameToDesc.put(higher, new NameDescriptor(higher)); + } + + Descriptor higherDesc = mapLocNameToDesc.get(higher); + + for (Iterator iterator3 = lowerSet.iterator(); iterator3.hasNext();) { + String lower = (String) iterator3.next(); + if (!mapLocNameToDesc.containsKey(lower)) { + mapLocNameToDesc.put(lower, new NameDescriptor(lower)); + } + Descriptor lowerDesc = mapLocNameToDesc.get(lower); + hierarchyGraph.addEdge(higherDesc, lowerDesc); + } } + + BasisSet basisSet = hierarchyGraph.computeBasisSet(new HashSet()); + + SSJavaLattice completeLattice = buildLattice.buildLattice(hierarchyGraph); + + int numLocs = completeLattice.getKeySet().size() + 1; + LocationInference.numLocationsSInfer += numLocs; + mapNumLocsMapManual.put(desc, new Integer(numLocs)); + + System.out.println(desc + "::" + "lattice=" + lattice.getKeySet().size() + " complete=" + + numLocs); + + int numPaths = completeLattice.countPaths(); + LocationInference.numLocationsSInfer += numPaths; + mapNumPathsMapManual.put(desc, new Integer(numPaths)); + + return completeLattice; + } + + public void writeNumLocsPathsCSVFile() { + + try { + BufferedWriter bw = new BufferedWriter(new FileWriter("manualnumbers.csv")); + + Set keySet = mapNumLocsMapManual.keySet(); + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + Descriptor desc = (Descriptor) iterator.next(); + int numLocs = mapNumLocsMapManual.get(desc); + int numPaths = mapNumPathsMapManual.get(desc); + bw.write(desc.getSymbol().replaceAll("[,]", "") + "," + numLocs + "," + numPaths + "\n"); + } + bw.close(); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } public void init() {