From 238b1bff87ff253ce5043d544dc2c574c6a25f6f Mon Sep 17 00:00:00 2001 From: rtrimana Date: Mon, 18 Nov 2019 13:08:29 -0800 Subject: [PATCH] Code refactoring for sleep set and persistent set analyses. --- .../jpf/listener/EfficientStateReducer.java | 70 +++++++++---------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/src/main/gov/nasa/jpf/listener/EfficientStateReducer.java b/src/main/gov/nasa/jpf/listener/EfficientStateReducer.java index 03efc87..f0d25d7 100644 --- a/src/main/gov/nasa/jpf/listener/EfficientStateReducer.java +++ b/src/main/gov/nasa/jpf/listener/EfficientStateReducer.java @@ -413,6 +413,32 @@ public class EfficientStateReducer extends ListenerAdapter { return integerArray; } + private void completeBacktrackChoiceList(List newChoiceList, int currentChoice, int conflictEventNumber, + LinkedList backtrackChoiceLists) { + // Put the conflicting event numbers first and reverse the order + newChoiceList.add(choices[currentChoice]); + newChoiceList.add(choices[conflictEventNumber]); + // Put the rest of the event numbers into the array starting from the minimum to the upper bound + for (int i = conflictEventNumber + 1; i < choices.length - 1; i++) { + // Check the sleep sets for excepted events that do not conflict with the current one + int prevChoiceNum = newChoiceList.get(newChoiceList.size()-1); + HashSet sleepSet = sleepSetMap.get(prevChoiceNum); + if (choices[i] != choices[currentChoice] && !sleepSet.contains(choices[i])) { + newChoiceList.add(choices[i]); + } + } + // Set the last element to '-1' as the end of the sequence + newChoiceList.add(-1); + Integer[] newChoiceArray = copyIntegerListToArray(newChoiceList); + backtrackChoiceLists.addLast(newChoiceArray); + if (!isResetAfterAnalysis) { + // The start index for the recursion is always 1 (from the main branch) + choiceListStartIndexMap.put(newChoiceArray, 1); + } else { + choiceListStartIndexMap.put(newChoiceArray, conflictEventNumber + 1); + } + } + private void createBacktrackChoiceList(int currentChoice, int conflictEventNumber) { LinkedList backtrackChoiceLists; @@ -430,52 +456,20 @@ public class EfficientStateReducer extends ListenerAdapter { backtrackChoiceLists = backtrackMap.get(conflictEventNumber); } List newChoiceList = new ArrayList<>(); - // Put the conflicting event numbers first and reverse the order - newChoiceList.add(choices[currentChoice]); - newChoiceList.add(choices[conflictEventNumber]); - // Put the rest of the event numbers into the array starting from the minimum to the upper bound - for (int i = conflictEventNumber + 1; i < choices.length - 1; i++) { - // Check the sleep sets for excepted events that do not conflict with the current one - int prevSleepSet = newChoiceList.get(newChoiceList.size()-1); - HashSet sleepSet = sleepSetMap.get(prevSleepSet); - if (choices[i] != choices[currentChoice] && !sleepSet.contains(choices[i])) { - newChoiceList.add(choices[i]); - } - } - // Set the last element to '-1' as the end of the sequence - newChoiceList.add(-1); - Integer[] newChoiceArray = copyIntegerListToArray(newChoiceList); - backtrackChoiceLists.addLast(newChoiceArray); - // The start index for the recursion is always 1 (from the main branch) - choiceListStartIndexMap.put(newChoiceArray, 1); + completeBacktrackChoiceList(newChoiceList, currentChoice, conflictEventNumber, backtrackChoiceLists); } else { // This is a sub-graph int backtrackListIndex = cgMap.get(currCG); backtrackChoiceLists = backtrackMap.get(backtrackListIndex); List newChoiceList = new ArrayList<>(); // Copy everything before the conflict number - int conflictEventCurrentIndex = getChoiceIndex(conflictEventNumber); - for(int i = 0; i < conflictEventCurrentIndex; i++) { + int conflictEventCurrentNumber = getChoiceIndex(conflictEventNumber); + for(int i = 0; i < conflictEventCurrentNumber; i++) { newChoiceList.add(choices[i]); } // Put the conflicting events - int currentChoiceCurrentIndex = getChoiceIndex(currentChoice); - newChoiceList.add(choices[currentChoiceCurrentIndex]); - newChoiceList.add(choices[conflictEventCurrentIndex]); - // Copy the rest - for(int i = conflictEventCurrentIndex + 1; i < choices.length - 1; i++) { - // Check the sleep sets for excepted events that do not conflict with the current one - int prevSleepSet = newChoiceList.get(newChoiceList.size()-1); - HashSet sleepSet = sleepSetMap.get(prevSleepSet); - if (choices[i] != choices[currentChoiceCurrentIndex] && !sleepSet.contains(choices[i])) { - newChoiceList.add(choices[i]); - } - } - // Set the last element to '-1' as the end of the sequence - newChoiceList.add(-1); - Integer[] newChoiceArray = copyIntegerListToArray(newChoiceList); - backtrackChoiceLists.addLast(newChoiceArray); - // For the sub-graph the start index depends on the conflicting event number - choiceListStartIndexMap.put(newChoiceArray, conflictEventCurrentIndex + 1); + int currentChoiceCurrentNumber = getChoiceIndex(currentChoice); + completeBacktrackChoiceList(newChoiceList, currentChoiceCurrentNumber, conflictEventCurrentNumber, + backtrackChoiceLists); } } -- 2.34.1