From d568c92869ed8d279615d50dc8e1c5ee765bef76 Mon Sep 17 00:00:00 2001 From: rtrimana Date: Mon, 18 Jan 2021 16:21:18 -0800 Subject: [PATCH] Refactoring/moving handler in the listener to check if the benchmark has no event (in this case we don't do DPOR). --- .../listener/DPORStateReducerWithSummary.java | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/src/main/gov/nasa/jpf/listener/DPORStateReducerWithSummary.java b/src/main/gov/nasa/jpf/listener/DPORStateReducerWithSummary.java index 6422b7d..cfc7067 100755 --- a/src/main/gov/nasa/jpf/listener/DPORStateReducerWithSummary.java +++ b/src/main/gov/nasa/jpf/listener/DPORStateReducerWithSummary.java @@ -190,42 +190,44 @@ public class DPORStateReducerWithSummary extends ListenerAdapter { @Override public void choiceGeneratorRegistered(VM vm, ChoiceGenerator nextCG, ThreadInfo currentThread, Instruction executedInstruction) { - if (isNotCheckedForEventsYet) { - // Check if this benchmark has no events - if (nextCG instanceof IntChoiceFromSet) { - IntChoiceFromSet icsCG = (IntChoiceFromSet) nextCG; - Integer[] cgChoices = icsCG.getAllChoices(); - if (cgChoices.length == 2 && cgChoices[0] == 0 && cgChoices[1] == -1) { - stateReductionMode = false; - } - isNotCheckedForEventsYet = false; - } - } if (stateReductionMode) { - // Initialize with necessary information from the CG - if (nextCG instanceof IntChoiceFromSet) { - IntChoiceFromSet icsCG = (IntChoiceFromSet) nextCG; - // Tell JPF that we are performing DPOR - icsCG.setDpor(); - if (!isEndOfExecution) { - // Check if CG has been initialized, otherwise initialize it + if (isNotCheckedForEventsYet) { + // Check if this benchmark has no events + if (nextCG instanceof IntChoiceFromSet) { + IntChoiceFromSet icsCG = (IntChoiceFromSet) nextCG; Integer[] cgChoices = icsCG.getAllChoices(); - // Record the events (from choices) - if (choices == null) { - choices = cgChoices; - // Make a copy of choices as reference - refChoices = copyChoices(choices); - // Record the max event choice (the last element of the choice array) - maxEventChoice = choices[choices.length - 1]; + if (cgChoices.length == 2 && cgChoices[0] == 0 && cgChoices[1] == -1) { + // This means the benchmark only has 2 choices, i.e., 0 and -1 which means that it has no events + stateReductionMode = false; + } + isNotCheckedForEventsYet = false; + } + } else { + // Initialize with necessary information from the CG + if (nextCG instanceof IntChoiceFromSet) { + IntChoiceFromSet icsCG = (IntChoiceFromSet) nextCG; + // Tell JPF that we are performing DPOR + icsCG.setDpor(); + if (!isEndOfExecution) { + // Check if CG has been initialized, otherwise initialize it + Integer[] cgChoices = icsCG.getAllChoices(); + // Record the events (from choices) + if (choices == null) { + choices = cgChoices; + // Make a copy of choices as reference + refChoices = copyChoices(choices); + // Record the max event choice (the last element of the choice array) + maxEventChoice = choices[choices.length - 1]; + } + icsCG.setNewValues(choices); + icsCG.reset(); + // Use a modulo since choiceCounter is going to keep increasing + int choiceIndex = choiceCounter % choices.length; + icsCG.advance(choices[choiceIndex]); + } else { + // Set done all CGs while transitioning to a new execution + icsCG.setDone(); } - icsCG.setNewValues(choices); - icsCG.reset(); - // Use a modulo since choiceCounter is going to keep increasing - int choiceIndex = choiceCounter % choices.length; - icsCG.advance(choices[choiceIndex]); - } else { - // Set done all CGs while transitioning to a new execution - icsCG.setDone(); } } } -- 2.34.1