KickJava   Java API By Example, From Geeks To Geeks.

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


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
23
24 /**
25  * MJI NativePeer class for java.lang.Object library abstraction
26  */

27 public class JPF_java_lang_Object {
28   public static int getClass (MJIEnv env, int objref) {
29     ClassInfo oci = env.getClassInfo(objref);
30
31     return oci.getClassObjectRef();
32   }
33
34   public static boolean $isDeterministic_wait__J (MJIEnv env, int objref,
35                                                   long length) {
36     return (length == 0);
37   }
38
39   public static boolean $isExecutable_wait__J (MJIEnv env, int objref,
40                                                long length) {
41     ThreadInfo ti = env.getThreadInfo();
42
43     if (length != 0) {
44       if (env.getSystemState().random(2) == 0) {
45         return true;
46       }
47     }
48
49     switch (ti.getStatus()) {
50     case ThreadInfo.RUNNING:
51     case ThreadInfo.SYNC_RUNNING:
52       return true;
53
54     case ThreadInfo.NOTIFIED:
55       return env.canLock(objref);
56
57     case ThreadInfo.INTERRUPTED:
58       return env.canLock(objref);
59
60     default:
61
62       return false;
63     }
64   }
65
66   public static int clone (MJIEnv env, int objref) {
67     // <2do>
68
return -1;
69   }
70
71   public static int hashCode (MJIEnv env, int objref) {
72     return (objref ^ 0xABCD);
73   }
74
75   public static void notifyAll (MJIEnv env, int objref) {
76     env.notifyAll(objref);
77   }
78
79   public static void registerNatives (MJIEnv env, int clsObjRef) {
80     // let go un-noticed
81
}
82
83   public static void wait__J (MJIEnv env, int objref, long length) {
84     ThreadInfo ti = env.getThreadInfo();
85     
86     if (length != 0) {
87       if (env.getSystemState().random(2) == 0) {
88         return;
89       }
90     }
91
92     switch (ti.getStatus()) {
93     case ThreadInfo.RUNNING:
94     case ThreadInfo.SYNC_RUNNING:
95
96       env.wait(objref);
97       env.repeatInvocation();
98
99       break;
100
101     case ThreadInfo.NOTIFIED:
102       env.lockNotified(objref);
103
104       break;
105
106     case ThreadInfo.INTERRUPTED:
107       env.lockNotified(objref);
108       env.throwException("java.lang.InterruptedException");
109
110       break;
111
112     default:
113
114       // <2do> - need to make this consistent
115
throw new JPFException("invalid thread state");
116     }
117   }
118
119   public static final void notify (MJIEnv env, int objref) {
120     env.notify(objref);
121   }
122 }
123
Popular Tags