X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FSSJava%2FFlowDownCheck.java;h=5dbf31e13b2b5eac195ef64d75da330e7011f091;hb=2dcc891b7dfc2a791c10b820da51755813adefd7;hp=45ceee7537df0f509f70b62a3ababa32bd803424;hpb=1bf00baead0bc7e05945fe5649f9d92afadae081;p=IRC.git diff --git a/Robust/src/Analysis/SSJava/FlowDownCheck.java b/Robust/src/Analysis/SSJava/FlowDownCheck.java index 45ceee75..5dbf31e1 100644 --- a/Robust/src/Analysis/SSJava/FlowDownCheck.java +++ b/Robust/src/Analysis/SSJava/FlowDownCheck.java @@ -226,7 +226,8 @@ public class FlowDownCheck { if (state.SSJAVADEBUG) { System.out.println("SSJAVA: Checking Flow-down Rules: " + md); } - checkMethodBody(cd, md, null); + CompositeLocation calleePCLOC = ssjava.getPCLocation(md); + checkMethodBody(cd, md, calleePCLOC); } } } @@ -320,12 +321,18 @@ public class FlowDownCheck { } else if (an.getMarker().equals(ssjava.THISLOC)) { String thisLoc = an.getValue(); ssjava.getMethodLattice(md).setThisLoc(thisLoc); + } else if (an.getMarker().equals(ssjava.GLOBALLOC)) { + String globalLoc = an.getValue(); + ssjava.getMethodLattice(md).setGlobalLoc(globalLoc); + } else if (an.getMarker().equals(ssjava.PCLOC)) { + String pcLocDeclaration = an.getValue(); + ssjava.setPCLocation(md, parseLocationDeclaration(md, null, pcLocDeclaration)); } } } // second, check return location annotation - if (!md.getReturnType().isVoid()) { + if (!md.getReturnType().isVoid() && !ssjava.getMethodContainingSSJavaLoop().equals(md)) { if (!hasReturnLocDeclaration) { // if developer does not define method lattice // search return location in the method default lattice @@ -344,17 +351,24 @@ public class FlowDownCheck { } - if (!md.getReturnType().isVoid()) { + if (!md.getReturnType().isVoid() && !ssjava.getMethodContainingSSJavaLoop().equals(md)) { MethodLattice methodLattice = ssjava.getMethodLattice(md); String thisLocId = methodLattice.getThisLoc(); - if ((!md.isStatic()) && thisLocId == null) { - throw new Error("Method '" + md + "' does not have the definition of 'this' location at " - + md.getClassDesc().getSourceFileName()); + if ((!md.isStatic())) { + + if (thisLocId == null) { + throw new Error("Method '" + md + "' does not have the definition of 'this' location at " + + md.getClassDesc().getSourceFileName()); + } + + CompositeLocation thisLoc = new CompositeLocation(new Location(md, thisLocId)); + paramList.add(0, thisLoc); + } - CompositeLocation thisLoc = new CompositeLocation(new Location(md, thisLocId)); - paramList.add(0, thisLoc); + md2ReturnLocGen.put(md, new ReturnLocGenerator(md2ReturnLoc.get(md), md, paramList, md + " of " + cd.getSourceFileName())); + } // fourth, check declarations inside of method @@ -538,8 +552,14 @@ public class FlowDownCheck { private CompositeLocation checkLocationFromReturnNode(MethodDescriptor md, SymbolTable nametable, ReturnNode rn, CompositeLocation constraint) { + if (ssjava.getMethodContainingSSJavaLoop().equals(md)) { + return new CompositeLocation(); + } + ExpressionNode returnExp = rn.getReturnExpression(); + CompositeLocation declaredReturnLoc = md2ReturnLoc.get(md); + CompositeLocation returnValueLoc; if (returnExp != null) { returnValueLoc = @@ -561,9 +581,40 @@ public class FlowDownCheck { // generateErrorMessage(md.getClassDesc(), rn)); // } + if (constraint != null) { + + // Set inputGLB = new HashSet(); + // inputGLB.add(returnValueLoc); + // inputGLB.add(constraint); + // returnValueLoc = + // CompositeLattice.calculateGLB(inputGLB, + // generateErrorMessage(md.getClassDesc(), rn)); + + // if (!returnValueLoc.get(returnValueLoc.getSize() - 1).isTop()) { + // if (!CompositeLattice.isGreaterThan(constraint, returnValueLoc, + // generateErrorMessage(md.getClassDesc(), rn))) { + // System.out.println("returnValueLoc.get(returnValueLoc.getSize() - 1).isTop()=" + // + returnValueLoc.get(returnValueLoc.getSize() - 1).isTop()); + // throw new Error("The value flow from " + constraint + " to " + + // returnValueLoc + // + " does not respect location hierarchy on the assignment " + + // rn.printNode(0) + // + " at " + md.getClassDesc().getSourceFileName() + "::" + + // rn.getNumLine()); + // } + // } + + if (!CompositeLattice.isGreaterThan(constraint, declaredReturnLoc, + generateErrorMessage(md.getClassDesc(), rn))) { + throw new Error("The value flow from " + constraint + " to " + declaredReturnLoc + + " does not respect location hierarchy on the assignment " + rn.printNode(0) + + " at " + md.getClassDesc().getSourceFileName() + "::" + rn.getNumLine()); + } + + } + // check if return value is equal or higher than RETRUNLOC of method // declaration annotation - CompositeLocation declaredReturnLoc = md2ReturnLoc.get(md); int compareResult = CompositeLattice.compare(returnValueLoc, declaredReturnLoc, false, @@ -606,9 +657,13 @@ public class FlowDownCheck { } else { // check 'for loop' case BlockNode bn = ln.getInitializer(); - // need to check initialization node - checkLocationFromBlockNode(md, nametable, bn, constraint); bn.getVarTable().setParent(nametable); + // need to check initialization node + // checkLocationFromBlockNode(md, bn.getVarTable(), bn, constraint); + for (int i = 0; i < bn.size(); i++) { + BlockStatementNode bsn = bn.get(i); + checkLocationFromBlockStatementNode(md, bn.getVarTable(), bsn, constraint); + } // calculate glb location of condition and update statements CompositeLocation condLoc = @@ -652,13 +707,14 @@ public class FlowDownCheck { private CompositeLocation checkLocationFromIfStatementNode(MethodDescriptor md, SymbolTable nametable, IfStatementNode isn, CompositeLocation constraint) { + System.out.println("checkLocationFromIfStatementNode=" + isn); CompositeLocation condLoc = checkLocationFromExpressionNode(md, nametable, isn.getCondition(), new CompositeLocation(), constraint, false); - // addLocationType(isn.getCondition().getType(), condLoc); - + System.out.println("-######old constraint=" + constraint); constraint = generateNewConstraint(constraint, condLoc); + System.out.println("-######new constraint=" + constraint); checkLocationFromBlockNode(md, nametable, isn.getTrueBlock(), constraint); if (isn.getFalseBlock() != null) { @@ -732,11 +788,12 @@ public class FlowDownCheck { private void checkDeclarationInSubBlockNode(MethodDescriptor md, SymbolTable nametable, SubBlockNode sbn) { - checkDeclarationInBlockNode(md, nametable.getParent(), sbn.getBlockNode()); + checkDeclarationInBlockNode(md, nametable, sbn.getBlockNode()); } private CompositeLocation checkLocationFromBlockExpressionNode(MethodDescriptor md, SymbolTable nametable, BlockExpressionNode ben, CompositeLocation constraint) { + CompositeLocation compLoc = checkLocationFromExpressionNode(md, nametable, ben.getExpression(), null, constraint, false); // addTypeLocation(ben.getExpression().getType(), compLoc); @@ -891,7 +948,7 @@ public class FlowDownCheck { CompositeLocation constraint) { ClassDescriptor cd = md.getClassDesc(); - MethodDescriptor calleeMD = min.getMethod(); + MethodDescriptor calleeMethodDesc = min.getMethod(); NameDescriptor baseName = min.getBaseName(); boolean isSystemout = false; @@ -899,8 +956,9 @@ public class FlowDownCheck { isSystemout = baseName.getSymbol().equals("System.out"); } - if (!ssjava.isSSJavaUtil(calleeMD.getClassDesc()) && !ssjava.isTrustMethod(calleeMD) - && !calleeMD.getModifiers().isNative() && !isSystemout) { + if (!ssjava.isSSJavaUtil(calleeMethodDesc.getClassDesc()) + && !ssjava.isTrustMethod(calleeMethodDesc) && !calleeMethodDesc.getModifiers().isNative() + && !isSystemout) { CompositeLocation baseLocation = null; if (min.getExpression() != null) { @@ -925,31 +983,109 @@ public class FlowDownCheck { // min.printNode(0) // + " baseLocation=" + baseLocation + " constraint=" + constraint); + // setup the location list of caller's arguments + List callerArgList = new ArrayList(); + + // setup the location list of callee's parameters + MethodLattice calleeLattice = ssjava.getMethodLattice(calleeMethodDesc); + List calleeParamList = new ArrayList(); + + if (min.numArgs() > 0) { + if (!calleeMethodDesc.isStatic()) { + callerArgList.add(baseLocation); + } + for (int i = 0; i < min.numArgs(); i++) { + ExpressionNode en = min.getArg(i); + CompositeLocation callerArgLoc = + checkLocationFromExpressionNode(md, nametable, en, new CompositeLocation(), + constraint, false); + callerArgList.add(callerArgLoc); + } + + if (!calleeMethodDesc.isStatic()) { + CompositeLocation calleeThisLoc = + new CompositeLocation(new Location(calleeMethodDesc, calleeLattice.getThisLoc())); + calleeParamList.add(calleeThisLoc); + } + + for (int i = 0; i < calleeMethodDesc.numParameters(); i++) { + VarDescriptor calleevd = (VarDescriptor) calleeMethodDesc.getParameter(i); + CompositeLocation calleeLoc = d2loc.get(calleevd); + calleeParamList.add(calleeLoc); + } + } + if (constraint != null) { - int compareResult = - CompositeLattice.compare(constraint, baseLocation, true, generateErrorMessage(cd, min)); - if (compareResult != ComparisonResult.GREATER) { - // if the current constraint is higher than method's THIS location - // no need to check constraints! - CompositeLocation calleeConstraint = - translateCallerLocToCalleeLoc(calleeMD, baseLocation, constraint); - // System.out.println("check method body for constraint:" + calleeMD + - // " calleeConstraint=" - // + calleeConstraint); - checkMethodBody(calleeMD.getClassDesc(), calleeMD, calleeConstraint); + // check whether the PC location is lower than one of the + // argument locations. If it is lower, the callee has to have @PCLOC + // annotation that declares the program counter that is higher than + // corresponding parameter + + CompositeLocation calleePCLOC = ssjava.getPCLocation(calleeMethodDesc); + + for (int idx = 0; idx < callerArgList.size(); idx++) { + CompositeLocation argLocation = callerArgList.get(idx); + + // if the PC location is lower than an argument location + // then, need to check that the callee's the initial location for the PC is also lower + // than the corresponding parameter location + + if (!argLocation.get(0).isTop() + && CompositeLattice.compare(argLocation, constraint, true, + generateErrorMessage(cd, min)) == ComparisonResult.LESS) { + + CompositeLocation paramLocation = calleeParamList.get(idx); + + int paramCompareResult = + CompositeLattice.compare(paramLocation, calleePCLOC, true, + generateErrorMessage(cd, min)); + // CompositeLattice.compare(calleePCLOC, paramLocation, true, + // generateErrorMessage(cd, min)); + + System.out.println("-CHECKPCLOC:"); + System.out.println("---ARG LOC=" + + argLocation + + " callerPCLOC=" + + constraint + + " result=" + + CompositeLattice.compare(argLocation, constraint, true, + generateErrorMessage(cd, min))); + System.out.println("---PARAM LOC=" + paramLocation + " calleePCLOC=" + calleePCLOC + + " paramCompareResult=" + paramCompareResult); + + if (!(paramLocation.get(0).equals(calleePCLOC.get(0)) && calleePCLOC.getSize() > 1) + && paramCompareResult != ComparisonResult.LESS) { + throw new Error( + "The program counter location " + + constraint + + " is lower than the argument(idx=" + + idx + + ") location " + + argLocation + + ". Need to specify that the initial PC location of the callee, which is currently set to " + + calleePCLOC + ", is lower than " + paramLocation + " in the method " + + calleeMethodDesc.getSymbol() + ":" + min.getNumLine()); + } + + } + } + } checkCalleeConstraints(md, nametable, min, baseLocation, constraint); - // checkCallerArgumentLocationConstraints(md, nametable, min, - // baseLocation, constraint); + checkCallerArgumentLocationConstraints(md, nametable, min, baseLocation, constraint); if (!min.getMethod().getReturnType().isVoid()) { // If method has a return value, compute the highest possible return // location in the caller's perspective CompositeLocation ceilingLoc = computeCeilingLocationForCaller(md, nametable, min, baseLocation, constraint); + + if (ceilingLoc == null) { + return new CompositeLocation(Location.createTopLocation(md)); + } return ceilingLoc; } } @@ -986,6 +1122,10 @@ public class FlowDownCheck { MethodDescriptor calleemd = min.getMethod(); + if (calleemd.isStatic()) { + return; + } + List callerArgList = new ArrayList(); List calleeParamList = new ArrayList(); @@ -1033,7 +1173,16 @@ public class FlowDownCheck { generateErrorMessage(md.getClassDesc(), min)); } - if (!CompositeLattice.isGreaterThan(callerArgLoc, paramLocation, errorMsg)) { + Location argLastLoc = callerArgLoc.get(callerArgLoc.getSize() - 1); + Location paramLastLoc = paramLocation.get(paramLocation.getSize() - 1); + + if (argLastLoc.equals(paramLastLoc) && ssjava.isSharedLocation(argLastLoc) + && ssjava.isSharedLocation(paramLastLoc)) { + continue; + } + + // if (!CompositeLattice.isGreaterThan(callerArgLoc, paramLocation, errorMsg)) { + if (CompositeLattice.compare(callerArgLoc, paramLocation, true, errorMsg) == ComparisonResult.LESS) { throw new Error("Caller argument '" + min.getArg(i).printNode(0) + " : " + callerArgLoc + "' should be higher than corresponding callee's parameter : " + paramLocation + " at " + errorMsg); @@ -1069,7 +1218,9 @@ public class FlowDownCheck { List argList = new ArrayList(); // by default, method has a THIS parameter - argList.add(baseLocation); + if (!min.getMethod().isStatic()) { + argList.add(baseLocation); + } for (int i = 0; i < min.numArgs(); i++) { ExpressionNode en = min.getArg(i); @@ -1079,8 +1230,7 @@ public class FlowDownCheck { argList.add(callerArg); } - // System.out.println("\n## computeReturnLocation=" + min.getMethod() + - // " argList=" + argList); + // System.out.println("\n## computeReturnLocation=" + min.getMethod() + " argList=" + argList); CompositeLocation ceilLoc = md2ReturnLocGen.get(min.getMethod()).computeReturnLocation(argList); // System.out.println("## ReturnLocation=" + ceilLoc); @@ -1091,13 +1241,12 @@ public class FlowDownCheck { private void checkCalleeConstraints(MethodDescriptor md, SymbolTable nametable, MethodInvokeNode min, CompositeLocation callerBaseLoc, CompositeLocation constraint) { - // System.out.println("checkCalleeConstraints=" + min.printNode(0)); - MethodDescriptor calleemd = min.getMethod(); MethodLattice calleeLattice = ssjava.getMethodLattice(calleemd); - CompositeLocation calleeThisLoc = - new CompositeLocation(new Location(calleemd, calleeLattice.getThisLoc())); + + System.out.println("checkCalleeConstraints=" + calleemd + " calleeLattice.getThisLoc()=" + + calleeLattice.getThisLoc()); List callerArgList = new ArrayList(); List calleeParamList = new ArrayList(); @@ -1108,7 +1257,8 @@ public class FlowDownCheck { // setup caller args set // first, add caller's base(this) location - callerArgList.add(callerBaseLoc); + if (!calleemd.isStatic()) + callerArgList.add(callerBaseLoc); // second, add caller's arguments for (int i = 0; i < min.numArgs(); i++) { ExpressionNode en = min.getArg(i); @@ -1120,7 +1270,11 @@ public class FlowDownCheck { // setup callee params set // first, add callee's this location - calleeParamList.add(calleeThisLoc); + if (!calleemd.isStatic()) { + CompositeLocation calleeThisLoc = + new CompositeLocation(new Location(calleemd, calleeLattice.getThisLoc())); + calleeParamList.add(calleeThisLoc); + } // second, add callee's parameters for (int i = 0; i < calleemd.numParameters(); i++) { VarDescriptor calleevd = (VarDescriptor) calleemd.getParameter(i); @@ -1175,16 +1329,24 @@ public class FlowDownCheck { String paramName1, paramName2; - if (i == 0) { - paramName1 = "'THIS'"; + if (!calleemd.isStatic()) { + if (i == 0) { + paramName1 = "'THIS'"; + } else { + paramName1 = "'parameter " + calleemd.getParamName(i - 1) + "'"; + } } else { - paramName1 = "'parameter " + calleemd.getParamName(i - 1) + "'"; + paramName1 = "'parameter " + calleemd.getParamName(i) + "'"; } - if (j == 0) { - paramName2 = "'THIS'"; + if (!calleemd.isStatic()) { + if (j == 0 && !calleemd.isStatic()) { + paramName2 = "'THIS'"; + } else { + paramName2 = "'parameter " + calleemd.getParamName(j - 1) + "'"; + } } else { - paramName2 = "'parameter " + calleemd.getParamName(j - 1) + "'"; + paramName2 = "'parameter " + calleemd.getParamName(j) + "'"; } throw new Error( @@ -1203,7 +1365,7 @@ public class FlowDownCheck { private CompositeLocation checkLocationFromArrayAccessNode(MethodDescriptor md, SymbolTable nametable, ArrayAccessNode aan, CompositeLocation constraint, boolean isLHS) { - + // System.out.println("aan=" + aan.printNode(0) + " line#=" + aan.getNumLine()); ClassDescriptor cd = md.getClassDesc(); CompositeLocation arrayLoc = @@ -1402,6 +1564,7 @@ public class FlowDownCheck { } } + return loc; } @@ -1428,26 +1591,29 @@ public class FlowDownCheck { } } + Set inputGLB = new HashSet(); if (left instanceof ArrayAccessNode) { ArrayAccessNode aan = (ArrayAccessNode) left; - left = aan.getExpression(); + CompositeLocation indexLoc = + checkLocationFromExpressionNode(md, nametable, aan.getIndex(), loc, constraint, false); + inputGLB.add(indexLoc); } loc = checkLocationFromExpressionNode(md, nametable, left, loc, constraint, false); - // System.out.println("### checkLocationFromFieldAccessNode=" + - // fan.printNode(0)); - // System.out.println("### left=" + left.printNode(0)); if (!left.getType().isPrimitive()) { - if (fd.getSymbol().equals("length")) { + if (!fd.getSymbol().equals("length")) { // array.length access, return the location of the array - return loc; + Location fieldLoc = getFieldLocation(fd); + loc.addLocation(fieldLoc); } - Location fieldLoc = getFieldLocation(fd); - loc.addLocation(fieldLoc); } + + inputGLB.add(loc); + loc = CompositeLattice.calculateGLB(inputGLB, generateErrorMessage(md.getClassDesc(), fan)); + return loc; } @@ -1492,8 +1658,6 @@ public class FlowDownCheck { private CompositeLocation checkLocationFromAssignmentNode(MethodDescriptor md, SymbolTable nametable, AssignmentNode an, CompositeLocation loc, CompositeLocation constraint) { - // System.out.println("\n# ASSIGNMENTNODE=" + an.printNode(0)); - ClassDescriptor cd = md.getClassDesc(); Set inputGLBSet = new HashSet(); @@ -1521,20 +1685,32 @@ public class FlowDownCheck { checkLocationFromExpressionNode(md, nametable, an.getSrc(), new CompositeLocation(), constraint, false); - srcLocation = rhsLocation; + if (an.getOperation().getOp() >= 2 && an.getOperation().getOp() <= 12) { + // if assignment contains OP+EQ operator, need to merge location types + // of LHS & RHS into the RHS + Set srcGLBSet = new HashSet(); + srcGLBSet.add(rhsLocation); + srcGLBSet.add(destLocation); + srcLocation = CompositeLattice.calculateGLB(srcGLBSet, generateErrorMessage(cd, an)); + } else { + srcLocation = rhsLocation; + } - // if (!rhsLocation.get(rhsLocation.getSize() - 1).isTop()) { if (constraint != null) { - inputGLBSet.add(rhsLocation); - inputGLBSet.add(constraint); - srcLocation = CompositeLattice.calculateGLB(inputGLBSet, generateErrorMessage(cd, an)); + + if (!CompositeLattice.isGreaterThan(constraint, destLocation, generateErrorMessage(cd, an))) { + throw new Error("The value flow from " + constraint + " to " + destLocation + + " does not respect location hierarchy on the assignment " + an.printNode(0) + + " at " + cd.getSourceFileName() + "::" + an.getNumLine()); + } + // inputGLBSet.add(srcLocation); + // inputGLBSet.add(constraint); + // srcLocation = CompositeLattice.calculateGLB(inputGLBSet, + // generateErrorMessage(cd, an)); } - // } - // System.out.println("dstLocation=" + destLocation); - // System.out.println("rhsLocation=" + rhsLocation); - // System.out.println("srcLocation=" + srcLocation); - // System.out.println("constraint=" + constraint); + // System.out.println("src=" + srcLocation + " dest=" + destLocation + " const=" + + // constraint); if (!CompositeLattice.isGreaterThan(srcLocation, destLocation, generateErrorMessage(cd, an))) { @@ -1565,17 +1741,21 @@ public class FlowDownCheck { constraint, false); if (constraint != null) { - inputGLBSet.add(rhsLocation); - inputGLBSet.add(constraint); - srcLocation = CompositeLattice.calculateGLB(inputGLBSet, generateErrorMessage(cd, an)); + + if (!CompositeLattice.isGreaterThan(constraint, destLocation, generateErrorMessage(cd, an))) { + throw new Error("The value flow from " + constraint + " to " + destLocation + + " does not respect location hierarchy on the assignment " + an.printNode(0) + + " at " + cd.getSourceFileName() + "::" + an.getNumLine()); + } + // inputGLBSet.add(rhsLocation); + // inputGLBSet.add(constraint); + // srcLocation = CompositeLattice.calculateGLB(inputGLBSet, + // generateErrorMessage(cd, an)); + srcLocation = rhsLocation; } else { srcLocation = rhsLocation; } - // System.out.println("srcLocation=" + srcLocation); - // System.out.println("rhsLocation=" + rhsLocation); - // System.out.println("constraint=" + constraint); - if (!CompositeLattice.isGreaterThan(srcLocation, destLocation, generateErrorMessage(cd, an))) { if (srcLocation.equals(destLocation)) { @@ -1965,7 +2145,7 @@ public class FlowDownCheck { public static CompositeLocation calculateGLB(Set inputSet, String errMsg) { - // System.out.println("Calculating GLB=" + inputSet); + System.out.println("Calculating GLB=" + inputSet); CompositeLocation glbCompLoc = new CompositeLocation(); // calculate GLB of the first(priority) element @@ -2014,7 +2194,6 @@ public class FlowDownCheck { SSJavaLattice locOrder = getLatticeByDescriptor(priorityDescriptor); String glbOfPriorityLoc = locOrder.getGLB(priorityLocIdentifierSet); - glbCompLoc.addLocation(new Location(priorityDescriptor, glbOfPriorityLoc)); Set compSet = locId2CompLocSet.get(glbOfPriorityLoc); @@ -2097,7 +2276,7 @@ public class FlowDownCheck { } } - // System.out.println("GLB=" + glbCompLoc); + System.out.println("GLB=" + glbCompLoc + "\n"); return glbCompLoc; } @@ -2276,6 +2455,9 @@ class ReturnLocGenerator { // compute GLB of arguments subset that are same or higher than return // location if (inputGLB.isEmpty()) { + if (args.size() == 0) { + return null; + } CompositeLocation rtr = new CompositeLocation(Location.createTopLocation(args.get(0).get(0).getDescriptor())); return rtr;