01: //
02: // Copyright (C) 2005 United States Government as represented by the
03: // Administrator of the National Aeronautics and Space Administration
04: // (NASA). All Rights Reserved.
05: //
06: // This software is distributed under the NASA Open Source Agreement
07: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
08: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
09: // 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.search.heuristic;
20:
21: import gov.nasa.jpf.VM;
22: import gov.nasa.jpf.jvm.JVM;
23: import gov.nasa.jpf.jvm.Reference;
24: import gov.nasa.jpf.jvm.SystemState;
25:
26: /**
27: * heuristic state prioritizer that uses fields of the Main class uner test
28: * to determine priorities (i.e. priorities can be set by the program under test)
29: *
30: * <2do> pcm - does this still make sense in light of MJI ? If we keep it, this
31: * has tobe moved to the Verify interface!
32: */
33: public class UserHeuristic implements Heuristic {
34: static final int defaultValue = 1000;
35: VM vm;
36:
37: public UserHeuristic(HeuristicSearch hSearch) {
38: vm = hSearch.getVM();
39: }
40:
41: public int heuristicValue() {
42: // <2do> pcm - BAD, remove the VM nuts-and-bolts dependencies
43: SystemState ss = (SystemState) ((JVM) vm).getSystemState();
44: Reference p = ss.getClass("Main");
45:
46: if (p != null) {
47: Reference b = p.getObjectField("buffer", null);
48:
49: if (b != null) {
50: int current = b.getIntField("current", null);
51: int capacity = b.getIntField("capacity", null);
52:
53: return (capacity - current);
54: }
55: }
56:
57: return defaultValue;
58: }
59:
60: public void processParent() {
61: }
62: }
|