From 531f76a639946cbb8080845674ccdba3c5fe1c2f Mon Sep 17 00:00:00 2001 From: yeom Date: Thu, 16 Aug 2012 15:16:03 +0000 Subject: [PATCH] changes. --- .../Analysis/SSJava/LocationInference.java | 73 +++++++++++-------- Robust/src/Analysis/SSJava/SSJavaLattice.java | 15 ++++ 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index 5957fa44..688627cf 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -349,7 +349,6 @@ public class LocationInference { int classDefLine = mapDescToDefinitionLine.get(cd); Vector sourceVec = mapFileNameToLineVector.get(sourceFileName); - if (locInfo == null) { locInfo = getLocationInfo(cd); @@ -634,11 +633,12 @@ public class LocationInference { ssjava.init(); LinkedList descriptorListToAnalyze = ssjava.getSortedDescriptors(); - Collections.sort(descriptorListToAnalyze, new Comparator() { - public int compare(MethodDescriptor o1, MethodDescriptor o2) { - return o1.getSymbol().compareToIgnoreCase(o2.getSymbol()); - } - }); + // Collections.sort(descriptorListToAnalyze, new + // Comparator() { + // public int compare(MethodDescriptor o1, MethodDescriptor o2) { + // return o1.getSymbol().compareToIgnoreCase(o2.getSymbol()); + // } + // }); // current descriptors to visit in fixed-point interprocedural analysis, // prioritized by @@ -864,12 +864,28 @@ public class LocationInference { } } + // create mapping from param idx to inferred composite location + + int offset; + if (!md.isStatic()) { + // add 'this' reference location + offset = 1; + methodInfo.addMapParamIdxToInferLoc(0, methodInfo.getInferLocation(md.getThis())); + } else { + offset = 0; + } + + for (int idx = 0; idx < md.numParameters(); idx++) { + Descriptor paramDesc = md.getParameter(idx); + CompositeLocation inferParamLoc = methodInfo.getInferLocation(paramDesc); + methodInfo.addMapParamIdxToInferLoc(idx + offset, inferParamLoc); + } + } private void calculateExtraLocations(MethodDescriptor md) { // calcualte pcloc, returnloc,... - System.out.println("#calculateExtraLocations=" + md); SSJavaLattice methodLattice = getMethodLattice(md); MethodLocationInfo methodInfo = getMethodLocationInfo(md); FlowGraph fg = getFlowGraph(md); @@ -887,23 +903,6 @@ public class LocationInference { } } - // create mapping from param idx to inferred composite location - - int offset; - if (!md.isStatic()) { - // add 'this' reference location - offset = 1; - methodInfo.addMapParamIdxToInferLoc(0, methodInfo.getInferLocation(md.getThis())); - } else { - offset = 0; - } - - for (int idx = 0; idx < md.numParameters(); idx++) { - Descriptor paramDesc = md.getParameter(idx); - CompositeLocation inferParamLoc = methodInfo.getInferLocation(paramDesc); - methodInfo.addMapParamIdxToInferLoc(idx + offset, inferParamLoc); - } - Map mapParamToLoc = methodInfo.getMapParamIdxToInferLoc(); Set keySet = mapParamToLoc.keySet(); @@ -912,6 +911,7 @@ public class LocationInference { // calculate the initial program counter location // PC location is higher than location types of all parameters String pcLocSymbol = "PCLOC"; + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { Integer paramIdx = (Integer) iterator.next(); CompositeLocation inferLoc = mapParamToLoc.get(paramIdx); @@ -927,6 +927,16 @@ public class LocationInference { } } } + + Set locElementSet = methodLattice.getElementSet(); + locElementSet.remove(pcLocSymbol); + for (Iterator iterator = locElementSet.iterator(); iterator.hasNext();) { + String loc = (String) iterator.next(); + if (!methodLattice.isGreaterThan(pcLocSymbol, loc)) { + addRelationHigherToLower(methodLattice, methodInfo, pcLocSymbol, loc); + } + } + } // calculate a return location @@ -934,7 +944,6 @@ public class LocationInference { // types // of return values if (!md.getReturnType().isVoid()) { - System.out.println("@@@@@ RETURN md=" + md); // first, generate the set of return value location types that starts // with // 'this' reference @@ -1143,6 +1152,7 @@ public class LocationInference { MethodDescriptor possibleMdCallee, SSJavaLattice methodLattice, MethodLocationInfo methodInfo) throws CyclicFlowException { + SSJavaLattice calleeLattice = getMethodLattice(possibleMdCallee); MethodLocationInfo calleeLocInfo = getMethodLocationInfo(possibleMdCallee); FlowGraph calleeFlowGraph = getFlowGraph(possibleMdCallee); @@ -1153,6 +1163,7 @@ public class LocationInference { for (int k = 0; k < numParam; k++) { if (i != k) { CompositeLocation param2 = calleeLocInfo.getParamCompositeLocation(k); + if (isGreaterThan(getLattice(possibleMdCallee), param1, param2)) { NodeTupleSet argDescTupleSet1 = getNodeTupleSetByArgIdx(min, i); NodeTupleSet argDescTupleSet2 = getNodeTupleSetByArgIdx(min, k); @@ -1866,7 +1877,6 @@ public class LocationInference { LinkedList methodDescList = computeMethodList(); - while (!methodDescList.isEmpty()) { MethodDescriptor md = methodDescList.removeLast(); if (state.SSJAVADEBUG) { @@ -2211,6 +2221,7 @@ public class LocationInference { private void analyzeFlowMethodInvokeNode(MethodDescriptor md, SymbolTable nametable, MethodInvokeNode min, NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) { + if (nodeSet == null) { nodeSet = new NodeTupleSet(); } @@ -2226,8 +2237,7 @@ public class LocationInference { } if (!ssjava.isSSJavaUtil(calleeMethodDesc.getClassDesc()) - && !ssjava.isTrustMethod(calleeMethodDesc) && !calleeMethodDesc.getModifiers().isNative() - && !isSystemout) { + && !ssjava.isTrustMethod(calleeMethodDesc) && !isSystemout) { FlowGraph calleeFlowGraph = getFlowGraph(calleeMethodDesc); Set calleeReturnSet = calleeFlowGraph.getReturnNodeSet(); @@ -2238,9 +2248,11 @@ public class LocationInference { analyzeFlowExpressionNode(md, nametable, min.getExpression(), baseNodeSet, null, implicitFlowTupleSet, false); + if (!min.getMethod().isStatic()) { addArgIdxMap(min, 0, baseNodeSet); + for (Iterator iterator = calleeReturnSet.iterator(); iterator.hasNext();) { FlowNode returnNode = (FlowNode) iterator.next(); NTuple returnDescTuple = returnNode.getDescTuple(); @@ -2282,11 +2294,12 @@ public class LocationInference { ExpressionNode en = min.getArg(i); int idx = i + offset; NodeTupleSet argTupleSet = new NodeTupleSet(); - analyzeFlowExpressionNode(md, nametable, en, argTupleSet, false); + analyzeFlowExpressionNode(md, nametable, en, argTupleSet, true); // if argument is liternal node, argTuple is set to NULL. addArgIdxMap(min, idx, argTupleSet); FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx); - if (hasInFlowTo(calleeFlowGraph, paramNode, calleeReturnSet)) { + if (hasInFlowTo(calleeFlowGraph, paramNode, calleeReturnSet) + || calleeMethodDesc.getModifiers().isNative()) { addParamNodeFlowingToReturnValue(calleeMethodDesc, paramNode); nodeSet.addTupleSet(argTupleSet); } diff --git a/Robust/src/Analysis/SSJava/SSJavaLattice.java b/Robust/src/Analysis/SSJava/SSJavaLattice.java index e2c85f29..2611d9f7 100644 --- a/Robust/src/Analysis/SSJava/SSJavaLattice.java +++ b/Robust/src/Analysis/SSJava/SSJavaLattice.java @@ -27,6 +27,21 @@ public class SSJavaLattice extends Lattice { public boolean isSharedLoc(T loc) { return sharedLocSet.contains(loc); } + + public Set getElementSet(){ + Set set=new HashSet(); + + Set keySet=getKeySet(); + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + T key = (T) iterator.next(); + set.add(key); + set.addAll(getTable().get(key)); + } + + set.remove(getTopItem()); + set.remove(getBottomItem()); + return set; + } public boolean addRelationHigherToLower(T higher, T lower) { -- 2.34.1