+ // Exclude certain field writes because of infrastructure needs, e.g., Event class field writes
+ for (String str : EXCLUDED_FIELDS_WRITE_INSTRUCTIONS_STARTS_WITH_LIST) {
+ if (fieldClass.startsWith(str)) {
+ return;
+ }
+ }
+ rwSet.addWriteField(fieldClass, objectId);
+ } else if (executedInsn instanceof ReadInstruction) {
+ rwSet.addReadField(fieldClass, objectId);
+ }
+ }
+
+ private boolean recordConflictPair(int currentEvent, int eventNumber) {
+ HashSet<Integer> conflictSet;
+ if (!conflictPairMap.containsKey(currentEvent)) {
+ conflictSet = new HashSet<>();
+ conflictPairMap.put(currentEvent, conflictSet);
+ } else {
+ conflictSet = conflictPairMap.get(currentEvent);
+ }
+ // If this conflict has been recorded before, we return false because
+ // we don't want to service this backtrack point twice
+ if (conflictSet.contains(eventNumber)) {
+ return false;
+ }
+ // If it hasn't been recorded, then do otherwise
+ conflictSet.add(eventNumber);
+ return true;
+ }
+
+ private String buildStringFromChoiceList(Integer[] newChoiceList) {
+
+ // When we see a choice list shorter than the upper bound, e.g., [3,2] for choices 0,1,2, and 3,
+ // then we have to pad the beginning before we store it, because [3,2] actually means [0,1,3,2]
+ // First, calculate the difference between this choice list and the upper bound
+ // The actual list doesn't include '-1' at the end
+ int actualListLength = newChoiceList.length - 1;
+ int diff = maxUpperBound - actualListLength;
+ StringBuilder sb = new StringBuilder();
+ // Pad the beginning if necessary
+ for (int i = 0; i < diff; i++) {
+ sb.append(i);
+ }
+ // Then continue with the actual choice list
+ // We don't include the '-1' at the end
+ for (int i = 0; i < newChoiceList.length - 1; i++) {
+ sb.append(newChoiceList[i]);
+ }
+ return sb.toString();
+ }
+
+ private void checkAndAddBacktrackList(LinkedList<Integer[]> backtrackChoiceLists, Integer[] newChoiceList) {
+
+ String newChoiceListString = buildStringFromChoiceList(newChoiceList);
+ // Add only if we haven't seen this combination before
+ if (!backtrackSet.contains(newChoiceListString)) {
+ backtrackSet.add(newChoiceListString);
+ backtrackChoiceLists.addLast(newChoiceList);
+ }
+ }
+
+ private void createBacktrackChoiceList(int currentChoice, int conflictEventNumber) {
+
+ LinkedList<Integer[]> backtrackChoiceLists;
+ // Create a new list of choices for backtrack based on the current choice and conflicting event number
+ // If we have a conflict between 1 and 3, then we create the list {3, 1, 2, 4, 5} for backtrack
+ // The backtrack point is the CG for event number 1 and the list length is one less than the original list
+ // (originally of length 6) since we don't start from event number 0
+ if (!isResetAfterAnalysis) {
+ // Check if we have a list for this choice number
+ // If not we create a new one for it
+ if (!backtrackMap.containsKey(conflictEventNumber)) {
+ backtrackChoiceLists = new LinkedList<>();
+ backtrackMap.put(conflictEventNumber, backtrackChoiceLists);
+ } else {
+ backtrackChoiceLists = backtrackMap.get(conflictEventNumber);
+ }
+ int maxListLength = choiceUpperBound + 1;
+ int listLength = maxListLength - conflictEventNumber;
+ Integer[] newChoiceList = new Integer[listLength];
+ // Put the conflicting event numbers first and reverse the order
+ newChoiceList[0] = refChoices[currentChoice];
+ newChoiceList[1] = refChoices[conflictEventNumber];
+ // Put the rest of the event numbers into the array starting from the minimum to the upper bound
+ for (int i = conflictEventNumber + 1, j = 2; j < listLength; i++) {
+ if (refChoices[i] != refChoices[currentChoice]) {
+ newChoiceList[j] = refChoices[i];
+ j++;
+ }
+ }
+ checkAndAddBacktrackList(backtrackChoiceLists, newChoiceList);
+ // The start index for the recursion is always 1 (from the main branch)
+ } else { // This is a sub-graph
+ // There is a case/bug that after a re-initialization, currCG is not yet initialized
+ if (currCG != null && cgMap.containsKey(currCG)) {
+ int backtrackListIndex = cgMap.get(currCG);
+ backtrackChoiceLists = backtrackMap.get(backtrackListIndex);
+ int listLength = refChoices.length;
+ Integer[] newChoiceList = new Integer[listLength];
+ // Copy everything before the conflict number
+ for (int i = 0; i < conflictEventNumber; i++) {
+ newChoiceList[i] = refChoices[i];
+ }
+ // Put the conflicting events
+ newChoiceList[conflictEventNumber] = refChoices[currentChoice];
+ newChoiceList[conflictEventNumber + 1] = refChoices[conflictEventNumber];
+ // Copy the rest
+ for (int i = conflictEventNumber + 1, j = conflictEventNumber + 2; j < listLength - 1; i++) {
+ if (refChoices[i] != refChoices[currentChoice]) {
+ newChoiceList[j] = refChoices[i];
+ j++;