KickJava   Java API By Example, From Geeks To Geeks.

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


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 instance method; special handling for superclass, private,
30  * and instance initialization method invocations
31  * ..., objectref, [arg1, [arg2 ...]] => ...
32  */

33 public class INVOKESPECIAL extends InvokeInstruction {
34   public INVOKESPECIAL () {}
35
36   public INVOKESPECIAL (MethodInfo mi, String JavaDoc cname, String JavaDoc mname, String JavaDoc signature,
37                        int offset, int position) {
38     super(mi, cname, mname, signature, offset, position);
39   }
40
41   public int getByteCode () {
42     return 0xB7;
43   }
44   
45   public boolean isDeterministic (SystemState ss, KernelState ks, ThreadInfo th) {
46     MethodInfo mi = getInvokedMethod(th, ks);
47     if (mi == null) {
48       return true;
49     }
50
51     return mi.isDeterministic(th);
52   }
53
54   public boolean isExecutable (SystemState ss, KernelState ks, ThreadInfo th) {
55     MethodInfo mi = getInvokedMethod(th, ks);
56     if (mi == null) {
57       return true;
58     }
59
60     return mi.isExecutable(th);
61   }
62
63   public Instruction execute (SystemState ss, KernelState ks, ThreadInfo th) {
64     MethodInfo mi = getInvokedMethod(th, ks);
65     if (mi == null) {
66       return th.createAndThrowException("java.lang.NoSuchMethodException",
67                                    "calling " + cname + "." + mname);
68     }
69
70     return mi.execute(th, false);
71   }
72
73   int getCalleeThis (ThreadInfo ti) {
74     return ti.getCalleeThis( getArgSize());
75   }
76
77   public boolean isSchedulingRelevant (SystemState ss, KernelState ks, ThreadInfo ti) {
78     MethodInfo mi = getInvokedMethod( ti, ks);
79     int objRef = getCalleeThis(ti);
80
81     return mi.isSchedulingRelevant(ti,ks.da.get(objRef));
82   }
83   
84   /**
85    * we can do some more caching here - the MethodInfo should be const
86    */

87   MethodInfo getInvokedMethod (ThreadInfo th, KernelState ks) {
88     
89     // since INVOKESPECIAL is only used for private methods and ctors,
90
// we don't have to deal with null object calls
91

92     if (invokedMethod == null) {
93       ClassInfo ci = ClassInfo.getClassInfo(cname);
94       invokedMethod = ci.getMethod(mname, true);
95     }
96
97     return invokedMethod; // we can store internally
98
}
99 }
100
Popular Tags