Changes: Inference engine works fine with the JavaNator benchmark. Found some problem...
authoryeom <yeom>
Sun, 4 Nov 2012 23:20:39 +0000 (23:20 +0000)
committeryeom <yeom>
Sun, 4 Nov 2012 23:20:39 +0000 (23:20 +0000)
15 files changed:
Robust/src/Analysis/SSJava/LocationInference.java
Robust/src/Benchmarks/SSJava/JavaNator/Command.java [new file with mode: 0644]
Robust/src/Benchmarks/SSJava/JavaNator/HWSimulator.java [new file with mode: 0644]
Robust/src/Benchmarks/SSJava/JavaNator/PWMManager.java
Robust/src/Benchmarks/SSJava/JavaNator/RCBridge.java
Robust/src/Benchmarks/SSJava/JavaNator/RandomWrapper.java [new file with mode: 0644]
Robust/src/Benchmarks/SSJava/JavaNator/RobotMain.java
Robust/src/Benchmarks/SSJava/JavaNator/StrategyMgr.java
Robust/src/Benchmarks/SSJava/JavaNatorInfer/Command.java [new file with mode: 0644]
Robust/src/Benchmarks/SSJava/JavaNatorInfer/HWSimulator.java [new file with mode: 0644]
Robust/src/Benchmarks/SSJava/JavaNatorInfer/MotorControl.java
Robust/src/Benchmarks/SSJava/JavaNatorInfer/PWMManager.java
Robust/src/Benchmarks/SSJava/JavaNatorInfer/RandomWrapper.java [new file with mode: 0644]
Robust/src/Benchmarks/SSJava/JavaNatorInfer/RobotMain.java
Robust/src/Benchmarks/SSJava/JavaNatorInfer/StrategyMgr.java

index 8c1c97926e25814c8f21649d7c1c6bed7ba6b612..ec8c60492b129128578221f5240e1b60a80e2a93 100644 (file)
@@ -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<FlowNode> 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<Descriptor> 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<Descriptor> paramDescTuple = paramNode.getCurrentDescTuple();
 
         NTuple<Location> 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<Descriptor> 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<Location> 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<MethodInvokeNode> 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<GlobalFlowNode> 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<Location> locTuple = translateToLocTuple(md, reachalbeNode.getDescTuple());
-    // NTuple<Location> 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<NTuple<Location>> toberemoved = new HashSet<NTuple<Location>>();
-    // for (int i = 0; i < prefixList.size(); i++) {
-    // NTuple<Location> 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<Location> 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>();
-      // Location loc = new Location(md, srcVarDesc);
-      // srcLocTuple.add(loc);
-      // }
-      //
       NTuple<Location> dstLocTuple = translateToLocTuple(md, dstDescTuple);
-      // Location dstMethodLoc = dstLocTuple.get(0);
-      // Descriptor dstVarDesc = dstMethodLoc.getLocDescriptor();
-      // if (!dstVarDesc.equals(md.getThis())) {
-      // dstLocTuple = new NTuple<Location>();
-      // 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<Location> pcLocTuple = (NTuple<Location>) 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<Descriptor> 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<NTuple<Location>> iterator = nodeSetRHS.globalIterator(); iterator.hasNext();) {
         NTuple<Location> calleeReturnLocTuple = iterator.next();
-        System.out.println("B7");
 
         globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, tupleLHS));
       }
