KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gov > nasa > jpf > jvm > bytecode > INVOKESTATIC


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.bytecode;
20
21 import gov.nasa.jpf.jvm.ClassInfo;
22 import gov.nasa.jpf.jvm.KernelState;
23 import gov.nasa.jpf.jvm.MethodInfo;
24 import gov.nasa.jpf.jvm.SystemState;
25 import gov.nasa.jpf.jvm.ThreadInfo;
26
27
28 /**
29  * Invoke a class (static) method
30  * ..., [arg1, [arg2 ...]] => ...
31  */

32 public class INVOKESTATIC extends InvokeInstruction {
33   ClassInfo ci;
34   
35   public INVOKESTATIC () {}
36   
37   public INVOKESTATIC (MethodInfo mi, String JavaDoc cname, String JavaDoc mname, String JavaDoc signature,
38                        int offset, int position) {
39     super(mi, cname, mname, signature, offset, position);
40   }
41
42   ClassInfo getClassInfo () {
43     if (ci == null) {
44       ci = ClassInfo.getClassInfo(cname);
45     }
46     return ci;
47   }
48   
49   public int getByteCode () {
50     return 0xB8;
51   }
52   
53   public boolean isDeterministic (SystemState ss, KernelState ks, ThreadInfo ti) {
54     MethodInfo mi = getInvokedMethod();
55     if (mi == null) {
56       return true; // doesn't really matter
57
}
58
59     return mi.isDeterministic(ti);
60   }
61
62   public boolean isExecutable (SystemState ss, KernelState ks, ThreadInfo ti) {
63     MethodInfo mi = getInvokedMethod();
64     if (mi == null) {
65       return true; // execute so that we get the exception
66
}
67
68     return mi.isExecutable(ti);
69   }
70
71   public boolean examineAbstraction (SystemState ss, KernelState ks,
72                                      ThreadInfo ti) {
73     MethodInfo mi = getInvokedMethod();
74
75    if (mi == null) {
76       return true;
77     }
78
79     return !ci.isStaticMethodAbstractionDeterministic(ti, mi);
80   }
81
82   public Instruction execute (SystemState ss, KernelState ks, ThreadInfo ti) {
83     // make sure the class got initialized, if this is not the '<clinit>'
84
// itself (note this could be a backtracked state where the class wasn't
85
// initialized yet, i.e. we can't store it here - how bad)
86
if (mname.charAt(0) != '<') {
87       ks.sa.get(cname);
88     }
89
90     MethodInfo mi = getInvokedMethod();
91     if (mi == null) {
92       return ti.createAndThrowException("java.lang.NoSuchMethodException",
93                                    "static " + ci.getName() + "." + mname);
94     }
95
96     return mi.execute(ti, false);
97   }
98
99   public boolean isSchedulingRelevant (SystemState ss, KernelState ks, ThreadInfo ti) {
100     ClassInfo clsInfo = getClassInfo();
101     MethodInfo mi = getInvokedMethod();
102     int objRef = clsInfo.getClassObjectRef();
103     
104     return mi.isSchedulingRelevant(ti, ks.da.get(objRef));
105   }
106   
107   public MethodInfo getInvokedMethod () {
108     ClassInfo clsInfo = getClassInfo();
109     if (invokedMethod == null) {
110       invokedMethod = clsInfo.getMethod(mname, true);
111     }
112
113     return invokedMethod;
114   }
115   
116   public String JavaDoc toString() {
117     if (asString == null) {
118       asString = ("invokeStatic " + cname + "." + mname);
119     }
120     
121     return asString;
122   }
123 }
124
125
Popular Tags