From 8642620b2e4b2c1c0e71d5612007a935abc42eb6 Mon Sep 17 00:00:00 2001 From: yeom Date: Sun, 4 Nov 2012 23:20:39 +0000 Subject: [PATCH] Changes: Inference engine works fine with the JavaNator benchmark. Found some problems in the original benchmark with the current version of location type checker + definitely written analysis. From the original benchmark, 1) removed static references 2) removed persistent states. --- .../Analysis/SSJava/LocationInference.java | 200 +++--------------- .../Benchmarks/SSJava/JavaNator/Command.java | 10 + .../SSJava/JavaNator/HWSimulator.java | 54 +++++ .../SSJava/JavaNator/PWMManager.java | 50 ++--- .../Benchmarks/SSJava/JavaNator/RCBridge.java | 2 +- .../SSJava/JavaNator/RandomWrapper.java | 14 ++ .../SSJava/JavaNator/RobotMain.java | 125 +++++------ .../SSJava/JavaNator/StrategyMgr.java | 6 +- .../SSJava/JavaNatorInfer/Command.java | 10 + .../SSJava/JavaNatorInfer/HWSimulator.java | 54 +++++ .../SSJava/JavaNatorInfer/MotorControl.java | 6 +- .../SSJava/JavaNatorInfer/PWMManager.java | 50 ++--- .../SSJava/JavaNatorInfer/RandomWrapper.java | 14 ++ .../SSJava/JavaNatorInfer/RobotMain.java | 125 +++++------ .../SSJava/JavaNatorInfer/StrategyMgr.java | 6 +- 15 files changed, 362 insertions(+), 364 deletions(-) create mode 100644 Robust/src/Benchmarks/SSJava/JavaNator/Command.java create mode 100644 Robust/src/Benchmarks/SSJava/JavaNator/HWSimulator.java create mode 100644 Robust/src/Benchmarks/SSJava/JavaNator/RandomWrapper.java create mode 100644 Robust/src/Benchmarks/SSJava/JavaNatorInfer/Command.java create mode 100644 Robust/src/Benchmarks/SSJava/JavaNatorInfer/HWSimulator.java create mode 100644 Robust/src/Benchmarks/SSJava/JavaNatorInfer/RandomWrapper.java diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index 8c1c9792..ec8c6049 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -400,7 +400,7 @@ public class LocationInference { while (!methodDescList.isEmpty()) { MethodDescriptor md = methodDescList.removeLast(); - System.out.println("\n#updateCompositeLocationAssignments=" + md); + // System.out.println("\n#updateCompositeLocationAssignments=" + md); FlowGraph flowGraph = getFlowGraph(md); @@ -409,19 +409,19 @@ 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()); + // 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); + // System.out.println("---updatedCompLoc1=" + updatedCompLoc); } else { NTuple descTuple = node.getDescTuple(); - System.out.println("update desc=" + descTuple); + // System.out.println("update desc=" + descTuple); CompositeLocation compLoc = convertToCompositeLocation(md, descTuple); compLoc = updateCompositeLocation(compLoc); node.setCompositeLocation(compLoc); - System.out.println("---updatedCompLoc2=" + compLoc); + // System.out.println("---updatedCompLoc2=" + compLoc); } if (node.isDeclaratonNode()) { @@ -472,8 +472,8 @@ public class LocationInference { private void translateCompositeLocationAssignmentToFlowGraph(MethodDescriptor mdCaller) { - System.out.println("\n\n###translateCompositeLocationAssignmentToFlowGraph mdCaller=" - + mdCaller); + // System.out.println("\n\n###translateCompositeLocationAssignmentToFlowGraph mdCaller=" + // + mdCaller); // First, assign a composite location to a node in the flow graph GlobalFlowGraph callerGlobalFlowGraph = getSubGlobalFlowGraph(mdCaller); @@ -535,7 +535,7 @@ public class LocationInference { // it matches with the current argument composite location // so what is the corresponding parameter local descriptor? FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx); - System.out.println("----------found paramNode=" + paramNode); + // System.out.println("----------found paramNode=" + paramNode); NTuple paramDescTuple = paramNode.getCurrentDescTuple(); NTuple newParamTupleFromArgTuple = translateToLocTuple(mdCallee, paramDescTuple); @@ -543,7 +543,7 @@ public class LocationInference { newParamTupleFromArgTuple.add(argLocTuple.get(i)); } - System.out.println("-----------newParamTuple=" + newParamTupleFromArgTuple); + // System.out.println("-----------newParamTuple=" + newParamTupleFromArgTuple); return new CompositeLocation(newParamTupleFromArgTuple); } @@ -608,7 +608,7 @@ public class LocationInference { for (Iterator iterator2 = holderOutEdge.iterator(); iterator2.hasNext();) { FlowEdge outEdge = (FlowEdge) iterator2.next(); NTuple toberemovedTuple = outEdge.getEndTuple(); - System.out.println("---remove " + tupleFromHolder + " -> " + toberemovedTuple); + // System.out.println("---remove " + tupleFromHolder + " -> " + toberemovedTuple); callerFlowGraph.removeEdge(tupleFromHolder, toberemovedTuple); } } @@ -698,7 +698,6 @@ public class LocationInference { System.out.println("----- add global flow globalArgLocTuple=" + globalArgLocTuple + "-> globalParamLocTuple=" + globalParamLocTuple); hasChanges = true; - System.out.println("B1"); globalGraph.addValueFlowEdge(globalArgLocTuple, globalParamLocTuple); } } @@ -714,7 +713,6 @@ public class LocationInference { + "-> globalParamLocTu!globalArgLocTuple.get(0).getLocDescriptor().equals(LITERALDESC)ple=" + globalParamLocTuple); hasChanges = true; - System.out.println("B2"); globalGraph.addValueFlowEdge(pcLocTuple, globalParamLocTuple); } @@ -796,10 +794,8 @@ public class LocationInference { baseLocTuple = translateToLocTuple(mdCaller, mapMethodInvokeNodeToBaseTuple.get(min)); } - System.out.println("\n-#translate caller=" + mdCaller + " infer composite loc to callee=" - + mdCallee + " baseLocTuple=" + baseLocTuple); - // System.out.println("-mapIdxToArgTuple=" + mapIdxToArgTuple); - // System.out.println("-callerMapLocToCompLoc=" + callerMapLocToCompLoc); + // System.out.println("\n-#translate caller=" + mdCaller + " infer composite loc to callee=" + // + mdCallee + " baseLocTuple=" + baseLocTuple); Set keySet = callerMapLocToCompLoc.keySet(); for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { @@ -816,9 +812,9 @@ public class LocationInference { translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee); calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc); - System.out.println("1---key=" + key + " callerCompLoc=" + callerCompLoc - + " newCalleeCompLoc=" + newCalleeCompLoc); - System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee); + // System.out.println("1---key=" + key + " callerCompLoc=" + callerCompLoc + // + " newCalleeCompLoc=" + newCalleeCompLoc); + // System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee); if (!newCalleeCompLoc.get(0).getDescriptor().equals(mdCallee)) { System.exit(0); } @@ -838,9 +834,9 @@ public class LocationInference { newCalleeCompLoc.addLocation(callerCompLoc.get(i)); } calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc); - System.out.println("2---key=" + key + " callerCompLoc=" + callerCompLoc - + " newCalleeCompLoc=" + newCalleeCompLoc); - System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee); + // System.out.println("2---key=" + key + " callerCompLoc=" + callerCompLoc + // + " newCalleeCompLoc=" + newCalleeCompLoc); + // System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee); } else { int paramIdx = getParamIdx(callerCompLoc, mapIdxToArgTuple); @@ -850,12 +846,12 @@ public class LocationInference { // so transfer the same composite location to the callee if (!calleeGlobalGraph.contrainsInferCompositeLocationMapKey(key)) { if (callerCompLoc.get(0).getDescriptor().equals(mdCallee)) { - System.out.println("3---key=" + key + " callerCompLoc=" + callerCompLoc - + " newCalleeCompLoc=" + callerCompLoc); - System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee); + // System.out.println("3---key=" + key + " callerCompLoc=" + callerCompLoc + // + " newCalleeCompLoc=" + callerCompLoc); + // System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee); calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, callerCompLoc); } else { - System.out.println("3---SKIP key=" + key + " callerCompLoc=" + callerCompLoc); + // System.out.println("3---SKIP key=" + key + " callerCompLoc=" + callerCompLoc); } } continue; @@ -883,14 +879,9 @@ public class LocationInference { newCalleeCompLoc.addLocation(callerCompLoc.get(i)); } calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc); - System.out.println("4---key=" + key + " callerCompLoc=" + callerCompLoc - + " newCalleeCompLoc=" + newCalleeCompLoc); - System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee); - - // System.out.println("-----argTuple=" + argTuple + " caller=" + mdCaller + - // " callee=" - // + mdCallee); - // System.out.println("-----paramIdx=" + paramIdx + " paramFlowNode=" + paramFlowNode); + // System.out.println("4---key=" + key + " callerCompLoc=" + callerCompLoc + // + " newCalleeCompLoc=" + newCalleeCompLoc); + // System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee); } @@ -899,9 +890,6 @@ public class LocationInference { } } - // System.out.println("-----*AFTER TRANSLATING COMP LOC MAPPING, CALLEE MAPPING=" - // + calleeGlobalGraph.getMapLocationToInferCompositeLocation()); - System.out.println("#ASSIGN COMP LOC TO CALLEE PARAMS: callee=" + mdCallee + " caller=" + mdCaller); // If the location of an argument has a composite location @@ -1073,8 +1061,6 @@ public class LocationInference { if (!needToGenerateCompositeLocation(paramGlobalNode, curPrefix)) { System.out.println("NO NEED TO GENERATE COMP LOC to " + paramGlobalNode + " with prefix=" + curPrefix); - // System.out.println("prefixList=" + prefixList); - // System.out.println("reachableNodeSet=" + reachableNodeSet); return null; } @@ -1340,7 +1326,6 @@ public class LocationInference { for (Iterator iterator = paramNodeSet.iterator(); iterator.hasNext();) { FlowNode paramFlowNode = (FlowNode) iterator.next(); if (curPrefix.startsWith(translateToLocTuple(md, paramFlowNode.getDescTuple()))) { - System.out.println("here1?!"); return true; } } @@ -1358,7 +1343,6 @@ public class LocationInference { FlowNode paramNode = getFlowGraph(mdCallee).getParamFlowNode(paramIdx); if (checkNodeReachToReturnNode(mdCallee, paramNode)) { - System.out.println("here2?!"); return true; } @@ -1381,7 +1365,6 @@ public class LocationInference { mapMethodDescriptorToCompositeReturnCase.get(md).booleanValue(); if (hasCompReturnLocWithThis) { if (checkNodeReachToReturnNode(md, flowNode)) { - System.out.println("here3?!"); return true; } } @@ -1391,7 +1374,6 @@ public class LocationInference { GlobalFlowNode subGlobalReachalbeNode = (GlobalFlowNode) iterator3.next(); if (subGlobalReachalbeNode.getLocTuple().get(0).getLocDescriptor().equals(md.getThis())) { System.out.println("PREFIX FOUND=" + subGlobalReachalbeNode); - System.out.println("here4?!"); return true; } } @@ -1399,16 +1381,6 @@ public class LocationInference { } } - // System.out.println("flowGraph.getReturnNodeSet()=" + flowGraph.getReturnNodeSet()); - // System.out.println("flowGraph.contains(node.getDescTuple())=" - // + flowGraph.contains(node.getDescTuple()) + " flowGraph.getFlowNode(node.getDescTuple())=" - // + flowGraph.getFlowNode(node.getDescTuple()));reachableSet - - // if (flowGraph.contains(node.getDescTuple()) - // && flowGraph.getReturnNodeSet().contains(flowGraph.getFlowNode(node.getDescTuple()))) { - // // return checkFlowNodeReturnThisField(flowGraph); - // } - Location lastLocationOfPrefix = curPrefix.get(curPrefix.size() - 1); // check whether prefix appears in the list of parameters Set minSet = mapMethodDescToMethodInvokeNodeSet.get(md); @@ -1438,8 +1410,6 @@ public class LocationInference { if (globalReachlocTuple.get(i).equals(lastLocationOfPrefix)) { System.out.println("ARG " + argTuple + " IS MATCHED WITH=" + lastLocationOfPrefix); - System.out.println("here5?!"); - return true; } } @@ -1449,39 +1419,6 @@ public class LocationInference { } } - // ClassDescriptor cd; - // if (lastLocationOfPrefix.getLocDescriptor() instanceof VarDescriptor) { - // cd = ((VarDescriptor) lastLocationOfPrefix.getLocDescriptor()).getType().getClassDesc(); - // } else { - // // it is a field descriptor - // cd = ((FieldDescriptor) lastLocationOfPrefix.getLocDescriptor()).getType().getClassDesc(); - // } - // - // GlobalFlowGraph subGlobalFlowGraph = getSubGlobalFlowGraph(md); - // Set subGlobalReachableSet = subGlobalFlowGraph.getReachableNodeSetFrom(node); - // - // System.out.println("TRY TO FIND lastLocationOfPrefix=" + lastLocationOfPrefix); - // for (Iterator iterator2 = subGlobalReachableSet.iterator(); iterator2.hasNext();) { - // GlobalFlowNode subGlobalReachalbeNode = (GlobalFlowNode) iterator2.next(); - // // NTuple locTuple = translateToLocTuple(md, reachalbeNode.getDescTuple()); - // NTuple locTuple = subGlobalReachalbeNode.getLocTuple(); - // - // for (int i = 0; i < locTuple.size(); i++) { - // if (locTuple.get(i).equals(lastLocationOfPrefix)) { - // return true; - // } - // } - // - // Location lastLoc = locTuple.get(locTuple.size() - 1); - // Descriptor enclosingDescriptor = lastLoc.getDescriptor(); - // - // if (enclosingDescriptor != null && enclosingDescriptor.equals(cd)) { - // System.out.println("# WHY HERE?"); - // System.out.println("subGlobalReachalbeNode=" + subGlobalReachalbeNode); - // return true; - // } - // } - return false; } @@ -1559,24 +1496,6 @@ public class LocationInference { } }); - // remove a prefix which is not suitable for generating composite location - Location localVarLoc = node.getLocTuple().get(0); - MethodDescriptor md = (MethodDescriptor) localVarLoc.getDescriptor(); - ClassDescriptor cd = md.getClassDesc(); - - int idx = 0; - Set> toberemoved = new HashSet>(); - // for (int i = 0; i < prefixList.size(); i++) { - // NTuple prefixLocTuple = prefixList.get(i); - // if (!containsClassDesc(cd, prefixLocTuple)) { - // toberemoved.add(prefixLocTuple); - // } - // } - - // System.out.println("method class=" + cd + " toberemoved=" + toberemoved); - - prefixList.removeAll(toberemoved); - return prefixList; } @@ -1621,17 +1540,6 @@ public class LocationInference { MethodDescriptor curPrefixFirstElementMethodDesc = (MethodDescriptor) curPrefix.get(0).getDescriptor(); - // MethodDescriptor nodePrefixLocFirstElementMethodDesc = - // (MethodDescriptor) prefixLoc.getDescriptor(); - - // System.out.println("curPrefixFirstElementMethodDesc=" + - // curPrefixFirstElementMethodDesc); - // System.out.println("nodePrefixLocFirstElementMethodDesc=" - // + nodePrefixLocFirstElementMethodDesc); - - // TODO - // if (!node.getLocTuple().startsWith(curPrefix.get(0))) { - Location curPrefixLocalLoc = curPrefix.get(0); Location targetLocalLoc = new Location(md, node.getDescTuple().get(0)); @@ -1641,12 +1549,6 @@ public class LocationInference { System.out.println("NEED2ASSIGN COMP LOC TO " + node + " with prefix=" + curPrefix); System.out.println("-targetLocalLoc=" + targetLocalLoc + " - newCompLoc=" + newCompLoc); - // // makes sure that a newly generated location appears in the hierarchy graph - // for (int compIdx = 0; compIdx < newCompLoc.getSize(); compIdx++) { - // Location curLoc = newCompLoc.get(compIdx); - // getHierarchyGraph(curLoc.getDescriptor()).getHNode(curLoc.getLocDescriptor()); - // } - // subGlobalFlowGraph.addMapLocationToInferCompositeLocation(targetLocalLoc, newCompLoc); node.setCompositeLocation(newCompLoc); return newCompLoc; @@ -1744,25 +1646,7 @@ public class LocationInference { // here only keep the first element(method location) of the descriptor // tuple NTuple srcLocTuple = translateToLocTuple(md, srcDescTuple); - // Location srcMethodLoc = srcLocTuple.get(0); - // Descriptor srcVarDesc = srcMethodLoc.getLocDescriptor(); - // // if (flowGraph.isParamDesc(srcVarDesc) && - // (!srcVarDesc.equals(md.getThis()))) { - // if (!srcVarDesc.equals(md.getThis())) { - // srcLocTuple = new NTuple(); - // Location loc = new Location(md, srcVarDesc); - // srcLocTuple.add(loc); - // } - // NTuple dstLocTuple = translateToLocTuple(md, dstDescTuple); - // Location dstMethodLoc = dstLocTuple.get(0); - // Descriptor dstVarDesc = dstMethodLoc.getLocDescriptor(); - // if (!dstVarDesc.equals(md.getThis())) { - // dstLocTuple = new NTuple(); - // Location loc = new Location(md, dstVarDesc); - // dstLocTuple.add(loc); - // } - System.out.println("B11"); globalGraph.addValueFlowEdge(srcLocTuple, dstLocTuple); @@ -1787,7 +1671,6 @@ public class LocationInference { } else if (desc instanceof FieldDescriptor) { enclosingDesc = ((FieldDescriptor) desc).getType().getClassDesc(); } else { - // TODO: inter descriptor case enclosingDesc = desc; } @@ -1875,7 +1758,6 @@ public class LocationInference { if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) { for (Iterator iterator2 = pcLocTupleSet.iterator(); iterator2.hasNext();) { NTuple pcLocTuple = (NTuple) iterator2.next(); - System.out.println("B12"); callerSubGlobalGraph.addValueFlowEdge(pcLocTuple, callerSrcNodeLocTuple); } @@ -1910,7 +1792,6 @@ public class LocationInference { // + callerDstNodeLocTuple); if (callerSrcNodeLocTuple != null && callerDstNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0 && callerDstNodeLocTuple.size() > 0) { - System.out.println("B3"); callerSubGlobalGraph.addValueFlowEdge(callerSrcNodeLocTuple, callerDstNodeLocTuple); } } @@ -2039,18 +1920,6 @@ public class LocationInference { FlowNode flowNode = flowGraph.getParamFlowNode(paramIdx); CompositeLocation inferredCompLoc = updateCompositeLocation(flowNode.getCompositeLocation()); - // NTuple descTuple = flowNode.getDescTuple(); - // - // CompositeLocation assignedCompLoc = flowNode.getCompositeLocation(); - // CompositeLocation inferredCompLoc; - // if (assignedCompLoc != null) { - // inferredCompLoc = translateCompositeLocation(assignedCompLoc); - // } else { - // Descriptor locDesc = descTuple.get(0); - // Location loc = new Location(md, locDesc.getSymbol()); - // loc.setLocDescriptor(locDesc); - // inferredCompLoc = new CompositeLocation(loc); - // } System.out.println("-paramIdx=" + paramIdx + " infer=" + inferredCompLoc + " original=" + flowNode.getCompositeLocation()); @@ -3374,7 +3243,6 @@ public class LocationInference { if (!paramDescNOTHavingInFlowSet.contains(node.getCurrentDescTuple().get(0))) { flowNodeLowerthanPCLocSet.add(node); fg.addValueFlowEdge(pcDescTuple, node.getDescTuple()); - System.out.println("B10"); subGlobalFlowGraph.addValueFlowEdge(pcLocTuple, translateToLocTuple(md, node.getDescTuple())); @@ -4661,7 +4529,6 @@ public class LocationInference { newImplicitTupleSet.addTupleSet(implicitFlowTupleSet); newImplicitTupleSet.addTupleSet(condTupleNode); - System.out.println("A5"); newImplicitTupleSet.addGlobalFlowTupleSet(implicitFlowTupleSet.getGlobalLocTupleSet()); newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet()); @@ -4815,7 +4682,6 @@ public class LocationInference { // translateToLocTuple(md, callerImplicitTuple)); // } // } - System.out.println("A4"); newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet()); analyzeFlowBlockNode(md, nametable, isn.getTrueBlock(), newImplicitTupleSet); @@ -4866,7 +4732,6 @@ public class LocationInference { GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md); for (Iterator> iterator = nodeSetRHS.globalIterator(); iterator.hasNext();) { NTuple calleeReturnLocTuple = iterator.next(); - System.out.println("B7"); globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, tupleLHS)); } @@ -4874,7 +4739,6 @@ public class LocationInference { for (Iterator> iterator = implicitFlowTupleSet.globalIterator(); iterator .hasNext();) { NTuple implicitGlobalTuple = iterator.next(); - System.out.println("B8"); globalFlowGraph.addValueFlowEdge(implicitGlobalTuple, translateToLocTuple(md, tupleLHS)); } @@ -4993,7 +4857,7 @@ public class LocationInference { private void analyzeFlowTertiaryNode(MethodDescriptor md, SymbolTable nametable, TertiaryNode tn, NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) { - System.out.println("analyzeFlowTertiaryNode=" + tn.printNode(0)); + // System.out.println("analyzeFlowTertiaryNode=" + tn.printNode(0)); NodeTupleSet tertiaryTupleNode = new NodeTupleSet(); analyzeFlowExpressionNode(md, nametable, tn.getCond(), tertiaryTupleNode, null, @@ -5020,7 +4884,6 @@ public class LocationInference { newImplicitTupleSet.addTuple(interTuple); } - System.out.println("A7"); newImplicitTupleSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet()); System.out.println("---------newImplicitTupleSet=" + newImplicitTupleSet); @@ -5032,7 +4895,6 @@ public class LocationInference { analyzeFlowExpressionNode(md, nametable, tn.getFalseExpr(), tertiaryTupleNode, null, newImplicitTupleSet, false); - System.out.println("A8"); nodeSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet()); nodeSet.addTupleSet(tertiaryTupleNode); @@ -5273,7 +5135,7 @@ public class LocationInference { } returnHolderNode.addTuple(interTuple); - // TODO + nodeSet.addTuple(interTuple); System.out.println("ADD TUPLESET=" + interTuple + " to returnnode=" + returnHolderNode); @@ -5476,7 +5338,6 @@ public class LocationInference { NTuple calleeReturnLocTuple = iterator.next(); for (Iterator> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) { NTuple arrTuple = arrIter.next(); - System.out.println("B4"); globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, arrTuple)); } @@ -5515,7 +5376,6 @@ public class LocationInference { } } - System.out.println("A1"); nodeSet.addGlobalFlowTupleSet(idxNodeTupleSet.getGlobalLocTupleSet()); nodeSet.addTupleSet(nodeSetArrayAccessExp); @@ -5586,7 +5446,6 @@ public class LocationInference { nodeSet.addTupleSet(leftOpSet); nodeSet.addTupleSet(rightOpSet); - System.out.println("A6"); nodeSet.addGlobalFlowTupleSet(leftOpSet.getGlobalLocTupleSet()); nodeSet.addGlobalFlowTupleSet(rightOpSet.getGlobalLocTupleSet()); @@ -5747,7 +5606,6 @@ public class LocationInference { for (Iterator> iterator = idxNodeTupleSet.globalIterator(); iterator .hasNext();) { NTuple calleeReturnLocTuple = iterator.next(); - System.out.println("B9"); globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, flowFieldTuple)); @@ -5790,7 +5648,6 @@ public class LocationInference { nodeSet.clear(); flowFieldTuple = interTuple; } - System.out.println("A3"); nodeSet.addGlobalFlowTupleSet(idxNodeTupleSet.getGlobalLocTupleSet()); } @@ -5881,7 +5738,6 @@ public class LocationInference { NTuple callerLHSTuple = iter2.next(); System.out.println("$$$ GLOBAL FLOW ADD=" + calleeReturnLocTuple + " -> " + translateToLocTuple(md, callerLHSTuple)); - System.out.println("B5"); globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, callerLHSTuple)); @@ -5893,7 +5749,6 @@ public class LocationInference { NTuple calleeReturnLocTuple = iterator.next(); for (Iterator> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) { NTuple callerLHSTuple = iter2.next(); - System.out.println("B6"); globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, callerLHSTuple)); @@ -5936,7 +5791,6 @@ public class LocationInference { if (nodeSet != null) { nodeSet.addTupleSet(nodeSetLHS); - System.out.println("A2"); nodeSet.addGlobalFlowTupleSet(nodeSetLHS.getGlobalLocTupleSet()); } } diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/Command.java b/Robust/src/Benchmarks/SSJava/JavaNator/Command.java new file mode 100644 index 00000000..801e670a --- /dev/null +++ b/Robust/src/Benchmarks/SSJava/JavaNator/Command.java @@ -0,0 +1,10 @@ +@LATTICE("V") +public class Command { + + @LOC("V") public int onOffMode; + @LOC("V") public int manualAutonomusMode; + @LOC("V") public byte lineSensorsMask; + @LOC("V") public byte sonarSensors; + @LOC("V") byte command; + +} diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/HWSimulator.java b/Robust/src/Benchmarks/SSJava/JavaNator/HWSimulator.java new file mode 100644 index 00000000..d859364e --- /dev/null +++ b/Robust/src/Benchmarks/SSJava/JavaNator/HWSimulator.java @@ -0,0 +1,54 @@ +public class HWSimulator { + + public static int onOffMode = RobotMain.ON_MODE; + public static int manualAutonomusMode = RobotMain.AUTONOMUS_MODE; + public static byte lineSensorsMask; + public static byte sonarSensors; + + // public byte currentSonars; + + @TRUST + public static Command getCommand() { + + byte currentCommand = TestSensorInput.getCommand(); + + int data = (int) (currentCommand & RobotMain.ALL_DATA); + int opCode = (int) (currentCommand & 0xe0); // ALL_COMMANDS); + + switch ((int) opCode) { + case RobotMain.ON_OFF: + if ((data & 0x1) == 0x1) { + HWSimulator.onOffMode = RobotMain.ON_MODE; + } else { + HWSimulator.onOffMode = RobotMain.OFF_MODE; + } + break; + case RobotMain.MANUAL_AUTONOMUS: + if ((data & 0x1) == 0x1) { + HWSimulator.manualAutonomusMode = RobotMain.MANUAL_MODE; + } else { + HWSimulator.manualAutonomusMode = RobotMain.AUTONOMUS_MODE; + } + break; + case RobotMain.LINE_SENSORS: + HWSimulator.lineSensorsMask = (byte) (data & RobotMain.LS_ALL); + break; + case RobotMain.SONAR_SENSORS: + HWSimulator.sonarSensors = (byte) (data & RobotMain.ALL_SONARS); + break; + } + + Command com = new Command(); + + com.command = currentCommand; + + com.onOffMode = HWSimulator.onOffMode; + com.manualAutonomusMode = HWSimulator.manualAutonomusMode; + com.lineSensorsMask = HWSimulator.lineSensorsMask; + com.sonarSensors = HWSimulator.sonarSensors; + + return com; + + } + +} diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/PWMManager.java b/Robust/src/Benchmarks/SSJava/JavaNator/PWMManager.java index d1944702..d93442fa 100644 --- a/Robust/src/Benchmarks/SSJava/JavaNator/PWMManager.java +++ b/Robust/src/Benchmarks/SSJava/JavaNator/PWMManager.java @@ -18,11 +18,10 @@ */ /** - * PWMManager - Interface between robot strategy code and the various motors - * PWMControl classes. Agility is a number between 0 to 100 and represent the - * precentage of max speed to be applied to the turn side wheel. On left turn - * the left wheel will receive less speed as % of "speed" value represented by - * agility. + * PWMManager - Interface between robot strategy code and the various motors PWMControl classes. + * Agility is a number between 0 to 100 and represent the precentage of max speed to be applied to + * the turn side wheel. On left turn the left wheel will receive less speed as % of "speed" value + * represented by agility. * * @author Michael Gesundheit * @version 1.0 @@ -57,8 +56,8 @@ public class PWMManager { */ public PWMManager(String pwmSelection) { /* - * Instantiate PWM Makers one for each motor. motorPortId is 1 to 8 and is - * corresponding to 8 bits in a byte. + * Instantiate PWM Makers one for each motor. motorPortId is 1 to 8 and is corresponding to 8 + * bits in a byte. */ // if (pwmSelection.equals("rtsj")) // pwmControl = new PWMRtsj(this, MOTOR_PORTID_6, MOTOR_PORTID_7); @@ -100,9 +99,8 @@ public class PWMManager { currentRegMask |= myValue; /* * // if (DEBUG){ // System.out.println("PWMM: writeToPort: myBit = 0x" + - * Integer.toHexString(myBit) + // " ~myBit = 0x" + - * Integer.toHexString(~myBit) + " myValue = 0x" + // - * Integer.toHexString(myValue) + " currentRegMask = 0x" + // + * Integer.toHexString(myBit) + // " ~myBit = 0x" + Integer.toHexString(~myBit) + + * " myValue = 0x" + // Integer.toHexString(myValue) + " currentRegMask = 0x" + // * Integer.toHexString(currentRegMask)); //} */ // rawJEM.set(GPIO_E_OUT, currentRegMask); @@ -112,20 +110,16 @@ public class PWMManager { * public void stop(){ if(DEBUG) System.out.println("PWMManager: stop...."); * pwmControl.setSpeedLeft(zeroSpeed); pwmControl.setSpeedRight(zeroSpeed); } * - * public void search(){ if(DEBUG) - * System.out.println("PWMManager: search...."); pwmControl.setSpeedLeft(70); - * pwmControl.setSpeedRight(50); } + * public void search(){ if(DEBUG) System.out.println("PWMManager: search...."); + * pwmControl.setSpeedLeft(70); pwmControl.setSpeedRight(50); } * - * public void straight(){ if(DEBUG) - * System.out.println("PWMManager: strait...."); pwmControl.setSpeedLeft(100); - * pwmControl.setSpeedRight(100); } + * public void straight(){ if(DEBUG) System.out.println("PWMManager: strait...."); + * pwmControl.setSpeedLeft(100); pwmControl.setSpeedRight(100); } * - * public void spinRight(){ if(DEBUG) - * System.out.println("PWMManager: spinRight...."); + * public void spinRight(){ if(DEBUG) System.out.println("PWMManager: spinRight...."); * pwmControl.setSpeedSpinLeft(100); pwmControl.setSpeedSpinRight(0); } * - * public void spinLeft(){ if(DEBUG) - * System.out.println("PWMManager: spinLeft...."); + * public void spinLeft(){ if(DEBUG) System.out.println("PWMManager: spinLeft...."); * pwmControl.setSpeedSpinLeft(0); pwmControl.setSpeedSpinRight(100); } * * public void spin180(){ int mod = (rand.nextInt() % 2); @@ -140,23 +134,19 @@ public class PWMManager { * public void left(){ if(DEBUG) System.out.println("PWMManager: left...."); * pwmControl.setSpeedLeft(zeroSpeed); pwmControl.setSpeedTurnRight(100); } * - * public void bearRight(){ if(DEBUG) - * System.out.println("PWMManager: bearRight...."); + * public void bearRight(){ if(DEBUG) System.out.println("PWMManager: bearRight...."); * pwmControl.setSpeedTurnLeft(100); pwmControl.setSpeedTurnRight(60); } * - * public void bearLeft(){ if(DEBUG) - * System.out.println("PWMManager: bearLeft...."); + * public void bearLeft(){ if(DEBUG) System.out.println("PWMManager: bearLeft...."); * pwmControl.setSpeedTurnLeft(60); pwmControl.setSpeedTurnRight(100); } * * public void back(){ if(DEBUG) System.out.println("PWMManager: back...."); * pwmControl.setSpeedLeft(0); pwmControl.setSpeedRight(0); } * - * public void backBearLeft(){ if(DEBUG) - * System.out.println("PWMManager: backBearLeft...."); + * public void backBearLeft(){ if(DEBUG) System.out.println("PWMManager: backBearLeft...."); * pwmControl.setSpeedLeft(30); pwmControl.setSpeedRight(0); } * - * public void backBearRight(){ if(DEBUG) - * System.out.println("PWMManager: backBearRight...."); + * public void backBearRight(){ if(DEBUG) System.out.println("PWMManager: backBearRight...."); * pwmControl.setSpeedLeft(0); pwmControl.setSpeedRight(30); } */ public void resume() { @@ -205,10 +195,10 @@ public class PWMManager { } /** - * Control debug messaging. true - Activate debug messages false - deactivate - * debug messages + * Control debug messaging. true - Activate debug messages false - deactivate debug messages */ public void setDebug(boolean debug) { DEBUG = debug; } + } \ No newline at end of file diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/RCBridge.java b/Robust/src/Benchmarks/SSJava/JavaNator/RCBridge.java index fd60f3be..28a23e9b 100644 --- a/Robust/src/Benchmarks/SSJava/JavaNator/RCBridge.java +++ b/Robust/src/Benchmarks/SSJava/JavaNator/RCBridge.java @@ -26,7 +26,7 @@ * @author Michael Gesundheit * @version 1.0 */ -@METHODDEFAULT("IN") +@METHODDEFAULT("IN,THISLOC=IN") public class RCBridge { public void setManualMode() { diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/RandomWrapper.java b/Robust/src/Benchmarks/SSJava/JavaNator/RandomWrapper.java new file mode 100644 index 00000000..9ab0fc6b --- /dev/null +++ b/Robust/src/Benchmarks/SSJava/JavaNator/RandomWrapper.java @@ -0,0 +1,14 @@ +public class RandomWrapper { + private static Random rand; + + @TRUST + public static void init() { + rand = new Random(); + } + + @TRUST + public static int nextInt() { + return rand.nextInt(); + } + +} diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/RobotMain.java b/Robust/src/Benchmarks/SSJava/JavaNator/RobotMain.java index 5c822396..a4ed1715 100644 --- a/Robust/src/Benchmarks/SSJava/JavaNator/RobotMain.java +++ b/Robust/src/Benchmarks/SSJava/JavaNator/RobotMain.java @@ -32,14 +32,14 @@ public class RobotMain { @LOC("T") private static boolean DEBUG = true; - private static final int OFF_MODE = 1; - private static final int ON_MODE = 2; - private static final int MANUAL_MODE = 1; - private static final int AUTONOMUS_MODE = 2; - private static final int ON_OFF = 128;// 0x80 - private static final int MANUAL_AUTONOMUS = 32; // 0x20 + public static final int OFF_MODE = 1; + public static final int ON_MODE = 2; + public static final int MANUAL_MODE = 1; + public static final int AUTONOMUS_MODE = 2; + public static final int ON_OFF = 128;// 0x80 + public static final int MANUAL_AUTONOMUS = 32; // 0x20 public static final int LINE_SENSORS = 64; // 0x40 - private static final int SONAR_SENSORS = 96; // 0x60 + public static final int SONAR_SENSORS = 96; // 0x60 public static final int ALL_COMMANDS = 0xe0; public static final byte LF_FRONT = 0x1; @@ -56,31 +56,31 @@ public class RobotMain { public static final byte LS_LEFT_REAR = 0x5; public static final byte LS_RIGHT_REAR = 0x6; public static final byte LS_ALL = 0x7; - private static final int ALL_DATA = 0x1f; + public static final int ALL_DATA = 0x1f; @LOC("MGR") - private static PWMManager pwmm; + private PWMManager pwmm; @LOC("MGR") - private static StrategyMgr strategyMgr; + private StrategyMgr strategyMgr; @LOC("MASK") - private static int onOffMode = ON_MODE; + private int onOffMode = ON_MODE; @LOC("MASK") - private static int manualAutonomusMode = AUTONOMUS_MODE; + private int manualAutonomusMode = AUTONOMUS_MODE; @LOC("MASK") - private static byte lineSensorsMask; + private byte lineSensorsMask; @LOC("MASK") - private static byte sonarSensors; + private byte sonarSensors; @LOC("CCMD") - private static byte currentCommand; + private byte currentCommand; @LOC("MASK") - private static byte privSonars; + private byte privSonars; @LOC("PREV") - private static byte privLineSensors; + private byte privLineSensors; @LOC("MASK") - private static byte currentSonars; + private byte currentSonars; @LOC("MASK") - public static String pwmSelection; + public String pwmSelection; /** * Constructor for the class for the robot main thread. @@ -89,20 +89,18 @@ public class RobotMain { } /** - * Processes sonar sensor input. This method is called each time new sonar - * sensor data arrives, and each time that a mode switch occurs between ON/OFF - * and Manual Override. + * Processes sonar sensor input. This method is called each time new sonar sensor data arrives, + * and each time that a mode switch occurs between ON/OFF and Manual Override. */ - static void processSonars() { + void processSonars() { strategyMgr.processSonars(sonarSensors); } /** - * Processes line sensor input. This method is called each time new line - * sensor data arrives, and each time that a mode switch occurs between ON/OFF - * and Manual Override. + * Processes line sensor input. This method is called each time new line sensor data arrives, and + * each time that a mode switch occurs between ON/OFF and Manual Override. */ - static void processLineSensors() { + void processLineSensors() { strategyMgr.processLineSensors(lineSensorsMask); resume(); } @@ -110,16 +108,16 @@ public class RobotMain { /** * Resumes motors as per the last sonar command. */ - public static void resume() { + void resume() { processSonars(); } /** - * Extracts sonar sensor data from the adjunct sensor controller and from line - * sensor data from the JStamp line sensor pins. + * Extracts sonar sensor data from the adjunct sensor controller and from line sensor data from + * the JStamp line sensor pins. */ @LATTICE("THIS,THISLOC=THIS,GLOBALLOC=THIS") - private static void processIOCommand() { + private void processIOCommand() { // int data = 0; // int opCode = 0; @@ -170,8 +168,8 @@ public class RobotMain { lineSensorsMask = (byte) (data & LS_ALL); /* - * Line sensors with '0' data means the robot moved off the edge line, and - * there is nothing to do. + * Line sensors with '0' data means the robot moved off the edge line, and there is nothing to + * do. */ if (((data & LS_ALL) == 0) || ((data & LS_ALL) == privLineSensors)) { privLineSensors = (byte) (data & LS_ALL); @@ -190,8 +188,8 @@ public class RobotMain { } currentSonars = (byte) (data & ALL_SONARS); /* - * No need to synchronized on this variable assignment since all referring - * code is on the same logical thread + * No need to synchronized on this variable assignment since all referring code is on the same + * logical thread */ sonarSensors = (byte) currentSonars; if ((onOffMode == ON_MODE) && (manualAutonomusMode == AUTONOMUS_MODE)) { @@ -222,7 +220,7 @@ public class RobotMain { /** * Saves the current IOManager command byte locally. */ - static public void setIOManagerCommand(byte[] cmd) { + public void setIOManagerCommand(byte[] cmd) { // synchronized (obj1) { currentCommand = cmd[0]; // } @@ -236,8 +234,7 @@ public class RobotMain { } /** - * Sets debug messaging state: true - Activate debug messages false - - * deactivate debug messages + * Sets debug messaging state: true - Activate debug messages false - deactivate debug messages */ static public void setDebug(boolean debug) { DEBUG = debug; @@ -246,19 +243,22 @@ public class RobotMain { /** * Runs the robot's main thread. */ - @LATTICE("THIS " + Integer.toString(timePosition)); } int timePosLocal = normalizeTime(timePosition); - int motorUpTime = - (timePosLocal * 100 + ((100 - timePosLocal) * (100 - agilityFactor))) * speedFactor; + int motorUpTime = (timePosLocal * 100 + ((100 - timePosLocal) * (100 - agilityFactor))) * speedFactor; if (motorUpTime == 0) { motorUpTime = 1; // System.out.println("returning...."); @@ -185,8 +184,7 @@ public class MotorControl { System.out.println("setSpeedTurnRight: input-> " + Integer.toString(timePosition)); } int timePos = normalizeTime(timePosition); - int motorUpTime = - ((timePos * 100) + ((100 - timePos) * (100 - agilityFactor))) * speedFactor; + int motorUpTime = ((timePos * 100) + ((100 - timePos) * (100 - agilityFactor))) * speedFactor; if (motorUpTime == 0) { motorUpTime = 1; // System.out.println("returning...."); diff --git a/Robust/src/Benchmarks/SSJava/JavaNatorInfer/PWMManager.java b/Robust/src/Benchmarks/SSJava/JavaNatorInfer/PWMManager.java index 09f4aeb7..e899ac9c 100644 --- a/Robust/src/Benchmarks/SSJava/JavaNatorInfer/PWMManager.java +++ b/Robust/src/Benchmarks/SSJava/JavaNatorInfer/PWMManager.java @@ -18,11 +18,10 @@ */ /** - * PWMManager - Interface between robot strategy code and the various motors - * PWMControl classes. Agility is a number between 0 to 100 and represent the - * precentage of max speed to be applied to the turn side wheel. On left turn - * the left wheel will receive less speed as % of "speed" value represented by - * agility. + * PWMManager - Interface between robot strategy code and the various motors PWMControl classes. + * Agility is a number between 0 to 100 and represent the precentage of max speed to be applied to + * the turn side wheel. On left turn the left wheel will receive less speed as % of "speed" value + * represented by agility. * * @author Michael Gesundheit * @version 1.0 @@ -57,8 +56,8 @@ public class PWMManager { */ public PWMManager(String pwmSelection) { /* - * Instantiate PWM Makers one for each motor. motorPortId is 1 to 8 and is - * corresponding to 8 bits in a byte. + * Instantiate PWM Makers one for each motor. motorPortId is 1 to 8 and is corresponding to 8 + * bits in a byte. */ // if (pwmSelection.equals("rtsj")) // pwmControl = new PWMRtsj(this, MOTOR_PORTID_6, MOTOR_PORTID_7); @@ -100,9 +99,8 @@ public class PWMManager { currentRegMask |= myValue; /* * // if (DEBUG){ // System.out.println("PWMM: writeToPort: myBit = 0x" + - * Integer.toHexString(myBit) + // " ~myBit = 0x" + - * Integer.toHexString(~myBit) + " myValue = 0x" + // - * Integer.toHexString(myValue) + " currentRegMask = 0x" + // + * Integer.toHexString(myBit) + // " ~myBit = 0x" + Integer.toHexString(~myBit) + + * " myValue = 0x" + // Integer.toHexString(myValue) + " currentRegMask = 0x" + // * Integer.toHexString(currentRegMask)); //} */ // rawJEM.set(GPIO_E_OUT, currentRegMask); @@ -112,20 +110,16 @@ public class PWMManager { * public void stop(){ if(DEBUG) System.out.println("PWMManager: stop...."); * pwmControl.setSpeedLeft(zeroSpeed); pwmControl.setSpeedRight(zeroSpeed); } * - * public void search(){ if(DEBUG) - * System.out.println("PWMManager: search...."); pwmControl.setSpeedLeft(70); - * pwmControl.setSpeedRight(50); } + * public void search(){ if(DEBUG) System.out.println("PWMManager: search...."); + * pwmControl.setSpeedLeft(70); pwmControl.setSpeedRight(50); } * - * public void straight(){ if(DEBUG) - * System.out.println("PWMManager: strait...."); pwmControl.setSpeedLeft(100); - * pwmControl.setSpeedRight(100); } + * public void straight(){ if(DEBUG) System.out.println("PWMManager: strait...."); + * pwmControl.setSpeedLeft(100); pwmControl.setSpeedRight(100); } * - * public void spinRight(){ if(DEBUG) - * System.out.println("PWMManager: spinRight...."); + * public void spinRight(){ if(DEBUG) System.out.println("PWMManager: spinRight...."); * pwmControl.setSpeedSpinLeft(100); pwmControl.setSpeedSpinRight(0); } * - * public void spinLeft(){ if(DEBUG) - * System.out.println("PWMManager: spinLeft...."); + * public void spinLeft(){ if(DEBUG) System.out.println("PWMManager: spinLeft...."); * pwmControl.setSpeedSpinLeft(0); pwmControl.setSpeedSpinRight(100); } * * public void spin180(){ int mod = (rand.nextInt() % 2); @@ -140,23 +134,19 @@ public class PWMManager { * public void left(){ if(DEBUG) System.out.println("PWMManager: left...."); * pwmControl.setSpeedLeft(zeroSpeed); pwmControl.setSpeedTurnRight(100); } * - * public void bearRight(){ if(DEBUG) - * System.out.println("PWMManager: bearRight...."); + * public void bearRight(){ if(DEBUG) System.out.println("PWMManager: bearRight...."); * pwmControl.setSpeedTurnLeft(100); pwmControl.setSpeedTurnRight(60); } * - * public void bearLeft(){ if(DEBUG) - * System.out.println("PWMManager: bearLeft...."); + * public void bearLeft(){ if(DEBUG) System.out.println("PWMManager: bearLeft...."); * pwmControl.setSpeedTurnLeft(60); pwmControl.setSpeedTurnRight(100); } * * public void back(){ if(DEBUG) System.out.println("PWMManager: back...."); * pwmControl.setSpeedLeft(0); pwmControl.setSpeedRight(0); } * - * public void backBearLeft(){ if(DEBUG) - * System.out.println("PWMManager: backBearLeft...."); + * public void backBearLeft(){ if(DEBUG) System.out.println("PWMManager: backBearLeft...."); * pwmControl.setSpeedLeft(30); pwmControl.setSpeedRight(0); } * - * public void backBearRight(){ if(DEBUG) - * System.out.println("PWMManager: backBearRight...."); + * public void backBearRight(){ if(DEBUG) System.out.println("PWMManager: backBearRight...."); * pwmControl.setSpeedLeft(0); pwmControl.setSpeedRight(30); } */ public void resume() { @@ -205,10 +195,10 @@ public class PWMManager { } /** - * Control debug messaging. true - Activate debug messages false - deactivate - * debug messages + * Control debug messaging. true - Activate debug messages false - deactivate debug messages */ public void setDebug(boolean debug) { DEBUG = debug; } + } \ No newline at end of file diff --git a/Robust/src/Benchmarks/SSJava/JavaNatorInfer/RandomWrapper.java b/Robust/src/Benchmarks/SSJava/JavaNatorInfer/RandomWrapper.java new file mode 100644 index 00000000..9ab0fc6b --- /dev/null +++ b/Robust/src/Benchmarks/SSJava/JavaNatorInfer/RandomWrapper.java @@ -0,0 +1,14 @@ +public class RandomWrapper { + private static Random rand; + + @TRUST + public static void init() { + rand = new Random(); + } + + @TRUST + public static int nextInt() { + return rand.nextInt(); + } + +} diff --git a/Robust/src/Benchmarks/SSJava/JavaNatorInfer/RobotMain.java b/Robust/src/Benchmarks/SSJava/JavaNatorInfer/RobotMain.java index a3d582a8..f7e780ee 100644 --- a/Robust/src/Benchmarks/SSJava/JavaNatorInfer/RobotMain.java +++ b/Robust/src/Benchmarks/SSJava/JavaNatorInfer/RobotMain.java @@ -32,14 +32,14 @@ public class RobotMain { private static boolean DEBUG = true; - private static final int OFF_MODE = 1; - private static final int ON_MODE = 2; - private static final int MANUAL_MODE = 1; - private static final int AUTONOMUS_MODE = 2; - private static final int ON_OFF = 128;// 0x80 - private static final int MANUAL_AUTONOMUS = 32; // 0x20 + public static final int OFF_MODE = 1; + public static final int ON_MODE = 2; + public static final int MANUAL_MODE = 1; + public static final int AUTONOMUS_MODE = 2; + public static final int ON_OFF = 128;// 0x80 + public static final int MANUAL_AUTONOMUS = 32; // 0x20 public static final int LINE_SENSORS = 64; // 0x40 - private static final int SONAR_SENSORS = 96; // 0x60 + public static final int SONAR_SENSORS = 96; // 0x60 public static final int ALL_COMMANDS = 0xe0; public static final byte LF_FRONT = 0x1; @@ -56,31 +56,31 @@ public class RobotMain { public static final byte LS_LEFT_REAR = 0x5; public static final byte LS_RIGHT_REAR = 0x6; public static final byte LS_ALL = 0x7; - private static final int ALL_DATA = 0x1f; + public static final int ALL_DATA = 0x1f; - private static PWMManager pwmm; + private PWMManager pwmm; - private static StrategyMgr strategyMgr; + private StrategyMgr strategyMgr; - private static int onOffMode = ON_MODE; + private int onOffMode = ON_MODE; - private static int manualAutonomusMode = AUTONOMUS_MODE; + private int manualAutonomusMode = AUTONOMUS_MODE; - private static byte lineSensorsMask; + private byte lineSensorsMask; - private static byte sonarSensors; + private byte sonarSensors; - private static byte currentCommand; + private byte currentCommand; - private static byte privSonars; + private byte privSonars; - private static byte privLineSensors; + private byte privLineSensors; - private static byte currentSonars; + private byte currentSonars; - public static String pwmSelection; + public String pwmSelection; /** * Constructor for the class for the robot main thread. @@ -89,20 +89,18 @@ public class RobotMain { } /** - * Processes sonar sensor input. This method is called each time new sonar - * sensor data arrives, and each time that a mode switch occurs between ON/OFF - * and Manual Override. + * Processes sonar sensor input. This method is called each time new sonar sensor data arrives, + * and each time that a mode switch occurs between ON/OFF and Manual Override. */ - static void processSonars() { + void processSonars() { strategyMgr.processSonars(sonarSensors); } /** - * Processes line sensor input. This method is called each time new line - * sensor data arrives, and each time that a mode switch occurs between ON/OFF - * and Manual Override. + * Processes line sensor input. This method is called each time new line sensor data arrives, and + * each time that a mode switch occurs between ON/OFF and Manual Override. */ - static void processLineSensors() { + void processLineSensors() { strategyMgr.processLineSensors(lineSensorsMask); resume(); } @@ -110,16 +108,16 @@ public class RobotMain { /** * Resumes motors as per the last sonar command. */ - public static void resume() { + void resume() { processSonars(); } /** - * Extracts sonar sensor data from the adjunct sensor controller and from line - * sensor data from the JStamp line sensor pins. + * Extracts sonar sensor data from the adjunct sensor controller and from line sensor data from + * the JStamp line sensor pins. */ - private static void processIOCommand() { + private void processIOCommand() { // int data = 0; // int opCode = 0; @@ -170,8 +168,8 @@ public class RobotMain { lineSensorsMask = (byte) (data & LS_ALL); /* - * Line sensors with '0' data means the robot moved off the edge line, and - * there is nothing to do. + * Line sensors with '0' data means the robot moved off the edge line, and there is nothing to + * do. */ if (((data & LS_ALL) == 0) || ((data & LS_ALL) == privLineSensors)) { privLineSensors = (byte) (data & LS_ALL); @@ -190,8 +188,8 @@ public class RobotMain { } currentSonars = (byte) (data & ALL_SONARS); /* - * No need to synchronized on this variable assignment since all referring - * code is on the same logical thread + * No need to synchronized on this variable assignment since all referring code is on the same + * logical thread */ sonarSensors = (byte) currentSonars; if ((onOffMode == ON_MODE) && (manualAutonomusMode == AUTONOMUS_MODE)) { @@ -222,7 +220,7 @@ public class RobotMain { /** * Saves the current IOManager command byte locally. */ - static public void setIOManagerCommand(byte[] cmd) { + public void setIOManagerCommand(byte[] cmd) { // synchronized (obj1) { currentCommand = cmd[0]; // } @@ -236,8 +234,7 @@ public class RobotMain { } /** - * Sets debug messaging state: true - Activate debug messages false - - * deactivate debug messages + * Sets debug messaging state: true - Activate debug messages false - deactivate debug messages */ static public void setDebug(boolean debug) { DEBUG = debug; @@ -246,19 +243,22 @@ public class RobotMain { /** * Runs the robot's main thread. */ - public static void main( String args[]) { TestSensorInput.init(); + RobotMain r = new RobotMain(); + r.doit(); + } + + + public void doit() { boolean active = true; /** - * RealTime management of the robot behaviour based on sensors and commands - * input. + * RealTime management of the robot behaviour based on sensors and commands input. */ /** - * Set the low level PWM interface type, e.g. "rtsj" or "native" (ajile - * library-based). + * Set the low level PWM interface type, e.g. "rtsj" or "native" (ajile library-based). */ pwmSelection = "rtsj"; @@ -273,38 +273,45 @@ public class RobotMain { strategyMgr = new StrategyMgr(mc); /* - * Sets initial values for the speed and agility parameters. Speed and - * agility are arbitrary scale factors for the overall speed and speed of - * turns, respectively. These work with PWM via the native ajile libraries, - * but do not work well with the RTSJ implementation due to limits on the - * granularity of timing for the PWM pulse (quantization). + * Sets initial values for the speed and agility parameters. Speed and agility are arbitrary + * scale factors for the overall speed and speed of turns, respectively. These work with PWM via + * the native ajile libraries, but do not work well with the RTSJ implementation due to limits + * on the granularity of timing for the PWM pulse (quantization). */ pwmm.setSpeedAgilityFactors(100, 100); /* - * Robot's initial state is "ON" by default. Set this parameter to "OFF" if - * the robot is to be started over the TCP/IP link. + * Robot's initial state is "ON" by default. Set this parameter to "OFF" if the robot is to be + * started over the TCP/IP link. */ // issueCommand("OFF"); SSJAVA: while (active) { - // if (DEBUG) { - // System.out.println("Main: Waiting for remote commands"); - // } - // try { - // obj.wait(); - // } catch (IllegalMonitorStateException ie) { - // System.out.println("IllegalMonitorStateException caught in main loop"); - // } - currentCommand = TestSensorInput.getCommand(); + Command com = HWSimulator.getCommand(); + currentCommand = com.command; + sonarSensors = com.sonarSensors; + lineSensorsMask = com.lineSensorsMask; + manualAutonomusMode = com.manualAutonomusMode; + onOffMode = com.onOffMode; + if (currentCommand == -1) { break; } System.out.println("currentCommand=" + currentCommand); processIOCommand(); + // erase current settings + initialize(); } System.exit(0); } + public void initialize() { + privLineSensors = 0; + currentCommand = 0; + privSonars = 0; + currentSonars = 0; + pwmSelection = ""; + } + } diff --git a/Robust/src/Benchmarks/SSJava/JavaNatorInfer/StrategyMgr.java b/Robust/src/Benchmarks/SSJava/JavaNatorInfer/StrategyMgr.java index c46b5fdf..37378625 100644 --- a/Robust/src/Benchmarks/SSJava/JavaNatorInfer/StrategyMgr.java +++ b/Robust/src/Benchmarks/SSJava/JavaNatorInfer/StrategyMgr.java @@ -32,8 +32,6 @@ public class StrategyMgr { private MotorControl mc; private static final int zeroSpeed = 45; - private Random rand; - private boolean DEBUGL = true; // private boolean DEBUGL = false; @@ -46,7 +44,7 @@ public class StrategyMgr { */ public StrategyMgr(@DELEGATE MotorControl motorControl) { mc = motorControl; - rand = new Random(); + RandomWrapper.init(); } void processSonars( byte sonarSensors) { @@ -206,7 +204,7 @@ public class StrategyMgr { } public void spin180() { - int mod = (rand.nextInt() % 2); + int mod = (RandomWrapper.nextInt() % 2); if (DEBUG) System.out.println("StrategyMgr: spin180...."); -- 2.34.1