KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gov > nasa > jpf > jvm > PathScheduler


1 //
2
// Copyright (C) 2005 United States Government as represented by the
3
// Administrator of the National Aeronautics and Space Administration
4
// (NASA). All Rights Reserved.
5
//
6
// This software is distributed under the NASA Open Source Agreement
7
// (NOSA), version 1.3. The NOSA has been approved by the Open Source
8
// Initiative. See the file NOSA-1.3-JPF at the top of the distribution
9
// directory tree for the complete NOSA document.
10
//
11
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18
//
19
package gov.nasa.jpf.jvm;
20
21 import gov.nasa.jpf.JPFException;
22 import gov.nasa.jpf.Path;
23 import gov.nasa.jpf.Transition;
24
25
26 /**
27  * this is just a pseudo scheduler that replays a previously saved path
28  * Note that it does not get configured, but automatically created in case
29  * we start JPF with a '*.xml' parameter instead of a main class name, hence
30  * it has a special ctor
31  */

32 public class PathScheduler extends Scheduler {
33   Path path;
34   int pos;
35
36   PathScheduler (Path execPath) {
37     path = execPath;
38     pos = 0;
39   }
40
41   public int getRandom () {
42     Transition t = path.get(pos);
43
44     return t.getRandom();
45   }
46
47   public int getThread () {
48     Transition t = path.get(pos);
49
50     return t.getThread();
51   }
52
53   public void initialize () {
54   }
55
56   public ThreadInfo locateThread (SystemState ss) {
57     if (pos < path.length()) {
58       Transition t = path.get(pos);
59       int idx = t.getThread();
60
61       if (idx < ss.getThreadCount()) {
62         ThreadInfo ti = ss.getThreadInfo(idx);
63
64         if (ti.isRunnable()) {
65           return ti;
66         } else {
67           // error, path has always to be executable right to the end
68
throw new JPFException("no runnable thread in path transition: " + t);
69         }
70       } else {
71         // error, path out of sync with VM
72
throw new JPFException("invalid thread list index: " + idx);
73       }
74     }
75
76     // done, no more transitions
77
return null;
78   }
79
80   public void next () {
81     // move scheduler to next pos
82
pos++;
83   }
84
85   public int random (int max) {
86     return getRandom();
87   }
88 }
Popular Tags