@@ -4874,7 +4739,6 @@ public class LocationInference {
       for (Iterator<NTuple<Location>> iterator = implicitFlowTupleSet.globalIterator(); iterator
           .hasNext();) {
         NTuple<Location> 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<Location> calleeReturnLocTuple = iterator.next();
         for (Iterator<NTuple<Descriptor>> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) {
           NTuple<Descriptor> 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<NTuple<Location>> iterator = idxNodeTupleSet.globalIterator(); iterator
             .hasNext();) {
           NTuple<Location> 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<Descriptor> 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<Location> calleeReturnLocTuple = iterator.next();
         for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
           NTuple<Descriptor> 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 (file)
index 0000000..801e670
--- /dev/null
@@ -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 (file)
index 0000000..d859364
--- /dev/null
@@ -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;
+
+  }
+
+}
index d194470246583d29f1df548d7d923f9cacfc4563..d93442fa8516b62439048d4b74328a8650ebd7a0 100644 (file)
  */\r
 \r
 /**\r
- * PWMManager - Interface between robot strategy code and the various motors\r
- * PWMControl classes. Agility is a number between 0 to 100 and represent the\r
- * precentage of max speed to be applied to the turn side wheel. On left turn\r
- * the left wheel will receive less speed as % of "speed" value represented by\r
- * agility.\r
+ * PWMManager - Interface between robot strategy code and the various motors PWMControl classes.\r
+ * Agility is a number between 0 to 100 and represent the precentage of max speed to be applied to\r
+ * the turn side wheel. On left turn the left wheel will receive less speed as % of "speed" value\r
+ * represented by agility.\r
  * \r
  * @author Michael Gesundheit\r
  * @version 1.0\r
@@ -57,8 +56,8 @@ public class PWMManager {
    */\r
   public PWMManager(String pwmSelection) {\r
     /*\r
-     * Instantiate PWM Makers one for each motor. motorPortId is 1 to 8 and is\r
-     * corresponding to 8 bits in a byte.\r
+     * Instantiate PWM Makers one for each motor. motorPortId is 1 to 8 and is corresponding to 8\r
+     * bits in a byte.\r
      */\r
     // if (pwmSelection.equals("rtsj"))\r
     // pwmControl = new PWMRtsj(this, MOTOR_PORTID_6, MOTOR_PORTID_7);\r
@@ -100,9 +99,8 @@ public class PWMManager {
     currentRegMask |= myValue;\r
     /*\r
      * // if (DEBUG){ // System.out.println("PWMM: writeToPort: myBit = 0x" +\r
-     * Integer.toHexString(myBit) + // " ~myBit = 0x" +\r
-     * Integer.toHexString(~myBit) + " myValue = 0x" + //\r
-     * Integer.toHexString(myValue) + " currentRegMask = 0x" + //\r
+     * Integer.toHexString(myBit) + // " ~myBit = 0x" + Integer.toHexString(~myBit) +\r
+     * " myValue = 0x" + // Integer.toHexString(myValue) + " currentRegMask = 0x" + //\r
      * Integer.toHexString(currentRegMask)); //}\r
      */\r
     // rawJEM.set(GPIO_E_OUT, currentRegMask);\r
@@ -112,20 +110,16 @@ public class PWMManager {
    * public void stop(){ if(DEBUG) System.out.println("PWMManager: stop....");\r
    * pwmControl.setSpeedLeft(zeroSpeed); pwmControl.setSpeedRight(zeroSpeed); }\r
    * \r
-   * public void search(){ if(DEBUG)\r
-   * System.out.println("PWMManager: search...."); pwmControl.setSpeedLeft(70);\r
-   * pwmControl.setSpeedRight(50); }\r
+   * public void search(){ if(DEBUG) System.out.println("PWMManager: search....");\r
+   * pwmControl.setSpeedLeft(70); pwmControl.setSpeedRight(50); }\r
    * \r
-   * public void straight(){ if(DEBUG)\r
-   * System.out.println("PWMManager: strait...."); pwmControl.setSpeedLeft(100);\r
-   * pwmControl.setSpeedRight(100); }\r
+   * public void straight(){ if(DEBUG) System.out.println("PWMManager: strait....");\r
+   * pwmControl.setSpeedLeft(100); pwmControl.setSpeedRight(100); }\r
    * \r
-   * public void spinRight(){ if(DEBUG)\r
-   * System.out.println("PWMManager: spinRight....");\r
+   * public void spinRight(){ if(DEBUG) System.out.println("PWMManager: spinRight....");\r
    * pwmControl.setSpeedSpinLeft(100); pwmControl.setSpeedSpinRight(0); }\r
    * \r
-   * public void spinLeft(){ if(DEBUG)\r
-   * System.out.println("PWMManager: spinLeft....");\r
+   * public void spinLeft(){ if(DEBUG) System.out.println("PWMManager: spinLeft....");\r
    * pwmControl.setSpeedSpinLeft(0); pwmControl.setSpeedSpinRight(100); }\r
    * \r
    * public void spin180(){ int mod = (rand.nextInt() % 2);\r
@@ -140,23 +134,19 @@ public class PWMManager {
    * public void left(){ if(DEBUG) System.out.println("PWMManager: left....");\r
    * pwmControl.setSpeedLeft(zeroSpeed); pwmControl.setSpeedTurnRight(100); }\r
    * \r
-   * public void bearRight(){ if(DEBUG)\r
-   * System.out.println("PWMManager: bearRight....");\r
+   * public void bearRight(){ if(DEBUG) System.out.println("PWMManager: bearRight....");\r
    * pwmControl.setSpeedTurnLeft(100); pwmControl.setSpeedTurnRight(60); }\r
    * \r
-   * public void bearLeft(){ if(DEBUG)\r
-   * System.out.println("PWMManager: bearLeft....");\r
+   * public void bearLeft(){ if(DEBUG) System.out.println("PWMManager: bearLeft....");\r
    * pwmControl.setSpeedTurnLeft(60); pwmControl.setSpeedTurnRight(100); }\r
    * \r
    * public void back(){ if(DEBUG) System.out.println("PWMManager: back....");\r
    * pwmControl.setSpeedLeft(0); pwmControl.setSpeedRight(0); }\r
    * \r
-   * public void backBearLeft(){ if(DEBUG)\r
-   * System.out.println("PWMManager: backBearLeft....");\r
+   * public void backBearLeft(){ if(DEBUG) System.out.println("PWMManager: backBearLeft....");\r
    * pwmControl.setSpeedLeft(30); pwmControl.setSpeedRight(0); }\r
    * \r
-   * public void backBearRight(){ if(DEBUG)\r
-   * System.out.println("PWMManager: backBearRight....");\r
+   * public void backBearRight(){ if(DEBUG) System.out.println("PWMManager: backBearRight....");\r
    * pwmControl.setSpeedLeft(0); pwmControl.setSpeedRight(30); }\r
    */\r
   public void resume() {\r
@@ -205,10 +195,10 @@ public class PWMManager {
   }\r
 \r
   /**\r
-   * Control debug messaging. true - Activate debug messages false - deactivate\r
-   * debug messages\r
+   * Control debug messaging. true - Activate debug messages false - deactivate debug messages\r
    */\r
   public void setDebug(boolean debug) {\r
     DEBUG = debug;\r
   }\r
+\r
 }
\ No newline at end of file
index fd60f3be8070eeccb0395a2119728602ec818001..28a23e9b24e5b38e400bcffeca30dc1bf22759bf 100644 (file)
@@ -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 (file)
index 0000000..9ab0fc6
--- /dev/null
@@ -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();
+  }
+
+}
index 5c822396179e0604d3d5735781fb0e85bb878df4..a4ed1715969698a7bcf866bef2d4b60ba64b8b70 100644 (file)
@@ -32,14 +32,14 @@ public class RobotMain {
   @LOC("T")\r
   private static boolean DEBUG = true;\r
 \r
-  private static final int OFF_MODE = 1;\r
-  private static final int ON_MODE = 2;\r
-  private static final int MANUAL_MODE = 1;\r
-  private static final int AUTONOMUS_MODE = 2;\r
-  private static final int ON_OFF = 128;// 0x80\r
-  private static final int MANUAL_AUTONOMUS = 32; // 0x20\r
+  public static final int OFF_MODE = 1;\r
+  public static final int ON_MODE = 2;\r
+  public static final int MANUAL_MODE = 1;\r
+  public static final int AUTONOMUS_MODE = 2;\r
+  public static final int ON_OFF = 128;// 0x80\r
+  public static final int MANUAL_AUTONOMUS = 32; // 0x20\r
   public static final int LINE_SENSORS = 64; // 0x40\r
-  private static final int SONAR_SENSORS = 96; // 0x60\r
+  public static final int SONAR_SENSORS = 96; // 0x60\r
   public static final int ALL_COMMANDS = 0xe0;\r
 \r
   public static final byte LF_FRONT = 0x1;\r
@@ -56,31 +56,31 @@ public class RobotMain {
   public static final byte LS_LEFT_REAR = 0x5;\r
   public static final byte LS_RIGHT_REAR = 0x6;\r
   public static final byte LS_ALL = 0x7;\r
-  private static final int ALL_DATA = 0x1f;\r
+  public static final int ALL_DATA = 0x1f;\r
 \r
   @LOC("MGR")\r
-  private static PWMManager pwmm;\r
+  private PWMManager pwmm;\r
   @LOC("MGR")\r
-  private static StrategyMgr strategyMgr;\r
+  private StrategyMgr strategyMgr;\r
 \r
   @LOC("MASK")\r
-  private static int onOffMode = ON_MODE;\r
+  private int onOffMode = ON_MODE;\r
   @LOC("MASK")\r
-  private static int manualAutonomusMode = AUTONOMUS_MODE;\r
+  private int manualAutonomusMode = AUTONOMUS_MODE;\r
   @LOC("MASK")\r
-  private static byte lineSensorsMask;\r
+  private byte lineSensorsMask;\r
   @LOC("MASK")\r
-  private static byte sonarSensors;\r
+  private byte sonarSensors;\r
   @LOC("CCMD")\r
-  private static byte currentCommand;\r
+  private byte currentCommand;\r
   @LOC("MASK")\r
-  private static byte privSonars;\r
+  private byte privSonars;\r
   @LOC("PREV")\r
-  private static byte privLineSensors;\r
+  private byte privLineSensors;\r
   @LOC("MASK")\r
-  private static byte currentSonars;\r
+  private byte currentSonars;\r
   @LOC("MASK")\r
-  public static String pwmSelection;\r
+  public String pwmSelection;\r
 \r
   /**\r
    * Constructor for the class for the robot main thread.\r
@@ -89,20 +89,18 @@ public class RobotMain {
   }\r
 \r
   /**\r
-   * Processes sonar sensor input. This method is called each time new sonar\r
-   * sensor data arrives, and each time that a mode switch occurs between ON/OFF\r
-   * and Manual Override.\r
+   * Processes sonar sensor input. This method is called each time new sonar sensor data arrives,\r
+   * and each time that a mode switch occurs between ON/OFF and Manual Override.\r
    */\r
-  static void processSonars() {\r
+  void processSonars() {\r
     strategyMgr.processSonars(sonarSensors);\r
   }\r
 \r
   /**\r
-   * Processes line sensor input. This method is called each time new line\r
-   * sensor data arrives, and each time that a mode switch occurs between ON/OFF\r
-   * and Manual Override.\r
+   * Processes line sensor input. This method is called each time new line sensor data arrives, and\r
+   * each time that a mode switch occurs between ON/OFF and Manual Override.\r
    */\r
-  static void processLineSensors() {\r
+  void processLineSensors() {\r
     strategyMgr.processLineSensors(lineSensorsMask);\r
     resume();\r
   }\r
@@ -110,16 +108,16 @@ public class RobotMain {
   /**\r
    * Resumes motors as per the last sonar command.\r
    */\r
-  public static void resume() {\r
+  void resume() {\r
     processSonars();\r
   }\r
 \r
   /**\r
-   * Extracts sonar sensor data from the adjunct sensor controller and from line\r
-   * sensor data from the JStamp line sensor pins.\r
+   * Extracts sonar sensor data from the adjunct sensor controller and from line sensor data from\r
+   * the JStamp line sensor pins.\r
    */\r
   @LATTICE("THIS,THISLOC=THIS,GLOBALLOC=THIS")\r
-  private static void processIOCommand() {\r
+  private void processIOCommand() {\r
 \r
     // int data = 0;\r
     // int opCode = 0;\r
@@ -170,8 +168,8 @@ public class RobotMain {
       lineSensorsMask = (byte) (data & LS_ALL);\r
 \r
       /*\r
-       * Line sensors with '0' data means the robot moved off the edge line, and\r
-       * there is nothing to do.\r
+       * Line sensors with '0' data means the robot moved off the edge line, and there is nothing to\r
+       * do.\r
        */\r
       if (((data & LS_ALL) == 0) || ((data & LS_ALL) == privLineSensors)) {\r
         privLineSensors = (byte) (data & LS_ALL);\r
@@ -190,8 +188,8 @@ public class RobotMain {
       }\r
       currentSonars = (byte) (data & ALL_SONARS);\r
       /*\r
-       * No need to synchronized on this variable assignment since all referring\r
-       * code is on the same logical thread\r
+       * No need to synchronized on this variable assignment since all referring code is on the same\r
+       * logical thread\r
        */\r
       sonarSensors = (byte) currentSonars;\r
       if ((onOffMode == ON_MODE) && (manualAutonomusMode == AUTONOMUS_MODE)) {\r
@@ -222,7 +220,7 @@ public class RobotMain {
   /**\r
    * Saves the current IOManager command byte locally.\r
    */\r
-  static public void setIOManagerCommand(byte[] cmd) {\r
+  public void setIOManagerCommand(byte[] cmd) {\r
     // synchronized (obj1) {\r
     currentCommand = cmd[0];\r
     // }\r
@@ -236,8 +234,7 @@ public class RobotMain {
   }\r
 \r
   /**\r
-   * Sets debug messaging state: true - Activate debug messages false -\r
-   * deactivate debug messages\r
+   * Sets debug messaging state: true - Activate debug messages false - deactivate debug messages\r
    */\r
   static public void setDebug(boolean debug) {\r
     DEBUG = debug;\r
@@ -246,19 +243,22 @@ public class RobotMain {
   /**\r
    * Runs the robot's main thread.\r
    */\r
-  @LATTICE("THIS<C,THIS<MC,MC<IN,C<IN,IN<T,C*,THISLOC=THIS,GLOBALLOC=THIS")\r
   public static void main(@LOC("IN") String args[]) {\r
 \r
     TestSensorInput.init();\r
+    RobotMain r = new RobotMain();\r
+    r.doit();\r
+  }\r
+\r
+  @LATTICE("THIS<C,THIS<MC,MC<IN,C<IN,IN<T,C*,THISLOC=THIS,GLOBALLOC=THIS")\r
+  public void doit() {\r
     @LOC("T") boolean active = true;\r
     /**\r
-     * RealTime management of the robot behaviour based on sensors and commands\r
-     * input.\r
+     * RealTime management of the robot behaviour based on sensors and commands input.\r
      */\r
 \r
     /**\r
-     * Set the low level PWM interface type, e.g. "rtsj" or "native" (ajile\r
-     * library-based).\r
+     * Set the low level PWM interface type, e.g. "rtsj" or "native" (ajile library-based).\r
      */\r
     pwmSelection = "rtsj";\r
 \r
@@ -273,38 +273,45 @@ public class RobotMain {
     strategyMgr = new StrategyMgr(mc);\r
 \r
     /*\r
-     * Sets initial values for the speed and agility parameters. Speed and\r
-     * agility are arbitrary scale factors for the overall speed and speed of\r
-     * turns, respectively. These work with PWM via the native ajile libraries,\r
-     * but do not work well with the RTSJ implementation due to limits on the\r
-     * granularity of timing for the PWM pulse (quantization).\r
+     * Sets initial values for the speed and agility parameters. Speed and agility are arbitrary\r
+     * scale factors for the overall speed and speed of turns, respectively. These work with PWM via\r
+     * the native ajile libraries, but do not work well with the RTSJ implementation due to limits\r
+     * on the granularity of timing for the PWM pulse (quantization).\r
      */\r
     pwmm.setSpeedAgilityFactors(100, 100);\r
 \r
     /*\r
-     * Robot's initial state is "ON" by default. Set this parameter to "OFF" if\r
-     * the robot is to be started over the TCP/IP link.\r
+     * Robot's initial state is "ON" by default. Set this parameter to "OFF" if the robot is to be\r
+     * started over the TCP/IP link.\r
      */\r
     // issueCommand("OFF");\r
 \r
     SSJAVA: while (active) {\r
 \r
-      // if (DEBUG) {\r
-      // System.out.println("Main: Waiting for remote commands");\r
-      // }\r
-      // try {\r
-      // obj.wait();\r
-      // } catch (IllegalMonitorStateException ie) {\r
-      // System.out.println("IllegalMonitorStateException caught in main loop");\r
-      // }\r
-      currentCommand = TestSensorInput.getCommand();\r
+      @LOC("IN") Command com = HWSimulator.getCommand();\r
+      currentCommand = com.command;\r
+      sonarSensors = com.sonarSensors;\r
+      lineSensorsMask = com.lineSensorsMask;\r
+      manualAutonomusMode = com.manualAutonomusMode;\r
+      onOffMode = com.onOffMode;\r
+\r
       if (currentCommand == -1) {\r
         break;\r
       }\r
       System.out.println("currentCommand=" + currentCommand);\r
       processIOCommand();\r
+      // erase current settings\r
+      initialize();\r
     }\r
     System.exit(0);\r
   }\r
 \r
+  public void initialize() {\r
+    privLineSensors = 0;\r
+    currentCommand = 0;\r
+    privSonars = 0;\r
+    currentSonars = 0;\r
+    pwmSelection = "";\r
+  }\r
+\r
 }\r
index 6e19ca04f2b10686fa92402d6457c0ca54dfd6b3..01a8bcc96af04373f1e22cf84b9520138b3453a9 100644 (file)
@@ -32,8 +32,6 @@ public class StrategyMgr {
   private MotorControl mc;\r
   private static final int zeroSpeed = 45;\r
   @LOC("T")\r
-  private Random rand;\r
-  @LOC("T")\r
   private boolean DEBUGL = true;\r
   // private boolean DEBUGL = false;\r
 \r
@@ -46,7 +44,7 @@ public class StrategyMgr {
    */\r
   public StrategyMgr(@DELEGATE MotorControl motorControl) {\r
     mc = motorControl;\r
-    rand = new Random();\r
+    RandomWrapper.init();\r
   }\r
 \r
   void processSonars(@LOC("IN") byte sonarSensors) {\r
@@ -206,7 +204,7 @@ public class StrategyMgr {
   }\r
 \r
   public void spin180() {\r
-    @LOC("THIS,StrategyMgr.V") int mod = (rand.nextInt() % 2);\r
+    @LOC("THIS,StrategyMgr.V") int mod = (RandomWrapper.nextInt() % 2);\r
 \r
     if (DEBUG)\r
       System.out.println("StrategyMgr: spin180....");\r
diff --git a/Robust/src/Benchmarks/SSJava/JavaNatorInfer/Command.java b/Robust/src/Benchmarks/SSJava/JavaNatorInfer/Command.java
new file mode 100644 (file)
index 0000000..9898585
--- /dev/null
@@ -0,0 +1,10 @@
+
+public class Command {
+
+   public int onOffMode;
+   public int manualAutonomusMode;
+   public byte lineSensorsMask;
+   public byte sonarSensors;
+   byte command;
+
+}
diff --git a/Robust/src/Benchmarks/SSJava/JavaNatorInfer/HWSimulator.java b/Robust/src/Benchmarks/SSJava/JavaNatorInfer/HWSimulator.java
new file mode 100644 (file)
index 0000000..d859364
--- /dev/null
@@ -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;
+
+  }
+
+}
index ea7f2f060e0b61da743e9177671c0d314e890d86..0ced28877c9a7924605d1e1852697cc444eeb297 100644 (file)
@@ -150,8 +150,7 @@ public class MotorControl {
       System.out.println("setSpeedTurnLeft: input-> " + Integer.toString(timePosition));\r
     }\r
      int timePosLocal = normalizeTime(timePosition);\r
-     int motorUpTime =\r
-        (timePosLocal * 100 + ((100 - timePosLocal) * (100 - agilityFactor))) * speedFactor;\r
+     int motorUpTime = (timePosLocal * 100 + ((100 - timePosLocal) * (100 - agilityFactor))) * speedFactor;\r
     if (motorUpTime == 0) {\r
       motorUpTime = 1;\r
       // System.out.println("returning....");\r
@@ -185,8 +184,7 @@ public class MotorControl {
       System.out.println("setSpeedTurnRight: input-> " + Integer.toString(timePosition));\r
     }\r
      int timePos = normalizeTime(timePosition);\r
-     int motorUpTime =\r
-        ((timePos * 100) + ((100 - timePos) * (100 - agilityFactor))) * speedFactor;\r
+     int motorUpTime = ((timePos * 100) + ((100 - timePos) * (100 - agilityFactor))) * speedFactor;\r
     if (motorUpTime == 0) {\r
       motorUpTime = 1;\r
       // System.out.println("returning....");\r
index 09f4aeb7597f894496da5f373325225751a8aa97..e899ac9c2026b8efc97fa79deef5fcd330263213 100644 (file)
  */\r
 \r
 /**\r
- * PWMManager - Interface between robot strategy code and the various motors\r
- * PWMControl classes. Agility is a number between 0 to 100 and represent the\r
- * precentage of max speed to be applied to the turn side wheel. On left turn\r
- * the left wheel will receive less speed as % of "speed" value represented by\r
- * agility.\r
+ * PWMManager - Interface between robot strategy code and the various motors PWMControl classes.\r
+ * Agility is a number between 0 to 100 and represent the precentage of max speed to be applied to\r
+ * the turn side wheel. On left turn the left wheel will receive less speed as % of "speed" value\r
+ * represented by agility.\r
  * \r
  * @author Michael Gesundheit\r
  * @version 1.0\r
@@ -57,8 +56,8 @@ public class PWMManager {
    */\r
   public PWMManager(String pwmSelection) {\r
     /*\r
-     * Instantiate PWM Makers one for each motor. motorPortId is 1 to 8 and is\r
-     * corresponding to 8 bits in a byte.\r
+     * Instantiate PWM Makers one for each motor. motorPortId is 1 to 8 and is corresponding to 8\r
+     * bits in a byte.\r
      */\r
     // if (pwmSelection.equals("rtsj"))\r
     // pwmControl = new PWMRtsj(this, MOTOR_PORTID_6, MOTOR_PORTID_7);\r
@@ -100,9 +99,8 @@ public class PWMManager {
     currentRegMask |= myValue;\r
     /*\r
      * // if (DEBUG){ // System.out.println("PWMM: writeToPort: myBit = 0x" +\r
-     * Integer.toHexString(myBit) + // " ~myBit = 0x" +\r
-     * Integer.toHexString(~myBit) + " myValue = 0x" + //\r
-     * Integer.toHexString(myValue) + " currentRegMask = 0x" + //\r
+     * Integer.toHexString(myBit) + // " ~myBit = 0x" + Integer.toHexString(~myBit) +\r
+     * " myValue = 0x" + // Integer.toHexString(myValue) + " currentRegMask = 0x" + //\r
      * Integer.toHexString(currentRegMask)); //}\r
      */\r
     // rawJEM.set(GPIO_E_OUT, currentRegMask);\r
@@ -112,20 +110,16 @@ public class PWMManager {
    * public void stop(){ if(DEBUG) System.out.println("PWMManager: stop....");\r
    * pwmControl.setSpeedLeft(zeroSpeed); pwmControl.setSpeedRight(zeroSpeed); }\r
    * \r
-   * public void search(){ if(DEBUG)\r
-   * System.out.println("PWMManager: search...."); pwmControl.setSpeedLeft(70);\r
-   * pwmControl.setSpeedRight(50); }\r
+   * public void search(){ if(DEBUG) System.out.println("PWMManager: search....");\r
+   * pwmControl.setSpeedLeft(70); pwmControl.setSpeedRight(50); }\r
    * \r
-   * public void straight(){ if(DEBUG)\r
-   * System.out.println("PWMManager: strait...."); pwmControl.setSpeedLeft(100);\r
-   * pwmControl.setSpeedRight(100); }\r
+   * public void straight(){ if(DEBUG) System.out.println("PWMManager: strait....");\r
+   * pwmControl.setSpeedLeft(100); pwmControl.setSpeedRight(100); }\r
    * \r
-   * public void spinRight(){ if(DEBUG)\r
-   * System.out.println("PWMManager: spinRight....");\r
+   * public void spinRight(){ if(DEBUG) System.out.println("PWMManager: spinRight....");\r
    * pwmControl.setSpeedSpinLeft(100); pwmControl.setSpeedSpinRight(0); }\r
    * \r
-   * public void spinLeft(){ if(DEBUG)\r
-   * System.out.println("PWMManager: spinLeft....");\r
+   * public void spinLeft(){ if(DEBUG) System.out.println("PWMManager: spinLeft....");\r
    * pwmControl.setSpeedSpinLeft(0); pwmControl.setSpeedSpinRight(100); }\r
    * \r
    * public void spin180(){ int mod = (rand.nextInt() % 2);\r
@@ -140,23 +134,19 @@ public class PWMManager {
    * public void left(){ if(DEBUG) System.out.println("PWMManager: left....");\r
    * pwmControl.setSpeedLeft(zeroSpeed); pwmControl.setSpeedTurnRight(100); }\r
    * \r
-   * public void bearRight(){ if(DEBUG)\r
-   * System.out.println("PWMManager: bearRight....");\r
+   * public void bearRight(){ if(DEBUG) System.out.println("PWMManager: bearRight....");\r
    * pwmControl.setSpeedTurnLeft(100); pwmControl.setSpeedTurnRight(60); }\r
    * \r
-   * public void bearLeft(){ if(DEBUG)\r
-   * System.out.println("PWMManager: bearLeft....");\r
+   * public void bearLeft(){ if(DEBUG) System.out.println("PWMManager: bearLeft....");\r
    * pwmControl.setSpeedTurnLeft(60); pwmControl.setSpeedTurnRight(100); }\r
    * \r
    * public void back(){ if(DEBUG) System.out.println("PWMManager: back....");\r
    * pwmControl.setSpeedLeft(0); pwmControl.setSpeedRight(0); }\r
    * \r
-   * public void backBearLeft(){ if(DEBUG)\r
-   * System.out.println("PWMManager: backBearLeft....");\r
+   * public void backBearLeft(){ if(DEBUG) System.out.println("PWMManager: backBearLeft....");\r
    * pwmControl.setSpeedLeft(30); pwmControl.setSpeedRight(0); }\r
    * \r
-   * public void backBearRight(){ if(DEBUG)\r
-   * System.out.println("PWMManager: backBearRight....");\r
+   * public void backBearRight(){ if(DEBUG) System.out.println("PWMManager: backBearRight....");\r
    * pwmControl.setSpeedLeft(0); pwmControl.setSpeedRight(30); }\r
    */\r
   public void resume() {\r
@@ -205,10 +195,10 @@ public class PWMManager {
   }\r
 \r
   /**\r
-   * Control debug messaging. true - Activate debug messages false - deactivate\r
-   * debug messages\r
+   * Control debug messaging. true - Activate debug messages false - deactivate debug messages\r
    */\r
   public void setDebug(boolean debug) {\r
     DEBUG = debug;\r
   }\r
+\r
 }
\ 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 (file)
index 0000000..9ab0fc6
--- /dev/null
@@ -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();
+  }
+
+}
index a3d582a839b7861e1a61babb15312586959c9c8e..f7e780ee349f272988df9cb1ee436969ceb770c9 100644 (file)
@@ -32,14 +32,14 @@ public class RobotMain {
   \r
   private static boolean DEBUG = true;\r
 \r
-  private static final int OFF_MODE = 1;\r
-  private static final int ON_MODE = 2;\r
-  private static final int MANUAL_MODE = 1;\r
-  private static final int AUTONOMUS_MODE = 2;\r
-  private static final int ON_OFF = 128;// 0x80\r
-  private static final int MANUAL_AUTONOMUS = 32; // 0x20\r
+  public static final int OFF_MODE = 1;\r
+  public static final int ON_MODE = 2;\r
+  public static final int MANUAL_MODE = 1;\r
+  public static final int AUTONOMUS_MODE = 2;\r
+  public static final int ON_OFF = 128;// 0x80\r
+  public static final int MANUAL_AUTONOMUS = 32; // 0x20\r
   public static final int LINE_SENSORS = 64; // 0x40\r
-  private static final int SONAR_SENSORS = 96; // 0x60\r
+  public static final int SONAR_SENSORS = 96; // 0x60\r
   public static final int ALL_COMMANDS = 0xe0;\r
 \r
   public static final byte LF_FRONT = 0x1;\r
@@ -56,31 +56,31 @@ public class RobotMain {
   public static final byte LS_LEFT_REAR = 0x5;\r
   public static final byte LS_RIGHT_REAR = 0x6;\r
   public static final byte LS_ALL = 0x7;\r
-  private static final int ALL_DATA = 0x1f;\r
+  public static final int ALL_DATA = 0x1f;\r
 \r
   \r
-  private static PWMManager pwmm;\r
+  private PWMManager pwmm;\r
   \r
-  private static StrategyMgr strategyMgr;\r
+  private StrategyMgr strategyMgr;\r
 \r
   \r
-  private static int onOffMode = ON_MODE;\r
+  private int onOffMode = ON_MODE;\r
   \r
-  private static int manualAutonomusMode = AUTONOMUS_MODE;\r
+  private int manualAutonomusMode = AUTONOMUS_MODE;\r
   \r
-  private static byte lineSensorsMask;\r
+  private byte lineSensorsMask;\r
   \r
-  private static byte sonarSensors;\r
+  private byte sonarSensors;\r
   \r
-  private static byte currentCommand;\r
+  private byte currentCommand;\r
   \r
-  private static byte privSonars;\r
+  private byte privSonars;\r
   \r
-  private static byte privLineSensors;\r
+  private byte privLineSensors;\r
   \r
-  private static byte currentSonars;\r
+  private byte currentSonars;\r
   \r
-  public static String pwmSelection;\r
+  public String pwmSelection;\r
 \r
   /**\r
    * Constructor for the class for the robot main thread.\r
@@ -89,20 +89,18 @@ public class RobotMain {
   }\r
 \r
   /**\r
-   * Processes sonar sensor input. This method is called each time new sonar\r
-   * sensor data arrives, and each time that a mode switch occurs between ON/OFF\r
-   * and Manual Override.\r
+   * Processes sonar sensor input. This method is called each time new sonar sensor data arrives,\r
+   * and each time that a mode switch occurs between ON/OFF and Manual Override.\r
    */\r
-  static void processSonars() {\r
+  void processSonars() {\r
     strategyMgr.processSonars(sonarSensors);\r
   }\r
 \r
   /**\r
-   * Processes line sensor input. This method is called each time new line\r
-   * sensor data arrives, and each time that a mode switch occurs between ON/OFF\r
-   * and Manual Override.\r
+   * Processes line sensor input. This method is called each time new line sensor data arrives, and\r
+   * each time that a mode switch occurs between ON/OFF and Manual Override.\r
    */\r
-  static void processLineSensors() {\r
+  void processLineSensors() {\r
     strategyMgr.processLineSensors(lineSensorsMask);\r
     resume();\r
   }\r
@@ -110,16 +108,16 @@ public class RobotMain {
   /**\r
    * Resumes motors as per the last sonar command.\r
    */\r
-  public static void resume() {\r
+  void resume() {\r
     processSonars();\r
   }\r
 \r
   /**\r
-   * Extracts sonar sensor data from the adjunct sensor controller and from line\r
-   * sensor data from the JStamp line sensor pins.\r
+   * Extracts sonar sensor data from the adjunct sensor controller and from line sensor data from\r
+   * the JStamp line sensor pins.\r
    */\r
   \r
-  private static void processIOCommand() {\r
+  private void processIOCommand() {\r
 \r
     // int data = 0;\r
     // int opCode = 0;\r
@@ -170,8 +168,8 @@ public class RobotMain {
       lineSensorsMask = (byte) (data & LS_ALL);\r
 \r
       /*\r
-       * Line sensors with '0' data means the robot moved off the edge line, and\r
-       * there is nothing to do.\r
+       * Line sensors with '0' data means the robot moved off the edge line, and there is nothing to\r
+       * do.\r
        */\r
       if (((data & LS_ALL) == 0) || ((data & LS_ALL) == privLineSensors)) {\r
         privLineSensors = (byte) (data & LS_ALL);\r
@@ -190,8 +188,8 @@ public class RobotMain {
       }\r
       currentSonars = (byte) (data & ALL_SONARS);\r
       /*\r
-       * No need to synchronized on this variable assignment since all referring\r
-       * code is on the same logical thread\r
+       * No need to synchronized on this variable assignment since all referring code is on the same\r
+       * logical thread\r
        */\r
       sonarSensors = (byte) currentSonars;\r
       if ((onOffMode == ON_MODE) && (manualAutonomusMode == AUTONOMUS_MODE)) {\r
@@ -222,7 +220,7 @@ public class RobotMain {
   /**\r
    * Saves the current IOManager command byte locally.\r
    */\r
-  static public void setIOManagerCommand(byte[] cmd) {\r
+  public void setIOManagerCommand(byte[] cmd) {\r
     // synchronized (obj1) {\r
     currentCommand = cmd[0];\r
     // }\r
@@ -236,8 +234,7 @@ public class RobotMain {
   }\r
 \r
   /**\r
-   * Sets debug messaging state: true - Activate debug messages false -\r
-   * deactivate debug messages\r
+   * Sets debug messaging state: true - Activate debug messages false - deactivate debug messages\r
    */\r
   static public void setDebug(boolean debug) {\r
     DEBUG = debug;\r
@@ -246,19 +243,22 @@ public class RobotMain {
   /**\r
    * Runs the robot's main thread.\r
    */\r
-  \r
   public static void main( String args[]) {\r
 \r
     TestSensorInput.init();\r
+    RobotMain r = new RobotMain();\r
+    r.doit();\r
+  }\r
+\r
+  \r
+  public void doit() {\r
      boolean active = true;\r
     /**\r
-     * RealTime management of the robot behaviour based on sensors and commands\r
-     * input.\r
+     * RealTime management of the robot behaviour based on sensors and commands input.\r
      */\r
 \r
     /**\r
-     * Set the low level PWM interface type, e.g. "rtsj" or "native" (ajile\r
-     * library-based).\r
+     * Set the low level PWM interface type, e.g. "rtsj" or "native" (ajile library-based).\r
      */\r
     pwmSelection = "rtsj";\r
 \r
@@ -273,38 +273,45 @@ public class RobotMain {
     strategyMgr = new StrategyMgr(mc);\r
 \r
     /*\r
-     * Sets initial values for the speed and agility parameters. Speed and\r
-     * agility are arbitrary scale factors for the overall speed and speed of\r
-     * turns, respectively. These work with PWM via the native ajile libraries,\r
-     * but do not work well with the RTSJ implementation due to limits on the\r
-     * granularity of timing for the PWM pulse (quantization).\r
+     * Sets initial values for the speed and agility parameters. Speed and agility are arbitrary\r
+     * scale factors for the overall speed and speed of turns, respectively. These work with PWM via\r
+     * the native ajile libraries, but do not work well with the RTSJ implementation due to limits\r
+     * on the granularity of timing for the PWM pulse (quantization).\r
      */\r
     pwmm.setSpeedAgilityFactors(100, 100);\r
 \r
     /*\r
-     * Robot's initial state is "ON" by default. Set this parameter to "OFF" if\r
-     * the robot is to be started over the TCP/IP link.\r
+     * Robot's initial state is "ON" by default. Set this parameter to "OFF" if the robot is to be\r
+     * started over the TCP/IP link.\r
      */\r
     // issueCommand("OFF");\r
 \r
     SSJAVA: while (active) {\r
 \r
-      // if (DEBUG) {\r
-      // System.out.println("Main: Waiting for remote commands");\r
-      // }\r
-      // try {\r
-      // obj.wait();\r
-      // } catch (IllegalMonitorStateException ie) {\r
-      // System.out.println("IllegalMonitorStateException caught in main loop");\r
-      // }\r
-      currentCommand = TestSensorInput.getCommand();\r
+      Command com = HWSimulator.getCommand();\r
+      currentCommand = com.command;\r
+      sonarSensors = com.sonarSensors;\r
+      lineSensorsMask = com.lineSensorsMask;\r
+      manualAutonomusMode = com.manualAutonomusMode;\r
+      onOffMode = com.onOffMode;\r
+\r
       if (currentCommand == -1) {\r
         break;\r
       }\r
       System.out.println("currentCommand=" + currentCommand);\r
       processIOCommand();\r
+      // erase current settings\r
+      initialize();\r
     }\r
     System.exit(0);\r
   }\r
 \r
+  public void initialize() {\r
+    privLineSensors = 0;\r
+    currentCommand = 0;\r
+    privSonars = 0;\r
+    currentSonars = 0;\r
+    pwmSelection = "";\r
+  }\r
+\r
 }\r
index c46b5fdf551176c6cc2ba958bfda61da3bfe7ced..373786253e6ff4793f6177878dd627197f190030 100644 (file)
@@ -32,8 +32,6 @@ public class StrategyMgr {
   private MotorControl mc;\r
   private static final int zeroSpeed = 45;\r
   \r
-  private Random rand;\r
-  \r
   private boolean DEBUGL = true;\r
   // private boolean DEBUGL = false;\r
 \r
@@ -46,7 +44,7 @@ public class StrategyMgr {
    */\r
   public StrategyMgr(@DELEGATE MotorControl motorControl) {\r
     mc = motorControl;\r
-    rand = new Random();\r
+    RandomWrapper.init();\r
   }\r
 \r
   void processSonars( byte sonarSensors) {\r
@@ -206,7 +204,7 @@ public class StrategyMgr {
   }\r
 \r
   public void spin180() {\r
-     int mod = (rand.nextInt() % 2);\r
+     int mod = (RandomWrapper.nextInt() % 2);\r
 \r
     if (DEBUG)\r
       System.out.println("StrategyMgr: spin180....");\r