Fixing the counter for unique transitions.
authorrtrimana <rtrimana@uci.edu>
Thu, 28 Jan 2021 23:23:11 +0000 (15:23 -0800)
committerrtrimana <rtrimana@uci.edu>
Thu, 28 Jan 2021 23:23:11 +0000 (15:23 -0800)
src/main/gov/nasa/jpf/listener/DPORStateReducerWithSummary.java

index 9a4af0c38093fbe3103ce20175133d2ce31c9b55..9e232bb31e24dad83b6c9709266ddb061e5f86c8 100755 (executable)
@@ -67,7 +67,7 @@ public class DPORStateReducerWithSummary extends ListenerAdapter {
   private HashSet<ClassInfo> nonRelevantClasses;// Class info objects of non-relevant classes
   private HashSet<FieldInfo> nonRelevantFields; // Field info objects of non-relevant fields
   private HashSet<FieldInfo> relevantFields;    // Field info objects of relevant fields
-  private HashMap<Integer, HashSet<Integer>> stateToEventMap;
+  private HashMap<Integer, HashSet<Integer>> stateToEventMap;       // Map state ID to events
   // Data structure to analyze field Read/Write accesses and conflicts
   private HashMap<Integer, LinkedList<BacktrackExecution>> backtrackMap;  // Track created backtracking points
   private PriorityQueue<Integer> backtrackStateQ;                 // Heap that returns the latest state
@@ -85,7 +85,7 @@ public class DPORStateReducerWithSummary extends ListenerAdapter {
 
   // Statistics
   private int numOfTransitions;
-  private int numOfUniqueTransitions;
+  private HashMap<Integer, HashSet<Integer>> stateToUniqueEventMap;
 
   public DPORStateReducerWithSummary(Config config, JPF jpf) {
     verboseMode = config.getBoolean("printout_state_transition", false);
@@ -106,12 +106,12 @@ public class DPORStateReducerWithSummary extends ListenerAdapter {
     isNotCheckedForEventsYet = true;
     mainSummary = new MainSummary();
     numOfTransitions = 0;
-    numOfUniqueTransitions = 0;
     nonRelevantClasses = new HashSet<>();
     nonRelevantFields = new HashSet<>();
     relevantFields = new HashSet<>();
     restorableStateMap = new HashMap<>();
     stateToPredInfo = new HashMap<>();
+    stateToUniqueEventMap = new HashMap<>();
     initializeStatesVariables();
   }
 
@@ -182,12 +182,12 @@ public class DPORStateReducerWithSummary extends ListenerAdapter {
       out.println("\n==> DEBUG: ----------------------------------- search finished");
       out.println("\n==> DEBUG: State reduction mode                : " + stateReductionMode);
       out.println("\n==> DEBUG: Number of transitions               : " + numOfTransitions);
-      out.println("\n==> DEBUG: Number of unique transitions (DPOR) : " + numOfUniqueTransitions);
+      out.println("\n==> DEBUG: Number of unique transitions (DPOR) : " + summarizeUniqueStateIds());
       out.println("\n==> DEBUG: ----------------------------------- search finished" + "\n");
 
       fileWriter.println("==> DEBUG: State reduction mode         : " + stateReductionMode);
       fileWriter.println("==> DEBUG: Number of transitions        : " + numOfTransitions);
-      fileWriter.println("==> DEBUG: Number of unique transitions : " + numOfUniqueTransitions);
+      fileWriter.println("==> DEBUG: Number of unique transitions : " + summarizeUniqueStateIds());
       fileWriter.println();
       fileWriter.close();
     }
@@ -265,9 +265,7 @@ public class DPORStateReducerWithSummary extends ListenerAdapter {
           exploreNextBacktrackPoints(vm, icsCG);
         } else {
           numOfTransitions++;
-          if (choiceCounter < choices.length) {
-            numOfUniqueTransitions++;
-          }
+          countUniqueStateId(vm.getStateId(), icsCG.getNextChoice());
         }
         // Map state to event
         mapStateToEvent(icsCG.getNextChoice());
@@ -275,10 +273,39 @@ public class DPORStateReducerWithSummary extends ListenerAdapter {
         choiceCounter++;
       }
     } else {
-      if (currentCG instanceof IntChoiceFromSet) {
-        numOfTransitions++;
-      }
+      numOfTransitions++;
+    }
+  }
+
+  // Count unique state IDs
+  private void countUniqueStateId(int stateId, int nextChoiceValue) {
+    HashSet<Integer> events;
+    // Get the set of events
+    if (!stateToUniqueEventMap.containsKey(stateId)) {
+      events = new HashSet<>();
+      stateToUniqueEventMap.put(stateId, events);
+    } else {
+      events = stateToUniqueEventMap.get(stateId);
     }
+    // Insert the event
+    if (!events.contains(nextChoiceValue)) {
+      events.add(nextChoiceValue);
+    }
+  }
+
+  // Summarize unique state IDs
+  private int summarizeUniqueStateIds() {
+    // Just count the set size of each of entry map and sum them up
+    int numOfUniqueTransitions = 0;
+    for (Map.Entry<Integer,HashSet<Integer>> entry : stateToUniqueEventMap.entrySet()) {
+      numOfUniqueTransitions = numOfUniqueTransitions + entry.getValue().size();
+    }
+    // We also need to count root and boolean CG if this is in state reduction mode (DPOR)
+    if (stateReductionMode) {
+      numOfUniqueTransitions = numOfUniqueTransitions + 3;
+    }
+
+    return numOfUniqueTransitions;
   }
 
   @Override