2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.vm.choice;
20 import gov.nasa.jpf.vm.ChoiceGenerator;
21 import gov.nasa.jpf.vm.ChoiceGeneratorBase;
22 import gov.nasa.jpf.vm.ThreadChoiceGenerator;
23 import gov.nasa.jpf.vm.ThreadInfo;
25 import java.io.PrintWriter;
28 * a pseudo CG that is used to break transitions. It can be used to break and
29 * just reschedule the current thread, or to indicate an end state
30 * (e.g. for System.exit())
32 public class BreakGenerator extends ChoiceGeneratorBase<ThreadInfo> implements ThreadChoiceGenerator {
34 protected ThreadInfo ti;
35 protected int state = -1;
36 protected boolean isTerminator;
38 public BreakGenerator (String id, ThreadInfo ti, boolean isTerminator) {
42 this.isTerminator = isTerminator;
46 public ThreadInfo getNextChoice () {
47 assert !isTerminator : "illegal operation on terminal BreakGenerator";
48 return (state == 0) ? ti : null;
52 public ThreadInfo getChoice (int idx){
56 throw new IllegalArgumentException("choice index out of range: " + idx);
61 public void printOn (PrintWriter pw) {
62 pw.println("BreakGenerator {" + ti.getName() + "}");
66 public void advance () {
67 assert !isTerminator : "illegal operation on terminal BreakGenerator";
72 public int getProcessedNumberOfChoices () {
73 return (state >= 0) ? 1 : 0;
77 public int getTotalNumberOfChoices () {
82 public boolean hasMoreChoices () {
91 public void reset () {
97 public boolean contains (ThreadInfo ti){
102 public Class<ThreadInfo> getChoiceType() {
103 return ThreadInfo.class;
107 public ChoiceGenerator<ThreadInfo> randomize() {
112 public boolean isSchedulingPoint(){
113 return true; // that's the whole point of having a BreakGenerator