1 package gov.nasa.jpf.jvm; 20 21 import java.util.Random ; 22 23 24 30 public class Verify { 31 static final int MAX_COUNTERS = 10; 32 static int[] counter; 34 private static Random random; 35 36 43 static Class peer; 44 45 51 public static void setPeerClass (Class cls) { 52 peer = cls; 53 } 54 55 public static int getCounter (int id) { 59 if (peer != null) { 60 return JPF_gov_nasa_jpf_jvm_Verify.getCounter(null, 0, id); 62 } else { 63 if (counter == null) { 64 counter = new int[id >= MAX_COUNTERS ? (id+1) : MAX_COUNTERS]; 65 } 66 if ((id < 0) || (id >= counter.length)) { 67 return 0; 68 } 69 70 return counter[id]; 71 } 72 } 73 74 public static void resetCounter (int id) { 75 if (peer != null){ 76 JPF_gov_nasa_jpf_jvm_Verify.resetCounter(null, 0, id); 77 } else { 78 if ((counter != null) && (id >= 0) && (id < counter.length)) { 79 counter[id] = 0; 80 } 81 } 82 } 83 84 public static int incrementCounter (int id) { 85 if (peer != null){ 86 return JPF_gov_nasa_jpf_jvm_Verify.incrementCounter(null, 0, id); 87 } else { 88 if (counter == null) { 89 counter = new int[(id >= MAX_COUNTERS) ? id+1 : MAX_COUNTERS]; 90 } else if (id >= counter.length) { 91 int[] newCounter = new int[id+1]; 92 System.arraycopy(counter, 0, newCounter, 0, counter.length); 93 counter = newCounter; 94 } 95 96 if ((id >= 0) && (id < counter.length)) { 97 return ++counter[id]; 98 } 99 100 return 0; 101 } 102 } 103 104 105 107 110 public static void addComment (String s) {} 111 112 116 public static void assertTrue (String s, boolean cond) { 117 if (!cond) { 118 System.out.println(s); 119 assertTrue(cond); 120 } 121 } 122 123 127 public static void assertTrue (boolean cond) { 128 if (!cond) { 129 throw new AssertionError ("Verify.assertTrue failed"); 130 } 131 } 132 133 public static void atLabel (String label) {} 134 135 public static void atLabel (int label) {} 136 137 140 public static void beginAtomic () {} 141 142 145 public static void endAtomic () {} 146 147 public static void boring (boolean cond) {} 148 149 public static void busyWait (long duration) { 150 while (duration > 0) { 152 duration--; 153 } 154 } 155 156 public static boolean isCalledFromClass (String refClsName) { 157 Throwable t = new Throwable (); 158 StackTraceElement [] st = t.getStackTrace(); 159 160 if (st.length < 3) { 161 return false; 163 } 164 165 try { 166 Class refClazz = Class.forName(refClsName); 167 Class callClazz = Class.forName(st[2].getClassName()); 168 169 return (refClazz.isAssignableFrom(callClazz)); 170 171 } catch (ClassNotFoundException cfnx) { 172 return false; 173 } 174 } 175 176 public static void dumpState () {} 177 178 public static void ignoreIf (boolean cond) {} 179 180 public static void instrumentPoint (String label) {} 181 182 public static void instrumentPointDeep (String label) {} 183 184 public static void instrumentPointDeepRecur (String label, int depth) {} 185 186 public static void interesting (boolean cond) {} 187 188 public static void print (String s) { 189 System.out.println(s); 190 } 191 192 public static void print (String s, int i) { 193 System.out.println(s + " : " + i); 194 } 195 196 public static void print (String s, boolean b) { 197 System.out.println(s + " : " + b); 198 } 199 200 201 206 public static boolean getBoolean () { 207 return ((System.currentTimeMillis() & 1) != 0); 209 } 210 211 public static int getInt (int min, int max) { 212 if (random == null) { 214 random = new Random (); 215 } 216 217 return random.nextInt((max-min+1)) + min; 218 } 219 220 225 public static int getInt (String key){ 226 if (random == null) { 228 random = new Random (); 229 } 230 return random.nextInt(); 231 } 232 233 238 public static double getDouble (String key){ 239 if (random == null) { 241 random = new Random (); 242 } 243 return random.nextDouble(); 244 } 245 246 249 public static int random (int max) { 250 if (random == null) { 252 random = new Random (); 253 } 254 return random.nextInt(max + 1); 255 } 256 257 262 public static boolean randomBool () { 263 if (random == null) { 265 random = new Random (); 266 } 267 return random.nextBoolean(); 268 } 269 270 public long currentTimeMillis () { 271 return System.currentTimeMillis(); 272 } 273 274 public static Object randomObject (String type) { 276 return null; 277 } 278 279 } 280 | Popular Tags |