From 9e11ce79473fe199b045066b384fdfed8eb022ea Mon Sep 17 00:00:00 2001 From: yeom Date: Sat, 13 Oct 2012 01:52:42 +0000 Subject: [PATCH] changes to pass the location type check. --- Robust/src/Analysis/SSJava/BuildLattice.java | 26 ++- .../src/Analysis/SSJava/HierarchyGraph.java | 75 +++++-- .../Analysis/SSJava/LocationInference.java | 190 +++++++++++------- .../src/Analysis/SSJava/LocationSummary.java | 2 +- Robust/src/Analysis/SSJava/MethodSummary.java | 28 +++ 5 files changed, 220 insertions(+), 101 deletions(-) diff --git a/Robust/src/Analysis/SSJava/BuildLattice.java b/Robust/src/Analysis/SSJava/BuildLattice.java index eb38f270..621f9efd 100644 --- a/Robust/src/Analysis/SSJava/BuildLattice.java +++ b/Robust/src/Analysis/SSJava/BuildLattice.java @@ -58,6 +58,8 @@ public class BuildLattice { lattice.addSharedLoc(higherName); } Set descSet = inputGraph.getDescSetOfNode(higherNode); + // System.out.println("higherName=" + higherName + " higherNode=" + higherNode + " descSet=" + // + descSet); for (Iterator iterator2 = descSet.iterator(); iterator2.hasNext();) { Descriptor d = (Descriptor) iterator2.next(); locSummary.addMapHNodeNameToLocationName(d.getSymbol(), higherName); @@ -69,13 +71,21 @@ public class BuildLattice { Set lower = (Set) iterator2.next(); String lowerName = generateElementName(basisSet, inputGraph, mapFToLocName, lower); - locSummary.addMapHNodeNameToLocationName(lowerName, lowerName); - - HNode lowerNode = inputGraph.getHNode(higherName); + HNode lowerNode = inputGraph.getHNode(lowerName); if (lowerNode != null && lowerNode.isSharedNode()) { lattice.addSharedLoc(lowerName); } + Set lowerDescSet = inputGraph.getDescSetOfNode(lowerNode); + // System.out.println("lowerName=" + lowerName + " lowerNode=" + lowerNode + " descSet=" + // + lowerDescSet); + for (Iterator iterator3 = lowerDescSet.iterator(); iterator3.hasNext();) { + Descriptor d = (Descriptor) iterator3.next(); + locSummary.addMapHNodeNameToLocationName(d.getSymbol(), lowerName); + } + // locSummary.addMapHNodeNameToLocationName(lowerName, lowerName); + + // System.out.println("higherName=" + higherName + " lowerName=" + lowerName); if (higher.size() == 0) { // empty case lattice.put(lowerName); @@ -131,7 +141,7 @@ public class BuildLattice { for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { HNode node = (HNode) iterator.next(); - System.out.println("node=" + node); + // System.out.println("node=" + node); if (node.isSkeleton() && (!visited.contains(node))) { visited.add(node); @@ -176,7 +186,7 @@ public class BuildLattice { } else { // we have a node that is neither combination or skeleton node - System.out.println("%%%skeleton node=" + node + " outNode=" + outNode); + // System.out.println("%%%skeleton node=" + node + " outNode=" + outNode); HNode startNode = scGraph.getCurrentHNode(node); // if (node.getDescriptor() != null) { @@ -191,14 +201,14 @@ public class BuildLattice { Set endNodeSetFromSimpleGraph = simpleGraph.getDirectlyReachableSkeletonCombinationNodeFrom(outNode, null); - System.out.println("endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph - + " from=" + outNode); + // System.out.println("endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph + // + " from=" + outNode); Set endCombNodeSet = new HashSet(); for (Iterator iterator3 = endNodeSetFromSimpleGraph.iterator(); iterator3.hasNext();) { HNode endNode = (HNode) iterator3.next(); endCombNodeSet.add(getCombinationNodeInSCGraph(desc, endNode)); } - System.out.println("endCombNodeSet=" + endCombNodeSet); + // System.out.println("endCombNodeSet=" + endCombNodeSet); visited.add(outNode); if (endCombNodeSet.size() > 0) { // follows the straight line up to another skeleton/combination node diff --git a/Robust/src/Analysis/SSJava/HierarchyGraph.java b/Robust/src/Analysis/SSJava/HierarchyGraph.java index 304121c7..50744f01 100644 --- a/Robust/src/Analysis/SSJava/HierarchyGraph.java +++ b/Robust/src/Analysis/SSJava/HierarchyGraph.java @@ -11,6 +11,7 @@ import java.util.Set; import IR.Descriptor; import IR.FieldDescriptor; +import IR.VarDescriptor; public class HierarchyGraph { @@ -33,8 +34,6 @@ public class HierarchyGraph { Map, HNode> mapCombineNodeSetToCombinationNode; Map, Set> mapCombineNodeSetToOutgoingNodeSet; - Map mapHNodeToLocationName; - Set nodeSet; public static int seed = 0; @@ -58,7 +57,6 @@ public class HierarchyGraph { mapHNodeToUniqueIndex = new HashMap(); mapHNodeToBasis = new HashMap>(); - mapHNodeToLocationName = new HashMap(); mapMergeNodetoMergingSet = new HashMap>(); mapHNodeToCurrentHNode = new HashMap(); @@ -73,14 +71,6 @@ public class HierarchyGraph { this.desc = desc; } - public void addMapHNodeToLocationName(HNode node, String locName) { - mapHNodeToLocationName.put(node, locName); - } - - public String getLocationName(HNode node) { - return mapHNodeToLocationName.get(node); - } - public String getName() { return name; } @@ -326,6 +316,10 @@ public class HierarchyGraph { continue; } + if (!isEligibleForMerging(node1, node2)) { + continue; + } + if (!node1.equals(node2)) { Set incomingNodeSet2 = getIncomingNodeSet(node2); @@ -349,6 +343,44 @@ public class HierarchyGraph { return false; } + private boolean isEligibleForMerging(HNode node1, HNode node2) { + + System.out.println("********isEligibleForMerging=" + node1 + " " + node2); + + if (node1.isSharedNode() || node2.isSharedNode()) { + + // if either of nodes is a shared node, + // all descriptors of node1 & node2 should have a primitive type + + Set descSet = new HashSet(); + descSet.addAll(getDescSetOfNode(node1)); + descSet.addAll(getDescSetOfNode(node2)); + + for (Iterator iterator = descSet.iterator(); iterator.hasNext();) { + Descriptor desc = (Descriptor) iterator.next(); + if (!isPrimitive(desc)) { + return false; + } + } + System.out.println("******** true"); + return true; + } + return false; + } + + private boolean isPrimitive(Descriptor desc) { + + if (desc instanceof FieldDescriptor) { + return ((FieldDescriptor) desc).getType().isPrimitive(); + } else if (desc instanceof VarDescriptor) { + return ((VarDescriptor) desc).getType().isPrimitive(); + } else if (desc instanceof InterDescriptor) { + return true; + } + + return false; + } + private void addEdgeWithNoCycleCheck(HNode srcHNode, HNode dstHNode) { getIncomingNodeSet(dstHNode).add(srcHNode); getOutgoingNodeSet(srcHNode).add(dstHNode); @@ -432,14 +464,23 @@ public class HierarchyGraph { HNode mergedNode = (HNode) iterator.next(); addMapHNodeToCurrentHNode(mergedNode, newMergeNode); } - + System.out.println("\n###mergedSkeletonNode=" + mergedSkeletonNode); System.out.println("###MERGING NODE=" + set + " new node=" + newMergeNode); + + for (Iterator iterator = set.iterator(); iterator.hasNext();) { + HNode hNode = (HNode) iterator.next(); + System.out.println("old=" + hNode + "----->newNode=" + getCurrentHNode(hNode)); + } + return newMergeNode; } private void addMapHNodeToCurrentHNode(HNode curNode, HNode newNode) { if (curNode.isMergeNode()) { Set mergingSet = getMergingSet(curNode); + mergingSet.add(curNode); + System.out.println("addMapHNodeToCurrentHNode curNode=" + curNode + " meringSet=" + + mergingSet); for (Iterator iterator = mergingSet.iterator(); iterator.hasNext();) { HNode mergingNode = (HNode) iterator.next(); mapHNodeToCurrentHNode.put(mergingNode, newNode); @@ -462,6 +503,7 @@ public class HierarchyGraph { for (Iterator iterator = mergedNode.iterator(); iterator.hasNext();) { HNode node = (HNode) iterator.next(); if (node.isMergeNode()) { + mergingSet.add(node); mergingSet.addAll(getMergingSet(node)); } else { mergingSet.add(node); @@ -669,8 +711,10 @@ public class HierarchyGraph { HNode outNode = getCombinationNode(combineNode); addEdgeWithNoCycleCheck(combinationNode, outNode); } else if (curNode.isSkeleton()) { - // HNode dstNode = getHNode(curNode.getDescriptor()); + // HNode dstNode2 = getHNode(curNode.getDescriptor()); HNode dstNode = getCurrentHNode(curNode); + // System.out.println("-----curNode=" + curNode + "------->" + dstNode + " dstNode2=" + // + dstNode2); addEdgeWithNoCycleCheck(combinationNode, dstNode); } } @@ -934,6 +978,7 @@ public class HierarchyGraph { public void assignUniqueIndexToNode() { int idx = 1; + System.out.println("nodeSet=" + nodeSet); for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { HNode node = (HNode) iterator.next(); mapHNodeToUniqueIndex.put(node, idx); @@ -960,7 +1005,7 @@ public class HierarchyGraph { Set reachableNodeSet = getReachableNodeSetFrom(node); System.out.println("node=" + node + " reachableNodeSet=" + reachableNodeSet); - + System.out.println("mapHNodeToUniqueIndex.get(node)=" + mapHNodeToUniqueIndex.get(node)); // if a node is reachable from the current node // need to remove the index of the reachable node from the basis @@ -968,6 +1013,8 @@ public class HierarchyGraph { for (Iterator iterator2 = reachableNodeSet.iterator(); iterator2.hasNext();) { HNode reachableNode = (HNode) iterator2.next(); System.out.println("reachableNode=" + reachableNode); + System.out.println("getHNodeIndex(reachableNode))=" + + mapHNodeToUniqueIndex.get(reachableNode)); int idx = getHNodeIndex(reachableNode); basis.remove(idx); } diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index e2c808c7..b1399149 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -132,6 +132,8 @@ public class LocationInference { public static final Descriptor TOPDESC = new NameDescriptor(TOPLOC); + public static final Descriptor RETURNLOC = new NameDescriptor(RLOC); + public static String newline = System.getProperty("line.separator"); LocationInfo curMethodInfo; @@ -226,6 +228,8 @@ public class LocationInference { assignCompositeLocation(); + // System.exit(0); + constructHierarchyGraph(); debug_writeHierarchyDotFiles(); @@ -257,17 +261,6 @@ public class LocationInference { System.exit(0); - // 2) construct lattices - // inferLattices(); - // simplifyLattices(); - // 3) check properties - // checkLattices(); - - debug_writeLatticeDotFile(); - - // 4) generate annotated source codes - generateAnnoatedCode(); - } public Map, NTuple> getMapCallerArgToCalleeParam( @@ -304,6 +297,9 @@ public class LocationInference { while (!methodDescList.isEmpty()) { MethodDescriptor md = methodDescList.removeLast(); + + System.out.println("\n#updateCompositeLocationAssignments=" + md); + FlowGraph flowGraph = getFlowGraph(md); MethodSummary methodSummary = getMethodSummary(md); @@ -311,15 +307,18 @@ public class LocationInference { Set nodeSet = flowGraph.getNodeSet(); for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { FlowNode node = (FlowNode) iterator.next(); + System.out.println("-node=" + node + " node.getDescTuple=" + node.getDescTuple()); if (node.getCompositeLocation() != null) { CompositeLocation compLoc = node.getCompositeLocation(); CompositeLocation updatedCompLoc = updateCompositeLocation(compLoc); node.setCompositeLocation(updatedCompLoc); + System.out.println("---updatedCompLoc1=" + updatedCompLoc); } else { NTuple descTuple = node.getDescTuple(); CompositeLocation compLoc = convertToCompositeLocation(md, descTuple); compLoc = updateCompositeLocation(compLoc); node.setCompositeLocation(compLoc); + System.out.println("---updatedCompLoc2=" + compLoc); } if (node.isDeclaratonNode()) { @@ -328,6 +327,14 @@ public class LocationInference { } } + // update PCLOC and RETURNLOC if they have a composite location assignment + if (methodSummary.getRETURNLoc() != null) { + methodSummary.setRETURNLoc(updateCompositeLocation(methodSummary.getRETURNLoc())); + } + if (methodSummary.getPCLoc() != null) { + methodSummary.setPCLoc(updateCompositeLocation(methodSummary.getPCLoc())); + } + } } @@ -338,7 +345,6 @@ public class LocationInference { Location loc = compLoc.get(i); String nodeIdentifier = loc.getLocIdentifier(); Descriptor enclosingDesc = loc.getDescriptor(); - System.out.println("enclosingDesc=" + enclosingDesc); String locName; if (!enclosingDesc.equals(GLOBALDESC)) { LocationSummary locSummary = getLocationSummary(enclosingDesc); @@ -380,12 +386,7 @@ public class LocationInference { MethodInvokeNode min = (MethodInvokeNode) iterator.next(); // need to translate a composite location that is started with the base // tuple of 'min'. - if (mapMethodInvokeNodeToBaseTuple.get(min) != null) { - // if mapMethodInvokeNodeToBaseTuple doesn't have a mapping - // it means that the corresponding callee method does not cause any - // flows - translateMapLocationToInferCompositeLocationToCalleeGraph(callerGlobalFlowGraph, min); - } + translateMapLocationToInferCompositeLocationToCalleeGraph(callerGlobalFlowGraph, min); calleeSet.add(min.getMethod()); } @@ -453,8 +454,10 @@ public class LocationInference { FlowGraph calleeFlowGraph = getFlowGraph(mdCallee); GlobalFlowGraph calleeGlobalGraph = getSubGlobalFlowGraph(mdCallee); - NTuple baseLocTuple = - translateToLocTuple(mdCaller, mapMethodInvokeNodeToBaseTuple.get(min)); + NTuple baseLocTuple = null; + if (mapMethodInvokeNodeToBaseTuple.containsKey(min)) { + baseLocTuple = translateToLocTuple(mdCaller, mapMethodInvokeNodeToBaseTuple.get(min)); + } // System.out.println("\n-translate caller infer composite loc to callee=" + mdCallee // + " baseLocTuple=" + baseLocTuple); @@ -464,23 +467,33 @@ public class LocationInference { CompositeLocation callerCompLoc = callerMapLocToCompLoc.get(key); if (!key.getDescriptor().equals(mdCaller)) { - // System.out.println("--- caller key=" + key + " callerCompLoc=" + callerCompLoc); - - // && callerCompLoc.getTuple().startsWith(baseLocTuple)) { - // need to translate to the callee side - // TODO CompositeLocation newCalleeCompLoc; - if (callerCompLoc.getTuple().startsWith(baseLocTuple)) { - System.out.println("---need to translate callerCompLoc=" + callerCompLoc - + " with baseTuple=" + baseLocTuple); + if (baseLocTuple != null && callerCompLoc.getTuple().startsWith(baseLocTuple)) { + // System.out.println("---need to translate callerCompLoc=" + callerCompLoc + // + " with baseTuple=" + baseLocTuple); newCalleeCompLoc = translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee); calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc); - System.out.println("---callee loc=" + key + " newCalleeCompLoc=" + newCalleeCompLoc); + // System.out.println("---callee loc=" + key + " newCalleeCompLoc=" + newCalleeCompLoc); } else { - // newCalleeCompLoc = callerCompLoc.clone(); + // check if it is the global access + Location compLocFirstElement = callerCompLoc.getTuple().get(0); + if (compLocFirstElement.getDescriptor().equals(mdCallee) + && compLocFirstElement.getLocDescriptor().equals(GLOBALDESC)) { + + newCalleeCompLoc = new CompositeLocation(); + Location newMethodLoc = new Location(mdCallee, GLOBALDESC); + + newCalleeCompLoc.addLocation(newMethodLoc); + for (int i = 1; i < callerCompLoc.getSize(); i++) { + newCalleeCompLoc.addLocation(callerCompLoc.get(i)); + } + calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc); + + } + } } @@ -513,7 +526,7 @@ public class LocationInference { callerCompLoc.addLocation(argLocTuple.get(i)); } - if (callerCompLoc.getTuple().startsWith(baseLocTuple)) { + if (baseLocTuple != null && callerCompLoc.getTuple().startsWith(baseLocTuple)) { FlowNode calleeParamFlowNode = calleeFlowGraph.getParamFlowNode(idx); NTuple calleeParamDescTuple = calleeParamFlowNode.getDescTuple(); @@ -589,6 +602,7 @@ public class LocationInference { next: for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { GlobalFlowNode node = (GlobalFlowNode) iterator.next(); + System.out.println("-GlobalFlowNode=" + node); Location prefixLoc = node.getLocTuple().get(0); if (calculatedPrefixSet.contains(prefixLoc)) { @@ -960,13 +974,8 @@ public class LocationInference { private NTuple translateToCallerLocTuple(MethodInvokeNode min, MethodDescriptor mdCallee, MethodDescriptor mdCaller, NTuple nodeLocTuple) { - // this method will return NULL if the corresponding argument is literal + // this method will return the same nodeLocTuple if the corresponding argument is literal // value. - // assumes that we don't need to propagate callee flows to the argument - // which is literal. - - // System.out.println("---translateToCallerLocTuple=" + min.printNode(0) - // + " callee nodeLocTuple=" + nodeLocTuple); FlowGraph calleeFlowGraph = getFlowGraph(mdCallee); @@ -974,12 +983,10 @@ public class LocationInference { if (calleeFlowGraph.isParameter(nodeDescTuple)) { int paramIdx = calleeFlowGraph.getParamIdx(nodeDescTuple); NTuple argDescTuple = mapMethodInvokeNodeToArgIdxMap.get(min).get(paramIdx); - // System.out.println(" mapMethodInvokeNodeToArgIdxMap.get(min)=" - // + mapMethodInvokeNodeToArgIdxMap.get(min)); if (argDescTuple.size() == 0) { // argument is literal - return null; + return nodeLocTuple.clone(); } NTuple argLocTuple = translateToLocTuple(mdCaller, argDescTuple); @@ -1206,10 +1213,21 @@ public class LocationInference { FlowGraph flowGraph = getFlowGraph(md); MethodSummary methodSummary = getMethodSummary(md); - // construct a parameter mapping that maps a parameter descriptor to an - // inferred composite - // location + HierarchyGraph scGraph = getSkeletonCombinationHierarchyGraph(md); + + // set the 'this' reference location + if (!md.isStatic()) { + System.out.println("setThisLocName=" + scGraph.getHNode(md.getThis()).getName()); + methodSummary.setThisLocName(scGraph.getHNode(md.getThis()).getName()); + } + // set the 'global' reference location if needed + if (methodSummary.hasGlobalAccess()) { + methodSummary.setGlobalLocName(scGraph.getHNode(GLOBALDESC).getName()); + } + + // construct a parameter mapping that maps a parameter descriptor to an + // inferred composite location for (int paramIdx = 0; paramIdx < flowGraph.getNumParameters(); paramIdx++) { FlowNode flowNode = flowGraph.getParamFlowNode(paramIdx); CompositeLocation inferredCompLoc = flowNode.getCompositeLocation(); @@ -1604,6 +1622,18 @@ public class LocationInference { } + setupToAnalyze(); + while (!toAnalyzeIsEmpty()) { + ClassDescriptor cd = toAnalyzeNext(); + HierarchyGraph graph = getHierarchyGraph(cd); + for (Iterator iter = cd.getFields(); iter.hasNext();) { + FieldDescriptor fieldDesc = (FieldDescriptor) iter.next(); + if (!(fieldDesc.isStatic() && fieldDesc.isFinal())) { + graph.getHNode(fieldDesc); + } + } + } + } private HierarchyGraph getHierarchyGraph(Descriptor d) { @@ -1627,9 +1657,16 @@ public class LocationInference { // for the method lattice, we need to look at the first element of // NTuple + boolean hasGlobalAccess = false; for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { FlowNode srcNode = (FlowNode) iterator.next(); + // if the srcNode is started with the global descriptor + // need to set as a skeleton node + if (!hasGlobalAccess && srcNode.getDescTuple().startsWith(GLOBALDESC)) { + hasGlobalAccess = true; + } + Set outEdgeSet = fg.getOutEdgeSet(srcNode); for (Iterator iterator2 = outEdgeSet.iterator(); iterator2.hasNext();) { FlowEdge outEdge = (FlowEdge) iterator2.next(); @@ -1680,6 +1717,13 @@ public class LocationInference { } } + // If the method accesses static fields + // set hasGloabalAccess true in the method summary. + if (hasGlobalAccess) { + getMethodSummary(md).setHasGlobalAccess(); + } + methodGraph.getHNode(GLOBALDESC).setSkeleton(true); + } private MethodSummary getMethodSummary(MethodDescriptor md) { @@ -1814,22 +1858,24 @@ public class LocationInference { rtr += "\")"; if (desc instanceof MethodDescriptor) { - TypeDescriptor returnType = ((MethodDescriptor) desc).getReturnType(); + System.out.println("#EXTRA LOC DECLARATION GEN=" + desc); MethodSummary methodSummary = getMethodSummary((MethodDescriptor) desc); - if (returnType != null && (!returnType.isVoid())) { - rtr += - "\n@RETURNLOC(\"" + generateLocationAnnoatation(methodSummary.getRETURNLoc()) + "\")"; + if (!ssjava.getMethodContainingSSJavaLoop().equals(desc)) { + TypeDescriptor returnType = ((MethodDescriptor) desc).getReturnType(); + if (returnType != null && (!returnType.isVoid())) { + rtr += + "\n@RETURNLOC(\"" + generateLocationAnnoatation(methodSummary.getRETURNLoc()) + "\")"; + } + CompositeLocation pcLoc = methodSummary.getPCLoc(); + if ((pcLoc != null) && (!pcLoc.get(0).isTop())) { + rtr += "\n@PCLOC(\"" + generateLocationAnnoatation(pcLoc) + "\")"; + } } - rtr += "\n@THISLOC(\"this\")"; - rtr += "\n@GLOBALLOC(\"GLOBALLOC\")"; - - CompositeLocation pcLoc = methodSummary.getPCLoc(); - if ((pcLoc != null) && (!pcLoc.get(0).isTop())) { - rtr += "\n@PCLOC(\"" + generateLocationAnnoatation(pcLoc) + "\")"; - } + rtr += "\n@THISLOC(\"" + methodSummary.getThisLocName() + "\")"; + rtr += "\n@GLOBALLOC(\"" + methodSummary.getGlobalLocName() + "\")"; } @@ -1846,7 +1892,6 @@ public class LocationInference { setupToAnalazeMethod(cd); - LocationInfo locInfo = mapClassToLocationInfo.get(cd); String sourceFileName = cd.getSourceFileName(); if (cd.isInterface()) { @@ -1856,26 +1901,13 @@ public class LocationInference { int classDefLine = mapDescToDefinitionLine.get(cd); Vector sourceVec = mapFileNameToLineVector.get(sourceFileName); - if (locInfo == null) { - locInfo = getLocationInfo(cd); - } - - for (Iterator iter = cd.getFields(); iter.hasNext();) { - FieldDescriptor fieldDesc = (FieldDescriptor) iter.next(); - if (!(fieldDesc.isStatic() && fieldDesc.isFinal())) { - String locIdentifier = locInfo.getFieldInferLocation(fieldDesc).getLocIdentifier(); - if (!getLattice(cd).getElementSet().contains(locIdentifier)) { - getLattice(cd).put(locIdentifier); - } - } - } + LocationSummary fieldLocSummary = getLocationSummary(cd); String fieldLatticeDefStr = generateLatticeDefinition(cd); String annoatedSrc = fieldLatticeDefStr + newline + sourceVec.get(classDefLine); sourceVec.set(classDefLine, annoatedSrc); // generate annotations for field declarations - LocationSummary fieldLocSummary = getLocationSummary(cd); // Map inferLocMap = fieldLocInfo.getMapDescToInferLocation(); Map mapFieldNameToLocName = fieldLocSummary.getMapHNodeNameToLocationName(); @@ -1972,9 +2004,9 @@ public class LocationInference { // reference... // boolean needToAddthisRef = hasThisReference(md); - if (localLocElementSet.contains("this")) { - methodLattice.put("this"); - } + // if (localLocElementSet.contains("this")) { + // methodLattice.put("this"); + // } String methodLatticeDefStr = generateLatticeDefinition(md); String annoatedStr = methodLatticeDefStr + newline + sourceVec.get(methodDefLine); @@ -2252,7 +2284,7 @@ public class LocationInference { return desc; } - private void calcualtePCLOC(MethodDescriptor md) { + private void calculatePCLOC(MethodDescriptor md) { System.out.println("#calcualtePCLOC"); MethodSummary methodSummary = getMethodSummary(md); @@ -2279,9 +2311,8 @@ public class LocationInference { System.out.println("paramLocTupleHavingInFlowSet=" + paramLocTupleHavingInFlowSet); - if (!coversAllParamters(md, fg, paramLocTupleHavingInFlowSet)) { - // if (numParamsWithIncomingValue > 0 && numParamsWithIncomingValue != fg.getNumParameters()) - // { + if (paramLocTupleHavingInFlowSet.size() > 0 + && !coversAllParamters(md, fg, paramLocTupleHavingInFlowSet)) { // Here, generates a location in the method lattice that is higher than the // paramLocTupleHavingInFlowSet @@ -2351,7 +2382,7 @@ public class LocationInference { private void calculateRETURNLOC(MethodDescriptor md) { - System.out.println("#calculateRETURNLOC"); + System.out.println("#calculateRETURNLOC= " + md); // calculate a return location: // the return location type is lower than all parameters and the location of return values @@ -2489,7 +2520,7 @@ public class LocationInference { System.out.println("\nSSJAVA:Calculate PCLOC/RETURNLOC locations: " + md); - calcualtePCLOC(md); + calculatePCLOC(md); calculateRETURNLOC(md); } @@ -3155,6 +3186,9 @@ public class LocationInference { if (lastDescOfPrefix instanceof FieldDescriptor) { enclosingDescriptor = ((FieldDescriptor) lastDescOfPrefix).getType().getClassDesc(); // System.out.println("enclosingDescriptor0=" + enclosingDescriptor); + } else if (lastDescOfPrefix.equals(GLOBALDESC)) { + MethodDescriptor currentMethodDesc = (MethodDescriptor) prefixLocTuple.get(0).getDescriptor(); + enclosingDescriptor = currentMethodDesc.getClassDesc(); } else { // var descriptor case enclosingDescriptor = ((VarDescriptor) lastDescOfPrefix).getType().getClassDesc(); diff --git a/Robust/src/Analysis/SSJava/LocationSummary.java b/Robust/src/Analysis/SSJava/LocationSummary.java index 4682b231..f6aefddc 100644 --- a/Robust/src/Analysis/SSJava/LocationSummary.java +++ b/Robust/src/Analysis/SSJava/LocationSummary.java @@ -12,7 +12,7 @@ public abstract class LocationSummary { } public void addMapHNodeNameToLocationName(String nodeName, String locName) { - System.out.println("nodeName="+nodeName+" locName="+locName); + // System.out.println("nodeName="+nodeName+" locName="+locName); mapHNodeNameToLocationName.put(nodeName, locName); } diff --git a/Robust/src/Analysis/SSJava/MethodSummary.java b/Robust/src/Analysis/SSJava/MethodSummary.java index d2f7916e..333b2240 100644 --- a/Robust/src/Analysis/SSJava/MethodSummary.java +++ b/Robust/src/Analysis/SSJava/MethodSummary.java @@ -19,12 +19,16 @@ public class MethodSummary extends LocationSummary { Map mapParamIdxToInferLoc; Map mapVarDescToInferCompositeLocation; + boolean hasGlobalAccess; + public MethodSummary(MethodDescriptor md) { this.md = md; this.pcLoc = new CompositeLocation(new Location(md, Location.TOP)); this.mapParamIdxToInferLoc = new HashMap(); this.mapVarDescToInferCompositeLocation = new HashMap(); this.thisLocName = "this"; + this.globalLocName = "GLOBAL"; + this.hasGlobalAccess = false; } public Map getMapVarDescToInferCompositeLocation() { @@ -70,4 +74,28 @@ public class MethodSummary extends LocationSummary { return returnLoc; } + public void setThisLocName(String name) { + this.thisLocName = name; + } + + public String getThisLocName() { + return thisLocName; + } + + public void setGlobalLocName(String name) { + this.globalLocName = name; + } + + public String getGlobalLocName() { + return globalLocName; + } + + public void setHasGlobalAccess() { + this.hasGlobalAccess = true; + } + + public boolean hasGlobalAccess() { + return hasGlobalAccess; + } + } -- 2.34.1