+ doMethodAnnotationCheck();
+
+ if (state.SSJAVA && !state.SSJAVAINFER) {
+ init();
+ computeLinearTypeCheckMethodSet();
+ doLinearTypeCheck();
+ }
+
+ if (state.SSJAVADEBUG) {
+ // debug_printAnnotationRequiredSet();
+ }
+ if (state.SSJAVAINFER) {
+ inference();
+ System.exit(0);
+ } else {
+ parseLocationAnnotation();
+ debug_countNumLocations();
+ // System.exit(0);
+ doFlowDownCheck();
+ doDefinitelyWrittenCheck();
+ doLoopCheck();
+ }
+
+ for (Iterator iterator = annotationRequireSet.iterator(); iterator.hasNext();) {
+ MethodDescriptor md = (MethodDescriptor) iterator.next();
+ MethodLattice<String> locOrder = getMethodLattice(md);
+ writeLatticeDotFile(md.getClassDesc(), md, getMethodLattice(md));
+ 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<String> lattice = cd2lattice.get(cd).clone();
+ SSJavaLattice<String> 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<String> lattice = md2lattice.get(md).clone();
+ SSJavaLattice<String> 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<String> lattice = getMethodLattice(md).clone();
+ if (!mapDescToCompleteLattice.containsKey(md)) {
+ System.out.println("@NOT FOUND!");
+ SSJavaLattice<String> completeLattice =
+ debug_buildCompleteLattice(buildLattice, md, lattice);
+ mapDescToCompleteLattice.put(md, completeLattice);
+ writeLatticeDotFile(md.getClassDesc(), md, completeLattice);
+ }
+ }
+
+ writeNumLocsPathsCSVFile();
+
+ }
+
+ public SSJavaLattice<String> debug_buildCompleteLattice(BuildLattice buildLattice,
+ Descriptor desc, SSJavaLattice<String> lattice) {
+
+ // First, create a hierarchy graph
+ HierarchyGraph hierarchyGraph = new HierarchyGraph();
+ Set<String> keySet = lattice.getKeySet();
+
+ Map<String, Descriptor> mapLocNameToDesc = new HashMap<String, Descriptor>();
+
+ for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
+ String higher = (String) iterator2.next();
+ Set<String> 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<HNode>());
+
+ SSJavaLattice<String> completeLattice = buildLattice.buildLattice(hierarchyGraph);
+
+ int numLocs = completeLattice.getKeySet().size();
+ 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<Descriptor> 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() {
+ // perform topological sort over the set of methods accessed by the main
+ // event loop
+ Set<MethodDescriptor> methodDescriptorsToAnalyze = new HashSet<MethodDescriptor>();
+ methodDescriptorsToAnalyze.addAll(getAnnotationRequireSet());
+ sortedDescriptors = topologicalSort(methodDescriptorsToAnalyze);
+ }
+
+ public LinkedList<MethodDescriptor> getSortedDescriptors() {
+ return (LinkedList<MethodDescriptor>) sortedDescriptors.clone();
+ }
+
+ public void addSharedDesc(Location loc, Descriptor fd) {
+ if (!mapSharedLocToDescSet.containsKey(loc)) {
+ mapSharedLocToDescSet.put(loc, new HashSet<Descriptor>());
+ }
+ mapSharedLocToDescSet.get(loc).add(fd);
+ }
+
+ public Set<Descriptor> getSharedDescSet(Location loc) {
+ return mapSharedLocToDescSet.get(loc);
+ }
+
+ private void inference() {
+ LocationInference inferEngine = new LocationInference(this, state, tu);
+ inferEngine.inference();
+ }
+
+ private void doLoopCheck() {
+ GlobalFieldType gft = new GlobalFieldType(callgraph, state, tu.getMain());
+ LoopOptimize lo = new LoopOptimize(gft, tu);
+
+ SymbolTable classtable = state.getClassSymbolTable();
+
+ List<ClassDescriptor> toanalyzeList = new ArrayList<ClassDescriptor>();
+ List<MethodDescriptor> toanalyzeMethodList = new ArrayList<MethodDescriptor>();
+
+ toanalyzeList.addAll(classtable.getValueSet());
+ Collections.sort(toanalyzeList, new Comparator<ClassDescriptor>() {
+ public int compare(ClassDescriptor o1, ClassDescriptor o2) {
+ return o1.getClassName().compareTo(o2.getClassName());
+ }
+ });
+
+ for (int i = 0; i < toanalyzeList.size(); i++) {
+ ClassDescriptor cd = toanalyzeList.get(i);
+
+ SymbolTable methodtable = cd.getMethodTable();
+ toanalyzeMethodList.clear();
+ toanalyzeMethodList.addAll(methodtable.getValueSet());
+ Collections.sort(toanalyzeMethodList, new Comparator<MethodDescriptor>() {
+ public int compare(MethodDescriptor o1, MethodDescriptor o2) {
+ return o1.getSymbol().compareTo(o2.getSymbol());
+ }
+ });
+
+ for (int mdIdx = 0; mdIdx < toanalyzeMethodList.size(); mdIdx++) {
+ MethodDescriptor md = toanalyzeMethodList.get(mdIdx);
+ if (needTobeAnnotated(md)) {
+ lo.analyze(state.getMethodFlat(md));
+ doLoopTerminationCheck(lo, state.getMethodFlat(md));
+ }
+ }
+
+ }
+